IAndroidBufferQueue.c revision 262059f71a68edc5e510427c63f5f1623d3672a8
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/* AndroidBufferQueue implementation */
18
19#include "sles_allinclusive.h"
20
21SLresult IAndroidBufferQueue_RegisterCallback(SLAndroidBufferQueueItf self,
22        slAndroidBufferQueueCallback callback, void *pContext)
23{
24    SL_ENTER_INTERFACE
25
26    IAndroidBufferQueue *this = (IAndroidBufferQueue *) self;
27
28    interface_lock_exclusive(this);
29
30    // verify pre-condition that media object is in the SL_PLAYSTATE_STOPPED state
31    // FIXME PRIORITY 1 check play state
32    //if (SL_PLAYSTATE_STOPPED == ((CAudioPlayer*) this->mThis)->mPlay.mState) {
33        this->mCallback = callback;
34        this->mContext = pContext;
35
36        switch (InterfaceToObjectID(this)) {
37        case SL_OBJECTID_AUDIOPLAYER:
38            result = SL_RESULT_SUCCESS;
39            android_audioPlayer_androidBufferQueue_registerCallback_l((CAudioPlayer*) this->mThis);
40            break;
41        case XA_OBJECTID_MEDIAPLAYER:
42            SL_LOGI("IAndroidBufferQueue_RegisterCallback()");
43            result = SL_RESULT_SUCCESS;
44            android_Player_androidBufferQueue_registerCallback_l((CMediaPlayer*) this->mThis);
45            break;
46        default:
47            result = SL_RESULT_PARAMETER_INVALID;
48            break;
49        }
50
51    //} else {
52    //    result = SL_RESULT_PRECONDITIONS_VIOLATED;
53    //}
54
55    interface_unlock_exclusive(this);
56
57    SL_LEAVE_INTERFACE
58}
59
60
61SLresult IAndroidBufferQueue_Clear(SLAndroidBufferQueueItf self)
62{
63    SL_ENTER_INTERFACE
64
65    IAndroidBufferQueue *this = (IAndroidBufferQueue *) self;
66
67    interface_lock_exclusive(this);
68
69    // FIXME return value?
70    result = SL_RESULT_SUCCESS;
71    android_audioPlayer_androidBufferQueue_clear_l((CAudioPlayer*) this->mThis);
72
73    interface_unlock_exclusive(this);
74
75    SL_LEAVE_INTERFACE
76}
77
78
79SLresult IAndroidBufferQueue_Enqueue(SLAndroidBufferQueueItf self,
80        SLuint32 bufferId,
81        SLuint32 length,
82        SLAbufferQueueEvent event,
83        void *pData)
84{
85    SL_ENTER_INTERFACE
86
87    IAndroidBufferQueue *this = (IAndroidBufferQueue *) self;
88
89    interface_lock_exclusive(this);
90
91    // FIXME return value? of particular interest: error is length is larger than size received
92    //   in callback
93    switch (InterfaceToObjectID(this)) {
94    case SL_OBJECTID_AUDIOPLAYER:
95        result = SL_RESULT_SUCCESS;
96        android_audioPlayer_androidBufferQueue_enqueue_l((CAudioPlayer*) this->mThis,
97                bufferId, length, event, pData);
98        break;
99    case XA_OBJECTID_MEDIAPLAYER:
100        //SL_LOGV("IAndroidBufferQueue_Enqueue()");
101        result = SL_RESULT_SUCCESS;
102        android_Player_androidBufferQueue_enqueue_l((CMediaPlayer*) this->mThis,
103                bufferId, length, event, pData);
104        break;
105    default:
106        result = SL_RESULT_PARAMETER_INVALID;
107        break;
108    }
109
110    interface_unlock_exclusive(this);
111
112    SL_LEAVE_INTERFACE
113}
114
115
116static const struct SLAndroidBufferQueueItf_ IAndroidBufferQueue_Itf = {
117    IAndroidBufferQueue_RegisterCallback,
118    IAndroidBufferQueue_Clear,
119    IAndroidBufferQueue_Enqueue
120};
121
122void IAndroidBufferQueue_init(void *self)
123{
124    IAndroidBufferQueue *this = (IAndroidBufferQueue *) self;
125    this->mItf = &IAndroidBufferQueue_Itf;
126
127    this->mCallback = NULL;
128    this->mContext = NULL;
129}
130