If there is a failure when decoding due to lack of support for the codec profile, re-init without hwaccel

pull/2975/head
Isaac Connor 2020-05-12 15:10:08 -04:00
parent e40c3d8487
commit 7e80b33ee0
2 changed files with 9 additions and 2 deletions

View File

@ -148,6 +148,7 @@ FfmpegCamera::FfmpegCamera(
have_video_keyframe = false; have_video_keyframe = false;
packetqueue = NULL; packetqueue = NULL;
error_count = 0; error_count = 0;
use_hwaccel = true;
#if HAVE_LIBAVUTIL_HWCONTEXT_H #if HAVE_LIBAVUTIL_HWCONTEXT_H
hwFrame = NULL; hwFrame = NULL;
hw_device_ctx = NULL; hw_device_ctx = NULL;
@ -471,7 +472,7 @@ int FfmpegCamera::OpenFfmpeg() {
zm_dump_stream_format(mFormatContext, mVideoStreamId, 0, 0); zm_dump_stream_format(mFormatContext, mVideoStreamId, 0, 0);
if ( hwaccel_name != "" ) { if ( use_hwaccel && (hwaccel_name != "") ) {
#if HAVE_LIBAVUTIL_HWCONTEXT_H #if HAVE_LIBAVUTIL_HWCONTEXT_H
// 3.2 doesn't seem to have all the bits in place, so let's require 3.3 and up // 3.2 doesn't seem to have all the bits in place, so let's require 3.3 and up
#if LIBAVCODEC_VERSION_CHECK(57, 89, 0, 89, 0) #if LIBAVCODEC_VERSION_CHECK(57, 89, 0, 89, 0)
@ -503,8 +504,9 @@ int FfmpegCamera::OpenFfmpeg() {
hw_pix_fmt = config->pix_fmt; hw_pix_fmt = config->pix_fmt;
break; break;
} else { } else {
Debug(1, "decoder %s hwConfig doesn't match our type: %s, pix_fmt %s.", Debug(1, "decoder %s hwConfig doesn't match our type: %s != %s, pix_fmt %s.",
mVideoCodec->name, mVideoCodec->name,
av_hwdevice_get_type_name(type),
av_hwdevice_get_type_name(config->device_type), av_hwdevice_get_type_name(config->device_type),
av_get_pix_fmt_name(config->pix_fmt) av_get_pix_fmt_name(config->pix_fmt)
); );
@ -973,6 +975,10 @@ int FfmpegCamera::CaptureAndRecord(
Error("Error count over 100, going to close and re-open stream"); Error("Error count over 100, going to close and re-open stream");
return -1; return -1;
} }
if ( (ret == AVERROR_INVALIDDATA ) && (hw_pix_fmt != AV_PIX_FMT_NONE) ) {
use_hwaccel = false;
return -1;
}
} }
zm_av_packet_unref(&packet); zm_av_packet_unref(&packet);
continue; continue;

View File

@ -60,6 +60,7 @@ class FfmpegCamera : public Camera {
AVFrame *input_frame; // Use to point to mRawFrame or hwFrame; AVFrame *input_frame; // Use to point to mRawFrame or hwFrame;
AVFrame *hwFrame; // Will also be used to indicate if hwaccel is in use AVFrame *hwFrame; // Will also be used to indicate if hwaccel is in use
bool use_hwaccel; //will default to on if hwaccel specified, will get turned off if there is a failure
#if HAVE_LIBAVUTIL_HWCONTEXT_H #if HAVE_LIBAVUTIL_HWCONTEXT_H
AVBufferRef *hw_device_ctx = NULL; AVBufferRef *hw_device_ctx = NULL;
#endif #endif