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 #define ANDROID_DEFAULT_AUDIOTRACK_BUFFER_SIZE 4096
18 
19 /**************************************************************************************************
20  * AudioPlayer lifecycle
21  ****************************/
22 /*
23  * Checks that the combination of source and sink parameters is supported in this implementation.
24  * Return
25  *     SL_RESULT_SUCCESS
26  *     SL_PARAMETER_INVALID
27  */
28 extern SLresult android_audioPlayer_checkSourceSink(CAudioPlayer *pAudioPlayer);
29 
30 /*
31  * Finish the Android-specific pre-Realize initialization of a CAudioPlayer.
32  */
33 extern void android_audioPlayer_create(CAudioPlayer *pAudioPlayer);
34 
35 /*
36  * Allocates and initializes the Android media framework objects intended to be used with the
37  * given CAudioPlayer data
38  * Return
39  *     SL_RESULT_SUCCESS
40  *     SL_RESULT_CONTENT_UNSUPPORTED if an error occurred during the allocation and initialization
41  *         of the Android resources
42  */
43 extern SLresult android_audioPlayer_realize(CAudioPlayer *pAudioPlayer, SLboolean async);
44 
45 /*
46  * Return
47  *     SL_RESULT_SUCCESS
48  *     SL_RESULT_PARAMETER_INVALID
49  *     SL_RESULT_INTERNAL_ERROR
50  *     SL_RESULT_PRECONDITIONS_VIOLATED
51  */
52 extern SLresult android_audioPlayer_setConfig(CAudioPlayer *pAudioPlayer, const SLchar *configKey,
53         const void *pConfigValue, SLuint32 valueSize);
54 
55 /*
56  * if pConfigValue is NULL, pValueSize contains the size required for the given key
57  *
58  * Return
59  *     SL_RESULT_SUCCESS
60  *     SL_RESULT_PARAMETER_INVALID
61  *     SL_RESULT_INTERNAL_ERROR
62  *     SL_RESULT_PRECONDITIONS_VIOLATED
63  */
64 extern SLresult android_audioPlayer_getConfig(CAudioPlayer *pAudioPlayer, const SLchar *configKey,
65         SLuint32* pValueSize, void *pConfigValue);
66 
67 extern SLresult android_audioPlayer_preDestroy(CAudioPlayer *pAudioPlayer);
68 
69 extern SLresult android_audioPlayer_destroy(CAudioPlayer *pAudioPlayer);
70 
71 /**************************************************************************************************
72  * Configuration
73  ****************************/
74 extern SLresult android_audioPlayer_setPlaybackRateAndConstraints(CAudioPlayer *pAudioPlayer,
75         SLpermille rate, SLuint32 constraints);
76 
77 extern SLresult android_audioPlayer_getDuration(IPlay *pPlayItf, SLmillisecond *pDurMsec);
78 
79 extern void android_audioPlayer_volumeUpdate(CAudioPlayer *pAudioPlayer);
80 
81 extern SLresult android_audioPlayer_setBufferingUpdateThresholdPerMille(CAudioPlayer *pAudioPlayer,
82         SLpermille threshold);
83 
84 /**************************************************************************************************
85  * Metadata Extraction
86  ****************************/
87 /*
88  * For all metadata extraction functions:
89  * Precondition:
90  *     no lock held
91  *     pAudioPlayer != NULL
92  *     input pointers != NULL (pItemCount, pKeySize, pKey, pValueSize, pValue)
93  * Return:
94  *     SL_RESULT_SUCCESS
95  *     SL_RESULT_PARAMETER_INVALID
96  */
97 extern SLresult android_audioPlayer_metadata_getItemCount(CAudioPlayer *pAudioPlayer,
98         SLuint32 *pItemCount);
99 
100 extern SLresult android_audioPlayer_metadata_getKeySize(CAudioPlayer *pAudioPlayer,
101         SLuint32 index, SLuint32 *pKeySize);
102 
103 extern SLresult android_audioPlayer_metadata_getKey(CAudioPlayer *pAudioPlayer,
104         SLuint32 index, SLuint32 size, SLMetadataInfo *pKey);
105 
106 extern SLresult android_audioPlayer_metadata_getValueSize(CAudioPlayer *pAudioPlayer,
107         SLuint32 index, SLuint32 *pValueSize);
108 
109 extern SLresult android_audioPlayer_metadata_getValue(CAudioPlayer *pAudioPlayer,
110         SLuint32 index, SLuint32 size, SLMetadataInfo *pValue);
111 
112 /**************************************************************************************************
113  * Playback control and events
114  ****************************/
115 extern void android_audioPlayer_setPlayState(CAudioPlayer *pAudioPlayer);
116 
117 extern void android_audioPlayer_usePlayEventMask(CAudioPlayer *pAudioPlayer);
118 
119 extern SLresult android_audioPlayer_seek(CAudioPlayer *pAudioPlayer, SLmillisecond posMsec);
120 
121 extern SLresult android_audioPlayer_loop(CAudioPlayer *pAudioPlayer, SLboolean loopEnable);
122 
123 extern void android_audioPlayer_getPosition(IPlay *pPlayItf, SLmillisecond *pPosMsec);
124 
125 /**************************************************************************************************
126  * Buffer Queue events
127  ****************************/
128 extern void android_audioPlayer_bufferQueue_onRefilled_l(CAudioPlayer *pAudioPlayer);
129 
130 extern SLresult android_audioPlayer_bufferQueue_onClear(CAudioPlayer *pAudioPlayer);
131 
132 /**************************************************************************************************
133  * Android Buffer Queue
134  ****************************/
135 /* must be called with a lock on pAudioPlayer->mThis */
136 extern void android_audioPlayer_androidBufferQueue_clear_l(CAudioPlayer *pAudioPlayer);
137 /* must be called with a lock on pAudioPlayer->mThis */
138 extern void android_audioPlayer_androidBufferQueue_onRefilled_l(CAudioPlayer *pAudioPlayer);
139