}\r
\r
if(!sws_device) \r
- BOOST_THROW_EXCEPTION(operation_failed() << msg_info("Could not create software scaling device.") << boost::errinfo_api_function("sws_getContext")); \r
+ CASPAR_THROW_EXCEPTION(operation_failed() << msg_info("Could not create software scaling device.") << boost::errinfo_api_function("sws_getContext")); \r
\r
auto dest_frame = spl::make_shared<buffer>(width*height*4);\r
temp_buffers_.push(dest_frame);\r
unbind();\r
\r
if(!pbo_)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer."));\r
\r
//CASPAR_LOG(trace) << "[buffer] [" << ++(usage_ == buffer::usage::write_only ? g_w_total_count : g_r_total_count) << L"] allocated size:" << size_ << " usage: " << (usage == buffer::usage::write_only ? "write_only" : "read_only");\r
} \r
\r
GL(glBindBuffer(target_, 0));\r
if(!data_)\r
- BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to map target OpenGL Pixel Buffer Object."));\r
+ CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to map target OpenGL Pixel Buffer Object."));\r
\r
return data_;\r
}\r
device_->SetActive(true); \r
\r
if (glewInit() != GLEW_OK)\r
- BOOST_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to initialize GLEW."));\r
+ CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to initialize GLEW."));\r
\r
if(!GLEW_VERSION_3_0)\r
- BOOST_THROW_EXCEPTION(not_supported() << msg_info("Your graphics card does not meet the minimum hardware requirements since it does not support OpenGL 3.0 or higher."));\r
+ CASPAR_THROW_EXCEPTION(not_supported() << msg_info("Your graphics card does not meet the minimum hardware requirements since it does not support OpenGL 3.0 or higher."));\r
\r
glGenFramebuffers(1, &fbo_); \r
glBindFramebuffer(GL_FRAMEBUFFER, fbo_);\r
auto ctx2 = wglGetCurrentContext();\r
\r
if(!wglShareLists(ctx1, ctx2))\r
- BOOST_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to share OpenGL devices."));\r
+ CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to share OpenGL devices."));\r
});\r
\r
render_executor_.invoke([=]\r
CASPAR_VERIFY(width > 0 && height > 0);\r
\r
if(!render_executor_.is_current())\r
- BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Operation only valid in an OpenGL Context."));\r
+ CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Operation only valid in an OpenGL Context."));\r
\r
auto pool = &device_pools_[stride-1][((width << 16) & 0xFFFF0000) | (height & 0x0000FFFF)];\r
\r
boost::unique_future<array<const std::uint8_t>> copy_async(const spl::shared_ptr<texture>& source)\r
{\r
if(!render_executor_.is_current())\r
- BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Operation only valid in an OpenGL Context."));\r
+ CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Operation only valid in an OpenGL Context."));\r
\r
auto buffer = create_buffer(source->size(), buffer::usage::read_only); \r
source->copy_to(*buffer); \r
GL(glDeleteObjectARB(vertex_shader));\r
std::stringstream str;\r
str << "Failed to compile vertex shader:" << std::endl << info << std::endl;\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(str.str()));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(str.str()));\r
}\r
\r
const char* fragment_source = fragment_source_str.c_str();\r
GL(glDeleteObjectARB(fragmemt_shader));\r
std::stringstream str;\r
str << "Failed to compile fragment shader:" << std::endl << info << std::endl;\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(str.str()));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(str.str()));\r
}\r
\r
program_ = glCreateProgramObjectARB();\r
GL(glDeleteObjectARB(program_));\r
std::stringstream str;\r
str << "Failed to link shader program:" << std::endl << info << std::endl;\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(str.str()));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(str.str()));\r
}\r
GL(glUseProgramObjectARB(program_));\r
}\r
void check_is_configured()\r
{\r
if(pt.empty())\r
- BOOST_THROW_EXCEPTION(invalid_operation() << msg_info(L"Enviroment properties has not been configured"));\r
+ CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info(L"Enviroment properties has not been configured"));\r
}\r
\r
void configure(const std::wstring& filename)\r
\r
#include "utf.h"\r
\r
+#include "log.h"\r
+\r
#include <exception>\r
#include <boost/exception/all.hpp>\r
#include <boost/exception/error_info.hpp>\r
typedef boost::error_info<struct tag_arg_name_info, std::string> arg_name_info_t;\r
typedef boost::error_info<struct tag_arg_value_info, std::string> arg_value_info_t;\r
typedef boost::error_info<struct tag_msg_info, std::string> msg_info_t;\r
+typedef boost::error_info<struct tag_call_stack_info, std::string> call_stack_info_t;\r
typedef boost::error_info<struct tag_msg_info, std::string> error_info_t;\r
typedef boost::error_info<struct tag_source_info, std::string> source_info_t;\r
typedef boost::error_info<struct tag_file_name_info, std::string> file_name_info_t;\r
\r
template<typename T>\r
-inline arg_name_info_t arg_name_info(const T& str) {return arg_name_info_t(u8(str));}\r
+inline arg_name_info_t arg_name_info(const T& str) {return arg_name_info_t(u8(str));}\r
+template<typename T>\r
+inline arg_value_info_t arg_value_info(const T& str) {return arg_value_info_t(u8(str));}\r
template<typename T>\r
-inline arg_value_info_t arg_value_info(const T& str) {return arg_value_info_t(u8(str));}\r
+inline msg_info_t msg_info(const T& str) {return msg_info_t(u8(str));}\r
template<typename T>\r
-inline msg_info_t msg_info(const T& str) {return msg_info_t(u8(str));}\r
+inline call_stack_info_t call_stack_info(const T& str) {return call_stack_info_t(u8(str));}\r
template<typename T>\r
-inline error_info_t error_info(const T& str) {return error_info_t(u8(str));}\r
+inline error_info_t error_info(const T& str) {return error_info_t(u8(str));}\r
template<typename T>\r
-inline source_info_t source_info(const T& str) {return source_info_t(u8(str));}\r
+inline source_info_t source_info(const T& str) {return source_info_t(u8(str));}\r
template<typename T>\r
inline file_name_info_t file_name_info(const T& str) {return file_name_info_t(u8(str));}\r
\r
address badAddress_;\r
};\r
\r
+#define CASPAR_THROW_EXCEPTION(e) BOOST_THROW_EXCEPTION(e << call_stack_info(caspar::log::internal::get_call_stack()))\r
+\r
}\r
\r
namespace std\r
{\r
try\r
{\r
- wait();\r
+ internal_begin_invoke([=]\r
+ {\r
+ is_running_ = false;\r
+ }).wait();\r
}\r
catch(...)\r
{\r
CASPAR_LOG_CURRENT_EXCEPTION();\r
}\r
\r
- is_running_ = false;\r
- semaphore_.try_push(0);\r
-\r
thread_.join();\r
}\r
\r
auto begin_invoke(Func&& func, task_priority priority = task_priority::normal_priority) -> boost::unique_future<decltype(func())> // noexcept\r
{ \r
if(execution_queue_.size() > 128)\r
- BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("executor overflow.") << source_info(name_));\r
+ CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("executor overflow.") << source_info(name_));\r
\r
if(!is_running_)\r
- BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("executor not running.") << source_info(name_));\r
+ CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("executor not running.") << source_info(name_));\r
\r
return internal_begin_invoke(std::forward<Func>(func), priority); \r
}\r
void yield()\r
{\r
if(!is_current())\r
- BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Executor can only yield inside of thread context.") << source_info(name_));\r
+ CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Executor can only yield inside of thread context.") << source_info(name_));\r
\r
int dummy;\r
if(!semaphore_.try_pop(dummy))\r
switch (LastErrorCode)\r
{\r
case GL_INVALID_ENUM :\r
- BOOST_THROW_EXCEPTION(ogl_invalid_enum()\r
+ CASPAR_THROW_EXCEPTION(ogl_invalid_enum()\r
<< msg_info("an unacceptable value has been specified for an enumerated argument")\r
<< error_info("GL_INVALID_ENUM")\r
<< line_info(line)\r
<< source_info(file));\r
\r
case GL_INVALID_VALUE :\r
- BOOST_THROW_EXCEPTION(ogl_invalid_value()\r
+ CASPAR_THROW_EXCEPTION(ogl_invalid_value()\r
<< msg_info("a numeric argument is out of range")\r
<< error_info("GL_INVALID_VALUE")\r
<< line_info(line)\r
<< source_info(file));\r
\r
case GL_INVALID_OPERATION :\r
- BOOST_THROW_EXCEPTION(ogl_invalid_operation()\r
+ CASPAR_THROW_EXCEPTION(ogl_invalid_operation()\r
<< msg_info("the specified operation is not allowed in the current state")\r
<< error_info("GL_INVALID_OPERATION")\r
<< line_info(line)\r
<< source_info(file));\r
\r
case GL_STACK_OVERFLOW :\r
- BOOST_THROW_EXCEPTION(ogl_stack_overflow()\r
+ CASPAR_THROW_EXCEPTION(ogl_stack_overflow()\r
<< msg_info("this command would cause a stack overflow")\r
<< error_info("GL_STACK_OVERFLOW")\r
<< line_info(line)\r
<< source_info(file));\r
\r
case GL_STACK_UNDERFLOW :\r
- BOOST_THROW_EXCEPTION(ogl_stack_underflow()\r
+ CASPAR_THROW_EXCEPTION(ogl_stack_underflow()\r
<< msg_info("this command would cause a stack underflow")\r
<< error_info("GL_STACK_UNDERFLOW")\r
<< line_info(line)\r
<< source_info(file));\r
\r
case GL_OUT_OF_MEMORY :\r
- BOOST_THROW_EXCEPTION(ogl_out_of_memory()\r
+ CASPAR_THROW_EXCEPTION(ogl_out_of_memory()\r
<< msg_info("there is not enough memory left to execute the command")\r
<< error_info("GL_OUT_OF_MEMORY")\r
<< line_info(line)\r
<< source_info(file));\r
\r
case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :\r
- BOOST_THROW_EXCEPTION(ogl_stack_underflow()\r
+ CASPAR_THROW_EXCEPTION(ogl_stack_underflow()\r
<< msg_info("the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"")\r
<< error_info("GL_INVALID_FRAMEBUFFER_OPERATION_EXT")\r
<< line_info(line)\r
try\r
{\r
if(!boost::filesystem::is_directory(folder))\r
- BOOST_THROW_EXCEPTION(directory_not_found());\r
+ CASPAR_THROW_EXCEPTION(directory_not_found());\r
\r
auto file_sink = boost::make_shared<file_sink_type>(\r
boost::log::keywords::file_name = (folder + L"caspar_%Y-%m-%d.log"),\r
}\r
catch(...)\r
{ \r
- BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Failed to parse param.") << arg_name_info(name) << nested_exception(std::current_exception()));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("Failed to parse param.") << arg_name_info(name) << nested_exception(std::current_exception()));\r
}\r
}\r
\r
}\r
catch(...)\r
{ \r
- BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Failed to parse param.") << arg_name_info(name) << nested_exception(std::current_exception()));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("Failed to parse param.") << arg_name_info(name) << nested_exception(std::current_exception()));\r
}\r
}\r
\r
\r
auto it = tweens.find(name);\r
if(it == tweens.end())\r
- BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Could not find tween.") << arg_value_info(name));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("Could not find tween.") << arg_value_info(name));\r
\r
auto tween = it->second;\r
return [=](double t, double b, double c, double d)\r
spl::shared_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params)\r
{\r
if(params.empty())\r
- BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));\r
\r
auto consumer = frame_consumer::empty();\r
std::any_of(g_factories.begin(), g_factories.end(), [&](const consumer_factory_t& factory) -> bool\r
});\r
\r
if(consumer == frame_consumer::empty())\r
- BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax."));\r
+ CASPAR_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax."));\r
\r
return spl::make_shared<destroy_consumer_proxy>(\r
spl::make_shared<print_consumer_proxy>(\r
{\r
BOOST_FOREACH(auto& buffer, buffers_)\r
if(!buffer.data())\r
- BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("mutable_frame: null argument"));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("mutable_frame: null argument"));\r
}\r
};\r
\r
, id_(reinterpret_cast<int>(this))\r
{\r
if(desc.format != core::pixel_format::bgra)\r
- BOOST_THROW_EXCEPTION(not_implemented());\r
+ CASPAR_THROW_EXCEPTION(not_implemented());\r
\r
future_buffers_.push_back(std::move(image));\r
}\r
{\r
auto color2 = get_hex_color(color);\r
if(color2.length() != 9 || color2[0] != '#')\r
- BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(color2) << msg_info("Invalid color."));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(color2) << msg_info("Invalid color."));\r
\r
core::pixel_format_desc desc(pixel_format::bgra);\r
desc.planes.push_back(core::pixel_format_desc::plane(1, 1, 4));\r
auto& value = *reinterpret_cast<uint32_t*>(frame.image_data(0).begin());\r
std::wstringstream str(color2.substr(1));\r
if(!(str >> std::hex >> value) || !str.eof())\r
- BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(color2) << msg_info("Invalid color."));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(color2) << msg_info("Invalid color."));\r
\r
return core::draw_frame(std::move(frame));\r
}\r
\r
boost::unique_future<std::wstring> frame_producer_base::call(const std::wstring&) \r
{\r
- BOOST_THROW_EXCEPTION(not_supported());\r
+ CASPAR_THROW_EXCEPTION(not_supported());\r
}\r
\r
uint32_t frame_producer_base::nb_frames() const\r
void unsubscribe(const monitor::observable::observer_ptr& o) override{} \r
std::wstring name() const override {return L"empty";}\r
uint32_t frame_number() const override {return 0;}\r
- boost::unique_future<std::wstring> call(const std::wstring& params) override{BOOST_THROW_EXCEPTION(not_supported());}\r
+ boost::unique_future<std::wstring> call(const std::wstring& params) override{CASPAR_THROW_EXCEPTION(not_supported());}\r
draw_frame last_frame() const {return draw_frame::empty();}\r
\r
boost::property_tree::wptree info() const override\r
spl::shared_ptr<core::frame_producer> do_create_producer(const spl::shared_ptr<frame_factory>& my_frame_factory, const video_format_desc& format_desc, const std::vector<std::wstring>& params)\r
{\r
if(params.empty())\r
- BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));\r
\r
auto producer = frame_producer::empty();\r
std::any_of(g_factories.begin(), g_factories.end(), [&](const producer_factory_t& factory) -> bool\r
std::wstring str;\r
BOOST_FOREACH(auto& param, params)\r
str += param + L" ";\r
- BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax.") << arg_value_info(u8(str)));\r
+ CASPAR_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax.") << arg_value_info(u8(str)));\r
}\r
\r
return producer;\r
\r
//Setting output Video mode\r
if(BLUE_FAIL(set_card_property(blue_, VIDEO_MODE, vid_fmt_))) \r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to set videomode."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to set videomode."));\r
\r
//Select Update Mode for output\r
if(BLUE_FAIL(set_card_property(blue_, VIDEO_UPDATE_TYPE, UPD_FMT_FRAME))) \r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to set update type."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to set update type."));\r
\r
disable_video_output();\r
\r
//Enable dual link output\r
if(BLUE_FAIL(set_card_property(blue_, VIDEO_DUAL_LINK_OUTPUT, 1)))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to enable dual link."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to enable dual link."));\r
\r
if(BLUE_FAIL(set_card_property(blue_, VIDEO_DUAL_LINK_OUTPUT_SIGNAL_FORMAT_TYPE, Signal_FormatType_4224)))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to set dual link format type to 4:2:2:4."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to set dual link format type to 4:2:2:4."));\r
\r
//Select output memory format\r
if(BLUE_FAIL(set_card_property(blue_, VIDEO_MEMORY_FORMAT, MEM_FMT_ARGB_PC))) \r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to set memory format."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to set memory format."));\r
\r
//Select image orientation\r
if(BLUE_FAIL(set_card_property(blue_, VIDEO_IMAGE_ORIENTATION, ImageOrientation_Normal)))\r
if(!module)\r
LoadLibrary(u16(std::string(getenv("SystemDrive")) + "\\Program Files (x86)\\BlueFish444\\Driver\\" + module_str).c_str());\r
if(!module)\r
- BOOST_THROW_EXCEPTION(file_not_found() << msg_info("Could not find BlueVelvet3.dll. Required drivers are not installed."));\r
+ CASPAR_THROW_EXCEPTION(file_not_found() << msg_info("Could not find BlueVelvet3.dll. Required drivers are not installed."));\r
static std::shared_ptr<void> lib(module, FreeLibrary);\r
BlueVelvetFactory4 = reinterpret_cast<decltype(BlueVelvetFactory4)>(GetProcAddress(module, "BlueVelvetFactory4"));\r
BlueVelvetDestroy = reinterpret_cast<decltype(BlueVelvetDestroy)>(GetProcAddress(module, "BlueVelvetDestroy"));\r
if(!module)\r
LoadLibrary(u16(std::string(getenv("SystemDrive")) + "\\Program Files (x86)\\BlueFish444\\Driver\\" + module_str).c_str());\r
if(!module)\r
- BOOST_THROW_EXCEPTION(file_not_found() << msg_info("Could not find BlueHancUtils.dll. Required drivers are not installed."));\r
+ CASPAR_THROW_EXCEPTION(file_not_found() << msg_info("Could not find BlueHancUtils.dll. Required drivers are not installed."));\r
static std::shared_ptr<void> lib(module, FreeLibrary);\r
encode_hanc_frame = reinterpret_cast<decltype(encode_hanc_frame)>(GetProcAddress(module, "encode_hanc_frame"));\r
encode_hanc_frame_ex = reinterpret_cast<decltype(encode_hanc_frame_ex)>(GetProcAddress(module, "encode_hanc_frame_ex"));\r
vid_fmt = videoMode; \r
}\r
if(vid_fmt == VID_FMT_INVALID)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("video-mode not supported.") << arg_value_info(format_desc.name));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("video-mode not supported.") << arg_value_info(format_desc.name));\r
\r
return vid_fmt;\r
}\r
spl::shared_ptr<CBlueVelvet4> create_blue()\r
{\r
if(!BlueVelvetFactory4 || !encode_hanc_frame || !encode_hanc_frame)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Bluefish drivers not found."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Bluefish drivers not found."));\r
\r
return spl::shared_ptr<CBlueVelvet4>(BlueVelvetFactory4(), BlueVelvetDestroy);\r
}\r
auto blue = create_blue();\r
\r
if(BLUE_FAIL(blue->device_attach(device_index, FALSE))) \r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to attach device."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to attach device."));\r
\r
return blue;\r
}\r
void enable_audio()\r
{\r
if(FAILED(output_->EnableAudioOutput(bmdAudioSampleRate48kHz, bmdAudioSampleType32bitInteger, 2, bmdAudioOutputStreamTimestamped)))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(u8(print()) + " Could not enable audio output."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(u8(print()) + " Could not enable audio output."));\r
\r
if(FAILED(output_->SetAudioCallback(this)))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(u8(print()) + " Could not set audio callback."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(u8(print()) + " Could not set audio callback."));\r
\r
CASPAR_LOG(info) << print() << L" Enabled embedded-audio.";\r
}\r
void enable_video(BMDDisplayMode display_mode)\r
{\r
if(FAILED(output_->EnableVideoOutput(display_mode, bmdVideoOutputFlagDefault))) \r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(u8(print()) + " Could not enable video output."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(u8(print()) + " Could not enable video output."));\r
\r
if(FAILED(output_->SetScheduledFrameCompletionCallback(this)))\r
- BOOST_THROW_EXCEPTION(caspar_exception() \r
+ CASPAR_THROW_EXCEPTION(caspar_exception() \r
<< msg_info(u8(print()) + " Failed to set playback completion callback.")\r
<< boost::errinfo_api_function("SetScheduledFrameCompletionCallback"));\r
}\r
void start_playback()\r
{\r
if(FAILED(output_->StartScheduledPlayback(0, format_desc_.time_scale, 1.0))) \r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(u8(print()) + " Failed to schedule playback."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(u8(print()) + " Failed to schedule playback."));\r
}\r
\r
STDMETHOD (QueryInterface(REFIID, LPVOID*)) {return E_NOINTERFACE;}\r
std::rethrow_exception(exception); \r
\r
if(!is_running_)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(u8(print()) + " Is not running."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(u8(print()) + " Is not running."));\r
\r
if(config_.embedded_audio)\r
audio_frame_buffer_.push(frame); \r
\r
// NOTE: bmdFormat8BitARGB is currently not supported by any decklink card. (2011-05-08)\r
if(FAILED(input_->EnableVideoInput(display_mode, bmdFormat8BitYUV, 0))) \r
- BOOST_THROW_EXCEPTION(caspar_exception() \r
+ CASPAR_THROW_EXCEPTION(caspar_exception() \r
<< msg_info(print() + L" Could not enable video input.")\r
<< boost::errinfo_api_function("EnableVideoInput"));\r
\r
if(FAILED(input_->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType32bitInteger, static_cast<int>(in_format_desc.audio_channels)))) \r
- BOOST_THROW_EXCEPTION(caspar_exception() \r
+ CASPAR_THROW_EXCEPTION(caspar_exception() \r
<< msg_info(print() + L" Could not enable audio input.")\r
<< boost::errinfo_api_function("EnableAudioInput"));\r
\r
if (FAILED(input_->SetCallback(this)) != S_OK)\r
- BOOST_THROW_EXCEPTION(caspar_exception() \r
+ CASPAR_THROW_EXCEPTION(caspar_exception() \r
<< msg_info(print() + L" Failed to set input callback.")\r
<< boost::errinfo_api_function("SetCallback"));\r
\r
if(FAILED(input_->StartStreams()))\r
- BOOST_THROW_EXCEPTION(caspar_exception() \r
+ CASPAR_THROW_EXCEPTION(caspar_exception() \r
<< msg_info(print() + L" Failed to start input stream.")\r
<< boost::errinfo_api_function("StartStreams"));\r
\r
}\r
\r
if(!mode)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Device could not find requested video-format.") \r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Device could not find requested video-format.") \r
<< arg_value_info(boost::lexical_cast<std::string>(format))\r
<< arg_name_info("format"));\r
\r
BMDDisplayModeSupport displayModeSupport;\r
if(FAILED(device->DoesSupportVideoMode(mode->GetDisplayMode(), pix_fmt, flag, &displayModeSupport, nullptr)) || displayModeSupport == bmdDisplayModeNotSupported)\r
CASPAR_LOG(warning) << L"Device does not support video-format: " << mode->GetDisplayMode();\r
- //BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Device does not support requested video-format.")\r
+ //CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Device does not support requested video-format.")\r
// << arg_value_info(boost::lexical_cast<std::string>(format))\r
// << arg_name_info("format"));\r
else if(displayModeSupport == bmdDisplayModeSupportedWithConversion)\r
{\r
CComPtr<IDeckLinkIterator> pDecklinkIterator;\r
if(FAILED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator)))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Decklink drivers not found."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Decklink drivers not found."));\r
\r
size_t n = 0;\r
CComPtr<IDeckLink> decklink;\r
while(n < device_index && pDecklinkIterator->Next(&decklink) == S_OK){++n;} \r
\r
if(n != device_index || !decklink)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Decklink device not found.") << arg_name_info("device_index") << arg_value_info(boost::lexical_cast<std::string>(device_index)));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Decklink device not found.") << arg_name_info("device_index") << arg_value_info(boost::lexical_cast<std::string>(device_index)));\r
\r
return decklink;\r
}\r
// norm = NTSC;\r
\r
// if(norm == UNKNOWN)\r
- // BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("target"));\r
+ // CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("target"));\r
// \r
// if (name.find("-dv") != std::string::npos) \r
// {\r
format = av_guess_format(value.c_str(), nullptr, nullptr);\r
\r
if(format == nullptr)\r
- BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("f"));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("f"));\r
\r
return true;\r
}\r
{\r
auto c = avcodec_find_encoder_by_name(value.c_str());\r
if(c == nullptr)\r
- BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("vcodec"));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("vcodec"));\r
\r
vcodec = avcodec_find_encoder_by_name(value.c_str())->id;\r
return true;\r
{\r
auto c = avcodec_find_encoder_by_name(value.c_str());\r
if(c == nullptr)\r
- BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("acodec"));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("acodec"));\r
\r
acodec = avcodec_find_encoder_by_name(value.c_str())->id;\r
\r
else if(name == "s")\r
{\r
if(av_parse_video_size(&width, &height, value.c_str()) < 0)\r
- BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("s"));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << arg_name_info("s"));\r
\r
return true;\r
}\r
\r
auto st = av_new_stream(oc_.get(), 0);\r
if (!st) \r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Could not allocate video-stream.") << boost::errinfo_api_function("av_new_stream")); \r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Could not allocate video-stream.") << boost::errinfo_api_function("av_new_stream")); \r
\r
auto encoder = avcodec_find_encoder(output_format_.vcodec);\r
if (!encoder)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Codec not found."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Codec not found."));\r
\r
auto c = st->codec;\r
\r
else if(c->codec_id == CODEC_ID_DNXHD)\r
{\r
if(c->width < 1280 || c->height < 720)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Unsupported video dimensions."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Unsupported video dimensions."));\r
\r
c->bit_rate = 220*1000000;\r
c->pix_fmt = PIX_FMT_YUV422P;\r
\r
auto st = av_new_stream(oc_.get(), 1);\r
if(!st)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Could not allocate audio-stream") << boost::errinfo_api_function("av_new_stream")); \r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Could not allocate audio-stream") << boost::errinfo_api_function("av_new_stream")); \r
\r
auto encoder = avcodec_find_encoder(output_format_.acodec);\r
if (!encoder)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("codec not found"));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("codec not found"));\r
\r
auto c = st->codec;\r
\r
SWS_BICUBIC, nullptr, nullptr, nullptr), \r
sws_freeContext);\r
if (sws_ == nullptr) \r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Cannot initialize the conversion context"));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Cannot initialize the conversion context"));\r
}\r
\r
std::shared_ptr<AVFrame> in_frame(avcodec_alloc_frame(), av_free);\r
0, nullptr), [](SwrContext* p){swr_free(&p);});\r
\r
if(!swr_)\r
- BOOST_THROW_EXCEPTION(std::bad_alloc("swr_"));\r
+ CASPAR_THROW_EXCEPTION(bad_alloc());\r
\r
THROW_ON_ERROR2(swr_init(swr_.get()), "[audio_decoder]");\r
}\r
explicit impl(input& in, const core::video_format_desc& format_desc) \r
: input_(&in)\r
, format_desc_(format_desc) \r
- , codec_context_(open_codec(*input_->context(), AVMEDIA_TYPE_AUDIO, index_))\r
+ , codec_context_(open_codec(input_->context(), AVMEDIA_TYPE_AUDIO, index_))\r
, swr_(swr_alloc_set_opts(nullptr,\r
av_get_default_channel_layout(format_desc_.audio_channels), AV_SAMPLE_FMT_S32, format_desc_.audio_sample_rate,\r
get_channel_layout(codec_context_.get()), codec_context_->sample_fmt, codec_context_->sample_rate,\r
, buffer_(AVCODEC_MAX_AUDIO_FRAME_SIZE*4)\r
{ \r
if(!swr_)\r
- BOOST_THROW_EXCEPTION(std::bad_alloc("swr_"));\r
+ CASPAR_THROW_EXCEPTION(bad_alloc());\r
\r
THROW_ON_ERROR2(swr_init(swr_.get()), "[audio_decoder]");\r
}\r
{ \r
std::shared_ptr<AVFrame> decoded_frame(avcodec_alloc_frame(), av_free);\r
\r
- int frame_finished = 0;\r
- auto len = THROW_ON_ERROR2(avcodec_decode_audio4(codec_context_.get(), decoded_frame.get(), &frame_finished, &pkt), "[audio_decoder]");\r
+ int got_frame = 0;\r
+ auto len = THROW_ON_ERROR2(avcodec_decode_audio4(codec_context_.get(), decoded_frame.get(), &got_frame, &pkt), "[audio_decoder]");\r
\r
if(len == 0)\r
{\r
pkt.data += len;\r
pkt.size -= len;\r
\r
- if(!frame_finished)\r
- return audio;\r
+ if(!got_frame)\r
+ continue;\r
\r
const uint8_t *in[] = {decoded_frame->data[0]};\r
uint8_t* out[] = {buffer_.data()};\r
, frame_factory_(frame_factory) \r
, format_desc_(format_desc)\r
, input_(graph_, filename_, loop, start, length)\r
- , fps_(read_fps(*input_.context(), format_desc_.fps))\r
+ , fps_(read_fps(input_.context(), format_desc_.fps))\r
, muxer_(fps_, frame_factory, format_desc_, filter)\r
, start_(start)\r
, last_frame_(core::draw_frame::empty())\r
result = boost::lexical_cast<std::wstring>(start());\r
}\r
else\r
- BOOST_THROW_EXCEPTION(invalid_argument());\r
+ CASPAR_THROW_EXCEPTION(invalid_argument());\r
\r
return async(launch::deferred, [=]{return result;});\r
}\r
return;\r
\r
if(frame->data[0] == nullptr || frame->width < 1)\r
- BOOST_THROW_EXCEPTION(invalid_argument());\r
+ CASPAR_THROW_EXCEPTION(invalid_argument());\r
\r
if(filters_.empty())\r
{\r
}\r
catch(...)\r
{\r
- BOOST_THROW_EXCEPTION(ffmpeg_error() << boost::errinfo_nested_exception(boost::current_exception()));\r
+ CASPAR_THROW_EXCEPTION(ffmpeg_error() << boost::errinfo_nested_exception(boost::current_exception()));\r
}\r
}\r
\r
}\r
catch(...)\r
{\r
- BOOST_THROW_EXCEPTION(ffmpeg_error() << boost::errinfo_nested_exception(boost::current_exception()));\r
+ CASPAR_THROW_EXCEPTION(ffmpeg_error() << boost::errinfo_nested_exception(boost::current_exception()));\r
}\r
}\r
};\r
stream video_stream_;\r
stream audio_stream_;\r
\r
- executor executor_;\r
+ tbb::atomic<uint32_t> seek_target_;\r
+\r
+ tbb::atomic<bool> is_running_;\r
+ boost::mutex mutex_;\r
+ boost::condition_variable cond_;\r
+ boost::thread thread_;\r
\r
impl(const spl::shared_ptr<diagnostics::graph> graph, const std::wstring& filename, const bool loop, const uint32_t start, const uint32_t length) \r
: graph_(graph)\r
, fps_(read_fps(*format_context_, 0.0))\r
, video_stream_(av_find_best_stream(format_context_.get(), AVMEDIA_TYPE_VIDEO, -1, -1, 0, 0))\r
, audio_stream_(av_find_best_stream(format_context_.get(), AVMEDIA_TYPE_AUDIO, -1, -1, 0, 0))\r
- , executor_(print())\r
{ \r
start_ = start;\r
length_ = length;\r
loop_ = loop;\r
-\r
- if(start_ > 0) \r
- seek(start_, false);\r
- \r
+ seek_target_ = start_;\r
+ is_running_ = true;\r
+ thread_ = boost::thread([this]{run();});\r
+ \r
graph_->set_color("seek", diagnostics::color(1.0f, 0.5f, 0.0f)); \r
graph_->set_color("audio-buffer", diagnostics::color(0.7f, 0.4f, 0.4f));\r
- graph_->set_color("video-buffer", diagnostics::color(1.0f, 1.0f, 0.0f)); \r
- \r
- tick();\r
+ graph_->set_color("video-buffer", diagnostics::color(1.0f, 1.0f, 0.0f)); \r
+ }\r
+\r
+ ~impl()\r
+ {\r
+ is_running_ = false;\r
+ cond_.notify_one();\r
+ thread_.join();\r
}\r
\r
bool try_pop_video(std::shared_ptr<AVPacket>& packet)\r
{ \r
bool result = video_stream_.try_pop(packet);\r
if(result)\r
- tick();\r
+ cond_.notify_one();\r
\r
graph_->set_value("video-buffer", std::min(1.0, static_cast<double>(video_stream_.size()/MIN_FRAMES)));\r
\r
{ \r
bool result = audio_stream_.try_pop(packet);\r
if(result)\r
- tick();\r
+ cond_.notify_one();\r
\r
graph_->set_value("audio-buffer", std::min(1.0, static_cast<double>(audio_stream_.size()/MIN_FRAMES)));\r
\r
return result;\r
}\r
\r
- void seek(uint32_t target, bool clear)\r
+ void seek(uint32_t target)\r
{\r
- executor_.invoke([=]\r
- { \r
- CASPAR_LOG(debug) << print() << " Seeking: " << target;\r
+ seek_target_ = target;\r
+ video_stream_.clear();\r
+ audio_stream_.clear();\r
+ }\r
+ \r
+ std::wstring print() const\r
+ {\r
+ return L"ffmpeg_input[" + filename_ + L")]";\r
+ }\r
\r
- int flags = AVSEEK_FLAG_FRAME;\r
- if(target == 0)\r
+private:\r
+ void internal_seek(uint32_t target)\r
+ {\r
+ CASPAR_LOG(debug) << print() << " Seeking: " << target;\r
+\r
+ int flags = AVSEEK_FLAG_FRAME;\r
+ if(target == 0)\r
+ {\r
+ // Fix VP6 seeking\r
+ int vid_stream_index = av_find_best_stream(format_context_.get(), AVMEDIA_TYPE_VIDEO, -1, -1, 0, 0);\r
+ if(vid_stream_index >= 0)\r
{\r
- // Fix VP6 seeking\r
- int vid_stream_index = av_find_best_stream(format_context_.get(), AVMEDIA_TYPE_VIDEO, -1, -1, 0, 0);\r
- if(vid_stream_index >= 0)\r
- {\r
- auto codec_id = format_context_->streams[vid_stream_index]->codec->codec_id;\r
- if(codec_id == CODEC_ID_VP6A || codec_id == CODEC_ID_VP6F || codec_id == CODEC_ID_VP6)\r
- flags = AVSEEK_FLAG_BYTE;\r
- }\r
+ auto codec_id = format_context_->streams[vid_stream_index]->codec->codec_id;\r
+ if(codec_id == CODEC_ID_VP6A || codec_id == CODEC_ID_VP6F || codec_id == CODEC_ID_VP6)\r
+ flags = AVSEEK_FLAG_BYTE;\r
}\r
+ }\r
\r
- auto stream = format_context_->streams[default_stream_index_];\r
- auto codec = stream->codec;\r
- auto fixed_target = (target*stream->time_base.den*codec->time_base.num)/(stream->time_base.num*codec->time_base.den)*codec->ticks_per_frame;\r
+ auto stream = format_context_->streams[default_stream_index_];\r
+ auto codec = stream->codec;\r
+ auto fixed_target = (target*stream->time_base.den*codec->time_base.num)/(stream->time_base.num*codec->time_base.den)*codec->ticks_per_frame;\r
\r
- THROW_ON_ERROR2(avformat_seek_file(format_context_.get(), default_stream_index_, std::numeric_limits<int64_t>::min(), fixed_target, fixed_target, 0), print()); \r
+ THROW_ON_ERROR2(avformat_seek_file(format_context_.get(), default_stream_index_, std::numeric_limits<int64_t>::min(), fixed_target, fixed_target, 0), print()); \r
\r
- if(clear)\r
- {\r
- video_stream_.clear();\r
- audio_stream_.clear();\r
- }\r
-\r
- video_stream_.push(flush_packet());\r
- audio_stream_.push(flush_packet());\r
- \r
- tick();\r
- }, task_priority::high_priority);\r
+ video_stream_.push(flush_packet());\r
+ audio_stream_.push(flush_packet());\r
}\r
\r
- std::wstring print() const\r
- {\r
- return L"ffmpeg_input[" + filename_ + L")]";\r
- }\r
- \r
bool full() const\r
{\r
return video_stream_.size() > MIN_FRAMES && audio_stream_.size() > MIN_FRAMES;\r
}\r
\r
void tick()\r
- { \r
- if(!executor_.is_running())\r
- return;\r
- \r
- executor_.begin_invoke([this]\r
- { \r
- if(full())\r
- return;\r
+ {\r
+ if(seek_target_.fetch_and_store(std::numeric_limits<uint32_t>::max()) != std::numeric_limits<uint32_t>::max()) \r
+ internal_seek(seek_target_);\r
\r
- try\r
- {\r
- auto packet = create_packet();\r
+ auto packet = create_packet();\r
\r
- auto ret = av_read_frame(format_context_.get(), packet.get()); // packet is only valid until next call of av_read_frame. Use av_dup_packet to extend its life. \r
+ auto ret = av_read_frame(format_context_.get(), packet.get()); // packet is only valid until next call of av_read_frame. Use av_dup_packet to extend its life. \r
\r
- if(is_eof(ret)) \r
- {\r
- for(int n = 0; n < 3; ++n)\r
- {\r
- video_stream_.push(null_packet());\r
- audio_stream_.push(null_packet());\r
- }\r
-\r
- if(loop_)\r
- {\r
- seek(start_, false);\r
- graph_->set_tag("seek"); \r
- }\r
- }\r
- else\r
- { \r
- THROW_ON_ERROR(ret, "av_read_frame", print());\r
+ if(is_eof(ret)) \r
+ {\r
+ for(int n = 0; n < 3; ++n)\r
+ {\r
+ video_stream_.push(null_packet());\r
+ audio_stream_.push(null_packet());\r
+ }\r
+\r
+ if(loop_)\r
+ {\r
+ internal_seek(start_);\r
+ graph_->set_tag("seek"); \r
+ }\r
+ }\r
+ else\r
+ { \r
+ THROW_ON_ERROR(ret, "av_read_frame", print());\r
\r
- THROW_ON_ERROR2(av_dup_packet(packet.get()), print());\r
+ THROW_ON_ERROR2(av_dup_packet(packet.get()), print());\r
\r
- // Make sure that the packet is correctly deallocated even if size and data is modified during decoding.\r
- auto size = packet->size;\r
- auto data = packet->data;\r
+ // Make sure that the packet is correctly deallocated even if size and data is modified during decoding.\r
+ auto size = packet->size;\r
+ auto data = packet->data;\r
\r
- packet = spl::shared_ptr<AVPacket>(packet.get(), [packet, size, data](AVPacket*)\r
- {\r
- packet->size = size;\r
- packet->data = data; \r
- });\r
+ packet = spl::shared_ptr<AVPacket>(packet.get(), [packet, size, data](AVPacket*)\r
+ {\r
+ packet->size = size;\r
+ packet->data = data; \r
+ });\r
\r
- auto stream_time_base = format_context_->streams[packet->stream_index]->time_base;\r
- auto packet_frame_number = static_cast<uint32_t>((static_cast<double>(packet->pts * stream_time_base.num)/stream_time_base.den)*fps_);\r
+ auto stream_time_base = format_context_->streams[packet->stream_index]->time_base;\r
+ auto packet_frame_number = static_cast<uint32_t>((static_cast<double>(packet->pts * stream_time_base.num)/stream_time_base.den)*fps_);\r
\r
- if(packet->stream_index == default_stream_index_)\r
- frame_number_ = packet_frame_number;\r
+ if(packet->stream_index == default_stream_index_)\r
+ frame_number_ = packet_frame_number;\r
\r
- if(packet_frame_number >= start_ && packet_frame_number < length_)\r
- {\r
- video_stream_.push(packet);\r
- audio_stream_.push(packet);\r
+ if(packet_frame_number >= start_ && packet_frame_number < length_)\r
+ {\r
+ video_stream_.push(packet);\r
+ audio_stream_.push(packet);\r
\r
- graph_->set_value("video-buffer", std::min(1.0, static_cast<double>(video_stream_.size()/MIN_FRAMES)));\r
- graph_->set_value("audio-buffer", std::min(1.0, static_cast<double>(audio_stream_.size()/MIN_FRAMES)));\r
- }\r
+ graph_->set_value("video-buffer", std::min(1.0, static_cast<double>(video_stream_.size()/MIN_FRAMES)));\r
+ graph_->set_value("audio-buffer", std::min(1.0, static_cast<double>(audio_stream_.size()/MIN_FRAMES)));\r
+ }\r
+ } \r
+ }\r
+\r
+ void run()\r
+ {\r
+ win32_exception::install_handler();\r
+\r
+ while(is_running_)\r
+ {\r
+ boost::unique_lock<boost::mutex> lock(mutex_);\r
\r
- tick(); \r
- } \r
+ try\r
+ {\r
+ tick();\r
+\r
+ boost::this_thread::sleep(boost::posix_time::milliseconds(1));\r
+ \r
+ while(full() && is_running_)\r
+ cond_.wait(lock);\r
}\r
catch(...)\r
{\r
CASPAR_LOG_CURRENT_EXCEPTION();\r
- executor_.stop();\r
+ is_running_ = false;\r
}\r
- });\r
- } \r
+ }\r
+ }\r
\r
bool is_eof(int ret)\r
{\r
: impl_(new impl(graph, filename, loop, start, length)){}\r
bool input::try_pop_video(std::shared_ptr<AVPacket>& packet){return impl_->try_pop_video(packet);}\r
bool input::try_pop_audio(std::shared_ptr<AVPacket>& packet){return impl_->try_pop_audio(packet);}\r
-spl::shared_ptr<AVFormatContext> input::context(){return impl_->format_context_;}\r
+AVFormatContext& input::context(){return *impl_->format_context_;}\r
void input::loop(bool value){impl_->loop_ = value;}\r
bool input::loop() const{return impl_->loop_;}\r
-void input::seek(uint32_t target){impl_->seek(target, true);}\r
+void input::seek(uint32_t target){impl_->seek(target);}\r
void input::start(uint32_t value){impl_->start_ = value;}\r
uint32_t input::start() const{return impl_->start_;}\r
void input::length(uint32_t value){impl_->length_ = value;}\r
\r
void seek(uint32_t target);\r
\r
- spl::shared_ptr<AVFormatContext> context();\r
+ AVFormatContext& context();\r
private:\r
struct impl;\r
std::shared_ptr<impl> impl_;\r
break;\r
}\r
default:\r
- BOOST_THROW_EXCEPTION(invalid_operation());\r
+ CASPAR_THROW_EXCEPTION(invalid_operation());\r
}\r
}\r
}\r
core::audio_buffer pop_audio()\r
{\r
if(audio_stream_.size() < audio_cadence_.front())\r
- BOOST_THROW_EXCEPTION(out_of_range());\r
+ CASPAR_THROW_EXCEPTION(out_of_range());\r
\r
auto begin = audio_stream_.begin();\r
auto end = begin + audio_cadence_.front();\r
try\r
{\r
if(!boost::filesystem::exists(filename))\r
- BOOST_THROW_EXCEPTION(caspar_exception());\r
+ CASPAR_THROW_EXCEPTION(caspar_exception());\r
\r
std::fstream fileStream = std::fstream(filename, std::fstream::in);\r
\r
\r
if(!sws_context)\r
{\r
- BOOST_THROW_EXCEPTION(operation_failed() << msg_info("Could not create software scaling context.") << \r
+ CASPAR_THROW_EXCEPTION(operation_failed() << msg_info("Could not create software scaling context.") << \r
boost::errinfo_api_function("sws_getContext"));\r
} \r
\r
\r
std::queue<spl::shared_ptr<AVPacket>> packets_;\r
\r
+ const AVStream* stream_;\r
const uint32_t nb_frames_;\r
-\r
const int width_;\r
const int height_;\r
+\r
bool is_progressive_;\r
uint32_t file_frame_number_;\r
double fps_;\r
\r
explicit impl(input& in) \r
: input_(&in)\r
- , codec_context_(open_codec(*input_->context(), AVMEDIA_TYPE_VIDEO, index_))\r
- , nb_frames_(static_cast<uint32_t>(input_->context()->streams[index_]->nb_frames))\r
+ , codec_context_(open_codec(input_->context(), AVMEDIA_TYPE_VIDEO, index_))\r
+ , stream_(input_->context().streams[index_])\r
+ , nb_frames_(static_cast<uint32_t>(stream_->nb_frames))\r
, width_(codec_context_->width)\r
, height_(codec_context_->height)\r
, file_frame_number_(0)\r
- , fps_(read_fps(*input_->context(), 0.0))\r
+ , fps_(read_fps(input_->context(), 0.0))\r
{\r
}\r
\r
\r
std::shared_ptr<AVFrame> decode(AVPacket& pkt)\r
{\r
- std::shared_ptr<AVFrame> decoded_frame(avcodec_alloc_frame(), av_free);\r
+ std::shared_ptr<AVFrame> frame(avcodec_alloc_frame(), av_free);\r
\r
- int frame_finished = 0;\r
- THROW_ON_ERROR2(avcodec_decode_video2(codec_context_.get(), decoded_frame.get(), &frame_finished, &pkt), "[video_decocer]");\r
+ int got_frame = 0;\r
+ THROW_ON_ERROR2(avcodec_decode_video2(codec_context_.get(), frame.get(), &got_frame, &pkt), "[video_decocer]");\r
\r
// If a decoder consumes less then the whole packet then something is wrong\r
// that might be just harmless padding at the end, or a problem with the\r
// AVParser or demuxer which puted more then one frame in a AVPacket.\r
\r
- if(frame_finished == 0) \r
+ if(got_frame == 0) \r
return nullptr;\r
\r
- auto stream_time_base = input_->context()->streams[pkt.stream_index]->time_base;\r
+ auto stream_time_base = stream_->time_base;\r
auto packet_frame_number = static_cast<uint32_t>((static_cast<double>(pkt.pts * stream_time_base.num)/stream_time_base.den)*fps_);\r
\r
file_frame_number_ = packet_frame_number;\r
\r
- is_progressive_ = !decoded_frame->interlaced_frame;\r
+ is_progressive_ = !frame->interlaced_frame;\r
\r
- if(decoded_frame->repeat_pict > 0)\r
+ if(frame->repeat_pict > 0)\r
CASPAR_LOG(warning) << "[video_decoder] Field repeat_pict not implemented.";\r
\r
event_subject_ << monitor::event("file/video/width") % width_\r
<< monitor::event("file/video/height") % height_\r
- << monitor::event("file/video/field") % u8(!decoded_frame->interlaced_frame ? "progressive" : (decoded_frame->top_field_first ? "upper" : "lower"))\r
+ << monitor::event("file/video/field") % u8(!frame->interlaced_frame ? "progressive" : (frame->top_field_first ? "upper" : "lower"))\r
<< monitor::event("file/video/codec") % u8(codec_context_->codec->long_name);\r
\r
- return decoded_frame;\r
+ return frame;\r
}\r
\r
uint32_t nb_frames() const\r
SelectObject(static_cast<HDC>(hdc_.get()), bmp_.get()); \r
\r
if(!bmp_data_)\r
- BOOST_THROW_EXCEPTION(std::bad_alloc());\r
+ CASPAR_THROW_EXCEPTION(bad_alloc());\r
}\r
\r
operator HDC() {return static_cast<HDC>(hdc_.get());}\r
: result_(CoInitialize(nullptr))\r
{\r
if(FAILED(result_))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to initialize com-context for flash-player"));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to initialize com-context for flash-player"));\r
}\r
\r
~com_init()\r
graph_->set_color("sync", diagnostics::color(0.8f, 0.3f, 0.2f)); \r
\r
if(FAILED(CComObject<caspar::flash::FlashAxContainer>::CreateInstance(&ax_)))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to create FlashAxContainer"));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to create FlashAxContainer"));\r
\r
ax_->set_print([this]{return print();});\r
\r
if(FAILED(ax_->CreateAxControl()))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to Create FlashAxControl"));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to Create FlashAxControl"));\r
\r
CComPtr<IShockwaveFlash> spFlash;\r
if(FAILED(ax_->QueryControl(&spFlash)))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to Query FlashAxControl"));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to Query FlashAxControl"));\r
\r
if(FAILED(spFlash->put_Playing(true)) )\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to start playing Flash"));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to start playing Flash"));\r
\r
if(FAILED(spFlash->put_Movie(CComBSTR(filename.c_str()))))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to Load Template Host"));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to Load Template Host"));\r
\r
if(FAILED(spFlash->put_ScaleMode(2))) //Exact fit. Scale without respect to the aspect ratio.\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to Set Scale Mode"));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(print() + L" Failed to Set Scale Mode"));\r
\r
ax_->SetSize(width_, height_); \r
\r
CASPAR_LOG(trace) << print() << " Call: " << param;\r
\r
if(!ax_->FlashCall(param, result))\r
- CASPAR_LOG(warning) << print() << L" Flash call failed:" << param;//BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Flash function call failed.") << arg_name_info("param") << arg_value_info(narrow(param)));\r
+ CASPAR_LOG(warning) << print() << L" Flash call failed:" << param;//CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Flash function call failed.") << arg_name_info("param") << arg_value_info(narrow(param)));\r
graph_->set_tag("param");\r
\r
return result;\r
auto filename = env::template_folder() + L"\\" + template_host.filename;\r
\r
if(!boost::filesystem::exists(filename))\r
- BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(u8(filename))); \r
+ CASPAR_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(u8(filename))); \r
\r
return create_destroy_proxy(spl::make_shared<flash_producer>(frame_factory, format_desc, filename, template_host.width, template_host.height));\r
}\r
std::vector<char> decompress_one_file(const std::vector<char>& in_data, uLong buf_size = 5000000)\r
{\r
if(buf_size > 300*1000000)\r
- BOOST_THROW_EXCEPTION(file_read_error());\r
+ CASPAR_THROW_EXCEPTION(file_read_error());\r
\r
std::vector<char> out_data(buf_size, 0);\r
\r
return decompress_one_file(in_data, buf_size*2);\r
\r
if(ret != Z_OK)\r
- BOOST_THROW_EXCEPTION(file_read_error());\r
+ CASPAR_THROW_EXCEPTION(file_read_error());\r
\r
out_data.resize(buf_size);\r
\r
auto file = std::fstream(filename, std::ios::in | std::ios::binary);\r
\r
if(!file)\r
- BOOST_THROW_EXCEPTION(file_read_error());\r
+ CASPAR_THROW_EXCEPTION(file_read_error());\r
\r
char head[4] = {};\r
file.read(head, 3);\r
auto end_it = std::find_end(beg_it, data.end(), end_str.begin(), end_str.end());\r
\r
if(beg_it == data.end() || end_it == data.end())\r
- BOOST_THROW_EXCEPTION(file_read_error());\r
+ CASPAR_THROW_EXCEPTION(file_read_error());\r
\r
return std::string(beg_it, end_it+end_str.size());\r
}\r
std::shared_ptr<FIBITMAP> load_image(const std::wstring& filename)\r
{\r
if(!boost::filesystem::exists(filename))\r
- BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(u8(filename)));\r
+ CASPAR_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(u8(filename)));\r
\r
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeU(filename.c_str(), 0); \r
if(fif == FIF_UNKNOWN || !FreeImage_FIFSupportsReading(fif)) \r
- BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format."));\r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format."));\r
\r
auto bitmap = std::shared_ptr<FIBITMAP>(FreeImage_LoadU(fif, filename.c_str(), 0), FreeImage_Unload);\r
\r
{\r
bitmap = std::shared_ptr<FIBITMAP>(FreeImage_ConvertTo32Bits(bitmap.get()), FreeImage_Unload);\r
if(!bitmap)\r
- BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format.")); \r
+ CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format.")); \r
}\r
\r
return bitmap;\r
device_ = alcOpenDevice(nullptr);\r
\r
if(!device_)\r
- BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to initialize audio device."));\r
+ CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to initialize audio device."));\r
\r
context_ = alcCreateContext(device_, nullptr);\r
\r
if(!context_)\r
- BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to create audio context."));\r
+ CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to create audio context."));\r
\r
if(alcMakeContextCurrent(context_) == ALC_FALSE)\r
- BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to activate audio context."));\r
+ CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to activate audio context."));\r
}\r
\r
~device()\r
window_.SetActive();\r
\r
if(!GLEW_VERSION_2_1 && glewInit() != GLEW_OK)\r
- BOOST_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to initialize GLEW."));\r
+ CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to initialize GLEW."));\r
\r
if(!GLEW_VERSION_2_1)\r
- BOOST_THROW_EXCEPTION(not_supported() << msg_info("Missing OpenGL 2.1 support."));\r
+ CASPAR_THROW_EXCEPTION(not_supported() << msg_info("Missing OpenGL 2.1 support."));\r
\r
GL(glEnable(GL_TEXTURE_2D));\r
GL(glDisable(GL_DEPTH_TEST)); \r
\r
bool ChannelGridCommand::DoExecute()\r
{\r
- BOOST_THROW_EXCEPTION(not_implemented());\r
+ CASPAR_THROW_EXCEPTION(not_implemented());\r
\r
//int index = 1;\r
//auto self = GetChannels().back();\r
auto result = GetChannel()->stage().call(GetLayerIndex(), boost::trim_copy(param));\r
\r
if(!result.timed_wait(boost::posix_time::seconds(2)))\r
- BOOST_THROW_EXCEPTION(timed_out());\r
+ CASPAR_THROW_EXCEPTION(timed_out());\r
\r
std::wstringstream replyString;\r
if(result.get().empty())\r
// { \r
// std::wstring fullFilename = flash::flash_producer::find_template(server::template_folder() + templatename);\r
// if(fullFilename.empty())\r
-// BOOST_THROW_EXCEPTION(file_not_found());\r
+// CASPAR_THROW_EXCEPTION(file_not_found());\r
// \r
// std::wstring extension = boost::filesystem::wpath(fullFilename).extension();\r
// std::wstring filename = templatename;\r
pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), _parameters);\r
\r
if(pFP == frame_producer::empty())\r
- BOOST_THROW_EXCEPTION(file_not_found() << msg_info(_parameters.size() > 0 ? _parameters[0] : L""));\r
+ CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(_parameters.size() > 0 ? _parameters[0] : L""));\r
\r
bool auto_play = std::find(_parameters.begin(), _parameters.end(), L"AUTO") != _parameters.end();\r
\r
{ \r
auto format_desc = video_format_desc(xml_channel.second.get(L"video-mode", L"PAL")); \r
if(format_desc.format == video_format::invalid)\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Invalid video-mode."));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Invalid video-mode."));\r
\r
auto channel = spl::make_shared<video_channel>(static_cast<int>(channels_.size()+1), format_desc, accelerator_.create_image_mixer());\r
\r
else if(boost::iequals(name, L"CLOCK"))\r
return spl::make_shared<CLK::CLKProtocolStrategy>(channels_);\r
\r
- BOOST_THROW_EXCEPTION(caspar_exception() << arg_name_info(L"name") << arg_value_info(name) << msg_info(L"Invalid protocol"));\r
+ CASPAR_THROW_EXCEPTION(caspar_exception() << arg_name_info(L"name") << arg_value_info(name) << msg_info(L"Invalid protocol"));\r
}\r
};\r
\r