Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Apr 25, 2022
1 parent c077990 commit f4d375d
Show file tree
Hide file tree
Showing 30 changed files with 299 additions and 333 deletions.
5 changes: 2 additions & 3 deletions src/common/except.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ struct not_supported : virtual user_error

#define CASPAR_THROW_EXCEPTION(x) \
::boost::throw_exception(::boost::enable_error_info(x) \
<< ::boost::throw_function(BOOST_CURRENT_FUNCTION) \
<< ::boost::throw_file(__FILE__) << ::boost::throw_line((int)__LINE__) \
<< stacktrace_info())
<< ::boost::throw_function(BOOST_CURRENT_FUNCTION) << ::boost::throw_file(__FILE__) \
<< ::boost::throw_line((int)__LINE__) << stacktrace_info())

} // namespace caspar
8 changes: 4 additions & 4 deletions src/common/os/linux/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace caspar {

void set_thread_name(const std::wstring& name) { pthread_setname_np(pthread_self(), u8(name).c_str()); }

void set_thread_realtime_priority() {
pthread_t handle = pthread_self();
int policy;
void set_thread_realtime_priority()
{
pthread_t handle = pthread_self();
int policy;
struct sched_param param;
if (pthread_getschedparam(handle, &policy, &param) != 0)
return;
param.sched_priority = 2;
pthread_setschedparam(handle, SCHED_FIFO, &param);
}


} // namespace caspar
4 changes: 1 addition & 3 deletions src/common/os/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ namespace caspar {

void set_thread_name(const std::wstring& name);
void set_thread_realtime_priority();
}


} // namespace caspar
5 changes: 1 addition & 4 deletions src/common/os/windows/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ inline void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName)

void set_thread_name(const std::wstring& name) { SetThreadName(GetCurrentThreadId(), u8(name).c_str()); }

void set_thread_realtime_priority() {
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
}

void set_thread_realtime_priority() { SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); }

} // namespace caspar
3 changes: 1 addition & 2 deletions src/core/consumer/frame_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ class destroy_consumer_proxy : public frame_consumer

pointer_guard.reset();
counter--;
})
.detach();
}).detach();
}

std::future<bool> send(const_frame frame) override { return consumer_->send(std::move(frame)); }
Expand Down
15 changes: 9 additions & 6 deletions src/core/producer/stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ struct stage::impl : public std::enable_shared_from_this<impl>
if (0 == depth)
routeSources.clear();

if (std::find_if(layerVec.begin(), layerVec.end(), [l](std::pair<int, bool> p) { return p.first == l; }) != layerVec.end()) {
if (std::find_if(layerVec.begin(), layerVec.end(), [l](std::pair<int, bool> p) { return p.first == l; }) !=
layerVec.end()) {
return;
}

Expand All @@ -88,7 +89,8 @@ struct stage::impl : public std::enable_shared_from_this<impl>
layerOK = false;
}

if (std::find_if(layerVec.begin(), layerVec.end(), [l](std::pair<int, bool> p) { return p.first == l; }) == layerVec.end()) {
if (std::find_if(layerVec.begin(), layerVec.end(), [l](std::pair<int, bool> p) { return p.first == l; }) ==
layerVec.end()) {
layerVec.push_back(std::make_pair(l, layerOK));
}
}
Expand Down Expand Up @@ -140,8 +142,9 @@ struct stage::impl : public std::enable_shared_from_this<impl>
auto& layer = p->second;
auto& tween = tweens_[p->first];

