OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/api/videotrackrenderers.h" | 11 #include "webrtc/api/videotrackrenderers.h" |
12 #include "webrtc/media/webrtc/webrtcvideoframe.h" | 12 #include "webrtc/media/webrtc/webrtcvideoframe.h" |
13 | 13 |
14 namespace webrtc { | 14 namespace webrtc { |
15 | 15 |
16 VideoTrackRenderers::VideoTrackRenderers() : enabled_(true) { | 16 VideoTrackRenderers::VideoTrackRenderers() : enabled_(true) { |
17 } | 17 } |
18 | 18 |
19 VideoTrackRenderers::~VideoTrackRenderers() { | 19 VideoTrackRenderers::~VideoTrackRenderers() { |
20 } | 20 } |
21 | 21 |
22 void VideoTrackRenderers::AddRenderer(VideoRendererInterface* renderer) { | 22 void VideoTrackRenderers::AddOrUpdateSink( |
23 if (!renderer) { | 23 VideoSinkInterface<cricket::VideoFrame>* sink, |
24 return; | 24 const rtc::VideoSinkWants& wants) { |
25 } | |
26 rtc::CritScope cs(&critical_section_); | 25 rtc::CritScope cs(&critical_section_); |
27 renderers_.insert(renderer); | 26 broadcaster_.AddOrUpdateSink(sink, wants); |
perkj_webrtc
2016/02/11 15:30:44
broadcaster_ is single threaded. I am afraid remot
nisse-webrtc
2016/02/12 08:36:03
Ok, I'm going back to not using VideoBroadcaster.
| |
28 } | 27 } |
29 | 28 |
30 void VideoTrackRenderers::RemoveRenderer(VideoRendererInterface* renderer) { | 29 void VideoTrackRenderers::RemoveSink( |
30 VideoSinkInterface<cricket::VideoFrame>* sink) { | |
31 rtc::CritScope cs(&critical_section_); | 31 rtc::CritScope cs(&critical_section_); |
32 renderers_.erase(renderer); | 32 broadcaster_.RemoveSink(sink); |
33 } | 33 } |
34 | 34 |
35 void VideoTrackRenderers::SetEnabled(bool enable) { | 35 void VideoTrackRenderers::SetEnabled(bool enable) { |
36 rtc::CritScope cs(&critical_section_); | 36 rtc::CritScope cs(&critical_section_); |
37 enabled_ = enable; | 37 enabled_ = enable; |
38 } | 38 } |
39 | 39 |
40 bool VideoTrackRenderers::RenderFrame(const cricket::VideoFrame* frame) { | 40 bool VideoTrackRenderers::RenderFrame(const cricket::VideoFrame* frame) { |
41 { | 41 { |
42 rtc::CritScope cs(&critical_section_); | 42 rtc::CritScope cs(&critical_section_); |
43 if (enabled_) { | 43 if (enabled_) { |
44 RenderFrameToRenderers(frame); | 44 broadcaster_.OnFrame(*frame); |
45 return true; | 45 return true; |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 // Generate the black frame outside of the critical section. Note | 49 // Generate the black frame outside of the critical section. Note |
50 // that this may result in unexpected frame order, in the unlikely | 50 // that this may result in unexpected frame order, in the unlikely |
51 // case that RenderFrame is called from multiple threads without | 51 // case that RenderFrame is called from multiple threads without |
52 // proper serialization, and the track is switched from disabled to | 52 // proper serialization, and the track is switched from disabled to |
53 // enabled in the middle of the first call. | 53 // enabled in the middle of the first call. |
54 cricket::WebRtcVideoFrame black(new rtc::RefCountedObject<I420Buffer>( | 54 cricket::WebRtcVideoFrame black(new rtc::RefCountedObject<I420Buffer>( |
55 static_cast<int>(frame->GetWidth()), | 55 static_cast<int>(frame->GetWidth()), |
56 static_cast<int>(frame->GetHeight())), | 56 static_cast<int>(frame->GetHeight())), |
57 frame->GetTimeStamp(), | 57 frame->GetTimeStamp(), |
58 frame->GetVideoRotation()); | 58 frame->GetVideoRotation()); |
59 black.SetToBlack(); | 59 black.SetToBlack(); |
60 | 60 |
61 { | 61 { |
62 rtc::CritScope cs(&critical_section_); | 62 rtc::CritScope cs(&critical_section_); |
63 // Check enabled_ flag again, since the track might have been | 63 // Check enabled_ flag again, since the track might have been |
64 // enabled while we generated the black frame. I think the | 64 // enabled while we generated the black frame. I think the |
65 // enabled-ness ought to be applied at the track output, and hence | 65 // enabled-ness ought to be applied at the track output, and hence |
66 // an enabled track shouldn't send any blacked out frames. | 66 // an enabled track shouldn't send any blacked out frames. |
67 RenderFrameToRenderers(enabled_ ? frame : &black); | 67 broadcaster_.OnFrame(enabled_ ? *frame : black); |
68 | 68 |
69 return true; | 69 return true; |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 // Called with critical_section_ already locked | |
74 void VideoTrackRenderers::RenderFrameToRenderers( | |
75 const cricket::VideoFrame* frame) { | |
76 for (VideoRendererInterface* renderer : renderers_) { | |
77 renderer->RenderFrame(frame); | |
78 } | |
79 } | |
80 | |
81 } // namespace webrtc | 73 } // namespace webrtc |
OLD | NEW |