LCOV - code coverage report
Current view: top level - isomedia - box_code_3gpp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 580 636 91.2 %
Date: 2021-04-29 23:48:07 Functions: 93 93 100.0 %

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

Generated by: LCOV version 1.13