| OLD | NEW |
| 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/buffers.h" | 10 #include "media/base/buffers.h" |
| 11 #include "media/base/demuxer_stream.h" | 11 #include "media/base/demuxer_stream.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& stop_done_cb, | 24 const base::Closure& stop_done_cb, |
| 24 const base::Closure& error_cb, | 25 const base::Closure& error_cb, |
| 25 const SetTimeCallback& update_current_time_cb, | 26 const SetTimeCallback& update_current_time_cb, |
| 26 const VideoSizeChangedCallback& video_size_changed_cb, | 27 const VideoSizeChangedCallback& video_size_changed_cb, |
| 27 const base::Closure& codec_created_cb) | 28 const base::Closure& codec_created_cb) |
| 28 : MediaCodecDecoder(media_task_runner, | 29 : MediaCodecDecoder(media_task_runner, |
| 29 request_data_cb, | 30 request_data_cb, |
| 30 starvation_cb, | 31 starvation_cb, |
| 32 decoder_drained_cb, |
| 31 stop_done_cb, | 33 stop_done_cb, |
| 32 error_cb, | 34 error_cb, |
| 33 "VideoDecoder"), | 35 "VideoDecoder"), |
| 34 update_current_time_cb_(update_current_time_cb), | 36 update_current_time_cb_(update_current_time_cb), |
| 35 video_size_changed_cb_(video_size_changed_cb), | 37 video_size_changed_cb_(video_size_changed_cb), |
| 36 codec_created_cb_(codec_created_cb) { | 38 codec_created_cb_(codec_created_cb) { |
| 37 } | 39 } |
| 38 | 40 |
| 39 MediaCodecVideoDecoder::~MediaCodecVideoDecoder() { | 41 MediaCodecVideoDecoder::~MediaCodecVideoDecoder() { |
| 40 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 42 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 41 DVLOG(1) << "VideoDecoder::~VideoDecoder()"; | 43 DVLOG(1) << "VideoDecoder::~VideoDecoder()"; |
| 42 ReleaseDecoderResources(); | 44 ReleaseDecoderResources(); |
| 43 } | 45 } |
| 44 | 46 |
| 45 const char* MediaCodecVideoDecoder::class_name() const { | 47 const char* MediaCodecVideoDecoder::class_name() const { |
| 46 return "VideoDecoder"; | 48 return "VideoDecoder"; |
| 47 } | 49 } |
| 48 | 50 |
| 49 bool MediaCodecVideoDecoder::HasStream() const { | 51 bool MediaCodecVideoDecoder::HasStream() const { |
| 50 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 52 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 51 | 53 |
| 52 return configs_.video_codec != kUnknownVideoCodec; | 54 return configs_.video_codec != kUnknownVideoCodec; |
| 53 } | 55 } |
| 54 | 56 |
| 55 void MediaCodecVideoDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) { | 57 void MediaCodecVideoDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) { |
| 56 DCHECK(media_task_runner_->BelongsToCurrentThread()); | |
| 57 | |
| 58 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs; | 58 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs; |
| 59 | 59 |
| 60 configs_ = configs; | 60 configs_ = configs; |
| 61 | 61 |
| 62 if (video_size_.IsEmpty()) { | 62 if (video_size_.IsEmpty()) { |
| 63 video_size_ = configs_.video_size; | 63 video_size_ = configs_.video_size; |
| 64 media_task_runner_->PostTask( | 64 media_task_runner_->PostTask( |
| 65 FROM_HERE, base::Bind(video_size_changed_cb_, video_size_)); | 65 FROM_HERE, base::Bind(video_size_changed_cb_, video_size_)); |
| 66 } | 66 } |
| 67 } | 67 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 95 needs_reconfigure_ = true; | 95 needs_reconfigure_ = true; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool MediaCodecVideoDecoder::HasVideoSurface() const { | 98 bool MediaCodecVideoDecoder::HasVideoSurface() const { |
| 99 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 99 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 100 | 100 |
| 101 return !surface_.IsEmpty(); | 101 return !surface_.IsEmpty(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool MediaCodecVideoDecoder::IsCodecReconfigureNeeded( | 104 bool MediaCodecVideoDecoder::IsCodecReconfigureNeeded( |
| 105 const DemuxerConfigs& curr, | |
| 106 const DemuxerConfigs& next) const { | 105 const DemuxerConfigs& next) const { |
| 107 if (curr.video_codec != next.video_codec || | 106 if (always_reconfigure_for_tests_) |
| 108 curr.is_video_encrypted != next.is_video_encrypted) { | 107 return true; |
| 108 |
| 109 if (configs_.video_codec != next.video_codec || |
| 110 configs_.is_video_encrypted != next.is_video_encrypted) { |
| 109 return true; | 111 return true; |
| 110 } | 112 } |
| 111 | 113 |
| 112 // Only size changes below this point | 114 // Only size changes below this point |
| 113 | 115 |
| 114 if (curr.video_size.width() == next.video_size.width() && | 116 if (configs_.video_size.width() == next.video_size.width() && |
| 115 curr.video_size.height() == next.video_size.height()) { | 117 configs_.video_size.height() == next.video_size.height()) { |
| 116 return false; // i.e. curr == next | 118 return false; // i.e. configs_ == next |
| 117 } | 119 } |
| 118 | 120 |
| 119 return !static_cast<VideoCodecBridge*>(media_codec_bridge_.get()) | 121 return !static_cast<VideoCodecBridge*>(media_codec_bridge_.get()) |
| 120 ->IsAdaptivePlaybackSupported(next.video_size.width(), | 122 ->IsAdaptivePlaybackSupported(next.video_size.width(), |
| 121 next.video_size.height()); | 123 next.video_size.height()); |
| 122 } | 124 } |
| 123 | 125 |
| 124 MediaCodecDecoder::ConfigStatus MediaCodecVideoDecoder::ConfigureInternal() { | 126 MediaCodecDecoder::ConfigStatus MediaCodecVideoDecoder::ConfigureInternal() { |
| 125 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 127 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 126 | 128 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 if (!media_codec_bridge_) { | 161 if (!media_codec_bridge_) { |
| 160 DVLOG(0) << class_name() << "::" << __FUNCTION__ | 162 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
| 161 << " failed: cannot create video codec"; | 163 << " failed: cannot create video codec"; |
| 162 return kConfigFailure; | 164 return kConfigFailure; |
| 163 } | 165 } |
| 164 | 166 |
| 165 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " succeeded"; | 167 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " succeeded"; |
| 166 | 168 |
| 167 media_task_runner_->PostTask(FROM_HERE, codec_created_cb_); | 169 media_task_runner_->PostTask(FROM_HERE, codec_created_cb_); |
| 168 | 170 |
| 171 if (!codec_created_for_tests_cb_.is_null()) |
| 172 media_task_runner_->PostTask(FROM_HERE, codec_created_for_tests_cb_); |
| 173 |
| 169 return kConfigOk; | 174 return kConfigOk; |
| 170 } | 175 } |
| 171 | 176 |
| 172 void MediaCodecVideoDecoder::AssociateCurrentTimeWithPTS(base::TimeDelta pts) { | 177 void MediaCodecVideoDecoder::AssociateCurrentTimeWithPTS(base::TimeDelta pts) { |
| 173 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 178 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 174 | 179 |
| 175 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " pts:" << pts; | 180 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " pts:" << pts; |
| 176 | 181 |
| 177 start_time_ticks_ = base::TimeTicks::Now(); | 182 start_time_ticks_ = base::TimeTicks::Now(); |
| 178 start_pts_ = pts; | 183 start_pts_ = pts; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 321 |
| 317 // |update_current_time_cb_| might be null if there is audio stream. | 322 // |update_current_time_cb_| might be null if there is audio stream. |
| 318 // Do not update current time for stand-alone EOS frames. | 323 // Do not update current time for stand-alone EOS frames. |
| 319 if (!update_current_time_cb_.is_null() && update_time) { | 324 if (!update_current_time_cb_.is_null() && update_time) { |
| 320 media_task_runner_->PostTask( | 325 media_task_runner_->PostTask( |
| 321 FROM_HERE, base::Bind(update_current_time_cb_, pts, pts, false)); | 326 FROM_HERE, base::Bind(update_current_time_cb_, pts, pts, false)); |
| 322 } | 327 } |
| 323 } | 328 } |
| 324 | 329 |
| 325 } // namespace media | 330 } // namespace media |
| OLD | NEW |