1 /*
2 * GPAC - Multimedia Framework C SDK
3 *
4 * Authors: Jean Le Feuvre
5 * Copyright (c) Telecom ParisTech 2000-2019
6 * All rights reserved
7 *
8 * This file is part of GPAC / ISO Media File Format 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/isomedia_dev.h>
27 #include <gpac/tools.h>
28
29 #ifndef GPAC_DISABLE_ISOM
30
31
32
gppc_box_new()33 GF_Box *gppc_box_new()
34 {
35 //default type is amr but overwritten by box constructor
36 ISOM_DECL_BOX_ALLOC(GF_3GPPConfigBox, GF_ISOM_BOX_TYPE_DAMR);
37 return (GF_Box *)tmp;
38 }
39
gppc_box_del(GF_Box * s)40 void gppc_box_del(GF_Box *s)
41 {
42 GF_3GPPConfigBox *ptr = (GF_3GPPConfigBox *)s;
43 if (ptr == NULL) return;
44 gf_free(ptr);
45 }
46
47
gppc_box_read(GF_Box * s,GF_BitStream * bs)48 GF_Err gppc_box_read(GF_Box *s, GF_BitStream *bs)
49 {
50 GF_3GPPConfigBox *ptr = (GF_3GPPConfigBox *)s;
51 if (ptr == NULL) return GF_BAD_PARAM;
52 memset(&ptr->cfg, 0, sizeof(GF_3GPConfig));
53
54 ISOM_DECREASE_SIZE(s, 5)
55 ptr->cfg.vendor = gf_bs_read_u32(bs);
56 ptr->cfg.decoder_version = gf_bs_read_u8(bs);
57
58 switch (ptr->type) {
59 case GF_ISOM_BOX_TYPE_D263:
60 ISOM_DECREASE_SIZE(s, 2)
61 ptr->cfg.H263_level = gf_bs_read_u8(bs);
62 ptr->cfg.H263_profile = gf_bs_read_u8(bs);
63 break;
64 case GF_ISOM_BOX_TYPE_DAMR:
65 ISOM_DECREASE_SIZE(s, 4)
66 ptr->cfg.AMR_mode_set = gf_bs_read_u16(bs);
67 ptr->cfg.AMR_mode_change_period = gf_bs_read_u8(bs);
68 ptr->cfg.frames_per_sample = gf_bs_read_u8(bs);
69 break;
70 case GF_ISOM_BOX_TYPE_DEVC:
71 case GF_ISOM_BOX_TYPE_DQCP:
72 case GF_ISOM_BOX_TYPE_DSMV:
73 ISOM_DECREASE_SIZE(s, 1)
74 ptr->cfg.frames_per_sample = gf_bs_read_u8(bs);
75 break;
76 }
77 return GF_OK;
78 }
79
80 #ifndef GPAC_DISABLE_ISOM_WRITE
81
gppc_box_write(GF_Box * s,GF_BitStream * bs)82 GF_Err gppc_box_write(GF_Box *s, GF_BitStream *bs)
83 {
84 GF_Err e;
85 GF_3GPPConfigBox *ptr = (GF_3GPPConfigBox *)s;
86 e = gf_isom_box_write_header(s, bs);
87 if (e) return e;
88
89 gf_bs_write_u32(bs, ptr->cfg.vendor);
90 gf_bs_write_u8(bs, ptr->cfg.decoder_version);
91 switch (ptr->cfg.type) {
92 case GF_ISOM_SUBTYPE_3GP_H263:
93 gf_bs_write_u8(bs, ptr->cfg.H263_level);
94 gf_bs_write_u8(bs, ptr->cfg.H263_profile);
95 break;
96 case GF_ISOM_SUBTYPE_3GP_AMR:
97 case GF_ISOM_SUBTYPE_3GP_AMR_WB:
98 gf_bs_write_u16(bs, ptr->cfg.AMR_mode_set);
99 gf_bs_write_u8(bs, ptr->cfg.AMR_mode_change_period);
100 gf_bs_write_u8(bs, ptr->cfg.frames_per_sample);
101 break;
102 case GF_ISOM_SUBTYPE_3GP_EVRC:
103 case GF_ISOM_SUBTYPE_3GP_QCELP:
104 case GF_ISOM_SUBTYPE_3GP_SMV:
105 gf_bs_write_u8(bs, ptr->cfg.frames_per_sample);
106 break;
107 }
108 return GF_OK;
109 }
110
gppc_box_size(GF_Box * s)111 GF_Err gppc_box_size(GF_Box *s)
112 {
113 GF_3GPPConfigBox *ptr = (GF_3GPPConfigBox *)s;
114
115 s->size += 5;
116 if (!ptr->cfg.type) {
117 switch (ptr->type) {
118 case GF_ISOM_BOX_TYPE_D263:
119 ptr->cfg.type = GF_ISOM_SUBTYPE_3GP_H263;
120 break;
121 case GF_ISOM_BOX_TYPE_DAMR:
122 ptr->cfg.type = GF_ISOM_SUBTYPE_3GP_AMR;
123 break;
124 case GF_ISOM_BOX_TYPE_DEVC:
125 ptr->cfg.type = GF_ISOM_SUBTYPE_3GP_EVRC;
126 break;
127 case GF_ISOM_BOX_TYPE_DQCP:
128 ptr->cfg.type = GF_ISOM_SUBTYPE_3GP_QCELP;
129 break;
130 case GF_ISOM_BOX_TYPE_DSMV:
131 ptr->cfg.type = GF_ISOM_SUBTYPE_3GP_SMV;
132 break;
133 }
134 }
135 switch (ptr->cfg.type) {
136 case GF_ISOM_SUBTYPE_3GP_H263:
137 s->size += 2;
138 break;
139 case GF_ISOM_SUBTYPE_3GP_AMR:
140 case GF_ISOM_SUBTYPE_3GP_AMR_WB:
141 s->size += 4;
142 break;
143 case GF_ISOM_SUBTYPE_3GP_EVRC:
144 case GF_ISOM_SUBTYPE_3GP_QCELP:
145 case GF_ISOM_SUBTYPE_3GP_SMV:
146 s->size += 1;
147 break;
148 }
149 return GF_OK;
150 }
151
152 #endif /*GPAC_DISABLE_ISOM_WRITE*/
153
154
ftab_box_new()155 GF_Box *ftab_box_new()
156 {
157 ISOM_DECL_BOX_ALLOC(GF_FontTableBox, GF_ISOM_BOX_TYPE_FTAB);
158 return (GF_Box *) tmp;
159 }
ftab_box_del(GF_Box * s)160 void ftab_box_del(GF_Box *s)
161 {
162 GF_FontTableBox *ptr = (GF_FontTableBox *)s;
163 if (ptr->fonts) {
164 u32 i;
165 for (i=0; i<ptr->entry_count; i++)
166 if (ptr->fonts[i].fontName) gf_free(ptr->fonts[i].fontName);
167 gf_free(ptr->fonts);
168 }
169 gf_free(ptr);
170 }
ftab_box_read(GF_Box * s,GF_BitStream * bs)171 GF_Err ftab_box_read(GF_Box *s, GF_BitStream *bs)
172 {
173 u32 i;
174 GF_FontTableBox *ptr = (GF_FontTableBox *)s;
175 ptr->entry_count = gf_bs_read_u16(bs);
176 ISOM_DECREASE_SIZE(ptr, 2);
177
178 if (ptr->size<ptr->entry_count*3) {
179 GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("[iso file] Corrupted ftap box, skipping\n"));
180 ptr->entry_count = 0;
181 return GF_OK;
182 }
183 ptr->fonts = (GF_FontRecord *) gf_malloc(sizeof(GF_FontRecord)*ptr->entry_count);
184 if (!ptr->fonts) return GF_OUT_OF_MEM;
185
186 memset(ptr->fonts, 0, sizeof(GF_FontRecord)*ptr->entry_count);
187 for (i=0; i<ptr->entry_count; i++) {
188 u32 len;
189 ISOM_DECREASE_SIZE(ptr, 3);
190 ptr->fonts[i].fontID = gf_bs_read_u16(bs);
191 len = gf_bs_read_u8(bs);
192 if (len) {
193 ISOM_DECREASE_SIZE(ptr, len);
194 ptr->fonts[i].fontName = (char *)gf_malloc(sizeof(char)*(len+1));
195 if (!ptr->fonts[i].fontName) return GF_OUT_OF_MEM;
196 gf_bs_read_data(bs, ptr->fonts[i].fontName, len);
197 ptr->fonts[i].fontName[len] = 0;
198 }
199 }
200 return GF_OK;
201 }
202
203 #ifndef GPAC_DISABLE_ISOM_WRITE
ftab_box_write(GF_Box * s,GF_BitStream * bs)204 GF_Err ftab_box_write(GF_Box *s, GF_BitStream *bs)
205 {
206 GF_Err e;
207 u32 i;
208 GF_FontTableBox *ptr = (GF_FontTableBox *)s;
209 e = gf_isom_box_write_header(s, bs);
210 if (e) return e;
211 gf_bs_write_u16(bs, ptr->entry_count);
212 for (i=0; i<ptr->entry_count; i++) {
213 gf_bs_write_u16(bs, ptr->fonts[i].fontID);
214 if (ptr->fonts[i].fontName) {
215 u32 len = (u32) strlen(ptr->fonts[i].fontName);
216 gf_bs_write_u8(bs, len);
217 gf_bs_write_data(bs, ptr->fonts[i].fontName, len);
218 } else {
219 gf_bs_write_u8(bs, 0);
220 }
221 }
222 return GF_OK;
223 }
ftab_box_size(GF_Box * s)224 GF_Err ftab_box_size(GF_Box *s)
225 {
226 u32 i;
227 GF_FontTableBox *ptr = (GF_FontTableBox *)s;
228
229 s->size += 2;
230 for (i=0; i<ptr->entry_count; i++) {
231 s->size += 3;
232 if (ptr->fonts[i].fontName) s->size += strlen(ptr->fonts[i].fontName);
233 }
234 return GF_OK;
235 }
236
237 #endif /*GPAC_DISABLE_ISOM_WRITE*/
238
239
240
text_box_new()241 GF_Box *text_box_new()
242 {
243 ISOM_DECL_BOX_ALLOC(GF_TextSampleEntryBox, GF_ISOM_BOX_TYPE_TEXT);
244 return (GF_Box *) tmp;
245 }
246
text_box_del(GF_Box * s)247 void text_box_del(GF_Box *s)
248 {
249 GF_TextSampleEntryBox *ptr = (GF_TextSampleEntryBox*)s;
250 gf_isom_sample_entry_predestroy((GF_SampleEntryBox *)s);
251
252 if (ptr->textName)
253 gf_free(ptr->textName);
254 gf_free(ptr);
255 }
256
tx3g_box_new()257 GF_Box *tx3g_box_new()
258 {
259 ISOM_DECL_BOX_ALLOC(GF_Tx3gSampleEntryBox, GF_ISOM_BOX_TYPE_TX3G);
260 return (GF_Box *) tmp;
261 }
262
tx3g_box_del(GF_Box * s)263 void tx3g_box_del(GF_Box *s)
264 {
265 gf_isom_sample_entry_predestroy((GF_SampleEntryBox *)s);
266 gf_free(s);
267 }
268
gpp_read_rgba(GF_BitStream * bs)269 u32 gpp_read_rgba(GF_BitStream *bs)
270 {
271 u8 r, g, b, a;
272 u32 col;
273 r = gf_bs_read_u8(bs);
274 g = gf_bs_read_u8(bs);
275 b = gf_bs_read_u8(bs);
276 a = gf_bs_read_u8(bs);
277 col = a;
278 col<<=8;
279 col |= r;
280 col<<=8;
281 col |= g;
282 col<<=8;
283 col |= b;
284 return col;
285 }
286
287 #define GPP_BOX_SIZE 8
gpp_read_box(GF_BitStream * bs,GF_BoxRecord * rec)288 void gpp_read_box(GF_BitStream *bs, GF_BoxRecord *rec)
289 {
290 rec->top = gf_bs_read_u16(bs);
291 rec->left = gf_bs_read_u16(bs);
292 rec->bottom = gf_bs_read_u16(bs);
293 rec->right = gf_bs_read_u16(bs);
294 }
295
296 #define GPP_STYLE_SIZE 12
gpp_read_style(GF_BitStream * bs,GF_StyleRecord * rec)297 void gpp_read_style(GF_BitStream *bs, GF_StyleRecord *rec)
298 {
299 rec->startCharOffset = gf_bs_read_u16(bs);
300 rec->endCharOffset = gf_bs_read_u16(bs);
301 rec->fontID = gf_bs_read_u16(bs);
302 rec->style_flags = gf_bs_read_u8(bs);
303 rec->font_size = gf_bs_read_u8(bs);
304 rec->text_color = gpp_read_rgba(bs);
305 }
306
tx3g_on_child_box(GF_Box * s,GF_Box * a)307 GF_Err tx3g_on_child_box(GF_Box *s, GF_Box *a)
308 {
309 GF_Tx3gSampleEntryBox *ptr = (GF_Tx3gSampleEntryBox*)s;
310 switch (a->type) {
311 case GF_ISOM_BOX_TYPE_FTAB:
312 if (ptr->font_table) ERROR_ON_DUPLICATED_BOX(a, ptr)
313 ptr->font_table = (GF_FontTableBox *)a;
314 break;
315 default:
316 return GF_OK;
317 }
318 return GF_OK;
319 }
320
tx3g_box_read(GF_Box * s,GF_BitStream * bs)321 GF_Err tx3g_box_read(GF_Box *s, GF_BitStream *bs)
322 {
323 GF_Err e;
324 GF_Tx3gSampleEntryBox *ptr = (GF_Tx3gSampleEntryBox*)s;
325
326 ISOM_DECREASE_SIZE(ptr, (18 + GPP_BOX_SIZE + GPP_STYLE_SIZE) );
327
328 e = gf_isom_base_sample_entry_read((GF_SampleEntryBox *)ptr, bs);
329 if (e) return e;
330
331 ptr->displayFlags = gf_bs_read_u32(bs);
332 ptr->horizontal_justification = gf_bs_read_u8(bs);
333 ptr->vertical_justification = gf_bs_read_u8(bs);
334 ptr->back_color = gpp_read_rgba(bs);
335 gpp_read_box(bs, &ptr->default_box);
336 gpp_read_style(bs, &ptr->default_style);
337
338
339 return gf_isom_box_array_read(s, bs, tx3g_on_child_box);
340 }
341
342 /*this is a quicktime specific box - see apple documentation*/
text_box_read(GF_Box * s,GF_BitStream * bs)343 GF_Err text_box_read(GF_Box *s, GF_BitStream *bs)
344 {
345 GF_Err e;
346 u16 pSize;
347 GF_TextSampleEntryBox *ptr = (GF_TextSampleEntryBox*)s;
348
349 ISOM_DECREASE_SIZE(ptr, 51);
350
351 e = gf_isom_base_sample_entry_read((GF_SampleEntryBox *)ptr, bs);
352 if (e) return e;
353
354 ptr->displayFlags = gf_bs_read_u32(bs); /*Display flags*/
355 ptr->textJustification = gf_bs_read_u32(bs); /*Text justification*/
356 gf_bs_read_data(bs, ptr->background_color, 6); /*Background color*/
357 gpp_read_box(bs, &ptr->default_box); /*Default text box*/
358 gf_bs_read_data(bs, ptr->reserved1, 8); /*Reserved*/
359 ptr->fontNumber = gf_bs_read_u16(bs); /*Font number*/
360 ptr->fontFace = gf_bs_read_u16(bs); /*Font face*/
361 ptr->reserved2 = gf_bs_read_u8(bs); /*Reserved*/
362 ptr->reserved3 = gf_bs_read_u16(bs); /*Reserved*/
363 gf_bs_read_data(bs, ptr->foreground_color, 6); /*Foreground color*/
364
365 /*ffmpeg compatibility with iPod streams: no pascal string*/
366 if (!ptr->size)
367 return GF_OK;
368
369 ISOM_DECREASE_SIZE(ptr, 1);
370 pSize = gf_bs_read_u8(bs); /*a Pascal string begins with its size: get textName size*/
371
372 if (ptr->size < pSize) {
373 u32 b_size = pSize;
374 size_t i = 0;
375 GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[iso file] text box doesn't use a Pascal string: trying to decode anyway.\n"));
376 ptr->textName = (char*)gf_malloc((size_t)ptr->size + 1 + 1);
377 if (!ptr->textName) return GF_OUT_OF_MEM;
378
379 do {
380 char c = (char)b_size;
381 if (c == '\0') {
382 break;
383 } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
384 ptr->textName[i] = c;
385 } else {
386 gf_free(ptr->textName);
387 ptr->textName = NULL;
388 GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("[iso file] text box doesn't use a Pascal string and contains non-chars. Abort.\n"));
389 return GF_ISOM_INVALID_FILE;
390 }
391 i++;
392 if (!ptr->size)
393 break;
394 ptr->size--;
395 b_size = gf_bs_read_u8(bs);
396 } while (b_size);
397
398 ptr->textName[i] = '\0'; /*Font name*/
399 GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("[iso file] text box doesn't use a Pascal string: \"%s\" detected.\n", ptr->textName));
400 return GF_OK;
401 }
402 if (pSize) {
403 ptr->textName = (char*) gf_malloc(pSize+1 * sizeof(char));
404 if (!ptr->textName) return GF_OUT_OF_MEM;
405
406 if (gf_bs_read_data(bs, ptr->textName, pSize) != pSize) {
407 gf_free(ptr->textName);
408 ptr->textName = NULL;
409 return GF_ISOM_INVALID_FILE;
410 }
411 ptr->textName[pSize] = '\0'; /*Font name*/
412 }
413 ISOM_DECREASE_SIZE(ptr, pSize);
414 return gf_isom_box_array_read(s, bs, NULL);
415 }
416
gpp_write_rgba(GF_BitStream * bs,u32 col)417 void gpp_write_rgba(GF_BitStream *bs, u32 col)
418 {
419 gf_bs_write_u8(bs, (col>>16) & 0xFF);
420 gf_bs_write_u8(bs, (col>>8) & 0xFF);
421 gf_bs_write_u8(bs, (col) & 0xFF);
422 gf_bs_write_u8(bs, (col>>24) & 0xFF);
423 }
424
gpp_write_box(GF_BitStream * bs,GF_BoxRecord * rec)425 void gpp_write_box(GF_BitStream *bs, GF_BoxRecord *rec)
426 {
427 gf_bs_write_u16(bs, rec->top);
428 gf_bs_write_u16(bs, rec->left);
429 gf_bs_write_u16(bs, rec->bottom);
430 gf_bs_write_u16(bs, rec->right);
431 }
432
433 #define GPP_STYLE_SIZE 12
gpp_write_style(GF_BitStream * bs,GF_StyleRecord * rec)434 void gpp_write_style(GF_BitStream *bs, GF_StyleRecord *rec)
435 {
436 gf_bs_write_u16(bs, rec->startCharOffset);
437 gf_bs_write_u16(bs, rec->endCharOffset);
438 gf_bs_write_u16(bs, rec->fontID);
439 gf_bs_write_u8(bs, rec->style_flags);
440 gf_bs_write_u8(bs, rec->font_size);
441 gpp_write_rgba(bs, rec->text_color);
442 }
443
444 #ifndef GPAC_DISABLE_ISOM_WRITE
445
tx3g_box_write(GF_Box * s,GF_BitStream * bs)446 GF_Err tx3g_box_write(GF_Box *s, GF_BitStream *bs)
447 {
448 GF_Err e;
449 GF_Tx3gSampleEntryBox *ptr = (GF_Tx3gSampleEntryBox*)s;
450
451 e = gf_isom_box_write_header(s, bs);
452 if (e) return e;
453 gf_bs_write_data(bs, ptr->reserved, 6);
454 gf_bs_write_u16(bs, ptr->dataReferenceIndex);
455 gf_bs_write_u32(bs, ptr->displayFlags);
456 gf_bs_write_u8(bs, ptr->horizontal_justification);
457 gf_bs_write_u8(bs, ptr->vertical_justification);
458 gpp_write_rgba(bs, ptr->back_color);
459 gpp_write_box(bs, &ptr->default_box);
460 gpp_write_style(bs, &ptr->default_style);
461 return GF_OK;
462 }
463
text_box_write(GF_Box * s,GF_BitStream * bs)464 GF_Err text_box_write(GF_Box *s, GF_BitStream *bs)
465 {
466 GF_Err e;
467 u16 pSize;
468 GF_TextSampleEntryBox *ptr = (GF_TextSampleEntryBox*)s;
469
470 e = gf_isom_box_write_header(s, bs);
471 if (e) return e;
472 gf_bs_write_data(bs, ptr->reserved, 6);
473 gf_bs_write_u16(bs, ptr->dataReferenceIndex);
474 gf_bs_write_u32(bs, ptr->displayFlags); /*Display flags*/
475 gf_bs_write_u32(bs, ptr->textJustification); /*Text justification*/
476 gf_bs_write_data(bs, ptr->background_color, 6); /*Background color*/
477 gpp_write_box(bs, &ptr->default_box); /*Default text box*/
478 gf_bs_write_data(bs, ptr->reserved1, 8); /*Reserved*/
479 gf_bs_write_u16(bs, ptr->fontNumber); /*Font number*/
480 gf_bs_write_u16(bs, ptr->fontFace); /*Font face*/
481 gf_bs_write_u8(bs, ptr->reserved2); /*Reserved*/
482 gf_bs_write_u16(bs, ptr->reserved3); /*Reserved*/
483 gf_bs_write_data(bs, ptr->foreground_color, 6); /*Foreground color*/
484 //pSize assignment below is not a mistake
485 if (ptr->textName && (pSize = (u16) strlen(ptr->textName))) {
486 gf_bs_write_u8(bs, pSize); /*a Pascal string begins with its size*/
487 gf_bs_write_data(bs, ptr->textName, pSize); /*Font name*/
488 } else {
489 gf_bs_write_u8(bs, 0);
490 }
491 return GF_OK;
492 }
493
tx3g_box_size(GF_Box * s)494 GF_Err tx3g_box_size(GF_Box *s)
495 {
496 /*base + this + box + style*/
497 s->size += 18 + GPP_BOX_SIZE + GPP_STYLE_SIZE;
498 return GF_OK;
499 }
500
text_box_size(GF_Box * s)501 GF_Err text_box_size(GF_Box *s)
502 {
503 GF_TextSampleEntryBox *ptr = (GF_TextSampleEntryBox*)s;
504
505 /*base + this + string length*/
506 s->size += 51 + 1;
507 if (ptr->textName)
508 s->size += strlen(ptr->textName);
509 return GF_OK;
510 }
511
512 #endif
513
styl_box_new()514 GF_Box *styl_box_new()
515 {
516 ISOM_DECL_BOX_ALLOC(GF_TextStyleBox, GF_ISOM_BOX_TYPE_STYL);
517 return (GF_Box *) tmp;
518 }
519
styl_box_del(GF_Box * s)520 void styl_box_del(GF_Box *s)
521 {
522 GF_TextStyleBox*ptr = (GF_TextStyleBox*)s;
523 if (ptr->styles) gf_free(ptr->styles);
524 gf_free(ptr);
525 }
526
styl_box_read(GF_Box * s,GF_BitStream * bs)527 GF_Err styl_box_read(GF_Box *s, GF_BitStream *bs)
528 {
529 u32 i;
530 GF_TextStyleBox*ptr = (GF_TextStyleBox*)s;
531 ISOM_DECREASE_SIZE(ptr, 2);
532 ptr->entry_count = gf_bs_read_u16(bs);
533
534 if (ptr->size<ptr->entry_count * GPP_STYLE_SIZE)
535 return GF_ISOM_INVALID_FILE;
536
537 if (ptr->entry_count) {
538 ptr->styles = (GF_StyleRecord*)gf_malloc(sizeof(GF_StyleRecord)*ptr->entry_count);
539 if (!ptr->styles) return GF_OUT_OF_MEM;
540 for (i=0; i<ptr->entry_count; i++) {
541 ISOM_DECREASE_SIZE(ptr, GPP_STYLE_SIZE);
542 gpp_read_style(bs, &ptr->styles[i]);
543 }
544 }
545 return GF_OK;
546 }
547
548 #ifndef GPAC_DISABLE_ISOM_WRITE
styl_box_write(GF_Box * s,GF_BitStream * bs)549 GF_Err styl_box_write(GF_Box *s, GF_BitStream *bs)
550 {
551 GF_Err e;
552 u32 i;
553 GF_TextStyleBox*ptr = (GF_TextStyleBox*)s;
554 e = gf_isom_box_write_header(s, bs);
555 if (e) return e;
556
557 gf_bs_write_u16(bs, ptr->entry_count);
558 for (i=0; i<ptr->entry_count; i++) gpp_write_style(bs, &ptr->styles[i]);
559 return GF_OK;
560 }
561
styl_box_size(GF_Box * s)562 GF_Err styl_box_size(GF_Box *s)
563 {
564 GF_TextStyleBox*ptr = (GF_TextStyleBox*)s;
565
566 s->size += 2 + ptr->entry_count * GPP_STYLE_SIZE;
567 return GF_OK;
568 }
569
570 #endif /*GPAC_DISABLE_ISOM_WRITE*/
571
hlit_box_new()572 GF_Box *hlit_box_new()
573 {
574 ISOM_DECL_BOX_ALLOC(GF_TextHighlightBox, GF_ISOM_BOX_TYPE_HLIT);
575 return (GF_Box *) tmp;
576 }
577
hlit_box_del(GF_Box * s)578 void hlit_box_del(GF_Box *s)
579 {
580 gf_free(s);
581 }
582
hlit_box_read(GF_Box * s,GF_BitStream * bs)583 GF_Err hlit_box_read(GF_Box *s, GF_BitStream *bs)
584 {
585 GF_TextHighlightBox *ptr = (GF_TextHighlightBox *)s;
586 ISOM_DECREASE_SIZE(ptr, 4)
587 ptr->startcharoffset = gf_bs_read_u16(bs);
588 ptr->endcharoffset = gf_bs_read_u16(bs);
589 return GF_OK;
590 }
591
592 #ifndef GPAC_DISABLE_ISOM_WRITE
hlit_box_write(GF_Box * s,GF_BitStream * bs)593 GF_Err hlit_box_write(GF_Box *s, GF_BitStream *bs)
594 {
595 GF_Err e;
596 GF_TextHighlightBox *ptr = (GF_TextHighlightBox *)s;
597 e = gf_isom_box_write_header(s, bs);
598 if (e) return e;
599 gf_bs_write_u16(bs, ptr->startcharoffset);
600 gf_bs_write_u16(bs, ptr->endcharoffset);
601 return GF_OK;
602 }
603
hlit_box_size(GF_Box * s)604 GF_Err hlit_box_size(GF_Box *s)
605 {
606 s->size += 4;
607 return GF_OK;
608 }
609
610 #endif /*GPAC_DISABLE_ISOM_WRITE*/
611
hclr_box_new()612 GF_Box *hclr_box_new()
613 {
614 ISOM_DECL_BOX_ALLOC(GF_TextHighlightColorBox, GF_ISOM_BOX_TYPE_HCLR);
615 return (GF_Box *) tmp;
616 }
617
hclr_box_del(GF_Box * s)618 void hclr_box_del(GF_Box *s)
619 {
620 gf_free(s);
621 }
622
hclr_box_read(GF_Box * s,GF_BitStream * bs)623 GF_Err hclr_box_read(GF_Box *s, GF_BitStream *bs)
624 {
625 GF_TextHighlightColorBox*ptr = (GF_TextHighlightColorBox*)s;
626 ISOM_DECREASE_SIZE(ptr, 4)
627 ptr->hil_color = gpp_read_rgba(bs);
628 return GF_OK;
629 }
630
631 #ifndef GPAC_DISABLE_ISOM_WRITE
hclr_box_write(GF_Box * s,GF_BitStream * bs)632 GF_Err hclr_box_write(GF_Box *s, GF_BitStream *bs)
633 {
634 GF_Err e;
635 GF_TextHighlightColorBox*ptr = (GF_TextHighlightColorBox*)s;
636 e = gf_isom_box_write_header(s, bs);
637 if (e) return e;
638 gpp_write_rgba(bs, ptr->hil_color);
639 return GF_OK;
640 }
641
hclr_box_size(GF_Box * s)642 GF_Err hclr_box_size(GF_Box *s)
643 {
644 s->size += 4;
645 return GF_OK;
646 }
647
648 #endif /*GPAC_DISABLE_ISOM_WRITE*/
649
krok_box_new()650 GF_Box *krok_box_new()
651 {
652 ISOM_DECL_BOX_ALLOC(GF_TextKaraokeBox, GF_ISOM_BOX_TYPE_KROK);
653 return (GF_Box *) tmp;
654 }
655
krok_box_del(GF_Box * s)656 void krok_box_del(GF_Box *s)
657 {
658 GF_TextKaraokeBox*ptr = (GF_TextKaraokeBox*)s;
659 if (ptr->records) gf_free(ptr->records);
660 gf_free(ptr);
661 }
662
krok_box_read(GF_Box * s,GF_BitStream * bs)663 GF_Err krok_box_read(GF_Box *s, GF_BitStream *bs)
664 {
665 GF_TextKaraokeBox*ptr = (GF_TextKaraokeBox*)s;
666
667 ISOM_DECREASE_SIZE(ptr, 6)
668 ptr->highlight_starttime = gf_bs_read_u32(bs);
669 ptr->nb_entries = gf_bs_read_u16(bs);
670 if (ptr->size < ptr->nb_entries * 8)
671 return GF_ISOM_INVALID_FILE;
672
673 if (ptr->nb_entries) {
674 u32 i;
675 ptr->records = (KaraokeRecord*)gf_malloc(sizeof(KaraokeRecord)*ptr->nb_entries);
676 if (!ptr->records) return GF_OUT_OF_MEM;
677 for (i=0; i<ptr->nb_entries; i++) {
678 ISOM_DECREASE_SIZE(ptr, 8)
679 ptr->records[i].highlight_endtime = gf_bs_read_u32(bs);
680 ptr->records[i].start_charoffset = gf_bs_read_u16(bs);
681 ptr->records[i].end_charoffset = gf_bs_read_u16(bs);
682 }
683 }
684 return GF_OK;
685 }
686
687 #ifndef GPAC_DISABLE_ISOM_WRITE
krok_box_write(GF_Box * s,GF_BitStream * bs)688 GF_Err krok_box_write(GF_Box *s, GF_BitStream *bs)
689 {
690 GF_Err e;
691 u32 i;
692 GF_TextKaraokeBox*ptr = (GF_TextKaraokeBox*)s;
693 e = gf_isom_box_write_header(s, bs);
694 if (e) return e;
695
696 gf_bs_write_u32(bs, ptr->highlight_starttime);
697 gf_bs_write_u16(bs, ptr->nb_entries);
698 for (i=0; i<ptr->nb_entries; i++) {
699 gf_bs_write_u32(bs, ptr->records[i].highlight_endtime);
700 gf_bs_write_u16(bs, ptr->records[i].start_charoffset);
701 gf_bs_write_u16(bs, ptr->records[i].end_charoffset);
702 }
703 return GF_OK;
704 }
705
krok_box_size(GF_Box * s)706 GF_Err krok_box_size(GF_Box *s)
707 {
708 GF_TextKaraokeBox*ptr = (GF_TextKaraokeBox*)s;
709 s->size += 6 + 8*ptr->nb_entries;
710 return GF_OK;
711 }
712
713 #endif /*GPAC_DISABLE_ISOM_WRITE*/
714
dlay_box_new()715 GF_Box *dlay_box_new()
716 {
717 ISOM_DECL_BOX_ALLOC(GF_TextScrollDelayBox, GF_ISOM_BOX_TYPE_DLAY);
718 return (GF_Box *) tmp;
719 }
720
dlay_box_del(GF_Box * s)721 void dlay_box_del(GF_Box *s)
722 {
723 gf_free(s);
724 }
725
dlay_box_read(GF_Box * s,GF_BitStream * bs)726 GF_Err dlay_box_read(GF_Box *s, GF_BitStream *bs)
727 {
728 GF_TextScrollDelayBox*ptr = (GF_TextScrollDelayBox*)s;
729 ISOM_DECREASE_SIZE(ptr, 4)
730 ptr->scroll_delay = gf_bs_read_u32(bs);
731 return GF_OK;
732 }
733
734 #ifndef GPAC_DISABLE_ISOM_WRITE
dlay_box_write(GF_Box * s,GF_BitStream * bs)735 GF_Err dlay_box_write(GF_Box *s, GF_BitStream *bs)
736 {
737 GF_Err e;
738 GF_TextScrollDelayBox*ptr = (GF_TextScrollDelayBox*)s;
739 e = gf_isom_box_write_header(s, bs);
740 if (e) return e;
741 gf_bs_write_u32(bs, ptr->scroll_delay);
742 return GF_OK;
743 }
744
dlay_box_size(GF_Box * s)745 GF_Err dlay_box_size(GF_Box *s)
746 {
747 s->size += 4;
748 return GF_OK;
749 }
750
751 #endif /*GPAC_DISABLE_ISOM_WRITE*/
752
href_box_new()753 GF_Box *href_box_new()
754 {
755 ISOM_DECL_BOX_ALLOC(GF_TextHyperTextBox, GF_ISOM_BOX_TYPE_HREF);
756 return (GF_Box *) tmp;
757 }
758
href_box_del(GF_Box * s)759 void href_box_del(GF_Box *s)
760 {
761 GF_TextHyperTextBox*ptr = (GF_TextHyperTextBox*)s;
762 if (ptr->URL) gf_free(ptr->URL);
763 if (ptr->URL_hint) gf_free(ptr->URL_hint);
764 gf_free(ptr);
765 }
766
href_box_read(GF_Box * s,GF_BitStream * bs)767 GF_Err href_box_read(GF_Box *s, GF_BitStream *bs)
768 {
769 u32 len;
770 GF_TextHyperTextBox*ptr = (GF_TextHyperTextBox*)s;
771 ISOM_DECREASE_SIZE(ptr, 6) //including 2 length fields
772 ptr->startcharoffset = gf_bs_read_u16(bs);
773 ptr->endcharoffset = gf_bs_read_u16(bs);
774 len = gf_bs_read_u8(bs);
775 if (len) {
776 ISOM_DECREASE_SIZE(ptr, len)
777 ptr->URL = (char *) gf_malloc(sizeof(char) * (len+1));
778 if (!ptr->URL) return GF_OUT_OF_MEM;
779 gf_bs_read_data(bs, ptr->URL, len);
780 ptr->URL[len] = 0;
781 }
782 len = gf_bs_read_u8(bs);
783 if (len) {
784 ISOM_DECREASE_SIZE(ptr, len)
785 ptr->URL_hint = (char *) gf_malloc(sizeof(char) * (len+1));
786 if (!ptr->URL_hint) return GF_OUT_OF_MEM;
787 gf_bs_read_data(bs, ptr->URL_hint, len);
788 ptr->URL_hint[len]= 0;
789 }
790 return GF_OK;
791 }
792
793 #ifndef GPAC_DISABLE_ISOM_WRITE
href_box_write(GF_Box * s,GF_BitStream * bs)794 GF_Err href_box_write(GF_Box *s, GF_BitStream *bs)
795 {
796 u32 len;
797 GF_Err e;
798 GF_TextHyperTextBox*ptr = (GF_TextHyperTextBox*)s;
799 e = gf_isom_box_write_header(s, bs);
800 if (e) return e;
801
802 gf_bs_write_u16(bs, ptr->startcharoffset);
803 gf_bs_write_u16(bs, ptr->endcharoffset);
804 if (ptr->URL) {
805 len = (u32) strlen(ptr->URL);
806 gf_bs_write_u8(bs, len);
807 gf_bs_write_data(bs, ptr->URL, len);
808 } else {
809 gf_bs_write_u8(bs, 0);
810 }
811 if (ptr->URL_hint) {
812 len = (u32) strlen(ptr->URL_hint);
813 gf_bs_write_u8(bs, len);
814 gf_bs_write_data(bs, ptr->URL_hint, len);
815 } else {
816 gf_bs_write_u8(bs, 0);
817 }
818 return GF_OK;
819 }
820
href_box_size(GF_Box * s)821 GF_Err href_box_size(GF_Box *s)
822 {
823 GF_TextHyperTextBox*ptr = (GF_TextHyperTextBox*)s;
824 s->size += 6;
825 if (ptr->URL) s->size += strlen(ptr->URL);
826 if (ptr->URL_hint) s->size += strlen(ptr->URL_hint);
827 return GF_OK;
828 }
829
830 #endif /*GPAC_DISABLE_ISOM_WRITE*/
831
832
tbox_box_new()833 GF_Box *tbox_box_new()
834 {
835 ISOM_DECL_BOX_ALLOC(GF_TextBoxBox, GF_ISOM_BOX_TYPE_TBOX);
836 return (GF_Box *) tmp;
837 }
838
tbox_box_del(GF_Box * s)839 void tbox_box_del(GF_Box *s)
840 {
841 gf_free(s);
842 }
843
tbox_box_read(GF_Box * s,GF_BitStream * bs)844 GF_Err tbox_box_read(GF_Box *s, GF_BitStream *bs)
845 {
846 GF_TextBoxBox*ptr = (GF_TextBoxBox*)s;
847 ISOM_DECREASE_SIZE(ptr, GPP_BOX_SIZE)
848 gpp_read_box(bs, &ptr->box);
849 return GF_OK;
850 }
851
852 #ifndef GPAC_DISABLE_ISOM_WRITE
tbox_box_write(GF_Box * s,GF_BitStream * bs)853 GF_Err tbox_box_write(GF_Box *s, GF_BitStream *bs)
854 {
855 GF_Err e;
856 GF_TextBoxBox*ptr = (GF_TextBoxBox*)s;
857 e = gf_isom_box_write_header(s, bs);
858 if (e) return e;
859 gpp_write_box(bs, &ptr->box);
860 return GF_OK;
861 }
862
tbox_box_size(GF_Box * s)863 GF_Err tbox_box_size(GF_Box *s)
864 {
865 s->size += 8;
866 return GF_OK;
867 }
868
869 #endif /*GPAC_DISABLE_ISOM_WRITE*/
870
871
blnk_box_new()872 GF_Box *blnk_box_new()
873 {
874 ISOM_DECL_BOX_ALLOC(GF_TextBlinkBox, GF_ISOM_BOX_TYPE_BLNK);
875 return (GF_Box *) tmp;
876 }
877
blnk_box_del(GF_Box * s)878 void blnk_box_del(GF_Box *s)
879 {
880 gf_free(s);
881 }
882
blnk_box_read(GF_Box * s,GF_BitStream * bs)883 GF_Err blnk_box_read(GF_Box *s, GF_BitStream *bs)
884 {
885 GF_TextBlinkBox*ptr = (GF_TextBlinkBox*)s;
886 ISOM_DECREASE_SIZE(ptr, 4)
887 ptr->startcharoffset = gf_bs_read_u16(bs);
888 ptr->endcharoffset = gf_bs_read_u16(bs);
889 return GF_OK;
890 }
891
892 #ifndef GPAC_DISABLE_ISOM_WRITE
blnk_box_write(GF_Box * s,GF_BitStream * bs)893 GF_Err blnk_box_write(GF_Box *s, GF_BitStream *bs)
894 {
895 GF_Err e;
896 GF_TextBlinkBox*ptr = (GF_TextBlinkBox*)s;
897 e = gf_isom_box_write_header(s, bs);
898 if (e) return e;
899 gf_bs_write_u16(bs, ptr->startcharoffset);
900 gf_bs_write_u16(bs, ptr->endcharoffset);
901 return GF_OK;
902 }
903
blnk_box_size(GF_Box * s)904 GF_Err blnk_box_size(GF_Box *s)
905 {
906 s->size += 4;
907 return GF_OK;
908 }
909
910 #endif /*GPAC_DISABLE_ISOM_WRITE*/
911
twrp_box_new()912 GF_Box *twrp_box_new()
913 {
914 ISOM_DECL_BOX_ALLOC(GF_TextWrapBox, GF_ISOM_BOX_TYPE_TWRP);
915 return (GF_Box *) tmp;
916 }
917
twrp_box_del(GF_Box * s)918 void twrp_box_del(GF_Box *s)
919 {
920 gf_free(s);
921 }
922
twrp_box_read(GF_Box * s,GF_BitStream * bs)923 GF_Err twrp_box_read(GF_Box *s, GF_BitStream *bs)
924 {
925 GF_TextWrapBox*ptr = (GF_TextWrapBox*)s;
926 ISOM_DECREASE_SIZE(ptr, 1)
927 ptr->wrap_flag = gf_bs_read_u8(bs);
928 return GF_OK;
929 }
930
931 #ifndef GPAC_DISABLE_ISOM_WRITE
twrp_box_write(GF_Box * s,GF_BitStream * bs)932 GF_Err twrp_box_write(GF_Box *s, GF_BitStream *bs)
933 {
934 GF_Err e;
935 GF_TextWrapBox*ptr = (GF_TextWrapBox*)s;
936 e = gf_isom_box_write_header(s, bs);
937 if (e) return e;
938 gf_bs_write_u8(bs, ptr->wrap_flag);
939 return GF_OK;
940 }
twrp_box_size(GF_Box * s)941 GF_Err twrp_box_size(GF_Box *s)
942 {
943 s->size += 1;
944 return GF_OK;
945 }
946
947 #endif /*GPAC_DISABLE_ISOM_WRITE*/
948
tsel_box_del(GF_Box * s)949 void tsel_box_del(GF_Box *s)
950 {
951 GF_TrackSelectionBox *ptr;
952 ptr = (GF_TrackSelectionBox *) s;
953 if (ptr == NULL) return;
954 if (ptr->attributeList) gf_free(ptr->attributeList);
955 gf_free(ptr);
956 }
957
tsel_box_read(GF_Box * s,GF_BitStream * bs)958 GF_Err tsel_box_read(GF_Box *s,GF_BitStream *bs)
959 {
960 u32 i;
961 GF_TrackSelectionBox *ptr = (GF_TrackSelectionBox *) s;
962
963 ISOM_DECREASE_SIZE(ptr, 4);
964 ptr->switchGroup = gf_bs_read_u32(bs);
965
966 if (ptr->size % 4) return GF_ISOM_INVALID_FILE;
967 ptr->attributeListCount = (u32)ptr->size/4;
968 ptr->attributeList = gf_malloc(ptr->attributeListCount*sizeof(u32));
969 if (ptr->attributeList == NULL) return GF_OUT_OF_MEM;
970
971 for (i=0; i< ptr->attributeListCount; i++) {
972 ptr->attributeList[i] = gf_bs_read_u32(bs);
973 }
974 return GF_OK;
975 }
976
tsel_box_new()977 GF_Box *tsel_box_new()
978 {
979 ISOM_DECL_BOX_ALLOC(GF_TrackSelectionBox, GF_ISOM_BOX_TYPE_TSEL);
980 return (GF_Box *)tmp;
981 }
982
983
984 #ifndef GPAC_DISABLE_ISOM_WRITE
985
tsel_box_write(GF_Box * s,GF_BitStream * bs)986 GF_Err tsel_box_write(GF_Box *s, GF_BitStream *bs)
987 {
988 GF_Err e;
989 u32 i;
990 GF_TrackSelectionBox *ptr = (GF_TrackSelectionBox *) s;
991
992 e = gf_isom_full_box_write(s, bs);
993 if (e) return e;
994 gf_bs_write_u32(bs,ptr->switchGroup);
995
996 for (i = 0; i < ptr->attributeListCount; i++ ) {
997 gf_bs_write_u32(bs, ptr->attributeList[i]);
998 }
999
1000 return GF_OK;
1001 }
1002
tsel_box_size(GF_Box * s)1003 GF_Err tsel_box_size(GF_Box *s)
1004 {
1005 GF_TrackSelectionBox *ptr = (GF_TrackSelectionBox *) s;
1006 ptr->size += 4 + (4*ptr->attributeListCount);
1007 return GF_OK;
1008 }
1009
1010 #endif /*GPAC_DISABLE_ISOM_WRITE*/
1011
1012
dimC_box_new()1013 GF_Box *dimC_box_new()
1014 {
1015 ISOM_DECL_BOX_ALLOC(GF_DIMSSceneConfigBox, GF_ISOM_BOX_TYPE_DIMC);
1016 return (GF_Box *)tmp;
1017 }
dimC_box_del(GF_Box * s)1018 void dimC_box_del(GF_Box *s)
1019 {
1020 GF_DIMSSceneConfigBox *p = (GF_DIMSSceneConfigBox *)s;
1021 if (p->contentEncoding) gf_free(p->contentEncoding);
1022 if (p->textEncoding) gf_free(p->textEncoding);
1023 gf_free(p);
1024 }
1025
dimC_box_read(GF_Box * s,GF_BitStream * bs)1026 GF_Err dimC_box_read(GF_Box *s, GF_BitStream *bs)
1027 {
1028 char str[1024];
1029 u32 i;
1030 GF_DIMSSceneConfigBox *p = (GF_DIMSSceneConfigBox *)s;
1031
1032 ISOM_DECREASE_SIZE(p, 3);
1033 p->profile = gf_bs_read_u8(bs);
1034 p->level = gf_bs_read_u8(bs);
1035 p->pathComponents = gf_bs_read_int(bs, 4);
1036 p->fullRequestHost = gf_bs_read_int(bs, 1);
1037 p->streamType = gf_bs_read_int(bs, 1);
1038 p->containsRedundant = gf_bs_read_int(bs, 2);
1039
1040 i=0;
1041 str[0]=0;
1042 while (i < GF_ARRAY_LENGTH(str)) {
1043 str[i] = gf_bs_read_u8(bs);
1044 if (!str[i]) break;
1045 i++;
1046 }
1047 ISOM_DECREASE_SIZE(p, i);
1048
1049 p->textEncoding = gf_strdup(str);
1050
1051 i=0;
1052 str[0]=0;
1053 while (i < GF_ARRAY_LENGTH(str)) {
1054 str[i] = gf_bs_read_u8(bs);
1055 if (!str[i]) break;
1056 i++;
1057 }
1058 ISOM_DECREASE_SIZE(p, i);
1059
1060 p->contentEncoding = gf_strdup(str);
1061 return GF_OK;
1062 }
1063
1064 #ifndef GPAC_DISABLE_ISOM_WRITE
dimC_box_write(GF_Box * s,GF_BitStream * bs)1065 GF_Err dimC_box_write(GF_Box *s, GF_BitStream *bs)
1066 {
1067 GF_DIMSSceneConfigBox *p = (GF_DIMSSceneConfigBox *)s;
1068 GF_Err e = gf_isom_box_write_header(s, bs);
1069 if (e) return e;
1070 gf_bs_write_u8(bs, p->profile);
1071 gf_bs_write_u8(bs, p->level);
1072 gf_bs_write_int(bs, p->pathComponents, 4);
1073 gf_bs_write_int(bs, p->fullRequestHost, 1);
1074 gf_bs_write_int(bs, p->streamType, 1);
1075 gf_bs_write_int(bs, p->containsRedundant, 2);
1076 if (p->textEncoding)
1077 gf_bs_write_data(bs, p->textEncoding, (u32) strlen(p->textEncoding));
1078 gf_bs_write_u8(bs, 0);
1079 if (p->contentEncoding)
1080 gf_bs_write_data(bs, p->contentEncoding, (u32) strlen(p->contentEncoding));
1081 gf_bs_write_u8(bs, 0);
1082 return GF_OK;
1083 }
dimC_box_size(GF_Box * s)1084 GF_Err dimC_box_size(GF_Box *s)
1085 {
1086 GF_DIMSSceneConfigBox *p = (GF_DIMSSceneConfigBox *)s;
1087 s->size += 3 + 2;
1088 if (p->textEncoding) s->size += strlen(p->textEncoding);
1089 if (p->contentEncoding) s->size += strlen(p->contentEncoding);
1090 return GF_OK;
1091 }
1092 #endif /*GPAC_DISABLE_ISOM_WRITE*/
1093
1094
1095
diST_box_new()1096 GF_Box *diST_box_new()
1097 {
1098 ISOM_DECL_BOX_ALLOC(GF_DIMSScriptTypesBox, GF_ISOM_BOX_TYPE_DIST);
1099 return (GF_Box *)tmp;
1100 }
diST_box_del(GF_Box * s)1101 void diST_box_del(GF_Box *s)
1102 {
1103 GF_DIMSScriptTypesBox *p = (GF_DIMSScriptTypesBox *)s;
1104 if (p->content_script_types) gf_free(p->content_script_types);
1105 gf_free(p);
1106 }
1107
diST_box_read(GF_Box * s,GF_BitStream * bs)1108 GF_Err diST_box_read(GF_Box *s, GF_BitStream *bs)
1109 {
1110 u32 i;
1111 char str[1024];
1112 GF_DIMSScriptTypesBox *p = (GF_DIMSScriptTypesBox *)s;
1113
1114 i=0;
1115 str[0]=0;
1116 while (1) {
1117 str[i] = gf_bs_read_u8(bs);
1118 if (!str[i]) break;
1119 i++;
1120 }
1121 ISOM_DECREASE_SIZE(p, i);
1122
1123 p->content_script_types = gf_strdup(str);
1124 return GF_OK;
1125 }
1126
1127 #ifndef GPAC_DISABLE_ISOM_WRITE
diST_box_write(GF_Box * s,GF_BitStream * bs)1128 GF_Err diST_box_write(GF_Box *s, GF_BitStream *bs)
1129 {
1130 GF_DIMSScriptTypesBox *p = (GF_DIMSScriptTypesBox *)s;
1131 GF_Err e = gf_isom_box_write_header(s, bs);
1132 if (e) return e;
1133 if (p->content_script_types)
1134 gf_bs_write_data(bs, p->content_script_types, (u32) strlen(p->content_script_types)+1);
1135 else
1136 gf_bs_write_u8(bs, 0);
1137 return GF_OK;
1138 }
diST_box_size(GF_Box * s)1139 GF_Err diST_box_size(GF_Box *s)
1140 {
1141 GF_DIMSScriptTypesBox *p = (GF_DIMSScriptTypesBox *)s;
1142 s->size += p->content_script_types ? (strlen(p->content_script_types)+1) : 1;
1143 return GF_OK;
1144 }
1145 #endif /*GPAC_DISABLE_ISOM_WRITE*/
1146
1147
dims_box_new()1148 GF_Box *dims_box_new()
1149 {
1150 ISOM_DECL_BOX_ALLOC(GF_DIMSSampleEntryBox, GF_ISOM_BOX_TYPE_DIMS);
1151 return (GF_Box*)tmp;
1152 }
dims_box_del(GF_Box * s)1153 void dims_box_del(GF_Box *s)
1154 {
1155 gf_isom_sample_entry_predestroy((GF_SampleEntryBox *)s);
1156 gf_free(s);
1157 }
1158
dims_on_child_box(GF_Box * s,GF_Box * a)1159 static GF_Err dims_on_child_box(GF_Box *s, GF_Box *a)
1160 {
1161 GF_DIMSSampleEntryBox *ptr = (GF_DIMSSampleEntryBox *)s;
1162 switch (a->type) {
1163 case GF_ISOM_BOX_TYPE_DIMC:
1164 if (ptr->config) ERROR_ON_DUPLICATED_BOX(a, ptr)
1165 ptr->config = (GF_DIMSSceneConfigBox*)a;
1166 break;
1167 case GF_ISOM_BOX_TYPE_DIST:
1168 if (ptr->scripts) ERROR_ON_DUPLICATED_BOX(a, ptr)
1169 ptr->scripts = (GF_DIMSScriptTypesBox*)a;
1170 break;
1171 }
1172 return GF_OK;
1173 }
dims_box_read(GF_Box * s,GF_BitStream * bs)1174 GF_Err dims_box_read(GF_Box *s, GF_BitStream *bs)
1175 {
1176 GF_Err e;
1177 GF_DIMSSampleEntryBox *p = (GF_DIMSSampleEntryBox *)s;
1178
1179 e = gf_isom_base_sample_entry_read((GF_SampleEntryBox *)p, bs);
1180 if (e) return e;
1181
1182 ISOM_DECREASE_SIZE(p, 8);
1183 return gf_isom_box_array_read(s, bs, dims_on_child_box);
1184 }
1185
1186 #ifndef GPAC_DISABLE_ISOM_WRITE
dims_box_write(GF_Box * s,GF_BitStream * bs)1187 GF_Err dims_box_write(GF_Box *s, GF_BitStream *bs)
1188 {
1189 GF_DIMSSampleEntryBox *p = (GF_DIMSSampleEntryBox *)s;
1190 GF_Err e = gf_isom_box_write_header(s, bs);
1191 if (e) return e;
1192 gf_bs_write_data(bs, p->reserved, 6);
1193 gf_bs_write_u16(bs, p->dataReferenceIndex);
1194 return GF_OK;
1195 }
1196
dims_box_size(GF_Box * s)1197 GF_Err dims_box_size(GF_Box *s)
1198 {
1199 u32 pos = 0;
1200 GF_DIMSSampleEntryBox *p = (GF_DIMSSampleEntryBox *)s;
1201 s->size += 8;
1202 gf_isom_check_position(s, (GF_Box *) p->config, &pos);
1203 gf_isom_check_position(s, (GF_Box *) p->scripts, &pos);
1204 return GF_OK;
1205 }
1206 #endif /*GPAC_DISABLE_ISOM_WRITE*/
1207
1208 #endif /*GPAC_DISABLE_ISOM*/
1209