1 /*
2 * GPAC - Multimedia Framework C SDK
3 *
4 * Authors: Jean Le Feuvre
5 * Copyright (c) Telecom ParisTech 2000-2012
6 * All rights reserved
7 *
8 * This file is part of GPAC / MPEG-4 ObjectDescriptor sub-project
9 *
10 * GPAC is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * GPAC is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26 #include <gpac/internal/odf_dev.h>
27 #include <gpac/constants.h>
28
29 #ifndef GPAC_DISABLE_AV_PARSERS
30 #include <gpac/avparse.h>
31 #endif
32
33 GF_EXPORT
gf_odf_stream_type_name(u32 streamType)34 const char *gf_odf_stream_type_name(u32 streamType)
35 {
36 switch (streamType) {
37 case GF_STREAM_OD:
38 return "ObjectDescriptor";
39 case GF_STREAM_OCR:
40 return "ClockReference";
41 case GF_STREAM_SCENE:
42 return "SceneDescription";
43 case GF_STREAM_VISUAL:
44 return "Visual";
45 case GF_STREAM_AUDIO:
46 return "Audio";
47 case GF_STREAM_MPEG7:
48 return "MPEG7";
49 case GF_STREAM_IPMP:
50 return "IPMP";
51 case GF_STREAM_OCI:
52 return "OCI";
53 case GF_STREAM_MPEGJ:
54 return "MPEGJ";
55 case GF_STREAM_INTERACT:
56 return "Interaction";
57 case GF_STREAM_FONT:
58 return "Font";
59 case GF_STREAM_TEXT:
60 return "Text";
61 case GF_STREAM_ND_SUBPIC:
62 return "NeroDigital Subpicture";
63 default:
64 return "Unknown";
65 }
66 }
67
68 GF_EXPORT
gf_odf_stream_type_by_name(const char * streamType)69 u32 gf_odf_stream_type_by_name(const char *streamType)
70 {
71 if (!streamType) return 0;
72 if (!stricmp(streamType, "ObjectDescriptor")) return GF_STREAM_OD;
73 if (!stricmp(streamType, "ClockReference")) return GF_STREAM_OCR;
74 if (!stricmp(streamType, "SceneDescription")) return GF_STREAM_SCENE;
75 if (!stricmp(streamType, "Visual")) return GF_STREAM_VISUAL;
76 if (!stricmp(streamType, "Audio")) return GF_STREAM_AUDIO;
77 if (!stricmp(streamType, "MPEG7")) return GF_STREAM_MPEG7;
78 if (!stricmp(streamType, "IPMP")) return GF_STREAM_IPMP;
79 if (!stricmp(streamType, "OCI")) return GF_STREAM_OCI;
80 if (!stricmp(streamType, "MPEGJ")) return GF_STREAM_MPEGJ;
81 if (!stricmp(streamType, "Interaction")) return GF_STREAM_INTERACT;
82 if (!stricmp(streamType, "Text")) return GF_STREAM_TEXT;
83 return 0;
84 }
85
86
gf_odf_size_field_size(u32 size_desc)87 s32 gf_odf_size_field_size(u32 size_desc)
88 {
89 if (size_desc < 0x00000080) {
90 return 1 + 1;
91 }
92 else if (size_desc < 0x00004000) {
93 return 2 + 1;
94 }
95 else if (size_desc < 0x00200000) {
96 return 3 + 1;
97 }
98 else if (size_desc < 0x10000000) {
99 return 4 + 1;
100 }
101 else {
102 return -1;
103 }
104
105 }
106
107
108 GF_EXPORT
gf_odf_parse_descriptor(GF_BitStream * bs,GF_Descriptor ** desc,u32 * desc_size)109 GF_Err gf_odf_parse_descriptor(GF_BitStream *bs, GF_Descriptor **desc, u32 *desc_size)
110 {
111 u32 val, size, sizeHeader;
112 u8 tag;
113 GF_Err err;
114 GF_Descriptor *newDesc;
115 if (!bs) return GF_BAD_PARAM;
116
117 *desc_size = 0;
118
119 //tag
120 tag = (u8)gf_bs_read_int(bs, 8);
121 sizeHeader = 1;
122
123 //size
124 size = 0;
125 do {
126 val = gf_bs_read_int(bs, 8);
127 sizeHeader++;
128 size <<= 7;
129 size |= val & 0x7F;
130 } while (val & 0x80);
131 *desc_size = size;
132
133 GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[ODF] Reading descriptor (tag %d size %d)\n", tag, size));
134
135 newDesc = gf_odf_create_descriptor(tag);
136 if (!newDesc) {
137 *desc = NULL;
138 *desc_size = sizeHeader;
139 if ((tag >= GF_ODF_ISO_RES_BEGIN_TAG) &&
140 (tag <= GF_ODF_ISO_RES_END_TAG)) {
141 return GF_ODF_FORBIDDEN_DESCRIPTOR;
142 }
143 else if (!tag || (tag == 0xFF)) {
144 return GF_ODF_INVALID_DESCRIPTOR;
145 }
146 #ifndef GPAC_MINIMAL_ODF
147 return GF_OUT_OF_MEM;
148 #else
149 gf_bs_skip_bytes(bs, size);
150 *desc_size = size + sizeHeader - gf_odf_size_field_size(*desc_size);
151 return GF_OK;
152 #endif
153 }
154
155 newDesc->tag = tag;
156 err = gf_odf_read_descriptor(bs, newDesc, *desc_size);
157
158 /*FFMPEG fix*/
159 if ((tag == GF_ODF_SLC_TAG) && (((GF_SLConfig*)newDesc)->predefined == 2)) {
160 if (*desc_size == 3) {
161 *desc_size = 1;
162 err = GF_OK;
163 }
164 }
165
166 //little trick to handle lazy bitstreams that encode
167 //SizeOfInstance on a fix number of bytes
168 //This nb of bytes is added in Read methods
169 *desc_size += sizeHeader - gf_odf_size_field_size(*desc_size);
170 *desc = newDesc;
171 if (err) {
172 GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC, ("[ODF] Error reading descriptor (tag %d size %d): %s\n", tag, size, gf_error_to_string(err)));
173 gf_odf_delete_descriptor(newDesc);
174 *desc = NULL;
175 }
176 return err;
177 }
178
179
180
gf_odf_delete_descriptor_list(GF_List * descList)181 GF_Err gf_odf_delete_descriptor_list(GF_List *descList)
182 {
183 GF_Err e;
184 GF_Descriptor*tmp;
185 u32 i;
186 //no error if NULL chain...
187 if (!descList) return GF_OK;
188 i = 0;
189 while ((tmp = (GF_Descriptor*)gf_list_enum(descList, &i))) {
190 e = gf_odf_delete_descriptor(tmp);
191 if (e) return e;
192 }
193 gf_list_del(descList);
194 return GF_OK;
195 }
196
gf_odf_write_base_descriptor(GF_BitStream * bs,u8 tag,u32 size)197 GF_Err gf_odf_write_base_descriptor(GF_BitStream *bs, u8 tag, u32 size)
198 {
199 u32 length;
200 unsigned char vals[4];
201
202 if (!tag) return GF_BAD_PARAM;
203
204 length = size;
205 vals[3] = (unsigned char)(length & 0x7f);
206 length >>= 7;
207 vals[2] = (unsigned char)((length & 0x7f) | 0x80);
208 length >>= 7;
209 vals[1] = (unsigned char)((length & 0x7f) | 0x80);
210 length >>= 7;
211 vals[0] = (unsigned char)((length & 0x7f) | 0x80);
212
213 gf_bs_write_int(bs, tag, 8);
214 if (size < 0x00000080) {
215 gf_bs_write_int(bs, vals[3], 8);
216 }
217 else if (size < 0x00004000) {
218 gf_bs_write_int(bs, vals[2], 8);
219 gf_bs_write_int(bs, vals[3], 8);
220 }
221 else if (size < 0x00200000) {
222 gf_bs_write_int(bs, vals[1], 8);
223 gf_bs_write_int(bs, vals[2], 8);
224 gf_bs_write_int(bs, vals[3], 8);
225 }
226 else if (size < 0x10000000) {
227 gf_bs_write_int(bs, vals[0], 8);
228 gf_bs_write_int(bs, vals[1], 8);
229 gf_bs_write_int(bs, vals[2], 8);
230 gf_bs_write_int(bs, vals[3], 8);
231 }
232 else {
233 return GF_ODF_INVALID_DESCRIPTOR;
234 }
235 return GF_OK;
236 }
237
238
gf_odf_size_descriptor_list(GF_List * descList,u32 * outSize)239 GF_Err gf_odf_size_descriptor_list(GF_List *descList, u32 *outSize)
240 {
241 GF_Err e;
242 GF_Descriptor *tmp;
243 u32 tmpSize, count, i;
244 if (!descList) return GF_OK;
245
246 count = gf_list_count(descList);
247 for (i = 0; i < count; i++) {
248 tmp = (GF_Descriptor*)gf_list_get(descList, i);
249 if (tmp) {
250 e = gf_odf_size_descriptor(tmp, &tmpSize);
251 if (e) return e;
252 if (tmpSize) *outSize += tmpSize + gf_odf_size_field_size(tmpSize);
253 }
254 }
255 return GF_OK;
256 }
257
gf_odf_write_descriptor_list(GF_BitStream * bs,GF_List * descList)258 GF_Err gf_odf_write_descriptor_list(GF_BitStream *bs, GF_List *descList)
259 {
260 GF_Err e;
261 u32 count, i;
262 GF_Descriptor *tmp;
263
264 if (!descList) return GF_OK;
265 count = gf_list_count(descList);
266 for (i = 0; i < count; i++) {
267 tmp = (GF_Descriptor*)gf_list_get(descList, i);
268 if (tmp) {
269 e = gf_odf_write_descriptor(bs, tmp);
270 if (e) return e;
271 }
272 }
273 return GF_OK;
274 }
275
gf_odf_write_descriptor_list_filter(GF_BitStream * bs,GF_List * descList,u8 only_tag)276 GF_Err gf_odf_write_descriptor_list_filter(GF_BitStream *bs, GF_List *descList, u8 only_tag)
277 {
278 GF_Err e;
279 u32 count, i;
280 GF_Descriptor *tmp;
281
282 if (!descList) return GF_OK;
283 count = gf_list_count(descList);
284 for (i = 0; i < count; i++) {
285 tmp = (GF_Descriptor*)gf_list_get(descList, i);
286 if (tmp && (tmp->tag == only_tag)) {
287 e = gf_odf_write_descriptor(bs, tmp);
288 if (e) return e;
289 }
290 }
291 return GF_OK;
292 }
293 #ifndef GPAC_DISABLE_ODF
294
295
gf_ipmpx_array_size(GF_BitStream * bs,u32 * array_size)296 u32 gf_ipmpx_array_size(GF_BitStream *bs, u32 *array_size)
297 {
298 u32 val, size, io_size;
299
300 io_size = size = 0;
301 do {
302 val = gf_bs_read_int(bs, 8);
303 io_size++;
304 size <<= 7;
305 size |= val & 0x7F;
306 } while (val & 0x80);
307 *array_size = size;
308 return io_size;
309 }
310
gf_ipmpx_write_array(GF_BitStream * bs,char * data,u32 data_len)311 void gf_ipmpx_write_array(GF_BitStream *bs, char *data, u32 data_len)
312 {
313 u32 length;
314 unsigned char vals[4];
315
316 if (!data || !data_len) return;
317
318 length = data_len;
319 vals[3] = (unsigned char)(length & 0x7f);
320 length >>= 7;
321 vals[2] = (unsigned char)((length & 0x7f) | 0x80);
322 length >>= 7;
323 vals[1] = (unsigned char)((length & 0x7f) | 0x80);
324 length >>= 7;
325 vals[0] = (unsigned char)((length & 0x7f) | 0x80);
326
327 if (data_len < 0x00000080) {
328 gf_bs_write_int(bs, vals[3], 8);
329 }
330 else if (data_len < 0x00004000) {
331 gf_bs_write_int(bs, vals[2], 8);
332 gf_bs_write_int(bs, vals[3], 8);
333 }
334 else if (data_len < 0x00200000) {
335 gf_bs_write_int(bs, vals[1], 8);
336 gf_bs_write_int(bs, vals[2], 8);
337 gf_bs_write_int(bs, vals[3], 8);
338 }
339 else if (data_len < 0x10000000) {
340 gf_bs_write_int(bs, vals[0], 8);
341 gf_bs_write_int(bs, vals[1], 8);
342 gf_bs_write_int(bs, vals[2], 8);
343 gf_bs_write_int(bs, vals[3], 8);
344 }
345 else {
346 return;
347 }
348 gf_bs_write_data(bs, data, data_len);
349 }
350
351
352 #endif /*GPAC_MINIMAL_ODF*/
353
354 /*special authoring functions*/
355 GF_EXPORT
gf_odf_get_bifs_config(GF_DefaultDescriptor * dsi,u8 oti)356 GF_BIFSConfig *gf_odf_get_bifs_config(GF_DefaultDescriptor *dsi, u8 oti)
357 {
358 Bool hasSize, cmd_stream;
359 GF_BitStream *bs;
360 GF_BIFSConfig *cfg;
361
362 if (oti >= GPAC_OTI_SCENE_BIFS_EXTENDED) return NULL;
363
364 if (!dsi || !dsi->data || !dsi->dataLength) {
365 /* Hack for T-DMB non compliant streams (OnTimeTek ?) */
366 cfg = (GF_BIFSConfig *)gf_odf_desc_new(GF_ODF_BIFS_CFG_TAG);
367 cfg->pixelMetrics = GF_TRUE;
368 cfg->version = 1;
369 return cfg;
370 }
371 bs = gf_bs_new(dsi->data, dsi->dataLength, GF_BITSTREAM_READ);
372
373 cfg = (GF_BIFSConfig *)gf_odf_desc_new(GF_ODF_BIFS_CFG_TAG);
374 if (oti == 2) {
375 /*3D Mesh Coding*/
376 gf_bs_read_int(bs, 1);
377 /*PMF*/
378 gf_bs_read_int(bs, 1);
379 }
380 cfg->nodeIDbits = gf_bs_read_int(bs, 5);
381 cfg->routeIDbits = gf_bs_read_int(bs, 5);
382 if (oti == 2) cfg->protoIDbits = gf_bs_read_int(bs, 5);
383
384 cmd_stream = (Bool)gf_bs_read_int(bs, 1);
385 if (!cmd_stream) {
386 cfg->elementaryMasks = gf_list_new();
387 while (1) {
388 GF_ElementaryMask* em = (GF_ElementaryMask*)gf_odf_New_ElemMask();
389 em->node_id = gf_bs_read_int(bs, cfg->nodeIDbits);
390 gf_list_add(cfg->elementaryMasks, em);
391 /*this assumes only FDP, BDP and IFS2D (no elem mask)*/
392 if (gf_bs_read_int(bs, 1) == 0) break;
393 }
394 gf_bs_align(bs);
395 if (gf_bs_get_size(bs) != gf_bs_get_position(bs)) {
396 GF_LOG(GF_LOG_WARNING, GF_LOG_CODEC, ("[ODF] Reading bifs config: shift in sizes (not supported)\n"));
397 }
398 }
399 else {
400 cfg->pixelMetrics = (Bool)gf_bs_read_int(bs, 1);
401 hasSize = (Bool)gf_bs_read_int(bs, 1);
402 if (hasSize) {
403 cfg->pixelWidth = gf_bs_read_int(bs, 16);
404 cfg->pixelHeight = gf_bs_read_int(bs, 16);
405 }
406 gf_bs_align(bs);
407 if (gf_bs_get_size(bs) != gf_bs_get_position(bs))
408 GF_LOG(GF_LOG_WARNING, GF_LOG_CODEC, ("[ODF] Reading bifs config: shift in sizes (invalid descriptor)\n"));
409 }
410 gf_bs_del(bs);
411 return cfg;
412 }
413
414 /*special function for authoring - convert DSI to LASERConfig*/
415 GF_EXPORT
gf_odf_get_laser_config(GF_DefaultDescriptor * dsi,GF_LASERConfig * cfg)416 GF_Err gf_odf_get_laser_config(GF_DefaultDescriptor *dsi, GF_LASERConfig *cfg)
417 {
418 u32 to_skip;
419 GF_BitStream *bs;
420
421 if (!cfg) return GF_BAD_PARAM;
422 memset(cfg, 0, sizeof(GF_LASERConfig));
423
424 if (!dsi || !dsi->data || !dsi->dataLength || !cfg) return GF_BAD_PARAM;
425 bs = gf_bs_new(dsi->data, dsi->dataLength, GF_BITSTREAM_READ);
426 memset(cfg, 0, sizeof(GF_LASERConfig));
427 cfg->tag = GF_ODF_LASER_CFG_TAG;
428 cfg->profile = gf_bs_read_int(bs, 8);
429 cfg->level = gf_bs_read_int(bs, 8);
430 /*cfg->reserved = */gf_bs_read_int(bs, 3);
431 cfg->pointsCodec = gf_bs_read_int(bs, 2);
432 cfg->pathComponents = gf_bs_read_int(bs, 4);
433 cfg->fullRequestHost = gf_bs_read_int(bs, 1);
434 if (gf_bs_read_int(bs, 1)) cfg->time_resolution = gf_bs_read_int(bs, 16);
435 else cfg->time_resolution = 1000;
436 cfg->colorComponentBits = 1 + gf_bs_read_int(bs, 4);
437 cfg->resolution = gf_bs_read_int(bs, 4);
438 if (cfg->resolution>7) cfg->resolution -= 16;
439 cfg->coord_bits = gf_bs_read_int(bs, 5);
440 cfg->scale_bits_minus_coord_bits = gf_bs_read_int(bs, 4);
441 cfg->newSceneIndicator = gf_bs_read_int(bs, 1);
442 /*reserved2*/ gf_bs_read_int(bs, 3);
443 cfg->extensionIDBits = gf_bs_read_int(bs, 4);
444 /*hasExtConfig - we just ignore it*/
445 if (gf_bs_read_int(bs, 1)) {
446 to_skip = gf_bs_read_vluimsbf5(bs);
447 while (to_skip) {
448 gf_bs_read_int(bs, 8);
449 to_skip--;
450 }
451 }
452 /*hasExtension - we just ignore it*/
453 if (gf_bs_read_int(bs, 1)) {
454 to_skip = gf_bs_read_vluimsbf5(bs);
455 while (to_skip) {
456 gf_bs_read_int(bs, 8);
457 to_skip--;
458 }
459 }
460 gf_bs_del(bs);
461 return GF_OK;
462 }
463
464 GF_EXPORT
gf_odf_get_ui_config(GF_DefaultDescriptor * dsi,GF_UIConfig * cfg)465 GF_Err gf_odf_get_ui_config(GF_DefaultDescriptor *dsi, GF_UIConfig *cfg)
466 {
467 u32 len, i;
468 GF_BitStream *bs;
469 if (!dsi || !dsi->data || !dsi->dataLength || !cfg) return GF_BAD_PARAM;
470 memset(cfg, 0, sizeof(GF_UIConfig));
471 cfg->tag = GF_ODF_UI_CFG_TAG;
472 bs = gf_bs_new(dsi->data, dsi->dataLength, GF_BITSTREAM_READ);
473 len = gf_bs_read_int(bs, 8);
474 cfg->deviceName = (char*)gf_malloc(sizeof(char) * (len + 1));
475 for (i = 0; i<len; i++) cfg->deviceName[i] = gf_bs_read_int(bs, 8);
476 cfg->deviceName[i] = 0;
477
478 if (!stricmp(cfg->deviceName, "StringSensor") && gf_bs_available(bs)) {
479 cfg->termChar = gf_bs_read_int(bs, 8);
480 cfg->delChar = gf_bs_read_int(bs, 8);
481 }
482 gf_bs_del(bs);
483 return GF_OK;
484 }
485
486 GF_EXPORT
gf_odf_encode_ui_config(GF_UIConfig * cfg,GF_DefaultDescriptor ** out_dsi)487 GF_Err gf_odf_encode_ui_config(GF_UIConfig *cfg, GF_DefaultDescriptor **out_dsi)
488 {
489 u32 i, len;
490 GF_BitStream *bs;
491 GF_DefaultDescriptor *dsi;
492 if (!out_dsi || (cfg->tag != GF_ODF_UI_CFG_TAG)) return GF_BAD_PARAM;
493
494 *out_dsi = NULL;
495 if (!cfg->deviceName) return GF_OK;
496
497 bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
498 len = (u32)strlen(cfg->deviceName);
499 gf_bs_write_int(bs, len, 8);
500 for (i = 0; i<len; i++) gf_bs_write_int(bs, cfg->deviceName[i], 8);
501 if (!stricmp(cfg->deviceName, "StringSensor")) {
502 /*fixme - this should be UTF-8 chars*/
503 if (cfg->delChar || cfg->termChar) {
504 gf_bs_write_int(bs, cfg->termChar, 8);
505 gf_bs_write_int(bs, cfg->delChar, 8);
506 }
507 }
508 if (cfg->ui_data) gf_bs_write_data(bs, cfg->ui_data, cfg->ui_data_length);
509
510 dsi = (GF_DefaultDescriptor *)gf_odf_desc_new(GF_ODF_DSI_TAG);
511 gf_bs_get_content(bs, &dsi->data, &dsi->dataLength);
512 gf_bs_del(bs);
513 *out_dsi = dsi;
514 return GF_OK;
515 }
516
517
518 GF_EXPORT
gf_odf_avc_cfg_new()519 GF_AVCConfig *gf_odf_avc_cfg_new()
520 {
521 GF_AVCConfig *cfg;
522 GF_SAFEALLOC(cfg, GF_AVCConfig);
523 if (!cfg) return NULL;
524 cfg->sequenceParameterSets = gf_list_new();
525 cfg->pictureParameterSets = gf_list_new();
526 cfg->AVCLevelIndication = 1;
527 cfg->chroma_format = 1;
528 cfg->chroma_bit_depth = 8;
529 cfg->luma_bit_depth = 8;
530 return cfg;
531 }
532
533 GF_EXPORT
gf_odf_avc_cfg_del(GF_AVCConfig * cfg)534 void gf_odf_avc_cfg_del(GF_AVCConfig *cfg)
535 {
536 if (!cfg) return;
537 while (gf_list_count(cfg->sequenceParameterSets)) {
538 GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(cfg->sequenceParameterSets, 0);
539 gf_list_rem(cfg->sequenceParameterSets, 0);
540 if (sl->data) gf_free(sl->data);
541 gf_free(sl);
542 }
543 gf_list_del(cfg->sequenceParameterSets);
544 while (gf_list_count(cfg->pictureParameterSets)) {
545 GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(cfg->pictureParameterSets, 0);
546 gf_list_rem(cfg->pictureParameterSets, 0);
547 if (sl->data) gf_free(sl->data);
548 gf_free(sl);
549 }
550 gf_list_del(cfg->pictureParameterSets);
551
552 if (cfg->sequenceParameterSetExtensions) {
553 while (gf_list_count(cfg->sequenceParameterSetExtensions)) {
554 GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(cfg->sequenceParameterSetExtensions, 0);
555 gf_list_rem(cfg->sequenceParameterSetExtensions, 0);
556 if (sl->data) gf_free(sl->data);
557 gf_free(sl);
558 }
559 gf_list_del(cfg->sequenceParameterSetExtensions);
560 }
561 gf_free(cfg);
562 }
563
564 GF_EXPORT
gf_odf_avc_cfg_write(GF_AVCConfig * cfg,char ** outData,u32 * outSize)565 GF_Err gf_odf_avc_cfg_write(GF_AVCConfig *cfg, char **outData, u32 *outSize)
566 {
567 u32 i, count;
568 GF_BitStream *bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
569 gf_bs_write_int(bs, cfg->configurationVersion, 8);
570 gf_bs_write_int(bs, cfg->AVCProfileIndication, 8);
571 gf_bs_write_int(bs, cfg->profile_compatibility, 8);
572 gf_bs_write_int(bs, cfg->AVCLevelIndication, 8);
573 gf_bs_write_int(bs, 0x3F, 6);
574 gf_bs_write_int(bs, cfg->nal_unit_size - 1, 2);
575 gf_bs_write_int(bs, 0x7, 3);
576 count = gf_list_count(cfg->sequenceParameterSets);
577 gf_bs_write_int(bs, count, 5);
578 for (i = 0; i<count; i++) {
579 GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(cfg->sequenceParameterSets, i);
580 gf_bs_write_int(bs, sl->size, 16);
581 gf_bs_write_data(bs, sl->data, sl->size);
582 }
583 count = gf_list_count(cfg->pictureParameterSets);
584 gf_bs_write_int(bs, count, 8);
585 for (i = 0; i<count; i++) {
586 GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(cfg->pictureParameterSets, i);
587 gf_bs_write_int(bs, sl->size, 16);
588 gf_bs_write_data(bs, sl->data, sl->size);
589 }
590 if (gf_avc_is_rext_profile(cfg->AVCProfileIndication)) {
591 gf_bs_write_int(bs, 0xFF, 6);
592 gf_bs_write_int(bs, cfg->chroma_format, 2);
593 gf_bs_write_int(bs, 0xFF, 5);
594 gf_bs_write_int(bs, cfg->luma_bit_depth - 8, 3);
595 gf_bs_write_int(bs, 0xFF, 5);
596 gf_bs_write_int(bs, cfg->chroma_bit_depth - 8, 3);
597
598 count = cfg->sequenceParameterSetExtensions ? gf_list_count(cfg->sequenceParameterSetExtensions) : 0;
599 gf_bs_write_u8(bs, count);
600 for (i = 0; i<count; i++) {
601 GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(cfg->sequenceParameterSetExtensions, i);
602 gf_bs_write_u16(bs, sl->size);
603 gf_bs_write_data(bs, sl->data, sl->size);
604 }
605 }
606 *outSize = 0;
607 *outData = NULL;
608 gf_bs_get_content(bs, outData, outSize);
609 gf_bs_del(bs);
610 return GF_OK;
611 }
612
613 GF_EXPORT
gf_odf_avc_cfg_read(char * dsi,u32 dsi_size)614 GF_AVCConfig *gf_odf_avc_cfg_read(char *dsi, u32 dsi_size)
615 {
616 u32 i, count;
617 GF_AVCConfig *avcc = gf_odf_avc_cfg_new();
618 GF_BitStream *bs = gf_bs_new(dsi, dsi_size, GF_BITSTREAM_READ);
619 avcc->configurationVersion = gf_bs_read_int(bs, 8);
620 avcc->AVCProfileIndication = gf_bs_read_int(bs, 8);
621 avcc->profile_compatibility = gf_bs_read_int(bs, 8);
622 avcc->AVCLevelIndication = gf_bs_read_int(bs, 8);
623 gf_bs_read_int(bs, 6);
624 avcc->nal_unit_size = 1 + gf_bs_read_int(bs, 2);
625 gf_bs_read_int(bs, 3);
626 count = gf_bs_read_int(bs, 5);
627 for (i = 0; i<count; i++) {
628 GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_malloc(sizeof(GF_AVCConfigSlot));
629 sl->size = gf_bs_read_int(bs, 16);
630 sl->data = (char*)gf_malloc(sizeof(char)*sl->size);
631 gf_bs_read_data(bs, sl->data, sl->size);
632 gf_list_add(avcc->sequenceParameterSets, sl);
633 }
634 count = gf_bs_read_int(bs, 8);
635 for (i = 0; i<count; i++) {
636 GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_malloc(sizeof(GF_AVCConfigSlot));
637 sl->size = gf_bs_read_int(bs, 16);
638 sl->data = (char*)gf_malloc(sizeof(char)*sl->size);
639 gf_bs_read_data(bs, sl->data, sl->size);
640 gf_list_add(avcc->pictureParameterSets, sl);
641 }
642 if (gf_avc_is_rext_profile(avcc->AVCProfileIndication)) {
643 gf_bs_read_int(bs, 6);
644 avcc->chroma_format = gf_bs_read_int(bs, 2);
645 gf_bs_read_int(bs, 5);
646 avcc->luma_bit_depth = 8 + gf_bs_read_int(bs, 3);
647 gf_bs_read_int(bs, 5);
648 avcc->chroma_bit_depth = 8 + gf_bs_read_int(bs, 3);
649
650 count = gf_bs_read_int(bs, 8);
651 if (count) {
652 avcc->sequenceParameterSetExtensions = gf_list_new();
653 for (i = 0; i<count; i++) {
654 GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_malloc(sizeof(GF_AVCConfigSlot));
655 sl->size = gf_bs_read_u16(bs);
656 sl->data = (char *)gf_malloc(sizeof(char) * sl->size);
657 gf_bs_read_data(bs, sl->data, sl->size);
658 gf_list_add(avcc->sequenceParameterSetExtensions, sl);
659 }
660 }
661 }
662
663
664 gf_bs_del(bs);
665 return avcc;
666 }
667
668
gf_odf_new_tx3g()669 GF_Descriptor *gf_odf_new_tx3g()
670 {
671 GF_TextSampleDescriptor *newDesc = (GF_TextSampleDescriptor*)gf_malloc(sizeof(GF_TextSampleDescriptor));
672 if (!newDesc) return NULL;
673 memset(newDesc, 0, sizeof(GF_TextSampleDescriptor));
674 newDesc->tag = GF_ODF_TX3G_TAG;
675 return (GF_Descriptor *)newDesc;
676 }
gf_odf_del_tx3g(GF_TextSampleDescriptor * sd)677 GF_Err gf_odf_del_tx3g(GF_TextSampleDescriptor *sd)
678 {
679 u32 i;
680 for (i = 0; i<sd->font_count; i++)
681 if (sd->fonts[i].fontName) gf_free(sd->fonts[i].fontName);
682 gf_free(sd->fonts);
683 gf_free(sd);
684 return GF_OK;
685 }
686
687 /*TextConfig*/
gf_odf_new_text_cfg()688 GF_Descriptor *gf_odf_new_text_cfg()
689 {
690 GF_TextConfig *newDesc = (GF_TextConfig*)gf_malloc(sizeof(GF_TextConfig));
691 if (!newDesc) return NULL;
692 memset(newDesc, 0, sizeof(GF_TextConfig));
693 newDesc->tag = GF_ODF_TEXT_CFG_TAG;
694 newDesc->sample_descriptions = gf_list_new();
695 newDesc->Base3GPPFormat = 0x10;
696 newDesc->MPEGExtendedFormat = 0x10;
697 newDesc->profileLevel = 0x10;
698 newDesc->timescale = 1000;
699 return (GF_Descriptor *)newDesc;
700 }
701
ResetTextConfig(GF_TextConfig * desc)702 void ResetTextConfig(GF_TextConfig *desc)
703 {
704 GF_List *bck;
705 while (gf_list_count(desc->sample_descriptions)) {
706 GF_TextSampleDescriptor *sd = (GF_TextSampleDescriptor *)gf_list_get(desc->sample_descriptions, 0);
707 gf_list_rem(desc->sample_descriptions, 0);
708 gf_odf_del_tx3g(sd);
709 }
710 bck = desc->sample_descriptions;
711 memset(desc, 0, sizeof(GF_TextConfig));
712 desc->tag = GF_ODF_TEXT_CFG_TAG;
713 desc->sample_descriptions = bck;
714 }
715
gf_odf_del_text_cfg(GF_TextConfig * desc)716 GF_Err gf_odf_del_text_cfg(GF_TextConfig *desc)
717 {
718 ResetTextConfig(desc);
719 gf_list_del(desc->sample_descriptions);
720 gf_free(desc);
721 return GF_OK;
722 }
723
724 /*we need box parsing*/
725 #include <gpac/internal/isomedia_dev.h>
726 GF_EXPORT
gf_odf_get_text_config(GF_DefaultDescriptor * dsi,u8 oti,GF_TextConfig * cfg)727 GF_Err gf_odf_get_text_config(GF_DefaultDescriptor *dsi, u8 oti, GF_TextConfig *cfg)
728 {
729 u32 i;
730 Bool has_alt_format;
731 #ifndef GPAC_DISABLE_ISOM
732 Bool has_sd;
733 u32 j;
734 #endif
735 GF_Err e;
736 GF_BitStream *bs;
737 if (!dsi || !dsi->data || !dsi->dataLength || !cfg) return GF_BAD_PARAM;
738 if (oti != 0x08) return GF_NOT_SUPPORTED;
739
740 /*reset*/
741 ResetTextConfig(cfg);
742 bs = gf_bs_new(dsi->data, dsi->dataLength, GF_BITSTREAM_READ);
743
744 e = GF_OK;
745 cfg->Base3GPPFormat = gf_bs_read_int(bs, 8);
746 cfg->MPEGExtendedFormat = gf_bs_read_int(bs, 8);
747 cfg->profileLevel = gf_bs_read_int(bs, 8);
748 cfg->timescale = gf_bs_read_int(bs, 24);
749 has_alt_format = (Bool)gf_bs_read_int(bs, 1);
750 cfg->sampleDescriptionFlags = gf_bs_read_int(bs, 2);
751 #ifndef GPAC_DISABLE_ISOM
752 has_sd = (Bool)gf_bs_read_int(bs, 1);
753 #else
754 gf_bs_read_int(bs, 1);
755 #endif
756 cfg->has_vid_info = (Bool)gf_bs_read_int(bs, 1);
757 gf_bs_read_int(bs, 3);
758 cfg->layer = gf_bs_read_int(bs, 8);
759 cfg->text_width = gf_bs_read_int(bs, 16);
760 cfg->text_height = gf_bs_read_int(bs, 16);
761 if (has_alt_format) {
762 cfg->nb_compatible_formats = gf_bs_read_int(bs, 8);
763 for (i = 0; i<cfg->nb_compatible_formats; i++) cfg->compatible_formats[i] = gf_bs_read_int(bs, 8);
764 }
765 #ifndef GPAC_DISABLE_ISOM
766 if (has_sd) {
767 u8 sample_index;
768 GF_TextSampleDescriptor *txdesc;
769 GF_Tx3gSampleEntryBox *a;
770 s64 avail;
771 u32 nb_desc = gf_bs_read_int(bs, 8);
772
773 /*parse TTU[5]s*/
774 avail = (s64)gf_bs_available(bs);
775 for (i = 0; i<nb_desc; i++) {
776 sample_index = gf_bs_read_int(bs, 8);
777 avail -= 1;
778 e = gf_isom_parse_box((GF_Box **)&a, bs);
779 if (e) goto exit;
780 avail -= (s32)a->size;
781
782 if (avail<0) {
783 e = GF_NON_COMPLIANT_BITSTREAM;
784 goto exit;
785 }
786 txdesc = (GF_TextSampleDescriptor *)gf_malloc(sizeof(GF_TextSampleDescriptor));
787 txdesc->sample_index = sample_index;
788 txdesc->displayFlags = a->displayFlags;
789 txdesc->back_color = a->back_color;
790 txdesc->default_pos = a->default_box;
791 txdesc->default_style = a->default_style;
792 txdesc->vert_justif = a->vertical_justification;
793 txdesc->horiz_justif = a->horizontal_justification;
794 txdesc->font_count = a->font_table ? a->font_table->entry_count : 0;
795 if (txdesc->font_count) {
796 txdesc->fonts = (GF_FontRecord*)gf_malloc(sizeof(GF_FontRecord)*txdesc->font_count);
797 for (j = 0; j<txdesc->font_count; j++) {
798 txdesc->fonts[j].fontID = a->font_table->fonts[j].fontID;
799 txdesc->fonts[j].fontName = a->font_table->fonts[j].fontName ? gf_strdup(a->font_table->fonts[j].fontName) : NULL;
800 }
801 }
802 gf_list_add(cfg->sample_descriptions, txdesc);
803 gf_isom_box_del((GF_Box *)a);
804 }
805 }
806 #endif
807
808 if (cfg->has_vid_info) {
809 cfg->video_width = gf_bs_read_int(bs, 16);
810 cfg->video_height = gf_bs_read_int(bs, 16);
811 cfg->horiz_offset = gf_bs_read_int(bs, 16);
812 cfg->vert_offset = gf_bs_read_int(bs, 16);
813 }
814
815 #ifndef GPAC_DISABLE_ISOM
816 exit :
817 #endif
818 gf_bs_del(bs);
819 if (e) ResetTextConfig(cfg);
820 return e;
821 }
822
823
824
825 GF_EXPORT
gf_odf_hevc_cfg_new()826 GF_HEVCConfig *gf_odf_hevc_cfg_new()
827 {
828 GF_HEVCConfig *cfg;
829 GF_SAFEALLOC(cfg, GF_HEVCConfig);
830 if (!cfg) return NULL;
831 cfg->param_array = gf_list_new();
832 cfg->nal_unit_size = 4;
833 return cfg;
834 }
835
836 GF_EXPORT
gf_odf_hevc_cfg_del(GF_HEVCConfig * cfg)837 void gf_odf_hevc_cfg_del(GF_HEVCConfig *cfg)
838 {
839 if (!cfg) return;
840 while (gf_list_count(cfg->param_array)) {
841 GF_HEVCParamArray *pa = (GF_HEVCParamArray*)gf_list_get(cfg->param_array, 0);
842 gf_list_rem(cfg->param_array, 0);
843
844 while (gf_list_count(pa->nalus)) {
845 GF_AVCConfigSlot *n = (GF_AVCConfigSlot*)gf_list_get(pa->nalus, 0);
846 gf_list_rem(pa->nalus, 0);
847 if (n->data) gf_free(n->data);
848 gf_free(n);
849 }
850 gf_list_del(pa->nalus);
851 gf_free(pa);
852 }
853 gf_list_del(cfg->param_array);
854 gf_free(cfg);
855 }
856
857 GF_EXPORT
gf_odf_hevc_cfg_write_bs(GF_HEVCConfig * cfg,GF_BitStream * bs)858 GF_Err gf_odf_hevc_cfg_write_bs(GF_HEVCConfig *cfg, GF_BitStream *bs)
859 {
860 u32 i, count;
861
862 gf_bs_write_int(bs, cfg->configurationVersion, 8);
863
864 if (!cfg->is_lhvc) {
865 gf_bs_write_int(bs, cfg->profile_space, 2);
866 gf_bs_write_int(bs, cfg->tier_flag, 1);
867 gf_bs_write_int(bs, cfg->profile_idc, 5);
868 gf_bs_write_int(bs, cfg->general_profile_compatibility_flags, 32);
869 gf_bs_write_int(bs, cfg->progressive_source_flag, 1);
870 gf_bs_write_int(bs, cfg->interlaced_source_flag, 1);
871 gf_bs_write_int(bs, cfg->non_packed_constraint_flag, 1);
872 gf_bs_write_int(bs, cfg->frame_only_constraint_flag, 1);
873 /*only lowest 44 bits used*/
874 gf_bs_write_long_int(bs, cfg->constraint_indicator_flags, 44);
875 gf_bs_write_int(bs, cfg->level_idc, 8);
876 }
877
878 gf_bs_write_int(bs, 0xFF, 4);
879 gf_bs_write_int(bs, cfg->min_spatial_segmentation_idc, 12);
880
881 gf_bs_write_int(bs, 0xFF, 6);
882 gf_bs_write_int(bs, cfg->parallelismType, 2);
883
884 if (!cfg->is_lhvc) {
885 gf_bs_write_int(bs, 0xFF, 6);
886 gf_bs_write_int(bs, cfg->chromaFormat, 2);
887 gf_bs_write_int(bs, 0xFF, 5);
888 gf_bs_write_int(bs, cfg->luma_bit_depth - 8, 3);
889 gf_bs_write_int(bs, 0xFF, 5);
890 gf_bs_write_int(bs, cfg->chroma_bit_depth - 8, 3);
891 gf_bs_write_int(bs, cfg->avgFrameRate, 16);
892 }
893
894 if (!cfg->is_lhvc)
895 gf_bs_write_int(bs, cfg->constantFrameRate, 2);
896 else
897 gf_bs_write_int(bs, 0xFF, 2);
898
899 gf_bs_write_int(bs, cfg->numTemporalLayers, 3);
900 gf_bs_write_int(bs, cfg->temporalIdNested, 1);
901 gf_bs_write_int(bs, cfg->nal_unit_size - 1, 2);
902
903 count = gf_list_count(cfg->param_array);
904 gf_bs_write_int(bs, count, 8);
905 for (i = 0; i<count; i++) {
906 u32 nalucount, j;
907 GF_HEVCParamArray *ar = (GF_HEVCParamArray*)gf_list_get(cfg->param_array, i);
908 gf_bs_write_int(bs, ar->array_completeness, 1);
909 gf_bs_write_int(bs, 0, 1);
910 gf_bs_write_int(bs, ar->type, 6);
911 nalucount = gf_list_count(ar->nalus);
912 gf_bs_write_int(bs, nalucount, 16);
913 for (j = 0; j<nalucount; j++) {
914 GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)gf_list_get(ar->nalus, j);
915 gf_bs_write_int(bs, sl->size, 16);
916 gf_bs_write_data(bs, sl->data, sl->size);
917 }
918 }
919 return GF_OK;
920 }
921
922 GF_EXPORT
gf_odf_hevc_cfg_write(GF_HEVCConfig * cfg,char ** outData,u32 * outSize)923 GF_Err gf_odf_hevc_cfg_write(GF_HEVCConfig *cfg, char **outData, u32 *outSize)
924 {
925 GF_Err e;
926 GF_BitStream *bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
927 *outSize = 0;
928 *outData = NULL;
929 e = gf_odf_hevc_cfg_write_bs(cfg, bs);
930 if (e == GF_OK)
931 gf_bs_get_content(bs, outData, outSize);
932
933 gf_bs_del(bs);
934 return e;
935 }
936
937 GF_EXPORT
gf_odf_hevc_cfg_read_bs(GF_BitStream * bs,Bool is_lhvc)938 GF_HEVCConfig *gf_odf_hevc_cfg_read_bs(GF_BitStream *bs, Bool is_lhvc)
939 {
940 u32 i, count;
941 GF_HEVCConfig *cfg = gf_odf_hevc_cfg_new();
942
943 cfg->is_lhvc = is_lhvc;
944
945 cfg->configurationVersion = gf_bs_read_int(bs, 8);
946
947 if (!is_lhvc) {
948 cfg->profile_space = gf_bs_read_int(bs, 2);
949 cfg->tier_flag = gf_bs_read_int(bs, 1);
950 cfg->profile_idc = gf_bs_read_int(bs, 5);
951 cfg->general_profile_compatibility_flags = gf_bs_read_int(bs, 32);
952
953 cfg->progressive_source_flag = gf_bs_read_int(bs, 1);
954 cfg->interlaced_source_flag = gf_bs_read_int(bs, 1);
955 cfg->non_packed_constraint_flag = gf_bs_read_int(bs, 1);
956 cfg->frame_only_constraint_flag = gf_bs_read_int(bs, 1);
957 /*only lowest 44 bits used*/
958 cfg->constraint_indicator_flags = gf_bs_read_long_int(bs, 44);
959 cfg->level_idc = gf_bs_read_int(bs, 8);
960 }
961
962 gf_bs_read_int(bs, 4); //reserved
963 cfg->min_spatial_segmentation_idc = gf_bs_read_int(bs, 12);
964
965 gf_bs_read_int(bs, 6);//reserved
966 cfg->parallelismType = gf_bs_read_int(bs, 2);
967
968 if (!is_lhvc) {
969 gf_bs_read_int(bs, 6);
970 cfg->chromaFormat = gf_bs_read_int(bs, 2);
971 gf_bs_read_int(bs, 5);
972 cfg->luma_bit_depth = gf_bs_read_int(bs, 3) + 8;
973 gf_bs_read_int(bs, 5);
974 cfg->chroma_bit_depth = gf_bs_read_int(bs, 3) + 8;
975 cfg->avgFrameRate = gf_bs_read_int(bs, 16);
976 }
977
978 if (!is_lhvc)
979 cfg->constantFrameRate = gf_bs_read_int(bs, 2);
980 else
981 gf_bs_read_int(bs, 2); //reserved
982
983 cfg->numTemporalLayers = gf_bs_read_int(bs, 3);
984 cfg->temporalIdNested = gf_bs_read_int(bs, 1);
985
986 cfg->nal_unit_size = 1 + gf_bs_read_int(bs, 2);
987
988 count = gf_bs_read_int(bs, 8);
989 for (i = 0; i<count; i++) {
990 u32 nalucount, j;
991 GF_HEVCParamArray *ar;
992 GF_SAFEALLOC(ar, GF_HEVCParamArray);
993 if (!ar) {
994 gf_odf_hevc_cfg_del(cfg);
995 return NULL;
996 }
997 ar->nalus = gf_list_new();
998 gf_list_add(cfg->param_array, ar);
999
1000 ar->array_completeness = gf_bs_read_int(bs, 1);
1001 gf_bs_read_int(bs, 1);
1002 ar->type = gf_bs_read_int(bs, 6);
1003 nalucount = gf_bs_read_int(bs, 16);
1004 for (j = 0; j<nalucount; j++) {
1005 GF_AVCConfigSlot *sl;
1006 GF_SAFEALLOC(sl, GF_AVCConfigSlot);
1007 if (!sl) {
1008 gf_odf_hevc_cfg_del(cfg);
1009 return NULL;
1010 }
1011
1012 sl->size = gf_bs_read_int(bs, 16);
1013
1014 sl->data = (char *)gf_malloc(sizeof(char) * sl->size);
1015 gf_bs_read_data(bs, sl->data, sl->size);
1016 gf_list_add(ar->nalus, sl);
1017 }
1018 }
1019 return cfg;
1020 }
1021
1022 GF_EXPORT
gf_odf_hevc_cfg_read(char * dsi,u32 dsi_size,Bool is_lhvc)1023 GF_HEVCConfig *gf_odf_hevc_cfg_read(char *dsi, u32 dsi_size, Bool is_lhvc)
1024 {
1025 GF_BitStream *bs = gf_bs_new(dsi, dsi_size, GF_BITSTREAM_READ);
1026 GF_HEVCConfig *cfg = gf_odf_hevc_cfg_read_bs(bs, is_lhvc);
1027 gf_bs_del(bs);
1028 return cfg;
1029 }
1030
1031 GF_EXPORT
gf_afx_get_type_description(u8 afx_code)1032 const char *gf_afx_get_type_description(u8 afx_code)
1033 {
1034 switch (afx_code) {
1035 case GPAC_AFX_3DMC:
1036 return "AFX 3D Mesh Compression";
1037 case GPAC_AFX_WAVELET_SUBDIVISION:
1038 return "AFX Wavelet Subdivision Surface";
1039 case GPAC_AFX_MESHGRID:
1040 return "AFX Mesh Grid";
1041 case GPAC_AFX_COORDINATE_INTERPOLATOR:
1042 return "AFX Coordinate Interpolator";
1043 case GPAC_AFX_ORIENTATION_INTERPOLATOR:
1044 return "AFX Orientation Interpolator";
1045 case GPAC_AFX_POSITION_INTERPOLATOR:
1046 return "AFX Position Interpolator";
1047 case GPAC_AFX_OCTREE_IMAGE:
1048 return "AFX Octree Image";
1049 case GPAC_AFX_BBA:
1050 return "AFX BBA";
1051 case GPAC_AFX_POINT_TEXTURE:
1052 return "AFX Point Texture";
1053 case GPAC_AFX_3DMC_EXT:
1054 return "AFX 3D Mesh Compression Extension";
1055 case GPAC_AFX_FOOTPRINT:
1056 return "AFX FootPrint Representation";
1057 case GPAC_AFX_ANIMATED_MESH:
1058 return "AFX Animated Mesh Compression";
1059 case GPAC_AFX_SCALABLE_COMPLEXITY:
1060 return "AFX Scalable Complexity Representation";
1061 default:
1062 break;
1063 }
1064 return "AFX Unknown";
1065 }
1066
1067
1068 GF_EXPORT
gf_esd_get_textual_description(GF_ESD * esd)1069 const char *gf_esd_get_textual_description(GF_ESD *esd)
1070 {
1071 if (!esd || !esd->decoderConfig) return "Bad parameter";
1072
1073 switch (esd->decoderConfig->streamType) {
1074 case GF_STREAM_OD:
1075 return "MPEG-4 Object Descriptor";
1076 case GF_STREAM_OCR:
1077 return "MPEG-4 Object Clock Reference";
1078 case GF_STREAM_SCENE:
1079 switch (esd->decoderConfig->objectTypeIndication) {
1080 case 0x0:
1081 case 0x1:
1082 case 0x2:
1083 case 0x3:
1084 case 0xFF:
1085 return "MPEG-4 BIFS Scene Description";
1086 case GPAC_OTI_SCENE_BIFS_EXTENDED:
1087 return "MPEG-4 Extended BIFS Scene Description";
1088 case GPAC_OTI_SCENE_AFX:
1089 if (!esd->decoderConfig->decoderSpecificInfo || !esd->decoderConfig->decoderSpecificInfo->data)
1090 return "AFX Unknown";
1091 return gf_afx_get_type_description(esd->decoderConfig->decoderSpecificInfo->data[0]);
1092 case GPAC_OTI_SCENE_LASER:
1093 {
1094 GF_LASERConfig l_cfg;
1095 gf_odf_get_laser_config(esd->decoderConfig->decoderSpecificInfo, &l_cfg);
1096 if (!l_cfg.newSceneIndicator) return "LASeR Scene Segment Description";
1097 }
1098 return "LASeR Scene Description";
1099 case GPAC_OTI_SCENE_SYNTHESIZED_TEXTURE:
1100 return "MPEG-4 Synthesized Texture";
1101 case GPAC_OTI_SCENE_SAF:
1102 return "MPEG-4 SAF";
1103 case GPAC_OTI_3GPP2_CMF:
1104 return "3GPP2 CMF";
1105 default:
1106 return "Unknown Scene Type";
1107 }
1108 break;
1109 case GF_STREAM_VISUAL:
1110 switch (esd->decoderConfig->objectTypeIndication) {
1111 case GPAC_OTI_VIDEO_MPEG2_SIMPLE:
1112 return "MPEG-2 Visual Simple Profile";
1113 case GPAC_OTI_VIDEO_MPEG2_MAIN:
1114 return "MPEG-2 Visual Main Profile";
1115 case GPAC_OTI_VIDEO_MPEG2_SNR:
1116 return "MPEG-2 Visual SNR Profile";
1117 case GPAC_OTI_VIDEO_MPEG2_SPATIAL:
1118 return "MPEG-2 Visual SNR Profile";
1119 case GPAC_OTI_VIDEO_MPEG2_HIGH:
1120 return "MPEG-2 Visual SNR Profile";
1121 case GPAC_OTI_VIDEO_MPEG2_422:
1122 return "MPEG-2 Visual SNR Profile";
1123 case GPAC_OTI_VIDEO_MPEG1:
1124 return "MPEG-1 Video";
1125 case GPAC_OTI_IMAGE_JPEG:
1126 return "JPEG Image";
1127 case GPAC_OTI_IMAGE_PNG:
1128 return "PNG Image";
1129 case GPAC_OTI_IMAGE_JPEG_2000:
1130 return "JPEG2000 Image";
1131 case GPAC_OTI_VIDEO_MPEG4_PART2:
1132 return "MPEG-4 Part 2 Video";
1133 case GPAC_OTI_VIDEO_AVC:
1134 return "MPEG-4 AVC|H264 Video";
1135 case GPAC_OTI_VIDEO_SVC:
1136 return "MPEG-4 SVC Video";
1137 case GPAC_OTI_VIDEO_AVC_PS:
1138 return "MPEG-4 AVC|H264 Parameter Set";
1139 case GPAC_OTI_VIDEO_HEVC:
1140 return "MPEG-H HEVC Video";
1141 case GPAC_OTI_VIDEO_LHVC:
1142 return "MPEG-H L-HEVC Video";
1143 case GPAC_OTI_MEDIA_FFMPEG:
1144 return "GPAC FFMPEG Private Video";
1145 case GPAC_OTI_VIDEO_SMPTE_VC1:
1146 return "SMPTE VC-1 Video";
1147 case GPAC_OTI_VIDEO_DIRAC:
1148 return "Dirac Video";
1149 default:
1150 return "Unknown Video type";
1151 }
1152 break;
1153 case GF_STREAM_AUDIO:
1154 switch (esd->decoderConfig->objectTypeIndication) {
1155 case GPAC_OTI_AUDIO_AAC_MPEG2_MP:
1156 return "MPEG-2 AAC Main Profile";
1157 case GPAC_OTI_AUDIO_AAC_MPEG2_LCP:
1158 return "MPEG-2 AAC Low Complexity Profile";
1159 case GPAC_OTI_AUDIO_AAC_MPEG2_SSRP:
1160 return "MPEG-2 AAC Scaleable Sampling Rate Profile";
1161 case GPAC_OTI_AUDIO_MPEG2_PART3:
1162 return "MPEG-2 Audio Part 3";
1163 case GPAC_OTI_AUDIO_MPEG1:
1164 return "MPEG-1 Audio";
1165 case GPAC_OTI_AUDIO_AAC_MPEG4:
1166 {
1167 #ifdef GPAC_DISABLE_AV_PARSERS
1168 return "MPEG-4 AAC";
1169 #else
1170 GF_M4ADecSpecInfo a_cfg;
1171 if (!esd->decoderConfig->decoderSpecificInfo) return "MPEG-4 AAC";
1172 gf_m4a_get_config(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength, &a_cfg);
1173 return gf_m4a_object_type_name(a_cfg.base_object_type);
1174 #endif
1175 }
1176 break;
1177 case GPAC_OTI_MEDIA_FFMPEG:
1178 return "GPAC FFMPEG Private Audio";
1179 case GPAC_OTI_AUDIO_EVRC_VOICE:
1180 return "EVRC Voice";
1181 case GPAC_OTI_AUDIO_SMV_VOICE:
1182 return "SMV Voice";
1183 case GPAC_OTI_AUDIO_AC3:
1184 return "AC-3 audio";
1185 case GPAC_OTI_AUDIO_EAC3:
1186 return "Enhanced AC-3 Audio";
1187 case GPAC_OTI_AUDIO_DRA:
1188 return "DRA Audio";
1189 case GPAC_OTI_AUDIO_ITU_G719:
1190 return "ITU G719 Audio";
1191 case GPAC_OTI_AUDIO_DTS_CA:
1192 return "DTS Coherent Acoustics audio";
1193 case GPAC_OTI_AUDIO_DTS_HD_HR:
1194 return "DTS-HD High Resolution audio";
1195 case GPAC_OTI_AUDIO_DTS_HD_MASTER:
1196 return "DTS-HD Master audios";
1197 default:
1198 return "Unknown Audio Type";
1199 }
1200 break;
1201 case GF_STREAM_MPEG7:
1202 return "MPEG-7 Description";
1203 case GF_STREAM_IPMP:
1204 return "MPEG-4 IPMP";
1205 case GF_STREAM_OCI:
1206 return "MPEG-4 OCI";
1207 case GF_STREAM_MPEGJ:
1208 return "MPEG-4 MPEG-J";
1209 case GF_STREAM_INTERACT:
1210 return "MPEG-4 User Interaction";
1211 case GF_STREAM_IPMP_TOOL:
1212 return "MPEG-4 IPMP Tool";
1213 case GF_STREAM_FONT:
1214 return "MPEG-4 Font Data";
1215 case GF_STREAM_TEXT:
1216 return "MPEG-4 Streaming Text";
1217 case GF_STREAM_ND_SUBPIC:
1218 return "Nero Digital Subpicture";
1219
1220 case GF_STREAM_PRIVATE_SCENE:
1221 switch (esd->decoderConfig->objectTypeIndication) {
1222 case GPAC_OTI_PRIVATE_SCENE_GENERIC:
1223 {
1224 char *ext = strchr(esd->decoderConfig->decoderSpecificInfo->data + 4, '.');
1225 if (!ext) return "GPAC Internal Scene Description";
1226 ext += 1;
1227 if (!strnicmp(ext, "bt", 2))
1228 return "BT Scene Description";
1229 if (!strnicmp(ext, "xmt", 2))
1230 return "XMT Scene Description";
1231 if (!strnicmp(ext, "wrl", 3))
1232 return "VRML Scene Description";
1233 if (!strnicmp(ext, "x3d", 3))
1234 return "W3D Scene Description";
1235 if (!strnicmp(ext, "x3dv", 4))
1236 return "X3D Scene Description";
1237 if (!strnicmp(ext, "swf", 3))
1238 return "Flash (SWF) Scene Description";
1239 if (!strnicmp(ext, "xsr", 3))
1240 return "LASeR-ML Scene Description";
1241 if (!strnicmp(ext, "wgt", 3))
1242 return "W3C Widget Package";
1243 if (!strnicmp(ext, "mgt", 3))
1244 return "MPEG-U Widget Package";
1245 }
1246 return "GPAC Internal Scene Description";
1247 case GPAC_OTI_PRIVATE_SCENE_SVG:
1248 return "SVG";
1249 case GPAC_OTI_PRIVATE_SCENE_LASER:
1250 return "LASeR (XML)";
1251 case GPAC_OTI_PRIVATE_SCENE_XBL:
1252 return "XBL";
1253 case GPAC_OTI_PRIVATE_SCENE_EPG:
1254 return "DVB Event Information";
1255 case GPAC_OTI_PRIVATE_SCENE_WGT:
1256 return "W3C/MPEG-U Widget";
1257 case GPAC_OTI_SCENE_SVG:
1258 return "SVG over RTP";
1259 case GPAC_OTI_SCENE_SVG_GZ:
1260 return "SVG+gz over RTP";
1261 case GPAC_OTI_SCENE_DIMS:
1262 return "3GPP DIMS";
1263 default:
1264 return "Unknown Scene Description";
1265 }
1266 break;
1267 case GF_STREAM_PRIVATE_MEDIA:
1268 return "Opaque Decoder";
1269 case GF_STREAM_4CC:
1270 return gf_4cc_to_str(esd->decoderConfig->objectTypeIndication);
1271 default:
1272 return "Unknown Media Type";
1273 }
1274 }
1275