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

Side by Side Diff: media/audio/audio_parameters.cc

Issue 9655018: Make AudioParameters a class instead of a struct (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copyright years Created 8 years, 9 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
« no previous file with comments | « media/audio/audio_parameters.h ('k') | media/audio/audio_parameters_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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 "media/audio/audio_parameters.h" 5 #include "media/audio/audio_parameters.h"
6 6
7 #include "media/base/limits.h" 7 #include "media/base/limits.h"
8 8
9 AudioParameters::AudioParameters() 9 AudioParameters::AudioParameters()
10 : format(AUDIO_PCM_LINEAR), 10 : format_(AUDIO_PCM_LINEAR),
11 channel_layout(CHANNEL_LAYOUT_NONE), 11 channel_layout_(CHANNEL_LAYOUT_NONE),
12 sample_rate(0), 12 sample_rate_(0),
13 bits_per_sample(0), 13 bits_per_sample_(0),
14 samples_per_packet(0), 14 frames_per_buffer_(0),
15 channels(0) { 15 channels_(0) {
16 } 16 }
17 17
18 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, 18 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout,
19 int sample_rate, int bits_per_sample, 19 int sample_rate, int bits_per_sample,
20 int samples_per_packet) 20 int frames_per_buffer)
21 : format(format), 21 : format_(format),
22 channel_layout(channel_layout), 22 channel_layout_(channel_layout),
23 sample_rate(sample_rate), 23 sample_rate_(sample_rate),
24 bits_per_sample(bits_per_sample), 24 bits_per_sample_(bits_per_sample),
25 samples_per_packet(samples_per_packet), 25 frames_per_buffer_(frames_per_buffer),
26 channels(ChannelLayoutToChannelCount(channel_layout)) { 26 channels_(ChannelLayoutToChannelCount(channel_layout)) {
27 }
28
29 void AudioParameters::Reset(Format format, ChannelLayout channel_layout,
30 int sample_rate, int bits_per_sample,
31 int frames_per_buffer) {
32 format_ = format;
33 channel_layout_ = channel_layout;
34 sample_rate_ = sample_rate;
35 bits_per_sample_ = bits_per_sample;
36 frames_per_buffer_ = frames_per_buffer;
37 channels_ = ChannelLayoutToChannelCount(channel_layout);
27 } 38 }
28 39
29 bool AudioParameters::IsValid() const { 40 bool AudioParameters::IsValid() const {
30 return (format >= 0) && (format < AUDIO_LAST_FORMAT) && 41 return (format_ >= 0) && (format_ < AUDIO_LAST_FORMAT) &&
31 (channels > 0) && (channels <= media::limits::kMaxChannels) && 42 (channels_ > 0) && (channels_ <= media::limits::kMaxChannels) &&
32 (sample_rate > 0) && (sample_rate <= media::limits::kMaxSampleRate) && 43 (sample_rate_ > 0) &&
33 (bits_per_sample > 0) && 44 (sample_rate_ <= media::limits::kMaxSampleRate) &&
34 (bits_per_sample <= media::limits::kMaxBitsPerSample) && 45 (bits_per_sample_ > 0) &&
35 (samples_per_packet > 0) && 46 (bits_per_sample_ <= media::limits::kMaxBitsPerSample) &&
36 (samples_per_packet <= media::limits::kMaxSamplesPerPacket); 47 (frames_per_buffer_ > 0) &&
48 (frames_per_buffer_ <= media::limits::kMaxSamplesPerPacket);
37 } 49 }
38 50
39 int AudioParameters::GetPacketSize() const { 51 int AudioParameters::GetBytesPerBuffer() const {
40 return samples_per_packet * channels * bits_per_sample / 8; 52 return frames_per_buffer_ * GetBytesPerFrame();
41 } 53 }
42 54
43 int AudioParameters::GetBytesPerSecond() const { 55 int AudioParameters::GetBytesPerSecond() const {
44 return sample_rate * channels * bits_per_sample / 8; 56 return sample_rate_ * GetBytesPerFrame();
57 }
58
59 int AudioParameters::GetBytesPerFrame() const {
60 return channels_ * bits_per_sample_ / 8;
45 } 61 }
46 62
47 bool AudioParameters::Compare::operator()( 63 bool AudioParameters::Compare::operator()(
48 const AudioParameters& a, 64 const AudioParameters& a,
49 const AudioParameters& b) const { 65 const AudioParameters& b) const {
50 if (a.format < b.format) 66 if (a.format_ < b.format_)
51 return true; 67 return true;
52 if (a.format > b.format) 68 if (a.format_ > b.format_)
53 return false; 69 return false;
54 if (a.channels < b.channels) 70 if (a.channels_ < b.channels_)
55 return true; 71 return true;
56 if (a.channels > b.channels) 72 if (a.channels_ > b.channels_)
57 return false; 73 return false;
58 if (a.sample_rate < b.sample_rate) 74 if (a.sample_rate_ < b.sample_rate_)
59 return true; 75 return true;
60 if (a.sample_rate > b.sample_rate) 76 if (a.sample_rate_ > b.sample_rate_)
61 return false; 77 return false;
62 if (a.bits_per_sample < b.bits_per_sample) 78 if (a.bits_per_sample_ < b.bits_per_sample_)
63 return true; 79 return true;
64 if (a.bits_per_sample > b.bits_per_sample) 80 if (a.bits_per_sample_ > b.bits_per_sample_)
65 return false; 81 return false;
66 return a.samples_per_packet < b.samples_per_packet; 82 return a.frames_per_buffer_ < b.frames_per_buffer_;
67 } 83 }
OLDNEW
« no previous file with comments | « media/audio/audio_parameters.h ('k') | media/audio/audio_parameters_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698