From 9851b98978d94e4f6d35969851658f58120c6863 Mon Sep 17 00:00:00 2001 From: Good Guy Date: Wed, 4 May 2016 12:42:27 -0600 Subject: [PATCH] fix for ffmpeg seek pos 0, add pactl probe --- cinelerra-5.1/cinelerra/audioalsa.C | 2 ++ cinelerra-5.1/cinelerra/ffmpeg.C | 33 +++++++++++++---------------- cinelerra-5.1/cinelerra/ffmpeg.h | 8 ++++--- cinelerra-5.1/configure | 3 ++- cinelerra-5.1/global_config | 1 + 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/cinelerra-5.1/cinelerra/audioalsa.C b/cinelerra-5.1/cinelerra/audioalsa.C index ee5b6530..166324d6 100644 --- a/cinelerra-5.1/cinelerra/audioalsa.C +++ b/cinelerra-5.1/cinelerra/audioalsa.C @@ -156,6 +156,7 @@ void AudioALSA::list_devices(ArrayList *devices, int pcm_title, int mode) snd_ctl_close(handle); } +#ifdef HAVE_PACTL // attempt to add pulseaudio "monitor" devices // run: pactl list | // scan output for #n, Name: @@ -211,6 +212,7 @@ void AudioALSA::list_devices(ArrayList *devices, int pcm_title, int mode) } pclose(pactl); } +#endif } void AudioALSA::translate_name(char *output, char *input, int mode) diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C index 51565786..74d1d745 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.C +++ b/cinelerra-5.1/cinelerra/ffmpeg.C @@ -47,21 +47,15 @@ static void ff_err(int ret, const char *fmt, ...) fprintf(stderr,_("%s err: %s\n"),msg, errmsg); } -FFPacket::FFPacket() -{ - init(); -} - -FFPacket::~FFPacket() -{ - av_packet_unref(&pkt); -} - void FFPacket::init() { av_init_packet(&pkt); pkt.data = 0; pkt.size = 0; } +void FFPacket::finit() +{ + av_packet_unref(&pkt); +} FFrame::FFrame(FFStream *fst) { @@ -449,7 +443,7 @@ int FFStream::flush() int FFStream::seek(int64_t no, double rate) { - if( no < 0 ) no = 0; + int64_t tstmp = -INT64_MAX+1; // default ffmpeg native seek int npkts = 1; int64_t pos = no, plmt = -1; @@ -461,27 +455,30 @@ int FFStream::seek(int64_t no, double rate) if( no-n < 30*rate ) { if( n < 0 ) n = 0; pos = n; - if( ++i < marks.size() ) plmt = marks[i].pos; + if( i < marks.size() ) plmt = marks[i].pos; npkts = MAX_RETRY; } } - double secs = pos / rate; - int64_t pkt_ts, tstmp = secs * st->time_base.den / st->time_base.num; - if( nudge != AV_NOPTS_VALUE ) tstmp += nudge; + if( pos > 0 ) { + double secs = pos / rate; + tstmp = secs * st->time_base.den / st->time_base.num; + if( nudge != AV_NOPTS_VALUE ) tstmp += nudge; + } int ret = avformat_seek_file(fmt_ctx, st->index, -INT64_MAX, tstmp, INT64_MAX, AVSEEK_FLAG_ANY); if( ret >= 0 ) { avcodec_flush_buffers(st->codec); + ipkt.finit(); ipkt.init(); need_packet = 0; flushed = 0; seeked = 1; st_eof(0); // read up to retry packets, limited to npkts in stream, and not past pkt.pos plmt - for( int retry=MAX_RETRY; ret>=0 && --retry>=0; ) { + for(;;) { if( read_packet() <= 0 ) { ret = -1; break; } if( plmt >= 0 && ipkt->pos >= plmt ) break; if( ipkt->stream_index != st->index ) continue; if( --npkts <= 0 ) break; - if( (pkt_ts=ipkt->dts) == AV_NOPTS_VALUE && - (pkt_ts=ipkt->pts) == AV_NOPTS_VALUE ) continue; + int64_t pkt_ts = ipkt->dts != AV_NOPTS_VALUE ? ipkt->dts : ipkt->pts; + if( pkt_ts == AV_NOPTS_VALUE ) continue; if( pkt_ts >= tstmp ) break; } } diff --git a/cinelerra-5.1/cinelerra/ffmpeg.h b/cinelerra-5.1/cinelerra/ffmpeg.h index 4860c002..674e2703 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.h +++ b/cinelerra-5.1/cinelerra/ffmpeg.h @@ -40,12 +40,14 @@ extern "C" { class FFPacket { AVPacket pkt; public: - FFPacket(); - ~FFPacket(); - void init(); operator AVPacket*() { return &pkt; } operator AVPacket&() { return pkt; } AVPacket *operator ->() { return &pkt; } + + void init(); + void finit(); + FFPacket() { init(); } + ~FFPacket() { finit(); } }; class FFrame : public ListItem { diff --git a/cinelerra-5.1/configure b/cinelerra-5.1/configure index 02e4c514..06bbc566 100755 --- a/cinelerra-5.1/configure +++ b/cinelerra-5.1/configure @@ -6,7 +6,7 @@ #edit global_config and set HAVE_var to override probe PROBED="STATIC_LIBRARIES HAVE_VIDEO4LINUX2 HAVE_DVB HAVE_GL" -PROBED="$PROBED HAVE_DL HAVE_NUMA" +PROBED="$PROBED HAVE_DL HAVE_NUMA HAVE_PACTL" if [ $# -gt 0 ]; then if [ "$1" = "reset" ]; then @@ -169,6 +169,7 @@ if [ -x a.out ]; then HAVE_NUMA=y; else HAVE_NUMA=n; fi rm -f a.out conftest.c +if pactl --version >& /dev/null; then HAVE_PACTL=y; else HAVE_PACTL=n; fi # update global_config with probe data diff --git a/cinelerra-5.1/global_config b/cinelerra-5.1/global_config index 43126b32..e25ee315 100644 --- a/cinelerra-5.1/global_config +++ b/cinelerra-5.1/global_config @@ -18,6 +18,7 @@ HAVE_LADSPA := y #HAVE_GL := y #HAVE_DL := y #HAVE_NUMA := y +#HAVE_PACTL := y OBJDIR := $(shell uname -m) -- 2.26.2