Per | 8e16e61 | 2016-02-11 15:56:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MEDIA_BASE_VIDEOBROADCASTER_H_ |
| 12 | #define MEDIA_BASE_VIDEOBROADCASTER_H_ |
Per | 8e16e61 | 2016-02-11 15:56:51 +0100 | [diff] [blame] | 13 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 14 | #include <memory> |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 15 | #include <utility> |
| 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/video/video_frame.h" |
Niels Möller | c6ce9c5 | 2018-05-11 11:15:30 +0200 | [diff] [blame^] | 19 | #include "api/video/video_sink_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "media/base/videosourcebase.h" |
| 21 | #include "rtc_base/criticalsection.h" |
| 22 | #include "rtc_base/thread_checker.h" |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 23 | |
| 24 | namespace rtc { |
| 25 | |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 26 | // VideoBroadcaster broadcast video frames to sinks and combines |
| 27 | // VideoSinkWants from its sinks. It does that by implementing |
| 28 | // rtc::VideoSourceInterface and rtc::VideoSinkInterface. |
| 29 | // Sinks must be added and removed on one and only one thread. |
| 30 | // Video frames can be broadcasted on any thread. I.e VideoBroadcaster::OnFrame |
| 31 | // can be called on any thread. |
perkj | d6c3954 | 2016-03-17 10:35:23 +0100 | [diff] [blame] | 32 | class VideoBroadcaster : public VideoSourceBase, |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 33 | public VideoSinkInterface<webrtc::VideoFrame> { |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 34 | public: |
| 35 | VideoBroadcaster(); |
Paulina Hensman | a680a6a | 2018-04-05 11:42:24 +0200 | [diff] [blame] | 36 | ~VideoBroadcaster() override; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 37 | void AddOrUpdateSink(VideoSinkInterface<webrtc::VideoFrame>* sink, |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 38 | const VideoSinkWants& wants) override; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 39 | void RemoveSink(VideoSinkInterface<webrtc::VideoFrame>* sink) override; |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 40 | |
| 41 | // Returns true if the next frame will be delivered to at least one sink. |
| 42 | bool frame_wanted() const; |
| 43 | |
| 44 | // Returns VideoSinkWants a source is requested to fulfill. They are |
| 45 | // aggregated by all VideoSinkWants from all sinks. |
| 46 | VideoSinkWants wants() const; |
| 47 | |
nisse | 6f5a6c3 | 2016-09-22 01:25:59 -0700 | [diff] [blame] | 48 | // This method ensures that if a sink sets rotation_applied == true, |
| 49 | // it will never receive a frame with pending rotation. Our caller |
| 50 | // may pass in frames without precise synchronization with changes |
| 51 | // to the VideoSinkWants. |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 52 | void OnFrame(const webrtc::VideoFrame& frame) override; |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 53 | |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 54 | void OnDiscardedFrame() override; |
| 55 | |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 56 | protected: |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 57 | void UpdateWants() RTC_EXCLUSIVE_LOCKS_REQUIRED(sinks_and_wants_lock_); |
nisse | efec590 | 2016-06-09 00:31:39 -0700 | [diff] [blame] | 58 | const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& GetBlackFrameBuffer( |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 59 | int width, |
| 60 | int height) RTC_EXCLUSIVE_LOCKS_REQUIRED(sinks_and_wants_lock_); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 61 | |
| 62 | ThreadChecker thread_checker_; |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 63 | rtc::CriticalSection sinks_and_wants_lock_; |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 64 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 65 | VideoSinkWants current_wants_ RTC_GUARDED_BY(sinks_and_wants_lock_); |
nisse | efec590 | 2016-06-09 00:31:39 -0700 | [diff] [blame] | 66 | rtc::scoped_refptr<webrtc::VideoFrameBuffer> black_frame_buffer_; |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace rtc |
Per | 8e16e61 | 2016-02-11 15:56:51 +0100 | [diff] [blame] | 70 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 71 | #endif // MEDIA_BASE_VIDEOBROADCASTER_H_ |