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

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

Issue 1254293003: MediaCodecPlayer implementation (stage 4 - preroll) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mtplayer-browserseek
Patch Set: Addressed Matt's comments 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
19 // Fake buffer index that refers to pending buffer.
20 const int kPendingBufferIndex = -1;
18 } 21 }
19 22
20 namespace media { 23 namespace media {
21 24
22 MediaCodecAudioDecoder::MediaCodecAudioDecoder( 25 MediaCodecAudioDecoder::MediaCodecAudioDecoder(
23 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, 26 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
24 const base::Closure& request_data_cb, 27 const base::Closure& request_data_cb,
25 const base::Closure& starvation_cb, 28 const base::Closure& starvation_cb,
26 const base::Closure& stop_done_cb, 29 const base::Closure& stop_done_cb,
27 const base::Closure& error_cb, 30 const base::Closure& error_cb,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 output_sampling_rate_ = configs.audio_sampling_rate; 67 output_sampling_rate_ = configs.audio_sampling_rate;
65 } 68 }
66 69
67 void MediaCodecAudioDecoder::Flush() { 70 void MediaCodecAudioDecoder::Flush() {
68 DCHECK(media_task_runner_->BelongsToCurrentThread()); 71 DCHECK(media_task_runner_->BelongsToCurrentThread());
69 72
70 MediaCodecDecoder::Flush(); 73 MediaCodecDecoder::Flush();
71 frame_count_ = 0; 74 frame_count_ = 0;
72 } 75 }
73 76
77 void MediaCodecAudioDecoder::ReleaseMediaCodec() {
78 DCHECK(media_task_runner_->BelongsToCurrentThread());
79 MediaCodecDecoder::ReleaseMediaCodec();
80 }
81
74 void MediaCodecAudioDecoder::SetVolume(double volume) { 82 void MediaCodecAudioDecoder::SetVolume(double volume) {
75 DCHECK(media_task_runner_->BelongsToCurrentThread()); 83 DCHECK(media_task_runner_->BelongsToCurrentThread());
76 84
77 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << volume; 85 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << volume;
78 86
79 volume_ = volume; 87 volume_ = volume;
80 SetVolumeInternal(); 88 SetVolumeInternal();
81 } 89 }
82 90
83 void MediaCodecAudioDecoder::SetBaseTimestamp(base::TimeDelta base_timestamp) { 91 void MediaCodecAudioDecoder::SetBaseTimestamp(base::TimeDelta base_timestamp) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 DCHECK(media_codec_bridge_); 160 DCHECK(media_codec_bridge_);
153 161
154 int old_sampling_rate = output_sampling_rate_; 162 int old_sampling_rate = output_sampling_rate_;
155 output_sampling_rate_ = media_codec_bridge_->GetOutputSamplingRate(); 163 output_sampling_rate_ = media_codec_bridge_->GetOutputSamplingRate();
156 if (output_sampling_rate_ != old_sampling_rate) 164 if (output_sampling_rate_ != old_sampling_rate)
157 ResetTimestampHelper(); 165 ResetTimestampHelper();
158 } 166 }
159 167
160 void MediaCodecAudioDecoder::Render(int buffer_index, 168 void MediaCodecAudioDecoder::Render(int buffer_index,
161 size_t size, 169 size_t size,
162 bool render_output, 170 RenderMode render_mode,
163 base::TimeDelta pts, 171 base::TimeDelta pts,
164 bool eos_encountered) { 172 bool eos_encountered) {
165 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); 173 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
166 174
167 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts; 175 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts << " "
176 << AsString(render_mode);
168 177
169 render_output = render_output && (size != 0u); 178 const bool do_play = (render_mode != kRenderSkip);
170 179
171 if (render_output) { 180 if (do_play) {
181 AudioCodecBridge* audio_codec =
182 static_cast<AudioCodecBridge*>(media_codec_bridge_.get());
183
184 DCHECK(audio_codec);
185
186 const bool postpone = (render_mode == kRenderAfterPreroll);
187
172 int64 head_position = 188 int64 head_position =
173 (static_cast<AudioCodecBridge*>(media_codec_bridge_.get())) 189 audio_codec->PlayOutputBuffer(buffer_index, size, postpone);
174 ->PlayOutputBuffer(buffer_index, size); 190
191 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts
192 << (postpone ? " POSTPONE" : "")
193 << " head_position:" << head_position;
175 194
176 size_t new_frames_count = size / bytes_per_frame_; 195 size_t new_frames_count = size / bytes_per_frame_;
177 frame_count_ += new_frames_count; 196 frame_count_ += new_frames_count;
178 audio_timestamp_helper_->AddFrames(new_frames_count); 197 audio_timestamp_helper_->AddFrames(new_frames_count);
179 int64 frames_to_play = frame_count_ - head_position;
180 DCHECK_GE(frames_to_play, 0);
181 198
182 base::TimeDelta last_buffered = audio_timestamp_helper_->GetTimestamp(); 199 if (!postpone) {
183 base::TimeDelta now_playing = 200 int64 frames_to_play = frame_count_ - head_position;
184 last_buffered -
185 audio_timestamp_helper_->GetFrameDuration(frames_to_play);
186 201
187 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts 202 DCHECK_GE(frames_to_play, 0) << class_name() << "::" << __FUNCTION__
188 << " will play: [" << now_playing << "," << last_buffered << "]"; 203 << " pts:" << pts
204 << " frame_count_:" << frame_count_
205 << " head_position:" << head_position;
189 206
190 media_task_runner_->PostTask( 207 base::TimeDelta last_buffered = audio_timestamp_helper_->GetTimestamp();
191 FROM_HERE, 208 base::TimeDelta now_playing =
192 base::Bind(update_current_time_cb_, now_playing, last_buffered)); 209 last_buffered -
210 audio_timestamp_helper_->GetFrameDuration(frames_to_play);
211
212 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts
213 << " will play: [" << now_playing << "," << last_buffered << "]";
214
215 media_task_runner_->PostTask(
216 FROM_HERE,
217 base::Bind(update_current_time_cb_, now_playing, last_buffered));
218 }
193 } 219 }
194 220
195 media_codec_bridge_->ReleaseOutputBuffer(buffer_index, false); 221 media_codec_bridge_->ReleaseOutputBuffer(buffer_index, false);
196 222
197 CheckLastFrame(eos_encountered, false); // no delayed tasks 223 CheckLastFrame(eos_encountered, false); // no delayed tasks
198 } 224 }
199 225
200 void MediaCodecAudioDecoder::SetVolumeInternal() { 226 void MediaCodecAudioDecoder::SetVolumeInternal() {
201 DCHECK(media_task_runner_->BelongsToCurrentThread()); 227 DCHECK(media_task_runner_->BelongsToCurrentThread());
202 228
(...skipping 11 matching lines...) Expand all
214 if (audio_timestamp_helper_) 240 if (audio_timestamp_helper_)
215 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); 241 base_timestamp_ = audio_timestamp_helper_->GetTimestamp();
216 242
217 audio_timestamp_helper_.reset( 243 audio_timestamp_helper_.reset(
218 new AudioTimestampHelper(configs_.audio_sampling_rate)); 244 new AudioTimestampHelper(configs_.audio_sampling_rate));
219 245
220 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); 246 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_);
221 } 247 }
222 248
223 } // namespace media 249 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698