layer_frame res = {};
res.foreground = draw_frame::push(l.second ? layer.receive(format_desc, nb_samples) : draw_frame(), tween.fetch());
layer_frame res = {};
res.foreground = draw_frame::push(l.second ? layer.receive(format_desc, nb_samples) : draw_frame(),
tween.fetch());
res.has_background = layer.has_background();
if (std::find(fetch_background.begin(), fetch_background.end(), p->first) !=
fetch_background.end()) {
Expand Down Expand Up @@ -230,8 +233,8 @@ struct stage::impl : public std::enable_shared_from_this<impl>
{
return executor_.begin_invoke([=] { get_layer(index).load(producer, preview, auto_play); });
}
std::future<void> preview(int index)

std::future<void> preview(int index)
{
return executor_.begin_invoke([=] { get_layer(index).preview(); });
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/producer/stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ class stage final

std::future<void> apply_transforms(const std::vector<transform_tuple_t>& transforms);
std::future<void>
apply_transform(int index, const transform_func_t& transform, unsigned int mix_duration, const tweener& tween);
apply_transform(int index, const transform_func_t& transform, unsigned int mix_duration, const tweener& tween);
std::future<void> clear_transforms(int index);
std::future<void> clear_transforms();
std::future<frame_transform> get_current_transform(int index);
std::future<void>
load(int index, const spl::shared_ptr<frame_producer>& producer, bool preview = false, bool auto_play = false);
load(int index, const spl::shared_ptr<frame_producer>& producer, bool preview = false, bool auto_play = false);
std::future<void> preview(int index);
std::future<void> pause(int index);
std::future<void> resume(int index);
Expand Down
1 change: 0 additions & 1 deletion src/core/producer/transition/transition_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class transition_producer : public frame_producer
dst_frame.transform().image_transform.clip_scale[0] = delta;
} else {
dst_frame.transform().image_transform.clip_translation[0] = (1.0 - delta);

}
}

Expand Down
12 changes: 6 additions & 6 deletions src/modules/bluefish/consumer/bluefish_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ struct bluefish_consumer
const int channel_index_;
const configuration config_;

spl::shared_ptr<bvc_wrapper> blue_ = create_blue(config_.device_index);
spl::shared_ptr<bvc_wrapper> blue_ = create_blue(config_.device_index);
spl::shared_ptr<bvc_wrapper> watchdog_bvc_ = create_blue(config_.device_index);

std::mutex exception_mutex_;
std::exception_ptr exception_;

Expand Down Expand Up @@ -239,7 +239,7 @@ struct bluefish_consumer
// Specify the video channel
setup_hardware_output_channel(); // ie stream id

model_name_ = get_card_desc(*blue_.get(), (int)config_.device_index);
model_name_ = get_card_desc(*blue_.get(), (int)config_.device_index);

// disable the video output while we do all the config.
disable_video_output();
Expand Down Expand Up @@ -317,7 +317,7 @@ struct bluefish_consumer
SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST);
#endif
}

configure_watchdog();
enable_video_output();
}
Expand Down Expand Up @@ -382,8 +382,8 @@ struct bluefish_consumer
blue_prop = EPOCH_WATCHDOG_TIMER_SET_MACRO(enum_blue_app_watchdog_timer_start_stop, (unsigned int)0);
blue_->set_card_property32(EPOCH_APP_WATCHDOG_TIMER, blue_prop);
}
// Setting up the watchdog properties

// Setting up the watchdog properties
unsigned int watchdog_timer_gpo_port = 1; // GPO port to use: 0 = none, 1 = port A, 2 = port B
blue_prop =
EPOCH_WATCHDOG_TIMER_SET_MACRO(enum_blue_app_watchdog_enable_gpo_on_active, watchdog_timer_gpo_port);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/decklink/producer/decklink_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ class decklink_producer : public IDeckLinkInputCallback
}

HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, LPVOID*) override { return E_NOINTERFACE; }
ULONG STDMETHODCALLTYPE AddRef() override { return 1; }
ULONG STDMETHODCALLTYPE Release() override { return 1; }
ULONG STDMETHODCALLTYPE AddRef() override { return 1; }
ULONG STDMETHODCALLTYPE Release() override { return 1; }

HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents notificationEvents,
IDeckLinkDisplayMode* newDisplayMode,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/ffmpeg/producer/av_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <common/param.h>
#include <common/scope_exit.h>

#include <boost/filesystem.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/filesystem.hpp>

#include <set>

Expand Down
2 changes: 1 addition & 1 deletion src/modules/ffmpeg/producer/av_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include <tbb/concurrent_queue.h>

#include <boost/thread.hpp>
#include <boost/optional.hpp>
#include <boost/thread.hpp>

