diff options
-rw-r--r-- | contrib/libsamplerate/module.defs | 18 | ||||
-rw-r--r-- | contrib/libsamplerate/module.rules | 2 | ||||
-rw-r--r-- | gtk/configure.ac | 2 | ||||
-rw-r--r-- | libhb/audio_resample.c | 7 | ||||
-rw-r--r-- | libhb/module.defs | 2 | ||||
-rw-r--r-- | libhb/sync.c | 104 | ||||
-rw-r--r-- | make/include/main.defs | 1 | ||||
-rw-r--r-- | test/module.defs | 2 |
8 files changed, 50 insertions, 88 deletions
diff --git a/contrib/libsamplerate/module.defs b/contrib/libsamplerate/module.defs deleted file mode 100644 index f5d6ac01a..000000000 --- a/contrib/libsamplerate/module.defs +++ /dev/null @@ -1,18 +0,0 @@ -$(eval $(call import.MODULE.defs,LIBSAMPLERATE,libsamplerate)) -$(eval $(call import.CONTRIB.defs,LIBSAMPLERATE)) - -# libsamplerate 0.1.9-49-ga2eb281 -LIBSAMPLERATE.FETCH.url = https://download.handbrake.fr/handbrake/contrib/libsamplerate-a2eb2814150a4ada0b49ea3cc5e51170572fc606.tar.gz -LIBSAMPLERATE.FETCH.url += https://github.com/erikd/libsamplerate/archive/a2eb2814150a4ada0b49ea3cc5e51170572fc606.tar.gz -LIBSAMPLERATE.FETCH.sha256 = b8228e8bdbd754e95146745f85e37a25fb43d626cca7f785f3fd8e0a1c1f5f22 -LIBSAMPLERATE.EXTRACT.basename = libsamplerate-a2eb2814150a4ada0b49ea3cc5e51170572fc606.tar.gz -LIBSAMPLERATE.EXTRACT.tarbase = libsamplerate-a2eb2814150a4ada0b49ea3cc5e51170572fc606 - -LIBSAMPLERATE.CONFIGURE.bootstrap = rm -fr aclocal.m4 autom4te.cache configure; autoreconf -fiv; - -# Disable to avoid Carbon.h dependency on OSX -LIBSAMPLERATE.CONFIGURE.extra = --disable-sndfile - -ifeq (1-msys,$(HOST.cross)-$(BUILD.system)) - LIBSAMPLERATE.CONFIGURE.args.build = --build=$(BUILD.machine)-unknown-linux-gnu -endif diff --git a/contrib/libsamplerate/module.rules b/contrib/libsamplerate/module.rules deleted file mode 100644 index ef633856c..000000000 --- a/contrib/libsamplerate/module.rules +++ /dev/null @@ -1,2 +0,0 @@ -$(eval $(call import.MODULE.rules,LIBSAMPLERATE)) -$(eval $(call import.CONTRIB.rules,LIBSAMPLERATE)) diff --git a/gtk/configure.ac b/gtk/configure.ac index e282b1d56..dc3a7dc26 100644 --- a/gtk/configure.ac +++ b/gtk/configure.ac @@ -192,7 +192,7 @@ PKG_CHECK_MODULES(GHB, [$GHB_PACKAGES]) GHB_CFLAGS="$HBINC $GHB_CFLAGS" -HB_LIBS="-lhandbrake -lavformat -lavfilter -lavcodec -lavutil -lswresample -lpostproc -ldvdnav -ldvdread -lmp3lame -lvorbis -lvorbisenc -logg -lsamplerate -lx264 -lswscale -ltheoraenc -ltheoradec -lvpx -lz -lbz2 -lbluray -lass -lfontconfig -lfreetype -lxml2 -ljansson -lopus -lspeex -llzma" +HB_LIBS="-lhandbrake -lavformat -lavfilter -lavcodec -lavutil -lswresample -lpostproc -ldvdnav -ldvdread -lmp3lame -lvorbis -lvorbisenc -logg -lx264 -lswscale -ltheoraenc -ltheoradec -lvpx -lz -lbz2 -lbluray -lass -lfontconfig -lfreetype -lxml2 -ljansson -lopus -lspeex -llzma" if test "x$use_fdk_aac" = "xyes" ; then HB_LIBS="$HB_LIBS -lfdk-aac" diff --git a/libhb/audio_resample.c b/libhb/audio_resample.c index 165368395..d415b574a 100644 --- a/libhb/audio_resample.c +++ b/libhb/audio_resample.c @@ -274,8 +274,8 @@ hb_buffer_t* hb_audio_resample(hb_audio_resample_t *resample, if (resample->resample_needed) { - out_samples = (nsamples + 1) * resample->out.sample_rate / - resample->in.sample_rate; + out_samples = nsamples * resample->out.sample_rate / + resample->in.sample_rate + 1; out_size = av_samples_get_buffer_size(NULL, resample->out.channels, out_samples, resample->out.sample_fmt, 0); @@ -286,7 +286,9 @@ hb_buffer_t* hb_audio_resample(hb_audio_resample_t *resample, if (out_samples <= 0) { if (out_samples < 0) + { hb_log("hb_audio_resample: swr_convert() failed"); + } // don't send empty buffers downstream (EOF) hb_buffer_close(&out); return NULL; @@ -322,6 +324,7 @@ hb_buffer_t* hb_audio_resample(hb_audio_resample_t *resample, } out->size = out_samples * sample_size; } + out->s.duration = 90000. * out_samples / resample->out.sample_rate; return out; } diff --git a/libhb/module.defs b/libhb/module.defs index c7321fffc..e76358f39 100644 --- a/libhb/module.defs +++ b/libhb/module.defs @@ -102,7 +102,7 @@ LIBHB.lib = $(LIBHB.build/)hb.lib LIBHB.dll.libs = $(foreach n, \ ass avformat avfilter avcodec avutil swresample postproc dvdnav dvdread \ - freetype mp3lame samplerate swscale vpx theora vorbis vorbisenc ogg \ + freetype mp3lame swscale vpx theora vorbis vorbisenc ogg \ x264 xml2 bluray jansson harfbuzz opus speex, \ $(CONTRIB.build/)lib/lib$(n).a ) diff --git a/libhb/sync.c b/libhb/sync.c index 56edd2ba4..5ff7f1e17 100644 --- a/libhb/sync.c +++ b/libhb/sync.c @@ -10,7 +10,7 @@ #include "hb.h" #include "hbffmpeg.h" #include <stdio.h> -#include "samplerate.h" +#include "audio_resample.h" #define SYNC_MAX_VIDEO_QUEUE_LEN 40 #define SYNC_MIN_VIDEO_QUEUE_LEN 20 @@ -121,16 +121,12 @@ typedef struct // Audio stream context struct { - hb_audio_t * audio; + hb_audio_t * audio; // Audio filter settings // Samplerate conversion - struct - { - SRC_STATE * ctx; - SRC_DATA pkt; - } src; - double gain_factor; + hb_audio_resample_t * resample; + double gain_factor; } audio; // Subtitle stream context @@ -2245,13 +2241,24 @@ static int InitAudio( sync_common_t * common, int index ) if (!(audio->config.out.codec & HB_ACODEC_PASS_FLAG) && audio->config.in.samplerate != audio->config.out.samplerate) { - /* Initialize libsamplerate */ - int error; - pv->stream->audio.src.ctx = src_new(SRC_SINC_MEDIUM_QUALITY, - hb_mixdown_get_discrete_channel_count(audio->config.out.mixdown), - &error); - if (pv->stream->audio.src.ctx == NULL) goto fail; - pv->stream->audio.src.pkt.end_of_input = 0; + /* Initialize samplerate conversion */ + pv->stream->audio.resample = + hb_audio_resample_init(AV_SAMPLE_FMT_FLT, + audio->config.out.samplerate, + audio->config.out.mixdown, + audio->config.out.normalize_mix_level); + if (pv->stream->audio.resample == NULL) + { + hb_error("sync: audio 0x%x resample init failed", audio->id); + goto fail; + } + hb_audio_resample_set_sample_rate(pv->stream->audio.resample, + audio->config.in.samplerate); + if (hb_audio_resample_update(pv->stream->audio.resample)) + { + hb_error("sync: audio 0x%x resample update failed", audio->id); + goto fail; + } } pv->stream->audio.gain_factor = pow(10, audio->config.out.gain / 20); @@ -2265,9 +2272,9 @@ fail: { if (pv->stream != NULL) { - if (pv->stream->audio.src.ctx) + if (pv->stream->audio.resample) { - src_delete(pv->stream->audio.src.ctx); + hb_audio_resample_free(pv->stream->audio.resample); } hb_list_close(&pv->stream->delta_list); hb_list_close(&pv->stream->in_queue); @@ -3047,9 +3054,9 @@ static void syncAudioClose( hb_work_object_t * w ) } // Free samplerate conversion context - if (pv->stream->audio.src.ctx) + if (pv->stream->audio.resample) { - src_delete(pv->stream->audio.src.ctx); + hb_audio_resample_free(pv->stream->audio.resample); } sync_delta_t * delta; @@ -3136,54 +3143,27 @@ static hb_buffer_t * FilterAudioFrame( sync_stream_t * stream, // Audio is not passthru. Check if we need to modify the audio // in any way. - if (stream->audio.src.ctx != NULL) + if (stream->audio.resample != NULL) { /* do sample rate conversion */ - int count_in, count_out; - hb_buffer_t * buf_raw = buf; - int sample_size = hb_mixdown_get_discrete_channel_count( - audio->config.out.mixdown ) * sizeof( float ); - - count_in = buf_raw->size / sample_size; - /* - * When using stupid rates like 44.1 there will always be some - * truncation error. E.g., a 1536 sample AC3 frame will turn into a - * 1536*44.1/48.0 = 1411.2 sample frame. If we just truncate the .2 - * the error will build up over time and eventually the audio will - * substantially lag the video. libsamplerate will keep track of the - * fractional sample & give it to us when appropriate if we give it - * an extra sample of space in the output buffer. - */ - count_out = (buf->s.duration * audio->config.out.samplerate) / - 90000 + 1; - - stream->audio.src.pkt.input_frames = count_in; - stream->audio.src.pkt.output_frames = count_out; - stream->audio.src.pkt.src_ratio = - (double)audio->config.out.samplerate / - audio->config.in.samplerate; - - buf = hb_buffer_init( count_out * sample_size ); - buf->s = buf_raw->s; - stream->audio.src.pkt.data_in = (float *) buf_raw->data; - stream->audio.src.pkt.data_out = (float *) buf->data; - if (src_process(stream->audio.src.ctx, &stream->audio.src.pkt)) - { - /* XXX If this happens, we're screwed */ - hb_error("sync: audio 0x%x src_process failed", audio->id); - } - hb_buffer_close(&buf_raw); - - if (stream->audio.src.pkt.output_frames_gen <= 0) + hb_buffer_t * out; + int nsamples, sample_size; + + sample_size = hb_mixdown_get_discrete_channel_count( + audio->config.out.mixdown ) * sizeof( float ); + + nsamples = buf->size / sample_size; + out = hb_audio_resample(stream->audio.resample, + (const uint8_t **)&buf->data, + nsamples); + hb_buffer_close(&buf); + if (out == NULL) { - hb_buffer_close(&buf); return NULL; } - buf->size = stream->audio.src.pkt.output_frames_gen * sample_size; - buf->s.duration = 90000. * stream->audio.src.pkt.output_frames_gen / - audio->config.out.samplerate; - buf->s.start = stream->next_pts; - buf->s.stop = stream->next_pts + buf->s.duration; + out->s.start = stream->next_pts; + out->s.stop = stream->next_pts + out->s.duration; + buf = out; } if (audio->config.out.gain > 0.0) { diff --git a/make/include/main.defs b/make/include/main.defs index 380362d6e..b11d00d28 100644 --- a/make/include/main.defs +++ b/make/include/main.defs @@ -24,7 +24,6 @@ ifneq (,$(filter $(HOST.system),darwin cygwin mingw)) MODULES += contrib/libopus MODULES += contrib/libspeex MODULES += contrib/libtheora - MODULES += contrib/libsamplerate MODULES += contrib/lame MODULES += contrib/x264 MODULES += contrib/jansson diff --git a/test/module.defs b/test/module.defs index db2ec169a..22000f73c 100644 --- a/test/module.defs +++ b/test/module.defs @@ -16,7 +16,7 @@ TEST.libs = $(LIBHB.a) TEST.GCC.l = \ ass avformat avfilter avcodec avutil swresample postproc mp3lame dvdnav \ dvdread fribidi \ - samplerate swscale vpx theoraenc theoradec vorbis vorbisenc ogg x264 \ + swscale vpx theoraenc theoradec vorbis vorbisenc ogg x264 \ bluray freetype xml2 bz2 z jansson harfbuzz opus speex lzma ifeq (,$(filter $(HOST.system),darwin cygwin mingw)) |