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 |
78 // Drop null packets. | |
79 if (!packet.get()) | |
Sergey Ulanov
2012/08/15 00:47:20
You don't need this. scoped_ptr's -> operation wil
kxing
2012/08/15 16:00:05
A packet might end up null if some malicious host
Sergey Ulanov
2012/08/15 17:38:10
Oh, I see. Maybe better to handle this case in Aud
| |
80 return; | |
81 | |
82 CHECK_EQ(1, packet->data_size()); | |
83 CHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); | |
Sergey Ulanov
2012/08/15 00:47:20
nit: this doesn't really need to be CHECK - DCHECK
kxing
2012/08/15 16:00:05
Done.
| |
84 if (packet->data(0).size() % (kChannels * kSampleSizeBytes) != 0) { | |
78 LOG(WARNING) << "Received corrupted packet."; | 85 LOG(WARNING) << "Received corrupted packet."; |
79 return; | 86 return; |
80 } | 87 } |
81 base::AutoLock auto_lock(lock_); | 88 base::AutoLock auto_lock(lock_); |
82 | 89 |
83 // No-op if the Pepper player won't start. | 90 // No-op if the Pepper player won't start. |
84 if (start_failed_) { | 91 if (start_failed_) { |
85 return; | 92 return; |
86 } | 93 } |
87 | 94 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 size_t bytes_extracted = 0; | 129 size_t bytes_extracted = 0; |
123 | 130 |
124 while (bytes_extracted < bytes_needed) { | 131 while (bytes_extracted < bytes_needed) { |
125 // Check if we've run out of samples for this packet. | 132 // Check if we've run out of samples for this packet. |
126 if (queued_packets_.empty()) { | 133 if (queued_packets_.empty()) { |
127 memset(next_sample, 0, bytes_needed - bytes_extracted); | 134 memset(next_sample, 0, bytes_needed - bytes_extracted); |
128 return; | 135 return; |
129 } | 136 } |
130 | 137 |
131 // Pop off the packet if we've already consumed all its bytes. | 138 // Pop off the packet if we've already consumed all its bytes. |
132 if (queued_packets_.front()->data().size() == bytes_consumed_) { | 139 if (queued_packets_.front()->data(0).size() == bytes_consumed_) { |
133 delete queued_packets_.front(); | 140 delete queued_packets_.front(); |
134 queued_packets_.pop_front(); | 141 queued_packets_.pop_front(); |
135 bytes_consumed_ = 0; | 142 bytes_consumed_ = 0; |
136 continue; | 143 continue; |
137 } | 144 } |
138 | 145 |
139 const std::string& packet_data = queued_packets_.front()->data(); | 146 const std::string& packet_data = queued_packets_.front()->data(0); |
140 size_t bytes_to_copy = std::min( | 147 size_t bytes_to_copy = std::min( |
141 packet_data.size() - bytes_consumed_, | 148 packet_data.size() - bytes_consumed_, |
142 bytes_needed - bytes_extracted); | 149 bytes_needed - bytes_extracted); |
143 memcpy(next_sample, packet_data.data() + bytes_consumed_, bytes_to_copy); | 150 memcpy(next_sample, packet_data.data() + bytes_consumed_, bytes_to_copy); |
144 | 151 |
145 next_sample += bytes_to_copy; | 152 next_sample += bytes_to_copy; |
146 bytes_consumed_ += bytes_to_copy; | 153 bytes_consumed_ += bytes_to_copy; |
147 bytes_extracted += bytes_to_copy; | 154 bytes_extracted += bytes_to_copy; |
148 } | 155 } |
149 } | 156 } |
150 | 157 |
151 } // namespace remoting | 158 } // namespace remoting |
OLD | NEW |