From f4ed2b868cf9b80b37a39abcbf34888d3e13879f Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 24 Jul 2014 14:08:46 +0200 Subject: [PATCH 1/8] Audio demultiplexing: fix little endian case * It was an offset problem. --- src/AvTranscoder/EssenceStream/InputAudio.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/AvTranscoder/EssenceStream/InputAudio.cpp b/src/AvTranscoder/EssenceStream/InputAudio.cpp index 1343e0b4..053ed616 100644 --- a/src/AvTranscoder/EssenceStream/InputAudio.cpp +++ b/src/AvTranscoder/EssenceStream/InputAudio.cpp @@ -162,11 +162,13 @@ bool InputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex unsigned char* src = *_frame->data; unsigned char* dst = audioBuffer.getPtr(); - src += ( nbChannels - 1 ) - ( subStreamIndex * bytePerSample ); - // std::cout << "frame samples count " << _frame->nb_samples << std::endl; // std::cout << "frame data size " << audioBuffer.getSize() << std::endl; + // @todo check little / big endian + // offset for little endian + src += ( nbChannels - 1 - subStreamIndex ) * bytePerSample; + for( int sample = 0; sample < _frame->nb_samples; ++sample ) { // std::cout << "sample " << sample << " ==| "; From 48f854ea00a3e6997b2fc05adf9d278348c2f6a7 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 24 Jul 2014 14:11:31 +0200 Subject: [PATCH 2/8] InputAudio: refactoring readNextFrame with subStream * Suppress comments. * Add todo. --- src/AvTranscoder/EssenceStream/InputAudio.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/AvTranscoder/EssenceStream/InputAudio.cpp b/src/AvTranscoder/EssenceStream/InputAudio.cpp index 053ed616..0137d369 100644 --- a/src/AvTranscoder/EssenceStream/InputAudio.cpp +++ b/src/AvTranscoder/EssenceStream/InputAudio.cpp @@ -139,19 +139,14 @@ bool InputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex if( ! getNextFrame() ) return false; - size_t decodedSize = av_samples_get_buffer_size(NULL, 1, - _frame->nb_samples, - _codecContext->sample_fmt, 1); + const int output_nbChannels = 1; + 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 bytePerSample = av_get_bytes_per_sample( (AVSampleFormat)_frame->format ); AudioFrame& audioBuffer = static_cast( frameBuffer ); - - // std::cout << "needed size " << audioBuffer.desc().getDataSize() << std::endl; - - // std::cout << _frame->nb_samples * bytePerSample << std::endl; - //audioBuffer.getBuffer().resize( _frame->nb_samples * bytePerSample ); audioBuffer.setNbSamples( _frame->nb_samples ); if( decodedSize ) @@ -159,12 +154,10 @@ bool InputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex if( audioBuffer.getSize() != decodedSize ) audioBuffer.getBuffer().resize( decodedSize, 0 ); - unsigned char* src = *_frame->data; + // @todo manage cases with data of frame not only on data[0] (use _frame.linesize) + unsigned char* src = _frame->data[0]; unsigned char* dst = audioBuffer.getPtr(); - // std::cout << "frame samples count " << _frame->nb_samples << std::endl; - // std::cout << "frame data size " << audioBuffer.getSize() << std::endl; - // @todo check little / big endian // offset for little endian src += ( nbChannels - 1 - subStreamIndex ) * bytePerSample; From 89bcaef1851551566f953c6cfced050e555f8007 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 24 Jul 2014 15:19:42 +0200 Subject: [PATCH 3/8] VideoDesc: refactoring - rename local variable --- src/AvTranscoder/CodedStructures/VideoDesc.cpp | 4 ++-- src/AvTranscoder/CodedStructures/VideoDesc.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AvTranscoder/CodedStructures/VideoDesc.cpp b/src/AvTranscoder/CodedStructures/VideoDesc.cpp index 1335b9d4..96c83433 100644 --- a/src/AvTranscoder/CodedStructures/VideoDesc.cpp +++ b/src/AvTranscoder/CodedStructures/VideoDesc.cpp @@ -44,9 +44,9 @@ std::pair< size_t, size_t > VideoDesc::getTimeBase() const return timeBase; } -void VideoDesc::setImageParameters( const VideoFrameDesc& VideoFrameDesc ) +void VideoDesc::setImageParameters( const VideoFrameDesc& videoFrameDesc ) { - setImageParameters( VideoFrameDesc.getWidth(), VideoFrameDesc.getHeight(), VideoFrameDesc.getPixelDesc() ); + setImageParameters( videoFrameDesc.getWidth(), videoFrameDesc.getHeight(), videoFrameDesc.getPixelDesc() ); } diff --git a/src/AvTranscoder/CodedStructures/VideoDesc.hpp b/src/AvTranscoder/CodedStructures/VideoDesc.hpp index b50da314..7b4dcbb9 100644 --- a/src/AvTranscoder/CodedStructures/VideoDesc.hpp +++ b/src/AvTranscoder/CodedStructures/VideoDesc.hpp @@ -23,7 +23,7 @@ class AvExport VideoDesc : public CodedDesc VideoFrameDesc getVideoFrameDesc() const; std::pair< size_t, size_t > getTimeBase() const; - void setImageParameters( const VideoFrameDesc& VideoFrameDesc ); + void setImageParameters( const VideoFrameDesc& videoFrameDesc ); 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 ); From 07f56886671bea456e5f4bbbc5ff4c605f61133d Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 24 Jul 2014 15:20:14 +0200 Subject: [PATCH 4/8] VideoDesc: refactoring - reorder includes --- src/AvTranscoder/CodedStructures/VideoDesc.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/AvTranscoder/CodedStructures/VideoDesc.hpp b/src/AvTranscoder/CodedStructures/VideoDesc.hpp index 7b4dcbb9..e21fb748 100644 --- a/src/AvTranscoder/CodedStructures/VideoDesc.hpp +++ b/src/AvTranscoder/CodedStructures/VideoDesc.hpp @@ -1,12 +1,11 @@ #ifndef _AV_TRANSCODER_DATA_VIDEO_DESC_HPP_ #define _AV_TRANSCODER_DATA_VIDEO_DESC_HPP_ -#include - -#include #include - #include "CodedDesc.hpp" +#include + +#include class AVCodec; From 40acbca6dcec29a5c9729953e13ef95d8646a4a9 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 24 Jul 2014 15:20:57 +0200 Subject: [PATCH 5/8] AudioDesc: refactoring - reorder includes --- src/AvTranscoder/CodedStructures/AudioDesc.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/AvTranscoder/CodedStructures/AudioDesc.hpp b/src/AvTranscoder/CodedStructures/AudioDesc.hpp index 280bfbdf..2a7c5b74 100644 --- a/src/AvTranscoder/CodedStructures/AudioDesc.hpp +++ b/src/AvTranscoder/CodedStructures/AudioDesc.hpp @@ -1,12 +1,11 @@ #ifndef _AV_TRANSCODER_DATA_AUDIO_DESC_HPP_ #define _AV_TRANSCODER_DATA_AUDIO_DESC_HPP_ -#include - -#include #include - #include "CodedDesc.hpp" +#include + +#include class AVCodec; From 1d42f16fdeb9c3fbddcb7231c5ca6b964672370f Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 24 Jul 2014 15:21:31 +0200 Subject: [PATCH 6/8] Ratio: add default constructor --- src/AvTranscoder/common.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AvTranscoder/common.hpp b/src/AvTranscoder/common.hpp index 075234ff..3999e0cf 100644 --- a/src/AvTranscoder/common.hpp +++ b/src/AvTranscoder/common.hpp @@ -55,6 +55,11 @@ namespace avtranscoder struct Ratio { + Ratio() + : num( 0 ) + , den( 0 ) + {} + size_t num; size_t den; }; From a10dc3fe318c700a5b310e8718c6352cb04525e3 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 24 Jul 2014 15:22:12 +0200 Subject: [PATCH 7/8] VideoFrameDesc: add default constructor --- src/AvTranscoder/EssenceStructures/VideoFrame.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/AvTranscoder/EssenceStructures/VideoFrame.hpp b/src/AvTranscoder/EssenceStructures/VideoFrame.hpp index f7e8c2f5..fe0e9bce 100644 --- a/src/AvTranscoder/EssenceStructures/VideoFrame.hpp +++ b/src/AvTranscoder/EssenceStructures/VideoFrame.hpp @@ -33,6 +33,15 @@ namespace avtranscoder class AvExport VideoFrameDesc { public: + VideoFrameDesc() + : m_width( 0 ) + , m_height( 0 ) + , m_displayAspectRatio() + , m_pixel() + , m_interlaced( false ) + , m_topFieldFirst( false ) + {}; + void setWidth ( const size_t width ) { m_width = width; } void setHeight( const size_t height ) { m_height = height; } void setPixel ( const Pixel pixel ) { m_pixel = pixel; } From 3f2678f4caf69717c74379fae5b662c2116b7dd0 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 24 Jul 2014 15:23:34 +0200 Subject: [PATCH 8/8] OutputVideo: refactoring - rename local variable --- src/AvTranscoder/EssenceStream/OutputVideo.cpp | 4 ++-- src/AvTranscoder/EssenceStream/OutputVideo.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AvTranscoder/EssenceStream/OutputVideo.cpp b/src/AvTranscoder/EssenceStream/OutputVideo.cpp index 80bf4ceb..d440e71d 100644 --- a/src/AvTranscoder/EssenceStream/OutputVideo.cpp +++ b/src/AvTranscoder/EssenceStream/OutputVideo.cpp @@ -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& videoFrameDesc ) { if( ! desc.count( Profile::avProfileCodec ) || ! desc.count( Profile::avProfilePixelFormat ) || @@ -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( videoFrameDesc ); for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it ) { diff --git a/src/AvTranscoder/EssenceStream/OutputVideo.hpp b/src/AvTranscoder/EssenceStream/OutputVideo.hpp index 5334501b..065e30dc 100644 --- a/src/AvTranscoder/EssenceStream/OutputVideo.hpp +++ b/src/AvTranscoder/EssenceStream/OutputVideo.hpp @@ -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& videoFrameDesc ); VideoDesc& getVideoDesc() { return _videoDesc; }