Skip to content

Refactoring & minor updates #32

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 15 commits into from
Jul 25, 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 src/AvTranscoder/CodedStream/AvInputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "InputStream.hpp"

#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
#include <AvTranscoder/CodedStructures/DataStream.hpp>

namespace avtranscoder
{
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/CodedStream/InputStream.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _AV_TRANSCODER_CODED_STREAM_INPUT_STREAM_HPP_
#define _AV_TRANSCODER_CODED_STREAM_INPUT_STREAM_HPP_

#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
#include <AvTranscoder/CodedStructures/DataStream.hpp>
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/CodedStream/OutputStream.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _AV_TRANSCODER_CODED_STREAM_OUTPUT_STREAM_HPP_
#define _AV_TRANSCODER_CODED_STREAM_OUTPUT_STREAM_HPP_

#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
#include <AvTranscoder/CodedStructures/DataStream.hpp>
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>

Expand Down
4 changes: 4 additions & 0 deletions src/AvTranscoder/CodedStructures/AudioDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const AVSampleFormat AudioDesc::getSampleFormat() const
return m_codecContext->sample_fmt;
}

void AudioDesc::setAudioParameters( const AudioFrameDesc& audioFrameDesc )
{
setAudioParameters( audioFrameDesc.getSampleRate(), audioFrameDesc.getChannels(), audioFrameDesc.getSampleFormat() );
}

void AudioDesc::setAudioParameters( const size_t sampleRate, const size_t channels, const AVSampleFormat sampleFormat )
{
Expand Down
1 change: 1 addition & 0 deletions src/AvTranscoder/CodedStructures/AudioDesc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AvExport AudioDesc : public CodedDesc
const size_t getChannels() const;
const AVSampleFormat getSampleFormat() const;

void setAudioParameters( const AudioFrameDesc& audioFrameDesc );
void setAudioParameters( const size_t sampleRate, const size_t channels, const AVSampleFormat sampleFormat );
};

Expand Down
14 changes: 9 additions & 5 deletions src/AvTranscoder/EssenceStream/InputAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ bool InputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex
const int output_align = 1;
size_t decodedSize = av_samples_get_buffer_size(NULL, output_nbChannels, _frame->nb_samples, _codecContext->sample_fmt, output_align);

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

if( subStreamIndex > nbSubStreams - 1 )
{
throw std::runtime_error( "The subStream doesn't exist");
}

AudioFrame& audioBuffer = static_cast<AudioFrame&>( frameBuffer );
audioBuffer.setNbSamples( _frame->nb_samples );

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

// @todo check little / big endian
// offset for little endian
src += ( nbChannels - 1 - subStreamIndex ) * bytePerSample;
// offset
src += ( nbSubStreams - 1 - subStreamIndex ) * bytePerSample;

for( int sample = 0; sample < _frame->nb_samples; ++sample )
{
Expand All @@ -169,7 +173,7 @@ bool InputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex
// std::cout << "dst " << static_cast<void *>(dst) << std::endl;
memcpy( dst, src, bytePerSample );
dst += bytePerSample;
src += bytePerSample * nbChannels;
src += bytePerSample * nbSubStreams;
}
}
return true;
Expand Down
19 changes: 5 additions & 14 deletions src/AvTranscoder/EssenceStream/OutputAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ extern "C" {

#include <iostream>
#include <stdexcept>
#include <cstdlib>

namespace avtranscoder
{
Expand Down Expand Up @@ -177,28 +176,22 @@ bool OutputAudio::encodeFrame( DataStream& codedFrame )
void OutputAudio::setProfile( const Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc )
{
if( ! desc.count( Profile::avProfileCodec ) ||
! desc.count( Profile::avProfileSampleFormat ) ||
! desc.count( Profile::avProfileSampleRate ) ||
! desc.count( Profile::avProfileChannel ) )
! desc.count( Profile::avProfileSampleFormat ) )
{
throw std::runtime_error( "The profile " + desc.find( Profile::avProfileIdentificatorHuman )->second + " is invalid." );
}

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

size_t sample_rate = std::strtoul( desc.find( Profile::avProfileSampleRate )->second.c_str(), NULL, 0 );
size_t channels = std::strtoul( desc.find( Profile::avProfileChannel )->second.c_str(), NULL, 0 );
_audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc.find( Profile::avProfileSampleFormat )->second.c_str() ) );