struct AVPacket;
struct AVFormatContext;
Expand Down
51 changes: 24 additions & 27 deletions src/modules/ffmpeg/producer/av_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#include <common/diagnostics/graph.h>
#include <common/env.h>
#include <common/except.h>
#include <common/executor.h>
#include <common/os/thread.h>
#include <common/scope_exit.h>
#include <common/timer.h>
#include <common/executor.h>

#include <core/frame/draw_frame.h>
#include <core/frame/frame_factory.h>
Expand Down Expand Up @@ -77,23 +77,23 @@ class Decoder
Decoder(const Decoder&) = delete;
Decoder& operator=(const Decoder&) = delete;

AVStream* st = nullptr;
int64_t next_pts = AV_NOPTS_VALUE;
std::atomic<bool> eof = { false };
AVStream* st = nullptr;
int64_t next_pts = AV_NOPTS_VALUE;
std::atomic<bool> eof = {false};

std::queue<std::shared_ptr<AVPacket>> input;
mutable boost::mutex input_mutex;
boost::condition_variable input_cond;
int input_capacity = 2;
mutable boost::mutex input_mutex;
boost::condition_variable input_cond;
int input_capacity = 2;

std::queue<std::shared_ptr<AVFrame>> output;
mutable boost::mutex output_mutex;
boost::condition_variable output_cond;
int output_capacity = 8;
mutable boost::mutex output_mutex;
boost::condition_variable output_cond;
int output_capacity = 8;

boost::thread thread;

public:
public:
std::shared_ptr<AVCodecContext> ctx;

Decoder() = default;
Expand Down Expand Up @@ -140,12 +140,11 @@ class Decoder

FF(avcodec_open2(ctx.get(), codec, nullptr));

