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 DVLOG(1) << "VideoDecoder::~VideoDecoder()"; | 42 DVLOG(1) << "VideoDecoder::~VideoDecoder()"; |
41 ReleaseDecoderResources(); | 43 ReleaseDecoderResources(); |
42 } | 44 } |
43 | 45 |
44 const char* MediaCodecVideoDecoder::class_name() const { | 46 const char* MediaCodecVideoDecoder::class_name() const { |
45 return "VideoDecoder"; | 47 return "VideoDecoder"; |
46 } | 48 } |
47 | 49 |
48 bool MediaCodecVideoDecoder::HasStream() const { | 50 bool MediaCodecVideoDecoder::HasStream() const { |
49 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 51 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
50 | 52 |
51 return configs_.video_codec != kUnknownVideoCodec; | 53 return configs_.video_codec != kUnknownVideoCodec; |
52 } | 54 } |
53 | 55 |
54 void MediaCodecVideoDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) { | 56 void MediaCodecVideoDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) { |
55 DCHECK(media_task_runner_->BelongsToCurrentThread()); | |
56 | |
57 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs; | 57 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs; |
58 | 58 |
59 configs_ = configs; | 59 configs_ = configs; |
60 | 60 |
61 if (video_size_.IsEmpty()) { | 61 if (video_size_.IsEmpty()) { |
62 video_size_ = configs_.video_size; | 62 video_size_ = configs_.video_size; |
63 media_task_runner_->PostTask( | 63 media_task_runner_->PostTask( |
64 FROM_HERE, base::Bind(video_size_changed_cb_, video_size_)); | 64 FROM_HERE, base::Bind(video_size_changed_cb_, video_size_)); |
65 } | 65 } |
66 } | 66 } |
(...skipping 25 matching lines...) Expand all Loading... |
92 needs_reconfigure_ = true; | 92 needs_reconfigure_ = true; |
93 } | 93 } |
94 | 94 |
95 bool MediaCodecVideoDecoder::HasVideoSurface() const { | 95 bool MediaCodecVideoDecoder::HasVideoSurface() const { |
96 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 96 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
97 | 97 |
98 return !surface_.IsEmpty(); | 98 return !surface_.IsEmpty(); |
99 } | 99 } |
100 | 100 |
101 bool MediaCodecVideoDecoder::IsCodecReconfigureNeeded( | 101 bool MediaCodecVideoDecoder::IsCodecReconfigureNeeded( |
102 const DemuxerConfigs& curr, | |
103 const DemuxerConfigs& next) const { | 102 const DemuxerConfigs& next) const { |
104 if (curr.video_codec != next.video_codec || | 103 if (always_reconfigure_for_tests_) |
105 curr.is_video_encrypted != next.is_video_encrypted) { | 104 return true; |
| 105 |
| 106 if (configs_.video_codec != next.video_codec || |
| 107 configs_.is_video_encrypted != next.is_video_encrypted) { |
106 return true; | 108 return true; |
107 } | 109 } |
108 | 110 |
109 // Only size changes below this point | 111 // Only size changes below this point |
110 | 112 |
111 if (curr.video_size.width() == next.video_size.width() && | 113 if (configs_.video_size.width() == next.video_size.width() && |
112 curr.video_size.height() == next.video_size.height()) { | 114 configs_.video_size.height() == next.video_size.height()) { |
113 return false; // i.e. curr == next | 115 return false; // i.e. configs_ == next |
114 } | 116 } |
115 | 117 |
116 return !static_cast<VideoCodecBridge*>(media_codec_bridge_.get()) | 118 return !static_cast<VideoCodecBridge*>(media_codec_bridge_.get()) |
117 ->IsAdaptivePlaybackSupported(next.video_size.width(), | 119 ->IsAdaptivePlaybackSupported(next.video_size.width(), |
118 next.video_size.height()); | 120 next.video_size.height()); |
119 } | 121 } |
120 | 122 |
121 MediaCodecDecoder::ConfigStatus MediaCodecVideoDecoder::ConfigureInternal() { | 123 MediaCodecDecoder::ConfigStatus MediaCodecVideoDecoder::ConfigureInternal() { |
122 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 124 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
123 | 125 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 313 |
312 // |update_current_time_cb_| might be null if there is audio stream. | 314 // |update_current_time_cb_| might be null if there is audio stream. |
313 // Do not update current time for stand-alone EOS frames. | 315 // Do not update current time for stand-alone EOS frames. |
314 if (!update_current_time_cb_.is_null() && update_time) { | 316 if (!update_current_time_cb_.is_null() && update_time) { |
315 media_task_runner_->PostTask(FROM_HERE, | 317 media_task_runner_->PostTask(FROM_HERE, |
316 base::Bind(update_current_time_cb_, pts, pts)); | 318 base::Bind(update_current_time_cb_, pts, pts)); |
317 } | 319 } |
318 } | 320 } |
319 | 321 |
320 } // namespace media | 322 } // namespace media |
OLD | NEW |