| 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/audio_media_codec_decoder.h" | 5 #include "media/base/android/audio_media_codec_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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 return kConfigOk; | 169 return kConfigOk; |
| 170 } | 170 } |
| 171 | 171 |
| 172 void AudioMediaCodecDecoder::OnOutputFormatChanged() { | 172 void AudioMediaCodecDecoder::OnOutputFormatChanged() { |
| 173 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); | 173 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); |
| 174 | 174 |
| 175 DCHECK(media_codec_bridge_); | 175 DCHECK(media_codec_bridge_); |
| 176 | 176 |
| 177 int old_sampling_rate = output_sampling_rate_; | 177 int old_sampling_rate = output_sampling_rate_; |
| 178 output_sampling_rate_ = media_codec_bridge_->GetOutputSamplingRate(); | 178 MediaCodecStatus status = |
| 179 if (output_sampling_rate_ != old_sampling_rate) | 179 media_codec_bridge_->GetOutputSamplingRate(&output_sampling_rate_); |
| 180 if (status != MEDIA_CODEC_OK || output_sampling_rate_ != old_sampling_rate) |
| 180 ResetTimestampHelper(); | 181 ResetTimestampHelper(); |
| 181 } | 182 } |
| 182 | 183 |
| 183 void AudioMediaCodecDecoder::Render(int buffer_index, | 184 void AudioMediaCodecDecoder::Render(int buffer_index, |
| 184 size_t offset, | 185 size_t offset, |
| 185 size_t size, | 186 size_t size, |
| 186 RenderMode render_mode, | 187 RenderMode render_mode, |
| 187 base::TimeDelta pts, | 188 base::TimeDelta pts, |
| 188 bool eos_encountered) { | 189 bool eos_encountered) { |
| 189 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); | 190 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); |
| 190 | 191 |
| 191 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts << " " | 192 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts << " " |
| 192 << AsString(render_mode); | 193 << AsString(render_mode); |
| 193 | 194 |
| 194 const bool do_play = (render_mode != kRenderSkip); | 195 const bool do_play = (render_mode != kRenderSkip); |
| 195 | 196 |
| 196 if (do_play) { | 197 if (do_play) { |
| 197 AudioCodecBridge* audio_codec = | 198 AudioCodecBridge* audio_codec = |
| 198 static_cast<AudioCodecBridge*>(media_codec_bridge_.get()); | 199 static_cast<AudioCodecBridge*>(media_codec_bridge_.get()); |
| 199 | 200 |
| 200 DCHECK(audio_codec); | 201 DCHECK(audio_codec); |
| 201 | 202 |
| 202 const bool postpone = (render_mode == kRenderAfterPreroll); | 203 const bool postpone = (render_mode == kRenderAfterPreroll); |
| 203 | 204 |
| 204 int64_t head_position = | 205 int64_t head_position; |
| 205 audio_codec->PlayOutputBuffer(buffer_index, size, offset, postpone); | 206 MediaCodecStatus status = audio_codec->PlayOutputBuffer( |
| 207 buffer_index, size, offset, postpone, &head_position); |
| 208 // TODO(timav,watk): This CHECK maintains the behavior of this call before |
| 209 // we started catching CodecException and returning it as MEDIA_CODEC_ERROR. |
| 210 // It needs to be handled some other way. http://crbug.com/585978 |
| 211 CHECK_EQ(status, MEDIA_CODEC_OK); |
| 206 | 212 |
| 207 base::TimeTicks current_time = base::TimeTicks::Now(); | 213 base::TimeTicks current_time = base::TimeTicks::Now(); |
| 208 | 214 |
| 209 frame_statistics_->IncrementFrameCount(); | 215 frame_statistics_->IncrementFrameCount(); |
| 210 | 216 |
| 211 // Reset the base timestamp if we have not started playing. | 217 // Reset the base timestamp if we have not started playing. |
| 212 // SetBaseTimestamp() must be called before AddFrames() since it resets the | 218 // SetBaseTimestamp() must be called before AddFrames() since it resets the |
| 213 // internal frame count. | 219 // internal frame count. |
| 214 if (postpone && !frame_count_) | 220 if (postpone && !frame_count_) |
| 215 SetBaseTimestamp(pts); | 221 SetBaseTimestamp(pts); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 if (audio_timestamp_helper_) | 285 if (audio_timestamp_helper_) |
| 280 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); | 286 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); |
| 281 | 287 |
| 282 audio_timestamp_helper_.reset( | 288 audio_timestamp_helper_.reset( |
| 283 new AudioTimestampHelper(configs_.audio_sampling_rate)); | 289 new AudioTimestampHelper(configs_.audio_sampling_rate)); |
| 284 | 290 |
| 285 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); | 291 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); |
| 286 } | 292 } |
| 287 | 293 |
| 288 } // namespace media | 294 } // namespace media |
| OLD | NEW |