blob: 32fefdd3b35631d10e52c8149fa34d862bc17d4d [file] [log] [blame]
Per8e16e612016-02-11 15:56:51 +01001/*
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
11#ifndef WEBRTC_MEDIA_BASE_VIDEOBROADCASTER_H_
12#define WEBRTC_MEDIA_BASE_VIDEOBROADCASTER_H_
13
kwibergbfefb032016-05-01 14:53:46 -070014#include <memory>
Pera5092412016-02-12 13:30:57 +010015#include <utility>
16#include <vector>
17
nisseaf916892017-01-10 07:44:26 -080018#include "webrtc/api/video/video_frame.h"
Pera5092412016-02-12 13:30:57 +010019#include "webrtc/media/base/videosinkinterface.h"
perkjd6c39542016-03-17 10:35:23 +010020#include "webrtc/media/base/videosourcebase.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020021#include "webrtc/rtc_base/criticalsection.h"
22#include "webrtc/rtc_base/thread_checker.h"
Pera5092412016-02-12 13:30:57 +010023
24namespace rtc {
25
perkjf0dcfe22016-03-10 18:32:00 +010026// 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.
perkjd6c39542016-03-17 10:35:23 +010032class VideoBroadcaster : public VideoSourceBase,
nisseacd935b2016-11-11 03:55:13 -080033 public VideoSinkInterface<webrtc::VideoFrame> {
Pera5092412016-02-12 13:30:57 +010034 public:
35 VideoBroadcaster();
nisseacd935b2016-11-11 03:55:13 -080036 void AddOrUpdateSink(VideoSinkInterface<webrtc::VideoFrame>* sink,
Pera5092412016-02-12 13:30:57 +010037 const VideoSinkWants& wants) override;
nisseacd935b2016-11-11 03:55:13 -080038 void RemoveSink(VideoSinkInterface<webrtc::VideoFrame>* sink) override;
Pera5092412016-02-12 13:30:57 +010039
40 // Returns true if the next frame will be delivered to at least one sink.
41 bool frame_wanted() const;
42
43 // Returns VideoSinkWants a source is requested to fulfill. They are
44 // aggregated by all VideoSinkWants from all sinks.
45 VideoSinkWants wants() const;
46
nisse6f5a6c32016-09-22 01:25:59 -070047 // This method ensures that if a sink sets rotation_applied == true,
48 // it will never receive a frame with pending rotation. Our caller
49 // may pass in frames without precise synchronization with changes
50 // to the VideoSinkWants.
nisseacd935b2016-11-11 03:55:13 -080051 void OnFrame(const webrtc::VideoFrame& frame) override;
Pera5092412016-02-12 13:30:57 +010052
53 protected:
danilchapa37de392017-09-09 04:17:22 -070054 void UpdateWants() RTC_EXCLUSIVE_LOCKS_REQUIRED(sinks_and_wants_lock_);
nisseefec5902016-06-09 00:31:39 -070055 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& GetBlackFrameBuffer(
danilchapa37de392017-09-09 04:17:22 -070056 int width,
57 int height) RTC_EXCLUSIVE_LOCKS_REQUIRED(sinks_and_wants_lock_);
Pera5092412016-02-12 13:30:57 +010058
59 ThreadChecker thread_checker_;
perkjf0dcfe22016-03-10 18:32:00 +010060 rtc::CriticalSection sinks_and_wants_lock_;
Pera5092412016-02-12 13:30:57 +010061
danilchapa37de392017-09-09 04:17:22 -070062 VideoSinkWants current_wants_ RTC_GUARDED_BY(sinks_and_wants_lock_);
nisseefec5902016-06-09 00:31:39 -070063 rtc::scoped_refptr<webrtc::VideoFrameBuffer> black_frame_buffer_;
Pera5092412016-02-12 13:30:57 +010064};
65
66} // namespace rtc
Per8e16e612016-02-11 15:56:51 +010067
68#endif // WEBRTC_MEDIA_BASE_VIDEOBROADCASTER_H_