IStreamInformation.c revision a8179ea15c4ff78db589d742b135649f0eda7ef2
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 %d, only %d 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 %u has " 135 "unknown domain %u", streamIndex, streamInfo.domain); 136 result = XA_RESULT_INTERNAL_ERROR; 137 break; 138 } 139 140 } else { 141 SL_LOGE("Querying stream type for stream %d, only %d streams available", 142 streamIndex, nbStreams); 143 result = XA_RESULT_PARAMETER_INVALID; 144 } 145 146 interface_unlock_exclusive(thiz); 147#endif 148 149 } 150 151 XA_LEAVE_INTERFACE 152} 153 154 155static XAresult IStreamInformation_QueryStreamName( XAStreamInformationItf self, 156 XAuint32 streamIndex, /* [in] */ 157 XAuint16 * pNameSize, /* [in/out] */ 158 XAchar * pName) /* [out] */ 159{ 160 XA_ENTER_INTERFACE 161 162 SL_LOGE("unsupported XAStreamInformationItf function"); 163 result = XA_RESULT_CONTENT_UNSUPPORTED; 164 165 XA_LEAVE_INTERFACE 166} 167 168 169static XAresult IStreamInformation_RegisterStreamChangeCallback( XAStreamInformationItf self, 170 xaStreamEventChangeCallback callback, /* [in] */ 171 void * pContext) /* [in] */ 172{ 173 XA_ENTER_INTERFACE 174 175 IStreamInformation *thiz = (IStreamInformation *) self; 176 177 interface_lock_exclusive(thiz); 178 179 thiz->mCallback = callback; 180 thiz->mContext = pContext; 181 182 switch (InterfaceToObjectID(thiz)) { 183 184 case XA_OBJECTID_MEDIAPLAYER: 185 SL_LOGI("IStreamInformation_RegisterStreamChangeCallback()"); 186 result = SL_RESULT_SUCCESS; 187 break; 188 default: 189 result = SL_RESULT_PARAMETER_INVALID; 190 break; 191 } 192 193 interface_unlock_exclusive(thiz); 194 195 XA_LEAVE_INTERFACE 196} 197 198 199static XAresult IStreamInformation_QueryActiveStreams( XAStreamInformationItf self, 200 XAuint32 *numStreams, /* [in/out] */ 201 XAboolean *activeStreams) /* [out] */ 202{ 203 XA_ENTER_INTERFACE 204 205 if (NULL == numStreams) { 206 result = XA_RESULT_PARAMETER_INVALID; 207 XA_LEAVE_INTERFACE; 208 } 209 210 IStreamInformation *thiz = (IStreamInformation *) self; 211 212 interface_lock_exclusive(thiz); 213 214 result = XA_RESULT_SUCCESS; 215 *numStreams = thiz->mStreamInfoTable.itemAt(0).containerInfo.numStreams; 216 activeStreams = thiz->mActiveStreams; 217 218 interface_unlock_exclusive(thiz); 219 220 XA_LEAVE_INTERFACE 221} 222 223 224static XAresult IStreamInformation_SetActiveStream( XAStreamInformationItf self, 225 XAuint32 streamNum, /* [in] */ 226 XAboolean active, /* [in] */ 227 XAboolean commitNow) /* [in] */ 228{ 229 XA_ENTER_INTERFACE 230 231 SL_LOGE("unsupported XAStreamInformationItf function"); 232 result = XA_RESULT_FEATURE_UNSUPPORTED; 233 234 XA_LEAVE_INTERFACE 235} 236 237 238static const struct XAStreamInformationItf_ IStreamInformation_Itf = { 239 IStreamInformation_QueryMediaContainerInformation, 240 IStreamInformation_QueryStreamType, 241 IStreamInformation_QueryStreamInformation, 242 IStreamInformation_QueryStreamName, 243 IStreamInformation_RegisterStreamChangeCallback, 244 IStreamInformation_QueryActiveStreams, 245 IStreamInformation_SetActiveStream 246}; 247 248 249void IStreamInformation_init(void *self) 250{ 251 SL_LOGV("IStreamInformation_init\n"); 252 IStreamInformation *thiz = (IStreamInformation *) self; 253 thiz->mItf = &IStreamInformation_Itf; 254 255 thiz->mCallback = NULL; 256 thiz->mContext = NULL; 257 258 for (int i=0 ; i < NB_SUPPORTED_STREAMS ; i++) { 259 thiz->mActiveStreams[i] = XA_BOOLEAN_FALSE; 260 } 261 262#ifdef ANDROID 263 // placement new constructor for C++ field within C struct 264 (void) new (&thiz->mStreamInfoTable) android::Vector<StreamInfo>(); 265 // initialize container info 266 StreamInfo contInf; 267 contInf.domain = XA_DOMAINTYPE_CONTAINER; 268 contInf.containerInfo.containerType = XA_CONTAINERTYPE_UNSPECIFIED; 269 contInf.containerInfo.mediaDuration = XA_TIME_UNKNOWN; 270 // FIXME shouldn't this be 1 ? 271 contInf.containerInfo.numStreams = 0; 272 // always storing container info at index 0, as per spec: here, the table was still empty 273 thiz->mStreamInfoTable.add(contInf); 274#endif 275} 276 277 278void IStreamInformation_deinit(void *self) { 279#ifdef ANDROID 280 IStreamInformation *thiz = (IStreamInformation *) self; 281 // explicit destructor 282 thiz->mStreamInfoTable.~Vector<StreamInfo>(); 283#endif 284} 285