Skip to content

Commit 6173649

Browse files
committed
add AVCC box
1 parent 4d293d6 commit 6173649

File tree

5 files changed

+574
-0
lines changed

5 files changed

+574
-0
lines changed

ISOBMFF/include/ISOBMFF.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include <ISOBMFF/INFE.hpp>
6262
#include <ISOBMFF/IROT.hpp>
6363
#include <ISOBMFF/HVCC.hpp>
64+
#include <ISOBMFF/AVCC.hpp>
6465
#include <ISOBMFF/SingleItemTypeReferenceBox.hpp>
6566
#include <ISOBMFF/DIMG.hpp>
6667
#include <ISOBMFF/THMB.hpp>

ISOBMFF/include/ISOBMFF/AVCC.hpp

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*******************************************************************************
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2017 DigiDNA - www.digidna.net
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
******************************************************************************/
24+
25+
/*!
26+
* @header AVCC.hpp
27+
* @copyright (c) 2017, DigiDNA - www.digidna.net
28+
* @author Jean-David Gadina - www.digidna.net
29+
*/
30+
31+
#ifndef ISOBMFF_AVCC_HPP
32+
#define ISOBMFF_AVCC_HPP
33+
34+
#include <memory>
35+
#include <algorithm>
36+
#include <ISOBMFF/Macros.hpp>
37+
#include <ISOBMFF/FullBox.hpp>
38+
#include <ISOBMFF/DisplayableObject.hpp>
39+
#include <ISOBMFF/DisplayableObjectContainer.hpp>
40+
#include <vector>
41+
#include <cstdint>
42+
43+
namespace ISOBMFF
44+
{
45+
class ISOBMFF_EXPORT AVCC: public Box, public DisplayableObjectContainer
46+
{
47+
public:
48+
49+
AVCC();
50+
AVCC( const AVCC & o );
51+
AVCC( AVCC && o ) noexcept;
52+
virtual ~AVCC() override;
53+
54+
AVCC & operator =( AVCC o );
55+
56+
void ReadData( Parser & parser, BinaryStream & stream ) override;
57+
void WriteDescription( std::ostream & os, std::size_t indentLevel ) const override;
58+
59+
virtual std::vector< std::shared_ptr< DisplayableObject > > GetDisplayableObjects() const override;
60+
virtual std::vector< std::pair< std::string, std::string > > GetDisplayableProperties() const override;
61+
62+
uint8_t GetConfigurationVersion() const;
63+
uint8_t GetAVCProfileIndication() const;
64+
uint8_t GetProfileCompatibility() const;
65+
uint8_t GetAVCLevelIndication() const;
66+
uint8_t GetLengthSizeMinusOne() const;
67+
uint8_t GetNumOfSequenceParameterSets() const;
68+
uint8_t GetNumOfPictureParameterSets() const;
69+
70+
void SetConfigurationVersion( uint8_t value );
71+
void SetAVCProfileIndication( uint8_t value );
72+
void SetProfileCompatibility( uint8_t value );
73+
void SetAVCLevelIndication( uint8_t value );
74+
void SetLengthSizeMinusOne( uint8_t value );
75+
void SetNumOfSequenceParameterSets( uint8_t value );
76+
void SetNumOfPictureParameterSets( uint8_t value );
77+
78+
79+
class ISOBMFF_EXPORT NALUnit: public DisplayableObject
80+
{
81+
public:
82+
83+
NALUnit();
84+
NALUnit( BinaryStream & stream );
85+
NALUnit( const NALUnit & o );
86+
NALUnit( NALUnit && o ) noexcept;
87+
virtual ~NALUnit() override;
88+
89+
NALUnit & operator =( NALUnit o );
90+
91+
std::string GetName() const override;
92+
93+
std::vector< uint8_t > GetData() const;
94+
void SetData( const std::vector< uint8_t > & value );
95+
96+
virtual std::vector< std::pair< std::string, std::string > > GetDisplayableProperties() const override;
97+
98+
ISOBMFF_EXPORT friend void swap( NALUnit & o1, NALUnit & o2 );
99+
100+
private:
101+
102+
class IMPL;
103+
104+
std::unique_ptr< IMPL > impl;
105+
};
106+
107+
108+
std::vector< std::shared_ptr< NALUnit > > GetSequenceParameterSetNALUnits() const;
109+
void AddSequenceParameterSetNALUnit( std::shared_ptr< NALUnit > nal_unit );
110+
111+
std::vector< std::shared_ptr< NALUnit > > GetPictureParameterSetNALUnits() const;
112+
void AddPictureParameterSetNALUnit( std::shared_ptr< NALUnit > nal_unit );
113+
114+
115+
ISOBMFF_EXPORT friend void swap( AVCC & o1, AVCC & o2 );
116+
117+
private:
118+
119+
class IMPL;
120+
121+
std::unique_ptr< IMPL > impl;
122+
};
123+
}
124+
125+
#endif /* ISOBMFF_AVCC_HPP */

