#include <tbb/parallel_invoke.h>\r
\r
#include <deque>\r
+#include <functional>\r
\r
namespace caspar { namespace core { namespace ffmpeg{\r
\r
struct ffmpeg_producer : public frame_producer\r
{\r
- safe_ptr<diagnostics::graph> graph_;\r
+ const std::wstring filename_;\r
+ const bool loop_;\r
+ printer parent_printer_;\r
+ \r
+ std::shared_ptr<diagnostics::graph> graph_;\r
timer perf_timer_;\r
-\r
- input input_; \r
+ \r
std::unique_ptr<audio_decoder> audio_decoder_;\r
std::unique_ptr<video_decoder> video_decoder_;\r
\r
std::deque<std::vector<short>> audio_chunk_channel_;\r
\r
std::queue<safe_ptr<draw_frame>> ouput_channel_;\r
- \r
- const std::wstring filename_;\r
- \r
+ \r
safe_ptr<draw_frame> last_frame_;\r
std::shared_ptr<frame_factory> frame_factory_;\r
\r
+ std::unique_ptr<input> input_; \r
public:\r
explicit ffmpeg_producer(const std::wstring& filename, bool loop) \r
- : graph_(diagnostics::create_graph("ffmpeg"))\r
- , filename_(filename)\r
+ : filename_(filename)\r
+ , loop_(loop) \r
, last_frame_(draw_frame(draw_frame::empty()))\r
- , input_(graph_, filename, loop)\r
- {\r
- graph_->add_guide("frame_time_target", 0.5, diagnostics::color(0.5f, 0.0f, 0.0f));\r
- graph_->set_color("frame_time", diagnostics::color(1.0f, 0.0f, 0.0f));\r
- }\r
-\r
- ~ffmpeg_producer()\r
+ \r
{\r
- CASPAR_LOG(info) << print() << " closing.";\r
+ graph_ = diagnostics::create_graph(boost::bind(&ffmpeg_producer::print, this)); \r
+ graph_->guide("frame-time", 0.5);\r
+ graph_->set_color("frame-time", diagnostics::color(1.0f, 0.0f, 0.0f));\r
}\r
-\r
+ \r
virtual void initialize(const safe_ptr<frame_factory>& frame_factory)\r
{\r
frame_factory_ = frame_factory;\r
- video_decoder_.reset(input_.get_video_codec_context().get() ? new video_decoder(input_.get_video_codec_context().get(), frame_factory) : nullptr);\r
- audio_decoder_.reset(input_.get_audio_codec_context().get() ? new audio_decoder(input_.get_audio_codec_context().get(), frame_factory->get_video_format_desc().fps) : nullptr);\r
+ input_.reset(new input(safe_ptr<diagnostics::graph>(graph_), filename_, loop_, std::bind(&ffmpeg_producer::print, this)));\r
+ video_decoder_.reset(input_->get_video_codec_context().get() ? new video_decoder(input_->get_video_codec_context().get(), frame_factory) : nullptr);\r
+ audio_decoder_.reset(input_->get_audio_codec_context().get() ? new audio_decoder(input_->get_audio_codec_context().get(), frame_factory->get_video_format_desc().fps) : nullptr);\r
}\r
\r
+ virtual void set_parent_printer(const printer& parent_printer) \r
+ {\r
+ parent_printer_ = parent_printer;\r
+ }\r
+\r
virtual safe_ptr<draw_frame> receive()\r
{\r
perf_timer_.reset();\r
\r
- while(ouput_channel_.empty() && !input_.is_eof())\r
+ while(ouput_channel_.empty() && !input_->is_eof())\r
{ \r
aligned_buffer video_packet;\r
if(video_frame_channel_.size() < 3 && video_decoder_) \r
- video_packet = input_.get_video_packet(); \r
+ video_packet = input_->get_video_packet(); \r
\r
aligned_buffer audio_packet;\r
if(audio_chunk_channel_.size() < 3 && audio_decoder_) \r
- audio_packet = input_.get_audio_packet(); \r
+ audio_packet = input_->get_audio_packet(); \r
\r
tbb::parallel_invoke(\r
[&]\r
try\r
{\r
auto frame = video_decoder_->execute(video_packet);\r
+ frame->tag(reinterpret_cast<int>(this));\r
video_frame_channel_.push_back(std::move(frame));\r
}\r
catch(...)\r
return last_frame_; \r
}\r
\r
- graph_->update("frame_time", static_cast<float>(perf_timer_.elapsed()/frame_factory_->get_video_format_desc().interval*0.5));\r
+ graph_->update("frame-time", static_cast<float>(perf_timer_.elapsed()/frame_factory_->get_video_format_desc().interval*0.5));\r
\r
auto result = last_frame_;\r
if(!ouput_channel_.empty())\r
last_frame_->get_audio_transform().set_gain(0.0); // last_frame should not have audio\r
ouput_channel_.pop();\r
}\r
- else if(input_.is_eof())\r
+ else if(input_->is_eof())\r
return draw_frame::eof();\r
\r
return result;\r
\r
virtual std::wstring print() const\r
{\r
- return L"ffmpeg[" + boost::filesystem::wpath(filename_).filename() + L"]";\r
+ return (parent_printer_ ? parent_printer_() + L"/" : L"") + L"ffmpeg[" + boost::filesystem::wpath(filename_).filename() + L"]";\r
}\r
};\r
\r