Skip to content

Commit 425469a

Browse files
authored
Merge pull request #1 from leela9980/main
add mp4a box
2 parents 3496bb2 + 2cd016e commit 425469a

File tree

4 files changed

+279
-0
lines changed

4 files changed

+279
-0
lines changed

ISOBMFF/include/ISOBMFF.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
#include <ISOBMFF/HVC1.hpp>
8282
#include <ISOBMFF/AVC1.hpp>
8383
#include <ISOBMFF/AV01.hpp>
84+
#include <ISOBMFF/MP4A.hpp>
8485

8586
#ifdef _WIN32
8687
#include <ISOBMFF/WIN32.hpp>

ISOBMFF/include/ISOBMFF/MP4A.hpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 MP4A.hpp
27+
* @copyright (c) 2017, DigiDNA - www.digidna.net
28+
* @author https://github.com/leela9980
29+
*/
30+
31+
#ifndef ISOBMFF_MP4A_HPP
32+
#define ISOBMFF_MP4A_HPP
33+
34+
#include <memory>
35+
#include <algorithm>
36+
#include <ISOBMFF/Macros.hpp>
37+
#include <ISOBMFF/FullBox.hpp>
38+
#include <ISOBMFF/Container.hpp>
39+
#include <string>
40+
#include <cstdint>
41+
42+
namespace ISOBMFF
43+
{
44+
class ISOBMFF_EXPORT MP4A: public FullBox, public Container
45+
{
46+
public:
47+
48+
MP4A();
49+
MP4A( const MP4A & o );
50+
MP4A( MP4A && o ) noexcept;
51+
virtual ~MP4A() override;
52+
53+
MP4A & operator =( MP4A o );
54+
55+
void ReadData( Parser & parser, BinaryStream & stream ) override;
56+
void WriteDescription( std::ostream & os, std::size_t indentLevel ) const override;
57+
std::vector< std::pair< std::string, std::string > > GetDisplayableProperties() const override;
58+
59+
uint16_t GetChannelCount() const;
60+
uint16_t GetSampleSize() const;
61+
uint32_t GetSampleRate() const;
62+
63+
void SetChannelCount( uint16_t value );
64+
void SetSampleSize( uint16_t value );
65+
void SetSampleRate( uint32_t value );
66+
67+
void AddBox( std::shared_ptr< Box > box ) override;
68+
std::vector< std::shared_ptr< Box > > GetBoxes() const override;
69+
ISOBMFF_EXPORT friend void swap( MP4A & o1, MP4A & o2 );
70+
71+
private:
72+
73+
class IMPL;
74+
75+
std::unique_ptr< IMPL > impl;
76+
};
77+
}
78+
79+
#endif /* ISOBMFF_MP4A_HPP */

