Chromium Code Reviews| 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_ | |
|
gunsch
2015/04/27 16:09:11
filename should match class name
slan
2015/04/28 00:11:39
Done.
| |
| 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::AudioParameters. | |
|
byungchul
2015/04/27 17:38:06
This file is for oem partners, and supposed to be
slan
2015/04/28 00:11:39
Done.
| |
| 16 // TODO(slan): Add to these as needed. | |
| 17 struct CHROMECAST_EXPORT AudioParameters { | |
|
byungchul
2015/04/27 17:38:06
CHROMECAST_EXPORT not necessary.
slan
2015/04/28 00:11:39
Done.
| |
| 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 { | |
|
byungchul
2015/04/27 17:38:06
CHROMECAST_EXPORT not necessary.
slan
2015/04/28 00:11:39
Done.
| |
| 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 { | |
|
byungchul
2015/04/27 17:38:06
What is thread model here? Do we allow callback fu
slan
2015/04/28 00:11:39
Done.
| |
| 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 | |
| 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, | |
|
byungchul
2015/04/27 17:38:06
is void* enough to explain how dest will be filled
slan
2015/04/28 00:11:39
Documentation added explaining interleaved format.
| |
| 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; | |
|
byungchul
2015/04/27 17:38:06
Do we allow this function block the thread?
slan
2015/04/28 00:11:39
I think this call should be able to block the audi
| |
| 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. | |
|
byungchul
2015/04/27 17:38:06
Do we allow this function blocking the thread?
slan
2015/04/28 00:11:39
This one should block as well. Documentation added
| |
| 86 virtual double GetVolume() = 0; | |
| 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 |