Chromium Code Reviews| 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) { |
| 39 // Generate |kConfigChanged| before every key frame | |
|
qinmin
2015/08/20 19:41:25
why we need this? cannot we just do that in test b
Tima Vaisburd
2015/08/20 20:05:22
It was intended not for the unit tests, but for te
| |
| 40 // au_queue_.EmulateConfigChanges(true); | |
| 41 // always_reconfigure_for_tests_ = true; | |
| 37 } | 42 } |
| 38 | 43 |
| 39 MediaCodecVideoDecoder::~MediaCodecVideoDecoder() { | 44 MediaCodecVideoDecoder::~MediaCodecVideoDecoder() { |
| 40 DVLOG(1) << "VideoDecoder::~VideoDecoder()"; | 45 DVLOG(1) << "VideoDecoder::~VideoDecoder()"; |
| 41 ReleaseDecoderResources(); | 46 ReleaseDecoderResources(); |
| 42 } | 47 } |
| 43 | 48 |
| 44 const char* MediaCodecVideoDecoder::class_name() const { | 49 const char* MediaCodecVideoDecoder::class_name() const { |
| 45 return "VideoDecoder"; | 50 return "VideoDecoder"; |
| 46 } | 51 } |
| 47 | 52 |
| 48 bool MediaCodecVideoDecoder::HasStream() const { | 53 bool MediaCodecVideoDecoder::HasStream() const { |
| 49 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 54 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 50 | 55 |
| 51 return configs_.video_codec != kUnknownVideoCodec; | 56 return configs_.video_codec != kUnknownVideoCodec; |
| 52 } | 57 } |
| 53 | 58 |
| 54 void MediaCodecVideoDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) { | 59 void MediaCodecVideoDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) { |
| 55 DCHECK(media_task_runner_->BelongsToCurrentThread()); | |
| 56 | |
| 57 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs; | 60 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs; |
| 58 | 61 |
| 59 configs_ = configs; | 62 configs_ = configs; |
| 60 | 63 |
| 64 // au_queue_.SetLastConfigs(configs); | |
| 65 | |
| 61 if (video_size_.IsEmpty()) { | 66 if (video_size_.IsEmpty()) { |
| 62 video_size_ = configs_.video_size; | 67 video_size_ = configs_.video_size; |
| 63 media_task_runner_->PostTask( | 68 media_task_runner_->PostTask( |
| 64 FROM_HERE, base::Bind(video_size_changed_cb_, video_size_)); | 69 FROM_HERE, base::Bind(video_size_changed_cb_, video_size_)); |
| 65 } | 70 } |
| 66 } | 71 } |
| 67 | 72 |
| 68 void MediaCodecVideoDecoder::ReleaseDecoderResources() { | 73 void MediaCodecVideoDecoder::ReleaseDecoderResources() { |
| 69 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 74 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 70 | 75 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 92 needs_reconfigure_ = true; | 97 needs_reconfigure_ = true; |
| 93 } | 98 } |
| 94 | 99 |
| 95 bool MediaCodecVideoDecoder::HasVideoSurface() const { | 100 bool MediaCodecVideoDecoder::HasVideoSurface() const { |
| 96 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 101 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 97 | 102 |
| 98 return !surface_.IsEmpty(); | 103 return !surface_.IsEmpty(); |
| 99 } | 104 } |
| 100 | 105 |
| 101 bool MediaCodecVideoDecoder::IsCodecReconfigureNeeded( | 106 bool MediaCodecVideoDecoder::IsCodecReconfigureNeeded( |
| 102 const DemuxerConfigs& curr, | |
| 103 const DemuxerConfigs& next) const { | 107 const DemuxerConfigs& next) const { |
| 104 if (curr.video_codec != next.video_codec || | 108 if (always_reconfigure_for_tests_) |
| 105 curr.is_video_encrypted != next.is_video_encrypted) { | 109 return true; |
| 110 | |
| 111 if (configs_.video_codec != next.video_codec || | |
| 112 configs_.is_video_encrypted != next.is_video_encrypted) { | |
| 106 return true; | 113 return true; |
| 107 } | 114 } |
| 108 | 115 |
| 109 // Only size changes below this point | 116 // Only size changes below this point |
| 110 | 117 |
| 111 if (curr.video_size.width() == next.video_size.width() && | 118 if (configs_.video_size.width() == next.video_size.width() && |
| 112 curr.video_size.height() == next.video_size.height()) { | 119 configs_.video_size.height() == next.video_size.height()) { |
| 113 return false; // i.e. curr == next | 120 return false; // i.e. configs_ == next |
| 114 } | 121 } |
| 115 | 122 |
| 116 return !static_cast<VideoCodecBridge*>(media_codec_bridge_.get()) | 123 return !static_cast<VideoCodecBridge*>(media_codec_bridge_.get()) |
| 117 ->IsAdaptivePlaybackSupported(next.video_size.width(), | 124 ->IsAdaptivePlaybackSupported(next.video_size.width(), |
| 118 next.video_size.height()); | 125 next.video_size.height()); |
| 119 } | 126 } |
| 120 | 127 |
| 121 MediaCodecDecoder::ConfigStatus MediaCodecVideoDecoder::ConfigureInternal() { | 128 MediaCodecDecoder::ConfigStatus MediaCodecVideoDecoder::ConfigureInternal() { |
| 122 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 129 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 123 | 130 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 | 318 |
| 312 // |update_current_time_cb_| might be null if there is audio stream. | 319 // |update_current_time_cb_| might be null if there is audio stream. |
| 313 // Do not update current time for stand-alone EOS frames. | 320 // Do not update current time for stand-alone EOS frames. |
| 314 if (!update_current_time_cb_.is_null() && update_time) { | 321 if (!update_current_time_cb_.is_null() && update_time) { |
| 315 media_task_runner_->PostTask(FROM_HERE, | 322 media_task_runner_->PostTask(FROM_HERE, |
| 316 base::Bind(update_current_time_cb_, pts, pts)); | 323 base::Bind(update_current_time_cb_, pts, pts)); |
| 317 } | 324 } |
| 318 } | 325 } |
| 319 | 326 |
| 320 } // namespace media | 327 } // namespace media |
| OLD | NEW |