2 Copyright (c) 2005-2006, John Hurst
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <hex_utils.h>
39 #include <sys/types.h>
42 using namespace ASDCP;
45 //------------------------------------------------------------------------------------------
48 // There is no header file thet defines this function.
49 // You just have to know it's there...
50 void set_debug_mode(bool info_mode, bool debug_mode);
54 main(int argc, char** argv)
56 Result_t result = RESULT_OK;
57 bool read_mxf = false;
58 bool rewrite_mxf = false;
60 set_debug_mode(true, true);
62 if ( strcmp(argv[1], "-r") == 0 )
67 else if ( strcmp(argv[1], "-w") == 0 )
71 assert(argc - arg_i == 2);
74 fprintf(stderr, "Opening file %s\n", argv[arg_i]);
78 ASDCP::FileReader Reader;
79 ASDCP::MXF::OPAtomHeader Header;
81 result = Reader.OpenRead(argv[arg_i]);
83 if ( ASDCP_SUCCESS(result) )
84 result = Header.InitFromFile(Reader);
86 // if ( ASDCP_SUCCESS(result) )
89 if ( ASDCP_SUCCESS(result) )
91 ASDCP::MXF::OPAtomIndexFooter Index;
92 result = Reader.Seek(Header.FooterPartition);
94 if ( ASDCP_SUCCESS(result) )
96 Index.m_Lookup = &Header.m_Primer;
97 result = Index.InitFromFile(Reader);
100 if ( ASDCP_SUCCESS(result) )
104 else if ( rewrite_mxf )
106 ASDCP::FileReader Reader;
107 ASDCP::FileWriter Writer;
108 ASDCP::MXF::OPAtomHeader Header;
109 ASDCP::MXF::OPAtomIndexFooter Index;
111 result = Reader.OpenRead(argv[arg_i++]);
113 if ( ASDCP_SUCCESS(result) )
114 result = Header.InitFromFile(Reader);
116 if ( ASDCP_SUCCESS(result) )
117 result = Reader.Seek(Header.FooterPartition);
119 if ( ASDCP_SUCCESS(result) )
120 result = Index.InitFromFile(Reader);
122 Header.m_Primer.ClearTagList();
124 if ( ASDCP_SUCCESS(result) )
125 result = Writer.OpenWrite(argv[arg_i]);
127 if ( ASDCP_SUCCESS(result) )
128 result = Header.WriteToFile(Writer);
130 // if ( ASDCP_SUCCESS(result) )
131 // result = Index.WriteToFile(Writer);
141 ASDCP::FileReader Reader;
144 result = Reader.OpenRead(argv[arg_i]);
146 if ( ASDCP_SUCCESS(result) )
147 result = KP.InitFromFile(Reader);
149 while ( ASDCP_SUCCESS(result) )
151 KP.Dump(stderr, true);
152 result = KP.InitFromFile(Reader);
155 if( result == RESULT_ENDOFFILE )
159 if ( result != RESULT_OK )
161 fputs("Program stopped on error.\n", stderr);
163 if ( result != RESULT_FAIL )
165 fputs(GetResultString(result), stderr);