Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(583)

Side by Side Diff: talk/app/webrtc/videotrackrenderers.cc

Issue 1631703002: Make WebRtcVideoChannel2::WebRtcVideoSendStream implement rtc::VideoRendererInterface. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix PropagatesInputFrameTimestamp and ProducesIncreasingTimestampsWithResetInputSources. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 18 matching lines...) Expand all
29 #include "talk/media/webrtc/webrtcvideoframe.h" 29 #include "talk/media/webrtc/webrtcvideoframe.h"
30 30
31 namespace webrtc { 31 namespace webrtc {
32 32
33 VideoTrackRenderers::VideoTrackRenderers() : enabled_(true) { 33 VideoTrackRenderers::VideoTrackRenderers() : enabled_(true) {
34 } 34 }
35 35
36 VideoTrackRenderers::~VideoTrackRenderers() { 36 VideoTrackRenderers::~VideoTrackRenderers() {
37 } 37 }
38 38
39 void VideoTrackRenderers::AddRenderer(VideoRendererInterface* renderer) { 39 void VideoTrackRenderers::AddSink(
40 if (!renderer) { 40 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) {
41 if (!sink) {
41 return; 42 return;
42 } 43 }
43 rtc::CritScope cs(&critical_section_); 44 rtc::CritScope cs(&critical_section_);
44 renderers_.insert(renderer); 45 sinks_.insert(sink);
45 } 46 }
46 47
47 void VideoTrackRenderers::RemoveRenderer(VideoRendererInterface* renderer) { 48 void VideoTrackRenderers::RemoveSink(
49 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) {
48 rtc::CritScope cs(&critical_section_); 50 rtc::CritScope cs(&critical_section_);
49 renderers_.erase(renderer); 51 sinks_.erase(sink);
50 } 52 }
51 53
52 void VideoTrackRenderers::SetEnabled(bool enable) { 54 void VideoTrackRenderers::SetEnabled(bool enable) {
53 rtc::CritScope cs(&critical_section_); 55 rtc::CritScope cs(&critical_section_);
54 enabled_ = enable; 56 enabled_ = enable;
55 } 57 }
56 58
57 bool VideoTrackRenderers::RenderFrame(const cricket::VideoFrame* frame) { 59 bool VideoTrackRenderers::RenderFrame(const cricket::VideoFrame* frame) {
58 { 60 {
59 rtc::CritScope cs(&critical_section_); 61 rtc::CritScope cs(&critical_section_);
60 if (enabled_) { 62 if (enabled_) {
61 RenderFrameToRenderers(frame); 63 SendFrameToSinks(*frame);
62 return true; 64 return true;
63 } 65 }
64 } 66 }
65 67
66 // Generate the black frame outside of the critical section. Note 68 // Generate the black frame outside of the critical section. Note
67 // that this may result in unexpected frame order, in the unlikely 69 // that this may result in unexpected frame order, in the unlikely
68 // case that RenderFrame is called from multiple threads without 70 // case that RenderFrame is called from multiple threads without
69 // proper serialization, and the track is switched from disabled to 71 // proper serialization, and the track is switched from disabled to
70 // enabled in the middle of the first call. 72 // enabled in the middle of the first call.
71 cricket::WebRtcVideoFrame black(new rtc::RefCountedObject<I420Buffer>( 73 cricket::WebRtcVideoFrame black(new rtc::RefCountedObject<I420Buffer>(
72 static_cast<int>(frame->GetWidth()), 74 static_cast<int>(frame->GetWidth()),
73 static_cast<int>(frame->GetHeight())), 75 static_cast<int>(frame->GetHeight())),
74 frame->GetTimeStamp(), 76 frame->GetTimeStamp(),
75 frame->GetVideoRotation()); 77 frame->GetVideoRotation());
76 black.SetToBlack(); 78 black.SetToBlack();
77 79
78 { 80 {
79 rtc::CritScope cs(&critical_section_); 81 rtc::CritScope cs(&critical_section_);
80 // Check enabled_ flag again, since the track might have been 82 // Check enabled_ flag again, since the track might have been
81 // enabled while we generated the black frame. I think the 83 // enabled while we generated the black frame. I think the
82 // enabled-ness ought to be applied at the track output, and hence 84 // enabled-ness ought to be applied at the track output, and hence
83 // an enabled track shouldn't send any blacked out frames. 85 // an enabled track shouldn't send any blacked out frames.
84 RenderFrameToRenderers(enabled_ ? frame : &black); 86 SendFrameToSinks(enabled_ ? *frame : black);
85 87
86 return true; 88 return true;
87 } 89 }
88 } 90 }
89 91
90 // Called with critical_section_ already locked 92 // Called with critical_section_ already locked
91 void VideoTrackRenderers::RenderFrameToRenderers( 93 void VideoTrackRenderers::SendFrameToSinks(const cricket::VideoFrame& frame) {
92 const cricket::VideoFrame* frame) { 94 for (auto* sink : sinks_) {
93 for (VideoRendererInterface* renderer : renderers_) { 95 sink->OnFrame(frame);
94 renderer->RenderFrame(frame);
95 } 96 }
96 } 97 }
97 98
98 } // namespace webrtc 99 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698