2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG (www.casparcg.com).
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
19 * Author: Robert Nagy, ronag89@gmail.com
\r
22 #include "../stdafx.h"
\r
24 #include "reroute_producer.h"
\r
26 #include <core/producer/frame_producer.h>
\r
27 #include <core/frame/draw_frame.h>
\r
28 #include <core/frame/frame_factory.h>
\r
29 #include <core/frame/pixel_format.h>
\r
30 #include <core/frame/data_frame.h>
\r
32 #include <common/except.h>
\r
33 #include <common/diagnostics/graph.h>
\r
34 #include <common/log.h>
\r
35 #include <common/reactive.h>
\r
39 #include <tbb/concurrent_queue.h>
\r
41 #include <boost/property_tree/ptree.hpp>
\r
42 #include <boost/range/algorithm_ext/push_back.hpp>
\r
46 namespace caspar { namespace reroute {
\r
48 //class reroute_producer : public reactive::observer<spl::shared_ptr<const core::data_frame>>
\r
49 // , public core::frame_producer
\r
51 // const spl::shared_ptr<diagnostics::graph> graph_;
\r
52 // const spl::shared_ptr<core::frame_factory> frame_factory_;
\r
54 // tbb::concurrent_bounded_queue<std::shared_ptr<const core::data_frame>> input_buffer_;
\r
55 // std::queue<core::draw_frame> frame_buffer_;
\r
56 // uint64_t frame_number_;
\r
58 // core::draw_frame last_frame_;
\r
61 // explicit reroute_producer(const spl::shared_ptr<core::frame_factory>& frame_factory)
\r
62 // : frame_factory_(frame_factory)
\r
63 // , frame_number_(0)
\r
64 // , last_frame_(core::draw_frame::empty())
\r
66 // graph_->set_color("late-frame", diagnostics::color(0.6f, 0.3f, 0.3f));
\r
67 // graph_->set_color("dropped-frame", diagnostics::color(0.3f, 0.6f, 0.3f));
\r
68 // graph_->set_text(print());
\r
69 // diagnostics::register_graph(graph_);
\r
71 // input_buffer_.set_capacity(1);
\r
76 // void on_next(const spl::shared_ptr<const core::data_frame>& frame)
\r
78 // if(!input_buffer_.try_push(frame))
\r
79 // graph_->set_tag("dropped-frame");
\r
82 // // frame_producer
\r
84 // virtual core::draw_frame receive(int) override
\r
86 // if(!frame_buffer_.empty())
\r
88 // auto frame = std::move(frame_buffer_.front());
\r
89 // frame_buffer_.pop();
\r
90 // return last_frame_ = frame;
\r
93 // std::shared_ptr<const core::data_frame> read_frame;
\r
94 // if(!input_buffer_.try_pop(read_frame))
\r
96 // graph_->set_tag("late-frame");
\r
97 // return core::draw_frame::late();
\r
100 // frame_number_++;
\r
102 // bool double_speed = std::abs(frame_factory_->video_format_desc().fps / 2.0 - read_frame->frame_rate()) < 0.01;
\r
103 // bool half_speed = std::abs(read_frame->frame_rate() / 2.0 - frame_factory_->video_format_desc().fps) < 0.01;
\r
105 // if(half_speed && frame_number_ % 2 == 0) // Skip frame
\r
106 // return receive(0);
\r
108 // auto frame = frame_factory_->create_frame(this, read_frame->pixel_format_desc());
\r
110 // A_memcpy(frame->image_data(0).begin(), read_frame->image_data().begin(), read_frame->image_data().size());
\r
111 // boost::push_back(frame->audio_data(), read_frame->audio_data());
\r
113 // auto draw_frame = core::draw_frame(std::move(frame));
\r
115 // frame_buffer_.push(draw_frame);
\r
117 // if(double_speed)
\r
118 // frame_buffer_.push(draw_frame);
\r
120 // return receive(0);
\r
123 // virtual core::draw_frame last_frame() const override
\r
125 // return core::draw_frame::still(last_frame_);
\r
128 // virtual std::wstring print() const override
\r
130 // return L"reroute[]";
\r
133 // virtual std::wstring name() const override
\r
135 // return L"reroute";
\r
138 // virtual boost::property_tree::wptree info() const override
\r
140 // boost::property_tree::wptree info;
\r
141 // info.add(L"type", L"rerotue-producer");
\r
146 spl::shared_ptr<core::frame_producer> create_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, core::video_channel& channel)
\r
148 return core::frame_producer::empty();
\r
149 //auto producer = spl::make_shared<reroute_producer>(frame_factory);
\r
150 //o.subscribe(producer);
\r
151 //return core::wrap_producer(producer);
\r