Skip to content

Dev refactoring #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/avTranscoder/avTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )

videoDesc.setTimeBase( 1, 25 ); // 25 fps

videoDesc.setImageParameters( sourceImage );
videoDesc.setImageParameters( sourceImage.desc() );

//videoDesc.initCodecContext();

Expand Down
13 changes: 7 additions & 6 deletions app/avplay/AvReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class AvReader : public Reader
{
public:
AvReader( std::string filename )
AvReader( const std::string& filename )
: m_inputFile( filename )
, m_inputStreamVideo( NULL )
, m_sourceImage( NULL )
Expand All @@ -38,11 +38,11 @@ class AvReader : public Reader
pixel.setAlpha( false );
pixel.setPlanar( false );

imageDescToDisplay.setWidth ( m_sourceImage->desc().getWidth() );
imageDescToDisplay.setWidth( m_sourceImage->desc().getWidth() );
imageDescToDisplay.setHeight( m_sourceImage->desc().getHeight() );
imageDescToDisplay.setDar ( m_sourceImage->desc().getDar() );

imageDescToDisplay.setPixel ( pixel.findPixel() );
imageDescToDisplay.setDar( m_sourceImage->desc().getDar() );
imageDescToDisplay.setPixel( pixel.findPixel() );

m_imageToDisplay = new avtranscoder::Image( imageDescToDisplay );
}
Expand Down Expand Up @@ -105,6 +105,7 @@ class AvReader : public Reader

private:
avtranscoder::InputFile m_inputFile;

avtranscoder::InputStreamVideo* m_inputStreamVideo;

avtranscoder::Image* m_sourceImage;
Expand All @@ -117,4 +118,4 @@ class AvReader : public Reader
size_t m_videoStream;
};

#endif
#endif
9 changes: 6 additions & 3 deletions src/AvTranscoder/AvInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ AvInputStream::AvInputStream( )
{
}

AvInputStream::AvInputStream( InputFile* inputFile, const size_t streamIndex )
AvInputStream::AvInputStream( InputFile& inputFile, const size_t streamIndex )
: InputStream( )
, m_inputFile( inputFile )
, m_inputFile( &inputFile )
, m_packetDuration( 0 )
, m_streamIndex( streamIndex )
, m_bufferized( false )
Expand All @@ -44,6 +44,9 @@ AvInputStream::~AvInputStream( )

bool AvInputStream::readNextPacket( DataStream& data )
{
if( ! m_bufferized )
throw std::runtime_error( "Can't read packet on non-bufferized input stream." );

if( m_streamCache.empty() )
m_inputFile->readNextPacket( m_streamIndex );

Expand Down Expand Up @@ -137,4 +140,4 @@ void AvInputStream::clearBuffering()
m_streamCache.clear();
}

}
}
2 changes: 1 addition & 1 deletion src/AvTranscoder/AvInputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AvExport AvInputStream : public InputStream
public:
AvInputStream( );

AvInputStream( InputFile* inputFile, const size_t streamIndex );
AvInputStream( InputFile& inputFile, const size_t streamIndex );
~AvInputStream( );

AvInputStream( const AvInputStream& inputStream )
Expand Down
9 changes: 7 additions & 2 deletions src/AvTranscoder/DatasStructures/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ extern "C" {
namespace avtranscoder
{

typedef std::vector< unsigned char > DataBuffer;

// struct ColorProperties
// {
// //EColorspace eColorspace;
Expand Down Expand Up @@ -78,9 +76,14 @@ class AvExport ImageDesc
bool m_topFieldFirst;
};

//template< template<typename> Alloc >
//class AvExport ImageBase
class AvExport Image
{
public:
// typedef std::vector< unsigned char, Alloc<unsigned char> > DataBuffer;
typedef std::vector< unsigned char> DataBuffer;

Image( const ImageDesc& ref )
: m_dataBuffer( ref.getDataSize(), 0 )
, m_imageDesc( ref )
Expand All @@ -99,6 +102,8 @@ class AvExport Image
const ImageDesc m_imageDesc;
};

//typedef ImageBase<std::allocator> Image;

}

