Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: remoting/client/plugin/pepper_audio_player.cc

Issue 10823420: Added more error checking for audio packets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comment Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 77
78 // Drop null packets.
79 if (!packet.get())
80 return;
81
82 CHECK_EQ(1, packet->data_size()); 78 CHECK_EQ(1, packet->data_size());
83 DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); 79 DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding());
80 DCHECK_NE(AudioPacket::SAMPLING_RATE_INVALID, packet->sampling_rate());
81 DCHECK_EQ(kSampleSizeBytes, packet->bytes_per_sample());
82 DCHECK_EQ(static_cast<int>(kChannels), packet->channels());
83
84 if (packet->data(0).size() % (kChannels * kSampleSizeBytes) != 0) { 84 if (packet->data(0).size() % (kChannels * kSampleSizeBytes) != 0) {
85 LOG(WARNING) << "Received corrupted packet."; 85 LOG(WARNING) << "Received corrupted packet.";
86 return; 86 return;
87 } 87 }
88 base::AutoLock auto_lock(lock_); 88 base::AutoLock auto_lock(lock_);
89 89
90 // No-op if the Pepper player won't start. 90 // No-op if the Pepper player won't start.
91 if (start_failed_) { 91 if (start_failed_) {
92 return; 92 return;
93 } 93 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 bytes_needed - bytes_extracted); 149 bytes_needed - bytes_extracted);
150 memcpy(next_sample, packet_data.data() + bytes_consumed_, bytes_to_copy); 150 memcpy(next_sample, packet_data.data() + bytes_consumed_, bytes_to_copy);
151 151
152 next_sample += bytes_to_copy; 152 next_sample += bytes_to_copy;
153 bytes_consumed_ += bytes_to_copy; 153 bytes_consumed_ += bytes_to_copy;
154 bytes_extracted += bytes_to_copy; 154 bytes_extracted += bytes_to_copy;
155 } 155 }
156 } 156 }
157 157
158 } // namespace remoting 158 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698