]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/swf.c
use ff_neterrno() and FF_NETERROR() for networking error handling
[ffmpeg] / libavformat / swf.c
index 4f4fdb193945e98ae3da5d14c5a214d702d2fc5a..eaf2e8d75401fe0db71c35b6d80db9c86ab2268c 100644 (file)
@@ -67,7 +67,7 @@ typedef struct {
     int sound_samples;
     int swf_frame_number;
     int video_frame_number;
-    int ms_per_frame;
+    int frame_rate;
     int tag;
 
     uint8_t audio_fifo[AUDIO_FIFO_SIZE];
@@ -267,7 +267,7 @@ static int swf_write_header(AVFormatContext *s)
                 }
                 audio_enc = enc;
             } else {
-                av_log(enc, AV_LOG_ERROR, "SWF muxer only supports MP3\n");
+                av_log(s, AV_LOG_ERROR, "SWF muxer only supports MP3\n");
                 return -1;
             }
         } else {
@@ -276,7 +276,7 @@ static int swf_write_header(AVFormatContext *s)
                  enc->codec_id == CODEC_ID_MJPEG ) {
                 video_enc = enc;
             } else {
-                av_log(enc, AV_LOG_ERROR, "SWF muxer only supports VP6, FLV1 and MJPEG\n");
+                av_log(s, AV_LOG_ERROR, "SWF muxer only supports VP6, FLV1 and MJPEG\n");
                 return -1;
             }
         }
@@ -387,7 +387,6 @@ static int swf_write_header(AVFormatContext *s)
         default:
             /* not supported */
             av_log(s, AV_LOG_ERROR, "swf doesnt support that sample rate, choose from (44100, 22050, 11025)\n");
-            av_free(swf->audio_fifo);
             return -1;
         }
         v |= 0x02; /* 16 bit playback */
@@ -619,8 +618,6 @@ static int get_swf_tag(ByteIOContext *pb, int *len_ptr)
 static int swf_probe(AVProbeData *p)
 {
     /* check file header */
-    if (p->buf_size <= 16)
-        return 0;
     if ((p->buf[0] == 'F' || p->buf[0] == 'C') && p->buf[1] == 'W' &&
         p->buf[2] == 'S')
         return AVPROBE_SCORE_MAX;
@@ -632,7 +629,7 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
     SWFContext *swf = s->priv_data;
     ByteIOContext *pb = &s->pb;
-    int nbits, len, frame_rate, tag, v;
+    int nbits, len, tag, v;
     offset_t frame_offset = -1;
     AVStream *ast = 0;
     AVStream *vst = 0;
@@ -651,13 +648,9 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
     nbits = get_byte(pb) >> 3;
     len = (4 * nbits - 3 + 7) / 8;
     url_fskip(pb, len);
-    frame_rate = get_le16(pb);
+    swf->frame_rate = get_le16(pb); /* 8.8 fixed */
     get_le16(pb); /* frame count */
 
-    /* The Flash Player converts 8.8 frame rates
-       to milliseconds internally. Do the same to get
-       a correct framerate */
-    swf->ms_per_frame = ( 1000 * 256 ) / frame_rate;
     swf->samples_per_frame = 0;
 
     for(;;) {
@@ -684,16 +677,16 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
             v = get_byte(pb);
             swf->samples_per_frame = get_le16(pb);
             ast = av_new_stream(s, -1); /* -1 to avoid clash with video stream ch_id */
-            av_set_pts_info(ast, 24, 1, 1000); /* 24 bit pts in ms */
             swf->audio_stream_index = ast->index;
             ast->codec->channels = 1 + (v&1);
             ast->codec->codec_type = CODEC_TYPE_AUDIO;
             ast->codec->codec_id = codec_get_id(swf_audio_codec_tags, (v>>4) & 15);
-            ast->need_parsing = 1;
+            ast->need_parsing = AVSTREAM_PARSE_FULL;
             sample_rate_code= (v>>2) & 3;
             if (!sample_rate_code)
                 return AVERROR_IO;
             ast->codec->sample_rate = 11025 << (sample_rate_code-1);
+            av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
             if (len > 4)
                 url_fskip(pb,len-4);
 
@@ -707,13 +700,8 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
             url_fskip(pb, len);
         }
     }
-    if (vst) {
-        av_set_pts_info(vst, 24, 1, 1000); /* 24 bit pts in ms */
-        if (swf->ms_per_frame) {
-            vst->codec->time_base.den = 1000. / swf->ms_per_frame;
-            vst->codec->time_base.num = 1;
-        }
-    }
+    if (vst)
+        av_set_pts_info(vst, 64, 256, swf->frame_rate);
     return 0;
 }
 
@@ -736,7 +724,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
                 if (st->codec->codec_type == CODEC_TYPE_VIDEO && st->id == ch_id) {
                     frame = get_le16(pb);
                     av_get_packet(pb, pkt, len-2);
-                    pkt->pts = frame * swf->ms_per_frame;
+                    pkt->pts = frame;
                     pkt->stream_index = st->index;
                     return pkt->size;
                 }