Skip to content

Commit 708c1f9

Browse files
author
Valentin Noel
committed
Merge commits fixes and add OutputStreamWriter
1 parent d898aaf commit 708c1f9

18 files changed

+194
-134
lines changed

app/genericProcessor/genericProcessor.cpp

Lines changed: 2 additions & 2 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::StreamDefinitions& streams )
12+
void parseConfigFile( const std::string& configFilename, avtranscoder::Transcoder::InputStreamsDesc& streams )
1313
{
1414
std::ifstream configFile( configFilename.c_str(), std::ifstream::in );
1515

@@ -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::StreamDefinitions streams;
52+
avtranscoder::Transcoder::InputStreamsDesc streams;
5353

5454
parseConfigFile( inputConfigFile, streams );
5555

src/AvTranscoder/AvInputStream.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/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
@@ -23,13 +23,16 @@ class InputStream
2323
// Stream properties
2424
virtual VideoDesc getVideoDesc() const = 0;
2525
virtual AudioDesc getAudioDesc() const = 0;
26+
27+
virtual AVMediaType getStreamType() const = 0;
2628

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

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

3234
virtual void clearBuffering() = 0;
35+
3336
};
3437

3538
}

src/AvTranscoder/InputStreamAudio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace avtranscoder
2020
{
2121

2222
InputStreamAudio::InputStreamAudio( AvInputStream& inputStream )
23-
: InputStreamReader::InputStreamReader( inputStream )
23+
: InputStreamReader::InputStreamReader( inputStream )
2424
, m_inputStream ( &inputStream )
2525
, m_codec ( NULL )
2626
, m_codecContext ( NULL )

src/AvTranscoder/InputStreamReader.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class AvExport InputStreamReader
1212
{
1313
public:
1414
InputStreamReader( AvInputStream& inputStream ) {};
15-
// virtual ~InputStreamReader() = 0;
1615

1716
virtual void setup() = 0;
1817

src/AvTranscoder/OutputStreamAudio.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ extern "C" {
99
#include <libavutil/avutil.h>
1010
}
1111

12+
#include "DatasStructures/AudioFrame.hpp"
1213
#include "Profile.hpp"
1314

1415
namespace avtranscoder
1516
{
1617

1718
OutputStreamAudio::OutputStreamAudio()
18-
: m_audioDesc( "pcm_s16le" )
19+
: OutputStreamWriter::OutputStreamWriter()
20+
, m_audioDesc( "pcm_s16le" )
1921
{
2022
}
2123

2224
bool OutputStreamAudio::setup()
2325
{
24-
std::cout << "[OutputStreamAudio::setup] ..." << std::endl;
2526
av_register_all(); // Warning: should be called only once
2627

2728
AVCodecContext* codecContext( m_audioDesc.getCodecContext() );
@@ -36,7 +37,7 @@ bool OutputStreamAudio::setup()
3637
return true;
3738
}
3839

39-
bool OutputStreamAudio::encodeFrame( const AudioFrame& decodedFrame, DataStream& codedFrame )
40+
bool OutputStreamAudio::encodeFrame( const Frame& sourceFrame, DataStream& codedFrame )
4041
{
4142
#if LIBAVCODEC_VERSION_MAJOR > 54
4243
AVFrame* frame = av_frame_alloc();
@@ -52,8 +53,10 @@ bool OutputStreamAudio::encodeFrame( const AudioFrame& decodedFrame, DataStream&
5253
#else
5354
avcodec_get_frame_defaults( frame );
5455
#endif
56+
57+
const AudioFrame& sourceAudioFrame = static_cast<const AudioFrame&>( sourceFrame );
5558

56-
frame->nb_samples = decodedFrame.getNbSamples();
59+
frame->nb_samples = sourceAudioFrame.getNbSamples();
5760
frame->format = codecContext->sample_fmt;
5861
frame->channel_layout = codecContext->channel_layout;
5962

@@ -67,7 +70,7 @@ bool OutputStreamAudio::encodeFrame( const AudioFrame& decodedFrame, DataStream&
6770
throw std::runtime_error( "EncodeFrame error: buffer size < 0 - " + std::string(err) );
6871
}
6972

70-
int retvalue = avcodec_fill_audio_frame(frame, codecContext->channels, codecContext->sample_fmt, decodedFrame.getPtr(), buffer_size, 0);
73+
int retvalue = avcodec_fill_audio_frame(frame, codecContext->channels, codecContext->sample_fmt, sourceAudioFrame.getPtr(), buffer_size, 0);
7174
if( retvalue < 0 )
7275
{
7376
char err[250];

src/AvTranscoder/OutputStreamAudio.hpp

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

4-
#include "OutputStream.hpp"
5-
#include "DatasStructures/AudioFrame.hpp"
4+
#include "OutputStreamWriter.hpp"
65
#include "DatasStructures/AudioDesc.hpp"
76
#include "DatasStructures/DataStreamDesc.hpp"
87

98
namespace avtranscoder
109
{
1110

12-
class OutputStreamAudio : public OutputStream
11+
class OutputStreamAudio : public OutputStreamWriter
1312
{
1413
public:
1514
OutputStreamAudio();
@@ -19,7 +18,7 @@ class OutputStreamAudio : public OutputStream
1918
/**
2019
* @param[out] codedFrame
2120
*/
22-
bool encodeFrame( const AudioFrame& decodedFrame, DataStream& codedFrame );
21+
bool encodeFrame( const Frame& sourceFrame, DataStream& codedFrame );
2322

2423
/**
2524
* get delayed encoded frames

src/AvTranscoder/OutputStreamVideo.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212
#include <libavutil/mathematics.h>
1313
}
1414

15+
#include "DatasStructures/Image.hpp"
1516
#include "Profile.hpp"
1617

1718
#include <iostream>
@@ -20,7 +21,8 @@ namespace avtranscoder
2021
{
2122

2223
OutputStreamVideo::OutputStreamVideo( )
23-
: m_videoDesc( "mpeg2video" )
24+
: OutputStreamWriter::OutputStreamWriter( )
25+
, m_videoDesc( "mpeg2video" )
2426
{
2527
}
2628

@@ -41,7 +43,7 @@ bool OutputStreamVideo::setup( )
4143
}
4244

4345

44-
bool OutputStreamVideo::encodeFrame( const Image& sourceImage, DataStream& codedFrame )
46+
bool OutputStreamVideo::encodeFrame( const Frame& sourceFrame, DataStream& codedFrame )
4547
{
4648
#if LIBAVCODEC_VERSION_MAJOR > 54
4749
AVFrame* frame = av_frame_alloc();
@@ -58,10 +60,12 @@ bool OutputStreamVideo::encodeFrame( const Image& sourceImage, DataStream& coded
5860
avcodec_get_frame_defaults( frame );
5961
#endif
6062

63+
const Image& sourceImageFrame = static_cast<const Image&>( sourceFrame );
64+
6165
frame->width = codecContext->width;
6266
frame->height = codecContext->height;
6367
frame->format = codecContext->pix_fmt;
64-
avpicture_fill( (AVPicture*)frame, const_cast< unsigned char * >( sourceImage.getPtr() ), codecContext->pix_fmt, codecContext->width, codecContext->height );
68+
avpicture_fill( (AVPicture*)frame, const_cast< unsigned char * >( sourceImageFrame.getPtr() ), codecContext->pix_fmt, codecContext->width, codecContext->height );
6569

6670
AVPacket packet;
6771
av_init_packet( &packet );
@@ -87,6 +91,7 @@ bool OutputStreamVideo::encodeFrame( const Image& sourceImage, DataStream& coded
8791
packet.flags |= AV_PKT_FLAG_KEY;
8892
}
8993

94+
9095
#if LIBAVCODEC_VERSION_MAJOR > 53
9196
int gotPacket = 0;
9297
int ret = avcodec_encode_video2( codecContext, &packet, frame, &gotPacket );

src/AvTranscoder/OutputStreamVideo.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ extern "C" {
88
#include <libavutil/pixfmt.h>
99
}
1010

11-
#include "OutputStream.hpp"
11+
#include "OutputStreamWriter.hpp"
1212

13-
#include "DatasStructures/Image.hpp"
1413
#include "DatasStructures/VideoDesc.hpp"
1514
#include "DatasStructures/DataStreamDesc.hpp"
1615

@@ -23,7 +22,7 @@ class AVCodecContext;
2322
namespace avtranscoder
2423
{
2524

26-
class AvExport OutputStreamVideo : public OutputStream
25+
class AvExport OutputStreamVideo : public OutputStreamWriter
2726
{
2827
public:
2928
OutputStreamVideo();
@@ -33,9 +32,9 @@ class AvExport OutputStreamVideo : public OutputStream
3332
//void setVideoDesc( const VideoDesc& videoDesc );
3433

3534
/**
36-
* @param[out] codecFrame blabla
35+
* @param[out] codedFrame blabla
3736
*/
38-
bool encodeFrame( const Image& sourceImage, DataStream& codedFrame );
37+
bool encodeFrame( const Frame& sourceFrame, DataStream& codedFrame );
3938

4039
/**
4140
* get delayed encoded frames
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef _AV_TRANSCODER_OUTPUT_STREAM_WRITER_HPP_
2+
#define _AV_TRANSCODER_OUTPUT_STREAM_WRITER_HPP_
3+
4+
extern "C" {
5+
#ifndef __STDC_CONSTANT_MACROS
6+
#define __STDC_CONSTANT_MACROS
7+
#endif
8+
#include <libavutil/pixfmt.h>
9+
}
10+
11+
#include <string>
12+
#include <vector>
13+
14+
#include "DatasStructures/Frame.hpp"
15+
#include "DatasStructures/DataStreamDesc.hpp"
16+
17+
namespace avtranscoder
18+
{
19+
20+
class AvExport OutputStreamWriter
21+
{
22+
public:
23+
OutputStreamWriter()
24+
{
25+
}
26+
27+
virtual bool setup() = 0;
28+
29+
/**
30+
* @param[in] sourceFrame
31+
* @param[out] codedFrame
32+
*/
33+
virtual bool encodeFrame( const Frame& sourceFrame, DataStream& codedFrame ) = 0;
34+
35+
/**
36+
* get delayed encoded frames
37+
*/
38+
virtual bool encodeFrame( DataStream& codedFrame ) = 0;
39+
40+
virtual void setProfile( const std::string& profile ) = 0;
41+
42+
};
43+
44+
}
45+
46+
#endif

0 commit comments

Comments
 (0)