OLD | NEW |
---|---|
(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() { CHECK(is_destroyed_); } | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: s/CHECK/DCHECK/ I'm assuming you don't actua
wonsik
2013/05/20 14:02:24
Done.
| |
80 | |
81 const media::AudioDecoderConfig& RTCDemuxerStream::audio_decoder_config() { | |
82 LOG(FATAL) << "Does not support audio."; | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: NOTIMPLEMENTED();
wonsik
2013/05/20 14:02:24
Done.
| |
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() { | |
94 LOG(FATAL) << "Not reachable."; | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: NOTREACHED();
wonsik
2013/05/20 14:02:24
Done.
| |
95 } | |
96 | |
97 void RTCDemuxerStream::QueueBuffer(scoped_refptr<media::DecoderBuffer> buffer, | |
98 const base::Closure& done_cb, | |
99 const gfx::Size& new_size) { | |
100 base::AutoLock lock(lock_); | |
101 if (is_destroyed_) | |
102 return; | |
103 buffer_queue_.push(BufferEntry(buffer, done_cb, new_size)); | |
104 if (buffer) | |
105 frame_rate_tracker_.Update(1); | |
106 DLOG(INFO) << "frame rate received : " << frame_rate_tracker_.units_second(); | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: s/DLOG(INFO)/DVLOG(1)/ here and below. In gen
wonsik
2013/05/20 14:02:24
Done.
| |
107 RunReadCallback_Locked(); | |
108 } | |
109 | |
110 void RTCDemuxerStream::Read(const ReadCB& read_cb) { | |
111 base::AutoLock lock(lock_); | |
112 CHECK(read_cb_.is_null()); | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: s/DCHECK/CHECK/ ?
wonsik
2013/05/20 14:02:24
Done (assuming you meant the other way around :) )
| |
113 // A call to |Read| operation means that |MediaSourceDelegate| is done with | |
114 // the previous buffer. | |
115 if (!pending_done_cb_.is_null()) | |
116 base::ResetAndReturn(&pending_done_cb_).Run(); | |
117 read_cb_ = media::BindToLoop(base::MessageLoopProxy::current(), read_cb); | |
118 RunReadCallback_Locked(); | |
119 } | |
120 | |
121 void RTCDemuxerStream::Destroy() { | |
122 base::AutoLock lock(lock_); | |
123 CHECK(!is_destroyed_); | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: s/CHECK/DCHECK/?
wonsik
2013/05/20 14:02:24
Done.
| |
124 is_destroyed_ = true; | |
125 if (!read_cb_.is_null()) | |
126 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, NULL); | |
127 } | |
128 | |
129 void RTCDemuxerStream::RunReadCallback_Locked() { | |
130 if (read_cb_.is_null() || buffer_queue_.empty()) | |
131 return; | |
132 | |
133 BufferEntry& front = buffer_queue_.front(); | |
134 if (!front.new_size.IsEmpty()) { | |
135 // No VideoFrame actually reaches cc in Google TV case. We just make | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: What does cc refer to? Update the comment ple
wonsik
2013/05/20 14:02:24
Done.
| |
136 // coded_size == visible_rect == natural_size here. | |
137 video_decoder_config_.Initialize(media::kCodecVP8, | |
138 media::VP8PROFILE_MAIN, | |
139 media::VideoFrame::NATIVE_TEXTURE, | |
140 front.new_size, | |
141 gfx::Rect(front.new_size), | |
142 front.new_size, | |
143 NULL, | |
144 0, | |
145 false, | |
146 false); | |
147 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kConfigChanged, NULL); | |
148 front.new_size.SetSize(0, 0); | |
149 return; | |
150 } | |
151 DCHECK(pending_done_cb_.is_null()); | |
152 pending_done_cb_ = front.done_cb; | |
153 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kOk, front.decoder_buffer); | |
154 buffer_queue_.pop(); | |
155 } | |
156 | |
157 // RTCVideoDecoderFactoryTv ---------------------------------------------------- | |
158 | |
159 RTCVideoDecoderFactoryTv::RTCVideoDecoderFactoryTv() {} | |
160 RTCVideoDecoderFactoryTv::~RTCVideoDecoderFactoryTv() {} | |
161 | |
162 webrtc::VideoDecoder* RTCVideoDecoderFactoryTv::CreateVideoDecoder( | |
163 webrtc::VideoCodecType type) { | |
164 base::AutoLock lock(lock_); | |
165 // One decoder at a time! | |
166 if (decoder_) | |
167 return NULL; | |
168 if (type == webrtc::kVideoCodecVP8) { | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: reverse condition and merge with the one abov
wonsik
2013/05/20 14:02:24
Done.
| |
169 decoder_.reset(new RTCVideoDecoderBridgeTv(this)); | |
170 return decoder_.get(); | |
171 } | |
172 // returning NULL will make WebRTC fall back to SW decoder. | |
173 return NULL; | |
174 } | |
175 | |
176 void RTCVideoDecoderFactoryTv::DestroyVideoDecoder( | |
177 webrtc::VideoDecoder* decoder) { | |
178 base::AutoLock lock(lock_); | |
179 CHECK(decoder_.get() == decoder); | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: s/CHECK/DCHECK
wonsik
2013/05/20 14:02:24
Done.
| |
180 decoder_.reset(); | |
181 } | |
182 | |
183 bool RTCVideoDecoderFactoryTv::AcquireDemuxer() { | |
184 base::AutoLock lock(lock_); | |
185 if (is_acquired_) | |
186 return false; | |
187 is_acquired_ = true; | |
188 return true; | |
189 } | |
190 | |
191 void RTCVideoDecoderFactoryTv::ReleaseDemuxer() { | |
192 base::AutoLock lock(lock_); | |
193 CHECK(is_acquired_); | |
acolwell GONE FROM CHROMIUM
2013/05/14 18:17:47
nit: s/CHECK/DCHECK/ here and everywhere else belo
wonsik
2013/05/20 14:02:24
Done.
| |
194 is_acquired_ = false; | |
195 // Clean up internal state as a demuxer. | |
196 init_cb_.Reset(); | |
197 if (stream_) { | |
198 stream_->Destroy(); | |
199 stream_.reset(); | |
200 } | |
201 } | |
202 | |
203 void RTCVideoDecoderFactoryTv::Initialize(media::DemuxerHost*, | |
204 const media::PipelineStatusCB& cb) { | |
205 base::AutoLock lock(lock_); | |
206 init_cb_ = cb; | |
207 if (!stream_) | |
208 base::ResetAndReturn(&init_cb_).Run(media::PIPELINE_OK); | |
209 } | |
210 | |
211 DemuxerStream* RTCVideoDecoderFactoryTv::GetStream(DemuxerStream::Type type) { | |
212 base::AutoLock lock(lock_); | |
213 if (type == DemuxerStream::VIDEO) | |
214 return stream_.get(); | |
215 return NULL; | |
216 } | |
217 | |
218 base::TimeDelta RTCVideoDecoderFactoryTv::GetStartTime() const { | |
219 return base::TimeDelta(); | |
220 } | |
221 | |
222 void RTCVideoDecoderFactoryTv::InitializeStream(const gfx::Size& size) { | |
223 base::AutoLock lock(lock_); | |
224 CHECK(!stream_); | |
225 stream_.reset(new RTCDemuxerStream(size)); | |
226 if (!init_cb_.is_null()) | |
227 base::ResetAndReturn(&init_cb_).Run(media::PIPELINE_OK); | |
228 } | |
229 | |
230 void RTCVideoDecoderFactoryTv::QueueBuffer( | |
231 scoped_refptr<media::DecoderBuffer> buffer, | |
232 const base::Closure& done_cb, | |
233 const gfx::Size& new_size) { | |
234 base::AutoLock lock(lock_); | |
235 CHECK(stream_); | |
236 stream_->QueueBuffer(buffer, done_cb, new_size); | |
237 } | |
238 | |
239 } // namespace content | |
OLD | NEW |