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/callback_helpers.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 | 13 |
13 // If queue grows bigger than 150ms we start dropping packets. | 14 // If queue grows bigger than 150ms we start dropping packets. |
14 const int kMaxQueueLatencyMs = 150; | 15 const int kMaxQueueLatencyMs = 150; |
15 | 16 |
16 namespace remoting { | 17 namespace remoting { |
17 | 18 |
18 AudioPlayer::AudioPlayer() | 19 AudioPlayer::AudioPlayer() |
19 : sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID), | 20 : sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID), |
20 start_failed_(false), | 21 start_failed_(false), |
21 queued_bytes_(0), | 22 queued_bytes_(0), |
22 bytes_consumed_(0) { | 23 bytes_consumed_(0) {} |
23 } | |
24 | 24 |
25 AudioPlayer::~AudioPlayer() {} | 25 AudioPlayer::~AudioPlayer() {} |
26 | 26 |
27 void AudioPlayer::AddAudioPacket(std::unique_ptr<AudioPacket> packet) { | 27 void AudioPlayer::ProcessAudioPacket(std::unique_ptr<AudioPacket> packet, |
| 28 const base::Closure& done) { |
28 CHECK_EQ(1, packet->data_size()); | 29 CHECK_EQ(1, packet->data_size()); |
29 DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); | 30 DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); |
30 DCHECK_NE(AudioPacket::SAMPLING_RATE_INVALID, packet->sampling_rate()); | 31 DCHECK_NE(AudioPacket::SAMPLING_RATE_INVALID, packet->sampling_rate()); |
31 DCHECK_EQ(kSampleSizeBytes, static_cast<int>(packet->bytes_per_sample())); | 32 DCHECK_EQ(kSampleSizeBytes, static_cast<int>(packet->bytes_per_sample())); |
32 DCHECK_EQ(kChannels, static_cast<int>(packet->channels())); | 33 DCHECK_EQ(kChannels, static_cast<int>(packet->channels())); |
33 DCHECK_EQ(packet->data(0).size() % (kChannels * kSampleSizeBytes), 0u); | 34 DCHECK_EQ(packet->data(0).size() % (kChannels * kSampleSizeBytes), 0u); |
34 | 35 |
| 36 base::ScopedClosureRunner done_runner(done); |
| 37 |
35 // No-op if the Pepper player won't start. | 38 // No-op if the Pepper player won't start. |
36 if (start_failed_) { | 39 if (start_failed_) { |
37 return; | 40 return; |
38 } | 41 } |
39 | 42 |
40 // Start the Pepper audio player if this is the first packet. | 43 // Start the Pepper audio player if this is the first packet. |
41 if (sampling_rate_ != packet->sampling_rate()) { | 44 if (sampling_rate_ != packet->sampling_rate()) { |
42 // Drop all packets currently in the queue, since they are sampled at the | 45 // Drop all packets currently in the queue, since they are sampled at the |
43 // wrong rate. | 46 // wrong rate. |
44 { | 47 { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 122 |
120 next_sample += bytes_to_copy; | 123 next_sample += bytes_to_copy; |
121 bytes_consumed_ += bytes_to_copy; | 124 bytes_consumed_ += bytes_to_copy; |
122 bytes_extracted += bytes_to_copy; | 125 bytes_extracted += bytes_to_copy; |
123 queued_bytes_ -= bytes_to_copy; | 126 queued_bytes_ -= bytes_to_copy; |
124 DCHECK_GE(queued_bytes_, 0); | 127 DCHECK_GE(queued_bytes_, 0); |
125 } | 128 } |
126 } | 129 } |
127 | 130 |
128 } // namespace remoting | 131 } // namespace remoting |
OLD | NEW |