Skip to content

Commit 8c5c150

Browse files
author
Clement Champetier
committed
AudioFrame: split hpp/cpp
1 parent c64929f commit 8c5c150

File tree

3 files changed

+58
-37
lines changed

3 files changed

+58
-37
lines changed

src/AvTranscoder/file/IOutputFile.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <AvTranscoder/ProfileLoader.hpp>
1212

1313
#include <string>
14-
#include <exception>
14+
#include <stdexcept>
1515

1616
namespace avtranscoder
1717
{

src/AvTranscoder/frame/AudioFrame.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "AudioFrame.hpp"
2+
3+
#include <stdexcept>
4+
5+
namespace avtranscoder
6+
{
7+
8+
AudioFrameDesc::AudioFrameDesc( const size_t sampleRate, const size_t channels, const AVSampleFormat sampleFormat )
9+
: _sampleRate( sampleRate )
10+
, _channels( channels )
11+
, _sampleFormat( sampleFormat )
12+
, _fps( 1. )
13+
{}
14+
15+
AudioFrameDesc::AudioFrameDesc( const size_t sampleRate, const size_t channels, const std::string& sampleFormat )
16+
: _sampleRate( sampleRate )
17+
, _channels( channels )
18+
, _sampleFormat( av_get_sample_fmt( sampleFormat.c_str() ) )
19+
, _fps( 1. )
20+
{}
21+
22+
std::string AudioFrameDesc::getSampleFormatName() const
23+
{
24+
const char* formatName = av_get_sample_fmt_name( _sampleFormat );
25+
return formatName ? std::string( formatName ) : "unknown sample format";
26+
}
27+
28+
size_t AudioFrameDesc::getDataSize() const
29+
{
30+
if( _sampleFormat == AV_SAMPLE_FMT_NONE )
31+
throw std::runtime_error( "incorrect sample format" );
32+
33+
size_t size = ( _sampleRate / _fps ) * _channels * av_get_bytes_per_sample( _sampleFormat );
34+
if( size == 0 )
35+
throw std::runtime_error( "unable to determine audio buffer size" );
36+
37+
return size;
38+
}
39+
40+
void AudioFrameDesc::setSampleFormat( const std::string& sampleFormatName )
41+
{
42+
_sampleFormat = av_get_sample_fmt( sampleFormatName.c_str() );
43+
}
44+
45+
void AudioFrameDesc::setParameters( const ProfileLoader::Profile& profile )
46+
{
47+
if( profile.find( constants::avProfileSampleFormat ) != profile.end() )
48+
setSampleFormat( profile.find( constants::avProfileSampleFormat )->second );
49+
}
50+
51+
}

src/AvTranscoder/frame/AudioFrame.hpp

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,32 @@ extern "C" {
88
#include <libavutil/samplefmt.h>
99
}
1010

11-
#include <stdexcept>
12-
1311
namespace avtranscoder
1412
{
1513

1614
/// @brief Description of a number of samples, which corresponds to one video frame
1715
class AvExport AudioFrameDesc
1816
{
1917
public:
20-
AudioFrameDesc( const size_t sampleRate = 0, const size_t channels = 0, const AVSampleFormat sampleFormat = AV_SAMPLE_FMT_NONE )
21-
: _sampleRate( sampleRate )
22-
, _channels( channels )
23-
, _sampleFormat( sampleFormat )
24-
, _fps( 1. )
25-
{}
18+
AudioFrameDesc( const size_t sampleRate = 0, const size_t channels = 0, const AVSampleFormat sampleFormat = AV_SAMPLE_FMT_NONE );
2619

27-
AudioFrameDesc( const size_t sampleRate, const size_t channels, const std::string& sampleFormat )
28-
: _sampleRate( sampleRate )
29-
, _channels( channels )
30-
, _sampleFormat( av_get_sample_fmt( sampleFormat.c_str() ) )
31-
, _fps( 1. )
32-
{}
20+
AudioFrameDesc( const size_t sampleRate, const size_t channels, const std::string& sampleFormat );
3321

3422
size_t getSampleRate() const { return _sampleRate; }
3523
size_t getChannels() const { return _channels; }
3624
AVSampleFormat getSampleFormat() const { return _sampleFormat; }
37-
std::string getSampleFormatName() const
38-
{
39-
const char* formatName = av_get_sample_fmt_name( _sampleFormat );
40-
return formatName ? std::string( formatName ) : "unknown sample format";
41-
}
25+
std::string getSampleFormatName() const;
4226
double getFps() const { return _fps; }
4327

44-
size_t getDataSize() const
45-
{
46-
if( _sampleFormat == AV_SAMPLE_FMT_NONE )
47-
throw std::runtime_error( "incorrect sample format" );
48-
49-
size_t size = ( _sampleRate / _fps ) * _channels * av_get_bytes_per_sample( _sampleFormat );
50-
if( size == 0 )
51-
throw std::runtime_error( "unable to determine audio buffer size" );
52-
53-
return size;
54-
}
28+
size_t getDataSize() const;
5529

5630
void setSampleRate( const size_t sampleRate ) { _sampleRate = sampleRate; }
5731
void setChannels( const size_t channels ) { _channels = channels; }
58-
void setSampleFormat( const std::string& sampleFormatName ) { _sampleFormat = av_get_sample_fmt( sampleFormatName.c_str() ); }
32+
void setSampleFormat( const std::string& sampleFormatName );
5933
void setSampleFormat( const AVSampleFormat sampleFormat ) { _sampleFormat = sampleFormat; }
6034
void setFps( const double fps ) { _fps = fps; }
6135

62-
void setParameters( const ProfileLoader::Profile& profile )
63-
{
64-
if( profile.find( constants::avProfileSampleFormat ) != profile.end() )
65-
setSampleFormat( profile.find( constants::avProfileSampleFormat )->second );
66-
}
36+
void setParameters( const ProfileLoader::Profile& profile );
6737

6838
private:
6939
size_t _sampleRate;

0 commit comments

Comments
 (0)