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/plugin/pepper_audio_player.h" | 5 #include "remoting/client/plugin/pepper_audio_player.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 // Immediately start the player. | 67 // Immediately start the player. |
68 bool success = audio_.StartPlayback(); | 68 bool success = audio_.StartPlayback(); |
69 if (!success) | 69 if (!success) |
70 LOG(ERROR) << "Failed to start Pepper audio player"; | 70 LOG(ERROR) << "Failed to start Pepper audio player"; |
71 return success; | 71 return success; |
72 } | 72 } |
73 | 73 |
74 void PepperAudioPlayer::ProcessAudioPacket(scoped_ptr<AudioPacket> packet) { | 74 void PepperAudioPlayer::ProcessAudioPacket(scoped_ptr<AudioPacket> packet) { |
75 // TODO(kxing): Limit the size of the queue so that latency doesn't grow | 75 // TODO(kxing): Limit the size of the queue so that latency doesn't grow |
76 // too large. | 76 // too large. |
77 if (packet->data().size() % (kChannels * kSampleSizeBytes) != 0) { | 77 DCHECK_EQ(1, packet->data_size()); |
78 if (packet->data(0).size() % (kChannels * kSampleSizeBytes) != 0) { | |
Sergey Ulanov
2012/08/14 18:50:05
data(index) dchecks that the index is correct, so
kxing
2012/08/14 20:56:15
Done.
| |
78 LOG(WARNING) << "Received corrupted packet."; | 79 LOG(WARNING) << "Received corrupted packet."; |
79 return; | 80 return; |
80 } | 81 } |
81 base::AutoLock auto_lock(lock_); | 82 base::AutoLock auto_lock(lock_); |
82 | 83 |
83 // No-op if the Pepper player won't start. | 84 // No-op if the Pepper player won't start. |
84 if (start_failed_) { | 85 if (start_failed_) { |
85 return; | 86 return; |
86 } | 87 } |
87 | 88 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 size_t bytes_extracted = 0; | 123 size_t bytes_extracted = 0; |
123 | 124 |
124 while (bytes_extracted < bytes_needed) { | 125 while (bytes_extracted < bytes_needed) { |
125 // Check if we've run out of samples for this packet. | 126 // Check if we've run out of samples for this packet. |
126 if (queued_packets_.empty()) { | 127 if (queued_packets_.empty()) { |
127 memset(next_sample, 0, bytes_needed - bytes_extracted); | 128 memset(next_sample, 0, bytes_needed - bytes_extracted); |
128 return; | 129 return; |
129 } | 130 } |
130 | 131 |
131 // Pop off the packet if we've already consumed all its bytes. | 132 // Pop off the packet if we've already consumed all its bytes. |
132 if (queued_packets_.front()->data().size() == bytes_consumed_) { | 133 if (queued_packets_.front()->data(0).size() == bytes_consumed_) { |
133 delete queued_packets_.front(); | 134 delete queued_packets_.front(); |
134 queued_packets_.pop_front(); | 135 queued_packets_.pop_front(); |
135 bytes_consumed_ = 0; | 136 bytes_consumed_ = 0; |
136 continue; | 137 continue; |
137 } | 138 } |
138 | 139 |
139 const std::string& packet_data = queued_packets_.front()->data(); | 140 const std::string& packet_data = queued_packets_.front()->data(0); |
140 size_t bytes_to_copy = std::min( | 141 size_t bytes_to_copy = std::min( |
141 packet_data.size() - bytes_consumed_, | 142 packet_data.size() - bytes_consumed_, |
142 bytes_needed - bytes_extracted); | 143 bytes_needed - bytes_extracted); |
143 memcpy(next_sample, packet_data.data() + bytes_consumed_, bytes_to_copy); | 144 memcpy(next_sample, packet_data.data() + bytes_consumed_, bytes_to_copy); |
144 | 145 |
145 next_sample += bytes_to_copy; | 146 next_sample += bytes_to_copy; |
146 bytes_consumed_ += bytes_to_copy; | 147 bytes_consumed_ += bytes_to_copy; |
147 bytes_extracted += bytes_to_copy; | 148 bytes_extracted += bytes_to_copy; |
148 } | 149 } |
149 } | 150 } |
150 | 151 |
151 } // namespace remoting | 152 } // namespace remoting |
OLD | NEW |