_audioDesc.setAudioParameters( frameDesc );

for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
{
if( (*it).first == Profile::avProfileIdentificator ||
(*it).first == Profile::avProfileIdentificatorHuman ||
(*it).first == Profile::avProfileType ||
(*it).first == Profile::avProfileCodec ||
(*it).first == Profile::avProfileSampleFormat ||
(*it).first == Profile::avProfileSampleRate ||
(*it).first == Profile::avProfileChannel )
(*it).first == Profile::avProfileSampleFormat )
continue;

try
Expand All @@ -219,9 +212,7 @@ void OutputAudio::setProfile( const Profile::ProfileDesc& desc, const AudioFrame
(*it).first == Profile::avProfileIdentificatorHuman ||
(*it).first == Profile::avProfileType ||
(*it).first == Profile::avProfileCodec ||
(*it).first == Profile::avProfileSampleFormat ||
(*it).first == Profile::avProfileSampleRate ||
(*it).first == Profile::avProfileChannel )
(*it).first == Profile::avProfileSampleFormat )
continue;

try
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/EssenceStream/OutputAudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "OutputEssence.hpp"

#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
#include <AvTranscoder/CodedStructures/DataStream.hpp>
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
#include <AvTranscoder/EssenceStructures/AudioFrame.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/EssenceStream/OutputEssence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _AV_TRANSCODER_ESSENCE_STREAM_OUTPUT_ESSENCE_HPP_

#include <AvTranscoder/EssenceStructures/Frame.hpp>
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
#include <AvTranscoder/CodedStructures/DataStream.hpp>

namespace avtranscoder
{
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/EssenceStream/OutputVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ bool OutputVideo::encodeFrame( DataStream& codedFrame )
#endif
}

