Home | History | Annotate | Download | only in include
      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     The PVA_FF_Mpeg4File Class is the class that will construct and maintain all the
     20     mecessary data structures to be able to render a valid MP4 file to disk.
     21     Format.
     22 */
     23 
     24 
     25 #ifndef __Mpeg4File_H__
     26 #define __Mpeg4File_H__
     27 
     28 #include "pv_mp4ffcomposer_config.h"
     29 
     30 #include "filetypeatom.h"
     31 #include "a_impeg4file.h"
     32 #include "userdataatom.h"
     33 
     34 #include "movieatom.h"
     35 #include "mediadataatom.h"
     36 #include "a_atomdefs.h"
     37 #include "a_isucceedfail.h"
     38 
     39 #include "interleavebuffer.h"
     40 
     41 // movie fragment
     42 #include "moviefragmentatom.h"
     43 #include "moviefragmentrandomaccessatom.h"
     44 #include "assetinfoatoms.h"
     45 //HEADER FILES REQD FOR MULTIPLE SAMPLE API
     46 #include "oscl_media_data.h"
     47 #include "pv_gau.h"
     48 #ifndef OSCL_MEM_H_INCLUDED
     49 #include "oscl_mem.h"
     50 #endif
     51 #include "textsampledescinfo.h"
     52 
     53 class PVA_FF_Mpeg4File : public PVA_FF_IMpeg4File, public PVA_FF_Parentable
     54 {
     55 
     56     public:
     57         PVA_FF_Mpeg4File(int32 mediaType = FILE_TYPE_VIDEO); // Constructor
     58 
     59         virtual ~PVA_FF_Mpeg4File();
     60 
     61         // 03/21/01 Multiple instances support, commented out moved FROM private
     62         bool init(int32 mediaType,
     63                   void* osclFileServerSession = NULL,
     64                   uint32 fileAuthoringFlags = PVMP4FF_3GPP_DOWNLOAD_MODE);
     65 
     66         // Member get methods
     67         PVA_FF_MovieAtom &getMutableMovieAtom()
     68         {
     69             return *_pmovieAtom;
     70         }
     71         const PVA_FF_MovieAtom &getMovieAtom()
     72         {
     73             return *_pmovieAtom;
     74         }
     75 
     76         void addMediaDataAtom(PVA_FF_MediaDataAtom* atom);
     77 
     78         Oscl_Vector<PVA_FF_MediaDataAtom*, OsclMemAllocator>& getMediaDataAtomVec() const
     79         {
     80             return *_pmediaDataAtomVec;
     81         }
     82 
     83         uint32 getSize() const
     84         {
     85             return _size;
     86         }
     87 
     88         virtual void setVersion(PVA_FF_UNICODE_STRING_PARAM version,
     89                                 uint16 langCode = LANGUAGE_CODE_UNKNOWN);
     90         virtual void setTitle(PVA_FF_UNICODE_STRING_PARAM title,
     91                               uint16 langCode = LANGUAGE_CODE_UNKNOWN);
     92         virtual void setAuthor(PVA_FF_UNICODE_STRING_PARAM author,
     93                                uint16 langCode = LANGUAGE_CODE_UNKNOWN);
     94         virtual void setCopyright(PVA_FF_UNICODE_STRING_PARAM copyright,
     95                                   uint16 langCode = LANGUAGE_CODE_UNKNOWN);
     96         virtual void setDescription(PVA_FF_UNICODE_STRING_PARAM description,
     97                                     uint16 langCode = LANGUAGE_CODE_UNKNOWN);
     98 
     99         //AssetInfo specific
    100         virtual void setPerformer(PVA_FF_UNICODE_STRING_PARAM performer,
    101                                   uint16 langCode = LANGUAGE_CODE_UNKNOWN);
    102 
    103         virtual void setGenre(PVA_FF_UNICODE_STRING_PARAM genre,
    104                               uint16 langCode = LANGUAGE_CODE_UNKNOWN);
    105 
    106         virtual void setRating(PVA_FF_UNICODE_STRING_PARAM ratingInfo,
    107                                uint16 langCode = LANGUAGE_CODE_UNKNOWN,
    108                                uint32 ratingEntity = RATING_ENTITY_UNKNOWN,
    109                                uint32 ratingCriteria = RATING_CRITERIA_UNKNOWN);
    110 
    111         virtual void setClassification(PVA_FF_UNICODE_STRING_PARAM classificationInfo,
    112                                        uint32 classificationEntity,
    113                                        uint16 classificationTable,
    114                                        uint16 langCode = LANGUAGE_CODE_UNKNOWN);
    115 
    116         virtual void setKeyWord(uint8 keyWordSize,
    117                                 PVA_FF_UNICODE_HEAP_STRING keyWordInfo,
    118                                 uint16 langCode = LANGUAGE_CODE_UNKNOWN);
    119 
    120         virtual void setLocationInfo(PvmfAssetInfo3GPPLocationStruct*);
    121 
    122         virtual void setAlbumInfo(PVA_FF_UNICODE_STRING_PARAM albumInfo,
    123                                   uint16 langCode = LANGUAGE_CODE_UNKNOWN);
    124         virtual void setAlbumTrackNumber(uint8 trackNumber);
    125 
    126         virtual void setRecordingYear(uint16 recordingYear);
    127 
    128 
    129         virtual void setCreationDate(PVA_FF_UNICODE_STRING_PARAM creationDate);
    130 
    131         // Methods to set the sample rate (i.e. timescales) for the streams and
    132         // the overall Mpeg-4 presentation
    133         virtual void setPresentationTimescale(uint32 timescale);
    134 
    135         virtual int32 getFileType() const
    136         {
    137             return _fileType;
    138         }
    139 
    140         // MPEG4 header retrieval methods
    141         virtual void setDecoderSpecificInfo(uint8 * header, int32 size, int32 trackID);
    142 
    143         // MPEG4 header retrieval methods for timed text
    144         virtual void setTextDecoderSpecificInfo(PVA_FF_TextSampleDescInfo *header, int32 trackID);
    145 
    146         // Render to file with filename
    147         virtual bool renderToFile(PVA_FF_UNICODE_STRING_PARAM filename);
    148         // Rendering the PVA_FF_Mpeg4File in proper format (bitlengths, etc.) to an ostream
    149         virtual bool renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp);
    150 
    151         // An access function to set the postfix string for PVA_FF_MediaDataAtom objects
    152         virtual void SetTempFilePostFix(PVA_FF_UNICODE_STRING_PARAM postFix);
    153 
    154         virtual void setMajorBrand(uint32 brand)
    155         {
    156             if (_pFileTypeAtom != NULL)
    157             {
    158                 _pFileTypeAtom->setMajorBrand(brand);
    159             }
    160         }
    161 
    162         // 16.16 NOTATATION AND THE VERSION OF WMF SPEC is 1.1, hence the default
    163         // value 0x00010001
    164         virtual void setMajorBrandVersion(uint32 version = 0x10001)
    165         {
    166             if (_pFileTypeAtom != NULL)
    167             {
    168                 _pFileTypeAtom->setMajorBrandVersion(version);
    169             }
    170         }
    171         virtual void addCompatibleBrand(uint32 brand)
    172         {
    173             if (_pFileTypeAtom != NULL)
    174             {
    175                 _pFileTypeAtom->addCompatibleBrand(brand);
    176             }
    177         }
    178 
    179         virtual void setVideoParams(uint32 trackID, float frate, uint16 interval,
    180                                     uint32 frame_width, uint32 frame_height);
    181 
    182         virtual void setAudioEncodeParams(uint32 trackId,
    183                                           PVMP4FFComposerAudioEncodeParams &audioParams);
    184 
    185 
    186         virtual void setH263ProfileLevel(uint32 trackID,
    187                                          uint8 profile,
    188                                          uint8 level);
    189 
    190         uint32 addTrack(int32 mediaType,
    191                         int32 codecType,
    192                         bool oDirectRender = false,
    193                         uint8 profile = 1,
    194                         uint8 profileComp = 0xFF,
    195                         uint8 level = 0xFF);
    196 
    197         bool addSampleToTrack(uint32 trackID,
    198                               Oscl_Vector <OsclMemoryFragment, OsclMemAllocator>& fragmentList,
    199                               uint32 ts, uint8 flags);
    200         //special API for Timed text
    201         bool addTextSampleToTrack(uint32 trackID,
    202                                   Oscl_Vector <OsclMemoryFragment, OsclMemAllocator>& fragmentList,
    203                                   uint32 ts, uint8 flags, int32 index, uint8* Textsamplemodifier);
    204 
    205         void addTrackReference(uint32 currtrackID, int32 reftrackID);
    206         void setTargetBitrate(uint32 trackID, uint32 avgBitRate, uint32 maxBitRate = 0, uint32 bufferSizeDB = 0);
    207         void setTimeScale(uint32 trackID, uint32 rate);
    208 
    209         // An access function to set the output path string for PVA_FF_MediaDataAtom objects
    210         virtual void SetTempOutputPath(PVA_FF_UNICODE_STRING_PARAM outputPath);
    211 
    212         PVA_FF_MediaDataAtom* getMediaDataAtomForTrack(uint32 trackID);
    213 
    214         void setMaxBufferSizeDB(uint32 trackID, uint32 max)
    215         {
    216             _pmovieAtom->setMaxBufferSizeDB(trackID, max);
    217         }
    218 
    219         bool addMultipleAccessUnitsToTrack(uint32 trackID, GAU *pgau);
    220 
    221         bool renderTruncatedFile(PVA_FF_UNICODE_STRING_PARAM filename);
    222 
    223         uint32 convertCreationTime(PVA_FF_UNICODE_STRING_PARAM creationDate);
    224 
    225         bool checkInterLeaveDuration(uint32 trackID, uint32 ts);
    226 
    227         bool flushInterLeaveBuffer(uint32 trackID);
    228 
    229         bool getTargetFileSize(uint32 &metaDataSize, uint32 &mediaDataSize);
    230 
    231         bool prepareToEncode();
    232 
    233         void populateUserDataAtom();
    234 
    235 
    236         virtual bool setInterLeaveInterval(int32 interval)
    237         {
    238             if (interval > 0)
    239             {
    240                 _interLeaveDuration = (uint32)interval;
    241                 return true;
    242             }
    243             return false;
    244         }
    245 
    246         bool addMediaSampleInterleave(uint32 trackID,
    247                                       Oscl_Vector <OsclMemoryFragment, OsclMemAllocator>& fragmentList,
    248                                       uint32 size, uint32 ts, uint8 flags);
    249 
    250         bool addTextMediaSampleInterleave(uint32 trackID,
    251                                           Oscl_Vector <OsclMemoryFragment, OsclMemAllocator>& fragmentList,
    252                                           uint32 size, uint32 ts, uint8 flags, int32 index);
    253         //interleave buffer vector functions
    254         void addInterLeaveBuffer(PVA_FF_InterLeaveBuffer    *pInterLeaveBuffer);
    255         PVA_FF_InterLeaveBuffer*    getInterLeaveBuffer(uint32  trackID);
    256 
    257         bool setOutputFileName(PVA_FF_UNICODE_STRING_PARAM outputFileName);
    258         bool setOutputFileHandle(MP4_AUTHOR_FF_FILE_HANDLE outputFileHandle);
    259 
    260         bool reAuthorFirstSampleInTrack(uint32 trackID,
    261                                         uint8 *psample,
    262                                         uint32 size);
    263         void setLanguage(uint32 language)
    264         {
    265             if (_pmovieAtom != NULL)
    266                 _pmovieAtom->setLanguage(language);
    267         }
    268 
    269         void SetCacheSize(uint32 aCacheSize);
    270 
    271         // movie fragment : set duration of MOOF
    272         void setMovieFragmentDuration(uint32 duration);
    273         uint32 getMovieFragmentDuration();
    274 
    275         bool renderMoovAtom();
    276         bool renderMovieFragments();
    277 
    278     private:
    279 
    280         PVA_FF_UNICODE_HEAP_STRING _title;
    281         bool         _oSetTitleDone;
    282 
    283         PVA_FF_UNICODE_HEAP_STRING _author;
    284         bool         _oSetAuthorDone;
    285 
    286         PVA_FF_UNICODE_HEAP_STRING _copyright;
    287         bool         _oSetCopyrightDone;
    288 
    289         PVA_FF_UNICODE_HEAP_STRING _description;
    290         bool         _oSetDescriptionDone;
    291 
    292         PVA_FF_UNICODE_HEAP_STRING _performer;
    293         bool         _oSetPerformerDone;
    294 
    295         PVA_FF_UNICODE_HEAP_STRING _genre;
    296         bool         _oSetGenreDone;
    297 
    298         PVA_FF_UNICODE_HEAP_STRING _ratingInfo;
    299         uint32 _ratingEntity;
    300         uint32 _ratingCriteria;
    301         bool   _oSetRatingDone;
    302 
    303 
    304         PVA_FF_UNICODE_HEAP_STRING _classificationInfo;
    305         uint32 _classificationEntity;
    306         uint32 _classificationTable;
    307         bool         _oSetClassificationDone;
    308 
    309         PVA_FF_UNICODE_HEAP_STRING _keyWordInfo;
    310         uint8 _keyWordSize;
    311 
    312         PVA_FF_UNICODE_HEAP_STRING _locationName;
    313         PVA_FF_UNICODE_HEAP_STRING _locationInfoAstrBody;
    314         PVA_FF_UNICODE_HEAP_STRING _locationInfoAddNotes;
    315         uint8  _locationInfoRole;
    316         uint32 _locationInfoLongitude;
    317         uint32 _locationInfoLatitude;
    318         uint32 _locationInfoAltitude;
    319         bool         _oSetLocationInfoDone;
    320 
    321         PVA_FF_UNICODE_HEAP_STRING _albumInfo;
    322         bool         _oSetAlbumDone;
    323 
    324         uint16  _recordingYear;
    325         bool    _oSetRecordingYearDone;
    326 
    327 
    328         PVA_FF_UNICODE_HEAP_STRING _creationDate;
    329         bool         _oSetCreationDateDone;
    330 
    331         virtual void recomputeSize();
    332 
    333         PVA_FF_UserDataAtom *_puserDataAtom;
    334 
    335         PVA_FF_FileTypeAtom       *_pFileTypeAtom;
    336         PVA_FF_MovieAtom          *_pmovieAtom;
    337 
    338         Oscl_Vector<PVA_FF_MediaDataAtom*, OsclMemAllocator> *_pmediaDataAtomVec;
    339 
    340         // In movie fragment mode these parameters hold
    341         // the current MOOF and MDAT to add samples. They are destroyed once
    342         // they are written to file
    343         PVA_FF_MovieFragmentAtom                                *_pCurrentMoofAtom;
    344         PVA_FF_MediaDataAtom                                    *_pCurrentMediaDataAtom;
    345 
    346         // This media data atom holds MDAT for movie fragments only
    347 
    348         // Movie Fragment random access atom in case of movie fragments
    349         PVA_FF_MovieFragmentRandomAccessAtom *_pMfraAtom;
    350 
    351         // Movie Fragment mode parameters
    352         bool        _oMovieFragmentEnabled;
    353         bool        _oComposeMoofAtom;          // flag when true, samples are added in MOOF
    354         uint32      _currentMoofOffset;         // contains the offset of current MOOF before MDAT,
    355         // actual offset is current offset + size of MDAT for this MOOF
    356         uint32      _movieFragmentDuration;     // always in milliseconds : decides total sample length in MOOF and MOOV
    357         bool        _oTrunStart;                // true when new TRUN is to be added in MOOF from interleave buffer
    358         // made true for 1st sample of interleave buffer
    359         uint32      _sequenceNumber;            // keep track of number of movie fragments added
    360 
    361         // interleave buffers and vectors
    362         Oscl_Vector<PVA_FF_InterLeaveBuffer*, OsclMemAllocator> *_pInterLeaveBufferVec;
    363 
    364         uint32 _size;
    365         bool _modifiable;
    366 
    367         int32 _scalability;
    368         int32 _fileType;
    369 
    370         bool _firstFrameInLayer0;
    371         bool _firstFrameInLayer1;
    372 
    373         // Postfix string to handle multiple instances of the output filter,
    374         // the temporary file names will be different for every instances
    375         PVA_FF_UNICODE_HEAP_STRING _tempFilePostfix;
    376 
    377         bool             _downLoadOnly;
    378 
    379         int32 _codecType;
    380 
    381         // an output path for generated temporary files (.mdat)
    382         PVA_FF_UNICODE_HEAP_STRING _tempOutputPath;
    383 
    384         bool _fileWriteFailed;
    385         bool _oFileRenderCalled;
    386         bool _oUserDataPopulated;
    387         bool _oFtypPopulated;
    388 
    389         bool _o3GPPTrack;
    390         bool _oWMFTrack;
    391         bool _oMPEGTrack;
    392         bool _oPVMMTrack;
    393 
    394         uint32 _fileAuthoringFlags;
    395         bool   _oInterLeaveEnabled;
    396         bool   _oMovieAtomUpfront;
    397         uint32 _interLeaveDuration; // Always in milliseconds
    398 
    399 
    400         bool   _oAuthorASSETINFOAtoms;
    401         uint32 _baseOffset;
    402         bool   _oChunkStart;
    403 
    404         uint16 _nextAvailableODID;
    405         int32  _tempFileIndex;
    406 
    407         void *_aFs;
    408 
    409         PVA_FF_UNICODE_HEAP_STRING _targetFileName;
    410         MP4_AUTHOR_FF_FILE_HANDLE  _targetFileHandle;
    411 
    412         bool        _oPartialTempFileRemoval;
    413         bool        _oDirectRenderEnabled;
    414         uint32      _initialUserDataSize;
    415         uint32      _directRenderFileOffset;
    416 
    417         PVA_FF_UNICODE_HEAP_STRING _outputFileName;
    418         MP4_AUTHOR_FF_FILE_HANDLE  _outputFileHandle;
    419 
    420         bool        _outputFileNameSet;
    421         bool        _totalTempFileRemoval;
    422         bool        _oUserDataUpFront;
    423 
    424         bool        _oFileOpenedOutsideAFFLib;
    425 
    426         bool        _oFirstSampleEditMode;
    427         uint32      iCacheSize;
    428         bool        _oIsFileOpen;
    429 };
    430 
    431 
    432 
    433 #endif
    434 
    435