Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 
     19 
     20 #include "textsampleentry.h"
     21 #include "atomutils.h"
     22 #include "a_atomdefs.h"
     23 #include "boxrecord.h"
     24 #include "stylerecord.h"
     25 #include "fonttableatom.h"
     26 #include "textsampledescinfo.h"
     27 
     28 
     29 
     30 // Constructor
     31 PVA_FF_TextSampleEntry::PVA_FF_TextSampleEntry()
     32         : PVA_FF_SampleEntry(TEXT_SAMPLE_ENTRY)
     33 {
     34 
     35     init();
     36     recomputeSize();
     37 
     38 
     39 }
     40 
     41 // Destructor
     42 PVA_FF_TextSampleEntry::~PVA_FF_TextSampleEntry()
     43 {
     44     if (_pBackgroundRGBA)
     45     {
     46         OSCL_FREE(_pBackgroundRGBA);
     47         _pBackgroundRGBA = NULL;
     48     }
     49     PV_MP4_FF_DELETE(NULL, PVA_FF_BoxRecord, _pBoxRecord);
     50     PV_MP4_FF_DELETE(NULL, PVA_FF_StyleRecord, _pStyleRecord);
     51     PV_MP4_FF_DELETE(NULL, PVA_FF_FontTableAtom, _pFontTableAtom);
     52 }
     53 
     54 void PVA_FF_TextSampleEntry::init()
     55 {
     56     for (int i = 0; i < 6; i++)
     57     {
     58         _reserved[i] = 0;
     59     }
     60     _dataReferenceIndex = 1;
     61     _preDefined1 = 0;
     62     _reserved1 = 0;
     63 
     64     for (int j = 0; j < 3; j++)
     65     {
     66         _predefined2[j] = 0;
     67     }
     68 
     69     _reserved2 = 0;
     70     _preDefined2 = 0;
     71     _predefined3 = -1;
     72 
     73     PV_MP4_FF_NEW(fp->auditCB, PVA_FF_BoxRecord, (), _pBoxRecord);
     74     PV_MP4_FF_NEW(fp->auditCB, PVA_FF_StyleRecord, (), _pStyleRecord);
     75     PV_MP4_FF_NEW(fp->auditCB, PVA_FF_FontTableAtom, (), _pFontTableAtom);
     76 
     77 }
     78 
     79 
     80 void PVA_FF_TextSampleEntry::addTextDecoderSpecificInfo(PVA_FF_TextSampleDescInfo *pinfo)
     81 {
     82     _displayFlags = pinfo->display_flags;
     83     _horzJustification = pinfo->hJust;
     84     _vertJustification = pinfo->vJust;
     85 
     86     _pBackgroundRGBA = (uint8 *)(OSCL_MALLOC(4 * sizeof(uint8)));
     87     _pBackgroundRGBA[0] = pinfo->bkRgba[0];
     88     _pBackgroundRGBA[1] = pinfo->bkRgba[1];
     89     _pBackgroundRGBA[2] = pinfo->bkRgba[2];
     90     _pBackgroundRGBA[3] = pinfo->bkRgba[3];
     91 
     92     _start_sample_num = pinfo->start_sample_num;
     93     _end_sample_num = pinfo->end_sample_num;
     94     _sdIndex = pinfo->sdindex;
     95 
     96     int16 top = pinfo->top;
     97     _pBoxRecord->setBoxTop(top);
     98 
     99     int16 left = pinfo->left;
    100     _pBoxRecord->setBoxLeft(left);
    101 
    102     int16 bottom = pinfo->bottom;
    103     _pBoxRecord->setBoxBottom(bottom);
    104 
    105     int16 right = pinfo->right;
    106     _pBoxRecord->setBoxRight(right);
    107 
    108     uint16 startchar = pinfo->startChar;
    109     _pStyleRecord->setStartChar(startchar);
    110 
    111     uint16 endchar = pinfo->endChar;
    112     _pStyleRecord->setEndChar(endchar);
    113 
    114     uint16 fontid = pinfo->font_id;
    115     _pStyleRecord->setFontID(fontid);
    116 
    117     uint8 fontsize_flag = pinfo->fontSizeFlags;
    118     _pStyleRecord->setFontStyleFlags(fontsize_flag);
    119 
    120     uint8 fontsize = pinfo->fontSize;
    121     _pStyleRecord->setFontSize(fontsize);
    122 
    123     uint8* tRGBA = pinfo->tRgba;
    124     _pStyleRecord->setTextColourRGBA(tRGBA);
    125 
    126     uint16 fontlistsize = pinfo->fontListSize;
    127     _pFontTableAtom->setFontListSize(fontlistsize);
    128 
    129     uint16 Fontlistid = pinfo->fontListID;
    130     uint16 FontID = pinfo->fontID;
    131     int8 Fontlength = pinfo->font_length;
    132     uint8* Fontname = pinfo->font_name;
    133     _pFontTableAtom->setFontRecord(Fontlistid, FontID, Fontlength, Fontname);
    134 
    135 
    136 }
    137 
    138 
    139 // Rendering the PVA_FF_Atom in proper format (bitlengths, etc.) to an ostream
    140 bool PVA_FF_TextSampleEntry::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp)
    141 {
    142 
    143     int32 rendered = 0;
    144     if (!renderAtomBaseMembers(fp))
    145     {
    146         return false;
    147     }
    148     rendered += getDefaultSize();
    149 
    150     // From PVA_FF_SampleEntry base class
    151     for (int k = 0; k < 6; k++)
    152     {
    153         if (!PVA_FF_AtomUtils::render8(fp, _reserved[k]))
    154         {
    155             return false;
    156         }
    157         rendered += 1;
    158     }
    159 
    160 
    161     if (!PVA_FF_AtomUtils::render16(fp, _dataReferenceIndex))
    162     {
    163         return false;
    164     }
    165     rendered  += 2;
    166     if (!PVA_FF_AtomUtils::render32(fp, _displayFlags))
    167     {
    168         return false;
    169     }
    170     rendered  += 4;
    171     if (!PVA_FF_AtomUtils::render8(fp, _horzJustification))
    172     {
    173         return false;
    174     }
    175     rendered  += 1;
    176     if (!PVA_FF_AtomUtils::render8(fp, _vertJustification))
    177     {
    178         return false;
    179     }
    180     rendered  += 1;
    181     if (!PVA_FF_AtomUtils::renderByteData(fp, 4, (uint8 *)_pBackgroundRGBA))
    182     {
    183         return false;
    184     }
    185     rendered  += 4;
    186 
    187     if (!_pBoxRecord->renderToFileStream(fp))
    188     {
    189         return false;
    190     }
    191     rendered += _pBoxRecord->getSize();
    192 
    193     if (!_pStyleRecord->renderToFileStream(fp))
    194     {
    195         return false;
    196     }
    197     rendered += _pStyleRecord->getSize();
    198 
    199     if (!_pFontTableAtom->renderToFileStream(fp))
    200     {
    201         return false;
    202     }
    203     rendered += _pFontTableAtom->getSize();
    204     return true;
    205 }
    206 
    207 void PVA_FF_TextSampleEntry::recomputeSize()
    208 {
    209     int32 size = getDefaultSize();
    210 
    211     size += 8; // For reserved and dataRefIndex of PVA_FF_SampleEntry base class
    212 
    213     size += 4;
    214     size += 1;
    215     size += 1;
    216     size += 4;
    217     size += _pBoxRecord->getSize();
    218     size += _pStyleRecord->getSize();
    219     size += _pFontTableAtom->getSize();
    220     _size = size;
    221 
    222     // Update size of parent
    223     if (_pparent != NULL)
    224     {
    225         _pparent->recomputeSize();
    226     }
    227 }
    228