| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/client/audio_player.h" | 5 #include "remoting/client/audio_player.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/logging.h" | 10 #include "base/logging.h" | 
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" | 
| 12 | 12 | 
| 13 // If queue grows bigger than 150ms we start dropping packets. | 13 // If queue grows bigger than 150ms we start dropping packets. | 
| 14 const int kMaxQueueLatencyMs = 150; | 14 const int kMaxQueueLatencyMs = 150; | 
| 15 | 15 | 
| 16 namespace remoting { | 16 namespace remoting { | 
| 17 | 17 | 
| 18 AudioPlayer::AudioPlayer() | 18 AudioPlayer::AudioPlayer() | 
| 19     : sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID), | 19     : sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID), | 
| 20       start_failed_(false), | 20       start_failed_(false), | 
| 21       queued_bytes_(0), | 21       queued_bytes_(0), | 
| 22       bytes_consumed_(0) { | 22       bytes_consumed_(0) { | 
| 23 } | 23 } | 
| 24 | 24 | 
| 25 AudioPlayer::~AudioPlayer() { | 25 AudioPlayer::~AudioPlayer() {} | 
| 26 } |  | 
| 27 | 26 | 
| 28 void AudioPlayer::AddAudioPacket(std::unique_ptr<AudioPacket> packet) { | 27 void AudioPlayer::AddAudioPacket(std::unique_ptr<AudioPacket> packet) { | 
| 29   CHECK_EQ(1, packet->data_size()); | 28   CHECK_EQ(1, packet->data_size()); | 
| 30   DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); | 29   DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); | 
| 31   DCHECK_NE(AudioPacket::SAMPLING_RATE_INVALID, packet->sampling_rate()); | 30   DCHECK_NE(AudioPacket::SAMPLING_RATE_INVALID, packet->sampling_rate()); | 
| 32   DCHECK_EQ(kSampleSizeBytes, static_cast<int>(packet->bytes_per_sample())); | 31   DCHECK_EQ(kSampleSizeBytes, static_cast<int>(packet->bytes_per_sample())); | 
| 33   DCHECK_EQ(kChannels, static_cast<int>(packet->channels())); | 32   DCHECK_EQ(kChannels, static_cast<int>(packet->channels())); | 
| 34   DCHECK_EQ(packet->data(0).size() % (kChannels * kSampleSizeBytes), 0u); | 33   DCHECK_EQ(packet->data(0).size() % (kChannels * kSampleSizeBytes), 0u); | 
| 35 | 34 | 
| 36   // No-op if the Pepper player won't start. | 35   // No-op if the Pepper player won't start. | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 64       kMaxQueueLatencyMs * sampling_rate_ * kSampleSizeBytes * kChannels / | 63       kMaxQueueLatencyMs * sampling_rate_ * kSampleSizeBytes * kChannels / | 
| 65       base::Time::kMillisecondsPerSecond; | 64       base::Time::kMillisecondsPerSecond; | 
| 66   while (queued_bytes_ > max_buffer_size_) { | 65   while (queued_bytes_ > max_buffer_size_) { | 
| 67     queued_bytes_ -= queued_packets_.front()->data(0).size() - bytes_consumed_; | 66     queued_bytes_ -= queued_packets_.front()->data(0).size() - bytes_consumed_; | 
| 68     DCHECK_GE(queued_bytes_, 0); | 67     DCHECK_GE(queued_bytes_, 0); | 
| 69     queued_packets_.pop_front(); | 68     queued_packets_.pop_front(); | 
| 70     bytes_consumed_ = 0; | 69     bytes_consumed_ = 0; | 
| 71   } | 70   } | 
| 72 } | 71 } | 
| 73 | 72 | 
| 74 void AudioPlayer::ProcessAudioPacket(std::unique_ptr<AudioPacket> packet) { |  | 
| 75   AddAudioPacket(std::move(packet)); |  | 
| 76 } |  | 
| 77 |  | 
| 78 // static | 73 // static | 
| 79 void AudioPlayer::AudioPlayerCallback(void* samples, | 74 void AudioPlayer::AudioPlayerCallback(void* samples, | 
| 80                                       uint32_t buffer_size, | 75                                       uint32_t buffer_size, | 
| 81                                       void* data) { | 76                                       void* data) { | 
| 82   AudioPlayer* audio_player = static_cast<AudioPlayer*>(data); | 77   AudioPlayer* audio_player = static_cast<AudioPlayer*>(data); | 
| 83   audio_player->FillWithSamples(samples, buffer_size); | 78   audio_player->FillWithSamples(samples, buffer_size); | 
| 84 } | 79 } | 
| 85 | 80 | 
| 86 void AudioPlayer::ResetQueue() { | 81 void AudioPlayer::ResetQueue() { | 
| 87   lock_.AssertAcquired(); | 82   lock_.AssertAcquired(); | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 124 | 119 | 
| 125     next_sample += bytes_to_copy; | 120     next_sample += bytes_to_copy; | 
| 126     bytes_consumed_ += bytes_to_copy; | 121     bytes_consumed_ += bytes_to_copy; | 
| 127     bytes_extracted += bytes_to_copy; | 122     bytes_extracted += bytes_to_copy; | 
| 128     queued_bytes_ -= bytes_to_copy; | 123     queued_bytes_ -= bytes_to_copy; | 
| 129     DCHECK_GE(queued_bytes_, 0); | 124     DCHECK_GE(queued_bytes_, 0); | 
| 130   } | 125   } | 
| 131 } | 126 } | 
| 132 | 127 | 
| 133 }  // namespace remoting | 128 }  // namespace remoting | 
| OLD | NEW | 
|---|