| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 namespace media { | 34 namespace media { |
| 35 | 35 |
| 36 class MultizoneBackendTest; | 36 class MultizoneBackendTest; |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 const int64_t kMicrosecondsPerSecond = 1000 * 1000; | 40 const int64_t kMicrosecondsPerSecond = 1000 * 1000; |
| 41 // Total length of test, in microseconds. | 41 // Total length of test, in microseconds. |
| 42 const int64_t kPushTimeUs = 2 * kMicrosecondsPerSecond; | 42 const int64_t kPushTimeUs = 2 * kMicrosecondsPerSecond; |
| 43 const int64_t kStartPts = 0; | 43 const int64_t kStartPts = 0; |
| 44 const int64_t kRenderingDelayGracePeriodUs = 250 * 1000; | |
| 45 const int64_t kMaxRenderingDelayErrorUs = 200; | 44 const int64_t kMaxRenderingDelayErrorUs = 200; |
| 46 const int kNumEffectsStreams = 1; | 45 const int kNumEffectsStreams = 1; |
| 46 const int64_t kNoTimestamp = std::numeric_limits<int64_t>::min(); |
| 47 | 47 |
| 48 void IgnoreEos() {} | 48 void IgnoreEos() {} |
| 49 | 49 |
| 50 class BufferFeeder : public MediaPipelineBackend::Decoder::Delegate { | 50 class BufferFeeder : public MediaPipelineBackend::Decoder::Delegate { |
| 51 public: | 51 public: |
| 52 BufferFeeder(const AudioConfig& config, | 52 BufferFeeder(const AudioConfig& config, |
| 53 bool effects_only, | 53 bool effects_only, |
| 54 const base::Closure& eos_cb); | 54 const base::Closure& eos_cb); |
| 55 ~BufferFeeder() override {} | 55 ~BufferFeeder() override {} |
| 56 | 56 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 max_positive_rendering_delay_error_us_(0), | 164 max_positive_rendering_delay_error_us_(0), |
| 165 max_negative_rendering_delay_error_us_(0), | 165 max_negative_rendering_delay_error_us_(0), |
| 166 total_rendering_delay_error_us_(0), | 166 total_rendering_delay_error_us_(0), |
| 167 sample_count_(0), | 167 sample_count_(0), |
| 168 feeding_completed_(false), | 168 feeding_completed_(false), |
| 169 task_runner_(new TaskRunnerImpl()), | 169 task_runner_(new TaskRunnerImpl()), |
| 170 decoder_(nullptr), | 170 decoder_(nullptr), |
| 171 push_limit_us_(effects_only_ ? 0 : kPushTimeUs), | 171 push_limit_us_(effects_only_ ? 0 : kPushTimeUs), |
| 172 last_push_length_us_(0), | 172 last_push_length_us_(0), |
| 173 pushed_us_(0), | 173 pushed_us_(0), |
| 174 next_push_playback_timestamp_(0) { | 174 next_push_playback_timestamp_(kNoTimestamp) { |
| 175 CHECK(!eos_cb_.is_null()); | 175 CHECK(!eos_cb_.is_null()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void BufferFeeder::Initialize() { | 178 void BufferFeeder::Initialize() { |
| 179 MediaPipelineDeviceParams params( | 179 MediaPipelineDeviceParams params( |
| 180 MediaPipelineDeviceParams::kModeIgnorePts, | 180 MediaPipelineDeviceParams::kModeIgnorePts, |
| 181 effects_only_ ? MediaPipelineDeviceParams::kAudioStreamSoundEffects | 181 effects_only_ ? MediaPipelineDeviceParams::kAudioStreamSoundEffects |
| 182 : MediaPipelineDeviceParams::kAudioStreamNormal, | 182 : MediaPipelineDeviceParams::kAudioStreamNormal, |
| 183 task_runner_.get()); | 183 task_runner_.get()); |
| 184 backend_.reset(CastMediaShlib::CreateMediaPipelineBackend(params)); | 184 backend_.reset(CastMediaShlib::CreateMediaPipelineBackend(params)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 239 } |
| 240 | 240 |
| 241 void BufferFeeder::OnPushBufferComplete(BufferStatus status) { | 241 void BufferFeeder::OnPushBufferComplete(BufferStatus status) { |
| 242 DCHECK(thread_checker_.CalledOnValidThread()); | 242 DCHECK(thread_checker_.CalledOnValidThread()); |
| 243 pending_buffer_ = nullptr; | 243 pending_buffer_ = nullptr; |
| 244 ASSERT_NE(status, MediaPipelineBackend::kBufferFailed); | 244 ASSERT_NE(status, MediaPipelineBackend::kBufferFailed); |
| 245 | 245 |
| 246 if (!effects_only_) { | 246 if (!effects_only_) { |
| 247 MediaPipelineBackend::AudioDecoder::RenderingDelay delay = | 247 MediaPipelineBackend::AudioDecoder::RenderingDelay delay = |
| 248 decoder_->GetRenderingDelay(); | 248 decoder_->GetRenderingDelay(); |
| 249 int64_t expected_next_push_playback_timestamp = | 249 |
| 250 next_push_playback_timestamp_ + last_push_length_us_; | 250 if (delay.timestamp_microseconds != kNoTimestamp) { |
| 251 next_push_playback_timestamp_ = | 251 if (next_push_playback_timestamp_ == kNoTimestamp) { |
| 252 delay.timestamp_microseconds + delay.delay_microseconds; | 252 next_push_playback_timestamp_ = |
| 253 // Check rendering delay accuracy only if we have pushed more than | 253 delay.timestamp_microseconds + delay.delay_microseconds; |
| 254 // kRenderingDelayGracePeriodUs of data. | |
| 255 if (pushed_us_ > kRenderingDelayGracePeriodUs) { | |
| 256 int64_t error = | |
| 257 next_push_playback_timestamp_ - expected_next_push_playback_timestamp; | |
| 258 max_rendering_delay_error_us_ = | |
| 259 std::max(max_rendering_delay_error_us_, std::abs(error)); | |
| 260 total_rendering_delay_error_us_ += std::abs(error); | |
| 261 if (error >= 0) { | |
| 262 max_positive_rendering_delay_error_us_ = | |
| 263 std::max(max_positive_rendering_delay_error_us_, error); | |
| 264 } else { | 254 } else { |
| 265 max_negative_rendering_delay_error_us_ = | 255 int64_t expected_next_push_playback_timestamp = |
| 266 std::min(max_negative_rendering_delay_error_us_, error); | 256 next_push_playback_timestamp_ + last_push_length_us_; |
| 257 next_push_playback_timestamp_ = |
| 258 delay.timestamp_microseconds + delay.delay_microseconds; |
| 259 int64_t error = next_push_playback_timestamp_ - |
| 260 expected_next_push_playback_timestamp; |
| 261 max_rendering_delay_error_us_ = |
| 262 std::max(max_rendering_delay_error_us_, std::abs(error)); |
| 263 total_rendering_delay_error_us_ += std::abs(error); |
| 264 if (error >= 0) { |
| 265 max_positive_rendering_delay_error_us_ = |
| 266 std::max(max_positive_rendering_delay_error_us_, error); |
| 267 } else { |
| 268 max_negative_rendering_delay_error_us_ = |
| 269 std::min(max_negative_rendering_delay_error_us_, error); |
| 270 } |
| 271 sample_count_++; |
| 267 } | 272 } |
| 268 sample_count_++; | |
| 269 } | 273 } |
| 270 } | 274 } |
| 271 pushed_us_ += last_push_length_us_; | 275 pushed_us_ += last_push_length_us_; |
| 272 | 276 |
| 273 if (feeding_completed_) | 277 if (feeding_completed_) |
| 274 return; | 278 return; |
| 275 | 279 |
| 276 base::ThreadTaskRunnerHandle::Get()->PostTask( | 280 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 277 FROM_HERE, base::Bind(&BufferFeeder::FeedBuffer, base::Unretained(this))); | 281 FROM_HERE, base::Bind(&BufferFeeder::FeedBuffer, base::Unretained(this))); |
| 278 } | 282 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 32000, | 362 32000, |
| 359 44100, | 363 44100, |
| 360 48000)); | 364 48000)); |
| 361 | 365 |
| 362 INSTANTIATE_TEST_CASE_P(Optional, | 366 INSTANTIATE_TEST_CASE_P(Optional, |
| 363 MultizoneBackendTest, | 367 MultizoneBackendTest, |
| 364 ::testing::Values(64000, 88200, 96000)); | 368 ::testing::Values(64000, 88200, 96000)); |
| 365 | 369 |
| 366 } // namespace media | 370 } // namespace media |
| 367 } // namespace chromecast | 371 } // namespace chromecast |
| OLD | NEW |