srpcgen: Use 'const char*' for string parameters
[chromium-blink-merge.git] / media / audio / audio_parameters.cc
blob4395481764a626a3f6837742e0dac40be9aad487
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/audio/audio_parameters.h"
7 #include "media/base/limits.h"
9 AudioParameters::AudioParameters()
10 : format(AUDIO_PCM_LINEAR),
11 channel_layout(CHANNEL_LAYOUT_NONE),
12 sample_rate(0),
13 bits_per_sample(0),
14 samples_per_packet(0),
15 channels(0) {
18 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout,
19 int sample_rate, int bits_per_sample,
20 int samples_per_packet)
21 : format(format),
22 channel_layout(channel_layout),
23 sample_rate(sample_rate),
24 bits_per_sample(bits_per_sample),
25 samples_per_packet(samples_per_packet),
26 channels(ChannelLayoutToChannelCount(channel_layout)) {
29 bool AudioParameters::IsValid() const {
30 return (format >= 0) && (format < AUDIO_LAST_FORMAT) &&
31 (channels > 0) && (channels <= media::limits::kMaxChannels) &&
32 (sample_rate > 0) && (sample_rate <= media::limits::kMaxSampleRate) &&
33 (bits_per_sample > 0) &&
34 (bits_per_sample <= media::limits::kMaxBitsPerSample) &&
35 (samples_per_packet > 0) &&
36 (samples_per_packet <= media::limits::kMaxSamplesPerPacket);
39 int AudioParameters::GetPacketSize() const {
40 return samples_per_packet * channels * bits_per_sample / 8;
43 int AudioParameters::GetBytesPerSecond() const {
44 return sample_rate * channels * bits_per_sample / 8;
47 bool AudioParameters::Compare::operator()(
48 const AudioParameters& a,
49 const AudioParameters& b) const {
50 if (a.format < b.format)
51 return true;
52 if (a.format > b.format)
53 return false;
54 if (a.channels < b.channels)
55 return true;
56 if (a.channels > b.channels)
57 return false;
58 if (a.sample_rate < b.sample_rate)
59 return true;
60 if (a.sample_rate > b.sample_rate)
61 return false;
62 if (a.bits_per_sample < b.bits_per_sample)
63 return true;
64 if (a.bits_per_sample > b.bits_per_sample)
65 return false;
66 return a.samples_per_packet < b.samples_per_packet;