thread = boost::thread([=]()
{
thread = boost::thread([=]() {
try {
while (!thread.interruption_requested()) {
auto av_frame = alloc_frame();
auto ret = avcodec_receive_frame(ctx.get(), av_frame.get());
auto ret = avcodec_receive_frame(ctx.get(), av_frame.get());

if (ret == AVERROR(EAGAIN)) {
std::shared_ptr<AVPacket> packet;
Expand All @@ -159,8 +158,8 @@ class Decoder
} else if (ret == AVERROR_EOF) {
avcodec_flush_buffers(ctx.get());
av_frame->pts = next_pts;
next_pts = AV_NOPTS_VALUE;
eof = true;
next_pts = AV_NOPTS_VALUE;
eof = true;

{
boost::unique_lock<boost::mutex> lock(output_mutex);
Expand All @@ -181,13 +180,13 @@ class Decoder
auto duration_pts = av_frame->pkt_duration;
if (duration_pts <= 0) {
if (ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
const auto ticks =
av_stream_get_parser(st) ? av_stream_get_parser(st)->repeat_pict + 1 : ctx->ticks_per_frame;
duration_pts = static_cast<int64_t>(AV_TIME_BASE) * ctx->framerate.den * ticks /
ctx->framerate.num / ctx->ticks_per_frame;
duration_pts = av_rescale_q(duration_pts, { 1, AV_TIME_BASE }, st->time_base);
const auto ticks = av_stream_get_parser(st) ? av_stream_get_parser(st)->repeat_pict + 1
: ctx->ticks_per_frame;
duration_pts = static_cast<int64_t>(AV_TIME_BASE) * ctx->framerate.den * ticks /
ctx->framerate.num / ctx->ticks_per_frame;
duration_pts = av_rescale_q(duration_pts, {1, AV_TIME_BASE}, st->time_base);
} else if (ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
duration_pts = av_rescale_q(av_frame->nb_samples, { 1, ctx->sample_rate }, st->time_base);
duration_pts = av_rescale_q(av_frame->nb_samples, {1, ctx->sample_rate}, st->time_base);
}
}

Expand Down Expand Up @@ -570,7 +569,7 @@ struct Filter

auto av_frame = alloc_frame();
auto ret = nb_samples >= 0 ? av_buffersink_get_samples(sink, av_frame.get(), nb_samples)
: av_buffersink_get_frame(sink, av_frame.get());
: av_buffersink_get_frame(sink, av_frame.get());

if (ret == AVERROR(EAGAIN)) {
return false;
Expand Down Expand Up @@ -802,13 +801,12 @@ struct AVProducer::Impl

std::vector<std::future<bool>> futures;


if (!video_filter_.frame) {
futures.push_back(video_executor_->begin_invoke([&]() { return video_filter_(); }));
}

if (!audio_filter_.frame) {
futures.push_back(audio_executor_->begin_invoke([&]() { return audio_filter_(audio_cadence[0]); }));
futures.push_back(audio_executor_->begin_invoke([&]() { return audio_filter_(audio_cadence[0]); }));
}

for (auto& future : futures) {
Expand Down Expand Up @@ -1027,8 +1025,7 @@ struct AVProducer::Impl
private:
bool want_packet()
{
return std::any_of(
decoders_.begin(), decoders_.end(), [](auto& p) { return p.second.want_packet(); });
return std::any_of(decoders_.begin(), decoders_.end(), [](auto& p) { return p.second.want_packet(); });
}

bool schedule()
Expand Down
30 changes: 14 additions & 16 deletions src/modules/ffmpeg/producer/ffmpeg_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ struct ffmpeg_producer : public core::frame_producer
} catch (...) {
CASPAR_LOG_CURRENT_EXCEPTION();
}
})
.detach();
}).detach();
}

// frame_producer
Expand Down Expand Up @@ -196,18 +195,9 @@ struct ffmpeg_producer : public core::frame_producer

boost::tribool has_valid_extension(const std::wstring& filename)
{
static const auto invalid_exts = {L".tga",
L".tiff",
L".tif",
L".jp2",
L".jpx",
L".j2k",
L".j2c",
L".swf",
L".ct",
L".html",
L".htm"};
static const auto valid_exts = {L".m2t", L".m2ts", L".mov", L".mp4", L".dv", L".flv", L".mpg", L".dnxhd",
static const auto invalid_exts = {
L".tga", L".tiff", L".tif", L".jp2", L".jpx", L".j2k", L".j2c", L".swf", L".ct", L".html", L".htm"};
static const auto valid_exts = {L".m2t", L".m2ts", L".mov", L".mp4", L".dv", L".flv", L".mpg", L".dnxhd",
L".h264", L".prores", L".mkv", L".mxf", L".ts", L".mp3", L".wav", L".wma",
L".nut", L".flac", L".opus", L".ogg", L".ogv", L".oga", L".webm", L".webp"};

Expand Down Expand Up @@ -351,8 +341,16 @@ spl::shared_ptr<core::frame_producer> create_producer(const core::frame_producer
auto afilter = boost::to_lower_copy(get_param(L"AF", params, get_param(L"FILTER", params, L"")));

try {
auto producer = spl::make_shared<ffmpeg_producer>(
dependencies.frame_factory, dependencies.format_desc, name, path, vfilter, afilter, start, duration, loop, seekable);
auto producer = spl::make_shared<ffmpeg_producer>(dependencies.frame_factory,
dependencies.format_desc,
name,
path,
vfilter,
afilter,
start,
duration,
loop,
seekable);
return core::create_destroy_proxy(std::move(producer));
} catch (...) {
CASPAR_LOG_CURRENT_EXCEPTION();
Expand Down
6 changes: 2 additions & 4 deletions src/modules/ffmpeg/util/av_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ struct ffmpeg_error_t : virtual caspar_exception

using ffmpeg_errn_info = boost::error_info<struct tag_ffmpeg_errn_info, int>;

}
} // namespace caspar::ffmpeg
}} // namespace caspar::ffmpeg

#define THROW_ON_ERROR_STR_(call) #call
#define THROW_ON_ERROR_STR(call) THROW_ON_ERROR_STR_(call)

#define FF_RET(ret, func) \
if (ret < 0) { \
CASPAR_THROW_EXCEPTION(caspar::ffmpeg::ffmpeg_error_t() \
<< boost::errinfo_api_function(func) \
<< caspar::ffmpeg::ffmpeg_errn_info(ret) \
<< boost::errinfo_api_function(func) << caspar::ffmpeg::ffmpeg_errn_info(ret) \
<< boost::errinfo_errno(AVUNERROR(ret))); \
}

Expand Down
Loading

0 comments on commit f4d375d

Please sign in to comment.