1 #pragma once 2 /***************************************************************************** 3 * 4 * Copyright 2016 Varol Okan. All rights reserved. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 ****************************************************************************/ 19 20 // Tool for loading mpeg4 files and manipulating atoms. 21 #include <stdint.h> 22 #include <vector> 23 24 #include <fstream> 25 26 class Box 27 { 28 public: 29 Box ( ); 30 virtual ~Box ( ); 31 virtual int32_t type ( ); 32 33 static Box *load ( std::fstream &, uint32_t, uint32_t ); 34 static void clear ( std::vector<Box *> & ); 35 36 int content_start ( ); 37 virtual void save ( std::fstream &, std::fstream &, int32_t ); 38 void set ( uint8_t *, uint32_t ); 39 int size ( ); 40 const char *name( ); 41 virtual void print_structure ( const char * ); 42 void tag_copy ( std::fstream &, std::fstream &, int32_t ); 43 void index_copy ( std::fstream &, std::fstream &, Box *, bool, int32_t ); 44 void stco_copy ( std::fstream &, std::fstream &, Box *, int32_t ); 45 void co64_copy ( std::fstream &, std::fstream &, Box *, int32_t ); 46 47 public: 48 static int8_t readInt8 ( std::fstream &fs ); 49 static int16_t readInt16 ( std::fstream &fs ); 50 static int32_t readInt32 ( std::fstream &fs ); 51 static uint8_t readUint8 ( std::fstream &fs ); 52 static uint32_t readUint32 ( std::fstream &fs ); 53 static uint64_t readUint64 ( std::fstream &fs ); 54 static double readDouble ( std::fstream &fs ); 55 56 static void writeInt16 ( std::fstream &fs, int16_t ); 57 static void writeInt32 ( std::fstream &fs, int32_t ); 58 static void writeUint8 ( std::fstream &fs, uint8_t ); 59 static void writeUint32( std::fstream &fs, uint32_t ); 60 static void writeUint64( std::fstream &fs, uint64_t ); 61 62 int32_t m_iType; 63 64 private: 65 uint32_t uint32FromCont ( int32_t &iIDX ); 66 uint64_t uint64FromCont ( int32_t &iIDX ); 67 void index_copy_from_contents ( std::fstream &fsOut, Box *pBox, bool bBigMode, int32_t iDelta ); 68 69 public: 70 char m_name[4]; 71 uint32_t m_iPosition; 72 uint32_t m_iHeaderSize; 73 uint32_t m_iContentSize; 74 uint8_t *m_pContents; 75 }; 76 77