Home | History | Annotate | Download | only in itf
      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 /* MetadataExtraction implementation */
     18 
     19 #include "sles_allinclusive.h"
     20 
     21 
     22 static SLresult IMetadataExtraction_GetItemCount(SLMetadataExtractionItf self, SLuint32 *pItemCount)
     23 {
     24     SL_ENTER_INTERFACE
     25 
     26     if (NULL == pItemCount) {
     27         result = SL_RESULT_PARAMETER_INVALID;
     28     } else {
     29         IMetadataExtraction *thiz = (IMetadataExtraction *) self;
     30         if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) {
     31             result = android_audioPlayer_metadata_getItemCount((CAudioPlayer *)thiz->mThis,
     32                     pItemCount);
     33         } else {
     34             result = SL_RESULT_PARAMETER_INVALID;
     35         }
     36     }
     37 
     38     SL_LEAVE_INTERFACE
     39 }
     40 
     41 
     42 static SLresult IMetadataExtraction_GetKeySize(SLMetadataExtractionItf self,
     43     SLuint32 index, SLuint32 *pKeySize)
     44 {
     45     SL_ENTER_INTERFACE
     46 
     47     if (NULL == pKeySize) {
     48         result = SL_RESULT_PARAMETER_INVALID;
     49     } else {
     50         IMetadataExtraction *thiz = (IMetadataExtraction *) self;
     51         if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) {
     52             result = android_audioPlayer_metadata_getKeySize((CAudioPlayer *)thiz->mThis,
     53                     index, pKeySize);
     54         } else {
     55             result = SL_RESULT_PARAMETER_INVALID;
     56         }
     57     }
     58 
     59     SL_LEAVE_INTERFACE
     60 }
     61 
     62 
     63 static SLresult IMetadataExtraction_GetKey(SLMetadataExtractionItf self,
     64     SLuint32 index, SLuint32 keySize, SLMetadataInfo *pKey)
     65 {
     66     SL_ENTER_INTERFACE
     67 
     68     if (NULL == pKey) {
     69         result = SL_RESULT_PARAMETER_INVALID;
     70     } else {
     71         IMetadataExtraction *thiz = (IMetadataExtraction *) self;
     72         if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) {
     73             result = android_audioPlayer_metadata_getKey((CAudioPlayer *)thiz->mThis,
     74                     index, keySize, pKey);
     75         } else {
     76             result = SL_RESULT_PARAMETER_INVALID;
     77         }
     78     }
     79 
     80     SL_LEAVE_INTERFACE
     81 }
     82 
     83 
     84 static SLresult IMetadataExtraction_GetValueSize(SLMetadataExtractionItf self,
     85     SLuint32 index, SLuint32 *pValueSize)
     86 {
     87     SL_ENTER_INTERFACE
     88 
     89     if (NULL == pValueSize) {
     90         result = SL_RESULT_PARAMETER_INVALID;
     91     } else {
     92         IMetadataExtraction *thiz = (IMetadataExtraction *) self;
     93         if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) {
     94             result = android_audioPlayer_metadata_getValueSize((CAudioPlayer *)thiz->mThis,
     95                     index, pValueSize);
     96         } else {
     97             result = SL_RESULT_PARAMETER_INVALID;
     98         }
     99     }
    100 
    101     SL_LEAVE_INTERFACE
    102 }
    103 
    104 
    105 static SLresult IMetadataExtraction_GetValue(SLMetadataExtractionItf self,
    106     SLuint32 index, SLuint32 valueSize, SLMetadataInfo *pValue)
    107 {
    108     SL_ENTER_INTERFACE
    109 
    110     if (NULL == pValue) {
    111         result = SL_RESULT_PARAMETER_INVALID;
    112     } else {
    113         IMetadataExtraction *thiz = (IMetadataExtraction *) self;
    114         if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) {
    115             result = android_audioPlayer_metadata_getValue((CAudioPlayer *)thiz->mThis,
    116                     index, valueSize, pValue);
    117         } else {
    118             result = SL_RESULT_PARAMETER_INVALID;
    119         }
    120     }
    121 
    122     SL_LEAVE_INTERFACE
    123 }
    124 
    125 
    126 static SLresult IMetadataExtraction_AddKeyFilter(SLMetadataExtractionItf self,
    127     SLuint32 keySize, const void *pKey, SLuint32 keyEncoding,
    128     const SLchar *pValueLangCountry, SLuint32 valueEncoding, SLuint8 filterMask)
    129 {
    130     SL_ENTER_INTERFACE
    131 
    132     if (NULL == pKey || NULL == pValueLangCountry || (filterMask & ~(SL_METADATA_FILTER_KEY |
    133         SL_METADATA_FILTER_KEY | SL_METADATA_FILTER_KEY))) {
    134         result = SL_RESULT_PARAMETER_INVALID;
    135     } else {
    136         IMetadataExtraction *thiz = (IMetadataExtraction *) self;
    137         interface_lock_exclusive(thiz);
    138         thiz->mKeySize = keySize;
    139         thiz->mKey = pKey;
    140         thiz->mKeyEncoding = keyEncoding;
    141         thiz->mValueLangCountry = pValueLangCountry; // should make a local copy
    142         thiz->mValueEncoding = valueEncoding;
    143         thiz->mFilterMask = filterMask;
    144         interface_unlock_exclusive(thiz);
    145         result = SL_RESULT_SUCCESS;
    146     }
    147 
    148     SL_LEAVE_INTERFACE
    149 }
    150 
    151 
    152 static SLresult IMetadataExtraction_ClearKeyFilter(SLMetadataExtractionItf self)
    153 {
    154     SL_ENTER_INTERFACE
    155 
    156     IMetadataExtraction *thiz = (IMetadataExtraction *) self;
    157     thiz->mKeyFilter = 0;
    158     result = SL_RESULT_SUCCESS;
    159 
    160     SL_LEAVE_INTERFACE
    161 }
    162 
    163 
    164 static const struct SLMetadataExtractionItf_ IMetadataExtraction_Itf = {
    165     IMetadataExtraction_GetItemCount,
    166     IMetadataExtraction_GetKeySize,
    167     IMetadataExtraction_GetKey,
    168     IMetadataExtraction_GetValueSize,
    169     IMetadataExtraction_GetValue,
    170     IMetadataExtraction_AddKeyFilter,
    171     IMetadataExtraction_ClearKeyFilter
    172 };
    173 
    174 void IMetadataExtraction_init(void *self)
    175 {
    176     IMetadataExtraction *thiz = (IMetadataExtraction *) self;
    177     thiz->mItf = &IMetadataExtraction_Itf;
    178     thiz->mKeySize = 0;
    179     thiz->mKey = NULL;
    180     thiz->mKeyEncoding = 0 /*TBD*/;
    181     thiz->mValueLangCountry = 0 /*TBD*/;
    182     thiz->mValueEncoding = 0 /*TBD*/;
    183     thiz->mFilterMask = 0 /*TBD*/;
    184     thiz->mKeyFilter = 0;
    185 }
    186