- add sources.
[platform/framework/web/crosswalk.git] / src / media / base / android / video_decoder_job.cc
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:
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
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(
34       VideoCodecBridge::Create(video_codec, is_secure));
35   if (codec && codec->Start(video_codec, size, surface, media_crypto))
36     return new VideoDecoderJob(codec.Pass(), request_data_cb);
37
38   LOG(ERROR) << "Failed to create VideoDecoderJob.";
39   return NULL;
40 }
41
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
50 VideoDecoderJob::~VideoDecoderJob() {
51 }
52
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
62 bool VideoDecoderJob::ComputeTimeToRender() const {
63   return true;
64 }
65
66 }  // namespace media