Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: chromecast/public/cast_audio_stream.h

Issue 1105803002: Exposes a shlib interface for media/audio path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "chromecast_export.h"
10
11 namespace chromecast {
12
13 // A simple struct descibing an audio stream, modeled after
14 // media::AudioParmameters.
15 // TODO(slan): Add to these as needed.
16 struct CHROMECAST_EXPORT 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
23 // TODO(slan): This class borrows heavily (er-hem... very heavily) from
24 // media::AudioOutputStream. This will be reduced/inflated as needed as
25 // dependencies on media/ are broken within externally-facing chromecast
26 // interfaces.
27 class CHROMECAST_EXPORT AudioOutputStream {
28 public:
29 // Audio sources must implement AudioSourceCallback. This interface will be
30 // called in a random thread which very likely is a high priority thread. Do
31 // not rely on using this thread TLS or make calls that alter the thread
32 // itself such as creating Windows or initializing COM.
33 class AudioSourceCallback {
34 public:
35 virtual ~AudioSourceCallback() {}
36
37 // The AudioOutputStream calls this to request more data from the source.
38 // This fills |dest| with |frames| frames of interleaved data. |len| is
39 // the size of |dest| in bytes, and must satisfy the following condition:
40 //
41 // |len| >= |frames| * (num channels) * (bits per sample) / 8
42 //
43 // where bits per sample and channels are properties of the stream.
44 // |total_bytes_delay| contains current number of bytes of delay buffered
45 // by the AudioOutputStream. Returns the number of frames successfully
46 // filled.
47 // TODO(slan): Replace these params with an AudioBus-like class.
48 virtual int OnMoreData(void* dest,
49 uint32_t len,
50 int32_t frames,
51 uint32_t total_bytes_delay) = 0;
52
53 // There was an error while playing a buffer. Audio source cannot be
54 // destroyed yet. No direct action needed by the AudioStream, but it is
55 // a good place to stop accumulating sound data since is is likely that
56 // playback will not continue.
57 virtual void OnError(AudioOutputStream* stream) = 0;
58
59 // Called when the stream has been Close()d.
60 virtual void OnClose() = 0;
61 };
62
63 virtual ~AudioOutputStream() {}
64
65 // Open the stream. false is returned if the stream cannot be opened. Open()
66 // must always be followed by a call to Close() even if Open() fails.
67 virtual bool Open() = 0;
68
69 // Starts playing audio and generating AudioSourceCallback::OnMoreData().
70 // Since implementor of AudioOutputStream may have internal buffers, right
71 // after calling this method initial buffers are fetched.
72 //
73 // The output stream does not take ownership of this callback.
74 virtual void Start(AudioSourceCallback* callback) = 0;
75
76 // Stops playing audio. Effect might not be instantaneous as the hardware
77 // might have locked audio data that is processing.
78 virtual void Stop() = 0;
79
80 // Sets the relative volume, with range [0.0, 1.0] inclusive.
81 virtual void SetVolume(double volume) = 0;
82
83 // Gets the relative volume, with range [0.0, 1.0] inclusive.
84 virtual void GetVolume(double* volume) = 0;
85
86 // Close the stream. This also generates AudioSourceCallback::OnClose().
87 // After calling this method, the object should not be used anymore.
88 virtual void Close() = 0;
89 };
90
91 } // namespace chromecast
92
93 #endif // CHROMECAST_PUBLIC_CAST_AUDIO_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698