~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/libjingle/talk/session/phone/webrtcpassthroughrender.cc

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libjingle
 
3
 * Copyright 2004--2011, Google Inc.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions are met:
 
7
 *
 
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.
 
15
 *
 
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.
 
26
 */
 
27
 
 
28
#include "talk/session/phone/webrtcpassthroughrender.h"
 
29
 
 
30
#include "talk/base/common.h"
 
31
#include "talk/base/logging.h"
 
32
 
 
33
namespace cricket {
 
34
 
 
35
class PassthroughStream: public webrtc::VideoRenderCallback {
 
36
 public:
 
37
  explicit PassthroughStream(const WebRtc_UWord32 stream_id)
 
38
      : stream_id_(stream_id),
 
39
        running_(false) {
 
40
  }
 
41
  virtual ~PassthroughStream() {
 
42
  }
 
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);
 
49
    }
 
50
    return 0;
 
51
  }
 
52
  WebRtc_Word32 SetRenderer(VideoRenderCallback* renderer) {
 
53
    talk_base::CritScope cs(&stream_critical_);
 
54
    renderer_ = renderer;
 
55
    return 0;
 
56
  }
 
57
 
 
58
  WebRtc_Word32 StartRender() {
 
59
    talk_base::CritScope cs(&stream_critical_);
 
60
    running_ = true;
 
61
    return 0;
 
62
  }
 
63
 
 
64
  WebRtc_Word32 StopRender() {
 
65
    talk_base::CritScope cs(&stream_critical_);
 
66
    running_ = false;
 
67
    return 0;
 
68
  }
 
69
 
 
70
 private:
 
71
  WebRtc_UWord32 stream_id_;
 
72
  VideoRenderCallback* renderer_;
 
73
  talk_base::CriticalSection stream_critical_;
 
74
  bool running_;
 
75
};
 
76
 
 
77
WebRtcPassthroughRender::WebRtcPassthroughRender()
 
78
    : window_(NULL) {
 
79
}
 
80
 
 
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());
 
85
    delete stream;
 
86
  }
 
87
}
 
88
 
 
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)
 
97
    return NULL;
 
98
 
 
99
  PassthroughStream* stream = new PassthroughStream(stream_id);
 
100
  // Store the stream
 
101
  stream_render_map_[stream_id] = stream;
 
102
  return stream;
 
103
}
 
104
 
 
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) {
 
110
    return -1;
 
111
  }
 
112
  delete stream;
 
113
  stream_render_map_.erase(stream_id);
 
114
  return 0;
 
115
}
 
116
 
 
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) {
 
123
    return -1;
 
124
  }
 
125
  return stream->SetRenderer(render_object);
 
126
}
 
127
 
 
128
bool WebRtcPassthroughRender::HasIncomingRenderStream(
 
129
    const WebRtc_UWord32 stream_id) const {
 
130
  return (FindStream(stream_id) != NULL);
 
131
}
 
132
 
 
133
webrtc::RawVideoType WebRtcPassthroughRender::PreferredVideoType() const {
 
134
  return webrtc::kVideoI420;
 
135
}
 
136
 
 
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) {
 
142
    return -1;
 
143
  }
 
144
  return stream->StartRender();
 
145
}
 
146
 
 
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) {
 
152
    return -1;
 
153
  }
 
154
  return stream->StopRender();
 
155
}
 
156
 
 
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;
 
164
    return NULL;
 
165
  }
 
166
  return it->second;
 
167
}
 
168
 
 
169
}  // namespace cricket