]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rmdec.c
unused
[ffmpeg] / libavformat / rmdec.c
index 8ac86d77276196d84117f6d0847c463dc5f8f208..47f7cf11a431cc2c63575e0d8e26edfa261dacb8 100644 (file)
  */
 #include "avformat.h"
 #include "rm.h"
+#include "avstring.h"
 
-
-static void get_str(ByteIOContext *pb, char *buf, int buf_size)
+static inline void get_strl(ByteIOContext *pb, char *buf, int buf_size, int len)
 {
-    int len, i;
-    char *q;
+    int i;
+    char *q, r;
 
-    len = get_be16(pb);
     q = buf;
     for(i=0;i<len;i++) {
+        r = get_byte(pb);
         if (i < buf_size - 1)
-            *q++ = get_byte(pb);
+            *q++ = r;
     }
-    *q = '\0';
+    if (buf_size > 0) *q = '\0';
 }
 
-static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
+static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
 {
-    int len, i;
-    char *q;
+    get_strl(pb, buf, buf_size, get_be16(pb));
+}
 
-    len = get_byte(pb);
-    q = buf;
-    for(i=0;i<len;i++) {
-        if (i < buf_size - 1)
-            *q++ = get_byte(pb);
-    }
-    *q = '\0';
+static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
+{
+    get_strl(pb, buf, buf_size, get_byte(pb));
 }
 
 static int rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
@@ -175,8 +171,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
             }
         } else {
             st->codec->codec_id = CODEC_ID_NONE;
-            pstrcpy(st->codec->codec_name, sizeof(st->codec->codec_name),
-                    buf);
+            av_strlcpy(st->codec->codec_name, buf, sizeof(st->codec->codec_name));
         }
         if (read_all) {
             get_byte(pb);
@@ -221,7 +216,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
         /* very old .ra format */
         return rm_read_header_old(s, ap);
     } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
-        return AVERROR_IO;
+        return AVERROR(EIO);
     }
 
     get_be32(pb); /* header size */
@@ -262,10 +257,10 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
             flags = get_be16(pb); /* flags */
             break;
         case MKTAG('C', 'O', 'N', 'T'):
-            get_str(pb, s->title, sizeof(s->title));
-            get_str(pb, s->author, sizeof(s->author));
-            get_str(pb, s->copyright, sizeof(s->copyright));
-            get_str(pb, s->comment, sizeof(s->comment));
+            get_str16(pb, s->title, sizeof(s->title));
+            get_str16(pb, s->author, sizeof(s->author));
+            get_str16(pb, s->copyright, sizeof(s->copyright));
+            get_str16(pb, s->comment, sizeof(s->comment));
             break;
         case MKTAG('M', 'D', 'P', 'R'):
             st = av_new_stream(s, 0);
@@ -360,7 +355,7 @@ skip:
     for(i=0;i<s->nb_streams;i++) {
         av_free(s->streams[i]);
     }
-    return AVERROR_IO;
+    return AVERROR(EIO);
 }
 
 static int get_num(ByteIOContext *pb, int *len)
@@ -469,7 +464,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
             for (y = 0; y < rm->sub_packet_h; y++)
                 for (x = 0; x < rm->sub_packet_h/2; x++)
                     if (get_buffer(pb, rm->audiobuf+x*2*rm->audio_framesize+y*rm->coded_framesize, rm->coded_framesize) <= 0)
-                        return AVERROR_IO;
+                        return AVERROR(EIO);
             rm->audio_stream_num = 0;
             rm->audio_pkt_cnt = rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - 1;
             // Release first audio packet
@@ -483,7 +478,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
             len= av_get_packet(pb, pkt, len);
             pkt->stream_index = 0;
             if (len <= 0) {
-                return AVERROR_IO;
+                return AVERROR(EIO);
             }
             pkt->size = len;
         }
@@ -492,7 +487,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
 resync:
         len=sync(s, &timestamp, &flags, &i, &pos);
         if(len<0)
-            return AVERROR_IO;
+            return AVERROR(EIO);
         st = s->streams[i];
 
         if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
@@ -515,6 +510,8 @@ resync:
             rm->current_stream= st->id;
 
 //            av_log(NULL, AV_LOG_DEBUG, "%X len:%d pos:%d len2:%d pic_num:%d\n",h, len, pos, len2, pic_num);
+            if((h & 0xc0) == 0x80)
+                len=pos;
             if(len2 && len2<len)
                 len=len2;
             rm->remaining_len-= len;
@@ -609,7 +606,7 @@ resync:
     /* for AC3, needs to swap bytes */
     if (st->codec->codec_id == CODEC_ID_AC3) {
         ptr = pkt->data;
-        for(j=0;j<len;j+=2) {
+        for(j=0;j<pkt->size;j+=2) {
             FFSWAP(int, ptr[0], ptr[1]);
             ptr += 2;
         }