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