#endif
4 changes: 2 additions & 2 deletions src/AvTranscoder/DatasStructures/VideoDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ void VideoDesc::setVideoCodec( const AVCodecID codecId )
initCodecContext();
}

void VideoDesc::setImageParameters( const Image& image )
void VideoDesc::setImageParameters( const ImageDesc& imageDesc )
{
setImageParameters( image.desc().getWidth(), image.desc().getHeight(), image.desc().getPixelDesc() );
setImageParameters( imageDesc.getWidth(), imageDesc.getHeight(), imageDesc.getPixelDesc() );
}


Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/DatasStructures/VideoDesc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AvExport VideoDesc
void setVideoCodec( const std::string& codecName );
void setVideoCodec( const AVCodecID codecId );

void setImageParameters( const Image& image );
void setImageParameters( const ImageDesc& imageDesc );
void setImageParameters( const size_t width, const size_t height, const Pixel& pixel );
void setImageParameters( const size_t width, const size_t height, const AVPixelFormat& pixel );

Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/InputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ InputFile::InputFile( const std::string& filename )

for( size_t streamIndex = 0; streamIndex < m_formatContext->nb_streams; ++streamIndex )
{
m_inputStreams.push_back( new AvInputStream( this, streamIndex ) );
m_inputStreams.push_back( new AvInputStream( *this, streamIndex ) );
}
}

Expand Down Expand Up @@ -180,7 +180,7 @@ bool InputFile::readNextPacket( const size_t streamIndex )

void InputFile::seekAtFrame( const size_t frame )
{
uint64_t pos = frame / 25 * AV_TIME_BASE;
uint64_t pos = frame / 25 * AV_TIME_BASE; // WARNING: hardcoded fps

if( (int)m_formatContext->start_time != AV_NOPTS_VALUE )
pos += m_formatContext->start_time;
Expand Down
3 changes: 2 additions & 1 deletion src/AvTranscoder/InputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ class AvExport InputFile

AVMediaType getStreamType( size_t index );

::avtranscoder::AvInputStream& getStream( size_t index );
AvInputStream& getStream( size_t index );

AVFormatContext& getFormatContext() const { return *m_formatContext; }

bool readNextPacket( const size_t streamIndex );

void seekAtFrame( const size_t frame );

/// @brief Indicate that the stream should be bufferized
void readStream( const size_t streamIndex, const bool readStream = true );

protected:
Expand Down
4 changes: 1 addition & 3 deletions src/AvTranscoder/InputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class InputStream

virtual bool readNextPacket( DataStream& data ) = 0;

// Stream propeerties
// Stream properties
virtual VideoDesc getVideoDesc() const = 0;
virtual AudioDesc getAudioDesc() const = 0;

Expand All @@ -30,8 +30,6 @@ class InputStream
virtual void setBufferred( const bool bufferized ) = 0;

virtual void clearBuffering() = 0;

private:
};

}
Expand Down
13 changes: 9 additions & 4 deletions src/AvTranscoder/InputStreamAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ InputStreamAudio::InputStreamAudio( const InputStream& inputStream )
std::cout << "Audio codec Id : " << m_codecContext->codec_id << std::endl;
std::cout << "Audio codec Id : " << m_codec->long_name << std::endl;

m_codecContext->channels = m_inputStream->getAudioDesc().getCodecContext()->channels;

int ret = avcodec_open2( m_codecContext, m_codec, NULL );

std::cout << "ret value : " << ret << std::endl;
Expand Down Expand Up @@ -99,8 +101,7 @@ InputStreamAudio::~InputStreamAudio()

