summaryrefslogtreecommitdiff
path: root/chromium/media/base/android/video_decoder_job.cc
blob: 75124e7d0d7340896ebd91f0ddbc2ebf5996ff38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/base/android/video_decoder_job.h"

#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/threading/thread.h"
#include "media/base/android/media_codec_bridge.h"

namespace media {

class VideoDecoderThread : public base::Thread {
 public:
  VideoDecoderThread() : base::Thread("MediaSource_VideoDecoderThread") {
    Start();
  }
};

// TODO(qinmin): Check if it is tolerable to use worker pool to handle all the
// decoding tasks so that we don't need a global thread here.
// http://crbug.com/245750
base::LazyInstance<VideoDecoderThread>::Leaky
    g_video_decoder_thread = LAZY_INSTANCE_INITIALIZER;

VideoDecoderJob* VideoDecoderJob::Create(const VideoCodec video_codec,
                                         bool is_secure,
                                         const gfx::Size& size,
                                         jobject surface,
                                         jobject media_crypto,
                                         const base::Closure& request_data_cb) {
  scoped_ptr<VideoCodecBridge> codec(VideoCodecBridge::CreateDecoder(
      video_codec, is_secure, size, surface, media_crypto));
  if (codec)
    return new VideoDecoderJob(codec.Pass(), request_data_cb);

  LOG(ERROR) << "Failed to create VideoDecoderJob.";
  return NULL;
}

VideoDecoderJob::VideoDecoderJob(
    scoped_ptr<VideoCodecBridge> video_codec_bridge,
    const base::Closure& request_data_cb)
    : MediaDecoderJob(g_video_decoder_thread.Pointer()->message_loop_proxy(),
                      video_codec_bridge.get(), request_data_cb),
      video_codec_bridge_(video_codec_bridge.Pass()) {
}

VideoDecoderJob::~VideoDecoderJob() {
}

void VideoDecoderJob::ReleaseOutputBuffer(
    int output_buffer_index,
    size_t size,
    bool render_output,
    const ReleaseOutputCompletionCallback& callback) {
  video_codec_bridge_->ReleaseOutputBuffer(output_buffer_index, render_output);
  callback.Run(0u);
}

bool VideoDecoderJob::ComputeTimeToRender() const {
  return true;
}

}  // namespace media