OLD | NEW |
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 #ifndef MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
6 #define MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 6 #define MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "media/base/channel_layout.h" | 9 #include "media/base/channel_layout.h" |
10 #include "media/base/media_export.h" | 10 #include "media/base/media_export.h" |
11 | 11 |
12 // TODO(vrk): This should probably be changed to an immutable object instead of | 12 class MEDIA_EXPORT AudioParameters { |
13 // a struct. See crbug.com/115902. | 13 public: |
14 struct MEDIA_EXPORT AudioParameters { | |
15 // Compare is useful when AudioParameters is used as a key in std::map. | 14 // Compare is useful when AudioParameters is used as a key in std::map. |
16 class MEDIA_EXPORT Compare { | 15 class MEDIA_EXPORT Compare { |
17 public: | 16 public: |
18 bool operator()(const AudioParameters& a, const AudioParameters& b) const; | 17 bool operator()(const AudioParameters& a, const AudioParameters& b) const; |
19 }; | 18 }; |
20 | 19 |
21 enum Format { | 20 enum Format { |
22 AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples. | 21 AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples. |
23 AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested. | 22 AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested. |
24 AUDIO_MOCK, // Creates a dummy AudioOutputStream object. | 23 AUDIO_MOCK, // Creates a dummy AudioOutputStream object. |
25 AUDIO_LAST_FORMAT // Only used for validation of format.y | 24 AUDIO_LAST_FORMAT // Only used for validation of format.y |
26 }; | 25 }; |
27 | 26 |
28 // Telephone quality sample rate, mostly for speech-only audio. | 27 // Telephone quality sample rate, mostly for speech-only audio. |
29 static const uint32 kTelephoneSampleRate = 8000; | 28 static const uint32 kTelephoneSampleRate = 8000; |
30 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. | 29 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. |
31 static const uint32 kAudioCDSampleRate = 44100; | 30 static const uint32 kAudioCDSampleRate = 44100; |
32 // Digital Audio Tape sample rate. | 31 // Digital Audio Tape sample rate. |
33 static const uint32 kAudioDATSampleRate = 48000; | 32 static const uint32 kAudioDATSampleRate = 48000; |
34 | 33 |
35 AudioParameters(); | 34 AudioParameters(); |
36 AudioParameters(Format format, ChannelLayout channel_layout, int sample_rate, | 35 AudioParameters(Format format, ChannelLayout channel_layout, |
37 int bits_per_sample, int samples_per_packet); | 36 int sample_rate, int bits_per_sample, |
| 37 int frames_per_buffer); |
| 38 void Reset(Format format, ChannelLayout channel_layout, |
| 39 int sample_rate, int bits_per_sample, |
| 40 int frames_per_buffer); |
38 | 41 |
39 // Checks that all values are in the expected range. All limits are specified | 42 // Checks that all values are in the expected range. All limits are specified |
40 // in media::Limits. | 43 // in media::Limits. |
41 bool IsValid() const; | 44 bool IsValid() const; |
42 | 45 |
43 // Returns size of audio packets in bytes. | 46 // Returns size of audio buffer in bytes. |
44 int GetPacketSize() const; | 47 int GetBytesPerBuffer() const; |
45 | 48 |
46 // Returns the number of bytes representing one second of audio. | 49 // Returns the number of bytes representing one second of audio. |
47 int GetBytesPerSecond() const; | 50 int GetBytesPerSecond() const; |
48 | 51 |
49 Format format; // Format of the stream. | 52 // Returns the number of bytes representing a frame of audio. |
50 ChannelLayout channel_layout; // Order of surround sound channels. | 53 int GetBytesPerFrame() const; |
51 int sample_rate; // Sampling frequency/rate. | |
52 int bits_per_sample; // Number of bits per sample. | |
53 int samples_per_packet; // Size of a packet in frames. | |
54 | 54 |
55 int channels; // Number of channels. Value set based on | 55 Format format() const { return format_; } |
56 // |channel_layout|. | 56 ChannelLayout channel_layout() const { return channel_layout_; } |
| 57 int sample_rate() const { return sample_rate_; } |
| 58 int bits_per_sample() const { return bits_per_sample_; } |
| 59 int frames_per_buffer() const { return frames_per_buffer_; } |
| 60 int channels() const { return channels_; } |
| 61 |
| 62 private: |
| 63 Format format_; // Format of the stream. |
| 64 ChannelLayout channel_layout_; // Order of surround sound channels. |
| 65 int sample_rate_; // Sampling frequency/rate. |
| 66 int bits_per_sample_; // Number of bits per sample. |
| 67 int frames_per_buffer_; // Number of frames in a buffer. |
| 68 |
| 69 int channels_; // Number of channels. Value set based on |
| 70 // |channel_layout|. |
57 }; | 71 }; |
58 | 72 |
59 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 73 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
OLD | NEW |