ISOBMFF/source/AVCC-NALUnit.cpp

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*******************************************************************************
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2017 DigiDNA - www.digidna.net
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
******************************************************************************/
24+
25+
/*!
26+
* @file AVCC-NALUnit.cpp
27+
* @copyright (c) 2017, DigiDNA - www.digidna.net
28+
* @author Jean-David Gadina - www.digidna.net
29+
*/
30+
31+
#include <ISOBMFF/AVCC.hpp>
32+
#include <sstream>
33+
#include <iomanip>
34+
35+
namespace ISOBMFF
36+
{
37+
class AVCC::NALUnit::IMPL
38+
{
39+
public:
40+
41+
IMPL();
42+
IMPL( const IMPL & o );
43+
~IMPL();
44+
45+
std::vector< uint8_t > _data;
46+
};
47+
48+
AVCC::NALUnit::NALUnit():
49+
impl( std::make_unique< IMPL >() )
50+
{}
51+
52+
AVCC::NALUnit::NALUnit( BinaryStream & stream ):
53+
impl( std::make_unique< IMPL >() )
54+
{
55+
std::vector< uint8_t > data;
56+
uint16_t nal_unit_length;
57+
58+
nal_unit_length = stream.ReadBigEndianUInt16();
59+
60+
if( nal_unit_length > 0 )
61+
{
62+
data = std::vector< uint8_t >( nal_unit_length );
63+
64+
stream.Read( &( data[ 0 ] ), nal_unit_length );
65+
}
66+
67+
this->SetData( data );
68+
}
69+
70+
AVCC::NALUnit::NALUnit( const AVCC::NALUnit & o ):
71+
impl( std::make_unique< IMPL >( *( o.impl ) ) )
72+
{}
73+
74+
AVCC::NALUnit::NALUnit( AVCC::NALUnit && o ) noexcept:
75+
impl( std::move( o.impl ) )
76+
{
77+
o.impl = nullptr;
78+
}
79+
80+
AVCC::NALUnit::~NALUnit()
81+
{}
82+
83+
AVCC::NALUnit & AVCC::NALUnit::operator =( AVCC::NALUnit o )
84+
{
85+
swap( *( this ), o );
86+
87+
return *( this );
88+
}
89+
90+
void swap( AVCC::NALUnit & o1, AVCC::NALUnit & o2 )
91+
{
92+
using std::swap;
93+
94+
swap( o1.impl, o2.impl );
95+
}
96+
97+
std::string AVCC::NALUnit::GetName() const
98+
{
99+
return "NALUnit";
100+
}
101+
102+
std::vector< uint8_t > AVCC::NALUnit::GetData() const
103+
{
104+
return this->impl->_data;
105+
}
106+
107+
void AVCC::NALUnit::SetData( const std::vector< uint8_t > & value )
108+
{
109+
this->impl->_data = value;
110+
}
111+
112+
std::vector< std::pair< std::string, std::string > > AVCC::NALUnit::GetDisplayableProperties() const
113+
{
114+
std::vector< uint8_t > data;
115+
std::stringstream ss;
116+
std::string s;
117+
118+
data = this->GetData();
119+
120+
if( data.size() > 0 )
121+
{
122+
for( auto byte: data )
123+
{
124+
ss << std::hex
125+
<< std::uppercase
126+
<< std::setfill( '0' )
127+
<< std::setw( 2 )
128+
<< static_cast< uint32_t >( byte )
129+
<< " ";
130+
}
131+
132+
s = ss.str();
133+
s = s.substr( 0, s.length() - 1 );
134+
}
135+
136+
return
137+
{
138+
{ "Length", std::to_string( data.size() ) },
139+
{ "Data", s }
140+
};
141+
}
142+
143+
AVCC::NALUnit::IMPL::IMPL()
144+
{}
145+
146+
AVCC::NALUnit::IMPL::IMPL( const IMPL & o ):
147+
_data( o._data )
148+
{}
149+
150+
AVCC::NALUnit::IMPL::~IMPL()
151+
{}
152+
}

0 commit comments

Comments
 (0)