Permalink
Jul 31, 2013
Newer
100644
246 lines (183 sloc)
4.95 KB
1
/*
2
* Copyright (C) 2013 Canonical Ltd
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
* Authored by: Jim Hodapp <jim.hodapp@canonical.com>
17
*/
18
19
// Uncomment to enable verbose debug output
20
#define LOG_NDEBUG 0
21
22
#undef LOG_TAG
23
#define LOG_TAG "MediaFormatLayer"
24
25
#include <hybris/media/media_format_layer.h>
26
#include "media_format_layer_priv.h"
27
28
#include <assert.h>
29
30
#include <utils/Log.h>
31
32
#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__);
33
34
using namespace android;
35
36
static inline _MediaFormat *get_internal_format(MediaFormat format)
37
{
38
if (format == NULL)
39
{
40
ALOGE("format must not be NULL");
41
return NULL;
42
}
43
44
_MediaFormat *mf = static_cast<_MediaFormat*>(format);
45
assert(mf->refcount >= 1);
46
47
return mf;
48
}
49
50
MediaFormat media_format_create_video_format(const char *mime, int32_t width, int32_t height, int64_t duration_us, int32_t max_input_size)
51
{
52
REPORT_FUNCTION()
53
54
_MediaFormat *format = new _MediaFormat();
55
format->mime = AString(mime);
56
format->width = width;
57
format->height = height;
58
format->duration_us = duration_us;
59
format->max_input_size = max_input_size;
60
61
return format;
62
}
63
64
void media_format_destroy(MediaFormat format)
65
{
66
REPORT_FUNCTION()
67
68
_MediaFormat *mf = get_internal_format(format);
69
if (mf == NULL)
70
return;
71
72
if (mf->refcount)
73
return;
74
75
delete mf;
76
}
77
78
void media_format_ref(MediaFormat format)
79
{
80
REPORT_FUNCTION()
81
82
_MediaFormat *mf = get_internal_format(format);
83
if (mf == NULL)
84
return;
85
86
mf->refcount++;
87
}
88
89
void media_format_unref(MediaFormat format)
90
{
91
REPORT_FUNCTION()
92
93
_MediaFormat *mf = get_internal_format(format);
94
if (mf == NULL)
95
return;
96
97
if (mf->refcount)
98
mf->refcount--;
99
}
100
101
void media_format_set_byte_buffer(MediaFormat format, const char *key, uint8_t *data, size_t size)
102
{
103
REPORT_FUNCTION()
104
105
_MediaFormat *mf = get_internal_format(format);
106
if (mf == NULL)
107
return;
108
if (key == NULL || data == NULL || size == 0)
109
return;
110
111
mf->csd_key_name = AString(key);
112
mf->csd = sp<ABuffer>(new ABuffer(data, size));
113
}
114
115
const char* media_format_get_mime(MediaFormat format)
116
{
117
REPORT_FUNCTION()
118
119
_MediaFormat *mf = get_internal_format(format);
120
if (mf == NULL)
121
return NULL;
122
123
return mf->mime.c_str();
124
}
125
126
int64_t media_format_get_duration_us(MediaFormat format)
127
{
128
REPORT_FUNCTION()
129
130
_MediaFormat *mf = get_internal_format(format);
131
if (mf == NULL)
132
return 0;
133
134
return mf->duration_us;
135
}
136
137
int32_t media_format_get_width(MediaFormat format)
138
{
139
REPORT_FUNCTION()
140
141
_MediaFormat *mf = get_internal_format(format);
142
if (mf == NULL)
143
return 0;
144
145
return mf->width;
146
}
147
148
int32_t media_format_get_height(MediaFormat format)
149
{
150
REPORT_FUNCTION()
151
152
_MediaFormat *mf = get_internal_format(format);
153
if (mf == NULL)
154
return 0;
155
156
return mf->height;
157
}
158
159
int32_t media_format_get_max_input_size(MediaFormat format)
160
{
161
REPORT_FUNCTION()
162
163
_MediaFormat *mf = get_internal_format(format);
164
if (mf == NULL)
165
return 0;
166
167
return mf->max_input_size;
168
}
169
170
int32_t media_format_get_stride(MediaFormat format)
171
{
172
REPORT_FUNCTION()
173
174
_MediaFormat *mf = get_internal_format(format);
175
if (mf == NULL)
176
return 0;
177
178
return mf->stride;
179
}
180
181
int32_t media_format_get_slice_height(MediaFormat format)
182
{
183
REPORT_FUNCTION()
184
185
_MediaFormat *mf = get_internal_format(format);
186
if (mf == NULL)
187
return 0;
188
189
return mf->height;
190
}
191
192
int32_t media_format_get_color_format(MediaFormat format)
193
{
194
REPORT_FUNCTION()
195
196
_MediaFormat *mf = get_internal_format(format);
197
if (mf == NULL)
198
return 0;
199
200
return mf->color_format;
201
}
202
203
int32_t media_format_get_crop_left(MediaFormat format)
204
{
205
REPORT_FUNCTION()
206
207
_MediaFormat *mf = get_internal_format(format);
208
if (mf == NULL)
209
return 0;
210
211
return mf->crop_left;
212
}
213
214
int32_t media_format_get_crop_right(MediaFormat format)
215
{
216
REPORT_FUNCTION()
217
218
_MediaFormat *mf = get_internal_format(format);
219
if (mf == NULL)
220
return 0;
221
222
return mf->crop_right;
223
}
224
225
int32_t media_format_get_crop_top(MediaFormat format)
226
{
227
REPORT_FUNCTION()
228
229
_MediaFormat *mf = get_internal_format(format);
230
if (mf == NULL)
231
return 0;
232
233
return mf->crop_top;
234
}
235
236
int32_t media_format_get_crop_bottom(MediaFormat format)
237
{
238
REPORT_FUNCTION()
239
240
_MediaFormat *mf = get_internal_format(format);
241
if (mf == NULL)
242
return 0;
243
244
return mf->crop_bottom;
245
}