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_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_statistics.h" | 9 #include "media/base/android/media_statistics.h" |
10 #include "media/base/android/sdk_media_codec_bridge.h" | 10 #include "media/base/android/sdk_media_codec_bridge.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 const bool do_play = (render_mode != kRenderSkip); | 195 const bool do_play = (render_mode != kRenderSkip); |
196 | 196 |
197 if (do_play) { | 197 if (do_play) { |
198 AudioCodecBridge* audio_codec = | 198 AudioCodecBridge* audio_codec = |
199 static_cast<AudioCodecBridge*>(media_codec_bridge_.get()); | 199 static_cast<AudioCodecBridge*>(media_codec_bridge_.get()); |
200 | 200 |
201 DCHECK(audio_codec); | 201 DCHECK(audio_codec); |
202 | 202 |
203 const bool postpone = (render_mode == kRenderAfterPreroll); | 203 const bool postpone = (render_mode == kRenderAfterPreroll); |
204 | 204 |
205 int64 head_position = | 205 int64_t head_position = |
206 audio_codec->PlayOutputBuffer(buffer_index, size, offset, postpone); | 206 audio_codec->PlayOutputBuffer(buffer_index, size, offset, postpone); |
207 | 207 |
208 base::TimeTicks current_time = base::TimeTicks::Now(); | 208 base::TimeTicks current_time = base::TimeTicks::Now(); |
209 | 209 |
210 frame_statistics_->IncrementFrameCount(); | 210 frame_statistics_->IncrementFrameCount(); |
211 | 211 |
212 // Reset the base timestamp if we have not started playing. | 212 // Reset the base timestamp if we have not started playing. |
213 // SetBaseTimestamp() must be called before AddFrames() since it resets the | 213 // SetBaseTimestamp() must be called before AddFrames() since it resets the |
214 // internal frame count. | 214 // internal frame count. |
215 if (postpone && !frame_count_) | 215 if (postpone && !frame_count_) |
216 SetBaseTimestamp(pts); | 216 SetBaseTimestamp(pts); |
217 | 217 |
218 size_t new_frames_count = size / bytes_per_frame_; | 218 size_t new_frames_count = size / bytes_per_frame_; |
219 frame_count_ += new_frames_count; | 219 frame_count_ += new_frames_count; |
220 audio_timestamp_helper_->AddFrames(new_frames_count); | 220 audio_timestamp_helper_->AddFrames(new_frames_count); |
221 | 221 |
222 if (postpone) { | 222 if (postpone) { |
223 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts | 223 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts |
224 << " POSTPONE"; | 224 << " POSTPONE"; |
225 | 225 |
226 // Let the player adjust the start time. | 226 // Let the player adjust the start time. |
227 media_task_runner_->PostTask( | 227 media_task_runner_->PostTask( |
228 FROM_HERE, base::Bind(update_current_time_cb_, pts, pts, true)); | 228 FROM_HERE, base::Bind(update_current_time_cb_, pts, pts, true)); |
229 } else { | 229 } else { |
230 int64 frames_to_play = frame_count_ - head_position; | 230 int64_t frames_to_play = frame_count_ - head_position; |
231 | 231 |
232 DCHECK_GE(frames_to_play, 0) << class_name() << "::" << __FUNCTION__ | 232 DCHECK_GE(frames_to_play, 0) << class_name() << "::" << __FUNCTION__ |
233 << " pts:" << pts | 233 << " pts:" << pts |
234 << " frame_count_:" << frame_count_ | 234 << " frame_count_:" << frame_count_ |
235 << " head_position:" << head_position; | 235 << " head_position:" << head_position; |
236 | 236 |
237 base::TimeDelta last_buffered = audio_timestamp_helper_->GetTimestamp(); | 237 base::TimeDelta last_buffered = audio_timestamp_helper_->GetTimestamp(); |
238 base::TimeDelta now_playing = | 238 base::TimeDelta now_playing = |
239 last_buffered - | 239 last_buffered - |
240 audio_timestamp_helper_->GetFrameDuration(frames_to_play); | 240 audio_timestamp_helper_->GetFrameDuration(frames_to_play); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 if (audio_timestamp_helper_) | 280 if (audio_timestamp_helper_) |
281 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); | 281 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); |
282 | 282 |
283 audio_timestamp_helper_.reset( | 283 audio_timestamp_helper_.reset( |
284 new AudioTimestampHelper(configs_.audio_sampling_rate)); | 284 new AudioTimestampHelper(configs_.audio_sampling_rate)); |
285 | 285 |
286 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); | 286 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); |
287 } | 287 } |
288 | 288 |
289 } // namespace media | 289 } // namespace media |
OLD | NEW |