OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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/media/base/videobroadcaster.h" | 11 #include "webrtc/media/base/videobroadcaster.h" |
12 | 12 |
13 #include <limits> | 13 #include <limits> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
17 | 17 |
18 namespace rtc { | 18 namespace rtc { |
19 | 19 |
20 VideoBroadcaster::VideoBroadcaster() { | 20 VideoBroadcaster::VideoBroadcaster() { |
21 thread_checker_.DetachFromThread(); | 21 thread_checker_.DetachFromThread(); |
22 } | 22 } |
23 | 23 |
24 void VideoBroadcaster::AddOrUpdateSink( | 24 void VideoBroadcaster::AddOrUpdateSink( |
25 VideoSinkInterface<cricket::VideoFrame>* sink, | 25 VideoSinkInterface<webrtc::VideoFrame>* sink, |
26 const VideoSinkWants& wants) { | 26 const VideoSinkWants& wants) { |
27 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 27 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
28 RTC_DCHECK(sink != nullptr); | 28 RTC_DCHECK(sink != nullptr); |
29 rtc::CritScope cs(&sinks_and_wants_lock_); | 29 rtc::CritScope cs(&sinks_and_wants_lock_); |
30 VideoSourceBase::AddOrUpdateSink(sink, wants); | 30 VideoSourceBase::AddOrUpdateSink(sink, wants); |
31 UpdateWants(); | 31 UpdateWants(); |
32 } | 32 } |
33 | 33 |
34 void VideoBroadcaster::RemoveSink( | 34 void VideoBroadcaster::RemoveSink( |
35 VideoSinkInterface<cricket::VideoFrame>* sink) { | 35 VideoSinkInterface<webrtc::VideoFrame>* sink) { |
36 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 36 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
37 RTC_DCHECK(sink != nullptr); | 37 RTC_DCHECK(sink != nullptr); |
38 rtc::CritScope cs(&sinks_and_wants_lock_); | 38 rtc::CritScope cs(&sinks_and_wants_lock_); |
39 VideoSourceBase::RemoveSink(sink); | 39 VideoSourceBase::RemoveSink(sink); |
40 UpdateWants(); | 40 UpdateWants(); |
41 } | 41 } |
42 | 42 |
43 bool VideoBroadcaster::frame_wanted() const { | 43 bool VideoBroadcaster::frame_wanted() const { |
44 rtc::CritScope cs(&sinks_and_wants_lock_); | 44 rtc::CritScope cs(&sinks_and_wants_lock_); |
45 return !sink_pairs().empty(); | 45 return !sink_pairs().empty(); |
46 } | 46 } |
47 | 47 |
48 VideoSinkWants VideoBroadcaster::wants() const { | 48 VideoSinkWants VideoBroadcaster::wants() const { |
49 rtc::CritScope cs(&sinks_and_wants_lock_); | 49 rtc::CritScope cs(&sinks_and_wants_lock_); |
50 return current_wants_; | 50 return current_wants_; |
51 } | 51 } |
52 | 52 |
53 void VideoBroadcaster::OnFrame(const cricket::VideoFrame& frame) { | 53 void VideoBroadcaster::OnFrame(const webrtc::VideoFrame& frame) { |
54 rtc::CritScope cs(&sinks_and_wants_lock_); | 54 rtc::CritScope cs(&sinks_and_wants_lock_); |
55 for (auto& sink_pair : sink_pairs()) { | 55 for (auto& sink_pair : sink_pairs()) { |
56 if (sink_pair.wants.rotation_applied && | 56 if (sink_pair.wants.rotation_applied && |
57 frame.rotation() != webrtc::kVideoRotation_0) { | 57 frame.rotation() != webrtc::kVideoRotation_0) { |
58 // Calls to OnFrame are not synchronized with changes to the sink wants. | 58 // Calls to OnFrame are not synchronized with changes to the sink wants. |
59 // When rotation_applied is set to true, one or a few frames may get here | 59 // When rotation_applied is set to true, one or a few frames may get here |
60 // with rotation still pending. Protect sinks that don't expect any | 60 // with rotation still pending. Protect sinks that don't expect any |
61 // pending rotation. | 61 // pending rotation. |
62 LOG(LS_VERBOSE) << "Discarding frame with unexpected rotation."; | 62 LOG(LS_VERBOSE) << "Discarding frame with unexpected rotation."; |
63 continue; | 63 continue; |
64 } | 64 } |
65 if (sink_pair.wants.black_frames) { | 65 if (sink_pair.wants.black_frames) { |
66 sink_pair.sink->OnFrame(cricket::WebRtcVideoFrame( | 66 sink_pair.sink->OnFrame(webrtc::VideoFrame( |
67 GetBlackFrameBuffer(frame.width(), frame.height()), frame.rotation(), | 67 GetBlackFrameBuffer(frame.width(), frame.height()), frame.rotation(), |
68 frame.timestamp_us())); | 68 frame.timestamp_us())); |
69 } else { | 69 } else { |
70 sink_pair.sink->OnFrame(frame); | 70 sink_pair.sink->OnFrame(frame); |
71 } | 71 } |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 void VideoBroadcaster::UpdateWants() { | 75 void VideoBroadcaster::UpdateWants() { |
76 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 76 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 rtc::scoped_refptr<webrtc::I420Buffer> buffer = | 111 rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
112 new RefCountedObject<webrtc::I420Buffer>(width, height); | 112 new RefCountedObject<webrtc::I420Buffer>(width, height); |
113 buffer->SetToBlack(); | 113 buffer->SetToBlack(); |
114 black_frame_buffer_ = buffer; | 114 black_frame_buffer_ = buffer; |
115 } | 115 } |
116 | 116 |
117 return black_frame_buffer_; | 117 return black_frame_buffer_; |
118 } | 118 } |
119 | 119 |
120 } // namespace rtc | 120 } // namespace rtc |
OLD | NEW |