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

Side by Side Diff: content/renderer/media/rtc_video_decoder_factory_tv.cc

Issue 14247018: Implement WebRTC in Chrome for TV (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Aaron's comments Created 7 years, 7 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/renderer/media/rtc_video_decoder_factory_tv.h"
6
7 #include "base/callback_helpers.h"
8 #include "content/renderer/media/rtc_video_decoder_bridge_tv.h"
9 #include "media/base/audio_decoder_config.h"
10 #include "media/base/bind_to_loop.h"
11 #include "media/base/decoder_buffer.h"
12 #include "media/base/video_decoder_config.h"
13 #include "third_party/libjingle/source/talk/base/ratetracker.h"
14
15 using media::DemuxerStream;
16
17 namespace content {
18
19 // RTCDemuxerStream ------------------------------------------------------------
20
21 class RTCDemuxerStream : public DemuxerStream {
22 public:
23 explicit RTCDemuxerStream(const gfx::Size& size);
24 virtual ~RTCDemuxerStream();
25
26 // DemuxerStream implementation.
27 virtual void Read(const ReadCB& read_cb) OVERRIDE;
28 virtual const media::AudioDecoderConfig& audio_decoder_config() OVERRIDE;
29 virtual const media::VideoDecoderConfig& video_decoder_config() OVERRIDE;
30 virtual Type type() OVERRIDE;
31 virtual void EnableBitstreamConverter() OVERRIDE;
32
33 void QueueBuffer(scoped_refptr<media::DecoderBuffer> buffer,
34 const base::Closure& done_cb,
35 const gfx::Size& new_size);
36 void Destroy();
37
38 private:
39 struct BufferEntry {
40 BufferEntry(const scoped_refptr<media::DecoderBuffer>& decoder_buffer_param,
41 const base::Closure& done_cb_param,
42 const gfx::Size& new_size_param)
43 : decoder_buffer(decoder_buffer_param),
44 done_cb(done_cb_param),
45 new_size(new_size_param) {}
46
47 scoped_refptr<media::DecoderBuffer> decoder_buffer;
48 base::Closure done_cb;
49 // When |!new_size.isEmpty()|, it means that config change with new size
50 // |new_size| happened.
51 gfx::Size new_size;
52 };
53
54 void RunReadCallback_Locked();
55
56 base::Lock lock_;
57 bool is_destroyed_;
58 std::queue<BufferEntry> buffer_queue_;
59 ReadCB read_cb_;
60 base::Closure pending_done_cb_;
61
62 media::AudioDecoderConfig dummy_audio_decoder_config_;
63 media::VideoDecoderConfig video_decoder_config_;
64 talk_base::RateTracker frame_rate_tracker_;
65 };
66
67 RTCDemuxerStream::RTCDemuxerStream(const gfx::Size& size)
68 : is_destroyed_(false),
69 video_decoder_config_(media::kCodecVP8,
70 media::VP8PROFILE_MAIN,
71 media::VideoFrame::NATIVE_TEXTURE,
72 size,
73 gfx::Rect(size),
74 size,
75 NULL,
76 0,
77 false) {}
78
79 RTCDemuxerStream::~RTCDemuxerStream() { DCHECK(is_destroyed_); }
80
81 const media::AudioDecoderConfig& RTCDemuxerStream::audio_decoder_config() {
82 NOTIMPLEMENTED() << "Does not support audio.";
83 return dummy_audio_decoder_config_;
84 }
85
86 const media::VideoDecoderConfig& RTCDemuxerStream::video_decoder_config() {
87 base::AutoLock lock(lock_);
88 return video_decoder_config_;
89 }
90
91 DemuxerStream::Type RTCDemuxerStream::type() { return DemuxerStream::VIDEO; }
92
93 void RTCDemuxerStream::EnableBitstreamConverter() { NOTREACHED(); }
94
95 void RTCDemuxerStream::QueueBuffer(scoped_refptr<media::DecoderBuffer> buffer,
96 const base::Closure& done_cb,
97 const gfx::Size& new_size) {
98 base::AutoLock lock(lock_);
99 if (is_destroyed_)
100 return;
101 buffer_queue_.push(BufferEntry(buffer, done_cb, new_size));
102 if (buffer)
103 frame_rate_tracker_.Update(1);
104 DVLOG(1) << "frame rate received : " << frame_rate_tracker_.units_second();
105 RunReadCallback_Locked();
106 }
107
108 void RTCDemuxerStream::Read(const ReadCB& read_cb) {
109 base::AutoLock lock(lock_);
110 DCHECK(read_cb_.is_null());
111 if (is_destroyed_) {
112 read_cb.Run(DemuxerStream::kAborted, NULL);
acolwell GONE FROM CHROMIUM 2013/05/21 15:51:47 s/read_cb/media::BindToLoop(base::MessageLoopProxy
wonsik 2013/05/22 07:56:10 Done.
113 return;
114 }
115 // A call to |Read| operation means that |MediaSourceDelegate| is done with
116 // the previous buffer.
117 if (!pending_done_cb_.is_null())
118 base::ResetAndReturn(&pending_done_cb_).Run();
119 read_cb_ = media::BindToLoop(base::MessageLoopProxy::current(), read_cb);
120 RunReadCallback_Locked();
121 }
122
123 void RTCDemuxerStream::Destroy() {
124 base::AutoLock lock(lock_);
125 DCHECK(!is_destroyed_);
126 is_destroyed_ = true;
127 if (!read_cb_.is_null())
128 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, NULL);
129 pending_done_cb_.Reset();
130 while (!buffer_queue_.empty())
131 buffer_queue_.pop();
132 }
133
134 void RTCDemuxerStream::RunReadCallback_Locked() {
135 if (read_cb_.is_null() || buffer_queue_.empty())
136 return;
137
138 BufferEntry& front = buffer_queue_.front();
139 if (!front.new_size.IsEmpty()) {
140 // No VideoFrame actually reaches GL renderer in Google TV case. We just
141 // make coded_size == visible_rect == natural_size here.
142 video_decoder_config_.Initialize(media::kCodecVP8,
143 media::VP8PROFILE_MAIN,
144 media::VideoFrame::NATIVE_TEXTURE,
145 front.new_size,
146 gfx::Rect(front.new_size),
147 front.new_size,
148 NULL,
149 0,
150 false,
151 false);
152 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kConfigChanged, NULL);
153 front.new_size.SetSize(0, 0);
154 return;
155 }
156 DCHECK(pending_done_cb_.is_null());
157 pending_done_cb_ = front.done_cb;
158 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kOk, front.decoder_buffer);
159 buffer_queue_.pop();
160 }
161
162 // RTCVideoDecoderFactoryTv ----------------------------------------------------
163
164 RTCVideoDecoderFactoryTv::RTCVideoDecoderFactoryTv() : is_acquired_(false) {}
165 RTCVideoDecoderFactoryTv::~RTCVideoDecoderFactoryTv() {}
166
167 webrtc::VideoDecoder* RTCVideoDecoderFactoryTv::CreateVideoDecoder(
168 webrtc::VideoCodecType type) {
169 base::AutoLock lock(lock_);
170 // One decoder at a time!
171 if (decoder_)
172 return NULL;
173 // Only VP8 is supported --- returning NULL will make WebRTC fall back to SW
174 // decoder.
175 if (type != webrtc::kVideoCodecVP8)
176 return NULL;
177 decoder_.reset(new RTCVideoDecoderBridgeTv(this));
178 return decoder_.get();
179 }
180
181 void RTCVideoDecoderFactoryTv::DestroyVideoDecoder(
182 webrtc::VideoDecoder* decoder) {
183 base::AutoLock lock(lock_);
184 DCHECK(decoder_.get() == decoder);
185 decoder_.reset();
186 }
187
188 bool RTCVideoDecoderFactoryTv::AcquireDemuxer() {
189 base::AutoLock lock(lock_);
190 if (is_acquired_)
191 return false;
192 is_acquired_ = true;
193 return true;
194 }
195
196 void RTCVideoDecoderFactoryTv::ReleaseDemuxer() {
197 base::AutoLock lock(lock_);
198 DCHECK(is_acquired_);
199 is_acquired_ = false;
200 // Clean up internal state as a demuxer.
201 init_cb_.Reset();
202 if (stream_) {
203 stream_->Destroy();
204 stream_.reset();
205 }
206 }
207
208 void RTCVideoDecoderFactoryTv::Initialize(media::DemuxerHost*,
209 const media::PipelineStatusCB& cb) {
210 base::AutoLock lock(lock_);
211 init_cb_ = cb;
acolwell GONE FROM CHROMIUM 2013/05/21 15:51:47 nit: I believe you should use media::BindToLoop(ba
wonsik 2013/05/22 07:56:10 Done.
212 if (stream_)
213 base::ResetAndReturn(&init_cb_).Run(media::PIPELINE_OK);
214 }
215
216 DemuxerStream* RTCVideoDecoderFactoryTv::GetStream(DemuxerStream::Type type) {
217 base::AutoLock lock(lock_);
218 if (type == DemuxerStream::VIDEO)
219 return stream_.get();
220 return NULL;
221 }
222
223 base::TimeDelta RTCVideoDecoderFactoryTv::GetStartTime() const {
224 return base::TimeDelta();
225 }
226
227 void RTCVideoDecoderFactoryTv::InitializeStream(const gfx::Size& size) {
228 base::AutoLock lock(lock_);
229 DCHECK(!stream_);
230 stream_.reset(new RTCDemuxerStream(size));
231 if (!init_cb_.is_null())
232 base::ResetAndReturn(&init_cb_).Run(media::PIPELINE_OK);
233 }
234
235 void RTCVideoDecoderFactoryTv::QueueBuffer(
236 scoped_refptr<media::DecoderBuffer> buffer,
237 const base::Closure& done_cb,
238 const gfx::Size& new_size) {
239 base::AutoLock lock(lock_);
240 DCHECK(stream_);
241 stream_->QueueBuffer(buffer, done_cb, new_size);
242 }
243
244 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698