/***************************************************************** | | AP4 - avcC Atoms | | Copyright 2002-2008 Axiomatic Systems, LLC | | | This file is part of Bento4/AP4 (MP4 Atom Processing Library). | | Unless you have obtained Bento4 under a difference license, | this version of Bento4 is Bento4|GPL. | Bento4|GPL is free software; you can redistribute it and/or modify | it under the terms of the GNU General Public License as published by | the Free Software Foundation; either version 2, or (at your option) | any later version. | | Bento4|GPL is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | GNU General Public License for more details. | | You should have received a copy of the GNU General Public License | along with Bento4|GPL; see the file COPYING. If not, write to the | Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA | 02111-1307, USA. | ****************************************************************/ /*---------------------------------------------------------------------- | includes +---------------------------------------------------------------------*/ #include "Ap4AvccAtom.h" #include "Ap4AtomFactory.h" #include "Ap4Utils.h" #include "Ap4Types.h" /*---------------------------------------------------------------------- | dynamic cast support +---------------------------------------------------------------------*/ AP4_DEFINE_DYNAMIC_CAST_ANCHOR(AP4_AvccAtom) /*---------------------------------------------------------------------- | AP4_AvccAtom::GetProfileName +---------------------------------------------------------------------*/ const char* AP4_AvccAtom::GetProfileName(AP4_UI08 profile) { switch (profile) { case AP4_AVC_PROFILE_BASELINE: return "Baseline"; case AP4_AVC_PROFILE_MAIN: return "Main"; case AP4_AVC_PROFILE_EXTENDED: return "Extended"; case AP4_AVC_PROFILE_HIGH: return "High"; case AP4_AVC_PROFILE_HIGH_10: return "High 10"; case AP4_AVC_PROFILE_HIGH_422: return "High 4:2:2"; case AP4_AVC_PROFILE_HIGH_444: return "High 4:4:4"; } return NULL; } /*---------------------------------------------------------------------- | AP4_AvccAtom::Create +---------------------------------------------------------------------*/ AP4_AvccAtom* AP4_AvccAtom::Create(AP4_Size size, AP4_ByteStream& stream) { // read the raw bytes in a buffer unsigned int payload_size = size-AP4_ATOM_HEADER_SIZE; AP4_DataBuffer payload_data(payload_size); AP4_Result result = stream.Read(payload_data.UseData(), payload_size); if (AP4_FAILED(result)) return NULL; // check the version const AP4_UI08* payload = payload_data.GetData(); if (payload[0] != 1) { return NULL; } // check the size if (payload_size < 6) return NULL; unsigned int num_seq_params = payload[5]&31; unsigned int cursor = 6; for (unsigned int i=0; i payload_size) return NULL; cursor += 2+AP4_BytesToInt16BE(&payload[cursor]); if (cursor > payload_size) return NULL; } if (cursor+1 > payload_size) return NULL; unsigned int num_pic_params = payload[cursor++]; for (unsigned int i=0; i payload_size) return NULL; cursor += 2+AP4_BytesToInt16BE(&payload[cursor]); if (cursor > payload_size) return NULL; } return new AP4_AvccAtom(size, payload); } /*---------------------------------------------------------------------- | AP4_AvccAtom::AP4_AvccAtom +---------------------------------------------------------------------*/ AP4_AvccAtom::AP4_AvccAtom() : AP4_Atom(AP4_ATOM_TYPE_AVCC, AP4_ATOM_HEADER_SIZE), m_ConfigurationVersion(1), m_Profile(0), m_Level(0), m_ProfileCompatibility(0), m_NaluLengthSize(0), m_ChromaFormat(0), m_BitDepthLumaMinus8(0), m_BitDepthChromaMinus8(0) { UpdateRawBytes(); m_Size32 += m_RawBytes.GetDataSize(); } /*---------------------------------------------------------------------- | AP4_AvccAtom::AP4_AvccAtom +---------------------------------------------------------------------*/ AP4_AvccAtom::AP4_AvccAtom(const AP4_AvccAtom& other) : AP4_Atom(AP4_ATOM_TYPE_AVCC, other.m_Size32), m_ConfigurationVersion(other.m_ConfigurationVersion), m_Profile(other.m_Profile), m_Level(other.m_Level), m_ProfileCompatibility(other.m_ProfileCompatibility), m_NaluLengthSize(other.m_NaluLengthSize), m_RawBytes(other.m_RawBytes) { // deep copy of the parameters unsigned int i = 0; for (i=0; i= payload_size) { return; } AP4_UI08 num_pic_params = payload[cursor++]; m_PictureParameters.EnsureCapacity(num_pic_params); for (unsigned int i=0; i& sequence_parameters, const AP4_Array& picture_parameters) : AP4_Atom(AP4_ATOM_TYPE_AVCC, AP4_ATOM_HEADER_SIZE), m_ConfigurationVersion(1), m_Profile(profile), m_Level(level), m_ProfileCompatibility(profile_compatibility), m_NaluLengthSize(length_size), m_ChromaFormat(chroma_format), m_BitDepthLumaMinus8(bit_depth_luma_minus8), m_BitDepthChromaMinus8(bit_depth_chroma_minus8) { // deep copy of the parameters unsigned int i = 0; for (i=0; i