Skip to content

Commit 6d9229d

Browse files
Merge pull request #31 from cchampet/dev_subStreams
Fix audio demultiplexing
2 parents 792021a + 3f2678f commit 6d9229d

File tree

8 files changed

+35
-28
lines changed

8 files changed

+35
-28
lines changed

src/AvTranscoder/CodedStructures/AudioDesc.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#ifndef _AV_TRANSCODER_DATA_AUDIO_DESC_HPP_
22
#define _AV_TRANSCODER_DATA_AUDIO_DESC_HPP_
33

4-
#include <string>
5-
6-
#include <AvTranscoder/common.hpp>
74
#include <AvTranscoder/EssenceStructures/AudioFrame.hpp>
8-
95
#include "CodedDesc.hpp"
6+
#include <AvTranscoder/common.hpp>
7+
8+
#include <string>
109

1110
class AVCodec;
1211

src/AvTranscoder/CodedStructures/VideoDesc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ std::pair< size_t, size_t > VideoDesc::getTimeBase() const
4444
return timeBase;
4545
}
4646

47-
void VideoDesc::setImageParameters( const VideoFrameDesc& VideoFrameDesc )
47+
void VideoDesc::setImageParameters( const VideoFrameDesc& videoFrameDesc )
4848
{
49-
setImageParameters( VideoFrameDesc.getWidth(), VideoFrameDesc.getHeight(), VideoFrameDesc.getPixelDesc() );
49+
setImageParameters( videoFrameDesc.getWidth(), videoFrameDesc.getHeight(), videoFrameDesc.getPixelDesc() );
5050
}
5151

5252

src/AvTranscoder/CodedStructures/VideoDesc.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#ifndef _AV_TRANSCODER_DATA_VIDEO_DESC_HPP_
22
#define _AV_TRANSCODER_DATA_VIDEO_DESC_HPP_
33

4-
#include <string>
5-
6-
#include <AvTranscoder/common.hpp>
74
#include <AvTranscoder/EssenceStructures/VideoFrame.hpp>
8-
95
#include "CodedDesc.hpp"
6+
#include <AvTranscoder/common.hpp>
7+
8+
#include <string>
109

1110
class AVCodec;
1211

@@ -23,7 +22,7 @@ class AvExport VideoDesc : public CodedDesc
2322
VideoFrameDesc getVideoFrameDesc() const;
2423
std::pair< size_t, size_t > getTimeBase() const;
2524

26-
void setImageParameters( const VideoFrameDesc& VideoFrameDesc );
25+
void setImageParameters( const VideoFrameDesc& videoFrameDesc );
2726
void setImageParameters( const size_t width, const size_t height, const Pixel& pixel );
2827
void setImageParameters( const size_t width, const size_t height, const AVPixelFormat& pixel );
2928

src/AvTranscoder/EssenceStream/InputAudio.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,34 +139,29 @@ bool InputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex
139139
if( ! getNextFrame() )
140140
return false;
141141

142-
size_t decodedSize = av_samples_get_buffer_size(NULL, 1,
143-
_frame->nb_samples,
144-
_codecContext->sample_fmt, 1);
142+
const int output_nbChannels = 1;
143+
const int output_align = 1;
144+
size_t decodedSize = av_samples_get_buffer_size(NULL, output_nbChannels, _frame->nb_samples, _codecContext->sample_fmt, output_align);
145145

146146
size_t nbChannels = _codecContext->channels;
147147
size_t bytePerSample = av_get_bytes_per_sample( (AVSampleFormat)_frame->format );
148148

149149
AudioFrame& audioBuffer = static_cast<AudioFrame&>( frameBuffer );
150-
151-
// std::cout << "needed size " << audioBuffer.desc().getDataSize() << std::endl;
152-
153-
// std::cout << _frame->nb_samples * bytePerSample << std::endl;
154-
//audioBuffer.getBuffer().resize( _frame->nb_samples * bytePerSample );
155150
audioBuffer.setNbSamples( _frame->nb_samples );
156151

157152
if( decodedSize )
158153
{
159154
if( audioBuffer.getSize() != decodedSize )
160155
audioBuffer.getBuffer().resize( decodedSize, 0 );
161156

162-
unsigned char* src = *_frame->data;
157+
// @todo manage cases with data of frame not only on data[0] (use _frame.linesize)
158+
unsigned char* src = _frame->data[0];
163159
unsigned char* dst = audioBuffer.getPtr();
164160

165-
src += ( nbChannels - 1 ) - ( subStreamIndex * bytePerSample );
166-
167-
// std::cout << "frame samples count " << _frame->nb_samples << std::endl;
168-
// std::cout << "frame data size " << audioBuffer.getSize() << std::endl;
169-
161+
// @todo check little / big endian
162+
// offset for little endian
163+
src += ( nbChannels - 1 - subStreamIndex ) * bytePerSample;
164+
170165
for( int sample = 0; sample < _frame->nb_samples; ++sample )
171166
{
172167
// std::cout << "sample " << sample << " ==| ";

src/AvTranscoder/EssenceStream/OutputVideo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ bool OutputVideo::encodeFrame( DataStream& codedFrame )
181181
#endif
182182
}
183183

184-
void OutputVideo::setProfile( const Profile::ProfileDesc& desc, const avtranscoder::VideoFrameDesc& VideoFrameDesc )
184+
void OutputVideo::setProfile( const Profile::ProfileDesc& desc, const avtranscoder::VideoFrameDesc& videoFrameDesc )
185185
{
186186
if( ! desc.count( Profile::avProfileCodec ) ||
187187
! desc.count( Profile::avProfilePixelFormat ) ||
@@ -195,7 +195,7 @@ void OutputVideo::setProfile( const Profile::ProfileDesc& desc, const avtranscod
195195
const size_t frameRate = std::strtoul( desc.find( Profile::avProfileFrameRate )->second.c_str(), NULL, 0 );
196196
_videoDesc.setTimeBase( 1, frameRate );
197197

198-
_videoDesc.setImageParameters( VideoFrameDesc );
198+
_videoDesc.setImageParameters( videoFrameDesc );
199199

200200
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
201201
{

src/AvTranscoder/EssenceStream/OutputVideo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AvExport OutputVideo : public OutputEssence
3131
*/
3232
bool encodeFrame( DataStream& codedFrame );
3333

34-
void setProfile( const Profile::ProfileDesc& desc, const avtranscoder::VideoFrameDesc& VideoFrameDesc );
34+
void setProfile( const Profile::ProfileDesc& desc, const avtranscoder::VideoFrameDesc& videoFrameDesc );
3535

3636
VideoDesc& getVideoDesc() { return _videoDesc; }
3737

src/AvTranscoder/EssenceStructures/VideoFrame.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ namespace avtranscoder
3333
class AvExport VideoFrameDesc
3434
{
3535
public:
36+
VideoFrameDesc()
37+
: m_width( 0 )
38+
, m_height( 0 )
39+
, m_displayAspectRatio()
40+
, m_pixel()
41+
, m_interlaced( false )
42+
, m_topFieldFirst( false )
43+
{};
44+
3645
void setWidth ( const size_t width ) { m_width = width; }
3746
void setHeight( const size_t height ) { m_height = height; }
3847
void setPixel ( const Pixel pixel ) { m_pixel = pixel; }

src/AvTranscoder/common.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ namespace avtranscoder
5555

5656
struct Ratio
5757
{
58+
Ratio()
59+
: num( 0 )
60+
, den( 0 )
61+
{}
62+
5863
size_t num;
5964
size_t den;
6065
};

0 commit comments

Comments
 (0)