X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffmpeg_capture.cpp;h=7bd927801359b5906db8cec4641557c1898a82ed;hb=refs%2Ftags%2F1.7.4;hp=a0904dc3eb2f48881152cce24152274455eb1693;hpb=80a2892bbe07a4e065704830e9e7244d2b1139fa;p=nageru diff --git a/ffmpeg_capture.cpp b/ffmpeg_capture.cpp index a0904dc..7bd9278 100644 --- a/ffmpeg_capture.cpp +++ b/ffmpeg_capture.cpp @@ -282,9 +282,15 @@ void FFmpegCapture::producer_thread_func() pthread_setname_np(pthread_self(), thread_name); while (!producer_thread_should_quit.should_quit()) { - string pathname = search_for_file(filename); - if (filename.empty()) { - fprintf(stderr, "%s not found, sleeping one second and trying again...\n", filename.c_str()); + string filename_copy; + { + lock_guard lock(filename_mu); + filename_copy = filename; + } + + string pathname = search_for_file(filename_copy); + if (pathname.empty()) { + fprintf(stderr, "%s not found, sleeping one second and trying again...\n", filename_copy.c_str()); send_disconnected_frame(); producer_thread_should_quit.sleep_for(seconds(1)); continue; @@ -321,6 +327,7 @@ void FFmpegCapture::send_disconnected_frame() if (pixel_format == bmusb::PixelFormat_8BitBGRA) { video_format.stride = width * 4; video_frame.len = width * height * 4; + memset(video_frame.data, 0, video_frame.len); } else { video_format.stride = width; current_frame_ycbcr_format.luma_coefficients = YCBCR_REC_709; @@ -333,8 +340,9 @@ void FFmpegCapture::send_disconnected_frame() current_frame_ycbcr_format.cr_x_position = 0.0f; current_frame_ycbcr_format.cr_y_position = 0.0f; video_frame.len = width * height * 2; + memset(video_frame.data, 0, width * height); + memset(video_frame.data + width * height, 128, width * height); // Valid for both NV12 and planar. } - memset(video_frame.data, 0, video_frame.len); frame_callback(-1, AVRational{1, TIMEBASE}, -1, AVRational{1, TIMEBASE}, timecode++, video_frame, /*video_offset=*/0, video_format, @@ -743,7 +751,7 @@ void FFmpegCapture::convert_audio(const AVFrame *audio_avframe, FrameAllocator:: } av_opt_set_int(resampler, "in_channel_layout", channel_layout, 0); - av_opt_set_int(resampler, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0); + av_opt_set_int(resampler, "out_channel_layout", AV_CH_LAYOUT_STEREO_DOWNMIX, 0); av_opt_set_int(resampler, "in_sample_rate", av_frame_get_sample_rate(audio_avframe), 0); av_opt_set_int(resampler, "out_sample_rate", OUTPUT_FREQUENCY, 0); av_opt_set_int(resampler, "in_sample_fmt", audio_avframe->format, 0);