Skip to content

Dev process stat #200

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 11 commits into from
Jun 8, 2015
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/avPlay/AvReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ AvReader::AvReader( const std::string& filename )
_inputFile.activateStream( _videoStream );

_inputVideo = new avtranscoder::VideoDecoder( _inputFile.getStream( _videoStream ) );
_inputVideo->setup();
_inputVideo->setupDecoder();

_sourceImage = new avtranscoder::VideoFrame( _inputFile.getStream( _videoStream ).getVideoCodec().getVideoFrameDesc() );

Expand Down
1 change: 1 addition & 0 deletions src/AvTranscoder/avTranscoder.i
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
%include "AvTranscoder/encoder/encoder.i"
%include "AvTranscoder/transform/transform.i"
%include "AvTranscoder/file/file.i"
%include "AvTranscoder/stat/stat.i"
%include "AvTranscoder/transcoder/transcoder.i"
66 changes: 32 additions & 34 deletions src/AvTranscoder/decoder/AudioDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,39 @@ AudioDecoder::~AudioDecoder()
}


void AudioDecoder::setup()
void AudioDecoder::setupDecoder( const ProfileLoader::Profile& profile )
{
LOG_DEBUG( "Set profile of audio decoder with:\n" << profile )

AudioCodec& codec = _inputStream->getAudioCodec();

// set threads before any other options
if( profile.count( constants::avProfileThreads ) )
codec.getOption( constants::avProfileThreads ).setString( profile.at( constants::avProfileThreads ) );
else
codec.getOption( constants::avProfileThreads ).setString( "auto" );

// set decoder options
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
{
if( (*it).first == constants::avProfileIdentificator ||
(*it).first == constants::avProfileIdentificatorHuman ||
(*it).first == constants::avProfileType ||
(*it).first == constants::avProfileThreads )
continue;

try
{
Option& decodeOption = codec.getOption( (*it).first );
decodeOption.setString( (*it).second );
}
catch( std::exception& e )
{
LOG_WARN( "AudioDecoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
}
}

// open decoder
_inputStream->getAudioCodec().openCodec();
}

Expand Down Expand Up @@ -145,37 +176,4 @@ bool AudioDecoder::decodeNextFrame()
return true;
}

void AudioDecoder::setProfile( const ProfileLoader::Profile& profile )
{
LOG_DEBUG( "Set profile of audio decoder with:\n" << profile )

AudioCodec& codec = _inputStream->getAudioCodec();

// set threads before any other options
if( profile.count( constants::avProfileThreads ) )
codec.getOption( constants::avProfileThreads ).setString( profile.at( constants::avProfileThreads ) );
else
codec.getOption( constants::avProfileThreads ).setString( "auto" );

// set decoder options
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
{
if( (*it).first == constants::avProfileIdentificator ||
(*it).first == constants::avProfileIdentificatorHuman ||
(*it).first == constants::avProfileType ||
(*it).first == constants::avProfileThreads )
continue;

try
{
Option& decodeOption = codec.getOption( (*it).first );
decodeOption.setString( (*it).second );
}
catch( std::exception& e )
{
LOG_WARN( "AudioDecoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
}
}
}

}
5 changes: 1 addition & 4 deletions src/AvTranscoder/decoder/AudioDecoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define _AV_TRANSCODER_ESSENCE_STREAM_AV_INPUT_AUDIO_HPP_

#include "IDecoder.hpp"
#include <AvTranscoder/profile/ProfileLoader.hpp>

struct AVFrame;

Expand All @@ -17,13 +16,11 @@ class AvExport AudioDecoder : public IDecoder
AudioDecoder( InputStream& inputStream );
~AudioDecoder();

void setup();
void setupDecoder( const ProfileLoader::Profile& profile = ProfileLoader::Profile() );

bool decodeNextFrame( Frame& frameBuffer );
bool decodeNextFrame( Frame& frameBuffer, const size_t subStreamIndex );

void setProfile( const ProfileLoader::Profile& profile );

private:
bool decodeNextFrame();

Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/decoder/AudioGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AvExport AudioGenerator : public IDecoder

~AudioGenerator();

void setup() {}
void setupDecoder( const ProfileLoader::Profile& profile = ProfileLoader::Profile() ) {}

