cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / audio / audio_parameters.h
blobbc629a7db0033adb3a475e8a2f5d0e98bd5b438a
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_AUDIO_AUDIO_PARAMETERS_H_
6 #define MEDIA_AUDIO_AUDIO_PARAMETERS_H_
8 #include "base/basictypes.h"
9 #include "media/base/channel_layout.h"
10 #include "media/base/media_export.h"
12 namespace media {
14 struct MEDIA_EXPORT AudioInputBufferParameters {
15 double volume;
16 uint32 size;
17 bool key_pressed;
20 // Use a struct-in-struct approach to ensure that we can calculate the required
21 // size as sizeof(AudioInputBufferParameters) + #(bytes in audio buffer) without
22 // using packing.
23 struct MEDIA_EXPORT AudioInputBuffer {
24 AudioInputBufferParameters params;
25 int8 audio[1];
28 class MEDIA_EXPORT AudioParameters {
29 public:
30 // TODO(miu): Rename this enum to something that correctly reflects its
31 // semantics, such as "TransportScheme."
32 enum Format {
33 AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples.
34 AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested.
35 AUDIO_FAKE, // Creates a fake AudioOutputStream object.
36 AUDIO_LAST_FORMAT // Only used for validation of format.
39 enum {
40 // Telephone quality sample rate, mostly for speech-only audio.
41 kTelephoneSampleRate = 8000,
42 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7.
43 kAudioCDSampleRate = 44100,
46 AudioParameters();
47 AudioParameters(Format format, ChannelLayout channel_layout,
48 int sample_rate, int bits_per_sample,
49 int frames_per_buffer);
50 AudioParameters(Format format, ChannelLayout channel_layout,
51 int input_channels,
52 int sample_rate, int bits_per_sample,
53 int frames_per_buffer);
54 void Reset(Format format, ChannelLayout channel_layout,
55 int channels, int input_channels,
56 int sample_rate, int bits_per_sample,
57 int frames_per_buffer);
59 // Checks that all values are in the expected range. All limits are specified
60 // in media::Limits.
61 bool IsValid() const;
63 // Returns size of audio buffer in bytes.
64 int GetBytesPerBuffer() const;
66 // Returns the number of bytes representing one second of audio.
67 int GetBytesPerSecond() const;
69 // Returns the number of bytes representing a frame of audio.
70 int GetBytesPerFrame() const;
72 Format format() const { return format_; }
73 ChannelLayout channel_layout() const { return channel_layout_; }
74 int sample_rate() const { return sample_rate_; }
75 int bits_per_sample() const { return bits_per_sample_; }
76 int frames_per_buffer() const { return frames_per_buffer_; }
77 int channels() const { return channels_; }
78 int input_channels() const { return input_channels_; }
80 // Set to CHANNEL_LAYOUT_DISCRETE with given number of channels.
81 void SetDiscreteChannels(int channels);
83 // Comparison with other AudioParams.
84 bool operator==(const AudioParameters& other) const {
85 return format_ == other.format() &&
86 sample_rate_ == other.sample_rate() &&
87 channel_layout_ == other.channel_layout() &&
88 channels_ == other.channels() &&
89 input_channels_ == other.input_channels() &&
90 bits_per_sample_ == other.bits_per_sample() &&
91 frames_per_buffer_ == other.frames_per_buffer();
94 private:
95 Format format_; // Format of the stream.
96 ChannelLayout channel_layout_; // Order of surround sound channels.
97 int sample_rate_; // Sampling frequency/rate.
98 int bits_per_sample_; // Number of bits per sample.
99 int frames_per_buffer_; // Number of frames in a buffer.
101 int channels_; // Number of channels. Value set based on
102 // |channel_layout|.
103 int input_channels_; // Optional number of input channels.
104 // Normally 0, but can be set to specify
105 // synchronized I/O.
108 // Comparison is useful when AudioParameters is used with std structures.
109 inline bool operator<(const AudioParameters& a, const AudioParameters& b) {
110 if (a.format() != b.format())
111 return a.format() < b.format();
112 if (a.channels() != b.channels())
113 return a.channels() < b.channels();
114 if (a.input_channels() != b.input_channels())
115 return a.input_channels() < b.input_channels();
116 if (a.sample_rate() != b.sample_rate())
117 return a.sample_rate() < b.sample_rate();
118 if (a.bits_per_sample() != b.bits_per_sample())
119 return a.bits_per_sample() < b.bits_per_sample();
120 return a.frames_per_buffer() < b.frames_per_buffer();
123 } // namespace media
125 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_