3
* Copyright 2004--2011, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* 3. The name of the author may not be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#include "talk/session/phone/webrtcpassthroughrender.h"
30
#include "talk/base/common.h"
31
#include "talk/base/logging.h"
35
class PassthroughStream: public webrtc::VideoRenderCallback {
37
explicit PassthroughStream(const WebRtc_UWord32 stream_id)
38
: stream_id_(stream_id),
41
virtual ~PassthroughStream() {
43
virtual WebRtc_Word32 RenderFrame(const WebRtc_UWord32 stream_id,
44
webrtc::VideoFrame& videoFrame) {
45
talk_base::CritScope cs(&stream_critical_);
46
// Send frame for rendering directly
47
if (running_ && renderer_) {
48
renderer_->RenderFrame(stream_id, videoFrame);
52
WebRtc_Word32 SetRenderer(VideoRenderCallback* renderer) {
53
talk_base::CritScope cs(&stream_critical_);
58
WebRtc_Word32 StartRender() {
59
talk_base::CritScope cs(&stream_critical_);
64
WebRtc_Word32 StopRender() {
65
talk_base::CritScope cs(&stream_critical_);
71
WebRtc_UWord32 stream_id_;
72
VideoRenderCallback* renderer_;
73
talk_base::CriticalSection stream_critical_;
77
WebRtcPassthroughRender::WebRtcPassthroughRender()
81
WebRtcPassthroughRender::~WebRtcPassthroughRender() {
82
while (!stream_render_map_.empty()) {
83
PassthroughStream* stream = stream_render_map_.begin()->second;
84
stream_render_map_.erase(stream_render_map_.begin());
89
webrtc::VideoRenderCallback* WebRtcPassthroughRender::AddIncomingRenderStream(
90
const WebRtc_UWord32 stream_id,
91
const WebRtc_UWord32 zOrder,
92
const float left, const float top,
93
const float right, const float bottom) {
94
talk_base::CritScope cs(&render_critical_);
95
// Stream already exist.
96
if (FindStream(stream_id) != NULL)
99
PassthroughStream* stream = new PassthroughStream(stream_id);
101
stream_render_map_[stream_id] = stream;
105
WebRtc_Word32 WebRtcPassthroughRender::DeleteIncomingRenderStream(
106
const WebRtc_UWord32 stream_id) {
107
talk_base::CritScope cs(&render_critical_);
108
PassthroughStream* stream = FindStream(stream_id);
109
if (stream == NULL) {
113
stream_render_map_.erase(stream_id);
117
WebRtc_Word32 WebRtcPassthroughRender::AddExternalRenderCallback(
118
const WebRtc_UWord32 stream_id,
119
webrtc::VideoRenderCallback* render_object) {
120
talk_base::CritScope cs(&render_critical_);
121
PassthroughStream* stream = FindStream(stream_id);
122
if (stream == NULL) {
125
return stream->SetRenderer(render_object);
128
bool WebRtcPassthroughRender::HasIncomingRenderStream(
129
const WebRtc_UWord32 stream_id) const {
130
return (FindStream(stream_id) != NULL);
133
webrtc::RawVideoType WebRtcPassthroughRender::PreferredVideoType() const {
134
return webrtc::kVideoI420;
137
WebRtc_Word32 WebRtcPassthroughRender::StartRender(
138
const WebRtc_UWord32 stream_id) {
139
talk_base::CritScope cs(&render_critical_);
140
PassthroughStream* stream = FindStream(stream_id);
141
if (stream == NULL) {
144
return stream->StartRender();
147
WebRtc_Word32 WebRtcPassthroughRender::StopRender(
148
const WebRtc_UWord32 stream_id) {
149
talk_base::CritScope cs(&render_critical_);
150
PassthroughStream* stream = FindStream(stream_id);
151
if (stream == NULL) {
154
return stream->StopRender();
157
// TODO: Is it ok to return non-const pointer to PassthroughStream
158
// from this const function FindStream.
159
PassthroughStream* WebRtcPassthroughRender::FindStream(
160
const WebRtc_UWord32 stream_id) const {
161
StreamMap::const_iterator it = stream_render_map_.find(stream_id);
162
if (it == stream_render_map_.end()) {
163
LOG(LS_WARNING) << "Failed to find stream: " << stream_id;
169
} // namespace cricket