Skip to content

Commit a771f86

Browse files
Merge branch 'dev_streams' into dev_streamsProcessor
Conflicts: src/AvTranscoder/OutputStreamAudio.hpp src/AvTranscoder/OutputStreamVideo.hpp src/AvTranscoder/avTranscoder.i
2 parents b92a264 + 0177a09 commit a771f86

31 files changed

+519
-166
lines changed

app/genericProcessor/genericProcessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <cstdlib>
1010

1111

12-
void parseConfigFile( const std::string& configFilename, avtranscoder::Transcoder::StreamsDefinition& streams )
12+
void parseConfigFile( const std::string& configFilename, avtranscoder::Transcoder::InputStreamsDesc& streams )
1313
{
1414
std::ifstream configFile( configFilename.c_str(), std::ifstream::in );
1515

@@ -24,7 +24,7 @@ void parseConfigFile( const std::string& configFilename, avtranscoder::Transcode
2424
if( std::getline( is_line, streamId ) )
2525
{
2626
std::cout << filename << " ( " << streamId << " )" << std::endl;
27-
streams.push_back( std::pair< std::string, int >( filename, atoi( streamId.c_str() ) ) );
27+
streams.push_back( avtranscoder::Transcoder::InputStreamDesc( atoi( streamId.c_str() ), filename, "" ) );
2828
}
2929
}
3030
}
@@ -49,7 +49,7 @@ int main( int argc, char** argv )
4949
std::string inputConfigFile( argv[1] );
5050
avtranscoder::OutputFile outputFile( argv[2] );
5151

52-
avtranscoder::Transcoder::StreamsDefinition streams;
52+
avtranscoder::Transcoder::InputStreamsDesc streams;
5353

5454
parseConfigFile( inputConfigFile, streams );
5555

src/AvTranscoder/AvInputStream.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ VideoDesc AvInputStream::getVideoDesc() const
103103
VideoDesc desc( codecContext->codec_id );
104104

105105
desc.setImageParameters( codecContext->width, codecContext->height, codecContext->pix_fmt );
106-
desc.setTimeBase( codecContext->time_base.num, codecContext->time_base.den );
106+
desc.setTimeBase( codecContext->time_base.num, codecContext->time_base.den, codecContext->ticks_per_frame );
107107

108108
return desc;
109109
}
@@ -126,6 +126,10 @@ AudioDesc AvInputStream::getAudioDesc() const
126126
return desc;
127127
}
128128

129+
AVMediaType AvInputStream::getStreamType() const
130+
{
131+
return m_inputFile->getStreamType( m_streamIndex );
132+
}
129133

