From: Michael Niedermayer Date: Thu, 9 Aug 2012 13:14:57 +0000 (+0200) Subject: Merge commit 'f154ef1ae5b03f288dd8c025dab1884b4cb20c1a' X-Git-Tag: android-x86-4.4-r1~10159 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b7e9eea31f3e60dc506cf52bb78f0d9f679cb3bd;p=android-x86%2Fexternal-ffmpeg.git Merge commit 'f154ef1ae5b03f288dd8c025dab1884b4cb20c1a' * commit 'f154ef1ae5b03f288dd8c025dab1884b4cb20c1a': avconv: send EOF to lavfi even if flushing the decoder fails avconv: get rid of pointless temporary variable. avconv: simplify transcode(). avconv: cosmetics avconv: replace no_packet array in transcode() with a var in InputStream avconv: remove unused variable from InputFile. avconv: remove commented out cruft. avconv: maintain sync on lavfi outputs. Conflicts: ffmpeg.c ffmpeg.h Merged-by: Michael Niedermayer --- b7e9eea31f3e60dc506cf52bb78f0d9f679cb3bd diff --cc ffmpeg.c index b2963bbad0,d46c8e0943..bb69a347f8 --- a/ffmpeg.c +++ b/ffmpeg.c @@@ -1410,23 -1068,12 +1410,21 @@@ static int decode_audio(InputStream *is avcodec_get_frame_defaults(ist->decoded_frame); decoded_frame = ist->decoded_frame; + update_benchmark(NULL); ret = avcodec_decode_audio4(avctx, decoded_frame, got_output, pkt); + update_benchmark("decode_audio %d.%d", ist->file_index, ist->st->index); - if (ret < 0) { - return ret; - } - if (avctx->sample_rate <= 0) { ++ ++ if (ret >= 0 && avctx->sample_rate <= 0) { + av_log(avctx, AV_LOG_ERROR, "Sample rate %d invalid\n", avctx->sample_rate); + return AVERROR_INVALIDDATA; + } + - if (!*got_output) { - /* no audio frame */ - if (!pkt->size) + if (!*got_output || ret < 0) { + if (!pkt->size) { for (i = 0; i < ist->nb_filters; i++) - av_buffersrc_buffer(ist->filters[i]->filter, NULL); + av_buffersrc_add_ref(ist->filters[i]->filter, NULL, + AV_BUFFERSRC_FLAG_NO_COPY); + } return ret; } @@@ -1535,41 -1209,20 +1533,39 @@@ static int decode_video(InputStream *is else avcodec_get_frame_defaults(ist->decoded_frame); decoded_frame = ist->decoded_frame; + pkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ist->st->time_base); + update_benchmark(NULL); ret = avcodec_decode_video2(ist->st->codec, decoded_frame, got_output, pkt); + update_benchmark("decode_video %d.%d", ist->file_index, ist->st->index); - if (ret < 0) - return ret; - - quality = same_quant ? decoded_frame->quality : 0; - if (!*got_output) { - /* no picture yet */ - if (!pkt->size) + if (!*got_output || ret < 0) { + if (!pkt->size) { for (i = 0; i < ist->nb_filters; i++) - av_buffersrc_buffer(ist->filters[i]->filter, NULL); + av_buffersrc_add_ref(ist->filters[i]->filter, NULL, AV_BUFFERSRC_FLAG_NO_COPY); + } return ret; } + quality = same_quant ? decoded_frame->quality : 0; - decoded_frame->pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pkt_pts, - decoded_frame->pkt_dts); ++ + if(ist->top_field_first>=0) + decoded_frame->top_field_first = ist->top_field_first; + + best_effort_timestamp= av_frame_get_best_effort_timestamp(decoded_frame); + if(best_effort_timestamp != AV_NOPTS_VALUE) + ist->next_pts = ist->pts = av_rescale_q(decoded_frame->pts = best_effort_timestamp, ist->st->time_base, AV_TIME_BASE_Q); + + if (debug_ts) { + av_log(NULL, AV_LOG_INFO, "decoder -> ist_index:%d type:video " + "frame_pts:%s frame_pts_time:%s best_effort_ts:%"PRId64" best_effort_ts_time:%s keyframe:%d frame_type:%d \n", + ist->st->index, av_ts2str(decoded_frame->pts), + av_ts2timestr(decoded_frame->pts, &ist->st->time_base), + best_effort_timestamp, + av_ts2timestr(best_effort_timestamp, &ist->st->time_base), + decoded_frame->key_frame, decoded_frame->pict_type); + } + pkt->size = 0; pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free); @@@ -2387,177 -1948,27 +2383,177 @@@ static int need_output(void return 0; } -static InputFile *select_input_file(void) +static int input_acceptable(InputStream *ist) { - InputFile *ifile = NULL; - int64_t ipts_min = INT64_MAX; - int i; + av_assert1(!ist->discard); - return !input_files[ist->file_index]->unavailable && ++ return !input_files[ist->file_index]->eagain && + !input_files[ist->file_index]->eof_reached; +} - for (i = 0; i < nb_input_streams; i++) { - InputStream *ist = input_streams[i]; - int64_t ipts = ist->last_dts; +static int find_graph_input(FilterGraph *graph) +{ + int i, nb_req_max = 0, file_index = -1; + + for (i = 0; i < graph->nb_inputs; i++) { + int nb_req = av_buffersrc_get_nb_failed_requests(graph->inputs[i]->filter); + if (nb_req > nb_req_max) { + InputStream *ist = graph->inputs[i]->ist; + if (input_acceptable(ist)) { + nb_req_max = nb_req; + file_index = ist->file_index; + } + } + } - if (ist->discard || input_files[ist->file_index]->eagain) - continue; - if (!input_files[ist->file_index]->eof_reached) { - if (ipts < ipts_min) { - ipts_min = ipts; - ifile = input_files[ist->file_index]; + return file_index; +} + +/** + * Select the input file to read from. + * + * @return >=0 index of the input file to use; + * -1 if no file is acceptable; + * -2 to read from filters without reading from a file + */ +static int select_input_file(void) +{ + int i, ret, nb_active_out = nb_output_streams, ost_index = -1; + int64_t opts_min; + OutputStream *ost; + AVFilterBufferRef *dummy; + + for (i = 0; i < nb_output_streams; i++) + nb_active_out -= output_streams[i]->unavailable = + output_streams[i]->is_past_recording_time; + while (nb_active_out) { + opts_min = INT64_MAX; + ost_index = -1; + for (i = 0; i < nb_output_streams; i++) { + OutputStream *ost = output_streams[i]; + int64_t opts = av_rescale_q(ost->st->cur_dts, ost->st->time_base, + AV_TIME_BASE_Q); + if (!ost->unavailable && opts < opts_min) { + opts_min = opts; + ost_index = i; } } + if (ost_index < 0) + return -1; + + ost = output_streams[ost_index]; + if (ost->source_index >= 0) { + /* ost is directly connected to an input */ + InputStream *ist = input_streams[ost->source_index]; + if (input_acceptable(ist)) + return ist->file_index; + } else { + /* ost is connected to a complex filtergraph */ + av_assert1(ost->filter); + ret = av_buffersink_get_buffer_ref(ost->filter->filter, &dummy, + AV_BUFFERSINK_FLAG_PEEK); + if (ret >= 0) + return -2; + ret = find_graph_input(ost->filter->graph); + if (ret >= 0) + return ret; + } + ost->unavailable = 1; + nb_active_out--; } + return -1; +} - return ifile; +static int check_keyboard_interaction(int64_t cur_time) +{ + int i, ret, key; + static int64_t last_time; + if (received_nb_signals) + return AVERROR_EXIT; + /* read_key() returns 0 on EOF */ + if(cur_time - last_time >= 100000 && !run_as_daemon){ + key = read_key(); + last_time = cur_time; + }else + key = -1; + if (key == 'q') + return AVERROR_EXIT; + if (key == '+') av_log_set_level(av_log_get_level()+10); + if (key == '-') av_log_set_level(av_log_get_level()-10); + if (key == 's') qp_hist ^= 1; + if (key == 'h'){ + if (do_hex_dump){ + do_hex_dump = do_pkt_dump = 0; + } else if(do_pkt_dump){ + do_hex_dump = 1; + } else + do_pkt_dump = 1; + av_log_set_level(AV_LOG_DEBUG); + } + if (key == 'c' || key == 'C'){ + char buf[4096], target[64], command[256], arg[256] = {0}; + double time; + int k, n = 0; + fprintf(stderr, "\nEnter command: