Skip to content

Commit bfddb81

Browse files
Merge pull request #32 from cchampet/dev_subStreams
Refactoring & minor updates
2 parents 7e53cc7 + d2c8e12 commit bfddb81

19 files changed

+69
-63
lines changed

src/AvTranscoder/CodedStream/AvInputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "InputStream.hpp"
55

6-
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
6+
#include <AvTranscoder/CodedStructures/DataStream.hpp>
77

88
namespace avtranscoder
99
{

src/AvTranscoder/CodedStream/InputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _AV_TRANSCODER_CODED_STREAM_INPUT_STREAM_HPP_
22
#define _AV_TRANSCODER_CODED_STREAM_INPUT_STREAM_HPP_
33

4-
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
4+
#include <AvTranscoder/CodedStructures/DataStream.hpp>
55
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
66
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>
77

src/AvTranscoder/CodedStream/OutputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _AV_TRANSCODER_CODED_STREAM_OUTPUT_STREAM_HPP_
22
#define _AV_TRANSCODER_CODED_STREAM_OUTPUT_STREAM_HPP_
33

4-
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
4+
#include <AvTranscoder/CodedStructures/DataStream.hpp>
55
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
66
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>
77

src/AvTranscoder/CodedStructures/AudioDesc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ const AVSampleFormat AudioDesc::getSampleFormat() const
5353
return m_codecContext->sample_fmt;
5454
}
5555

56+
void AudioDesc::setAudioParameters( const AudioFrameDesc& audioFrameDesc )
57+
{
58+
setAudioParameters( audioFrameDesc.getSampleRate(), audioFrameDesc.getChannels(), audioFrameDesc.getSampleFormat() );
59+
}
5660

5761
void AudioDesc::setAudioParameters( const size_t sampleRate, const size_t channels, const AVSampleFormat sampleFormat )
5862
{

src/AvTranscoder/CodedStructures/AudioDesc.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class AvExport AudioDesc : public CodedDesc
2424
const size_t getChannels() const;
2525
const AVSampleFormat getSampleFormat() const;
2626

27+
void setAudioParameters( const AudioFrameDesc& audioFrameDesc );
2728
void setAudioParameters( const size_t sampleRate, const size_t channels, const AVSampleFormat sampleFormat );
2829
};
2930

src/AvTranscoder/EssenceStream/InputAudio.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,14 @@ bool InputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex
143143
const int output_align = 1;
144144
size_t decodedSize = av_samples_get_buffer_size(NULL, output_nbChannels, _frame->nb_samples, _codecContext->sample_fmt, output_align);
145145

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

149+
if( subStreamIndex > nbSubStreams - 1 )
150+
{
151+
throw std::runtime_error( "The subStream doesn't exist");
152+
}
153+
149154
AudioFrame& audioBuffer = static_cast<AudioFrame&>( frameBuffer );
150155
audioBuffer.setNbSamples( _frame->nb_samples );
151156

@@ -158,9 +163,8 @@ bool InputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex
158163
unsigned char* src = _frame->data[0];
159164
unsigned char* dst = audioBuffer.getPtr();
160165

161-
// @todo check little / big endian
162-
// offset for little endian
163-
src += ( nbChannels - 1 - subStreamIndex ) * bytePerSample;
166+
// offset
167+
src += ( nbSubStreams - 1 - subStreamIndex ) * bytePerSample;
164168

165169
for( int sample = 0; sample < _frame->nb_samples; ++sample )
166170
{
@@ -169,7 +173,7 @@ bool InputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex
169173
// std::cout << "dst " << static_cast<void *>(dst) << std::endl;
170174
memcpy( dst, src, bytePerSample );
171175
dst += bytePerSample;
172-
src += bytePerSample * nbChannels;
176+
src += bytePerSample * nbSubStreams;
173177
}
174178
}
175179
return true;

