On 04/27/2013 10:24 AM, Anton Khirnov wrote: > > On Wed, 24 Apr 2013 18:50:36 +0200, Luca Barbato <[email protected]> wrote: >> On 04/24/2013 05:29 PM, Anton Khirnov wrote: >>> Integrate the code in the packet reading function, instead of inserting >>> sleeps in many places. >>> This is simpler to follow and should work better. >>> --- >>> avconv.c | 28 +++++++++++----------------- >>> 1 file changed, 11 insertions(+), 17 deletions(-) >>> >>> diff --git a/avconv.c b/avconv.c >>> index 658dadc..7aee0cb 100644 >>> --- a/avconv.c >>> +++ b/avconv.c >>> @@ -1046,16 +1046,6 @@ static void do_streamcopy(InputStream *ist, >>> OutputStream *ost, const AVPacket *p >>> ost->st->codec->frame_number++; >>> } >>> >>> -static void rate_emu_sleep(InputStream *ist) >>> -{ >>> - if (input_files[ist->file_index]->rate_emu) { >>> - int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE); >>> - int64_t now = av_gettime() - ist->start; >>> - if (pts > now) >>> - av_usleep(pts - now); >>> - } >>> -} >>> - >>> int guess_input_channel_layout(InputStream *ist) >>> { >>> AVCodecContext *dec = ist->st->codec; >>> @@ -1104,8 +1094,6 @@ static int decode_audio(InputStream *ist, AVPacket >>> *pkt, int *got_output) >>> pkt->pts = AV_NOPTS_VALUE; >>> } >>> >>> - rate_emu_sleep(ist); >>> - >>> resample_changed = ist->resample_sample_fmt != >>> decoded_frame->format || >>> ist->resample_channels != avctx->channels >>> || >>> ist->resample_channel_layout != >>> decoded_frame->channel_layout || >>> @@ -1199,8 +1187,6 @@ static int decode_video(InputStream *ist, AVPacket >>> *pkt, int *got_output) >>> pre_process_video_frame(ist, (AVPicture *)decoded_frame, >>> &buffer_to_free); >>> #endif >>> >>> - rate_emu_sleep(ist); >>> - >>> if (ist->st->sample_aspect_ratio.num) >>> decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio; >>> >>> @@ -1260,8 +1246,6 @@ static int transcode_subtitles(InputStream *ist, >>> AVPacket *pkt, int *got_output) >>> if (!*got_output) >>> return ret; >>> >>> - rate_emu_sleep(ist); >>> - >>> for (i = 0; i < nb_output_streams; i++) { >>> OutputStream *ost = output_streams[i]; >>> >>> @@ -1349,7 +1333,6 @@ static int output_packet(InputStream *ist, const >>> AVPacket *pkt) >>> >>> /* handle stream copy */ >>> if (!ist->decoding_needed) { >>> - rate_emu_sleep(ist); >>> ist->last_dts = ist->next_dts; >>> switch (ist->st->codec->codec_type) { >>> case AVMEDIA_TYPE_AUDIO: >>> @@ -2056,6 +2039,17 @@ static int get_input_packet_mt(InputFile *f, >>> AVPacket *pkt) >>> >>> static int get_input_packet(InputFile *f, AVPacket *pkt) >>> { >>> + if (f->rate_emu) { >>> + int i; >>> + for (i = 0; i < f->nb_streams; i++) { >>> + InputStream *ist = input_streams[f->ist_index + i]; >>> + int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE); >>> + int64_t now = av_gettime() - ist->start; >>> + if (pts > now) >>> + return AVERROR(EAGAIN); >>> + } >>> + } >> >> Should be tested, surely it would be more precise but it is busy wait vs >> sleep so might cause unwanted effects. might be better get the timing >> for all the streams and wait for the least amount before returning eagain. >> > > There should be no such problems, there is a sleep in the reading loop if > there > was an eagain on all inputs. > But it should behave better if there are multiple inputs. > And of course i tested it and it appears to work fine.
Fine then =) lu _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
