Chromium Code Reviews| 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/bind_to_loop.h" | |
| 10 #include "media/base/decoder_buffer.h" | |
| 11 #include "third_party/libjingle/source/talk/base/ratetracker.h" | |
| 12 | |
| 13 using media::DemuxerStream; | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 // RTCDemuxerStream ------------------------------------------------------------ | |
| 18 | |
| 19 class RTCDemuxerStream : public DemuxerStream { | |
| 20 public: | |
| 21 explicit RTCDemuxerStream(const gfx::Size& size); | |
| 22 virtual ~RTCDemuxerStream(); | |
| 23 | |
| 24 // DemuxerStream implementation. | |
| 25 virtual void Read(const ReadCB& read_cb) OVERRIDE; | |
| 26 virtual const media::AudioDecoderConfig& audio_decoder_config() OVERRIDE; | |
| 27 virtual const media::VideoDecoderConfig& video_decoder_config() OVERRIDE; | |
| 28 virtual Type type() OVERRIDE; | |
| 29 virtual void EnableBitstreamConverter() OVERRIDE; | |
| 30 | |
| 31 void QueueBuffer(scoped_refptr<media::DecoderBuffer> buffer, | |
| 32 const base::Closure& done_cb, | |
| 33 const gfx::Size& new_size); | |
| 34 void Destroy(); | |
| 35 | |
| 36 private: | |
| 37 struct BufferEntry { | |
| 38 BufferEntry(const scoped_refptr<media::DecoderBuffer>& decoder_buffer_param, | |
| 39 const base::Closure& done_cb_param, | |
| 40 const gfx::Size& new_size_param) | |
| 41 : decoder_buffer(decoder_buffer_param), | |
| 42 done_cb(done_cb_param), | |
| 43 new_size(new_size_param) {} | |
| 44 | |
| 45 scoped_refptr<media::DecoderBuffer> decoder_buffer; | |
| 46 base::Closure done_cb; | |
| 47 // When |!new_size.isEmpty()|, it means that config change with new size | |
| 48 // |new_size| happened. | |
| 49 gfx::Size new_size; | |
| 50 }; | |
| 51 | |
| 52 void RunReadCallback_Locked(); | |
| 53 | |
| 54 base::Lock lock_; | |
| 55 bool is_destroyed_; | |
| 56 std::queue<BufferEntry> buffer_queue_; | |
| 57 ReadCB read_cb_; | |
| 58 base::Closure pending_done_cb_; | |
| 59 | |
| 60 media::AudioDecoderConfig dummy_audio_decoder_config_; | |
| 61 media::VideoDecoderConfig video_decoder_config_; | |
| 62 talk_base::RateTracker frame_rate_tracker_; | |
| 63 }; | |
| 64 | |
| 65 RTCDemuxerStream::RTCDemuxerStream(const gfx::Size& size) | |
| 66 : is_destroyed_(false), | |
| 67 video_decoder_config_(media::kCodecVP8, | |
| 68 media::VP8PROFILE_MAIN, | |
| 69 media::VideoFrame::NATIVE_TEXTURE, | |
| 70 size, | |
| 71 gfx::Rect(size), | |
| 72 size, | |
| 73 NULL, | |
| 74 0, | |
| 75 false) {} | |
| 76 | |
| 77 RTCDemuxerStream::~RTCDemuxerStream() { | |
| 78 CHECK(is_destroyed_); | |
| 79 } | |
| 80 | |
| 81 const media::AudioDecoderConfig& RTCDemuxerStream::audio_decoder_config() { | |
| 82 LOG(FATAL) << "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() { | |
| 92 return DemuxerStream::VIDEO; | |
| 93 } | |
| 94 | |
| 95 void RTCDemuxerStream::EnableBitstreamConverter() { | |
| 96 LOG(FATAL) << "Not reachable."; | |
| 97 } | |
| 98 | |
| 99 void RTCDemuxerStream::QueueBuffer(scoped_refptr<media::DecoderBuffer> buffer, | |
| 100 const base::Closure& done_cb, | |
| 101 const gfx::Size& new_size) { | |
| 102 base::AutoLock lock(lock_); | |
| 103 if (is_destroyed_) | |
| 104 return; | |
| 105 buffer_queue_.push(BufferEntry(buffer, done_cb, new_size)); | |
| 106 if (buffer) | |
| 107 frame_rate_tracker_.Update(1); | |
| 108 DLOG(INFO) << "frame rate received : " << frame_rate_tracker_.units_second(); | |
| 109 RunReadCallback_Locked(); | |
| 110 } | |
| 111 | |
| 112 void RTCDemuxerStream::Read(const ReadCB& read_cb) { | |
| 113 base::AutoLock lock(lock_); | |
| 114 CHECK(read_cb_.is_null()); | |
| 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() { | |
|
dwkang1
2013/05/14 07:57:48
Could you check if this method is being used?
wonsik
2013/05/14 12:53:57
Done; it is called at RTCVideoDecoderFactoryTv::Re
| |
| 124 base::AutoLock lock(lock_); | |
| 125 CHECK(!is_destroyed_); | |
| 126 is_destroyed_ = true; | |
| 127 if (!read_cb_.is_null()) | |
| 128 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, NULL); | |
| 129 } | |
| 130 | |
| 131 void RTCDemuxerStream::RunReadCallback_Locked() { | |
| 132 if (read_cb_.is_null() || buffer_queue_.empty()) | |
| 133 return; | |
| 134 | |
| 135 BufferEntry& front = buffer_queue_.front(); | |
| 136 if (!front.new_size.IsEmpty()) { | |
| 137 // No VideoFrame actually reaches cc in Google TV case. We just make | |
| 138 // coded_size == visible_rect == natural_size here. | |
| 139 video_decoder_config_.Initialize(media::kCodecVP8, | |
| 140 media::VP8PROFILE_MAIN, | |
| 141 media::VideoFrame::NATIVE_TEXTURE, | |
| 142 front.new_size, | |
| 143 gfx::Rect(front.new_size), | |
| 144 front.new_size, | |
| 145 NULL, | |
| 146 0, | |
| 147 false, | |
| 148 false); | |
| 149 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kConfigChanged, NULL); | |
| 150 front.new_size.SetSize(0, 0); | |
| 151 return; | |
| 152 } | |
| 153 DCHECK(pending_done_cb_.is_null()); | |
| 154 pending_done_cb_ = front.done_cb; | |
| 155 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kOk, front.decoder_buffer); | |
|
dwkang1
2013/05/14 07:57:48
This method can be called from QueueBuffer() which
wonsik
2013/05/14 12:53:57
read_cb_ is bound to the calling thread's message
| |
| 156 buffer_queue_.pop(); | |
| 157 } | |
| 158 | |
| 159 // RTCVideoDecoderFactoryTv ---------------------------------------------------- | |
| 160 | |
| 161 RTCVideoDecoderFactoryTv::RTCVideoDecoderFactoryTv() {} | |
| 162 | |
| 163 webrtc::VideoDecoder* RTCVideoDecoderFactoryTv::CreateVideoDecoder( | |
| 164 webrtc::VideoCodecType type) { | |
| 165 base::AutoLock lock(lock_); | |
| 166 // One decoder at a time! | |
| 167 if (decoder_) | |
| 168 return NULL; | |
| 169 if (type == webrtc::kVideoCodecVP8) { | |
| 170 decoder_.reset(new RTCVideoDecoderBridgeTv(this)); | |
| 171 return decoder_.get(); | |
| 172 } | |
| 173 // returning NULL will make WebRTC fall back to SW decoder. | |
| 174 return NULL; | |
| 175 } | |
| 176 | |
| 177 void RTCVideoDecoderFactoryTv::DestroyVideoDecoder( | |
| 178 webrtc::VideoDecoder* decoder) { | |
| 179 base::AutoLock lock(lock_); | |
| 180 CHECK(decoder_.get() == decoder); | |
| 181 decoder_.reset(); | |
| 182 } | |
| 183 | |
| 184 bool RTCVideoDecoderFactoryTv::AcquireDemuxer() { | |
| 185 base::AutoLock lock(lock_); | |
| 186 if (is_acquired_) | |
| 187 return false; | |
| 188 is_acquired_ = true; | |
| 189 return true; | |
| 190 } | |
| 191 | |
| 192 void RTCVideoDecoderFactoryTv::ReleaseDemuxer() { | |
| 193 base::AutoLock lock(lock_); | |
| 194 CHECK(is_acquired_); | |
| 195 is_acquired_ = false; | |
| 196 // Clean up internal state as a demuxer. | |
| 197 init_cb_.Reset(); | |
| 198 if (stream_) { | |
| 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 } | |
| 208 | |
| 209 DemuxerStream* RTCVideoDecoderFactoryTv::GetStream( | |
| 210 DemuxerStream::Type type) { | |
| 211 base::AutoLock lock(lock_); | |
| 212 if (type == DemuxerStream::VIDEO) | |
| 213 return stream_.get(); | |
| 214 return NULL; | |
| 215 } | |
| 216 | |
| 217 void RTCVideoDecoderFactoryTv::UpdateSize(const gfx::Size& new_size) { | |
|
dwkang1
2013/05/14 07:57:48
This method looks doing more then update size. How
wonsik
2013/05/14 12:53:57
Done.
| |
| 218 base::AutoLock lock(lock_); | |
| 219 CHECK(!stream_); | |
| 220 stream_.reset(new RTCDemuxerStream(new_size)); | |
| 221 DCHECK(!init_cb_.is_null()); | |
|
dwkang1
2013/05/14 07:57:48
Is there a good way to see Initialize() will be ca
wonsik
2013/05/14 12:53:57
The order is not deterministic --- made it work bo
| |
| 222 base::ResetAndReturn(&init_cb_).Run(media::PIPELINE_OK); | |
| 223 } | |
| 224 | |
| 225 void RTCVideoDecoderFactoryTv::QueueBuffer( | |
| 226 scoped_refptr<media::DecoderBuffer> buffer, | |
| 227 const base::Closure& done_cb, | |
| 228 const gfx::Size& new_size) { | |
| 229 base::AutoLock lock(lock_); | |
| 230 CHECK(stream_); | |
| 231 stream_->QueueBuffer(buffer, done_cb, new_size); | |
| 232 } | |
| 233 | |
| 234 base::TimeDelta RTCVideoDecoderFactoryTv::GetStartTime() const { | |
| 235 return base::TimeDelta(); | |
| 236 } | |
| 237 | |
| 238 } // namespace content | |
| OLD | NEW |