]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpegenc.c
Remove unnecessary header inclusion directives.
[ffmpeg] / libavformat / mpegenc.c
index 8665030421bd950abad98534d69da4dc9bc6857c..b37a7742952a06bf780fdeb745e21a5623947820 100644 (file)
@@ -89,7 +89,7 @@ static int put_pack_header(AVFormatContext *ctx,
 
     init_put_bits(&pb, buf, 128);
 
-    put_bits(&pb, 32, PACK_START_CODE);
+    put_bits32(&pb, PACK_START_CODE);
     if (s->is_mpeg2) {
         put_bits(&pb, 2, 0x1);
     } else {
@@ -125,7 +125,7 @@ static int put_system_header(AVFormatContext *ctx, uint8_t *buf,int only_for_str
 
     init_put_bits(&pb, buf, 128);
 
-    put_bits(&pb, 32, SYSTEM_HEADER_START_CODE);
+    put_bits32(&pb, SYSTEM_HEADER_START_CODE);
     put_bits(&pb, 16, 0);
     put_bits(&pb, 1, 1);
 
@@ -157,7 +157,7 @@ static int put_system_header(AVFormatContext *ctx, uint8_t *buf,int only_for_str
 
     put_bits(&pb, 1, 1); /* marker */
 
-    if (s->is_vcd && only_for_stream_id==AUDIO_ID) {
+    if (s->is_vcd && (only_for_stream_id & 0xe0) == AUDIO_ID) {
         /* This header applies only to the audio stream (see VCD standard p. IV-7)*/
         put_bits(&pb, 5, 0);
     } else
@@ -304,9 +304,14 @@ static int mpeg_mux_init(AVFormatContext *ctx)
                    (CONFIG_MPEG2SVCD_MUXER && ctx->oformat == &mpeg2svcd_muxer));
     s->is_dvd =    (CONFIG_MPEG2DVD_MUXER  && ctx->oformat == &mpeg2dvd_muxer);
 
-    if(ctx->packet_size)
+    if(ctx->packet_size) {
+        if (ctx->packet_size < 20 || ctx->packet_size > (1 << 23) + 10) {
+            av_log(ctx, AV_LOG_ERROR, "Invalid packet size %d\n",
+                   ctx->packet_size);
+            goto fail;
+        }
         s->packet_size = ctx->packet_size;
-    else
+    else
         s->packet_size = 2048;
 
     s->vcd_padding_bytes_written = 0;
@@ -330,7 +335,7 @@ static int mpeg_mux_init(AVFormatContext *ctx)
         av_set_pts_info(st, 64, 1, 90000);
 
         switch(st->codec->codec_type) {
-        case CODEC_TYPE_AUDIO:
+        case AVMEDIA_TYPE_AUDIO:
             if        (st->codec->codec_id == CODEC_ID_AC3) {
                 stream->id = ac3_id++;
             } else if (st->codec->codec_id == CODEC_ID_DTS) {
@@ -358,7 +363,7 @@ static int mpeg_mux_init(AVFormatContext *ctx)
             stream->max_buffer_size = 4 * 1024;
             s->audio_bound++;
             break;
-        case CODEC_TYPE_VIDEO:
+        case AVMEDIA_TYPE_VIDEO:
             stream->id = mpv_id++;
             if (st->codec->rc_buffer_size)
                 stream->max_buffer_size = 6*1024 + st->codec->rc_buffer_size/8;
@@ -374,7 +379,7 @@ static int mpeg_mux_init(AVFormatContext *ctx)
 #endif
             s->video_bound++;
             break;
-        case CODEC_TYPE_SUBTITLE:
+        case AVMEDIA_TYPE_SUBTITLE:
             stream->id = mps_id++;
             stream->max_buffer_size = 16 * 1024;
             break;
@@ -382,6 +387,8 @@ static int mpeg_mux_init(AVFormatContext *ctx)
             return -1;
         }
         stream->fifo= av_fifo_alloc(16);
+        if (!stream->fifo)
+            goto fail;
     }
     bitrate = 0;
     audio_bitrate = 0;
@@ -401,7 +408,7 @@ static int mpeg_mux_init(AVFormatContext *ctx)
 
         bitrate += codec_rate;
 
-        if (stream->id==AUDIO_ID)
+        if ((stream->id & 0xe0) == AUDIO_ID)
             audio_bitrate += codec_rate;
         else if (stream->id==VIDEO_ID)
             video_bitrate += codec_rate;
@@ -594,7 +601,7 @@ static int get_packet_payload_size(AVFormatContext *ctx, int stream_index,
             }
         }
 
-        if (s->is_vcd && stream->id == AUDIO_ID)
+        if (s->is_vcd && (stream->id & 0xe0) == AUDIO_ID)
             /* The VCD standard demands that 20 zero bytes follow
                each audio packet (see standard p. IV-8).*/
             buf_index+=20;
@@ -729,7 +736,7 @@ static int flush_packet(AVFormatContext *ctx, int stream_index,
 
     packet_size = s->packet_size - size;
 
-    if (s->is_vcd && id == AUDIO_ID)
+    if (s->is_vcd && (id & 0xe0) == AUDIO_ID)
         /* The VCD standard demands that 20 zero bytes follow
            each audio pack (see standard p. IV-8).*/
         zero_trail_bytes += 20;
@@ -868,7 +875,7 @@ static int flush_packet(AVFormatContext *ctx, int stream_index,
                 put_byte(ctx->pb, 0x10); /* flags */
 
                 /* P-STD buffer info */
-                if (id == AUDIO_ID)
+                if ((id & 0xe0) == AUDIO_ID)
                     put_be16(ctx->pb, 0x4000 | stream->max_buffer_size/ 128);
                 else
                     put_be16(ctx->pb, 0x6000 | stream->max_buffer_size/1024);
@@ -1039,7 +1046,7 @@ retry:
         /* for subtitle, a single PES packet must be generated,
            so we flush after every single subtitle packet */
         if(s->packet_size > avail_data && !flush
-           && st->codec->codec_type != CODEC_TYPE_SUBTITLE)
+           && st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE)
             return 0;
         if(avail_data==0)
             continue;
@@ -1149,7 +1156,7 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt)
     int64_t pts, dts;
     PacketDesc *pkt_desc;
     const int preload= av_rescale(ctx->preload, 90000, AV_TIME_BASE);
-    const int is_iframe = st->codec->codec_type == CODEC_TYPE_VIDEO && (pkt->flags & PKT_FLAG_KEY);
+    const int is_iframe = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (pkt->flags & AV_PKT_FLAG_KEY);
 
     pts= pkt->pts;
     dts= pkt->dts;