diff options
author | kxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-16 01:59:49 +0000 |
---|---|---|
committer | kxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-16 01:59:49 +0000 |
commit | a88e2dbe01cf2d00bbff782e7f59ad349d5a8c04 (patch) | |
tree | 319232b87af5032dbe02f0ecd8a8d8d59115c908 /remoting | |
parent | 3559a632a525d348f561399fac8b5dea7fa5d742 (diff) | |
download | chromium_src-a88e2dbe01cf2d00bbff782e7f59ad349d5a8c04.zip chromium_src-a88e2dbe01cf2d00bbff782e7f59ad349d5a8c04.tar.gz chromium_src-a88e2dbe01cf2d00bbff782e7f59ad349d5a8c04.tar.bz2 |
Changed AudioPacket data to a repeated field.
BUG=
Review URL: https://chromiumcodereview.appspot.com/10827324
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/client/plugin/pepper_audio_player.cc | 13 | ||||
-rw-r--r-- | remoting/codec/audio_decoder_verbatim.cc | 8 | ||||
-rw-r--r-- | remoting/codec/audio_encoder_verbatim.cc | 1 | ||||
-rw-r--r-- | remoting/host/audio_capturer_win.cc | 30 | ||||
-rw-r--r-- | remoting/proto/audio.proto | 7 |
5 files changed, 38 insertions, 21 deletions
diff --git a/remoting/client/plugin/pepper_audio_player.cc b/remoting/client/plugin/pepper_audio_player.cc index 4448770..dae8c1e 100644 --- a/remoting/client/plugin/pepper_audio_player.cc +++ b/remoting/client/plugin/pepper_audio_player.cc @@ -74,7 +74,14 @@ bool PepperAudioPlayer::ResetAudioPlayer( void PepperAudioPlayer::ProcessAudioPacket(scoped_ptr<AudioPacket> packet) { // TODO(kxing): Limit the size of the queue so that latency doesn't grow // too large. - if (packet->data().size() % (kChannels * kSampleSizeBytes) != 0) { + + // Drop null packets. + if (!packet.get()) + return; + + CHECK_EQ(1, packet->data_size()); + DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); + if (packet->data(0).size() % (kChannels * kSampleSizeBytes) != 0) { LOG(WARNING) << "Received corrupted packet."; return; } @@ -129,14 +136,14 @@ void PepperAudioPlayer::FillWithSamples(void* samples, uint32_t buffer_size) { } // Pop off the packet if we've already consumed all its bytes. - if (queued_packets_.front()->data().size() == bytes_consumed_) { + if (queued_packets_.front()->data(0).size() == bytes_consumed_) { delete queued_packets_.front(); queued_packets_.pop_front(); bytes_consumed_ = 0; continue; } - const std::string& packet_data = queued_packets_.front()->data(); + const std::string& packet_data = queued_packets_.front()->data(0); size_t bytes_to_copy = std::min( packet_data.size() - bytes_consumed_, bytes_needed - bytes_extracted); diff --git a/remoting/codec/audio_decoder_verbatim.cc b/remoting/codec/audio_decoder_verbatim.cc index 8a69705..903cb3f 100644 --- a/remoting/codec/audio_decoder_verbatim.cc +++ b/remoting/codec/audio_decoder_verbatim.cc @@ -17,7 +17,13 @@ AudioDecoderVerbatim::~AudioDecoderVerbatim() { scoped_ptr<AudioPacket> AudioDecoderVerbatim::Decode( scoped_ptr<AudioPacket> packet) { - DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); + // Return a null scoped_ptr if we get a corrupted packet. + if ((packet->encoding() != AudioPacket::ENCODING_RAW) || + (packet->data_size() != 1) || + (packet->sampling_rate() == AudioPacket::SAMPLING_RATE_INVALID) || + (packet->bytes_per_sample() == AudioPacket::BYTES_PER_SAMPLE_INVALID)) { + return scoped_ptr<AudioPacket>(); + } return packet.Pass(); } diff --git a/remoting/codec/audio_encoder_verbatim.cc b/remoting/codec/audio_encoder_verbatim.cc index b81486b..52e578a 100644 --- a/remoting/codec/audio_encoder_verbatim.cc +++ b/remoting/codec/audio_encoder_verbatim.cc @@ -16,6 +16,7 @@ AudioEncoderVerbatim::~AudioEncoderVerbatim() {} scoped_ptr<AudioPacket> AudioEncoderVerbatim::Encode( scoped_ptr<AudioPacket> packet) { DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); + DCHECK_EQ(1, packet->data_size()); return packet.Pass(); } diff --git a/remoting/host/audio_capturer_win.cc b/remoting/host/audio_capturer_win.cc index b450a9a..c648a0a 100644 --- a/remoting/host/audio_capturer_win.cc +++ b/remoting/host/audio_capturer_win.cc @@ -53,7 +53,7 @@ class AudioCapturerWin : public AudioCapturer { // to the network. void DoCapture(); - static bool IsPacketOfSilence(const AudioPacket* packet); + static bool IsPacketOfSilence(const int16* samples, int number_of_samples); PacketCapturedCallback callback_; @@ -274,15 +274,19 @@ void AudioCapturerWin::DoCapture() { return; } - scoped_ptr<AudioPacket> packet = scoped_ptr<AudioPacket>(new AudioPacket()); - packet->set_data(data, frames * wave_format_ex_->nBlockAlign); - packet->set_sampling_rate(sampling_rate_); - packet->set_bytes_per_sample( - static_cast<AudioPacket::BytesPerSample>(sizeof(int16))); - packet->set_encoding(AudioPacket::ENCODING_RAW); + if (!IsPacketOfSilence( + reinterpret_cast<const int16*>(data), + frames * kChannels)) { + scoped_ptr<AudioPacket> packet = + scoped_ptr<AudioPacket>(new AudioPacket()); + packet->add_data(data, frames * wave_format_ex_->nBlockAlign); + packet->set_sampling_rate(sampling_rate_); + packet->set_bytes_per_sample( + static_cast<AudioPacket::BytesPerSample>(sizeof(int16))); + packet->set_encoding(AudioPacket::ENCODING_RAW); - if (!IsPacketOfSilence(packet.get())) callback_.Run(packet.Pass()); + } hr = audio_capture_client_->ReleaseBuffer(frames); if (FAILED(hr)) { @@ -295,14 +299,10 @@ void AudioCapturerWin::DoCapture() { // Detects whether there is audio playing in a packet of samples. // Windows can give nonzero samples, even when there is no audio playing, so // extremely low amplitude samples are counted as silence. -bool AudioCapturerWin::IsPacketOfSilence(const AudioPacket* packet) { - DCHECK_EQ(static_cast<AudioPacket::BytesPerSample>(sizeof(int16)), - packet->bytes_per_sample()); - const int16* data = reinterpret_cast<const int16*>(packet->data().data()); - int number_of_samples = packet->data().size() * kBitsPerByte / kBitsPerSample; - +bool AudioCapturerWin::IsPacketOfSilence( + const int16* samples, int number_of_samples) { for (int i = 0; i < number_of_samples; i++) { - if (abs(data[i]) > kSilenceThreshold) + if (abs(samples[i]) > kSilenceThreshold) return false; } return true; diff --git a/remoting/proto/audio.proto b/remoting/proto/audio.proto index eabfcfe..d23071c 100644 --- a/remoting/proto/audio.proto +++ b/remoting/proto/audio.proto @@ -13,8 +13,11 @@ package remoting; message AudioPacket { optional int32 timestamp = 1 [default = 0]; - // Data is always signed and represented using little endian. - optional bytes data = 2; + // Packets with raw data must have exactly one data field. + // For those packets, samples are signed and represented using little endian. + // Some encoders (eg. Speex) may add multiple data fields to separate encoded + // frames. + repeated bytes data = 2; enum Encoding { ENCODING_INVALID = -1; |