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