src/AvTranscoder/EssenceStream/OutputAudio.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ extern "C" {
1111

1212
#include <iostream>
1313
#include <stdexcept>
14-
#include <cstdlib>
1514

1615
namespace avtranscoder
1716
{
@@ -177,28 +176,22 @@ bool OutputAudio::encodeFrame( DataStream& codedFrame )
177176
void OutputAudio::setProfile( const Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc )
178177
{
179178
if( ! desc.count( Profile::avProfileCodec ) ||
180-
! desc.count( Profile::avProfileSampleFormat ) ||
181-
! desc.count( Profile::avProfileSampleRate ) ||
182-
! desc.count( Profile::avProfileChannel ) )
179+
! desc.count( Profile::avProfileSampleFormat ) )
183180
{
184181
throw std::runtime_error( "The profile " + desc.find( Profile::avProfileIdentificatorHuman )->second + " is invalid." );
185182
}
186183

187184
_audioDesc.setCodec( desc.find( Profile::avProfileCodec )->second );
188185

189-
size_t sample_rate = std::strtoul( desc.find( Profile::avProfileSampleRate )->second.c_str(), NULL, 0 );
190-
size_t channels = std::strtoul( desc.find( Profile::avProfileChannel )->second.c_str(), NULL, 0 );
191-
_audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc.find( Profile::avProfileSampleFormat )->second.c_str() ) );
192-
186+
_audioDesc.setAudioParameters( frameDesc );
187+
193188
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
194189
{
195190
if( (*it).first == Profile::avProfileIdentificator ||
196191
(*it).first == Profile::avProfileIdentificatorHuman ||
197192
(*it).first == Profile::avProfileType ||
198193
(*it).first == Profile::avProfileCodec ||
199-
(*it).first == Profile::avProfileSampleFormat ||
200-
(*it).first == Profile::avProfileSampleRate ||
201-
(*it).first == Profile::avProfileChannel )
194+
(*it).first == Profile::avProfileSampleFormat )
202195
continue;
203196

204197
try
@@ -219,9 +212,7 @@ void OutputAudio::setProfile( const Profile::ProfileDesc& desc, const AudioFrame
219212
(*it).first == Profile::avProfileIdentificatorHuman ||
220213
(*it).first == Profile::avProfileType ||
221214
(*it).first == Profile::avProfileCodec ||
222-
(*it).first == Profile::avProfileSampleFormat ||
223-
(*it).first == Profile::avProfileSampleRate ||
224-
(*it).first == Profile::avProfileChannel )
215+
(*it).first == Profile::avProfileSampleFormat )
225216
continue;
226217

227218
try

src/AvTranscoder/EssenceStream/OutputAudio.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "OutputEssence.hpp"
55

6-
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
6+
#include <AvTranscoder/CodedStructures/DataStream.hpp>
77
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
88
#include <AvTranscoder/EssenceStructures/AudioFrame.hpp>
99

src/AvTranscoder/EssenceStream/OutputEssence.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _AV_TRANSCODER_ESSENCE_STREAM_OUTPUT_ESSENCE_HPP_
33

44
#include <AvTranscoder/EssenceStructures/Frame.hpp>
5-
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
5+
#include <AvTranscoder/CodedStructures/DataStream.hpp>
66

77
namespace avtranscoder
88
{

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& frameDesc )
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( frameDesc );
199199

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

src/AvTranscoder/EssenceStream/OutputVideo.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "OutputEssence.hpp"
55

6-
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
6+
#include <AvTranscoder/CodedStructures/DataStream.hpp>
77
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>
88
#include <AvTranscoder/EssenceStructures/VideoFrame.hpp>
99

@@ -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& frameDesc );
3535

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

src/AvTranscoder/EssenceStructures/AudioFrame.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef _AV_TRANSCODER_DATA_AUDIO_FRAME_HPP_
22
#define _AV_TRANSCODER_DATA_AUDIO_FRAME_HPP_
33

4-
#include <AvTranscoder/common.hpp>
5-
64
#include "Frame.hpp"
5+
#include <AvTranscoder/Profile.hpp>
6+
#include <AvTranscoder/common.hpp>
77

