• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_Renderable Class is the base class for ALL other components of the MP4
20     file format - including Atoms, Descriptors, and Commands.  This class provides
21     the renderToFileStream(...) and readFromFileStream(...) pure virtual methods.
22 */
23 
24 
25 #ifndef __Renderable_H__
26 #define __Renderable_H__
27 
28 #include "atomutils.h"
29 
30 class PVA_FF_Renderable
31 {
32 
33     public:
~PVA_FF_Renderable()34         virtual ~PVA_FF_Renderable() {}
35 
36         // Rendering the PVA_FF_Atom in proper format (bitlengths, etc.) to an ofstream
37         // Each subclass will override this method to render its own contents.
38         virtual bool renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp) = 0;
39 
40         virtual uint32 getSize() const = 0;
41 
dump(MP4_AUTHOR_FF_FILE_IO_WRAP * fp)42         virtual MP4_AUTHOR_FF_FILE_IO_WRAP* dump(MP4_AUTHOR_FF_FILE_IO_WRAP *fp)
43         {
44             return fp;
45         }
46 
47 };
48 
49 class PVA_FF_BufferHolder : public PVA_FF_Renderable
50 {
51 
52     public:
PVA_FF_BufferHolder(uint8 * buf,int32 size)53         PVA_FF_BufferHolder(uint8* buf, int32 size)
54         {
55             _dataBuffer = NULL;
56             _dataSize   = 0;
57 
58             if (size > 0)
59             {
60                 _dataBuffer = (uint8*)(oscl_malloc(sizeof(uint8) * size));
61                 oscl_memcpy(_dataBuffer, buf, size);
62                 _dataSize   = size;
63             }
64         };
65 
~PVA_FF_BufferHolder()66         virtual ~PVA_FF_BufferHolder()
67         {
68             if (_dataBuffer != NULL)
69             {
70                 oscl_free(_dataBuffer);
71             }
72         }
73 
74         // Rendering the PVA_FF_Atom in proper format (bitlengths, etc.) to an ofstream
75         // Each subclass will override this method to render its own contents.
renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP * fp)76         virtual bool renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp)
77         {
78             if (_dataBuffer != NULL)
79             {
80                 if (!PVA_FF_AtomUtils::renderByteData(fp, (uint32)_dataSize, _dataBuffer))
81                 {
82                     return false;
83                 }
84             }
85             return true;
86         };
87 
getSize()88         virtual uint32 getSize() const
89         {
90             return _dataSize;
91         }
92 
93     private:
94         uint8*   _dataBuffer;
95         int32    _dataSize;
96 
97 };
98 
99 
100 #endif
101 
102