Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/rtc_video_decoder_factory.h" | 5 #include "content/renderer/media/rtc_video_decoder_factory.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/renderer/media/rtc_video_decoder.h" | 9 #include "content/renderer/media/rtc_video_decoder.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 RTCVideoDecoderFactory::RTCVideoDecoderFactory( | 13 RTCVideoDecoderFactory::RTCVideoDecoderFactory( |
| 14 const scoped_refptr<base::MessageLoopProxy>& vda_loop_proxy, | |
| 14 const scoped_refptr<media::GpuVideoDecoder::Factories>& gpu_factories) | 15 const scoped_refptr<media::GpuVideoDecoder::Factories>& gpu_factories) |
| 15 : vda_loop_proxy_(gpu_factories->GetMessageLoop()) { | 16 : vda_loop_proxy_(vda_loop_proxy), gpu_factories_(gpu_factories) { |
| 16 DVLOG(2) << "RTCVideoDecoderFactory"; | 17 DVLOG(2) << "RTCVideoDecoderFactory"; |
| 17 // The decoder cannot be created in CreateVideoDecoder because VDA has to be | |
| 18 // created on |vda_loop_proxy_|, which can be the child thread. The child | |
| 19 // thread is blocked when CreateVideoDecoder runs. This supports only one | |
| 20 // VDA-powered <video> tag at a time. | |
| 21 // TODO(wuchengli): remove this restriction. | |
|
Ami GONE FROM CHROMIUM
2013/07/22 19:46:21
Yay!
wuchengli
2013/07/23 16:29:28
:)
| |
| 22 // |decoder_| can be null if VDA does not support VP8. | |
| 23 decoder_ = RTCVideoDecoder::Create(gpu_factories); | |
| 24 } | 18 } |
| 25 | 19 |
| 26 RTCVideoDecoderFactory::~RTCVideoDecoderFactory() { | 20 RTCVideoDecoderFactory::~RTCVideoDecoderFactory() { |
| 27 DVLOG(2) << "~RTCVideoDecoderFactory"; | 21 DVLOG(2) << "~RTCVideoDecoderFactory"; |
| 28 if (decoder_) { | |
| 29 webrtc::VideoDecoder* decoder = decoder_.release(); | |
| 30 if (!vda_loop_proxy_->DeleteSoon(FROM_HERE, decoder)) | |
| 31 delete decoder; | |
| 32 } | |
| 33 } | 22 } |
| 34 | 23 |
| 35 webrtc::VideoDecoder* RTCVideoDecoderFactory::CreateVideoDecoder( | 24 webrtc::VideoDecoder* RTCVideoDecoderFactory::CreateVideoDecoder( |
| 36 webrtc::VideoCodecType type) { | 25 webrtc::VideoCodecType type) { |
| 37 DVLOG(2) << "CreateVideoDecoder"; | 26 DVLOG(2) << "CreateVideoDecoder"; |
| 38 // Only VP8 is supported. | 27 // RendererGpuVideoDecoderFactories is not thread safe. It cannot be shared |
| 39 if (type == webrtc::kVideoCodecVP8) | 28 // by different decoders. This method runs on Chrome_libJingle_WorkerThread |
| 40 return decoder_.release(); | 29 // and the child thread is blocked while this runs. We cannot create new gpu |
| 41 return NULL; | 30 // factories here. Clone one instead. |
| 31 scoped_ptr<RTCVideoDecoder> decoder = | |
| 32 RTCVideoDecoder::Create(type, vda_loop_proxy_, gpu_factories_->Clone()); | |
|
scherkus (not reviewing)
2013/07/22 17:56:40
Considering this is a problem unique to content/ a
wuchengli
2013/07/23 16:29:28
Done. That's what I wasn't sure about in https://c
| |
| 33 return decoder.release(); | |
| 42 } | 34 } |
| 43 | 35 |
| 44 void RTCVideoDecoderFactory::DestroyVideoDecoder( | 36 void RTCVideoDecoderFactory::DestroyVideoDecoder( |
| 45 webrtc::VideoDecoder* decoder) { | 37 webrtc::VideoDecoder* decoder) { |
| 46 DVLOG(2) << "DestroyVideoDecoder"; | 38 DVLOG(2) << "DestroyVideoDecoder"; |
| 47 // Save back the decoder because it is the only one. VideoDecoder::Release | 39 if (!vda_loop_proxy_->DeleteSoon(FROM_HERE, decoder)) |
|
Ami GONE FROM CHROMIUM
2013/07/22 19:46:21
You might enjoy
https://plus.sandbox.google.com/10
wuchengli
2013/07/23 16:29:28
Haha. I copied the anti-pattern from other places.
| |
| 48 // should have been called. | 40 delete decoder; |
| 49 decoder->RegisterDecodeCompleteCallback(NULL); | |
| 50 decoder_.reset(decoder); | |
| 51 } | 41 } |
| 52 | 42 |
| 53 } // namespace content | 43 } // namespace content |
| OLD | NEW |