bool InputStreamAudio::readNextFrame( AudioFrame& audioFrameBuffer )
{
/*
int got_frame = 0;
/*int got_frame = 0;
while( ! got_frame )
{
AVPacket packet;
Expand All @@ -112,6 +113,10 @@ bool InputStreamAudio::readNextFrame( AudioFrame& audioFrameBuffer )
return false;
}

packet.stream_index = m_selectedStream;
packet.data = audioFrameBuffer.getPtr();
packet.size = audioFrameBuffer.getSize();

int ret = avcodec_decode_audio4( m_codecContext, m_frame, &got_frame, &packet );

if( ret < 0 )
Expand All @@ -120,8 +125,8 @@ bool InputStreamAudio::readNextFrame( AudioFrame& audioFrameBuffer )
}

av_free_packet( &packet );
}*/

}
*/
//size_t unpadded_linesize = m_frame->nb_samples * av_get_bytes_per_sample( m_frame->format );

// size_t decodedSize = avpicture_get_size( (AVPixelFormat)m_frame->format, m_frame->width, m_frame->height );
Expand Down
1 change: 0 additions & 1 deletion src/AvTranscoder/InputStreamVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ InputStreamVideo::~InputStreamVideo()

bool InputStreamVideo::readNextFrame( Image& frameBuffer )
{

int got_frame = 0;

while( ! got_frame )
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/InputStreamVideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AvExport InputStreamVideo
public:
InputStreamVideo( AvInputStream& inputStream );
~InputStreamVideo();

bool readNextFrame( Image& frameBuffer );

void flushDecoder();
Expand Down
5 changes: 3 additions & 2 deletions src/AvTranscoder/Transcoder.tcc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#include <AvTranscoder/InputFile.hpp>

#include <AvTranscoder/AvInputStream.hpp>
Expand Down Expand Up @@ -66,13 +67,13 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex )
{
case AVMEDIA_TYPE_VIDEO:
{
_inputStreams.push_back( &referenceFile->getStream( streamIndex ) );
_inputStreams.push_back( & referenceFile->getStream( streamIndex ) );
_outputFile.addVideoStream( _inputStreams.back()->getVideoDesc() );
break;
}
case AVMEDIA_TYPE_AUDIO:
{
_inputStreams.push_back( &referenceFile->getStream( streamIndex ) );
_inputStreams.push_back( & referenceFile->getStream( streamIndex ) );
_outputFile.addAudioStream( _inputStreams.back()->getAudioDesc() );
break;
}
Expand Down
14 changes: 8 additions & 6 deletions src/AvTranscoder/avTranscoder.i
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@

#include <AvTranscoder/Metadatas/MediaMetadatasStructures.hpp>

#include <AvTranscoder/InputFile.hpp>
#include <AvTranscoder/OutputFile.hpp>

#include <AvTranscoder/OutputStream.hpp>
#include <AvTranscoder/OutputStreamAudio.hpp>
#include <AvTranscoder/OutputStreamVideo.hpp>

#include <AvTranscoder/InputStream.hpp>
#include <AvTranscoder/AvInputStream.hpp>
#include <AvTranscoder/InputStreamAudio.hpp>
#include <AvTranscoder/InputStreamVideo.hpp>

#include <AvTranscoder/InputFile.hpp>
#include <AvTranscoder/OutputFile.hpp>

#include <AvTranscoder/Transcoder.hpp>

%}
Expand Down Expand Up @@ -59,15 +60,16 @@ namespace std {

%include <AvTranscoder/Metadatas/MediaMetadatasStructures.hpp>

%include <AvTranscoder/InputFile.hpp>
%include <AvTranscoder/OutputFile.hpp>

%include <AvTranscoder/OutputStream.hpp>
%include <AvTranscoder/OutputStreamAudio.hpp>
%include <AvTranscoder/OutputStreamVideo.hpp>

%include <AvTranscoder/InputStream.hpp>
%include <AvTranscoder/AvInputStream.hpp>
%include <AvTranscoder/InputStreamAudio.hpp>
%include <AvTranscoder/InputStreamVideo.hpp>

%include <AvTranscoder/InputFile.hpp>
%include <AvTranscoder/OutputFile.hpp>

%include <AvTranscoder/Transcoder.hpp>