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_STREAM_H_ | |
6 #define CHROMECAST_PUBLIC_CAST_AUDIO_STREAM_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "chromecast_export.h" | |
11 | |
12 namespace chromecast { | |
13 | |
14 // A simple struct descibing an audio stream, modeled after | |
15 // media::AudioParmameters. | |
halliwell
2015/04/24 15:04:48
typo: Parameters
slan
2015/04/24 16:19:39
Done.
| |
16 // TODO(slan): Add to these as needed. | |
17 struct CHROMECAST_EXPORT AudioParameters { | |
18 int sample_rate; // Sampling frequency/rate. | |
19 int bits_per_sample; // Number of bits per sample. | |
20 int frames_per_buffer; // Number of frames in a buffer. | |
21 int channels; // Number of channels. | |
22 }; | |
23 | |
24 // TODO(slan): This class borrows heavily (er-hem... very heavily) from | |
25 // media::AudioOutputStream. This will be reduced/inflated as needed as | |
26 // dependencies on media/ are broken within externally-facing chromecast | |
27 // interfaces. | |
28 class CHROMECAST_EXPORT CastAudioOutputStream { | |
29 public: | |
30 // Audio sources must implement AudioSourceCallback. This interface will be | |
31 // called in a random thread which very likely is a high priority thread. Do | |
32 // not rely on using this thread TLS or make calls that alter the thread | |
33 // itself such as creating Windows or initializing COM. | |
34 class AudioSourceCallback { | |
35 public: | |
36 virtual ~AudioSourceCallback() {} | |
37 | |
38 // The CastAudioOutputStream calls this to request more data from the | |
39 // source. | |
40 // This fills |dest| with |frames| frames of interleaved data. |len| is | |
41 // the size of |dest| in bytes, and must satisfy the following condition: | |
42 // | |
43 // |len| >= |frames| * (num channels) * (bits per sample) / 8 | |
halliwell
2015/04/24 15:04:48
If we ever had e.g. 20 bit audio, then bits/8 need
slan
2015/04/24 16:19:39
Good catch. I was making the blind assumption that
halliwell
2015/04/25 01:34:10
Someone else probably knows better than me, but ba
| |
44 // | |
45 // where bits per sample and channels are properties of the stream. | |
46 // |total_bytes_delay| contains current number of bytes of delay buffered | |
47 // by the CastAudioOutputStream. Returns the number of frames successfully | |
48 // filled. | |
49 // TODO(slan): Replace these params with an AudioBus-like class. | |
50 virtual int OnMoreData(void* dest, | |
51 uint32_t len, | |
52 int32_t frames, | |
53 uint32_t total_bytes_delay) = 0; | |
54 | |
55 // There was an error while playing a buffer. Audio source cannot be | |
56 // destroyed yet. No direct action needed by the AudioStream, but it is | |
57 // a good place to stop accumulating sound data since is is likely that | |
58 // playback will not continue. | |
59 virtual void OnError(CastAudioOutputStream* stream) = 0; | |
60 | |
61 // Called when the stream has been Close()d. | |
62 virtual void OnClose() = 0; | |
63 }; | |
64 | |
65 virtual ~CastAudioOutputStream() {} | |
66 | |
67 // Open the stream. false is returned if the stream cannot be opened. Open() | |
68 // must always be followed by a call to Close() even if Open() fails. | |
69 virtual bool Open() = 0; | |
70 | |
71 // Starts playing audio and generating AudioSourceCallback::OnMoreData(). | |
72 // Since implementor of CastAudioOutputStream may have internal buffers, right | |
73 // after calling this method initial buffers are fetched. | |
74 // | |
75 // The output stream does not take ownership of this callback. | |
76 virtual void Start(AudioSourceCallback* callback) = 0; | |
77 | |
78 // Stops playing audio. Effect might not be instantaneous as the hardware | |
79 // might have locked audio data that is processing. | |
80 virtual void Stop() = 0; | |
81 | |
82 // Sets the relative volume, with range [0.0, 1.0] inclusive. | |
83 virtual void SetVolume(double volume) = 0; | |
84 | |
85 // Gets the relative volume, with range [0.0, 1.0] inclusive. | |
86 virtual void GetVolume(double* volume) = 0; | |
halliwell
2015/04/24 15:04:48
Any reason why we don't just return double here?
slan
2015/04/24 16:19:39
No reason. Changed.
| |
87 | |
88 // Close the stream. This also generates AudioSourceCallback::OnClose(). | |
89 // After calling this method, the object should not be used anymore. | |
90 virtual void Close() = 0; | |
91 }; | |
92 | |
93 } // namespace chromecast | |
94 | |
95 #endif // CHROMECAST_PUBLIC_CAST_AUDIO_STREAM_H_ | |
OLD | NEW |