Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: media/base/android/video_decoder_job.cc

Issue 1372203002: Throttle media decoding after excessive Android media server crashes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 : MediaDecoderJob(g_video_decoder_thread.Pointer()->task_runner(), 31 : MediaDecoderJob(g_video_decoder_thread.Pointer()->task_runner(),
33 request_data_cb, 32 request_data_cb,
34 on_demuxer_config_changed_cb), 33 on_demuxer_config_changed_cb),
35 video_codec_(kUnknownVideoCodec), 34 video_codec_(kUnknownVideoCodec),
36 config_width_(0), 35 config_width_(0),
37 config_height_(0), 36 config_height_(0),
38 output_width_(0), 37 output_width_(0),
39 output_height_(0), 38 output_height_(0) {
40 request_resources_cb_(request_resources_cb) {
41 } 39 }
42 40
43 VideoDecoderJob::~VideoDecoderJob() {} 41 VideoDecoderJob::~VideoDecoderJob() {}
44 42
45 bool VideoDecoderJob::SetVideoSurface(gfx::ScopedJavaSurface surface) { 43 bool VideoDecoderJob::SetVideoSurface(gfx::ScopedJavaSurface surface) {
46 // For an empty surface, always pass it to the |media_codec_bridge_| job so 44 // For an empty surface, always pass it to the |media_codec_bridge_| job so
47 // that it can detach from the current one. Otherwise, don't pass an 45 // that it can detach from the current one. Otherwise, don't pass an
48 // unprotected surface if the video content requires a protected one. 46 // unprotected surface if the video content requires a protected one.
49 if (!surface.IsEmpty() && IsProtectedSurfaceRequired() && 47 if (!surface.IsEmpty() && IsProtectedSurfaceRequired() &&
50 !surface.is_protected()) { 48 !surface.is_protected()) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 bool is_secure = is_content_encrypted() && drm_bridge() && 132 bool is_secure = is_content_encrypted() && drm_bridge() &&
135 drm_bridge()->IsProtectedSurfaceRequired(); 133 drm_bridge()->IsProtectedSurfaceRequired();
136 134
137 media_codec_bridge_.reset(VideoCodecBridge::CreateDecoder( 135 media_codec_bridge_.reset(VideoCodecBridge::CreateDecoder(
138 video_codec_, is_secure, gfx::Size(config_width_, config_height_), 136 video_codec_, is_secure, gfx::Size(config_width_, config_height_),
139 surface_.j_surface().obj(), GetMediaCrypto().obj())); 137 surface_.j_surface().obj(), GetMediaCrypto().obj()));
140 138
141 if (!media_codec_bridge_) 139 if (!media_codec_bridge_)
142 return STATUS_FAILURE; 140 return STATUS_FAILURE;
143 141
144 request_resources_cb_.Run();
145 return STATUS_SUCCESS; 142 return STATUS_SUCCESS;
146 } 143 }
147 144
148 bool VideoDecoderJob::UpdateOutputFormat() { 145 bool VideoDecoderJob::UpdateOutputFormat() {
149 if (!media_codec_bridge_) 146 if (!media_codec_bridge_)
150 return false; 147 return false;
151 int prev_output_width = output_width_; 148 int prev_output_width = output_width_;
152 int prev_output_height = output_height_; 149 int prev_output_height = output_height_;
153 // See b/18224769. The values reported from MediaCodecBridge::GetOutputFormat 150 // See b/18224769. The values reported from MediaCodecBridge::GetOutputFormat
154 // correspond to the actual video frame size, but this is not necessarily the 151 // correspond to the actual video frame size, but this is not necessarily the
155 // size that should be output. 152 // size that should be output.
156 output_width_ = config_width_; 153 output_width_ = config_width_;
157 output_height_ = config_height_; 154 output_height_ = config_height_;
158 return (output_width_ != prev_output_width) || 155 return (output_width_ != prev_output_width) ||
159 (output_height_ != prev_output_height); 156 (output_height_ != prev_output_height);
160 } 157 }
161 158
162 bool VideoDecoderJob::IsProtectedSurfaceRequired() { 159 bool VideoDecoderJob::IsProtectedSurfaceRequired() {
163 return is_content_encrypted() && drm_bridge() && 160 return is_content_encrypted() && drm_bridge() &&
164 drm_bridge()->IsProtectedSurfaceRequired(); 161 drm_bridge()->IsProtectedSurfaceRequired();
165 } 162 }
166 163
167 } // namespace media 164 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698