IStreamInformation.c revision 2eac6c23b7bd8985e5bc842b9dec9fa3980dd100
1/*
2 * Copyright (C) 2011 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/* StreamInformation implementation */
18
19#include "sles_allinclusive.h"
20
21static XAresult IStreamInformation_QueryMediaContainerInformation( XAStreamInformationItf self,
22        XAMediaContainerInformation * info /* [out] */)
23{
24    XA_ENTER_INTERFACE
25
26#ifdef ANDROID
27    IStreamInformation *thiz = (IStreamInformation *) self;
28    interface_lock_exclusive(thiz);
29    // always storing container info at index 0, as per spec
30    info = (XAMediaContainerInformation*)&(thiz->mStreamInfoTable.itemAt(0).containerInfo);
31    interface_unlock_exclusive(thiz);
32    // even though the pointer to the media container info is returned, the values aren't set
33    //  for the actual container in this version, they are simply initialized to defaults
34    //  (see IStreamInformation_init)
35    result = XA_RESULT_CONTENT_UNSUPPORTED;
36#else
37    SL_LOGE("QueryMediaContainerInformation is unsupported");
38    info = NULL;
39    result = XA_RESULT_CONTENT_UNSUPPORTED;
40#endif
41
42    XA_LEAVE_INTERFACE
43}
44
45
46static XAresult IStreamInformation_QueryStreamType( XAStreamInformationItf self,
47        XAuint32 streamIndex, /* [in] */
48        XAuint32 *domain)     /* [out] */
49{
50    XA_ENTER_INTERFACE
51
52    if (NULL == domain) {
53        result = XA_RESULT_PARAMETER_INVALID;
54        XA_LEAVE_INTERFACE;
55    }
56
57#ifndef ANDROID
58    *domain =  XA_DOMAINTYPE_UNKNOWN;
59#else
60    if (0 == streamIndex) {
61        // stream 0 is reserved for the container
62        result = XA_RESULT_PARAMETER_INVALID;
63    } else {
64        IStreamInformation *thiz = (IStreamInformation *) self;
65
66        interface_lock_exclusive(thiz);
67
68        XAuint32 nbStreams = thiz->mStreamInfoTable.itemAt(0).containerInfo.numStreams;
69        // streams in the container are numbered 1..nbStreams
70        if (streamIndex <= nbStreams) {
71            result = XA_RESULT_SUCCESS;
72            *domain = thiz->mStreamInfoTable.itemAt(streamIndex).domain;
73        } else {
74            SL_LOGE("Querying stream type for stream %ld, only %ld streams available",
75                    streamIndex, nbStreams);
76            result = XA_RESULT_PARAMETER_INVALID;
77        }
78
79        interface_unlock_exclusive(thiz);
80    }
81#endif
82
83    XA_LEAVE_INTERFACE
84}
85
86
87static XAresult IStreamInformation_QueryStreamInformation( XAStreamInformationItf self,
88        XAuint32 streamIndex, /* [in] */
89        void * info)          /* [out] */
90{
91    XA_ENTER_INTERFACE
92
93    if (NULL == info) {
94        result = XA_RESULT_PARAMETER_INVALID;
95    } else {
96
97#ifndef ANDROID
98        result = XA_RESULT_FEATURE_UNSUPPORTED;
99#else
100
101        IStreamInformation *thiz = (IStreamInformation *) self;
102
103        interface_lock_exclusive(thiz);
104
105        XAuint32 nbStreams = thiz->mStreamInfoTable.itemAt(0).containerInfo.numStreams;
106        // streams in the container are numbered 1..nbStreams
107        if (streamIndex <= nbStreams) {
108            result = XA_RESULT_SUCCESS;
109            const StreamInfo& streamInfo = thiz->mStreamInfoTable.itemAt((size_t)streamIndex);
110
111            switch (streamInfo.domain) {
112            case XA_DOMAINTYPE_CONTAINER:
113                *(XAMediaContainerInformation *)info = streamInfo.containerInfo;
114                break;
115            case XA_DOMAINTYPE_AUDIO:
116                *(XAAudioStreamInformation *)info = streamInfo.audioInfo;
117                break;
118            case XA_DOMAINTYPE_VIDEO:
119                *(XAVideoStreamInformation *)info = streamInfo.videoInfo;
120                break;
121            case XA_DOMAINTYPE_IMAGE:
122                *(XAImageStreamInformation *)info = streamInfo.imageInfo;
123                break;
124            case XA_DOMAINTYPE_TIMEDTEXT:
125                *(XATimedTextStreamInformation *)info = streamInfo.textInfo;
126                break;
127            case XA_DOMAINTYPE_MIDI:
128                *(XAMIDIStreamInformation *)info = streamInfo.midiInfo;
129                break;
130            case XA_DOMAINTYPE_VENDOR:
131                *(XAVendorStreamInformation *)info = streamInfo.vendorInfo;
132                break;
133            default:
134                SL_LOGE("StreamInformation::QueryStreamInformation index %lu has unknown domain %lu", streamIndex, streamInfo.domain);
135                result = XA_RESULT_INTERNAL_ERROR;
136                break;
137            }
138
139        } else {
140            SL_LOGE("Querying stream type for stream %ld, only %ld streams available",
141                    streamIndex, nbStreams);
142            result = XA_RESULT_PARAMETER_INVALID;
143        }
144
145        interface_unlock_exclusive(thiz);
146#endif
147
148    }
149
150    XA_LEAVE_INTERFACE
151}
152
153
154static XAresult IStreamInformation_QueryStreamName( XAStreamInformationItf self,
155        XAuint32 streamIndex, /* [in] */
156        XAuint16 * pNameSize, /* [in/out] */
157        XAchar * pName)       /* [out] */
158{
159    XA_ENTER_INTERFACE
160
161    SL_LOGE("unsupported XAStreamInformationItf function");
162    result = XA_RESULT_CONTENT_UNSUPPORTED;
163
164    XA_LEAVE_INTERFACE
165}
166
167
168static XAresult IStreamInformation_RegisterStreamChangeCallback( XAStreamInformationItf self,
169        xaStreamEventChangeCallback callback, /* [in] */
170        void * pContext)                      /* [in] */
171{
172    XA_ENTER_INTERFACE
173
174    IStreamInformation *thiz = (IStreamInformation *) self;
175
176    interface_lock_exclusive(thiz);
177
178    thiz->mCallback = callback;
179    thiz->mContext = pContext;
180
181    switch (InterfaceToObjectID(thiz)) {
182
183    case XA_OBJECTID_MEDIAPLAYER:
184        SL_LOGI("IStreamInformation_RegisterStreamChangeCallback()");
185        result = SL_RESULT_SUCCESS;
186        break;
187    default:
188        result = SL_RESULT_PARAMETER_INVALID;
189        break;
190    }
191
192    interface_unlock_exclusive(thiz);
193
194    XA_LEAVE_INTERFACE
195}
196
197
198static XAresult IStreamInformation_QueryActiveStreams( XAStreamInformationItf self,
199        XAuint32 *numStreams,      /* [in/out] */
200        XAboolean *activeStreams)  /* [out] */
201{
202    XA_ENTER_INTERFACE
203
204    if (NULL == numStreams) {
205        result = XA_RESULT_PARAMETER_INVALID;
206        XA_LEAVE_INTERFACE;
207    }
208
209    IStreamInformation *thiz = (IStreamInformation *) self;
210
211    interface_lock_exclusive(thiz);
212
213    result = XA_RESULT_SUCCESS;
214    *numStreams = thiz->mStreamInfoTable.itemAt(0).containerInfo.numStreams;
215    activeStreams = thiz->mActiveStreams;
216
217    interface_unlock_exclusive(thiz);
218
219    XA_LEAVE_INTERFACE
220}
221
222
223static XAresult IStreamInformation_SetActiveStream( XAStreamInformationItf self,
224        XAuint32   streamNum, /* [in] */
225        XAboolean  active,    /* [in] */
226        XAboolean  commitNow) /* [in] */
227{
228    XA_ENTER_INTERFACE
229
230    SL_LOGE("unsupported XAStreamInformationItf function");
231    result = XA_RESULT_FEATURE_UNSUPPORTED;
232
233    XA_LEAVE_INTERFACE
234}
235
236
237static const struct XAStreamInformationItf_ IStreamInformation_Itf = {
238    IStreamInformation_QueryMediaContainerInformation,
239    IStreamInformation_QueryStreamType,
240    IStreamInformation_QueryStreamInformation,
241    IStreamInformation_QueryStreamName,
242    IStreamInformation_RegisterStreamChangeCallback,
243    IStreamInformation_QueryActiveStreams,
244    IStreamInformation_SetActiveStream
245};
246
247
248void IStreamInformation_init(void *self)
249{
250    SL_LOGV("IStreamInformation_init\n");
251    IStreamInformation *thiz = (IStreamInformation *) self;
252    thiz->mItf = &IStreamInformation_Itf;
253
254    thiz->mCallback = NULL;
255    thiz->mContext = NULL;
256
257    for (int i=0 ; i < NB_SUPPORTED_STREAMS ; i++) {
258        thiz->mActiveStreams[i] = XA_BOOLEAN_FALSE;
259    }
260
261#ifdef ANDROID
262    // placement new constructor for C++ field within C struct
263    (void) new (&thiz->mStreamInfoTable) android::Vector<StreamInfo>();
264    // initialize container info
265    StreamInfo contInf;
266    contInf.domain = XA_DOMAINTYPE_CONTAINER;
267    contInf.containerInfo.containerType = XA_CONTAINERTYPE_UNSPECIFIED;
268    contInf.containerInfo.mediaDuration = XA_TIME_UNKNOWN;
269    // FIXME shouldn't this be 1 ?
270    contInf.containerInfo.numStreams = 0;
271    // always storing container info at index 0, as per spec: here, the table was still empty
272    thiz->mStreamInfoTable.add(contInf);
273#endif
274}
275
276
277void IStreamInformation_deinit(void *self) {
278#ifdef ANDROID
279    IStreamInformation *thiz = (IStreamInformation *) self;
280    // explicit destructor
281    thiz->mStreamInfoTable.~Vector<StreamInfo>();
282#endif
283}
284