android_defs.h revision 7f5cc1afe49395fefaad9b2bbd728a45d1bfda6a
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18/**
19 * Used to define the mapping from an OpenSL ES or OpenMAX AL object to an Android
20 * media framework object
21 */
22enum AndroidObjectType {
23    INVALID_TYPE                                =-1,
24    // audio player, playing from a URI or FD data source
25    AUDIOPLAYER_FROM_URIFD                      = 0,
26    // audio player, playing PCM buffers in a buffer queue data source
27    AUDIOPLAYER_FROM_PCM_BUFFERQUEUE            = 1,
28    // audio player, playing transport stream packets in an Android buffer queue data source
29    AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE      = 2,
30    // audio player, decoding from a URI or FD data source to a buffer queue data sink in PCM format
31    AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE   = 3,
32    // audio video player, playing transport stream packets in an Android buffer queue data source
33    AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE = 4,
34    // audio video player, playing from a URI or FD data source
35    AUDIOVIDEOPLAYER_FROM_URIFD                 = 5,
36    // audio recorder, recording from an input device data source, streamed into a
37    //   PCM buffer queue data sink
38    AUDIORECORDER_FROM_MIC_TO_PCM_BUFFERQUEUE   = 6,
39    NUM_AUDIOPLAYER_MAP_TYPES
40};
41
42
43/**
44 * Used to define the states of the OpenSL ES / OpenMAX AL object initialization and preparation
45 * with regards to the Android-side of the data
46 */
47enum AndroidObjectState {
48    ANDROID_UNINITIALIZED = -1,
49    ANDROID_PREPARING,
50    ANDROID_READY,
51    NUM_ANDROID_STATES
52};
53
54
55#define ANDROID_DEFAULT_OUTPUT_STREAM_TYPE AUDIO_STREAM_MUSIC
56
57#define PLAYER_SUCCESS 1
58
59#define PLAYER_FD_FIND_FILE_SIZE ((int64_t)0xFFFFFFFFFFFFFFFFll)
60
61#define MPEG2_TS_BLOCK_SIZE 188
62
63// FIXME separate the cases where we don't need an AudioTrack callback
64typedef struct AudioPlayback_Parameters_struct {
65    int streamType;
66    int sessionId;
67    android::AudioTrack::callback_t trackcb;
68    void* trackcbUser;
69} AudioPlayback_Parameters;
70
71/**
72 * Structure to maintain the set of audio levels about a player
73 */
74typedef struct AndroidAudioLevels_t {
75    /**
76     * Is this player muted
77     */
78    bool mMute;
79    /**
80     * Send level to aux effect, there's a single aux bus, so there's a single level
81     */
82    // FIXME not used yet, will be used when supporting effects in OpenMAX AL
83    //SLmillibel mAuxSendLevel;
84    /**
85     * Attenuation factor derived from direct level
86     */
87    // FIXME not used yet, will be used when supporting effects in OpenMAX AL
88    //float mAmplFromDirectLevel;
89    /**
90     * Android Left/Right volume
91     * The final volume of an Android AudioTrack or MediaPlayer is a stereo amplification
92     * (or attenuation) represented as a float from 0.0f to 1.0f
93     */
94    float mFinalVolume[STEREO_CHANNELS];
95} AndroidAudioLevels;
96
97
98/**
99 * Event notification callback from Android to SL ES framework
100 */
101typedef void (*notif_cbf_t)(int event, int data1, int data2, void* notifUser);
102
103/**
104 * Audio data push callback from Android objects to SL ES framework
105 */
106typedef size_t (*data_push_cbf_t)(const uint8_t *data, size_t size, void* user);
107
108
109/**
110 * Events sent to mNotifyClient during prepare, prefetch, and playback
111 * used in APlayer::notify() and AMessage::findxxx()
112 */
113#define PLAYEREVENT_PREPARED                "prep"
114#define PLAYEREVENT_PREFETCHSTATUSCHANGE    "prsc"
115#define PLAYEREVENT_PREFETCHFILLLEVELUPDATE "pflu"
116#define PLAYEREVENT_ENDOFSTREAM             "eos"
117#define PLAYEREVENT_VIDEO_SIZE_UPDATE       "vsiz"
118
119
120/**
121 * Time value when time is unknown. Used for instance for duration or playback position
122 */
123#define ANDROID_UNKNOWN_TIME -1
124
125/**
126 * Event mask for MPEG-2 TS events associated with TS data
127 */
128#define ANDROID_MP2TSEVENT_NONE          ((SLuint32) 0x0)
129// buffer is at End Of Stream
130#define ANDROID_MP2TSEVENT_EOS           ((SLuint32) 0x1)
131// buffer marks a discontinuity with previous TS data, resume display as soon as possible
132#define ANDROID_MP2TSEVENT_DISCONTINUITY ((SLuint32) 0x1 << 1)
133// buffer marks a discontinuity with previous TS data, resume display upon reaching the
134// associated presentation time stamp
135#define ANDROID_MP2TSEVENT_DISCON_NEWPTS ((SLuint32) 0x1 << 2)
136
137
138/**
139 * Constants to define unknown property values
140 */
141#define ANDROID_UNKNOWN_NUMCHANNELS 0
142#define ANDROID_UNKNOWN_SAMPLERATE  0
143#define ANDROID_UNKNOWN_CHANNELMASK 0
144
145/**
146 * Additional metadata keys
147 *   the ANDROID_KEY_PCMFORMAT_* keys follow the fields of the SLDataFormat_PCM struct, and as such
148 *     all corresponding values match SLuint32 size, and field definitions.
149 * FIXME these values are candidates to be included in OpenSLES_Android.h as official metadata
150 *     keys supported on the platform.
151 */
152#define ANDROID_KEY_PCMFORMAT_NUMCHANNELS   "AndroidPcmFormatNumChannels"
153#define ANDROID_KEY_PCMFORMAT_SAMPLESPERSEC "AndroidPcmFormatSamplesPerSec"
154#define ANDROID_KEY_PCMFORMAT_BITSPERSAMPLE "AndroidPcmFormatBitsPerSample"
155#define ANDROID_KEY_PCMFORMAT_CONTAINERSIZE "AndroidPcmFormatContainerSize"
156#define ANDROID_KEY_PCMFORMAT_CHANNELMASK   "AndroidPcmFormatChannelMask"
157#define ANDROID_KEY_PCMFORMAT_ENDIANNESS    "AndroidPcmFormatEndianness"
158
159/**
160 * Types of buffers stored in Android Buffer Queues, see IAndroidBufferQueue.mBufferType
161 */
162enum AndroidBufferType_type {
163    kAndroidBufferTypeInvalid = ((SLuint16) 0x0),
164    kAndroidBufferTypeMpeg2Ts = ((SLuint16) 0x1),
165};
166
167/**
168 * Notification thresholds relative to content duration in the cache
169 */
170#define DURATION_CACHED_HIGH_MS  30000 // 30s
171#define DURATION_CACHED_MED_MS   10000 // 10s
172#define DURATION_CACHED_LOW_MS    2000 //  2s
173
174
175namespace android {
176
177/**
178 * Prefetch cache status
179 */
180enum CacheStatus_t {
181        kStatusUnknown = -1,
182        kStatusEmpty   = 0,
183        kStatusLow,
184        kStatusIntermediate,
185        kStatusEnough,
186        kStatusHigh
187};
188
189enum {
190    kDataLocatorNone = 'none',
191    kDataLocatorUri  = 'uri',
192    kDataLocatorFd   = 'fd',
193};
194
195struct FdInfo {
196    int fd;
197    int64_t offset;
198    int64_t length;
199};
200
201// TODO currently used by SfPlayer, to replace by DataLocator2
202union DataLocator {
203    char* uri;
204    FdInfo fdi;
205};
206
207union DataLocator2 {
208    const char* uriRef;
209    FdInfo fdi;
210};
211
212} // namespace android
213