Browse code

Place the bitstream_filters variable in the AVOutputStream, thus greatly simplifying its handling and reducing code duplication.

Patch by Nicolas George -bsf nicolas*george|normalesup+org.

Originally committed as revision 25501 to svn://svn.ffmpeg.org/ffmpeg/trunk

Nicolas George authored on 2010/10/16 19:06:13
Showing 1 changed files
... ...
@@ -247,8 +247,6 @@ static short *samples;
247 247
 static AVBitStreamFilterContext *video_bitstream_filters=NULL;
248 248
 static AVBitStreamFilterContext *audio_bitstream_filters=NULL;
249 249
 static AVBitStreamFilterContext *subtitle_bitstream_filters=NULL;
250
-static AVBitStreamFilterContext **bitstream_filters[MAX_FILES] = {NULL};
251
-static int nb_bitstream_filters[MAX_FILES] = {0};
252 250
 
253 251
 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
254 252
 
... ...
@@ -266,6 +264,7 @@ typedef struct AVOutputStream {
266 266
     //double sync_ipts;        /* dts from the AVPacket of the demuxer in second units */
267 267
     struct AVInputStream *sync_ist; /* input stream to sync against */
268 268
     int64_t sync_opts;       /* output frame counter, could be changed to some true timestamp */ //FIXME look at frame_number
269
+    AVBitStreamFilterContext *bitstream_filters;
269 270
     /* video only */
270 271
     int video_resample;
271 272
     AVFrame pict_tmp;      /* temporary image for resampling */
... ...
@@ -572,7 +571,6 @@ static int ffmpeg_exit(int ret)
572 572
         }
573 573
         av_metadata_free(&s->metadata);
574 574
         av_free(s);
575
-        av_free(bitstream_filters[i]);
576 575
         av_free(output_streams_for_file[i]);
577 576
     }
578 577
     for(i=0;i<nb_input_files;i++) {
... ...
@@ -967,7 +965,7 @@ need_realloc:
967 967
             if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
968 968
                 pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
969 969
             pkt.flags |= AV_PKT_FLAG_KEY;
970
-            write_frame(s, &pkt, enc, bitstream_filters[ost->file_index][pkt.stream_index]);
970
+            write_frame(s, &pkt, enc, ost->bitstream_filters);
971 971
 
972 972
             ost->sync_opts += enc->frame_size;
973 973
         }
... ...
@@ -1002,7 +1000,7 @@ need_realloc:
1002 1002
         if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
1003 1003
             pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
1004 1004
         pkt.flags |= AV_PKT_FLAG_KEY;
1005
-        write_frame(s, &pkt, enc, bitstream_filters[ost->file_index][pkt.stream_index]);
1005
+        write_frame(s, &pkt, enc, ost->bitstream_filters);
1006 1006
     }
1007 1007
 }
1008 1008
 
... ...
@@ -1107,7 +1105,7 @@ static void do_subtitle_out(AVFormatContext *s,
1107 1107
             else
1108 1108
                 pkt.pts += 90 * sub->end_display_time;
1109 1109
         }
1110
-        write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
1110
+        write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters);
1111 1111
     }
1112 1112
 }
1113 1113
 
... ...
@@ -1267,7 +1265,7 @@ static void do_video_out(AVFormatContext *s,
1267 1267
             pkt.pts= av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base);
1268 1268
             pkt.flags |= AV_PKT_FLAG_KEY;
1269 1269
 
1270
-            write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
1270
+            write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters);
1271 1271
             enc->coded_frame = old_frame;
1272 1272
         } else {
1273 1273
             AVFrame big_picture;
... ...
@@ -1311,7 +1309,7 @@ static void do_video_out(AVFormatContext *s,
1311 1311
 
1312 1312
                 if(enc->coded_frame->key_frame)
1313 1313
                     pkt.flags |= AV_PKT_FLAG_KEY;
1314
-                write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
1314
+                write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters);
1315 1315
                 *frame_size = ret;
1316 1316
                 video_size += ret;
1317 1317
                 //fprintf(stderr,"\nFrame: %3d size: %5d type: %d",
... ...
@@ -1766,7 +1764,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
1766 1766
                             opkt.size = data_size;
1767 1767
                         }
1768 1768
 
1769
-                        write_frame(os, &opkt, ost->st->codec, bitstream_filters[ost->file_index][opkt.stream_index]);
1769
+                        write_frame(os, &opkt, ost->st->codec, ost->bitstream_filters);
1770 1770
                         ost->st->codec->frame_number++;
1771 1771
                         ost->frame_number++;
1772 1772
                         av_free_packet(&opkt);
... ...
@@ -1875,7 +1873,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
1875 1875
                         pkt.size= ret;
1876 1876
                         if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
1877 1877
                             pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
1878
-                        write_frame(os, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
1878
+                        write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters);
1879 1879
                     }
1880 1880
                 }
1881 1881
             }
... ...
@@ -3401,11 +3399,7 @@ static void new_video_stream(AVFormatContext *oc, int file_idx)
3401 3401
     }
3402 3402
 
3403 3403
     avcodec_get_context_defaults3(st->codec, codec);
3404
-    bitstream_filters[file_idx] =
3405
-        grow_array(bitstream_filters[file_idx],
3406
-                   sizeof(*bitstream_filters[file_idx]),
3407
-                   &nb_bitstream_filters[file_idx], oc->nb_streams);
3408
-    bitstream_filters[file_idx][oc->nb_streams - 1]= video_bitstream_filters;
3404
+    ost->bitstream_filters = video_bitstream_filters;
3409 3405
     video_bitstream_filters= NULL;
3410 3406
 
3411 3407
     avcodec_thread_init(st->codec, thread_count);
... ...
@@ -3548,11 +3542,7 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx)
3548 3548
 
3549 3549
     avcodec_get_context_defaults3(st->codec, codec);
3550 3550
 
3551
-    bitstream_filters[file_idx] =
3552
-        grow_array(bitstream_filters[file_idx],
3553
-                   sizeof(*bitstream_filters[file_idx]),
3554
-                   &nb_bitstream_filters[file_idx], oc->nb_streams);
3555
-    bitstream_filters[file_idx][oc->nb_streams - 1]= audio_bitstream_filters;
3551
+    ost->bitstream_filters = audio_bitstream_filters;
3556 3552
     audio_bitstream_filters= NULL;
3557 3553
 
3558 3554
     avcodec_thread_init(st->codec, thread_count);
... ...
@@ -3622,11 +3612,7 @@ static void new_subtitle_stream(AVFormatContext *oc, int file_idx)
3622 3622
     }
3623 3623
     avcodec_get_context_defaults3(st->codec, codec);
3624 3624
 
3625
-    bitstream_filters[file_idx] =
3626
-        grow_array(bitstream_filters[file_idx],
3627
-                   sizeof(*bitstream_filters[file_idx]),
3628
-                   &nb_bitstream_filters[file_idx], oc->nb_streams);
3629
-    bitstream_filters[file_idx][oc->nb_streams - 1]= subtitle_bitstream_filters;
3625
+    ost->bitstream_filters = subtitle_bitstream_filters;
3630 3626
     subtitle_bitstream_filters= NULL;
3631 3627
 
3632 3628
     subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;