• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "media/base/android/video_decoder_job.h"
6 
7 #include "base/bind.h"
8 #include "base/lazy_instance.h"
9 #include "base/threading/thread.h"
10 #include "media/base/android/media_codec_bridge.h"
11 
12 namespace media {
13 
14 class VideoDecoderThread : public base::Thread {
15  public:
VideoDecoderThread()16   VideoDecoderThread() : base::Thread("MediaSource_VideoDecoderThread") {
17     Start();
18   }
19 };
20 
21 // TODO(qinmin): Check if it is tolerable to use worker pool to handle all the
22 // decoding tasks so that we don't need a global thread here.
23 // http://crbug.com/245750
24 base::LazyInstance<VideoDecoderThread>::Leaky
25     g_video_decoder_thread = LAZY_INSTANCE_INITIALIZER;
26 
Create(const VideoCodec video_codec,bool is_secure,const gfx::Size & size,jobject surface,jobject media_crypto,const base::Closure & request_data_cb)27 VideoDecoderJob* VideoDecoderJob::Create(const VideoCodec video_codec,
28                                          bool is_secure,
29                                          const gfx::Size& size,
30                                          jobject surface,
31                                          jobject media_crypto,
32                                          const base::Closure& request_data_cb) {
33   scoped_ptr<VideoCodecBridge> codec(VideoCodecBridge::CreateDecoder(
34       video_codec, is_secure, size, surface, media_crypto));
35   if (codec)
36     return new VideoDecoderJob(codec.Pass(), request_data_cb);
37 
38   LOG(ERROR) << "Failed to create VideoDecoderJob.";
39   return NULL;
40 }
41 
VideoDecoderJob(scoped_ptr<VideoCodecBridge> video_codec_bridge,const base::Closure & request_data_cb)42 VideoDecoderJob::VideoDecoderJob(
43     scoped_ptr<VideoCodecBridge> video_codec_bridge,
44     const base::Closure& request_data_cb)
45     : MediaDecoderJob(g_video_decoder_thread.Pointer()->message_loop_proxy(),
46                       video_codec_bridge.get(), request_data_cb),
47       video_codec_bridge_(video_codec_bridge.Pass()) {
48 }
49 
~VideoDecoderJob()50 VideoDecoderJob::~VideoDecoderJob() {
51 }
52 
ReleaseOutputBuffer(int output_buffer_index,size_t size,bool render_output,const ReleaseOutputCompletionCallback & callback)53 void VideoDecoderJob::ReleaseOutputBuffer(
54     int output_buffer_index,
55     size_t size,
56     bool render_output,
57     const ReleaseOutputCompletionCallback& callback) {
58   video_codec_bridge_->ReleaseOutputBuffer(output_buffer_index, render_output);
59   callback.Run(0u);
60 }
61 
ComputeTimeToRender() const62 bool VideoDecoderJob::ComputeTimeToRender() const {
63   return true;
64 }
65 
66 }  // namespace media
67