|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
|
3 /* |
|
4 * Copyright (c) 2014 The Linux Foundation. All rights reserved. |
|
5 * Copyright (C) 2007 The Android Open Source Project |
|
6 * |
|
7 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
8 * you may not use this file except in compliance with the License. |
|
9 * You may obtain a copy of the License at |
|
10 * |
|
11 * http://www.apache.org/licenses/LICENSE-2.0 |
|
12 * |
|
13 * Unless required by applicable law or agreed to in writing, software |
|
14 * distributed under the License is distributed on an "AS IS" BASIS, |
|
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
16 * See the License for the specific language governing permissions and |
|
17 * limitations under the License. |
|
18 */ |
|
19 |
|
20 #ifndef AUDIO_SINK_H_ |
|
21 #define AUDIO_SINK_H_ |
|
22 |
|
23 #include <utils/Errors.h> |
|
24 #include <utils/String8.h> |
|
25 #include <system/audio.h> |
|
26 |
|
27 #define DEFAULT_AUDIOSINK_BUFFERCOUNT 4 |
|
28 #define DEFAULT_AUDIOSINK_BUFFERSIZE 1200 |
|
29 #define DEFAULT_AUDIOSINK_SAMPLERATE 44100 |
|
30 |
|
31 // when the channel mask isn't known, use the channel count to derive a mask in |
|
32 // AudioSink::open() |
|
33 #define CHANNEL_MASK_USE_CHANNEL_ORDER 0 |
|
34 |
|
35 namespace mozilla { |
|
36 |
|
37 /** |
|
38 * AudioSink: abstraction layer for audio output |
|
39 * Stripped version of Android KK MediaPlayerBase::AudioSink class |
|
40 */ |
|
41 |
|
42 class AudioSink : public android::RefBase |
|
43 { |
|
44 typedef android::String8 String8; |
|
45 typedef android::status_t status_t; |
|
46 |
|
47 public: |
|
48 enum cb_event_t { |
|
49 CB_EVENT_FILL_BUFFER, // Request to write more data to buffer. |
|
50 CB_EVENT_STREAM_END, // Sent after all the buffers queued in AF and HW |
|
51 // are played back (after stop is called) |
|
52 CB_EVENT_TEAR_DOWN // The AudioTrack was invalidated due to usecase |
|
53 // change. Need to re-evaluate offloading options |
|
54 }; |
|
55 |
|
56 // Callback returns the number of bytes actually written to the buffer. |
|
57 typedef size_t (*AudioCallback)(AudioSink* aAudioSink, |
|
58 void* aBuffer, |
|
59 size_t aSize, |
|
60 void* aCookie, |
|
61 cb_event_t aEvent); |
|
62 virtual ~AudioSink() {} |
|
63 virtual ssize_t FrameSize() const = 0; |
|
64 virtual status_t GetPosition(uint32_t* aPosition) const = 0; |
|
65 virtual status_t SetVolume(float aVolume) const = 0; |
|
66 virtual status_t SetParameters(const String8& aKeyValuePairs) |
|
67 { |
|
68 return android::NO_ERROR; |
|
69 } |
|
70 |
|
71 virtual status_t Open(uint32_t aSampleRate, |
|
72 int aChannelCount, |
|
73 audio_channel_mask_t aChannelMask, |
|
74 audio_format_t aFormat=AUDIO_FORMAT_PCM_16_BIT, |
|
75 AudioCallback aCb = nullptr, |
|
76 void* aCookie = nullptr, |
|
77 audio_output_flags_t aFlags = AUDIO_OUTPUT_FLAG_NONE, |
|
78 const audio_offload_info_t* aOffloadInfo = nullptr) = 0; |
|
79 |
|
80 virtual status_t Start() = 0; |
|
81 virtual void Stop() = 0; |
|
82 virtual void Flush() = 0; |
|
83 virtual void Pause() = 0; |
|
84 virtual void Close() = 0; |
|
85 }; |
|
86 |
|
87 } // namespace mozilla |
|
88 |
|
89 #endif // AUDIO_SINK_H_ |