Skip to content

Commit e5ee852

Browse files
author
Clement Champetier
committed
AudioFrame: update constructors
* Remove default constructor. * Add a constructor from a profile.
1 parent ca3c386 commit e5ee852

File tree

6 files changed

+16
-14
lines changed

6 files changed

+16
-14
lines changed

src/AvTranscoder/codec/AudioCodec.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "AudioCodec.hpp"
22

3+
#include <AvTranscoder/util.hpp>
4+
35
#include <cmath>
46
#include <cassert>
57

@@ -24,7 +26,7 @@ AudioCodec::AudioCodec(const ECodecType type, AVCodecContext& avCodecContext)
2426
AudioFrameDesc AudioCodec::getAudioFrameDesc() const
2527
{
2628
assert(_avCodecContext != NULL);
27-
return AudioFrameDesc(_avCodecContext->sample_rate, _avCodecContext->channels, _avCodecContext->sample_fmt);
29+
return AudioFrameDesc(_avCodecContext->sample_rate, _avCodecContext->channels, getSampleFormatName(_avCodecContext->sample_fmt));
2830
}
2931

3032
void AudioCodec::setAudioParameters(const AudioFrameDesc& audioFrameDesc)

src/AvTranscoder/data/decoded/AudioFrame.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ extern "C" {
1212
namespace avtranscoder
1313
{
1414

15-
AudioFrameDesc::AudioFrameDesc(const size_t sampleRate, const size_t nbChannels, const AVSampleFormat sampleFormat)
15+
AudioFrameDesc::AudioFrameDesc(const size_t sampleRate, const size_t nbChannels, const std::string& sampleFormatName)
1616
: _sampleRate(sampleRate)
1717
, _nbChannels(nbChannels)
18-
, _sampleFormat(sampleFormat)
18+
, _sampleFormat(getAVSampleFormat(sampleFormatName))
1919
{
2020
}
2121

22-
AudioFrameDesc::AudioFrameDesc(const size_t sampleRate, const size_t nbChannels, const std::string& sampleFormatName)
23-
: _sampleRate(sampleRate)
24-
, _nbChannels(nbChannels)
25-
, _sampleFormat(getAVSampleFormat(sampleFormatName))
22+
AudioFrameDesc::AudioFrameDesc(const ProfileLoader::Profile& profile)
23+
: _sampleRate(0)
24+
, _nbChannels(0)
25+
, _sampleFormat(AV_SAMPLE_FMT_NONE)
2626
{
27+
setParameters(profile);
2728
}
2829

2930
void AudioFrameDesc::setParameters(const ProfileLoader::Profile& profile)

src/AvTranscoder/data/decoded/AudioFrame.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ namespace avtranscoder
1414
struct AvExport AudioFrameDesc
1515
{
1616
public:
17-
AudioFrameDesc(const size_t sampleRate = 0, const size_t channels = 0,
18-
const AVSampleFormat sampleFormat = AV_SAMPLE_FMT_NONE);
1917
AudioFrameDesc(const size_t sampleRate, const size_t channels, const std::string& sampleFormatName);
18+
AudioFrameDesc(const ProfileLoader::Profile& profile);
2019

2120
/**
2221
* @brief Set the attributes from the given profile.

src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "AudioDecoder.hpp"
22

3+
#include <AvTranscoder/util.hpp>
34
#include <AvTranscoder/codec/ICodec.hpp>
45
#include <AvTranscoder/stream/InputStream.hpp>
56
#include <AvTranscoder/data/decoded/AudioFrame.hpp>
@@ -133,7 +134,7 @@ bool AudioDecoder::decodeNextFrame(IFrame& frameBuffer, const std::vector<size_t
133134

134135
// else decode all data in an intermediate buffer
135136
AudioFrame& audioBuffer = static_cast<AudioFrame&>(frameBuffer);
136-
AudioFrame allDataOfNextFrame(AudioFrameDesc(audioBuffer.getSampleRate(), srcNbChannels, audioBuffer.getSampleFormat()), false);
137+
AudioFrame allDataOfNextFrame(AudioFrameDesc(audioBuffer.getSampleRate(), srcNbChannels, getSampleFormatName(audioBuffer.getSampleFormat())), false);
137138
if(!decodeNextFrame(allDataOfNextFrame))
138139
return false;
139140

src/AvTranscoder/reader/AudioReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void AudioReader::init()
5454
// create dst frame
5555
_outputSampleRate = srcFrame->getSampleRate();
5656
_outputNbChannels = (_channelIndex == -1) ? srcFrame->getNbChannels() : 1;
57-
_dstFrame = new AudioFrame(AudioFrameDesc(_outputSampleRate, _outputNbChannels, _outputSampleFormat));
57+
_dstFrame = new AudioFrame(AudioFrameDesc(_outputSampleRate, _outputNbChannels, getSampleFormatName(_outputSampleFormat)));
5858

5959
// generator
6060
_generator = new AudioGenerator(srcFrameDesc);
@@ -79,6 +79,6 @@ void AudioReader::updateOutput(const size_t sampleRate, const size_t nbChannels,
7979
_outputSampleFormat = getAVSampleFormat(sampleFormat);
8080
// update dst frame
8181
delete _dstFrame;
82-
_dstFrame = new AudioFrame(AudioFrameDesc(_outputSampleRate, _outputNbChannels, _outputSampleFormat));
82+
_dstFrame = new AudioFrame(AudioFrameDesc(_outputSampleRate, _outputNbChannels, getSampleFormatName(_outputSampleFormat)));
8383
}
8484
}

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ StreamTranscoder::StreamTranscoder(IOutputFile& outputFile, const ProfileLoader:
333333
else if(profile.find(constants::avProfileType)->second == constants::avProfileTypeAudio)
334334
{
335335
AudioCodec inputAudioCodec(eCodecTypeEncoder, profile.find(constants::avProfileCodec)->second);
336-
AudioFrameDesc inputFrameDesc;
337-
inputFrameDesc.setParameters(profile);
336+
AudioFrameDesc inputFrameDesc(profile);
338337
inputAudioCodec.setAudioParameters(inputFrameDesc);
339338

340339
// generator decoder

0 commit comments

Comments
 (0)