History

avconv: change {input,output}_{streams,files} into arrays of pointers.

Right now, they are arrays of structs, reallocated when new streams/files are added. This makes storing pointers to those structs harder than necessary.

Anton Khirnov committed 14 years ago

Commit 2e215261 parent ea9367e1 file · +143 −126Browse files

Unified · Split

avconv.c+143−126
@@ -264,15 +264,15 @@ typedef struct OutputFile { · 263 unmodified lines
264264 uint64_t limit_filesize;
265265 } OutputFile;
266266
267−static InputStream *input_streams = NULL;
268−static int nb_input_streams = 0;
269−static InputFile *input_files = NULL;
270−static int nb_input_files = 0;
267+static InputStream **input_streams = NULL;
268+static int nb_input_streams = 0;
269+static InputFile **input_files = NULL;
270+static int nb_input_files = 0;
271271
272−static OutputStream *output_streams = NULL;
273−static int nb_output_streams = 0;
274−static OutputFile *output_files = NULL;
275−static int nb_output_files = 0;
272+static OutputStream **output_streams = NULL;
273+static int nb_output_streams = 0;
274+static OutputFile **output_files = NULL;
275+static int nb_output_files = 0;
276276
277277 typedef struct OptionsContext {
278278 /* input/output options */
@@ -663,38 +663,42 @@ void exit_program(int ret) · 384 unmodified lines
663663
664664 /* close files */
665665 for (i = 0; i < nb_output_files; i++) {
666− AVFormatContext *s = output_files[i].ctx;
666+ AVFormatContext *s = output_files[i]->ctx;
667667 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
668668 avio_close(s->pb);
669669 avformat_free_context(s);
670− av_dict_free(&output_files[i].opts);
670+ av_dict_free(&output_files[i]->opts);
671+ av_freep(&output_files[i]);
671672 }
672673 for (i = 0; i < nb_output_streams; i++) {
673− AVBitStreamFilterContext *bsfc = output_streams[i].bitstream_filters;
674+ AVBitStreamFilterContext *bsfc = output_streams[i]->bitstream_filters;
674675 while (bsfc) {
675676 AVBitStreamFilterContext *next = bsfc->next;
676677 av_bitstream_filter_close(bsfc);
677678 bsfc = next;
678679 }
679− output_streams[i].bitstream_filters = NULL;
680+ output_streams[i]->bitstream_filters = NULL;
680681
681− if (output_streams[i].output_frame) {
682− AVFrame *frame = output_streams[i].output_frame;
682+ if (output_streams[i]->output_frame) {
683+ AVFrame *frame = output_streams[i]->output_frame;
683684 if (frame->extended_data != frame->data)
684685 av_freep(&frame->extended_data);
685686 av_freep(&frame);
686687 }
687688
688− av_freep(&output_streams[i].avfilter);
689+ av_freep(&output_streams[i]->avfilter);
690+ av_freep(&output_streams[i]);
689691 }
690692 for (i = 0; i < nb_input_files; i++) {
691− avformat_close_input(&input_files[i].ctx);
693+ avformat_close_input(&input_files[i]->ctx);
694+ av_freep(&input_files[i]);
692695 }
693696 for (i = 0; i < nb_input_streams; i++) {
694− av_freep(&input_streams[i].decoded_frame);
695− av_freep(&input_streams[i].filtered_frame);
696− av_dict_free(&input_streams[i].opts);
697− free_buffer_pool(&input_streams[i]);
697+ av_freep(&input_streams[i]->decoded_frame);
698+ av_freep(&input_streams[i]->filtered_frame);
699+ av_dict_free(&input_streams[i]->opts);
700+ free_buffer_pool(input_streams[i]);
701+ av_freep(&input_streams[i]);
698702 }
699703
700704 if (vstats_file)
@@ -860,7 +864,7 @@ static void choose_pixel_fmt(AVStream *st, AVCodec *codec) · 159 unmodified lines
860864 static double
861865 get_sync_ipts(const OutputStream *ost, int64_t pts)
862866 {
863− OutputFile *of = &output_files[ost->file_index];
867+ OutputFile *of = output_files[ost->file_index];
864868 return (double)(pts - of->start_time) / AV_TIME_BASE;
865869 }
866870
@@ -917,7 +921,7 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) · 50 unmodified lines
917921
918922 static int check_recording_time(OutputStream *ost)
919923 {
920− OutputFile *of = &output_files[ost->file_index];
924+ OutputFile *of = output_files[ost->file_index];
921925
922926 if (of->recording_time != INT64_MAX &&
923927 av_compare_ts(ost->sync_opts - ost->first_pts, ost->st->codec->time_base, of->recording_time,
@@ -1514,7 +1518,7 @@ static void print_report(int is_last_report, int64_t timer_start) · 590 unmodified lines
15141518 }
15151519
15161520
1517− oc = output_files[0].ctx;
1521+ oc = output_files[0]->ctx;
15181522
15191523 total_size = avio_size(oc->pb);
15201524 if (total_size < 0) // FIXME improve avio_size() so it works with non seekable output too
@@ -1525,7 +1529,7 @@ static void print_report(int is_last_report, int64_t timer_start) · 4 unmodified lines
15251529 vid = 0;
15261530 for (i = 0; i < nb_output_streams; i++) {
15271531 float q = -1;
1528− ost = &output_streams[i];
1532+ ost = output_streams[i];
15291533 enc = ost->st->codec;
15301534 if (!ost->stream_copy && enc->coded_frame)
15311535 q = enc->coded_frame->quality / (float)FF_QP2LAMBDA;
@@ -1611,9 +1615,9 @@ static void flush_encoders(void) · 79 unmodified lines
16111615 int i, ret;
16121616
16131617 for (i = 0; i < nb_output_streams; i++) {
1614− OutputStream *ost = &output_streams[i];
1618+ OutputStream *ost = output_streams[i];
16151619 AVCodecContext *enc = ost->st->codec;
1616− AVFormatContext *os = output_files[ost->file_index].ctx;
1620+ AVFormatContext *os = output_files[ost->file_index]->ctx;
16171621 int stop_encoding = 0;
16181622
16191623 if (!ost->encoding_needed)
@@ -1692,8 +1696,8 @@ static void flush_encoders(void) · 72 unmodified lines
16921696 */
16931697 static int check_output_constraints(InputStream *ist, OutputStream *ost)
16941698 {
1695− OutputFile *of = &output_files[ost->file_index];
1696− int ist_index = ist - input_streams;
1699+ OutputFile *of = output_files[ost->file_index];
1700+ int ist_index = input_files[ist->file_index]->ist_index + ist->st->index;
16971701
16981702 if (ost->source_index != ist_index)
16991703 return 0;
@@ -1706,7 +1710,7 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost) · 6 unmodified lines
17061710
17071711 static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
17081712 {
1709− OutputFile *of = &output_files[ost->file_index];
1713+ OutputFile *of = output_files[ost->file_index];
17101714 int64_t ost_tb_start_time = av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base);
17111715 AVPacket opkt;
17121716
@@ -1764,7 +1768,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p · 51 unmodified lines
17641768
17651769 static void rate_emu_sleep(InputStream *ist)
17661770 {
1767− if (input_files[ist->file_index].rate_emu) {
1771+ if (input_files[ist->file_index]->rate_emu) {
17681772 int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE);
17691773 int64_t now = av_gettime() - ist->start;
17701774 if (pts > now)
@@ -1866,11 +1870,11 @@ static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output) · 95 unmodified lines
18661870 rate_emu_sleep(ist);
18671871
18681872 for (i = 0; i < nb_output_streams; i++) {
1869− OutputStream *ost = &output_streams[i];
1873+ OutputStream *ost = output_streams[i];
18701874
18711875 if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
18721876 continue;
1873− do_audio_out(output_files[ost->file_index].ctx, ost, ist, decoded_frame);
1877+ do_audio_out(output_files[ost->file_index]->ctx, ost, ist, decoded_frame);
18741878 }
18751879
18761880 return ret;
@@ -1914,7 +1918,7 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int · 37 unmodified lines
19141918 decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;
19151919
19161920 for (i = 0; i < nb_output_streams; i++) {
1917− OutputStream *ost = &output_streams[i];
1921+ OutputStream *ost = output_streams[i];
19181922 int frame_size, resample_changed;
19191923
19201924 if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
@@ -1978,10 +1982,10 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int · 57 unmodified lines
19781982 if (!ost->frame_aspect_ratio)
19791983 ost->st->codec->sample_aspect_ratio = picref->video->pixel_aspect;
19801984
1981− do_video_out(output_files[ost->file_index].ctx, ost, filtered_frame, &frame_size,
1985+ do_video_out(output_files[ost->file_index]->ctx, ost, filtered_frame, &frame_size,
19821986 same_quant ? quality : ost->st->codec->global_quality);
19831987 if (vstats_filename && frame_size)
1984− do_video_stats(output_files[ost->file_index].ctx, ost, frame_size);
1988+ do_video_stats(output_files[ost->file_index]->ctx, ost, frame_size);
19851989 frame_available = ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]);
19861990 avfilter_unref_buffer(picref);
19871991 }
@@ -2005,12 +2009,12 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output) · 17 unmodified lines
20052009 rate_emu_sleep(ist);
20062010
20072011 for (i = 0; i < nb_output_streams; i++) {
2008− OutputStream *ost = &output_streams[i];
2012+ OutputStream *ost = output_streams[i];
20092013
20102014 if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
20112015 continue;
20122016
2013− do_subtitle_out(output_files[ost->file_index].ctx, ost, ist, &subtitle, pkt->pts);
2017+ do_subtitle_out(output_files[ost->file_index]->ctx, ost, ist, &subtitle, pkt->pts);
20142018 }
20152019
20162020 avsubtitle_free(&subtitle);
@@ -2113,7 +2117,7 @@ static int output_packet(InputStream *ist, const AVPacket *pkt) · 96 unmodified lines
21132117 }
21142118 }
21152119 for (i = 0; pkt && i < nb_output_streams; i++) {
2116− OutputStream *ost = &output_streams[i];
2120+ OutputStream *ost = output_streams[i];
21172121
21182122 if (!check_output_constraints(ist, ost) || ost->encoding_needed)
21192123 continue;
@@ -2133,7 +2137,7 @@ static void print_sdp(void) · 13 unmodified lines
21332137 if (!avc)
21342138 exit_program(1);
21352139 for (i = 0; i < nb_output_files; i++)
2136− avc[i] = output_files[i].ctx;
2140+ avc[i] = output_files[i]->ctx;
21372141
21382142 av_sdp_create(avc, nb_output_files, sdp, sizeof(sdp));
21392143 printf("SDP:\n%s\n", sdp);
@@ -2189,7 +2193,7 @@ static void get_default_channel_layouts(OutputStream *ost, InputStream *ist) · 49 unmodified lines
21892193 static int init_input_stream(int ist_index, char *error, int error_len)
21902194 {
21912195 int i;
2192− InputStream *ist = &input_streams[ist_index];
2196+ InputStream *ist = input_streams[ist_index];
21932197 if (ist->decoding_needed) {
21942198 AVCodec *codec = ist->dec;
21952199 if (!codec) {
@@ -2201,7 +2205,7 @@ static int init_input_stream(int ist_index, char *error, int error_len) · 5 unmodified lines
22012205 /* update requested sample format for the decoder based on the
22022206 corresponding encoder sample format */
22032207 for (i = 0; i < nb_output_streams; i++) {
2204− OutputStream *ost = &output_streams[i];
2208+ OutputStream *ost = output_streams[i];
22052209 if (ost->source_index == ist_index) {
22062210 update_sample_fmt(ist->st->codec, codec, ost->st->codec);
22072211 break;
@@ -2226,7 +2230,7 @@ static int init_input_stream(int ist_index, char *error, int error_len) · 18 unmodified lines
22262230
22272231 if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
22282232 for (i = 0; i < nb_output_streams; i++) {
2229− OutputStream *ost = &output_streams[i];
2233+ OutputStream *ost = output_streams[i];
22302234 if (ost->source_index == ist_index) {
22312235 if (!ist->st->codec->channel_layout || !ost->st->codec->channel_layout)
22322236 get_default_channel_layouts(ost, ist);
@@ -2256,15 +2260,15 @@ static int transcode_init(void) · 23 unmodified lines
22562260
22572261 /* init framerate emulation */
22582262 for (i = 0; i < nb_input_files; i++) {
2259− InputFile *ifile = &input_files[i];
2263+ InputFile *ifile = input_files[i];
22602264 if (ifile->rate_emu)
22612265 for (j = 0; j < ifile->nb_streams; j++)
2262− input_streams[j + ifile->ist_index].start = av_gettime();
2266+ input_streams[j + ifile->ist_index]->start = av_gettime();
22632267 }
22642268
22652269 /* output stream init */
22662270 for (i = 0; i < nb_output_files; i++) {
2267− oc = output_files[i].ctx;
2271+ oc = output_files[i]->ctx;
22682272 if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
22692273 av_dump_format(oc, i, oc->filename, 1);
22702274 av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", i);
@@ -2274,9 +2278,9 @@ static int transcode_init(void) · 3 unmodified lines
22742278
22752279 /* for each output stream, we compute the right encoding parameters */
22762280 for (i = 0; i < nb_output_streams; i++) {
2277− ost = &output_streams[i];
2278− oc = output_files[ost->file_index].ctx;
2279− ist = &input_streams[ost->source_index];
2281+ ost = output_streams[i];
2282+ oc = output_files[ost->file_index]->ctx;
2283+ ist = input_streams[ost->source_index];
22802284
22812285 if (ost->attachment_filename)
22822286 continue;
@@ -2495,10 +2499,10 @@ static int transcode_init(void) · 212 unmodified lines
24952499
24962500 /* open each encoder */
24972501 for (i = 0; i < nb_output_streams; i++) {
2498− ost = &output_streams[i];
2502+ ost = output_streams[i];
24992503 if (ost->encoding_needed) {
25002504 AVCodec *codec = ost->enc;
2501− AVCodecContext *dec = input_streams[ost->source_index].st->codec;
2505+ AVCodecContext *dec = input_streams[ost->source_index]->st->codec;
25022506 if (!codec) {
25032507 snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d:%d",
25042508 ost->st->codec->codec_id, ost->file_index, ost->index);
@@ -2530,7 +2534,7 @@ static int transcode_init(void) · 25 unmodified lines
25302534 extra_size += ost->st->codec->extradata_size;
25312535
25322536 if (ost->st->codec->me_threshold)
2533− input_streams[ost->source_index].st->codec->debug |= FF_DEBUG_MV;
2537+ input_streams[ost->source_index]->st->codec->debug |= FF_DEBUG_MV;
25342538 }
25352539 }
25362540
@@ -2541,13 +2545,13 @@ static int transcode_init(void) · 4 unmodified lines
25412545
25422546 /* discard unused programs */
25432547 for (i = 0; i < nb_input_files; i++) {
2544− InputFile *ifile = &input_files[i];
2548+ InputFile *ifile = input_files[i];
25452549 for (j = 0; j < ifile->ctx->nb_programs; j++) {
25462550 AVProgram *p = ifile->ctx->programs[j];
25472551 int discard = AVDISCARD_ALL;
25482552
25492553 for (k = 0; k < p->nb_stream_indexes; k++)
2550− if (!input_streams[ifile->ist_index + p->stream_index[k]].discard) {
2554+ if (!input_streams[ifile->ist_index + p->stream_index[k]]->discard) {
25512555 discard = AVDISCARD_DEFAULT;
25522556 break;
25532557 }
@@ -2557,14 +2561,14 @@ static int transcode_init(void) · 3 unmodified lines
25572561
25582562 /* open files and write file headers */
25592563 for (i = 0; i < nb_output_files; i++) {
2560− oc = output_files[i].ctx;
2564+ oc = output_files[i]->ctx;
25612565 oc->interrupt_callback = int_cb;
2562− if (avformat_write_header(oc, &output_files[i].opts) < 0) {
2566+ if (avformat_write_header(oc, &output_files[i]->opts) < 0) {
25632567 snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i);
25642568 ret = AVERROR(EINVAL);
25652569 goto dump_format;
25662570 }
2567− assert_avoptions(output_files[i].opts);
2571+ assert_avoptions(output_files[i]->opts);
25682572 if (strcmp(oc->oformat->name, "rtp")) {
25692573 want_sdp = 0;
25702574 }
@@ -2574,13 +2578,13 @@ static int transcode_init(void) · 3 unmodified lines
25742578 /* dump the file output parameters - cannot be done before in case
25752579 of stream copy */
25762580 for (i = 0; i < nb_output_files; i++) {
2577− av_dump_format(output_files[i].ctx, i, output_files[i].ctx->filename, 1);
2581+ av_dump_format(output_files[i]->ctx, i, output_files[i]->ctx->filename, 1);
25782582 }
25792583
25802584 /* dump the stream mapping */
25812585 av_log(NULL, AV_LOG_INFO, "Stream mapping:\n");
25822586 for (i = 0; i < nb_output_streams; i++) {
2583− ost = &output_streams[i];
2587+ ost = output_streams[i];
25842588
25852589 if (ost->attachment_filename) {
25862590 /* an attached file */
@@ -2589,19 +2593,19 @@ static int transcode_init(void) · 2 unmodified lines
25892593 continue;
25902594 }
25912595 av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d",
2592− input_streams[ost->source_index].file_index,
2593− input_streams[ost->source_index].st->index,
2596+ input_streams[ost->source_index]->file_index,
2597+ input_streams[ost->source_index]->st->index,
25942598 ost->file_index,
25952599 ost->index);
2596− if (ost->sync_ist != &input_streams[ost->source_index])
2600+ if (ost->sync_ist != input_streams[ost->source_index])
25972601 av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]",
25982602 ost->sync_ist->file_index,
25992603 ost->sync_ist->st->index);
26002604 if (ost->stream_copy)
26012605 av_log(NULL, AV_LOG_INFO, " (copy)");
26022606 else
2603− av_log(NULL, AV_LOG_INFO, " (%s -> %s)", input_streams[ost->source_index].dec ?
2604− input_streams[ost->source_index].dec->name : "?",
2607+ av_log(NULL, AV_LOG_INFO, " (%s -> %s)", input_streams[ost->source_index]->dec ?
2608+ input_streams[ost->source_index]->dec->name : "?",
26052609 ost->enc ? ost->enc->name : "?");
26062610 av_log(NULL, AV_LOG_INFO, "\n");
26072611 }
@@ -2659,16 +2663,16 @@ static int transcode(void) · 51 unmodified lines
26592663 OutputFile *of;
26602664 int64_t ipts;
26612665 double opts;
2662− ost = &output_streams[i];
2663− of = &output_files[ost->file_index];
2664− os = output_files[ost->file_index].ctx;
2665− ist = &input_streams[ost->source_index];
2666+ ost = output_streams[i];
2667+ of = output_files[ost->file_index];
2668+ os = output_files[ost->file_index]->ctx;
2669+ ist = input_streams[ost->source_index];
26662670 if (ost->is_past_recording_time || no_packet[ist->file_index] ||
26672671 (os->pb && avio_tell(os->pb) >= of->limit_filesize))
26682672 continue;
26692673 opts = ost->st->pts.val * av_q2d(ost->st->time_base);
26702674 ipts = ist->last_dts;
2671− if (!input_files[ist->file_index].eof_reached) {
2675+ if (!input_files[ist->file_index]->eof_reached) {
26722676 if (ipts < ipts_min) {
26732677 ipts_min = ipts;
26742678 if (input_sync)
@@ -2682,7 +2686,7 @@ static int transcode(void) · 7 unmodified lines
26822686 if (ost->frame_number >= ost->max_frames) {
26832687 int j;
26842688 for (j = 0; j < of->ctx->nb_streams; j++)
2685− output_streams[of->ost_index + j].is_past_recording_time = 1;
2689+ output_streams[of->ost_index + j]->is_past_recording_time = 1;
26862690 continue;
26872691 }
26882692 }
@@ -2698,7 +2702,7 @@ static int transcode(void) · 9 unmodified lines
26982702 }
26992703
27002704 /* read a frame from it and output it in the fifo */
2701− is = input_files[file_index].ctx;
2705+ is = input_files[file_index]->ctx;
27022706 ret = av_read_frame(is, &pkt);
27032707 if (ret == AVERROR(EAGAIN)) {
27042708 no_packet[file_index] = 1;
@@ -2706,7 +2710,7 @@ static int transcode(void) · 1 unmodified line
27062710 continue;
27072711 }
27082712 if (ret < 0) {
2709− input_files[file_index].eof_reached = 1;
2713+ input_files[file_index]->eof_reached = 1;
27102714 if (opt_shortest)
27112715 break;
27122716 else
@@ -2722,17 +2726,17 @@ static int transcode(void) · 9 unmodified lines
27222726 }
27232727 /* the following test is needed in case new streams appear
27242728 dynamically in stream : we ignore them */
2725− if (pkt.stream_index >= input_files[file_index].nb_streams)
2729+ if (pkt.stream_index >= input_files[file_index]->nb_streams)
27262730 goto discard_packet;
2727− ist_index = input_files[file_index].ist_index + pkt.stream_index;
2728− ist = &input_streams[ist_index];
2731+ ist_index = input_files[file_index]->ist_index + pkt.stream_index;
2732+ ist = input_streams[ist_index];
27292733 if (ist->discard)
27302734 goto discard_packet;
27312735
27322736 if (pkt.dts != AV_NOPTS_VALUE)
2733− pkt.dts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
2737+ pkt.dts += av_rescale_q(input_files[ist->file_index]->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
27342738 if (pkt.pts != AV_NOPTS_VALUE)
2735− pkt.pts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
2739+ pkt.pts += av_rescale_q(input_files[ist->file_index]->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
27362740
27372741 if (pkt.pts != AV_NOPTS_VALUE)
27382742 pkt.pts *= ist->ts_scale;
@@ -2748,10 +2752,10 @@ static int transcode(void) · 9 unmodified lines
27482752 int64_t pkt_dts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);
27492753 int64_t delta = pkt_dts - ist->next_dts;
27502754 if ((FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE || pkt_dts + 1 < ist->last_dts) && !copy_ts) {
2751− input_files[ist->file_index].ts_offset -= delta;
2755+ input_files[ist->file_index]->ts_offset -= delta;
27522756 av_log(NULL, AV_LOG_DEBUG,
27532757 "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
2754− delta, input_files[ist->file_index].ts_offset);
2758+ delta, input_files[ist->file_index]->ts_offset);
27552759 pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
27562760 if (pkt.pts != AV_NOPTS_VALUE)
27572761 pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
@@ -2778,7 +2782,7 @@ static int transcode(void) · 20 unmodified lines
27782782
27792783 /* at the end of stream, we must flush the decoder buffers */
27802784 for (i = 0; i < nb_input_streams; i++) {
2781− ist = &input_streams[i];
2785+ ist = input_streams[i];
27822786 if (ist->decoding_needed) {
27832787 output_packet(ist, NULL);
27842788 }
@@ -2789,7 +2793,7 @@ static int transcode(void) · 4 unmodified lines
27892793
27902794 /* write the trailer if needed and close file */
27912795 for (i = 0; i < nb_output_files; i++) {
2792− os = output_files[i].ctx;
2796+ os = output_files[i]->ctx;
27932797 av_write_trailer(os);
27942798 }
27952799
@@ -2798,7 +2802,7 @@ static int transcode(void) · 2 unmodified lines
27982802
27992803 /* close each encoder */
28002804 for (i = 0; i < nb_output_streams; i++) {
2801− ost = &output_streams[i];
2805+ ost = output_streams[i];
28022806 if (ost->encoding_needed) {
28032807 av_freep(&ost->st->codec->stats_in);
28042808 avcodec_close(ost->st->codec);
@@ -2808,7 +2812,7 @@ static int transcode(void) · 3 unmodified lines
28082812
28092813 /* close each decoder */
28102814 for (i = 0; i < nb_input_streams; i++) {
2811− ist = &input_streams[i];
2815+ ist = input_streams[i];
28122816 if (ist->decoding_needed) {
28132817 avcodec_close(ist->st->codec);
28142818 }
@@ -2822,7 +2826,7 @@ static int transcode(void) · 7 unmodified lines
28222826
28232827 if (output_streams) {
28242828 for (i = 0; i < nb_output_streams; i++) {
2825− ost = &output_streams[i];
2829+ ost = output_streams[i];
28262830 if (ost) {
28272831 if (ost->stream_copy)
28282832 av_freep(&ost->st->codec->extradata);
@@ -2913,13 +2917,13 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg) · 84 unmodified lines
29132917 }
29142918 if (*sync)
29152919 sync++;
2916− for (i = 0; i < input_files[sync_file_idx].nb_streams; i++)
2917− if (check_stream_specifier(input_files[sync_file_idx].ctx,
2918− input_files[sync_file_idx].ctx->streams[i], sync) == 1) {
2920+ for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++)
2921+ if (check_stream_specifier(input_files[sync_file_idx]->ctx,
2922+ input_files[sync_file_idx]->ctx->streams[i], sync) == 1) {
29192923 sync_stream_idx = i;
29202924 break;
29212925 }
2922− if (i == input_files[sync_file_idx].nb_streams) {
2926+ if (i == input_files[sync_file_idx]->nb_streams) {
29232927 av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
29242928 "match any streams.\n", arg);
29252929 exit_program(1);
@@ -2937,14 +2941,14 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg) · 11 unmodified lines
29372941 for (i = 0; i < o->nb_stream_maps; i++) {
29382942 m = &o->stream_maps[i];
29392943 if (file_idx == m->file_index &&
2940− check_stream_specifier(input_files[m->file_index].ctx,
2941− input_files[m->file_index].ctx->streams[m->stream_index],
2944+ check_stream_specifier(input_files[m->file_index]->ctx,
2945+ input_files[m->file_index]->ctx->streams[m->stream_index],
29422946 *p == ':' ? p + 1 : p) > 0)
29432947 m->disabled = 1;
29442948 }
29452949 else
2946− for (i = 0; i < input_files[file_idx].nb_streams; i++) {
2947− if (check_stream_specifier(input_files[file_idx].ctx, input_files[file_idx].ctx->streams[i],
2950+ for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
2951+ if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
29482952 *p == ':' ? p + 1 : p) <= 0)
29492953 continue;
29502954 o->stream_maps = grow_array(o->stream_maps, sizeof(*o->stream_maps),
@@ -3129,10 +3133,14 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) · 178 unmodified lines
31293133 for (i = 0; i < ic->nb_streams; i++) {
31303134 AVStream *st = ic->streams[i];
31313135 AVCodecContext *dec = st->codec;
3132− InputStream *ist;
3136+ InputStream *ist = av_mallocz(sizeof(*ist));
3137+
3138+ if (!ist)
3139+ exit_program(1);
31333140
31343141 input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1);
3135− ist = &input_streams[nb_input_streams - 1];
3142+ input_streams[nb_input_streams - 1] = ist;
3143+
31363144 ist->st = st;
31373145 ist->file_index = nb_input_files;
31383146 ist->discard = 1;
@@ -3314,11 +3322,14 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena · 175 unmodified lines
33143322 av_dump_format(ic, nb_input_files, filename, 0);
33153323
33163324 input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1);
3317− input_files[nb_input_files - 1].ctx = ic;
3318− input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams;
3319− input_files[nb_input_files - 1].ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp);
3320− input_files[nb_input_files - 1].nb_streams = ic->nb_streams;
3321− input_files[nb_input_files - 1].rate_emu = o->rate_emu;
3325+ if (!(input_files[nb_input_files - 1] = av_mallocz(sizeof(*input_files[0]))))
3326+ exit_program(1);
3327+
3328+ input_files[nb_input_files - 1]->ctx = ic;
3329+ input_files[nb_input_files - 1]->ist_index = nb_input_streams - ic->nb_streams;
3330+ input_files[nb_input_files - 1]->ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp);
3331+ input_files[nb_input_files - 1]->nb_streams = ic->nb_streams;
3332+ input_files[nb_input_files - 1]->rate_emu = o->rate_emu;
33223333
33233334 for (i = 0; i < o->nb_dump_attachment; i++) {
33243335 int j;
@@ -3445,7 +3456,10 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e · 120 unmodified lines
34453456
34463457 output_streams = grow_array(output_streams, sizeof(*output_streams), &nb_output_streams,
34473458 nb_output_streams + 1);
3448− ost = &output_streams[nb_output_streams - 1];
3459+ if (!(ost = av_mallocz(sizeof(*ost))))
3460+ exit_program(1);
3461+ output_streams[nb_output_streams - 1] = ost;
3462+
34493463 ost->file_index = nb_output_files;
34503464 ost->index = idx;
34513465 ost->st = st;
@@ -3825,16 +3839,16 @@ static void opt_output_file(void *optctx, const char *filename) · 373 unmodified lines
38253839 if (index >= 0) {\
38263840 ost = new_ ## type ## _stream(o, oc);\
38273841 ost->source_index = index;\
3828− ost->sync_ist = &input_streams[index];\
3829− input_streams[index].discard = 0;\
3830− input_streams[index].st->discard = AVDISCARD_NONE;\
3842+ ost->sync_ist = input_streams[index];\
3843+ input_streams[index]->discard = 0;\
3844+ input_streams[index]->st->discard = AVDISCARD_NONE;\
38313845 }
38323846
38333847 /* video: highest resolution */
38343848 if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) {
38353849 int area = 0, idx = -1;
38363850 for (i = 0; i < nb_input_streams; i++) {
3837− ist = &input_streams[i];
3851+ ist = input_streams[i];
38383852 if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
38393853 ist->st->codec->width * ist->st->codec->height > area) {
38403854 area = ist->st->codec->width * ist->st->codec->height;
@@ -3848,7 +3862,7 @@ static void opt_output_file(void *optctx, const char *filename) · 7 unmodified lines
38483862 if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) {
38493863 int channels = 0, idx = -1;
38503864 for (i = 0; i < nb_input_streams; i++) {
3851− ist = &input_streams[i];
3865+ ist = input_streams[i];
38523866 if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
38533867 ist->st->codec->channels > channels) {
38543868 channels = ist->st->codec->channels;
@@ -3861,7 +3875,7 @@ static void opt_output_file(void *optctx, const char *filename) · 6 unmodified lines
38613875 /* subtitles: pick first */
38623876 if (!o->subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) {
38633877 for (i = 0; i < nb_input_streams; i++)
3864− if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
3878+ if (input_streams[i]->st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
38653879 NEW_STREAM(subtitle, i);
38663880 break;
38673881 }
@@ -3874,7 +3888,7 @@ static void opt_output_file(void *optctx, const char *filename) · 6 unmodified lines
38743888 if (map->disabled)
38753889 continue;
38763890
3877− ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];
3891+ ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index];
38783892 switch (ist->st->codec->codec_type) {
38793893 case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break;
38803894 case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break;
@@ -3887,8 +3901,8 @@ static void opt_output_file(void *optctx, const char *filename) · 6 unmodified lines
38873901 exit_program(1);
38883902 }
38893903
3890− ost->source_index = input_files[map->file_index].ist_index + map->stream_index;
3891− ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index +
3904+ ost->source_index = input_files[map->file_index]->ist_index + map->stream_index;
3905+ ost->sync_ist = input_streams[input_files[map->sync_file_index]->ist_index +
38923906 map->sync_stream_index];
38933907 ist->discard = 0;
38943908 ist->st->discard = AVDISCARD_NONE;
@@ -3932,14 +3946,17 @@ static void opt_output_file(void *optctx, const char *filename) · 37 unmodified lines
39323946 }
39333947
39343948 output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1);
3935− output_files[nb_output_files - 1].ctx = oc;
3936− output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams;
3937− output_files[nb_output_files - 1].recording_time = o->recording_time;
3949+ if (!(output_files[nb_output_files - 1] = av_mallocz(sizeof(*output_files[0]))))
3950+ exit_program(1);
3951+
3952+ output_files[nb_output_files - 1]->ctx = oc;
3953+ output_files[nb_output_files - 1]->ost_index = nb_output_streams - oc->nb_streams;
3954+ output_files[nb_output_files - 1]->recording_time = o->recording_time;
39383955 if (o->recording_time != INT64_MAX)
39393956 oc->duration = o->recording_time;
3940− output_files[nb_output_files - 1].start_time = o->start_time;
3941− output_files[nb_output_files - 1].limit_filesize = o->limit_filesize;
3942− av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0);
3957+ output_files[nb_output_files - 1]->start_time = o->start_time;
3958+ output_files[nb_output_files - 1]->limit_filesize = o->limit_filesize;
3959+ av_dict_copy(&output_files[nb_output_files - 1]->opts, format_opts, 0);
39433960
39443961 /* check filename in case of an image number is expected */
39453962 if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
@@ -3956,7 +3973,7 @@ static void opt_output_file(void *optctx, const char *filename) · 10 unmodified lines
39563973 /* open the file */
39573974 if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
39583975 &oc->interrupt_callback,
3959− &output_files[nb_output_files - 1].opts)) < 0) {
3976+ &output_files[nb_output_files - 1]->opts)) < 0) {
39603977 print_error(filename, err);
39613978 exit_program(1);
39623979 }
@@ -3965,7 +3982,7 @@ static void opt_output_file(void *optctx, const char *filename) · 2 unmodified lines
39653982 if (o->mux_preload) {
39663983 uint8_t buf[64];
39673984 snprintf(buf, sizeof(buf), "%d", (int)(o->mux_preload*AV_TIME_BASE));
3968− av_dict_set(&output_files[nb_output_files - 1].opts, "preload", buf, 0);
3985+ av_dict_set(&output_files[nb_output_files - 1]->opts, "preload", buf, 0);
39693986 }
39703987 oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
39713988 oc->flags |= AVFMT_FLAG_NONBLOCK;
@@ -3981,7 +3998,7 @@ static void opt_output_file(void *optctx, const char *filename) · 9 unmodified lines
39813998 av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index);
39823999 exit_program(1);
39834000 }
3984− copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, input_files[in_file_index].ctx, o);
4001+ copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, input_files[in_file_index]->ctx, o);
39854002 }
39864003
39874004 /* copy chapters */
@@ -3990,7 +4007,7 @@ static void opt_output_file(void *optctx, const char *filename) · 2 unmodified lines
39904007 /* copy chapters from the first input file that has them*/
39914008 o->chapters_input_file = -1;
39924009 for (i = 0; i < nb_input_files; i++)
3993− if (input_files[i].ctx->nb_chapters) {
4010+ if (input_files[i]->ctx->nb_chapters) {
39944011 o->chapters_input_file = i;
39954012 break;
39964013 }
@@ -4001,20 +4018,20 @@ static void opt_output_file(void *optctx, const char *filename) · 4 unmodified lines
40014018 }
40024019 }
40034020 if (o->chapters_input_file >= 0)
4004− copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1],
4021+ copy_chapters(input_files[o->chapters_input_file], output_files[nb_output_files - 1],
40054022 !o->metadata_chapters_manual);
40064023
40074024 /* copy global metadata by default */
40084025 if (!o->metadata_global_manual && nb_input_files)
4009− av_dict_copy(&oc->metadata, input_files[0].ctx->metadata,
4026+ av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata,
40104027 AV_DICT_DONT_OVERWRITE);
40114028 if (!o->metadata_streams_manual)
4012− for (i = output_files[nb_output_files - 1].ost_index; i < nb_output_streams; i++) {
4029+ for (i = output_files[nb_output_files - 1]->ost_index; i < nb_output_streams; i++) {
40134030 InputStream *ist;
4014− if (output_streams[i].source_index < 0) /* this is true e.g. for attached files */
4031+ if (output_streams[i]->source_index < 0) /* this is true e.g. for attached files */
40154032 continue;
4016− ist = &input_streams[output_streams[i].source_index];
4017− av_dict_copy(&output_streams[i].st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
4033+ ist = input_streams[output_streams[i]->source_index];
4034+ av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
40184035 }
40194036
40204037 /* process manually set metadata */
@@ -4173,8 +4190,8 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) · 152 unmodified lines
41734190 if (nb_input_files) {
41744191 int i, j, fr;
41754192 for (j = 0; j < nb_input_files; j++) {
4176− for (i = 0; i < input_files[j].nb_streams; i++) {
4177− AVCodecContext *c = input_files[j].ctx->streams[i]->codec;
4193+ for (i = 0; i < input_files[j]->nb_streams; i++) {
4194+ AVCodecContext *c = input_files[j]->ctx->streams[i]->codec;
41784195 if (c->codec_type != AVMEDIA_TYPE_VIDEO)
41794196 continue;
41804197 fr = c->time_base.den * 1000 / c->time_base.num;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t