bool decodeNextFrame( Frame& frameBuffer );
bool decodeNextFrame( Frame& frameBuffer, const size_t subStreamIndex );
Expand Down
7 changes: 5 additions & 2 deletions src/AvTranscoder/decoder/IDecoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <AvTranscoder/common.hpp>
#include <AvTranscoder/frame/Frame.hpp>
#include <AvTranscoder/profile/ProfileLoader.hpp>

namespace avtranscoder
{
Expand All @@ -13,9 +14,11 @@ class AvExport IDecoder
virtual ~IDecoder() {};

/**
* @brief Open the decoder
* @brief Setup the decoder
* @param profile: set decoder parameters from the given profile
* @note Open the decoder.
*/
virtual void setup() = 0;
virtual void setupDecoder( const ProfileLoader::Profile& profile = ProfileLoader::Profile() ) = 0;

/**
* @brief Decode next frame
Expand Down
66 changes: 32 additions & 34 deletions src/AvTranscoder/decoder/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,39 @@ VideoDecoder::~VideoDecoder()
}
}

void VideoDecoder::setup()
void VideoDecoder::setupDecoder( const ProfileLoader::Profile& profile )
{
LOG_DEBUG( "Set profile of video decoder with:\n" << profile )

VideoCodec& codec = _inputStream->getVideoCodec();

// set threads before any other options
if( profile.count( constants::avProfileThreads ) )
codec.getOption( constants::avProfileThreads ).setString( profile.at( constants::avProfileThreads ) );
else
codec.getOption( constants::avProfileThreads ).setString( "auto" );

// set decoder options
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
{
if( (*it).first == constants::avProfileIdentificator ||
(*it).first == constants::avProfileIdentificatorHuman ||
(*it).first == constants::avProfileType ||
(*it).first == constants::avProfileThreads )
continue;

try
{
Option& decodeOption = codec.getOption( (*it).first );
decodeOption.setString( (*it).second );
}
catch( std::exception& e )
{
LOG_WARN( "VideoDecoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
}
}

// open decoder
_inputStream->getVideoCodec().openCodec();
}

Expand Down Expand Up @@ -104,37 +135,4 @@ void VideoDecoder::flushDecoder()
avcodec_flush_buffers( &_inputStream->getVideoCodec().getAVCodecContext() );
}

void VideoDecoder::setProfile( const ProfileLoader::Profile& profile )
{
LOG_DEBUG( "Set profile of video decoder with:\n" << profile )

VideoCodec& codec = _inputStream->getVideoCodec();

// set threads before any other options
if( profile.count( constants::avProfileThreads ) )
codec.getOption( constants::avProfileThreads ).setString( profile.at( constants::avProfileThreads ) );
else
codec.getOption( constants::avProfileThreads ).setString( "auto" );

// set decoder options
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
{
if( (*it).first == constants::avProfileIdentificator ||
(*it).first == constants::avProfileIdentificatorHuman ||
(*it).first == constants::avProfileType ||
(*it).first == constants::avProfileThreads )
continue;

try
{
Option& decodeOption = codec.getOption( (*it).first );
decodeOption.setString( (*it).second );
}
catch( std::exception& e )
{
LOG_WARN( "VideoDecoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
}
}
}

}
9 changes: 3 additions & 6 deletions src/AvTranscoder/decoder/VideoDecoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define _AV_TRANSCODER_DECODER_VIDEO_DECODER_HPP_

#include "IDecoder.hpp"
#include <AvTranscoder/profile/ProfileLoader.hpp>

struct AVFrame;

Expand All @@ -16,16 +15,14 @@ class AvExport VideoDecoder : public IDecoder
public:
VideoDecoder( InputStream& inputStream );
~VideoDecoder();
void setup();

void setupDecoder( const ProfileLoader::Profile& profile = ProfileLoader::Profile() );

bool decodeNextFrame( Frame& frameBuffer );
bool decodeNextFrame( Frame& frameBuffer, const size_t subStreamIndex );

void flushDecoder();

void setProfile( const ProfileLoader::Profile& profile );


private:
bool decodeNextFrame();

Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/decoder/VideoGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AvExport VideoGenerator : public IDecoder

~VideoGenerator();

void setup() {}
void setupDecoder( const ProfileLoader::Profile& profile = ProfileLoader::Profile() ) {}

bool decodeNextFrame( Frame& frameBuffer );
bool decodeNextFrame( Frame& frameBuffer, const size_t subStreamIndex );
Expand Down
120 changes: 61 additions & 59 deletions src/AvTranscoder/encoder/AudioEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,69 @@ AudioEncoder::~AudioEncoder()
#endif
}

void AudioEncoder::setup()
void AudioEncoder::setupAudioEncoder( const AudioFrameDesc& frameDesc, const ProfileLoader::Profile& profile )
{
LOG_DEBUG( "Set profile of audio encoder with:\n" << profile )

// set sampleRate, number of channels, sample format
_codec.setAudioParameters( frameDesc );

// setup encoder
setupEncoder( profile );
}

void AudioEncoder::setupEncoder( const ProfileLoader::Profile& profile )
{
// set threads before any other options
if( profile.count( constants::avProfileThreads ) )
_codec.getOption( constants::avProfileThreads ).setString( profile.at( constants::avProfileThreads ) );
else
_codec.getOption( constants::avProfileThreads ).setString( "auto" );


// set encoder options
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
{
if( (*it).first == constants::avProfileIdentificator ||
(*it).first == constants::avProfileIdentificatorHuman ||
(*it).first == constants::avProfileType ||
(*it).first == constants::avProfileCodec ||
(*it).first == constants::avProfileSampleFormat ||
(*it).first == constants::avProfileThreads )
continue;

try
{
Option& encodeOption = _codec.getOption( (*it).first );
encodeOption.setString( (*it).second );
}
catch( std::exception& e )
{}
}

// open encoder
_codec.openCodec();

for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
{
if( (*it).first == constants::avProfileIdentificator ||
(*it).first == constants::avProfileIdentificatorHuman ||
(*it).first == constants::avProfileType ||
(*it).first == constants::avProfileCodec ||
(*it).first == constants::avProfileSampleFormat ||
(*it).first == constants::avProfileThreads )
continue;

try
{
Option& encodeOption = _codec.getOption( (*it).first );
encodeOption.setString( (*it).second );
}
catch( std::exception& e )
{
LOG_WARN( "AudioEncoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
}
}
}

bool AudioEncoder::encodeFrame( const Frame& sourceFrame, Frame& codedFrame )
Expand Down Expand Up @@ -133,63 +193,5 @@ bool AudioEncoder::encodeFrame( Frame& codedFrame )
#endif
}

void AudioEncoder::setProfile( const ProfileLoader::Profile& profile, const AudioFrameDesc& frameDesc )
{
LOG_DEBUG( "Set profile of audio encoder with:\n" << profile )

// set sampleRate, number of channels, sample format
_codec.setAudioParameters( frameDesc );

// set threads before any other options
if( profile.count( constants::avProfileThreads ) )
_codec.getOption( constants::avProfileThreads ).setString( profile.at( constants::avProfileThreads ) );
else
_codec.getOption( constants::avProfileThreads ).setString( "auto" );


// set encoder options
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
{
if( (*it).first == constants::avProfileIdentificator ||
(*it).first == constants::avProfileIdentificatorHuman ||
(*it).first == constants::avProfileType ||
(*it).first == constants::avProfileCodec ||
(*it).first == constants::avProfileSampleFormat ||
(*it).first == constants::avProfileThreads )
continue;

try
{
Option& encodeOption = _codec.getOption( (*it).first );
encodeOption.setString( (*it).second );
}
catch( std::exception& e )
{}
}

setup();

for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
{
if( (*it).first == constants::avProfileIdentificator ||
(*it).first == constants::avProfileIdentificatorHuman ||
(*it).first == constants::avProfileType ||
(*it).first == constants::avProfileCodec ||
(*it).first == constants::avProfileSampleFormat ||
(*it).first == constants::avProfileThreads )
continue;

try
{
Option& encodeOption = _codec.getOption( (*it).first );
encodeOption.setString( (*it).second );
}
catch( std::exception& e )
{
LOG_WARN( "AudioEncoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
}
}
}

}

Loading