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

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

Issue 1344133002: MediaCodecPlayer implementation - stage 7 (DRM) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mtplayer-drm-prepare
Patch Set: Renamed a variable 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
« no previous file with comments | « media/base/android/media_codec_video_decoder.h ('k') | media/base/android/media_drm_bridge.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/media_codec_video_decoder.h" 5 #include "media/base/android/media_codec_video_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/base/android/media_codec_bridge.h" 9 #include "media/base/android/media_codec_bridge.h"
10 #include "media/base/demuxer_stream.h" 10 #include "media/base/demuxer_stream.h"
11 #include "media/base/timestamp_constants.h" 11 #include "media/base/timestamp_constants.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 namespace { 15 namespace {
16 const int kDelayForStandAloneEOS = 2; // milliseconds 16 const int kDelayForStandAloneEOS = 2; // milliseconds
17 } 17 }
18 18
19 MediaCodecVideoDecoder::MediaCodecVideoDecoder( 19 MediaCodecVideoDecoder::MediaCodecVideoDecoder(
20 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, 20 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
21 const base::Closure& request_data_cb, 21 const base::Closure& request_data_cb,
22 const base::Closure& starvation_cb, 22 const base::Closure& starvation_cb,
23 const base::Closure& decoder_drained_cb, 23 const base::Closure& decoder_drained_cb,
24 const base::Closure& stop_done_cb, 24 const base::Closure& stop_done_cb,
25 const base::Closure& waiting_for_decryption_key_cb,
25 const base::Closure& error_cb, 26 const base::Closure& error_cb,
26 const SetTimeCallback& update_current_time_cb, 27 const SetTimeCallback& update_current_time_cb,
27 const VideoSizeChangedCallback& video_size_changed_cb, 28 const VideoSizeChangedCallback& video_size_changed_cb,
28 const base::Closure& codec_created_cb) 29 const base::Closure& codec_created_cb)
29 : MediaCodecDecoder(media_task_runner, 30 : MediaCodecDecoder(media_task_runner,
30 request_data_cb, 31 request_data_cb,
31 starvation_cb, 32 starvation_cb,
32 decoder_drained_cb, 33 decoder_drained_cb,
33 stop_done_cb, 34 stop_done_cb,
35 waiting_for_decryption_key_cb,
34 error_cb, 36 error_cb,
35 "VideoDecoder"), 37 "VideoDecoder"),
38 is_protected_surface_required_(false),
36 update_current_time_cb_(update_current_time_cb), 39 update_current_time_cb_(update_current_time_cb),
37 video_size_changed_cb_(video_size_changed_cb), 40 video_size_changed_cb_(video_size_changed_cb),
38 codec_created_cb_(codec_created_cb) { 41 codec_created_cb_(codec_created_cb) {
39 } 42 }
40 43
41 MediaCodecVideoDecoder::~MediaCodecVideoDecoder() { 44 MediaCodecVideoDecoder::~MediaCodecVideoDecoder() {
42 DCHECK(media_task_runner_->BelongsToCurrentThread()); 45 DCHECK(media_task_runner_->BelongsToCurrentThread());
43 DVLOG(1) << "VideoDecoder::~VideoDecoder()"; 46 DVLOG(1) << "VideoDecoder::~VideoDecoder()";
44 ReleaseDecoderResources(); 47 ReleaseDecoderResources();
45 } 48 }
(...skipping 13 matching lines...) Expand all
59 62
60 configs_ = configs; 63 configs_ = configs;
61 64
62 if (video_size_.IsEmpty()) { 65 if (video_size_.IsEmpty()) {
63 video_size_ = configs_.video_size; 66 video_size_ = configs_.video_size;
64 media_task_runner_->PostTask( 67 media_task_runner_->PostTask(
65 FROM_HERE, base::Bind(video_size_changed_cb_, video_size_)); 68 FROM_HERE, base::Bind(video_size_changed_cb_, video_size_));
66 } 69 }
67 } 70 }
68 71
72 bool MediaCodecVideoDecoder::IsContentEncrypted() const {
73 // Make sure SetDemuxerConfigs() as been called.
74 DCHECK(configs_.video_codec != kUnknownVideoCodec);
75 return configs_.is_video_encrypted;
76 }
77
69 void MediaCodecVideoDecoder::ReleaseDecoderResources() { 78 void MediaCodecVideoDecoder::ReleaseDecoderResources() {
70 DCHECK(media_task_runner_->BelongsToCurrentThread()); 79 DCHECK(media_task_runner_->BelongsToCurrentThread());
71 DVLOG(1) << class_name() << "::" << __FUNCTION__; 80 DVLOG(1) << class_name() << "::" << __FUNCTION__;
72 81
73 DoEmergencyStop(); 82 DoEmergencyStop();
74 83
75 ReleaseMediaCodec(); 84 ReleaseMediaCodec();
76 85
77 surface_ = gfx::ScopedJavaSurface(); 86 surface_ = gfx::ScopedJavaSurface();
78 } 87 }
(...skipping 15 matching lines...) Expand all
94 103
95 needs_reconfigure_ = true; 104 needs_reconfigure_ = true;
96 } 105 }
97 106
98 bool MediaCodecVideoDecoder::HasVideoSurface() const { 107 bool MediaCodecVideoDecoder::HasVideoSurface() const {
99 DCHECK(media_task_runner_->BelongsToCurrentThread()); 108 DCHECK(media_task_runner_->BelongsToCurrentThread());
100 109
101 return !surface_.IsEmpty(); 110 return !surface_.IsEmpty();
102 } 111 }
103 112
113 void MediaCodecVideoDecoder::SetProtectedSurfaceRequired(bool value) {
114 DCHECK(media_task_runner_->BelongsToCurrentThread());
115
116 is_protected_surface_required_ = value;
117 }
118
119 bool MediaCodecVideoDecoder::IsProtectedSurfaceRequired() const {
120 DCHECK(media_task_runner_->BelongsToCurrentThread());
121
122 return is_protected_surface_required_;
123 }
124
104 bool MediaCodecVideoDecoder::IsCodecReconfigureNeeded( 125 bool MediaCodecVideoDecoder::IsCodecReconfigureNeeded(
105 const DemuxerConfigs& next) const { 126 const DemuxerConfigs& next) const {
106 if (always_reconfigure_for_tests_) 127 if (always_reconfigure_for_tests_)
107 return true; 128 return true;
108 129
109 if (configs_.video_codec != next.video_codec || 130 if (configs_.video_codec != next.video_codec ||
110 configs_.is_video_encrypted != next.is_video_encrypted) { 131 configs_.is_video_encrypted != next.is_video_encrypted) {
111 return true; 132 return true;
112 } 133 }
113 134
114 // Only size changes below this point 135 // Only size changes below this point
115 136
116 if (configs_.video_size.width() == next.video_size.width() && 137 if (configs_.video_size.width() == next.video_size.width() &&
117 configs_.video_size.height() == next.video_size.height()) { 138 configs_.video_size.height() == next.video_size.height()) {
118 return false; // i.e. configs_ == next 139 return false; // i.e. configs_ == next
119 } 140 }
120 141
121 return !static_cast<VideoCodecBridge*>(media_codec_bridge_.get()) 142 return !static_cast<VideoCodecBridge*>(media_codec_bridge_.get())
122 ->IsAdaptivePlaybackSupported(next.video_size.width(), 143 ->IsAdaptivePlaybackSupported(next.video_size.width(),
123 next.video_size.height()); 144 next.video_size.height());
124 } 145 }
125 146
126 MediaCodecDecoder::ConfigStatus MediaCodecVideoDecoder::ConfigureInternal() { 147 MediaCodecDecoder::ConfigStatus MediaCodecVideoDecoder::ConfigureInternal(
148 jobject media_crypto) {
127 DCHECK(media_task_runner_->BelongsToCurrentThread()); 149 DCHECK(media_task_runner_->BelongsToCurrentThread());
128 150
129 DVLOG(1) << class_name() << "::" << __FUNCTION__; 151 DVLOG(1) << class_name() << "::" << __FUNCTION__;
130 152
131 // If we cannot find a key frame in cache, the browser seek is needed. 153 // If we cannot find a key frame in cache, the browser seek is needed.
132 if (!au_queue_.RewindToLastKeyFrame()) { 154 if (!au_queue_.RewindToLastKeyFrame()) {
133 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " key frame required"; 155 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " key frame required";
134 return kConfigKeyFrameRequired; 156 return kConfigKeyFrameRequired;
135 } 157 }
136 158
137 if (configs_.video_codec == kUnknownVideoCodec) { 159 if (configs_.video_codec == kUnknownVideoCodec) {
138 DVLOG(0) << class_name() << "::" << __FUNCTION__ 160 DVLOG(0) << class_name() << "::" << __FUNCTION__
139 << " configuration parameters are required"; 161 << ": configuration parameters are required";
140 return kConfigFailure; 162 return kConfigFailure;
141 } 163 }
142 164
143 // TODO(timav): implement DRM.
144 // bool is_secure = is_content_encrypted() && drm_bridge() &&
145 // drm_bridge()->IsProtectedSurfaceRequired();
146
147 bool is_secure = false; // DRM is not implemented
148
149 if (surface_.IsEmpty()) { 165 if (surface_.IsEmpty()) {
150 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " surface required"; 166 DVLOG(0) << class_name() << "::" << __FUNCTION__ << ": surface is required";
151 return kConfigFailure; 167 return kConfigFailure;
152 } 168 }
153 169
170 bool is_secure = IsContentEncrypted() && is_protected_surface_required_;
171
154 media_codec_bridge_.reset(VideoCodecBridge::CreateDecoder( 172 media_codec_bridge_.reset(VideoCodecBridge::CreateDecoder(
155 configs_.video_codec, 173 configs_.video_codec,
156 is_secure, 174 is_secure,
157 configs_.video_size, 175 configs_.video_size,
158 surface_.j_surface().obj(), 176 surface_.j_surface().obj(),
159 GetMediaCrypto().obj())); 177 media_crypto));
160 178
161 if (!media_codec_bridge_) { 179 if (!media_codec_bridge_) {
162 DVLOG(0) << class_name() << "::" << __FUNCTION__ 180 DVLOG(0) << class_name() << "::" << __FUNCTION__
163 << " failed: cannot create video codec"; 181 << " failed: cannot create video codec";
164 return kConfigFailure; 182 return kConfigFailure;
165 } 183 }
166 184
167 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " succeeded"; 185 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " succeeded";
168 186
169 media_task_runner_->PostTask(FROM_HERE, codec_created_cb_); 187 media_task_runner_->PostTask(FROM_HERE, codec_created_cb_);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 338
321 // |update_current_time_cb_| might be null if there is audio stream. 339 // |update_current_time_cb_| might be null if there is audio stream.
322 // Do not update current time for stand-alone EOS frames. 340 // Do not update current time for stand-alone EOS frames.
323 if (!update_current_time_cb_.is_null() && update_time) { 341 if (!update_current_time_cb_.is_null() && update_time) {
324 media_task_runner_->PostTask( 342 media_task_runner_->PostTask(
325 FROM_HERE, base::Bind(update_current_time_cb_, pts, pts, false)); 343 FROM_HERE, base::Bind(update_current_time_cb_, pts, pts, false));
326 } 344 }
327 } 345 }
328 346
329 } // namespace media 347 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_codec_video_decoder.h ('k') | media/base/android/media_drm_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698