1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // The contents of this file are subject to the Mozilla Public License
4 // Version 1.1 (the "License"); you may not use this file except in
5 // compliance with the License. You may obtain a copy of the License at
6 // http://www.mozilla.org/MPL/
7 //
8 // Software distributed under the License is distributed on an "AS IS"
9 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10 // License for the specific language governing rights and limitations
11 // under the License.
12 //
13 // The Original Code is MP4v2.
14 //
15 // The Initial Developer of the Original Code is Kona Blend.
16 // Portions created by Kona Blend are Copyright (C) 2008.
17 // All Rights Reserved.
18 //
19 // Contributors:
20 // Kona Blend, kona8lend@@gmail.com
21 //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "impl.h"
25
26 namespace mp4v2 { namespace impl { namespace qtff {
27
28 ///////////////////////////////////////////////////////////////////////////////
29
30 namespace {
31 class StaticData
32 {
33 public:
StaticData()34 StaticData()
35 {
36 supportedCodings.insert( "avc1" );
37 supportedCodings.insert( "mp4v" );
38 }
39
40 set<string> supportedCodings;
41 };
42
43 const StaticData STATIC_DATA;
44 }
45
46 ///////////////////////////////////////////////////////////////////////////////
47
48 bool
findCoding(MP4FileHandle file,uint16_t trackIndex,MP4Atom * & coding)49 findCoding( MP4FileHandle file, uint16_t trackIndex, MP4Atom*& coding )
50 {
51 coding = NULL;
52 MP4File& mp4 = *((MP4File*)file);
53
54 if( trackIndex == numeric_limits<uint16_t>::max() ) {
55 ostringstream xss;
56 xss << "invalid track-index: " << trackIndex;
57 throw new Exception( xss.str(), __FILE__, __LINE__, __FUNCTION__ );
58 }
59
60 ostringstream oss;
61 oss << "moov.trak[" << trackIndex << "].mdia.hdlr";
62 MP4Atom* hdlr = mp4.FindAtom( oss.str().c_str() );
63 if( !hdlr )
64 throw new Exception( "media handler not found", __FILE__, __LINE__, __FUNCTION__ );
65
66 MP4StringProperty* handlerType;
67 if( !hdlr->FindProperty( "hdlr.handlerType", (MP4Property**)&handlerType ))
68 throw new Exception( "media handler type-property not found", __FILE__, __LINE__, __FUNCTION__ );
69
70 const string video = "vide";
71 if( video != handlerType->GetValue() )
72 throw new Exception( "video-track required", __FILE__, __LINE__, __FUNCTION__ );
73
74 oss.str( "" );
75 oss.clear();
76 oss << "moov.trak[" << trackIndex << "].mdia.minf.stbl.stsd";
77 MP4Atom* stsd = mp4.FindAtom( oss.str().c_str() );
78 if( !stsd )
79 throw new Exception( "media handler type-property not found", __FILE__, __LINE__, __FUNCTION__ );
80
81 // find first atom which is a supported coding
82 const uint32_t atomc = stsd->GetNumberOfChildAtoms();
83 for( uint32_t i = 0; i < atomc; i++ ) {
84 MP4Atom* atom = stsd->GetChildAtom( i );
85 if( STATIC_DATA.supportedCodings.find( atom->GetType() ) == STATIC_DATA.supportedCodings.end() )
86 continue;
87 coding = atom;
88 }
89
90 return coding == NULL;
91 }
92
93 ///////////////////////////////////////////////////////////////////////////////
94
95 }}} // namespace mp4v2::impl::qtff
96