• 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_HandlerAtom Class declares the nature of the media in the stream.
20 */
21 
22 #define IMPLEMENT_HandlerAtom
23 
24 #include "handleratom.h"
25 #include "a_atomdefs.h"
26 #include "atomutils.h"
27 
28 // Constructor
PVA_FF_HandlerAtom(int32 handlerType,uint8 version,uint32 flags)29 PVA_FF_HandlerAtom::PVA_FF_HandlerAtom(int32 handlerType, uint8 version, uint32 flags)
30         : PVA_FF_FullAtom(HANDLER_ATOM, version, flags)
31 {
32     init(handlerType);
33     recomputeSize();
34 }
35 
36 // Destructor
~PVA_FF_HandlerAtom()37 PVA_FF_HandlerAtom::~PVA_FF_HandlerAtom()
38 {
39     // Empty
40 }
41 
42 void
init(int32 handlerType)43 PVA_FF_HandlerAtom::init(int32 handlerType)
44 {
45     switch (handlerType)
46     {
47         case MEDIA_TYPE_AUDIO:
48             _handlerType = MEDIA_TYPE_AUDIO;
49             _name = "SoundHandler";
50             break;
51         case MEDIA_TYPE_TEXT:
52             _handlerType = MEDIA_TYPE_TEXT;
53             _name = "TextHandler";
54             break;
55         case MEDIA_TYPE_VISUAL:
56             _handlerType = MEDIA_TYPE_VISUAL;
57             _name = "VideoHandler";
58             break;
59         default:
60             _handlerType = UNKNOWN_HANDLER; // Error condition!
61             _name = "UNKNOWNHandler";
62             break;
63     }
64 
65     reserved1 = 0;
66 }
67 
68 void
recomputeSize()69 PVA_FF_HandlerAtom::recomputeSize()
70 {
71     int32 size = getDefaultSize();
72     size += 4; // For 4 bytes of missed 0
73     size += 4; // For handlerType
74     size += 12; // For (8)[12] reserved
75     size += _name.get_size() + 1; // +1 for null termination
76 
77     _size = size;
78 
79 }
80 
81 // Rendering the PVA_FF_Atom in proper format (bitlengths, etc.) to an ostream
82 bool
renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP * fp)83 PVA_FF_HandlerAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp)
84 {
85     int32 rendered = 0; // Keep track of number of bytes rendered
86 
87     // Render PVA_FF_Atom type and size
88     if (!renderAtomBaseMembers(fp))
89     {
90         return false;
91     }
92     rendered += getDefaultSize();
93 
94     if (!PVA_FF_AtomUtils::render32(fp, 0))
95     {
96         return false;
97     }
98     rendered += 4;
99 
100     if (!PVA_FF_AtomUtils::render32(fp, _handlerType))
101     {
102         return false;
103     }
104     rendered += 4;
105 
106     uint8 reserved = 0;
107     for (int32 i = 0; i < 12; i++)
108     {
109         if (!PVA_FF_AtomUtils::render8(fp, reserved))
110         {
111             return false;
112         }
113     }
114     rendered += 12;
115 
116     if (!PVA_FF_AtomUtils::renderNullTerminatedString(fp, _name))
117     {
118         return false;
119     }
120     rendered += _name.get_size() + 1;
121 
122     return true;
123 }
124 
125