fixes, handle when audio codec isn't open in ffmpeg_camera

This commit is contained in:
Isaac Connor 2019-09-13 16:06:25 -04:00
parent 3a5d1ff3ca
commit eafa0da06f
2 changed files with 12 additions and 8 deletions

View File

@ -718,18 +718,19 @@ int zm_resample_audio(
}
#endif
#endif
zm_dump_frame(out_frame, "Out frame after resample delay");
zm_dump_frame(out_frame, "Out frame after resample");
return 1;
}
int zm_resample_get_delay(
#if defined(HAVE_LIBSWRESAMPLE)
SwrContext *resample_ctx,
#else
#if defined(HAVE_LIBAVRESAMPLE)
AVAudioResampleContext *resample_ctx,
AVAudioResampleContext *resample_ctx,
#endif
#endif
int time_base
int time_base
) {
#if defined(HAVE_LIBSWRESAMPLE)
return sws_get_delay(resample_ctx, time_base);

View File

@ -273,9 +273,7 @@ VideoStore::VideoStore(
out_frame = NULL;
#if defined(HAVE_LIBSWRESAMPLE) || defined(HAVE_LIBAVRESAMPLE)
resample_ctx = NULL;
#if defined(HAVE_LIBSWRESAMPLE)
fifo = NULL;
#endif
#endif
video_first_pts = 0;
video_first_dts = 0;
@ -577,11 +575,11 @@ VideoStore::~VideoStore() {
#if defined(HAVE_LIBAVRESAMPLE) || defined(HAVE_LIBSWRESAMPLE)
if ( resample_ctx ) {
#if defined(HAVE_LIBSWRESAMPLE)
if ( fifo ) {
av_audio_fifo_free(fifo);
fifo = NULL;
}
#if defined(HAVE_LIBSWRESAMPLE)
swr_free(&resample_ctx);
#else
#if defined(HAVE_LIBAVRESAMPLE)
@ -636,7 +634,12 @@ bool VideoStore::setup_resampler() {
// codec is already open in ffmpeg_camera
audio_in_ctx = audio_in_stream->codec;
audio_in_codec = reinterpret_cast<const AVCodec *>(audio_in_ctx->codec);
//audio_in_codec = avcodec_find_decoder(audio_in_stream->codec->codec_id);
if ( !audio_in_codec ) {
audio_in_codec = avcodec_find_decoder(audio_in_stream->codec->codec_id);
}
if ( !audio_in_codec ) {
return false;
}
#endif
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
@ -770,13 +773,13 @@ bool VideoStore::setup_resampler() {
return false;
}
#if defined(HAVE_LIBSWRESAMPLE)
if ( !(fifo = av_audio_fifo_alloc(
audio_out_ctx->sample_fmt,
audio_out_ctx->channels, 1)) ) {
Error("Could not allocate FIFO");
return false;
}
#if defined(HAVE_LIBSWRESAMPLE)
resample_ctx = swr_alloc_set_opts(NULL,
audio_out_ctx->channel_layout,
audio_out_ctx->sample_fmt,