130134
double AvInputStream::getDuration() const
131135
{

src/AvTranscoder/AvInputStream.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class AvExport AvInputStream : public InputStream
3232
VideoDesc getVideoDesc() const;
3333
AudioDesc getAudioDesc() const;
3434

35+
AVMediaType getStreamType() const;
36+
3537
double getDuration() const;
3638
double getPacketDuration() const;
3739

src/AvTranscoder/AvOutputStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ AvOutputStream::~AvOutputStream()
2323

2424
bool AvOutputStream::wrap( DataStream& data )
2525
{
26-
_outputFile->wrap( data, _streamIndex );
26+
return _outputFile->wrap( data, _streamIndex );
2727
}
2828

2929
VideoDesc AvOutputStream::getVideoDesc() const

src/AvTranscoder/DatasStructures/AudioFrame.hpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ extern "C" {
2020
#include <stdexcept>
2121

2222
//#include "Sample.hpp"
23+
#include "Frame.hpp"
2324

2425
namespace avtranscoder
2526
{
2627

27-
typedef std::vector< unsigned char > DataBuffer;
28-
29-
class AudioFrameDesc
28+
class AvExport AudioFrameDesc
3029
{
3130
public:
3231
AudioFrameDesc()
@@ -59,28 +58,22 @@ class AudioFrameDesc
5958
AVSampleFormat m_sampleFormat;
6059
};
6160

62-
class AudioFrame
61+
class AvExport AudioFrame : public Frame
6362
{
6463
public:
6564
AudioFrame( const AudioFrameDesc& ref )
66-
: m_dataBuffer( ref.getDataSize(), 0 )
67-
, m_audioFrameDesc( ref )
65+
: m_audioFrameDesc( ref )
6866
, m_nbSamples( 0 )
69-
{ }
67+
{
68+
m_dataBuffer = DataBuffer( ref.getDataSize(), (unsigned char) 0 );
69+
}
7070

7171
const AudioFrameDesc& desc() const { return m_audioFrameDesc; }
72-
DataBuffer& getBuffer() { return m_dataBuffer; }
73-
unsigned char* getPtr() { return &m_dataBuffer[0]; }
74-
#ifndef SWIG
75-
const unsigned char* getPtr() const { return &m_dataBuffer[0]; }
76-
#endif
77-
size_t getSize() const { return m_dataBuffer.size(); }
7872

7973
size_t getNbSamples() const { return m_nbSamples; }
8074
void setNbSamples( size_t nbSamples ) { m_nbSamples = nbSamples; }
8175

8276
private:
83-
DataBuffer m_dataBuffer;
8477
const AudioFrameDesc m_audioFrameDesc;
8578
size_t m_nbSamples;
8679
};
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
#ifndef _AV_TRANSCODER_DATA_FRAME_HPP_
22
#define _AV_TRANSCODER_DATA_FRAME_HPP_
33

4+
#include <AvTranscoder/common.hpp>
5+
46
#include <string>
7+
#include <vector>
58

69
namespace avtranscoder
710
{
811

9-
class Frame
12+
typedef std::vector< unsigned char> DataBuffer;
13+
14+
class AvExport Frame
1015
{
1116
public:
12-
Frame(){};
1317

14-
private:
18+
Frame() {};
19+
20+
virtual DataBuffer& getBuffer() { return m_dataBuffer; }
21+
virtual unsigned char* getPtr() { return &m_dataBuffer[0]; }
22+
#ifndef SWIG
23+
virtual const unsigned char* getPtr() const { return &m_dataBuffer[0]; }
24+
#endif
25+
virtual size_t getSize() const { return m_dataBuffer.size(); }
26+
27+
protected:
28+
DataBuffer m_dataBuffer;
1529

1630
};
1731

1832
}
1933

20-
#endif
34+
#endif

src/AvTranscoder/DatasStructures/Image.hpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern "C" {
2020
#include <stdexcept>
2121

2222
#include "Pixel.hpp"
23+
#include "Frame.hpp"
2324

2425
namespace avtranscoder
2526
{
@@ -78,27 +79,18 @@ class AvExport ImageDesc
7879

7980
//template< template<typename> Alloc >
8081
//class AvExport ImageBase
81-
class AvExport Image
82+
class AvExport Image : public Frame
8283
{
8384
public:
84-
// typedef std::vector< unsigned char, Alloc<unsigned char> > DataBuffer;
85-
typedef std::vector< unsigned char> DataBuffer;
86-
8785
Image( const ImageDesc& ref )
88-
: m_dataBuffer( ref.getDataSize(), 0 )
89-
, m_imageDesc( ref )
90-
{ }
86+
: m_imageDesc( ref )
87+
{
88+
m_dataBuffer = DataBuffer( ref.getDataSize(), 0 );
89+
}
9190

9291
const ImageDesc& desc() const { return m_imageDesc; }
93-
DataBuffer& getBuffer() { return m_dataBuffer; }
94-
unsigned char* getPtr() { return &m_dataBuffer[0]; }
95-
#ifndef SWIG
96-
const unsigned char* getPtr() const { return &m_dataBuffer[0]; }
97-
#endif
98-
size_t getSize() const { return m_dataBuffer.size(); }
9992

10093
private:
101-
DataBuffer m_dataBuffer;
10294
const ImageDesc m_imageDesc;
10395
};
10496

src/AvTranscoder/DatasStructures/VideoDesc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ void VideoDesc::setImageParameters( const size_t width, const size_t height, con
6767
m_codecContext->pix_fmt = pixel;
6868
}
6969

70-
void VideoDesc::setTimeBase( const size_t num, const size_t den )
70+
void VideoDesc::setTimeBase( const size_t num, const size_t den, const size_t ticksPerFrame )
7171
{
7272
m_codecContext->time_base.num = num;
7373
m_codecContext->time_base.den = den;
74+
m_codecContext->ticks_per_frame = ticksPerFrame;
7475
}
7576

7677
std::string VideoDesc::getVideoCodec() const

src/AvTranscoder/DatasStructures/VideoDesc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AvExport VideoDesc
3434
void setImageParameters( const size_t width, const size_t height, const Pixel& pixel );
3535
void setImageParameters( const size_t width, const size_t height, const AVPixelFormat& pixel );
3636

37-
void setTimeBase( const size_t num, const size_t den );
37+
void setTimeBase( const size_t num, const size_t den, const size_t ticksPerFrame = 1 );
3838

3939
void set( const std::string& key, const std::string& flag, const bool enable );
4040
void set( const std::string& key, const bool value );

src/AvTranscoder/DummyInputStream.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ AudioDesc DummyInputStream::getAudioDesc() const
5252
return m_audioDesc;
5353
}
5454

55+
AVMediaType DummyInputStream::getStreamType() const
56+
{
57+
//TODO return different type whether it's an audio or video type
58+
return AVMEDIA_TYPE_AUDIO;
59+
}
5560

5661
double DummyInputStream::getDuration() const
5762
{

src/AvTranscoder/DummyInputStream.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class AvExport DummyInputStream : public InputStream
3131
VideoDesc getVideoDesc() const;
3232
AudioDesc getAudioDesc() const;
3333

34+
AVMediaType getStreamType() const;
35+
3436
double getDuration() const;
3537
double getPacketDuration() const;
3638

src/AvTranscoder/InputStream.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ class InputStream
2222
// Stream properties
2323
virtual VideoDesc getVideoDesc() const = 0;
2424
virtual AudioDesc getAudioDesc() const = 0;
25+
26+
virtual AVMediaType getStreamType() const = 0;
2527

2628
virtual double getDuration() const = 0;
2729
virtual double getPacketDuration() const = 0;
2830

2931
virtual void setBufferred( const bool bufferized ) = 0;
3032

3133
virtual void clearBuffering() = 0;
34+
3235
};
3336

3437
}

src/AvTranscoder/InputStreamAudio.cpp

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,41 @@ extern "C" {
1919
namespace avtranscoder
2020
{
2121

22-
InputStreamAudio::InputStreamAudio( AvInputStream& inputStream )
23-
: m_inputStream ( &inputStream )
22+
InputStreamAudio::InputStreamAudio( AvInputStream& inputStream )
23+
: InputStreamReader::InputStreamReader( inputStream )
24+
, m_inputStream ( &inputStream )
2425
, m_codec ( NULL )
2526
, m_codecContext ( NULL )
2627
, m_frame ( NULL )
2728
, m_selectedStream( -1 )
29+
{
30+
}
31+
32+
InputStreamAudio::~InputStreamAudio()
33+
{
34+
if( m_codecContext != NULL )
35+
{
36+
avcodec_close( m_codecContext );
37+
av_free( m_codecContext );
38+
m_codecContext = NULL;
39+
}
40+
if( m_frame != NULL )
41+
{
42+
#if LIBAVCODEC_VERSION_MAJOR > 54
43+
av_frame_free( &m_frame );
44+
#else
45+
#if LIBAVCODEC_VERSION_MAJOR > 53
46+
avcodec_free_frame( &m_frame );
47+
#else
48+
av_free( m_frame );
49+
#endif
50+
#endif
51+
m_frame = NULL;
52+
}
53+
}
54+
55+
56+
void InputStreamAudio::setup()
2857
{
2958
avcodec_register_all();
3059

@@ -77,30 +106,7 @@ InputStreamAudio::InputStreamAudio( AvInputStream& inputStream )
77106
}
78107
}
79108

80-
InputStreamAudio::~InputStreamAudio()
81-
{
82-
if( m_codecContext != NULL )
83-
{
84-
avcodec_close( m_codecContext );
85-
av_free( m_codecContext );
86-
m_codecContext = NULL;
87-
}
88-
if( m_frame != NULL )
89-
{
90-
#if LIBAVCODEC_VERSION_MAJOR > 54
91-
av_frame_free( &m_frame );
92-
#else
93-
#if LIBAVCODEC_VERSION_MAJOR > 53
94-
avcodec_free_frame( &m_frame );
95-
#else
96-
av_free( m_frame );
97-
#endif
98-
#endif
99-
m_frame = NULL;
100-
}
101-
}
102-
103-
bool InputStreamAudio::readNextFrame( AudioFrame& audioFrameBuffer )
109+
bool InputStreamAudio::readNextFrame( Frame& frameBuffer )
104110
{
105111
int got_frame = 0;
106112
while( ! got_frame )
@@ -133,14 +139,16 @@ bool InputStreamAudio::readNextFrame( AudioFrame& audioFrameBuffer )
133139
m_frame->nb_samples,
134140
m_codecContext->sample_fmt, 1);
135141

136-
audioFrameBuffer.setNbSamples( m_frame->nb_samples );
142+
AudioFrame& audioBuffer = static_cast<AudioFrame&>( frameBuffer );
143+
144+
audioBuffer.setNbSamples( m_frame->nb_samples );
137145

138146
if( decodedSize )
139147
{
140-
if( audioFrameBuffer.getSize() != decodedSize )
141-
audioFrameBuffer.getBuffer().resize( decodedSize, 0 );
148+
if( audioBuffer.getSize() != decodedSize )
149+
audioBuffer.getBuffer().resize( decodedSize, 0 );
142150

143-
unsigned char* dst = audioFrameBuffer.getPtr();
151+
unsigned char* dst = audioBuffer.getPtr();
144152
av_samples_copy(&dst, (uint8_t* const* )m_frame->data, 0,
145153
0, m_frame->nb_samples, m_codecContext->channels,
146154
m_codecContext->sample_fmt);

src/AvTranscoder/InputStreamAudio.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
#ifndef _AV_TRANSCODER_INPUT_STREAM_AUDIO_HPP_
22
#define _AV_TRANSCODER_INPUT_STREAM_AUDIO_HPP_
33

4-
#include "InputStream.hpp"
4+
#include "InputStreamReader.hpp"
55
#include "DatasStructures/AudioFrame.hpp"
66

7+
class AVFormatContext;
8+
class AVCodec;
9+
class AVCodecContext;
10+
class AVFrame;
11+
712
namespace avtranscoder
813
{
914

1015
class AvInputStream;
1116

12-
class AvExport InputStreamAudio
17+
class AvExport InputStreamAudio : public InputStreamReader
1318
{
1419
public:
1520
InputStreamAudio( AvInputStream& inputStream );
1621
~InputStreamAudio();
1722

18-
bool readNextFrame( AudioFrame& audioFrameBuffer );
23+
void setup();
24+
25+
bool readNextFrame( Frame& frameBuffer );
1926

2027
private:
2128
AvInputStream* m_inputStream;
@@ -28,4 +35,4 @@ class AvExport InputStreamAudio
2835

2936
}
3037

31-
#endif
38+
#endif

0 commit comments

Comments
 (0)