diff --git a/src/modules/ffmpeg/util/audio_resampler.cpp b/src/modules/ffmpeg/util/audio_resampler.cpp index e7f07203d1..ffd6e25d80 100644 --- a/src/modules/ffmpeg/util/audio_resampler.cpp +++ b/src/modules/ffmpeg/util/audio_resampler.cpp @@ -8,31 +8,31 @@ extern "C" { namespace caspar::ffmpeg { - AudioResampler::AudioResampler(int64_t sample_rate, AVSampleFormat in_sample_fmt) - : ctx(std::shared_ptr(swr_alloc_set_opts(nullptr, - AV_CH_LAYOUT_7POINT1, - AV_SAMPLE_FMT_S32, - sample_rate, - AV_CH_LAYOUT_7POINT1, - in_sample_fmt, - sample_rate, - 0, - nullptr), - [](SwrContext* ptr) { swr_free(&ptr); })) - { - if (!ctx) - FF_RET(AVERROR(ENOMEM), "swr_alloc_set_opts"); +AudioResampler::AudioResampler(int64_t sample_rate, AVSampleFormat in_sample_fmt) + : ctx(std::shared_ptr(swr_alloc_set_opts(nullptr, + AV_CH_LAYOUT_7POINT1, + AV_SAMPLE_FMT_S32, + sample_rate, + AV_CH_LAYOUT_7POINT1, + in_sample_fmt, + sample_rate, + 0, + nullptr), + [](SwrContext* ptr) { swr_free(&ptr); })) +{ + if (!ctx) + FF_RET(AVERROR(ENOMEM), "swr_alloc_set_opts"); - FF_RET(swr_init(ctx.get()), "swr_init"); - } + FF_RET(swr_init(ctx.get()), "swr_init"); +} - caspar::array AudioResampler::convert(int frames, const void** src) - { - auto result = caspar::array(frames * 8 * sizeof(int32_t)); - auto ptr = result.data(); - auto ret = swr_convert(ctx.get(), (uint8_t**)&ptr, frames, reinterpret_cast(src), frames); +caspar::array AudioResampler::convert(int frames, const void** src) +{ + auto result = caspar::array(frames * 8 * sizeof(int32_t)); + auto ptr = result.data(); + auto ret = swr_convert(ctx.get(), (uint8_t**)&ptr, frames, reinterpret_cast(src), frames); - return result; - } + return result; +} - }; // namespace caspar::ffmpeg \ No newline at end of file +}; // namespace caspar::ffmpeg \ No newline at end of file diff --git a/src/modules/ffmpeg/util/audio_resampler.h b/src/modules/ffmpeg/util/audio_resampler.h index a7a6316d7d..3f91b44cef 100644 --- a/src/modules/ffmpeg/util/audio_resampler.h +++ b/src/modules/ffmpeg/util/audio_resampler.h @@ -1,6 +1,8 @@ #include #include +#pragma once + extern "C" { #include } @@ -9,17 +11,17 @@ struct SwrContext; namespace caspar::ffmpeg { - class AudioResampler - { - std::shared_ptr ctx; +class AudioResampler +{ + std::shared_ptr ctx; - public: - AudioResampler(int64_t sample_rate, AVSampleFormat in_sample_fmt); + public: + AudioResampler(int64_t sample_rate, AVSampleFormat in_sample_fmt); - AudioResampler(const AudioResampler&) = delete; - AudioResampler& operator=(const AudioResampler&) = delete; + AudioResampler(const AudioResampler&) = delete; + AudioResampler& operator=(const AudioResampler&) = delete; - caspar::array convert(int frames, const void** src); - }; + caspar::array convert(int frames, const void** src); +}; - }; // namespace caspar::ffmpeg \ No newline at end of file +}; // namespace caspar::ffmpeg \ No newline at end of file diff --git a/src/modules/html/producer/html_producer.cpp b/src/modules/html/producer/html_producer.cpp index dfffb712ab..f5b42bd61b 100644 --- a/src/modules/html/producer/html_producer.cpp +++ b/src/modules/html/producer/html_producer.cpp @@ -69,27 +69,28 @@ namespace caspar { namespace html { inline std::int_least64_t now() { return std::chrono::duration_cast( - std::chrono::high_resolution_clock::now().time_since_epoch()) - .count(); + std::chrono::high_resolution_clock::now().time_since_epoch()) + .count(); } struct presentation_frame { std::int_least64_t timestamp = now(); - core::draw_frame frame = core::draw_frame::empty(); - bool has_video = false; - bool has_audio = false; + core::draw_frame frame = core::draw_frame::empty(); + bool has_video = false; + bool has_audio = false; explicit presentation_frame(core::draw_frame video = {}) { if (video) { - frame = std::move(video); + frame = std::move(video); has_video = true; } } - presentation_frame(presentation_frame&& other) - noexcept : timestamp(other.timestamp),frame(std::move(other.frame)) + presentation_frame(presentation_frame&& other) noexcept + : timestamp(other.timestamp) + , frame(std::move(other.frame)) { } @@ -105,30 +106,33 @@ struct presentation_frame ~presentation_frame() {} - void add_audio(core::mutable_frame audio) { - if (has_audio) return; + void add_audio(core::mutable_frame audio) + { + if (has_audio) + return; has_audio = true; if (frame) { - frame = core::draw_frame::over(frame, core::draw_frame(std::move (audio))); + frame = core::draw_frame::over(frame, core::draw_frame(std::move(audio))); } else { - frame = core::draw_frame(std::move (audio)); + frame = core::draw_frame(std::move(audio)); } } - void add_video(core::draw_frame video) { - if (has_video) return; + void add_video(core::draw_frame video) + { + if (has_video) + return; has_video = true; if (frame) { - frame = core::draw_frame::over(frame, std::move (video)); + frame = core::draw_frame::over(frame, std::move(video)); } else { - frame = std::move (video); + frame = std::move(video); } } }; - class html_client : public CefClient , public CefRenderHandler @@ -146,16 +150,16 @@ class html_client caspar::timer paint_timer_; caspar::timer test_timer_; - spl::shared_ptr frame_factory_; - core::video_format_desc format_desc_; - bool gpu_enabled_; - tbb::concurrent_queue javascript_before_load_; - std::atomic loaded_; - std::queue frames_; - core::draw_frame last_generated_frame_; - mutable std::mutex frames_mutex_; - const size_t frames_max_size_ = 4; - std::atomic closing_; + spl::shared_ptr frame_factory_; + core::video_format_desc format_desc_; + bool gpu_enabled_; + tbb::concurrent_queue javascript_before_load_; + std::atomic loaded_; + std::queue frames_; + core::draw_frame last_generated_frame_; + mutable std::mutex frames_mutex_; + const size_t frames_max_size_ = 4; + std::atomic closing_; std::unique_ptr audioResampler_; @@ -315,8 +319,6 @@ class html_client } private: - - void GetViewRect(CefRefPtr browser, CefRect& rect) override { CASPAR_ASSERT(CefCurrentlyOn(TID_UI)); @@ -368,7 +370,7 @@ class html_client std::lock_guard lock(frames_mutex_); core::draw_frame new_frame = core::draw_frame(std::move(frame)); - last_generated_frame_ = new_frame; + last_generated_frame_ = new_frame; frames_.push(presentation_frame(std::move(new_frame))); while (frames_.size() > 4) { @@ -421,7 +423,7 @@ class html_client CefRefPtr GetRenderHandler() override { return this; } - CefRefPtr GetAudioHandler() override { return this; } + CefRefPtr GetAudioHandler() override { return this; } CefRefPtr GetLifeSpanHandler() override { return this; } @@ -483,9 +485,10 @@ class html_client } void OnAudioStreamPacket(CefRefPtr browser, const float** data, int samples, int64_t pts) override { - if (!audioResampler_) return; + if (!audioResampler_) + return; - auto audio = audioResampler_->convert(samples, reinterpret_cast(data)); + auto audio = audioResampler_->convert(samples, reinterpret_cast(data)); auto audio_frame = core::mutable_frame(this, {}, std::move(audio), core::pixel_format_desc()); {