]> git.sesse.net Git - casparcg/blob - test/mock/mock_frame_producer.h
2.0.0.2:
[casparcg] / test / mock / mock_frame_producer.h
1 #pragma once\r
2 \r
3 #include "mock_frame.h"\r
4 \r
5 #include <core/producer/frame_producer.h>\r
6 #include <common/exception/exceptions.h>\r
7 \r
8 using namespace caspar;\r
9 using namespace caspar::core;\r
10 \r
11 class mock_frame_producer : public frame_producer\r
12 {\r
13 public:\r
14         mock_frame_producer(bool null = false, bool throws = false) \r
15                 : null_(null), throws_(throws), initialized_(false), volume_(100){}\r
16         void set_volume(short volume) { volume_ = volume;}\r
17         gpu_frame_ptr get_frame()\r
18         { \r
19                 if(throws_)\r
20                         BOOST_THROW_EXCEPTION(caspar_exception());\r
21                 if(leading_)\r
22                         return leading_->get_frame();\r
23                 if(!null_)\r
24                         return std::make_shared<mock_frame>(this, volume_);\r
25                 return nullptr;\r
26         }\r
27         std::shared_ptr<frame_producer> get_following_producer() const \r
28         { return following_; }\r
29         void set_leading_producer(const std::shared_ptr<frame_producer>& leading) \r
30         { leading_ = leading; }\r
31         const frame_format_desc& get_frame_format_desc() const\r
32         { \r
33                 static frame_format_desc format;\r
34                 return format;\r
35         }\r
36         void initialize(const frame_factory_ptr& factory)\r
37         {initialized_ = true;}\r
38         void set_following_producer(const std::shared_ptr<frame_producer>& following)\r
39         {following_ = following;}\r
40 \r
41         bool is_initialized() const { return initialized_;}\r
42 private:\r
43         std::shared_ptr<frame_producer> following_;\r
44         std::shared_ptr<frame_producer> leading_;\r
45         bool null_;\r
46         bool throws_;\r
47         bool initialized_;\r
48         short volume_;\r
49 };