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

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: Rebased 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
« no previous file with comments | « media/base/android/media_codec_audio_decoder.h ('k') | media/base/android/media_codec_bridge.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 22 matching lines...) Expand all
33 error_cb, 33 error_cb,
34 "AudioDecoder"), 34 "AudioDecoder"),
35 volume_(-1.0), 35 volume_(-1.0),
36 bytes_per_frame_(0), 36 bytes_per_frame_(0),
37 output_sampling_rate_(0), 37 output_sampling_rate_(0),
38 frame_count_(0), 38 frame_count_(0),
39 update_current_time_cb_(update_current_time_cb) { 39 update_current_time_cb_(update_current_time_cb) {
40 } 40 }
41 41
42 MediaCodecAudioDecoder::~MediaCodecAudioDecoder() { 42 MediaCodecAudioDecoder::~MediaCodecAudioDecoder() {
43 DCHECK(media_task_runner_->BelongsToCurrentThread());
43 DVLOG(1) << "AudioDecoder::~AudioDecoder()"; 44 DVLOG(1) << "AudioDecoder::~AudioDecoder()";
44 ReleaseDecoderResources(); 45 ReleaseDecoderResources();
45 } 46 }
46 47
47 const char* MediaCodecAudioDecoder::class_name() const { 48 const char* MediaCodecAudioDecoder::class_name() const {
48 return "AudioDecoder"; 49 return "AudioDecoder";
49 } 50 }
50 51
51 bool MediaCodecAudioDecoder::HasStream() const { 52 bool MediaCodecAudioDecoder::HasStream() const {
52 DCHECK(media_task_runner_->BelongsToCurrentThread()); 53 DCHECK(media_task_runner_->BelongsToCurrentThread());
53 54
54 return configs_.audio_codec != kUnknownAudioCodec; 55 return configs_.audio_codec != kUnknownAudioCodec;
55 } 56 }
56 57
57 void MediaCodecAudioDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) { 58 void MediaCodecAudioDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) {
58 DCHECK(media_task_runner_->BelongsToCurrentThread()); 59 DCHECK(media_task_runner_->BelongsToCurrentThread());
59 60
60 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs; 61 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs;
61 62
62 configs_ = configs; 63 configs_ = configs;
63 if (!media_codec_bridge_) 64 if (!media_codec_bridge_)
64 output_sampling_rate_ = configs.audio_sampling_rate; 65 output_sampling_rate_ = configs.audio_sampling_rate;
65 } 66 }
66 67
68 void MediaCodecAudioDecoder::ReleaseDecoderResources() {
69 DCHECK(media_task_runner_->BelongsToCurrentThread());
70 DVLOG(1) << class_name() << "::" << __FUNCTION__;
71
72 DoEmergencyStop();
73
74 ReleaseMediaCodec();
75 }
76
67 void MediaCodecAudioDecoder::Flush() { 77 void MediaCodecAudioDecoder::Flush() {
68 DCHECK(media_task_runner_->BelongsToCurrentThread()); 78 DCHECK(media_task_runner_->BelongsToCurrentThread());
69 79
70 MediaCodecDecoder::Flush(); 80 MediaCodecDecoder::Flush();
71 frame_count_ = 0; 81 frame_count_ = 0;
72 } 82 }
73 83
74 void MediaCodecAudioDecoder::SetVolume(double volume) { 84 void MediaCodecAudioDecoder::SetVolume(double volume) {
75 DCHECK(media_task_runner_->BelongsToCurrentThread()); 85 DCHECK(media_task_runner_->BelongsToCurrentThread());
76 86
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 163
154 int old_sampling_rate = output_sampling_rate_; 164 int old_sampling_rate = output_sampling_rate_;
155 output_sampling_rate_ = media_codec_bridge_->GetOutputSamplingRate(); 165 output_sampling_rate_ = media_codec_bridge_->GetOutputSamplingRate();
156 if (output_sampling_rate_ != old_sampling_rate) 166 if (output_sampling_rate_ != old_sampling_rate)
157 ResetTimestampHelper(); 167 ResetTimestampHelper();
158 } 168 }
159 169
160 void MediaCodecAudioDecoder::Render(int buffer_index, 170 void MediaCodecAudioDecoder::Render(int buffer_index,
161 size_t offset, 171 size_t offset,
162 size_t size, 172 size_t size,
163 bool render_output, 173 RenderMode render_mode,
164 base::TimeDelta pts, 174 base::TimeDelta pts,
165 bool eos_encountered) { 175 bool eos_encountered) {
166 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); 176 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
167 177
168 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts; 178 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts << " "
179 << AsString(render_mode);
169 180
170 render_output = render_output && (size != 0u); 181 const bool do_play = (render_mode != kRenderSkip);
171 182
172 if (render_output) { 183 if (do_play) {
184 AudioCodecBridge* audio_codec =
185 static_cast<AudioCodecBridge*>(media_codec_bridge_.get());
186
187 DCHECK(audio_codec);
188
189 const bool postpone = (render_mode == kRenderAfterPreroll);
190
173 int64 head_position = 191 int64 head_position =
174 (static_cast<AudioCodecBridge*>(media_codec_bridge_.get())) 192 audio_codec->PlayOutputBuffer(buffer_index, size, offset, postpone);
175 ->PlayOutputBuffer(buffer_index, size, offset); 193
194 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts
195 << (postpone ? " POSTPONE" : "")
196 << " head_position:" << head_position;
176 197
177 size_t new_frames_count = size / bytes_per_frame_; 198 size_t new_frames_count = size / bytes_per_frame_;
178 frame_count_ += new_frames_count; 199 frame_count_ += new_frames_count;
179 audio_timestamp_helper_->AddFrames(new_frames_count); 200 audio_timestamp_helper_->AddFrames(new_frames_count);
180 int64 frames_to_play = frame_count_ - head_position;
181 DCHECK_GE(frames_to_play, 0);
182 201
183 base::TimeDelta last_buffered = audio_timestamp_helper_->GetTimestamp(); 202 if (!postpone) {
184 base::TimeDelta now_playing = 203 int64 frames_to_play = frame_count_ - head_position;
185 last_buffered -
186 audio_timestamp_helper_->GetFrameDuration(frames_to_play);
187 204
188 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts 205 DCHECK_GE(frames_to_play, 0) << class_name() << "::" << __FUNCTION__
189 << " will play: [" << now_playing << "," << last_buffered << "]"; 206 << " pts:" << pts
207 << " frame_count_:" << frame_count_
208 << " head_position:" << head_position;
190 209
191 media_task_runner_->PostTask( 210 base::TimeDelta last_buffered = audio_timestamp_helper_->GetTimestamp();
192 FROM_HERE, 211 base::TimeDelta now_playing =
193 base::Bind(update_current_time_cb_, now_playing, last_buffered)); 212 last_buffered -
213 audio_timestamp_helper_->GetFrameDuration(frames_to_play);
214
215 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts
216 << " will play: [" << now_playing << "," << last_buffered << "]";
217
218 media_task_runner_->PostTask(
219 FROM_HERE,
220 base::Bind(update_current_time_cb_, now_playing, last_buffered));
221 }
194 } 222 }
195 223
196 media_codec_bridge_->ReleaseOutputBuffer(buffer_index, false); 224 media_codec_bridge_->ReleaseOutputBuffer(buffer_index, false);
197 225
198 CheckLastFrame(eos_encountered, false); // no delayed tasks 226 CheckLastFrame(eos_encountered, false); // no delayed tasks
199 } 227 }
200 228
201 void MediaCodecAudioDecoder::SetVolumeInternal() { 229 void MediaCodecAudioDecoder::SetVolumeInternal() {
202 DCHECK(media_task_runner_->BelongsToCurrentThread()); 230 DCHECK(media_task_runner_->BelongsToCurrentThread());
203 231
(...skipping 11 matching lines...) Expand all
215 if (audio_timestamp_helper_) 243 if (audio_timestamp_helper_)
216 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); 244 base_timestamp_ = audio_timestamp_helper_->GetTimestamp();
217 245
218 audio_timestamp_helper_.reset( 246 audio_timestamp_helper_.reset(
219 new AudioTimestampHelper(configs_.audio_sampling_rate)); 247 new AudioTimestampHelper(configs_.audio_sampling_rate));
220 248
221 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); 249 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_);
222 } 250 }
223 251
224 } // namespace media 252 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_codec_audio_decoder.h ('k') | media/base/android/media_codec_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698