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

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: Rebased 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 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& key_required_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 key_required_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 return configs_.is_video_encrypted;
74 }
75
69 void MediaCodecVideoDecoder::ReleaseDecoderResources() { 76 void MediaCodecVideoDecoder::ReleaseDecoderResources() {
70 DCHECK(media_task_runner_->BelongsToCurrentThread()); 77 DCHECK(media_task_runner_->BelongsToCurrentThread());
71 DVLOG(1) << class_name() << "::" << __FUNCTION__; 78 DVLOG(1) << class_name() << "::" << __FUNCTION__;
72 79
73 DoEmergencyStop(); 80 DoEmergencyStop();
74 81
75 ReleaseMediaCodec(); 82 ReleaseMediaCodec();
76 83
77 surface_ = gfx::ScopedJavaSurface(); 84 surface_ = gfx::ScopedJavaSurface();
78 } 85 }
(...skipping 15 matching lines...) Expand all
94 101
95 needs_reconfigure_ = true; 102 needs_reconfigure_ = true;
96 } 103 }
97 104
98 bool MediaCodecVideoDecoder::HasVideoSurface() const { 105 bool MediaCodecVideoDecoder::HasVideoSurface() const {
99 DCHECK(media_task_runner_->BelongsToCurrentThread()); 106 DCHECK(media_task_runner_->BelongsToCurrentThread());
100 107
101 return !surface_.IsEmpty(); 108 return !surface_.IsEmpty();
102 } 109 }
103 110
111 void MediaCodecVideoDecoder::SetProtectedSurfaceRequired(bool value) {
112 DCHECK(media_task_runner_->BelongsToCurrentThread());
113
114 is_protected_surface_required_ = value;
115 }
116
117 bool MediaCodecVideoDecoder::IsProtectedSurfaceRequired() const {
118 DCHECK(media_task_runner_->BelongsToCurrentThread());
119
120 return is_protected_surface_required_;
121 }
122
104 bool MediaCodecVideoDecoder::IsCodecReconfigureNeeded( 123 bool MediaCodecVideoDecoder::IsCodecReconfigureNeeded(
105 const DemuxerConfigs& next) const { 124 const DemuxerConfigs& next) const {
106 if (always_reconfigure_for_tests_) 125 if (always_reconfigure_for_tests_)
107 return true; 126 return true;
108 127
109 if (configs_.video_codec != next.video_codec || 128 if (configs_.video_codec != next.video_codec ||
110 configs_.is_video_encrypted != next.is_video_encrypted) { 129 configs_.is_video_encrypted != next.is_video_encrypted) {
111 return true; 130 return true;
112 } 131 }
113 132
114 // Only size changes below this point 133 // Only size changes below this point
115 134
116 if (configs_.video_size.width() == next.video_size.width() && 135 if (configs_.video_size.width() == next.video_size.width() &&
117 configs_.video_size.height() == next.video_size.height()) { 136 configs_.video_size.height() == next.video_size.height()) {
118 return false; // i.e. configs_ == next 137 return false; // i.e. configs_ == next
119 } 138 }
120 139
121 return !static_cast<VideoCodecBridge*>(media_codec_bridge_.get()) 140 return !static_cast<VideoCodecBridge*>(media_codec_bridge_.get())
122 ->IsAdaptivePlaybackSupported(next.video_size.width(), 141 ->IsAdaptivePlaybackSupported(next.video_size.width(),
123 next.video_size.height()); 142 next.video_size.height());
124 } 143 }
125 144
126 MediaCodecDecoder::ConfigStatus MediaCodecVideoDecoder::ConfigureInternal() { 145 MediaCodecDecoder::ConfigStatus MediaCodecVideoDecoder::ConfigureInternal(
146 jobject media_crypto) {
127 DCHECK(media_task_runner_->BelongsToCurrentThread()); 147 DCHECK(media_task_runner_->BelongsToCurrentThread());
128 148
129 DVLOG(1) << class_name() << "::" << __FUNCTION__; 149 DVLOG(1) << class_name() << "::" << __FUNCTION__;
130 150
131 // If we cannot find a key frame in cache, the browser seek is needed. 151 // If we cannot find a key frame in cache, the browser seek is needed.
132 if (!au_queue_.RewindToLastKeyFrame()) { 152 if (!au_queue_.RewindToLastKeyFrame()) {
133 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " key frame required"; 153 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " key frame required";
134 return kConfigKeyFrameRequired; 154 return kConfigKeyFrameRequired;
135 } 155 }
136 156
137 if (configs_.video_codec == kUnknownVideoCodec) { 157 if (configs_.video_codec == kUnknownVideoCodec) {
138 DVLOG(0) << class_name() << "::" << __FUNCTION__ 158 DVLOG(0) << class_name() << "::" << __FUNCTION__
139 << " configuration parameters are required"; 159 << ": configuration parameters are required";
140 return kConfigFailure; 160 return kConfigFailure;
141 } 161 }
142 162
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()) { 163 if (surface_.IsEmpty()) {
150 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " surface required"; 164 DVLOG(0) << class_name() << "::" << __FUNCTION__ << ": surface is required";
151 return kConfigFailure; 165 return kConfigFailure;
152 } 166 }
153 167
168 bool is_secure = IsContentEncrypted() && is_protected_surface_required_;
169
154 media_codec_bridge_.reset(VideoCodecBridge::CreateDecoder( 170 media_codec_bridge_.reset(VideoCodecBridge::CreateDecoder(
155 configs_.video_codec, 171 configs_.video_codec,
156 is_secure, 172 is_secure,
157 configs_.video_size, 173 configs_.video_size,
158 surface_.j_surface().obj(), 174 surface_.j_surface().obj(),
159 GetMediaCrypto().obj())); 175 media_crypto));
160 176
161 if (!media_codec_bridge_) { 177 if (!media_codec_bridge_) {
162 DVLOG(0) << class_name() << "::" << __FUNCTION__ 178 DVLOG(0) << class_name() << "::" << __FUNCTION__
163 << " failed: cannot create video codec"; 179 << " failed: cannot create video codec";
164 return kConfigFailure; 180 return kConfigFailure;
165 } 181 }
166 182
167 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " succeeded"; 183 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " succeeded";
168 184
169 media_task_runner_->PostTask(FROM_HERE, codec_created_cb_); 185 media_task_runner_->PostTask(FROM_HERE, codec_created_cb_);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 336
321 // |update_current_time_cb_| might be null if there is audio stream. 337 // |update_current_time_cb_| might be null if there is audio stream.
322 // Do not update current time for stand-alone EOS frames. 338 // Do not update current time for stand-alone EOS frames.
323 if (!update_current_time_cb_.is_null() && update_time) { 339 if (!update_current_time_cb_.is_null() && update_time) {
324 media_task_runner_->PostTask( 340 media_task_runner_->PostTask(
325 FROM_HERE, base::Bind(update_current_time_cb_, pts, pts, false)); 341 FROM_HERE, base::Bind(update_current_time_cb_, pts, pts, false));
326 } 342 }
327 } 343 }
328 344
329 } // namespace media 345 } // namespace media
OLDNEW
« media/base/android/media_codec_player.cc ('K') | « media/base/android/media_codec_video_decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698