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

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

Issue 1287423004: MediaCodecPlayer implementation (stage 5 - reconfiguration) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mtplayer-cleanuptest
Patch Set: Notified another stream after the drain completed; emulated reconfig Created 5 years, 4 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_audio_decoder.h" 5 #include "media/base/android/media_codec_audio_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/audio_timestamp_helper.h" 10 #include "media/base/audio_timestamp_helper.h"
11 #include "media/base/demuxer_stream.h" 11 #include "media/base/demuxer_stream.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Use 16bit PCM for audio output. Keep this value in sync with the output 15 // Use 16bit PCM for audio output. Keep this value in sync with the output
16 // format we passed to AudioTrack in MediaCodecBridge. 16 // format we passed to AudioTrack in MediaCodecBridge.
17 const int kBytesPerAudioOutputSample = 2; 17 const int kBytesPerAudioOutputSample = 2;
18 18
19 // Fake buffer index that refers to pending buffer. 19 // Fake buffer index that refers to pending buffer.
20 const int kPendingBufferIndex = -1; 20 const int kPendingBufferIndex = -1;
21 } 21 }
22 22
23 namespace media { 23 namespace media {
24 24
25 MediaCodecAudioDecoder::MediaCodecAudioDecoder( 25 MediaCodecAudioDecoder::MediaCodecAudioDecoder(
26 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, 26 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
27 const base::Closure& request_data_cb, 27 const base::Closure& request_data_cb,
28 const base::Closure& starvation_cb, 28 const base::Closure& starvation_cb,
29 const base::Closure& decoder_drained_cb,
29 const base::Closure& stop_done_cb, 30 const base::Closure& stop_done_cb,
30 const base::Closure& error_cb, 31 const base::Closure& error_cb,
31 const SetTimeCallback& update_current_time_cb) 32 const SetTimeCallback& update_current_time_cb)
32 : MediaCodecDecoder(media_task_runner, 33 : MediaCodecDecoder(media_task_runner,
33 request_data_cb, 34 request_data_cb,
34 starvation_cb, 35 starvation_cb,
36 decoder_drained_cb,
35 stop_done_cb, 37 stop_done_cb,
36 error_cb, 38 error_cb,
37 "AudioDecoder"), 39 "AudioDecoder"),
38 volume_(-1.0), 40 volume_(-1.0),
39 bytes_per_frame_(0), 41 bytes_per_frame_(0),
40 output_sampling_rate_(0), 42 output_sampling_rate_(0),
41 frame_count_(0), 43 frame_count_(0),
42 update_current_time_cb_(update_current_time_cb) { 44 update_current_time_cb_(update_current_time_cb) {
43 } 45 }
44 46
45 MediaCodecAudioDecoder::~MediaCodecAudioDecoder() { 47 MediaCodecAudioDecoder::~MediaCodecAudioDecoder() {
46 DVLOG(1) << "AudioDecoder::~AudioDecoder()"; 48 DVLOG(1) << "AudioDecoder::~AudioDecoder()";
47 ReleaseDecoderResources(); 49 ReleaseDecoderResources();
48 } 50 }
49 51
50 const char* MediaCodecAudioDecoder::class_name() const { 52 const char* MediaCodecAudioDecoder::class_name() const {
51 return "AudioDecoder"; 53 return "AudioDecoder";
52 } 54 }
53 55
54 bool MediaCodecAudioDecoder::HasStream() const { 56 bool MediaCodecAudioDecoder::HasStream() const {
55 DCHECK(media_task_runner_->BelongsToCurrentThread()); 57 DCHECK(media_task_runner_->BelongsToCurrentThread());
56 58
57 return configs_.audio_codec != kUnknownAudioCodec; 59 return configs_.audio_codec != kUnknownAudioCodec;
58 } 60 }
59 61
60 void MediaCodecAudioDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) { 62 void MediaCodecAudioDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) {
61 DCHECK(media_task_runner_->BelongsToCurrentThread());
62
63 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs; 63 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs;
64 64
65 configs_ = configs; 65 configs_ = configs;
66 if (!media_codec_bridge_) 66 if (!media_codec_bridge_)
67 output_sampling_rate_ = configs.audio_sampling_rate; 67 output_sampling_rate_ = configs.audio_sampling_rate;
68 } 68 }
69 69
70 void MediaCodecAudioDecoder::Flush() { 70 void MediaCodecAudioDecoder::Flush() {
71 DCHECK(media_task_runner_->BelongsToCurrentThread()); 71 DCHECK(media_task_runner_->BelongsToCurrentThread());
72 72
(...skipping 19 matching lines...) Expand all
92 DCHECK(media_task_runner_->BelongsToCurrentThread()); 92 DCHECK(media_task_runner_->BelongsToCurrentThread());
93 93
94 DVLOG(1) << __FUNCTION__ << " " << base_timestamp; 94 DVLOG(1) << __FUNCTION__ << " " << base_timestamp;
95 95
96 base_timestamp_ = base_timestamp; 96 base_timestamp_ = base_timestamp;
97 if (audio_timestamp_helper_) 97 if (audio_timestamp_helper_)
98 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); 98 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_);
99 } 99 }
100 100
101 bool MediaCodecAudioDecoder::IsCodecReconfigureNeeded( 101 bool MediaCodecAudioDecoder::IsCodecReconfigureNeeded(
102 const DemuxerConfigs& curr,
103 const DemuxerConfigs& next) const { 102 const DemuxerConfigs& next) const {
104 return curr.audio_codec != next.audio_codec || 103 if (always_reconfigure_for_tests_)
105 curr.audio_channels != next.audio_channels || 104 return true;
106 curr.audio_sampling_rate != next.audio_sampling_rate || 105
106 return configs_.audio_codec != next.audio_codec ||
107 configs_.audio_channels != next.audio_channels ||
108 configs_.audio_sampling_rate != next.audio_sampling_rate ||
107 next.is_audio_encrypted != next.is_audio_encrypted || 109 next.is_audio_encrypted != next.is_audio_encrypted ||
108 curr.audio_extra_data.size() != next.audio_extra_data.size() || 110 configs_.audio_extra_data.size() != next.audio_extra_data.size() ||
109 !std::equal(curr.audio_extra_data.begin(), curr.audio_extra_data.end(), 111 !std::equal(configs_.audio_extra_data.begin(),
112 configs_.audio_extra_data.end(),
110 next.audio_extra_data.begin()); 113 next.audio_extra_data.begin());
111 } 114 }
112 115
113 MediaCodecDecoder::ConfigStatus MediaCodecAudioDecoder::ConfigureInternal() { 116 MediaCodecDecoder::ConfigStatus MediaCodecAudioDecoder::ConfigureInternal() {
114 DCHECK(media_task_runner_->BelongsToCurrentThread()); 117 DCHECK(media_task_runner_->BelongsToCurrentThread());
115 118
116 DVLOG(1) << class_name() << "::" << __FUNCTION__; 119 DVLOG(1) << class_name() << "::" << __FUNCTION__;
117 120
118 if (configs_.audio_codec == kUnknownAudioCodec) { 121 if (configs_.audio_codec == kUnknownAudioCodec) {
119 DVLOG(0) << class_name() << "::" << __FUNCTION__ 122 DVLOG(0) << class_name() << "::" << __FUNCTION__
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 AudioCodecBridge* audio_codec = 184 AudioCodecBridge* audio_codec =
182 static_cast<AudioCodecBridge*>(media_codec_bridge_.get()); 185 static_cast<AudioCodecBridge*>(media_codec_bridge_.get());
183 186
184 DCHECK(audio_codec); 187 DCHECK(audio_codec);
185 188
186 const bool postpone = (render_mode == kRenderAfterPreroll); 189 const bool postpone = (render_mode == kRenderAfterPreroll);
187 190
188 int64 head_position = 191 int64 head_position =
189 audio_codec->PlayOutputBuffer(buffer_index, size, postpone); 192 audio_codec->PlayOutputBuffer(buffer_index, size, postpone);
190 193
191 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts
192 << (postpone ? " POSTPONE" : "")
193 << " head_position:" << head_position;
194
195 size_t new_frames_count = size / bytes_per_frame_; 194 size_t new_frames_count = size / bytes_per_frame_;
196 frame_count_ += new_frames_count; 195 frame_count_ += new_frames_count;
197 audio_timestamp_helper_->AddFrames(new_frames_count); 196 audio_timestamp_helper_->AddFrames(new_frames_count);
198 197
199 if (!postpone) { 198 if (postpone) {
199 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts
200 << " POSTPONE";
201 } else {
200 int64 frames_to_play = frame_count_ - head_position; 202 int64 frames_to_play = frame_count_ - head_position;
201 203
202 DCHECK_GE(frames_to_play, 0) << class_name() << "::" << __FUNCTION__ 204 DCHECK_GE(frames_to_play, 0) << class_name() << "::" << __FUNCTION__
203 << " pts:" << pts 205 << " pts:" << pts
204 << " frame_count_:" << frame_count_ 206 << " frame_count_:" << frame_count_
205 << " head_position:" << head_position; 207 << " head_position:" << head_position;
206 208
207 base::TimeDelta last_buffered = audio_timestamp_helper_->GetTimestamp(); 209 base::TimeDelta last_buffered = audio_timestamp_helper_->GetTimestamp();
208 base::TimeDelta now_playing = 210 base::TimeDelta now_playing =
209 last_buffered - 211 last_buffered -
(...skipping 30 matching lines...) Expand all
240 if (audio_timestamp_helper_) 242 if (audio_timestamp_helper_)
241 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); 243 base_timestamp_ = audio_timestamp_helper_->GetTimestamp();
242 244
243 audio_timestamp_helper_.reset( 245 audio_timestamp_helper_.reset(
244 new AudioTimestampHelper(configs_.audio_sampling_rate)); 246 new AudioTimestampHelper(configs_.audio_sampling_rate));
245 247
246 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); 248 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_);
247 } 249 }
248 250
249 } // namespace media 251 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698