OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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. | |
4 | |
5 #ifndef CHROMECAST_PUBLIC_CAST_AUDIO_OUTPUT_STREAM_H_ | |
6 #define CHROMECAST_PUBLIC_CAST_AUDIO_OUTPUT_STREAM_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 namespace chromecast { | |
11 namespace media { | |
12 | |
13 // A simple struct describing an audio stream. | |
14 struct AudioParameters { | |
15 int sample_rate; // Sampling frequency/rate. | |
16 int bits_per_sample; // Number of bits per sample. | |
17 int frames_per_buffer; // Number of frames in a buffer. | |
18 int channels; // Number of channels. | |
19 | |
20 static const int kMaxSampleRate = 192000; | |
21 static const int kMaxBitsPerSample = 32; | |
22 static const int kMaxFramesPerBuffer = kMaxSampleRate; | |
23 static const int kMaxChannels = 32; // The maximum number of channels. | |
24 }; | |
25 | |
26 // This is an interface for a Cast audio output stream. Implementations of this | |
27 // interface are responsible for making calls to an AudioSourceCallback. | |
28 class CastAudioOutputStream { | |
29 public: | |
30 // Audio sources must implement AudioSourceCallback. Calls to this interface | |
31 // must be made on the same thread on which the stream object is created. | |
32 class AudioSourceCallback { | |
33 public: | |
34 virtual ~AudioSourceCallback() {} | |
byungchul
2015/07/29 20:18:49
It should be protected since CastAudioOutputStream
slan
2015/07/30 21:00:42
Done.
| |
35 | |
36 // The CastAudioOutputStream calls this to request more data from the | |
37 // source. This method fills |dest| with |frames| frames of interleaved | |
38 // data, which takes the following struture for N channels: | |
39 // | |
40 // [ch0, ch1, ..., chN, ch0, ch1, ..., chN, ...] | |
41 // |<---- Frame 0 ---->|<---- Frame 1 ---->|...| | |
42 // | |
43 // |len| is the size of |dest| in bytes, and must satisfy the following: | |
44 // | |
45 // |len| >= |frames| * (num channels) * (bytes per sample) | |
46 // | |
47 // where bytes per sample and channels are properties of the stream. These | |
48 // can be detemined through GetParameters(). |total_bytes_delay| contains | |
49 // the current number of bytes of delay buffered by the | |
50 // CastAudioOutputStream. Returns the number of frames successfully filled. | |
51 virtual int GetMoreData(void* dest, | |
52 uint32_t len, | |
53 int32_t frames, | |
54 uint32_t total_bytes_delay) = 0; | |
55 | |
56 // There was an error while playing a buffer. Audio source cannot be | |
57 // destroyed yet. No direct action needed by the AudioStream, but it is | |
58 // a good place to stop accumulating sound data since is is likely that | |
59 // playback will not continue. | |
60 virtual void OnError(CastAudioOutputStream* stream) = 0; | |
61 }; | |
62 | |
63 virtual ~CastAudioOutputStream() {} | |
64 | |
65 // Returns the parameters describing the stream. | |
66 virtual const AudioParameters GetParameters() const = 0; | |
byungchul
2015/07/29 20:18:49
const function would be too restricted as a shlib
slan
2015/07/30 21:00:42
Done.
| |
67 | |
68 // Open the stream. A call to this method must always be followed by a call to | |
halliwell
2015/07/29 22:10:14
This comment is written from the POV of us (client
slan
2015/07/30 21:00:42
Done.
| |
69 // Close() even if Open() fails. This method may block the caller's thread. | |
70 virtual bool Open() = 0; | |
71 | |
72 // Starts playing audio and generating AudioSourceCallback::GetMoreData(). | |
73 // Since implementor of CastAudioOutputStream may have internal buffers, right | |
74 // after calling this method initial buffers are fetched. | |
75 // | |
76 // The output stream does not take ownership of this callback. | |
77 virtual void Start(AudioSourceCallback* callback) = 0; | |
78 | |
79 // Stops playing audio. Effect might not be instantaneous as the hardware | |
80 // might have locked audio data that is processing. | |
81 virtual void Stop() = 0; | |
82 | |
83 // Sets the relative volume, with range [0.0, 1.0] inclusive. | |
84 virtual void SetVolume(double volume) = 0; | |
85 | |
86 // Gets the relative volume, with range [0.0, 1.0] inclusive. This method may | |
87 // be . | |
88 virtual double GetVolume() = 0; | |
89 | |
90 // Close the stream. This also generates AudioSourceCallback::OnClose(). | |
91 // After calling this method, the object should not be used anymore. Like all | |
92 // other methods, this must be made on the same thread on which the stream was | |
93 // created. | |
94 virtual void Close() = 0; | |
95 }; | |
96 | |
97 } // namespace media | |
98 } // namespace chromecast | |
99 | |
100 #endif // CHROMECAST_PUBLIC_CAST_AUDIO_OUTPUT_STREAM_H_ | |
OLD | NEW |