-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathother.cpp
152 lines (123 loc) · 4.4 KB
/
other.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
///////////////////////////////////////////////////////////////////////////////
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is MP4v2.
//
// The Initial Developer of the Original Code is Kona Blend.
// Portions created by Kona Blend are Copyright (C) 2008.
// All Rights Reserved.
//
// Contributors:
// Kona Blend, kona8lend@@gmail.com
//
///////////////////////////////////////////////////////////////////////////////
#include "impl.h"
namespace mp4v2 { namespace util {
using namespace mp4v2::impl;
///////////////////////////////////////////////////////////////////////////////
// search atom recursively for any 64-bit characteristics.
// nlargsize indicates number of atoms which use largesize extension.
// nversion1 indicates number of atoms which use version==1 extension.
// nspecial indicates number of special 64-bit atoms;
// eg: stbl may container one of { stco || co64 } for chunkoffsets.
void
searchFor64bit( MP4Atom& atom, FileSummaryInfo& info )
{
const uint32_t max = atom.GetNumberOfChildAtoms();
for( uint32_t i = 0; i < max; i++ ) {
MP4Atom& child = *atom.GetChildAtom( i );
if( child.GetLargesizeMode() )
info.nlargesize++;
MP4Integer8Property* version;
if( child.FindProperty( "version", (MP4Property**)&version ) && version->GetValue() == 1 )
info.nversion1++;
if( !strcmp( child.GetType(), "co64" ))
info.nspecial++;
searchFor64bit( child, info );
}
}
///////////////////////////////////////////////////////////////////////////////
bool
fileFetchSummaryInfo( MP4FileHandle file, FileSummaryInfo& info )
{
if( file == MP4_INVALID_FILE_HANDLE )
return true;
MP4File& mp4 = *((MP4File*)file);
MP4Atom* root = mp4.FindAtom( "" );
if( !root )
return true;
MP4Atom* ftyp = root->FindAtom( "ftyp" );
if( !ftyp )
return true;
info.major_brand = ((MP4StringProperty*)ftyp->GetProperty( 0 ))->GetValue();
info.minor_version = ((MP4Integer32Property*)ftyp->GetProperty( 1 ))->GetValue();
uint32_t max = ((MP4Integer32Property*)ftyp->GetProperty( 2 ))->GetValue();
MP4TableProperty* table = (MP4TableProperty*)ftyp->GetProperty( 3 );
for( uint32_t i = 0; i < max; i++ ) {
string s = ((MP4StringProperty*)table->GetProperty( 0 ))->GetValue( i );
// remove spaces so brand set is presentable
string stripped;
const string::size_type max = s.length();
for( string::size_type pos = 0; pos < max; pos++ ) {
if( s[pos] != ' ' )
stripped += s[pos];
}
if( stripped.empty() )
continue;
info.compatible_brands.insert( stripped );
}
info.nlargesize = 0;
info.nversion1 = 0;
info.nspecial = 0;
searchFor64bit( *root, info );
return false;
}
///////////////////////////////////////////////////////////////////////////////
bool
MP4CopyClose( MP4FileHandle hFile, const string& tmpFileName )
{
if( !MP4_IS_VALID_FILE_HANDLE( hFile ))
return false;
bool success = false;
MP4File& f = *(MP4File*)hFile;
try {
success = f.CopyClose( tmpFileName.c_str() );
}
catch( MP4Error* e ) {
e->Print( stdout );
delete e;
}
if( !success )
return false;
delete &f;
return true;
}
///////////////////////////////////////////////////////////////////////////////
MP4FileHandle
MP4ReadCopy( const string& fileName, uint32_t verbosity )
{
MP4File* file = NULL;
try {
file = new MP4File( verbosity );
file->SetDisableWriteProtection( true );
file->Read( fileName.c_str() );
return static_cast<MP4FileHandle>(file);
}
catch( MP4Error* e) {
e->Print( stdout );
delete e;
delete file;
return MP4_INVALID_FILE_HANDLE;
}
}
///////////////////////////////////////////////////////////////////////////////
}} // namespace mp4v2::util