void OutputVideo::setProfile( const Profile::ProfileDesc& desc, const avtranscoder::VideoFrameDesc& videoFrameDesc )
void OutputVideo::setProfile( const Profile::ProfileDesc& desc, const avtranscoder::VideoFrameDesc& frameDesc )
{
if( ! desc.count( Profile::avProfileCodec ) ||
! desc.count( Profile::avProfilePixelFormat ) ||
Expand All @@ -195,7 +195,7 @@ void OutputVideo::setProfile( const Profile::ProfileDesc& desc, const avtranscod
const size_t frameRate = std::strtoul( desc.find( Profile::avProfileFrameRate )->second.c_str(), NULL, 0 );
_videoDesc.setTimeBase( 1, frameRate );

_videoDesc.setImageParameters( videoFrameDesc );
_videoDesc.setImageParameters( frameDesc );

for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
{
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/EssenceStream/OutputVideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "OutputEssence.hpp"

#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
#include <AvTranscoder/CodedStructures/DataStream.hpp>
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>
#include <AvTranscoder/EssenceStructures/VideoFrame.hpp>

Expand Down Expand Up @@ -31,7 +31,7 @@ class AvExport OutputVideo : public OutputEssence
*/
bool encodeFrame( DataStream& codedFrame );

void setProfile( const Profile::ProfileDesc& desc, const avtranscoder::VideoFrameDesc& videoFrameDesc );
void setProfile( const Profile::ProfileDesc& desc, const avtranscoder::VideoFrameDesc& frameDesc );

VideoDesc& getVideoDesc() { return _videoDesc; }

Expand Down
11 changes: 9 additions & 2 deletions src/AvTranscoder/EssenceStructures/AudioFrame.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef _AV_TRANSCODER_DATA_AUDIO_FRAME_HPP_
#define _AV_TRANSCODER_DATA_AUDIO_FRAME_HPP_

#include <AvTranscoder/common.hpp>

#include "Frame.hpp"
#include <AvTranscoder/Profile.hpp>
#include <AvTranscoder/common.hpp>

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

size_t getDataSize() const
{
return ( m_sampleRate / m_fps ) * m_channels * av_get_bytes_per_sample( m_sampleFormat );
}

void setParameters( const Profile::ProfileDesc& desc )
{
if( desc.find( Profile::avProfileSampleFormat ) != desc.end() )
setSampleFormat( desc.find( Profile::avProfileSampleFormat )->second );
}

size_t getSampleRate() const { return m_sampleRate; }
size_t getChannels () const { return m_channels; }
Expand Down
11 changes: 9 additions & 2 deletions src/AvTranscoder/EssenceStructures/VideoFrame.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef _AV_TRANSCODER_DATA_IMAGE_HPP_
#define _AV_TRANSCODER_DATA_IMAGE_HPP_

#include "Pixel.hpp"
#include "Frame.hpp"
#include <AvTranscoder/Profile.hpp>
#include <AvTranscoder/common.hpp>

extern "C" {
Expand All @@ -16,8 +19,6 @@ extern "C" {

#include <stdexcept>

#include "Pixel.hpp"
#include "Frame.hpp"

namespace avtranscoder
{
Expand Down Expand Up @@ -47,6 +48,12 @@ class AvExport VideoFrameDesc
void setPixel ( const Pixel pixel ) { m_pixel = pixel; }
void setDar ( const size_t num, const size_t den ) { m_displayAspectRatio.num = num; m_displayAspectRatio.den = den; }
void setDar ( const Ratio ratio ) { m_displayAspectRatio = ratio; }

void setParameters( const Profile::ProfileDesc& desc )
{
if( desc.find( Profile::avProfilePixelFormat ) != desc.end() )
setPixel( Pixel( desc.find( Profile::avProfilePixelFormat )->second.c_str() ) );
}

size_t getWidth () const { return m_width; }
size_t getHeight() const { return m_height; }
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/File/InputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <AvTranscoder/common.hpp>

#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
#include <AvTranscoder/CodedStructures/DataStream.hpp>
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/File/OutputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <AvTranscoder/common.hpp>

#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
#include <AvTranscoder/CodedStructures/DataStream.hpp>
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>

Expand Down
28 changes: 15 additions & 13 deletions src/AvTranscoder/Transcoder/StreamTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,13 @@ StreamTranscoder::StreamTranscoder(

_outputEssence = outputVideo;

VideoFrameDesc outputVideoFrameDesc = _inputStream->getVideoDesc().getVideoFrameDesc();

outputVideoFrameDesc.setPixel( Pixel( profile.find( Profile::avProfilePixelFormat )->second.c_str() ) );

outputVideo->setProfile( profile, outputVideoFrameDesc );
VideoFrameDesc outputFrameDesc = _inputStream->getVideoDesc().getVideoFrameDesc();
outputFrameDesc.setParameters( profile );
outputVideo->setProfile( profile, outputFrameDesc );

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

_sourceBuffer = new VideoFrame( _inputStream->getVideoDesc().getVideoFrameDesc() );

// outputVideo->getVideoDesc().setImageParameters( _inputStream->getVideoDesc().getVideoFrameDesc().getWidth(), _inputStream->getVideoDesc().getVideoFrameDesc().getHeight(), av_get_pix_fmt( desc[ Profile::avProfilePixelFormat ].c_str() ) );

_frameBuffer = new VideoFrame( outputVideo->getVideoDesc().getVideoFrameDesc() );

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

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

AudioFrameDesc outputFrameDesc( _inputStream->getAudioDesc().getFrameDesc() );
outputFrameDesc.setParameters( profile );
if( subStreamIndex > -1 )
audioFrameDesc.setChannels( 1 );

outputAudio->setProfile( profile, audioFrameDesc );
{
// @todo manage downmix ?
outputFrameDesc.setChannels( 1 );
}
outputAudio->setProfile( profile, outputFrameDesc );

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

_sourceBuffer = new AudioFrame( audioFrameDesc );
AudioFrameDesc inputFrameDesc( _inputStream->getAudioDesc().getFrameDesc() );
if( subStreamIndex > -1 )
inputFrameDesc.setChannels( 1 );

_sourceBuffer = new AudioFrame( inputFrameDesc );
_frameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() );

_transform = new AudioEssenceTransform();
Expand Down
10 changes: 0 additions & 10 deletions src/AvTranscoder/Transcoder/Transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@ void Transcoder::addTranscodeStream( const std::string& filename, const size_t s
switch( referenceFile->getStreamType( streamIndex ) )
{
case AVMEDIA_TYPE_VIDEO:
{
_streamTranscoders.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, profile ) );
_inputStreams.push_back( &referenceFile->getStream( streamIndex ) );
break;
}
case AVMEDIA_TYPE_AUDIO:
{
_streamTranscoders.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, profile ) );
Expand All @@ -267,11 +262,6 @@ void Transcoder::addTranscodeStream( const std::string& filename, const size_t s
switch( referenceFile->getStreamType( streamIndex ) )
{
case AVMEDIA_TYPE_VIDEO:
{
_streamTranscoders.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, profile, subStreamIndex ) );
_inputStreams.push_back( &referenceFile->getStream( streamIndex ) );
break;
}
case AVMEDIA_TYPE_AUDIO:
{
_streamTranscoders.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, profile, subStreamIndex ) );
Expand Down
12 changes: 6 additions & 6 deletions src/AvTranscoder/avTranscoder.i
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
%{
#include <AvTranscoder/common.hpp>

#include <AvTranscoder/Profile.hpp>

#include <AvTranscoder/EssenceStructures/Pixel.hpp>
#include <AvTranscoder/EssenceStructures/Frame.hpp>
#include <AvTranscoder/EssenceStructures/VideoFrame.hpp>
Expand All @@ -19,7 +21,7 @@
#include <AvTranscoder/CodedStructures/CodedDesc.hpp>
#include <AvTranscoder/CodedStructures/VideoDesc.hpp>
#include <AvTranscoder/CodedStructures/AudioDesc.hpp>
#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
#include <AvTranscoder/CodedStructures/DataStream.hpp>

#include <AvTranscoder/Metadatas/MediaMetadatasStructures.hpp>

Expand All @@ -42,8 +44,6 @@
#include <AvTranscoder/File/InputFile.hpp>
#include <AvTranscoder/File/OutputFile.hpp>

#include <AvTranscoder/Profile.hpp>

#include <AvTranscoder/Transcoder/StreamTranscoder.hpp>
#include <AvTranscoder/Transcoder/Transcoder.hpp>

Expand All @@ -65,6 +65,8 @@ namespace std {

%include <AvTranscoder/common.hpp>

%include <AvTranscoder/Profile.hpp>

%include <AvTranscoder/EssenceStructures/Pixel.hpp>
%include <AvTranscoder/EssenceStructures/Frame.hpp>
%include <AvTranscoder/EssenceStructures/VideoFrame.hpp>
Expand All @@ -73,7 +75,7 @@ namespace std {
%include <AvTranscoder/CodedStructures/CodedDesc.hpp>
%include <AvTranscoder/CodedStructures/VideoDesc.hpp>
%include <AvTranscoder/CodedStructures/AudioDesc.hpp>
%include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>
%include <AvTranscoder/CodedStructures/DataStream.hpp>

%include <AvTranscoder/Metadatas/MediaMetadatasStructures.hpp>

Expand All @@ -96,8 +98,6 @@ namespace std {
%include <AvTranscoder/File/InputFile.hpp>
%include <AvTranscoder/File/OutputFile.hpp>

%include <AvTranscoder/Profile.hpp>

%include <AvTranscoder/Transcoder/StreamTranscoder.hpp>
%include <AvTranscoder/Transcoder/Transcoder.hpp>