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

Side by Side Diff: remoting/host/audio_capturer.cc

Issue 10820059: Not streaming packets of silence. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/host/audio_capturer.h" 5 #include "remoting/host/audio_capturer.h"
6 6
7 #include <math.h>
Sergey Ulanov 2012/07/27 22:46:51 abs() is in stdlib.h
kxing 2012/07/30 16:55:18 Done.
8
9 #include "base/basictypes.h"
7 #include "remoting/proto/audio.pb.h" 10 #include "remoting/proto/audio.pb.h"
8 11
12 namespace {
13 const int kBytesPerSample = 2;
14 const int kSilenceThreshold = 2;
15 } // namespace
16
9 namespace remoting { 17 namespace remoting {
10 18
19 // static
11 bool AudioCapturer::IsValidSampleRate(int sample_rate) { 20 bool AudioCapturer::IsValidSampleRate(int sample_rate) {
12 switch (sample_rate) { 21 switch (sample_rate) {
13 case AudioPacket::SAMPLING_RATE_44100: 22 case AudioPacket::SAMPLING_RATE_44100:
14 case AudioPacket::SAMPLING_RATE_48000: 23 case AudioPacket::SAMPLING_RATE_48000:
15 return true; 24 return true;
16 default: 25 default:
17 return false; 26 return false;
18 } 27 }
19 } 28 }
20 29
30 // static
31 bool AudioCapturer::IsPacketOfSilence(const AudioPacket* packet) {
32 const int16* data = reinterpret_cast<const int16*>(packet->data().data());
33 int number_of_samples = packet->data().size() / kBytesPerSample;
34
35 for (int i = 0; i < number_of_samples; i++) {
36 if (std::abs(data[i]) > kSilenceThreshold)
Sergey Ulanov 2012/07/27 22:46:51 I think using memchr() to verify that the data is
Sergey Ulanov 2012/07/27 22:46:51 abs() without std::
kxing 2012/07/30 16:55:18 Done.
kxing 2012/07/30 16:55:18 Windows can give samples such as [0, 0, 0, 1, -1,
Sergey Ulanov 2012/07/30 17:53:48 Hm. that is strange. Then it looks like this parti
kxing 2012/07/30 20:21:36 Done.
37 return false;
38 }
39 return true;
40 }
41
21 } // namespace remoting 42 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698