88
namespace avtranscoder
99
{
@@ -21,12 +21,19 @@ class AvExport AudioFrameDesc
2121
void setSampleRate ( const size_t sampleRate ){ m_sampleRate = sampleRate; }
2222
void setChannels ( const size_t channels ){ m_channels = channels; }
2323
void setFps ( const size_t fps ){ m_fps = fps; }
24+
void setSampleFormat( const std::string& sampleFormatName ){ m_sampleFormat = av_get_sample_fmt( sampleFormatName.c_str() ); }
2425
void setSampleFormat( const AVSampleFormat sampleFormat ){ m_sampleFormat = sampleFormat; }
2526

2627
size_t getDataSize() const
2728
{
2829
return ( m_sampleRate / m_fps ) * m_channels * av_get_bytes_per_sample( m_sampleFormat );
2930
}
31+
32+
void setParameters( const Profile::ProfileDesc& desc )
33+
{
34+
if( desc.find( Profile::avProfileSampleFormat ) != desc.end() )
35+
setSampleFormat( desc.find( Profile::avProfileSampleFormat )->second );
36+
}
3037

3138
size_t getSampleRate() const { return m_sampleRate; }
3239
size_t getChannels () const { return m_channels; }

src/AvTranscoder/EssenceStructures/VideoFrame.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef _AV_TRANSCODER_DATA_IMAGE_HPP_
22
#define _AV_TRANSCODER_DATA_IMAGE_HPP_
33

4+
#include "Pixel.hpp"
5+
#include "Frame.hpp"
6+
#include <AvTranscoder/Profile.hpp>
47
#include <AvTranscoder/common.hpp>
58

69
extern "C" {
@@ -16,8 +19,6 @@ extern "C" {
1619

1720
#include <stdexcept>
1821

19-
#include "Pixel.hpp"
20-
#include "Frame.hpp"
2122

2223
namespace avtranscoder
2324
{
@@ -47,6 +48,12 @@ class AvExport VideoFrameDesc
4748
void setPixel ( const Pixel pixel ) { m_pixel = pixel; }
4849
void setDar ( const size_t num, const size_t den ) { m_displayAspectRatio.num = num; m_displayAspectRatio.den = den; }
4950
void setDar ( const Ratio ratio ) { m_displayAspectRatio = ratio; }
51+
52+
void setParameters( const Profile::ProfileDesc& desc )
53+
{
54+
if( desc.find( Profile::avProfilePixelFormat ) != desc.end() )
55+
setPixel( Pixel( desc.find( Profile::avProfilePixelFormat )->second.c_str() ) );
56+
}
5057

5158
size_t getWidth () const { return m_width; }
5259
size_t getHeight() const { return m_height; }

src/AvTranscoder/File/InputFile.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <AvTranscoder/common.hpp>
55

6-
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
6+
#include <AvTranscoder/CodedStructures/DataStream.hpp>
77
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
88
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>
99

src/AvTranscoder/File/OutputFile.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <AvTranscoder/common.hpp>
55

6-
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
6+
#include <AvTranscoder/CodedStructures/DataStream.hpp>
77
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>
88
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
99

src/AvTranscoder/Transcoder/StreamTranscoder.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,13 @@ StreamTranscoder::StreamTranscoder(
8181

8282
_outputEssence = outputVideo;
8383

84-
VideoFrameDesc outputVideoFrameDesc = _inputStream->getVideoDesc().getVideoFrameDesc();
85-
86-
outputVideoFrameDesc.setPixel( Pixel( profile.find( Profile::avProfilePixelFormat )->second.c_str() ) );
87-
88-
outputVideo->setProfile( profile, outputVideoFrameDesc );
84+
VideoFrameDesc outputFrameDesc = _inputStream->getVideoDesc().getVideoFrameDesc();
85+
outputFrameDesc.setParameters( profile );
86+
outputVideo->setProfile( profile, outputFrameDesc );
8987

9088
_outputStream = &outputFile.addVideoStream( outputVideo->getVideoDesc() );
9189

9290
_sourceBuffer = new VideoFrame( _inputStream->getVideoDesc().getVideoFrameDesc() );
93-
94-
// outputVideo->getVideoDesc().setImageParameters( _inputStream->getVideoDesc().getVideoFrameDesc().getWidth(), _inputStream->getVideoDesc().getVideoFrameDesc().getHeight(), av_get_pix_fmt( desc[ Profile::avProfilePixelFormat ].c_str() ) );
95-
9691
_frameBuffer = new VideoFrame( outputVideo->getVideoDesc().getVideoFrameDesc() );
9792

9893
_transform = new VideoEssenceTransform();
@@ -107,16 +102,23 @@ StreamTranscoder::StreamTranscoder(
107102
OutputAudio* outputAudio = new OutputAudio();
108103

109104
_outputEssence = outputAudio;
110-
AudioFrameDesc audioFrameDesc( _inputStream->getAudioDesc().getFrameDesc() );
111105

106+
AudioFrameDesc outputFrameDesc( _inputStream->getAudioDesc().getFrameDesc() );
107+
outputFrameDesc.setParameters( profile );
112108
if( subStreamIndex > -1 )
113-
audioFrameDesc.setChannels( 1 );
114-
115-
outputAudio->setProfile( profile, audioFrameDesc );
109+
{
110+
// @todo manage downmix ?
111+
outputFrameDesc.setChannels( 1 );
112+
}
113+
outputAudio->setProfile( profile, outputFrameDesc );
116114

117115
_outputStream = &outputFile.addAudioStream( outputAudio->getAudioDesc() );
118116

119-
_sourceBuffer = new AudioFrame( audioFrameDesc );
117+
AudioFrameDesc inputFrameDesc( _inputStream->getAudioDesc().getFrameDesc() );
118+
if( subStreamIndex > -1 )
119+
inputFrameDesc.setChannels( 1 );
120+
121+
_sourceBuffer = new AudioFrame( inputFrameDesc );
120122
_frameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() );
121123

122124
_transform = new AudioEssenceTransform();

src/AvTranscoder/Transcoder/Transcoder.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,6 @@ void Transcoder::addTranscodeStream( const std::string& filename, const size_t s
239239
switch( referenceFile->getStreamType( streamIndex ) )
240240
{
241241
case AVMEDIA_TYPE_VIDEO:
242-
{
243-
_streamTranscoders.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, profile ) );
244-
_inputStreams.push_back( &referenceFile->getStream( streamIndex ) );
245-
break;
246-
}
247242
case AVMEDIA_TYPE_AUDIO:
248243
{
249244
_streamTranscoders.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, profile ) );
@@ -267,11 +262,6 @@ void Transcoder::addTranscodeStream( const std::string& filename, const size_t s
267262
switch( referenceFile->getStreamType( streamIndex ) )
268263
{
269264
case AVMEDIA_TYPE_VIDEO:
270-
{
271-
_streamTranscoders.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, profile, subStreamIndex ) );
272-
_inputStreams.push_back( &referenceFile->getStream( streamIndex ) );
273-
break;
274-
}
275265
case AVMEDIA_TYPE_AUDIO:
276266
{
277267
_streamTranscoders.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, profile, subStreamIndex ) );

src/AvTranscoder/avTranscoder.i

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
%{
1212
#include <AvTranscoder/common.hpp>
1313

14+
#include <AvTranscoder/Profile.hpp>
15+
1416
#include <AvTranscoder/EssenceStructures/Pixel.hpp>
1517
#include <AvTranscoder/EssenceStructures/Frame.hpp>
1618
#include <AvTranscoder/EssenceStructures/VideoFrame.hpp>
@@ -19,7 +21,7 @@
1921
#include <AvTranscoder/CodedStructures/CodedDesc.hpp>
2022
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>
2123
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
22-
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
24+
#include <AvTranscoder/CodedStructures/DataStream.hpp>
2325

2426
#include <AvTranscoder/Metadatas/MediaMetadatasStructures.hpp>
2527

@@ -42,8 +44,6 @@
4244
#include <AvTranscoder/File/InputFile.hpp>
4345
#include <AvTranscoder/File/OutputFile.hpp>
4446

45-
#include <AvTranscoder/Profile.hpp>
46-
4747
#include <AvTranscoder/Transcoder/StreamTranscoder.hpp>
4848
#include <AvTranscoder/Transcoder/Transcoder.hpp>
4949

@@ -67,6 +67,8 @@ namespace std {
6767

6868
%include <AvTranscoder/common.hpp>
6969

70+
%include <AvTranscoder/Profile.hpp>
71+
7072
%include <AvTranscoder/EssenceStructures/Pixel.hpp>
7173
%include <AvTranscoder/EssenceStructures/Frame.hpp>
7274
%include <AvTranscoder/EssenceStructures/VideoFrame.hpp>
@@ -75,7 +77,7 @@ namespace std {
7577
%include <AvTranscoder/CodedStructures/CodedDesc.hpp>
7678
%include <AvTranscoder/CodedStructures/VideoDesc.hpp>
7779
%include <AvTranscoder/CodedStructures/AudioDesc.hpp>
78-
%include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
80+
%include <AvTranscoder/CodedStructures/DataStream.hpp>
7981

8082
%include <AvTranscoder/Metadatas/MediaMetadatasStructures.hpp>
8183

@@ -98,8 +100,6 @@ namespace std {
98100
%include <AvTranscoder/File/InputFile.hpp>
99101
%include <AvTranscoder/File/OutputFile.hpp>
100102

101-
%include <AvTranscoder/Profile.hpp>
102-
103103
%include <AvTranscoder/Transcoder/StreamTranscoder.hpp>
104104
%include <AvTranscoder/Transcoder/Transcoder.hpp>
105105

0 commit comments

Comments
 (0)