ISOBMFF/source/MP4A.cpp

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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 MP4A.cpp
27+
* @copyright (c) 2017, DigiDNA - www.digidna.net
28+
* @author https://github.com/leela9980
29+
*/
30+
31+
#include <ISOBMFF/MP4A.hpp>
32+
#include <ISOBMFF/ContainerBox.hpp>
33+
34+
namespace ISOBMFF
35+
{
36+
class MP4A::IMPL
37+
{
38+
public:
39+
40+
IMPL();
41+
IMPL( const IMPL & o );
42+
~IMPL();
43+
44+
uint16_t _channelcount;
45+
uint16_t _samplesize;
46+
uint32_t _samplerate;
47+
std::vector< std::shared_ptr< Box > > _boxes;
48+
};
49+
50+
MP4A::MP4A():
51+
FullBox( "mp4a" ),
52+
impl( std::make_unique< IMPL >() )
53+
{}
54+
55+
MP4A::MP4A( const MP4A & o ):
56+
FullBox( o ),
57+
impl( std::make_unique< IMPL >( *( o.impl ) ) )
58+
{}
59+
60+
MP4A::MP4A( MP4A && o ) noexcept:
61+
FullBox( std::move( o ) ),
62+
impl( std::move( o.impl ) )
63+
{
64+
o.impl = nullptr;
65+
}
66+
67+
MP4A::~MP4A()
68+
{}
69+
70+
MP4A & MP4A::operator =( MP4A o )
71+
{
72+
FullBox::operator=( o );
73+
swap( *( this ), o );
74+
75+
return *( this );
76+
}
77+
78+
void swap( MP4A & o1, MP4A & o2 )
79+
{
80+
using std::swap;
81+
82+
swap( static_cast< FullBox & >( o1 ), static_cast< FullBox & >( o2 ) );
83+
swap( o1.impl, o2.impl );
84+
}
85+
86+
void MP4A::ReadData( Parser & parser, BinaryStream & stream )
87+
{
88+
ContainerBox container( "????" );
89+
90+
// const unsigned int(8)[6] reserved = 0;
91+
stream.ReadUInt8();
92+
stream.ReadUInt8();
93+
stream.ReadUInt8();
94+
stream.ReadUInt8();
95+
stream.ReadUInt8();
96+
stream.ReadUInt8();
97+
// const unsigned int(16) data_reference_index;
98+
stream.ReadUInt16();
99+
// const unsigned int(32)[2] reserved = 0;
100+
stream.ReadUInt32();
101+
stream.ReadUInt32();
102+
103+
// unsigned int(16) channelcount;
104+
SetChannelCount( stream.ReadBigEndianUInt16() );
105+
// template unsigned int(16) samplesize = 16;
106+
SetSampleSize( stream.ReadBigEndianUInt16() );
107+
108+
// unsigned int(16) pre_defined = 0;
109+
stream.ReadUInt16();
110+
// unsigned int(16) reserved = 0;
111+
stream.ReadUInt16();
112+
113+
// template unsigned int(32) samplerate = { default samplerate of media } << 16;
114+
uint32_t sampleRateFixed = stream.ReadBigEndianUInt32();
115+
SetSampleRate( (sampleRateFixed >> 16) + ((sampleRateFixed & 0xFFFF) / 65536) );
116+
117+
container.ReadData( parser, stream );
118+
this->impl->_boxes = container.GetBoxes();
119+
}
120+
121+
std::vector< std::pair< std::string, std::string > > MP4A::GetDisplayableProperties() const
122+
{
123+
auto props( FullBox::GetDisplayableProperties() );
124+
125+
props.push_back( { "Channel Count", std::to_string(this->GetChannelCount()) } );
126+
props.push_back( { "Sample Size", std::to_string(this->GetSampleSize()) } );
127+
props.push_back( { "Sample Rate", std::to_string(this->GetSampleRate()) } );
128+
129+
return props;
130+
}
131+
132+
void MP4A::WriteDescription( std::ostream & os, std::size_t indentLevel ) const
133+
{
134+
FullBox::WriteDescription( os, indentLevel );
135+
Container::WriteBoxes( os, indentLevel );
136+
}
137+
138+
uint16_t MP4A::GetChannelCount() const
139+
{
140+
return this->impl->_channelcount;
141+
}
142+
143+
uint16_t MP4A::GetSampleSize() const
144+
{
145+
return this->impl->_samplesize;
146+
}
147+
148+
uint32_t MP4A::GetSampleRate() const
149+
{
150+
return this->impl->_samplerate;
151+
}
152+
153+
void MP4A::SetChannelCount( uint16_t channelcount )
154+
{
155+
this->impl->_channelcount = channelcount;
156+
}
157+
158+
void MP4A::SetSampleSize( uint16_t samplesize )
159+
{
160+
this->impl->_samplesize = samplesize;
161+
}
162+
163+
void MP4A::SetSampleRate( uint32_t samplerate )
164+
{
165+
this->impl->_samplerate = samplerate;
166+
}
167+
168+
void MP4A::AddBox( std::shared_ptr< Box > box )
169+
{
170+
if( box != nullptr )
171+
{
172+
this->impl->_boxes.push_back( box );
173+
}
174+
}
175+
176+
std::vector< std::shared_ptr< Box > > MP4A::GetBoxes() const
177+
{
178+
return this->impl->_boxes;
179+
}
180+
181+
MP4A::IMPL::IMPL():
182+
_channelcount( 0 ),
183+
_samplesize( 0 ),
184+
_samplerate( 0 )
185+
{
186+
}
187+
188+
MP4A::IMPL::IMPL( const IMPL & o ):
189+
_channelcount( o._channelcount ),
190+
_samplesize( o._samplesize ),
191+
_samplerate( o._samplerate )
192+
{
193+
}
194+
195+
MP4A::IMPL::~IMPL()
196+
{}
197+
}

ISOBMFF/source/Parser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include <ISOBMFF/HVC1.hpp>
6767
#include <ISOBMFF/AVC1.hpp>
6868
#include <ISOBMFF/AV01.hpp>
69+
#include <ISOBMFF/MP4A.hpp>
6970
#include <map>
7071
#include <stdexcept>
7172
#include <cstring>
@@ -383,5 +384,6 @@ namespace ISOBMFF
383384
this->RegisterBox( "hvc1", [ = ]() -> std::shared_ptr< Box > { return std::make_shared< HVC1 >(); } );
384385
this->RegisterBox( "avc1", [ = ]() -> std::shared_ptr< Box > { return std::make_shared< AVC1 >(); } );
385386
this->RegisterBox( "av01", [ = ]() -> std::shared_ptr< Box > { return std::make_shared< AV01 >(); } );
387+
this->RegisterBox( "mp4a", [ = ]() -> std::shared_ptr< Box > { return std::make_shared< MP4A >(); } );
386388
}
387389
}

0 commit comments

Comments
 (0)