|
| 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 | +} |
0 commit comments