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     This PVA_FF_MediaDataAtom Class contains the media data.
     20 */
     21 
     22 
     23 #ifndef __MediaDataAtom_H__
     24 #define __MediaDataAtom_H__
     25 
     26 #include "atom.h"
     27 #include "a_isucceedfail.h"
     28 
     29 #include "a_atomdefs.h"
     30 #include "renderable.h"
     31 #include "trackatom.h"
     32 
     33 #include <stdio.h>
     34 
     35 class PVA_FF_MediaDataAtom : public PVA_FF_Atom, public PVA_FF_ISucceedFail
     36 {
     37 
     38     public:
     39         // 03/21/01 Pass the postfixed string to the obejct
     40         // PVA_FF_MediaDataAtom(int32 type = MEDIA_DATA_IN_MEMORY); // Constructor
     41         // 03/21/01 Generate the temporary files into the output path
     42         // PVA_FF_MediaDataAtom(OSCL_wString postfixString, int32 type = MEDIA_DATA_IN_MEMORY); // Constructor
     43         PVA_FF_MediaDataAtom(PVA_FF_UNICODE_STRING_PARAM outputPathString,
     44                              PVA_FF_UNICODE_STRING_PARAM postfixString,
     45                              int32 tempFileIndex,
     46                              int32 type = MEDIA_DATA_IN_MEMORY,
     47                              void* osclFileServerSession = NULL,
     48                              uint32 aCacheSize = 0); // Constructor
     49 
     50         PVA_FF_MediaDataAtom(PVA_FF_UNICODE_STRING_PARAM targetFileName,
     51                              void* osclFileServerSession = NULL,
     52                              uint32 aCacheSize = 0); // Constructor
     53 
     54         PVA_FF_MediaDataAtom(MP4_AUTHOR_FF_FILE_HANDLE targetFileHandle,
     55                              void* osclFileServerSession = NULL,
     56                              uint32 aCacheSize = 0); // Constructor
     57 
     58         virtual ~PVA_FF_MediaDataAtom();
     59 
     60         // Add actual media sample to atom and return the size of the data
     61         bool addRawSample(void *psample, uint32 length = 0);
     62         // accepts memory fragments
     63         bool addRawSample(Oscl_Vector <OsclMemoryFragment, OsclMemAllocator>& fragmentList,
     64                           uint32 length, int32 mediaType, int32 codecType);
     65 
     66         int32 addRenderableSample(PVA_FF_Renderable *psample); // Adds to vector of renderables
     67 
     68         // Get and set the file offset where the chunks (data) start
     69         void setFileOffsetForChunkStart(uint32 offset)
     70         {
     71             _fileOffsetForChunkStart = offset;
     72         }
     73         uint32 getFileOffsetForChunkStart() const
     74         {
     75             return _fileOffsetForChunkStart;
     76         }
     77 
     78         // The trackReferencePtr keeps a ptr to the actual track that contains
     79         // the meta data for this media data atom
     80         void setTrackReferencePtr(PVA_FF_TrackAtom *ta)
     81         {
     82             _ptrackReferencePtr = ta;
     83             _ptrackReferencePtrVec->push_back(ta);
     84         }
     85         virtual void *getTrackReferencePtr()
     86         {
     87             return (void*)_ptrackReferencePtr;
     88         }
     89 
     90         virtual Oscl_Vector<PVA_FF_TrackAtom*, OsclMemAllocator> *getTrackReferencePtrVec()
     91         {
     92             return _ptrackReferencePtrVec;
     93         }
     94         const Oscl_Vector<PVA_FF_Renderable*, OsclMemAllocator> &getRenderables()
     95         {
     96             return *_prenderables;
     97         }
     98         void reserveBuffer(int32 size);
     99 
    100         // These are for FINAL rendering once the file data is complete
    101         // Rendering the PVA_FF_Atom in proper format (bitlengths, etc.) to an ostream
    102         virtual bool renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp);
    103 
    104         bool _targetFileWriteError;
    105 
    106         uint32 getMediaDataSize();
    107 
    108         bool prepareTargetFile(uint32 mediaOffset);
    109         uint32 prepareTargetFileForFragments(uint32 mediaStartOffset);
    110         bool closeTargetFile();
    111 
    112         bool IsTargetRender()
    113         {
    114             return _directRender;
    115         }
    116 
    117         uint32 getTotalDataRenderedToTargetFileInDirectRenderMode()
    118         {
    119             return _totalDataRenderedToTargetFile;
    120         }
    121 
    122         Oscl_File* getTargetFilePtr();
    123 
    124         int32 getMediaStorageType()
    125         {
    126             return _type;
    127         }
    128     private:
    129         virtual void recomputeSize();
    130         void prepareTempFile(uint32 aCache = 0);
    131 
    132         int32 _type;  // Either MEDIA_DATA_IN_MEMORY or MEDIA_DATA_ON_DISK
    133 
    134         uint32 _fileSize; // Size (in bytes) of actual media data stored within the atom
    135         uint32 _fileOffsetForChunkStart;
    136         uint32 _fileOffsetForAtomStart;
    137         PVA_FF_TrackAtom *_ptrackReferencePtr;
    138 
    139         Oscl_Vector<PVA_FF_TrackAtom*, OsclMemAllocator> *_ptrackReferencePtrVec;
    140         PVA_FF_UNICODE_HEAP_STRING      _tempFilename;
    141         MP4_AUTHOR_FF_FILE_IO_WRAP      _pofstream; // Pointer to file stream that is temp storing the actual media data
    142 
    143         int32 _tempFileIndex;
    144 
    145         // 03/21/01 Add postfix string to handle multiple instances of the output filter,
    146         // the temporary file names will be different for every instances
    147         PVA_FF_UNICODE_HEAP_STRING _tempFilePostfix;
    148 
    149         Oscl_Vector<PVA_FF_Renderable*, OsclMemAllocator> *_prenderables;
    150         bool _fileWriteError;
    151         bool _directRender;
    152 
    153 
    154         void*  _osclFileServerSession;
    155         uint32 _targetFileMediaStartOffset;
    156         uint32  _totalDataRenderedToTargetFile;
    157         bool _oIsFileOpen;
    158 };
    159 
    160 
    161 
    162 #endif
    163 
    164