Home | History | Annotate | Download | only in android
      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  */
     22 enum 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     // audio player, decoding from an Android buffer queue with ADTS data,
     40     //   to a buffer queue data sink in PCM format
     41     AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE = 7,
     42     NUM_AUDIOPLAYER_MAP_TYPES
     43 };
     44 
     45 
     46 /**
     47  * Used to define the states of the OpenSL ES / OpenMAX AL object initialization and preparation
     48  * with regards to the Android-side of the data, in particular as affected by the play state.
     49  */
     50 enum AndroidObjectState {
     51     ANDROID_UNINITIALIZED = -1, // never called SetPlayState(PAUSED or PLAYING)
     52     ANDROID_PREPARING,          // currently preparing due to first SetPlayState(PAUSED or PLAYING)
     53     ANDROID_READY,              // preparation has completed, and will not be attempted again
     54     // NUM_ANDROID_STATES       // unused
     55 };
     56 
     57 /**
     58  * Must be one of the supported stream types that can be set through SLAndroidConfigurationItf
     59  */
     60 #define ANDROID_DEFAULT_OUTPUT_STREAM_TYPE AUDIO_STREAM_MUSIC
     61 
     62 #define PLAYER_FAILURE ((int32_t) android::UNKNOWN_ERROR)
     63 #define PLAYER_SUCCESS ((int32_t) android::NO_ERROR)
     64 
     65 #define PLAYER_FD_FIND_FILE_SIZE ((int64_t)0xFFFFFFFFFFFFFFFFll)
     66 
     67 #define MPEG2_TS_PACKET_SIZE 188
     68 #define MPEG2_TS_PACKET_SYNC 0x47
     69 
     70 struct AudioPlayback_Parameters {
     71     audio_stream_type_t streamType;
     72     audio_session_t sessionId;
     73 };
     74 
     75 /**
     76  * Structure to maintain the set of audio levels about a player
     77  */
     78 struct AndroidAudioLevels {
     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 };
     96 
     97 
     98 /**
     99  * Event notification callback from Android to SL ES framework
    100  */
    101 typedef 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  */
    106 typedef size_t (*data_push_cbf_t)(const uint8_t *data, size_t size, CAudioPlayer* ap);
    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 #define PLAYEREVENT_CHANNEL_COUNT           "ccnt"  // channel count is now known
    119 #define PLAYEREVENT_PLAY                    "play"  // SL_PLAYEVENT_*
    120 #define PLAYEREVENT_ERRORAFTERPREPARE       "easp"  // error after successful prepare
    121 
    122 
    123 /**
    124  * Time value when time is unknown. Used for instance for duration or playback position
    125  */
    126 #define ANDROID_UNKNOWN_TIME (-1)
    127 
    128 /**
    129  * Event mask for MPEG-2 TS events associated with TS data
    130  */
    131 #define ANDROID_MP2TSEVENT_NONE          ((SLuint32) 0x0)
    132 // buffer is at End Of Stream
    133 #define ANDROID_MP2TSEVENT_EOS           ((SLuint32) 0x1)
    134 // buffer marks a discontinuity with previous TS data, resume display as soon as possible
    135 #define ANDROID_MP2TSEVENT_DISCONTINUITY ((SLuint32) 0x1 << 1)
    136 // buffer marks a discontinuity with previous TS data, resume display upon reaching the
    137 // associated presentation time stamp
    138 #define ANDROID_MP2TSEVENT_DISCON_NEWPTS ((SLuint32) 0x1 << 2)
    139 // buffer marks a format change with previous TS data, resume display as soon as possible
    140 #define ANDROID_MP2TSEVENT_FORMAT_CHANGE_FULL  ((SLuint32) 0x1 << 3)
    141 #define ANDROID_MP2TSEVENT_FORMAT_CHANGE_VIDEO ((SLuint32) 0x1 << 4)
    142 
    143 /**
    144  * Event mask for AAC ADTS events associated with ADTS data
    145  */
    146 #define ANDROID_ADTSEVENT_NONE           ANDROID_MP2TSEVENT_NONE
    147 // buffer is at End Of Stream
    148 #define ANDROID_ADTSEVENT_EOS            ANDROID_MP2TSEVENT_EOS
    149 
    150 /**
    151  * Types of buffers stored in Android Buffer Queues, see IAndroidBufferQueue.mBufferType
    152  */
    153 enum AndroidBufferType_type {
    154     kAndroidBufferTypeInvalid = ((SLuint16) 0x0),
    155     kAndroidBufferTypeMpeg2Ts = ((SLuint16) 0x1),
    156     kAndroidBufferTypeAacadts = ((SLuint16) 0x2),
    157 };
    158 
    159 /**
    160  * MIME types required for data in Android Buffer Queues
    161  */
    162 // The preferred MIME types for new applications are in ../../include/*/OpenMAXAL_Android.h
    163 // The legacy MIME type used elsewhere in the Android framework for AAC ADTS is below:
    164 #define ANDROID_MIME_AACADTS_ANDROID_FRAMEWORK "audio/aac-adts"
    165 
    166 /**
    167  * Notification thresholds relative to content duration in the cache
    168  */
    169 #define DURATION_CACHED_HIGH_MS  30000 // 30s
    170 #define DURATION_CACHED_MED_MS   10000 // 10s
    171 #define DURATION_CACHED_LOW_MS    2000 //  2s
    172 
    173 
    174 namespace android {
    175 
    176 /**
    177  * Prefetch cache status
    178  */
    179 enum CacheStatus_t {
    180         kStatusUnknown = -1,
    181         kStatusEmpty   = 0,
    182         kStatusLow,
    183         kStatusIntermediate,
    184         kStatusEnough,
    185         kStatusHigh
    186 };
    187 
    188 enum {
    189     kDataLocatorNone = 0,
    190     kDataLocatorUri  = 1,
    191     kDataLocatorFd   = 2,
    192 };
    193 
    194 struct FdInfo {
    195     int fd;
    196     int64_t offset;
    197     int64_t length;
    198     bool mCloseAfterUse;    // whether to close fd after last reference to fd
    199 };
    200 
    201 // TODO currently used by SfPlayer, to replace by DataLocator2
    202 union DataLocator {
    203     char* uri;
    204     FdInfo fdi;
    205 };
    206 
    207 union DataLocator2 {
    208     const char* uriRef;
    209     FdInfo fdi;
    210 };
    211 
    212 
    213 #define ANDROID_PERFORMANCE_MODE_NONE            ((SLuint32) 0x1 << 0)
    214 #define ANDROID_PERFORMANCE_MODE_LATENCY         ((SLuint32) 0x1 << 1)
    215 #define ANDROID_PERFORMANCE_MODE_LATENCY_EFFECTS ((SLuint32) 0x1 << 2)
    216 #define ANDROID_PERFORMANCE_MODE_POWER_SAVING    ((SLuint32) 0x1 << 3)
    217 
    218 #define ANDROID_PERFORMANCE_MODE_DEFAULT ANDROID_PERFORMANCE_MODE_LATENCY
    219 #define ANDROID_PERFORMANCE_MODE_ALL (ANDROID_PERFORMANCE_MODE_LATENCY | \
    220                                       ANDROID_PERFORMANCE_MODE_LATENCY_EFFECTS | \
    221                                       ANDROID_PERFORMANCE_MODE_NONE | \
    222                                       ANDROID_PERFORMANCE_MODE_POWER_SAVING)
    223 
    224 
    225 } // namespace android
    226