1 /*****************************************************************
2 |
3 | AP4 - odaf Atoms
4 |
5 | Copyright 2002-2008 Axiomatic Systems, LLC
6 |
7 |
8 | This file is part of Bento4/AP4 (MP4 Atom Processing Library).
9 |
10 | Unless you have obtained Bento4 under a difference license,
11 | this version of Bento4 is Bento4|GPL.
12 | Bento4|GPL is free software; you can redistribute it and/or modify
13 | it under the terms of the GNU General Public License as published by
14 | the Free Software Foundation; either version 2, or (at your option)
15 | any later version.
16 |
17 | Bento4|GPL is distributed in the hope that it will be useful,
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | GNU General Public License for more details.
21 |
22 | You should have received a copy of the GNU General Public License
23 | along with Bento4|GPL; see the file COPYING. If not, write to the
24 | Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 | 02111-1307, USA.
26 |
27 ****************************************************************/
28
29 /*----------------------------------------------------------------------
30 | includes
31 +---------------------------------------------------------------------*/
32 #include "Ap4Utils.h"
33 #include "Ap4OdafAtom.h"
34
35 /*----------------------------------------------------------------------
36 | dynamic cast support
37 +---------------------------------------------------------------------*/
AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_OdafAtom)38 AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_OdafAtom)
39
40 /*----------------------------------------------------------------------
41 | AP4_OdafAtom::Create
42 +---------------------------------------------------------------------*/
43 AP4_OdafAtom*
44 AP4_OdafAtom::Create(AP4_Size size, AP4_ByteStream& stream)
45 {
46 AP4_UI08 version;
47 AP4_UI32 flags;
48 if (AP4_FAILED(AP4_Atom::ReadFullHeader(stream, version, flags))) return NULL;
49 if (version != 0) return NULL;
50 return new AP4_OdafAtom(size, version, flags, stream);
51 }
52
53 /*----------------------------------------------------------------------
54 | AP4_OdafAtom::AP4_OdafAtom
55 +---------------------------------------------------------------------*/
AP4_OdafAtom(bool selective_encryption,AP4_UI08 key_length_indicator,AP4_UI08 iv_length)56 AP4_OdafAtom::AP4_OdafAtom(bool selective_encryption,
57 AP4_UI08 key_length_indicator,
58 AP4_UI08 iv_length) :
59 AP4_Atom(AP4_ATOM_TYPE_ODAF, AP4_FULL_ATOM_HEADER_SIZE+3, 0, 0),
60 m_SelectiveEncryption(selective_encryption),
61 m_KeyIndicatorLength(key_length_indicator),
62 m_IvLength(iv_length)
63 {
64 }
65
66 /*----------------------------------------------------------------------
67 | AP4_OdafAtom::AP4_OdafAtom
68 +---------------------------------------------------------------------*/
AP4_OdafAtom(AP4_UI32 size,AP4_UI08 version,AP4_UI32 flags,AP4_ByteStream & stream)69 AP4_OdafAtom::AP4_OdafAtom(AP4_UI32 size,
70 AP4_UI08 version,
71 AP4_UI32 flags,
72 AP4_ByteStream& stream) :
73 AP4_Atom(AP4_ATOM_TYPE_ODAF, size, version, flags),
74 m_KeyIndicatorLength(0),
75 m_IvLength(0)
76 {
77 AP4_UI08 s;
78 stream.ReadUI08(s);
79 m_SelectiveEncryption = ((s&0x80) != 0);
80 stream.ReadUI08(m_KeyIndicatorLength);
81 stream.ReadUI08(m_IvLength);
82 }
83
84 /*----------------------------------------------------------------------
85 | AP4_OdafAtom::WriteFields
86 +---------------------------------------------------------------------*/
87 AP4_Result
WriteFields(AP4_ByteStream & stream)88 AP4_OdafAtom::WriteFields(AP4_ByteStream& stream)
89 {
90 AP4_Result result;
91
92 // selective encryption
93 result = stream.WriteUI08(m_SelectiveEncryption ? 0x80 : 0);
94 if (AP4_FAILED(result)) return result;
95
96 // key indicator length
97 result = stream.WriteUI08(m_KeyIndicatorLength);
98 if (AP4_FAILED(result)) return result;
99
100 // IV length
101 result = stream.WriteUI08(m_IvLength);
102 if (AP4_FAILED(result)) return result;
103
104 return AP4_SUCCESS;
105 }
106
107 /*----------------------------------------------------------------------
108 | AP4_OdafAtom::InspectFields
109 +---------------------------------------------------------------------*/
110 AP4_Result
InspectFields(AP4_AtomInspector & inspector)111 AP4_OdafAtom::InspectFields(AP4_AtomInspector& inspector)
112 {
113 inspector.AddField("selective_encryption", m_SelectiveEncryption);
114 inspector.AddField("key_indicator_length", m_KeyIndicatorLength);
115 inspector.AddField("IV_length", m_IvLength);
116
117 return AP4_SUCCESS;
118 }
119