OLD | NEW |
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 CaptureRenderAdapter* CaptureRenderAdapter::Create( | 54 CaptureRenderAdapter* CaptureRenderAdapter::Create( |
55 VideoCapturer* video_capturer) { | 55 VideoCapturer* video_capturer) { |
56 if (!video_capturer) { | 56 if (!video_capturer) { |
57 return NULL; | 57 return NULL; |
58 } | 58 } |
59 CaptureRenderAdapter* return_value = new CaptureRenderAdapter(video_capturer); | 59 CaptureRenderAdapter* return_value = new CaptureRenderAdapter(video_capturer); |
60 return_value->Init(); // Can't fail. | 60 return_value->Init(); // Can't fail. |
61 return return_value; | 61 return return_value; |
62 } | 62 } |
63 | 63 |
64 bool CaptureRenderAdapter::AddRenderer(VideoRenderer* video_renderer) { | 64 void CaptureRenderAdapter::AddRenderer(VideoRenderer* video_renderer) { |
65 if (!video_renderer) { | 65 RTC_DCHECK(video_renderer); |
66 return false; | 66 |
67 } | |
68 rtc::CritScope cs(&capture_crit_); | 67 rtc::CritScope cs(&capture_crit_); |
69 if (IsRendererRegistered(*video_renderer)) { | 68 // This implements set semantics, the same renderer can only be |
70 return false; | 69 // added once. |
71 } | 70 // TODO(nisse): Is this really needed? |
72 video_renderers_.push_back(VideoRendererInfo(video_renderer)); | 71 if (std::find(video_renderers_.begin(), video_renderers_.end(), |
73 return true; | 72 video_renderer) == video_renderers_.end()) |
| 73 video_renderers_.push_back(video_renderer); |
74 } | 74 } |
75 | 75 |
76 bool CaptureRenderAdapter::RemoveRenderer(VideoRenderer* video_renderer) { | 76 void CaptureRenderAdapter::RemoveRenderer(VideoRenderer* video_renderer) { |
77 if (!video_renderer) { | 77 RTC_DCHECK(video_renderer); |
78 return false; | 78 |
79 } | |
80 rtc::CritScope cs(&capture_crit_); | 79 rtc::CritScope cs(&capture_crit_); |
| 80 // TODO(nisse): Switch to using std::list, and use its remove |
| 81 // method. And similarly in VideoTrackRenderers, which this class |
| 82 // mostly duplicates. |
81 for (VideoRenderers::iterator iter = video_renderers_.begin(); | 83 for (VideoRenderers::iterator iter = video_renderers_.begin(); |
82 iter != video_renderers_.end(); ++iter) { | 84 iter != video_renderers_.end(); ++iter) { |
83 if (video_renderer == iter->renderer) { | 85 if (video_renderer == *iter) { |
84 video_renderers_.erase(iter); | 86 video_renderers_.erase(iter); |
85 return true; | 87 break; |
86 } | 88 } |
87 } | 89 } |
88 return false; | |
89 } | 90 } |
90 | 91 |
91 void CaptureRenderAdapter::Init() { | 92 void CaptureRenderAdapter::Init() { |
92 video_capturer_->SignalVideoFrame.connect( | 93 video_capturer_->SignalVideoFrame.connect( |
93 this, | 94 this, |
94 &CaptureRenderAdapter::OnVideoFrame); | 95 &CaptureRenderAdapter::OnVideoFrame); |
95 } | 96 } |
96 | 97 |
97 void CaptureRenderAdapter::OnVideoFrame(VideoCapturer* capturer, | 98 void CaptureRenderAdapter::OnVideoFrame(VideoCapturer* capturer, |
98 const VideoFrame* video_frame) { | 99 const VideoFrame* video_frame) { |
99 rtc::CritScope cs(&capture_crit_); | 100 rtc::CritScope cs(&capture_crit_); |
100 if (video_renderers_.empty()) { | 101 if (video_renderers_.empty()) { |
101 return; | 102 return; |
102 } | 103 } |
103 MaybeSetRenderingSize(video_frame); | |
104 | 104 |
105 for (VideoRenderers::iterator iter = video_renderers_.begin(); | 105 for (auto* renderer : video_renderers_) |
106 iter != video_renderers_.end(); ++iter) { | 106 renderer->RenderFrame(video_frame); |
107 VideoRenderer* video_renderer = iter->renderer; | |
108 video_renderer->RenderFrame(video_frame); | |
109 } | |
110 } | |
111 | |
112 // The renderer_crit_ lock needs to be taken when calling this function. | |
113 void CaptureRenderAdapter::MaybeSetRenderingSize(const VideoFrame* frame) { | |
114 for (VideoRenderers::iterator iter = video_renderers_.begin(); | |
115 iter != video_renderers_.end(); ++iter) { | |
116 const bool new_resolution = iter->render_width != frame->GetWidth() || | |
117 iter->render_height != frame->GetHeight(); | |
118 if (new_resolution) { | |
119 iter->render_width = frame->GetWidth(); | |
120 iter->render_height = frame->GetHeight(); | |
121 } | |
122 } | |
123 } | |
124 | |
125 // The renderer_crit_ lock needs to be taken when calling this function. | |
126 bool CaptureRenderAdapter::IsRendererRegistered( | |
127 const VideoRenderer& video_renderer) const { | |
128 for (VideoRenderers::const_iterator iter = video_renderers_.begin(); | |
129 iter != video_renderers_.end(); ++iter) { | |
130 if (&video_renderer == iter->renderer) { | |
131 return true; | |
132 } | |
133 } | |
134 return false; | |
135 } | 107 } |
136 | 108 |
137 } // namespace cricket | 109 } // namespace cricket |
OLD | NEW |