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