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 "media/base/android/video_decoder_job.h" | 5 #include "media/base/android/video_decoder_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "media/base/android/media_codec_bridge.h" | 10 #include "media/base/android/media_codec_bridge.h" |
11 #include "media/base/android/media_drm_bridge.h" | 11 #include "media/base/android/media_drm_bridge.h" |
12 | 12 |
13 namespace media { | 13 namespace media { |
14 | 14 |
15 class VideoDecoderThread : public base::Thread { | 15 class VideoDecoderThread : public base::Thread { |
16 public: | 16 public: |
17 VideoDecoderThread() : base::Thread("MediaSource_VideoDecoderThread") { | 17 VideoDecoderThread() : base::Thread("MediaSource_VideoDecoderThread") { |
18 Start(); | 18 Start(); |
19 } | 19 } |
20 }; | 20 }; |
21 | 21 |
22 // TODO(qinmin): Check if it is tolerable to use worker pool to handle all the | 22 // TODO(qinmin): Check if it is tolerable to use worker pool to handle all the |
23 // decoding tasks so that we don't need a global thread here. | 23 // decoding tasks so that we don't need a global thread here. |
24 // http://crbug.com/245750 | 24 // http://crbug.com/245750 |
25 base::LazyInstance<VideoDecoderThread>::Leaky | 25 base::LazyInstance<VideoDecoderThread>::Leaky |
26 g_video_decoder_thread = LAZY_INSTANCE_INITIALIZER; | 26 g_video_decoder_thread = LAZY_INSTANCE_INITIALIZER; |
27 | 27 |
28 VideoDecoderJob::VideoDecoderJob( | 28 VideoDecoderJob::VideoDecoderJob( |
29 const base::Closure& request_data_cb, | 29 const base::Closure& request_data_cb, |
30 const base::Closure& request_resources_cb, | |
31 const base::Closure& on_demuxer_config_changed_cb, | 30 const base::Closure& on_demuxer_config_changed_cb, |
32 FrameStatistics* frame_statistics) | 31 FrameStatistics* frame_statistics) |
33 : MediaDecoderJob(g_video_decoder_thread.Pointer()->task_runner(), | 32 : MediaDecoderJob(g_video_decoder_thread.Pointer()->task_runner(), |
34 request_data_cb, | 33 request_data_cb, |
35 on_demuxer_config_changed_cb, | 34 on_demuxer_config_changed_cb, |
36 frame_statistics), | 35 frame_statistics), |
37 video_codec_(kUnknownVideoCodec), | 36 video_codec_(kUnknownVideoCodec), |
38 config_width_(0), | 37 config_width_(0), |
39 config_height_(0), | 38 config_height_(0), |
40 output_width_(0), | 39 output_width_(0), |
41 output_height_(0), | 40 output_height_(0) { |
42 request_resources_cb_(request_resources_cb) { | |
43 } | 41 } |
44 | 42 |
45 VideoDecoderJob::~VideoDecoderJob() {} | 43 VideoDecoderJob::~VideoDecoderJob() {} |
46 | 44 |
47 bool VideoDecoderJob::SetVideoSurface(gfx::ScopedJavaSurface surface) { | 45 bool VideoDecoderJob::SetVideoSurface(gfx::ScopedJavaSurface surface) { |
48 // For an empty surface, always pass it to the |media_codec_bridge_| job so | 46 // For an empty surface, always pass it to the |media_codec_bridge_| job so |
49 // that it can detach from the current one. Otherwise, don't pass an | 47 // that it can detach from the current one. Otherwise, don't pass an |
50 // unprotected surface if the video content requires a protected one. | 48 // unprotected surface if the video content requires a protected one. |
51 if (!surface.IsEmpty() && IsProtectedSurfaceRequired() && | 49 if (!surface.IsEmpty() && IsProtectedSurfaceRequired() && |
52 !surface.is_protected()) { | 50 !surface.is_protected()) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 bool is_secure = is_content_encrypted() && drm_bridge() && | 134 bool is_secure = is_content_encrypted() && drm_bridge() && |
137 drm_bridge()->IsProtectedSurfaceRequired(); | 135 drm_bridge()->IsProtectedSurfaceRequired(); |
138 | 136 |
139 media_codec_bridge_.reset(VideoCodecBridge::CreateDecoder( | 137 media_codec_bridge_.reset(VideoCodecBridge::CreateDecoder( |
140 video_codec_, is_secure, gfx::Size(config_width_, config_height_), | 138 video_codec_, is_secure, gfx::Size(config_width_, config_height_), |
141 surface_.j_surface().obj(), GetMediaCrypto().obj())); | 139 surface_.j_surface().obj(), GetMediaCrypto().obj())); |
142 | 140 |
143 if (!media_codec_bridge_) | 141 if (!media_codec_bridge_) |
144 return STATUS_FAILURE; | 142 return STATUS_FAILURE; |
145 | 143 |
146 request_resources_cb_.Run(); | |
147 return STATUS_SUCCESS; | 144 return STATUS_SUCCESS; |
148 } | 145 } |
149 | 146 |
150 bool VideoDecoderJob::UpdateOutputFormat() { | 147 bool VideoDecoderJob::UpdateOutputFormat() { |
151 if (!media_codec_bridge_) | 148 if (!media_codec_bridge_) |
152 return false; | 149 return false; |
153 int prev_output_width = output_width_; | 150 int prev_output_width = output_width_; |
154 int prev_output_height = output_height_; | 151 int prev_output_height = output_height_; |
155 // See b/18224769. The values reported from MediaCodecBridge::GetOutputFormat | 152 // See b/18224769. The values reported from MediaCodecBridge::GetOutputFormat |
156 // correspond to the actual video frame size, but this is not necessarily the | 153 // correspond to the actual video frame size, but this is not necessarily the |
157 // size that should be output. | 154 // size that should be output. |
158 output_width_ = config_width_; | 155 output_width_ = config_width_; |
159 output_height_ = config_height_; | 156 output_height_ = config_height_; |
160 return (output_width_ != prev_output_width) || | 157 return (output_width_ != prev_output_width) || |
161 (output_height_ != prev_output_height); | 158 (output_height_ != prev_output_height); |
162 } | 159 } |
163 | 160 |
164 bool VideoDecoderJob::IsProtectedSurfaceRequired() { | 161 bool VideoDecoderJob::IsProtectedSurfaceRequired() { |
165 return is_content_encrypted() && drm_bridge() && | 162 return is_content_encrypted() && drm_bridge() && |
166 drm_bridge()->IsProtectedSurfaceRequired(); | 163 drm_bridge()->IsProtectedSurfaceRequired(); |
167 } | 164 } |
168 | 165 |
169 } // namespace media | 166 } // namespace media |
OLD | NEW |