]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mtv.c
Merge rtp_internal.h in rtp.h, and remove rtp_internal.h
[ffmpeg] / libavformat / mtv.c
index 7f99bd65bdb63274d3893a039f05af1c9f7d5928..7bf0d841897aadb737d9029a514d50985b9c71a4 100644 (file)
 
 typedef struct MTVDemuxContext {
 
-    unsigned int        file_size;         ///< filesize, not always right
-    unsigned int        segments;          ///< number of 512 byte segments
-    unsigned int        audio_identifier;  ///< 'MP3' on all files I have seen
-    unsigned int        audio_br;          ///< bitrate of audio chanel (mp3)
-    unsigned int        img_colorfmt;      ///< frame colorfmt rgb 565/555
-    unsigned int        img_bpp;           ///< frame bits per pixel
-    unsigned int        img_width;         //
-    unsigned int        img_height;        //
-    unsigned int        img_segment_size;  ///< size of image segment
-    unsigned int        video_fps;         //
-    unsigned int        audio_subsegments; ///< audio subsegments on one segment
-
-    uint8_t             audio_packet_count;
+    unsigned int file_size;         ///< filesize, not always right
+    unsigned int segments;          ///< number of 512 byte segments
+    unsigned int audio_identifier;  ///< 'MP3' on all files I have seen
+    unsigned int audio_br;          ///< bitrate of audio chanel (mp3)
+    unsigned int img_colorfmt;      ///< frame colorfmt rgb 565/555
+    unsigned int img_bpp;           ///< frame bits per pixel
+    unsigned int img_width;         //
+    unsigned int img_height;        //
+    unsigned int img_segment_size;  ///< size of image segment
+    unsigned int video_fps;         //
+    unsigned int full_segment_size;
 
 } MTVDemuxContext;
 
 static int mtv_probe(AVProbeData *p)
 {
     /* Magic is 'AMV' */
-
     if(*(p->buf) != 'A' || *(p->buf+1) != 'M' || *(p->buf+2) != 'V')
         return 0;
 
@@ -64,10 +61,10 @@ static int mtv_probe(AVProbeData *p)
 
 static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
-    MTVDemuxContext    *mtv = s->priv_data;
-    ByteIOContext      *pb  = s->pb;
-    AVStream           *st;
-
+    MTVDemuxContext *mtv = s->priv_data;
+    ByteIOContext   *pb  = s->pb;
+    AVStream        *st;
+    unsigned int    audio_subsegments;
 
     url_fskip(pb, 3);
     mtv->file_size         = get_le32(pb);
@@ -81,18 +78,17 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap)
     mtv->img_height        = get_le16(pb);
     mtv->img_segment_size  = get_le16(pb);
     url_fskip(pb, 4);
-    mtv->audio_subsegments = get_le16(pb);
-    mtv->video_fps         = (mtv->audio_br / 4) / mtv->audio_subsegments;
-
-    /* FIXME Add sanity check here */
-
-    /* first packet is always audio*/
+    audio_subsegments = get_le16(pb);
+    mtv->full_segment_size =
+        audio_subsegments * (MTV_AUDIO_PADDING_SIZE + MTV_ASUBCHUNK_DATA_SIZE) +
+        mtv->img_segment_size;
+    mtv->video_fps         = (mtv->audio_br / 4) / audio_subsegments;
 
-    mtv->audio_packet_count = 1;
+    // FIXME Add sanity check here
 
-    /* all systems go! init decoders */
+    // all systems go! init decoders
 
-    /* video - raw rgb565 */
+    // video - raw rgb565
 
     st = av_new_stream(s, VIDEO_SID);
     if(!st)
@@ -104,10 +100,10 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap)
     st->codec->codec_tag       = MKTAG('R', 'G', 'B', mtv->img_bpp);
     st->codec->width           = mtv->img_width;
     st->codec->height          = mtv->img_height;
-    st->codec->bits_per_sample = mtv->img_bpp;
+    st->codec->bits_per_coded_sample = mtv->img_bpp;
     st->codec->sample_rate     = mtv->video_fps;
 
-    /* audio - mp3 */
+    // audio - mp3
 
     st = av_new_stream(s, AUDIO_SID);
     if(!st)
@@ -119,7 +115,7 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap)
     st->codec->bit_rate        = mtv->audio_br;
     st->need_parsing           = AVSTREAM_PARSE_FULL;
 
-    /* Jump over header */
+    // Jump over header
 
     if(url_fseek(pb, MTV_HEADER_SIZE, SEEK_SET) != MTV_HEADER_SIZE)
         return AVERROR(EIO);
@@ -139,7 +135,7 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     ret = 0;
 
-    if(mtv->audio_subsegments >= mtv->audio_packet_count)
+    if((url_ftell(pb) - s->data_offset + mtv->img_segment_size) % mtv->full_segment_size)
     {
         url_fskip(pb, MTV_AUDIO_PADDING_SIZE);
 
@@ -147,7 +143,6 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt)
         if(ret != MTV_ASUBCHUNK_DATA_SIZE)
             return AVERROR(EIO);
 
-        mtv->audio_packet_count++;
         pkt->pos -= MTV_AUDIO_PADDING_SIZE;
         pkt->stream_index = AUDIO_SID;
 
@@ -168,7 +163,6 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt)
         for(i=0;i<mtv->img_segment_size/2;i++)
             *((uint16_t *)pkt->data+i) = bswap_16(*((uint16_t *)pkt->data+i));
 #endif
-        mtv->audio_packet_count = 1;
         pkt->stream_index = VIDEO_SID;
     }