diff --git a/libavformat/rdt.c b/libavformat/rdt.c
index c96ed4a607a731cc7af4a8aad339c7bf5603a4d6..197f9db46e1f081c6b9a89e0452c90a15f8917c7 100644
--- a/libavformat/rdt.c
+++ b/libavformat/rdt.c
@@ -312,14 +312,16 @@ rdt_parse_packet (AVFormatContext *ctx, PayloadContext *rdt, AVStream *st,
         pos = url_ftell(&pb);
         if (res < 0)
             return res;
-        rdt->audio_pkt_cnt = res;
-        if (rdt->audio_pkt_cnt > 0 &&
-            st->codec->codec_id == CODEC_ID_AAC) {
+        if (res > 0) {
+            if (st->codec->codec_id == CODEC_ID_AAC) {
             memcpy (rdt->buffer, buf + pos, len - pos);
             rdt->rmctx->pb = av_alloc_put_byte (rdt->buffer, len - pos, 0,
                                                 NULL, NULL, NULL, NULL);
+            }
+            goto get_cache;
         }
     } else {
+get_cache:
         rdt->audio_pkt_cnt =
             ff_rm_retrieve_cache (rdt->rmctx, rdt->rmctx->pb,
                                   st, rdt->rmst[st->index], pkt);
diff --git a/libavformat/rm.h b/libavformat/rm.h
index 6e5d2c5f7ec3c5e22ef15b9a1d506eef0c315231..53dd019cded31a1328c4276a7ffa408881d5ba59 100644
--- a/libavformat/rm.h
+++ b/libavformat/rm.h
@@ -64,9 +64,9 @@ int ff_rm_read_mdpr_codecdata (AVFormatContext *s, ByteIOContext *pb,
  * @param flags pointer to an integer containing the packet flags, may be
                 updated
  * @param ts pointer to timestamp, may be updated
- * @return >=0 on success (where >0 indicates there are cached samples that
- *         can be retrieved with subsequent calls to ff_rm_retrieve_cache()),
- *         errno codes on error
+ * @return <0 on error, 0 if a packet was placed in the \p pkt pointer. A
+ *         value >0 means that no data was placed in \p pkt, but that cached
+ *         data is available by calling ff_rm_retrieve_cache().
  */
 int ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb,
                         AVStream *st, RMStream *rst, int len,
diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 1303b9f5c4fe747bd35ca30e3502c48692ae6075..055abf65becb88583307a0c82d35b13a8a1223be 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -627,16 +627,9 @@ ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb,
 
             if (++(ast->sub_packet_cnt) < h)
                 return -1;
-            else {
                 ast->sub_packet_cnt = 0;
                 rm->audio_stream_num = st->index;
-                rm->audio_pkt_cnt = h * w / st->codec->block_align - 1;
-                // Release first audio packet
-                av_new_packet(pkt, st->codec->block_align);
-                memcpy(pkt->data, ast->pkt.data, st->codec->block_align); //FIXME avoid this
-                *timestamp = ast->audiotimestamp;
-                *flags = 2; // Mark first packet as keyframe
-            }
+                rm->audio_pkt_cnt = h * w / st->codec->block_align;
         } else if (st->codec->codec_id == CODEC_ID_AAC) {
             int x;
             rm->audio_stream_num = st->index;
@@ -644,11 +637,10 @@ ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb,
             if (ast->sub_packet_cnt) {
                 for (x = 0; x < ast->sub_packet_cnt; x++)
                     ast->sub_packet_lengths[x] = get_be16(pb);
-                // Release first audio packet
-                rm->audio_pkt_cnt = ast->sub_packet_cnt - 1;
-                av_get_packet(pb, pkt, ast->sub_packet_lengths[0]);
-                *flags = 2; // Mark first packet as keyframe
-            }
+                rm->audio_pkt_cnt = ast->sub_packet_cnt;
+                ast->audiotimestamp = *timestamp;
+            } else
+                return -1;
         } else {
             av_get_packet(pb, pkt, len);
             rm_ac3_swap_bytes(st, pkt);