Skip to content

Fix audio demultiplexing #31

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 8 commits into from
Jul 24, 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
7 changes: 3 additions & 4 deletions src/AvTranscoder/CodedStructures/AudioDesc.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#ifndef _AV_TRANSCODER_DATA_AUDIO_DESC_HPP_
#define _AV_TRANSCODER_DATA_AUDIO_DESC_HPP_

#include <string>

#include <AvTranscoder/common.hpp>
#include <AvTranscoder/EssenceStructures/AudioFrame.hpp>

#include "CodedDesc.hpp"
#include <AvTranscoder/common.hpp>

#include <string>

class AVCodec;

Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/CodedStructures/VideoDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}


Expand Down
9 changes: 4 additions & 5 deletions src/AvTranscoder/CodedStructures/VideoDesc.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#ifndef _AV_TRANSCODER_DATA_VIDEO_DESC_HPP_
#define _AV_TRANSCODER_DATA_VIDEO_DESC_HPP_

#include <string>

#include <AvTranscoder/common.hpp>
#include <AvTranscoder/EssenceStructures/VideoFrame.hpp>

#include "CodedDesc.hpp"
#include <AvTranscoder/common.hpp>

#include <string>

class AVCodec;

Expand All @@ -23,7 +22,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 );

Expand Down
23 changes: 9 additions & 14 deletions src/AvTranscoder/EssenceStream/InputAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,34 +139,29 @@ 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<AudioFrame&>( 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 )
{
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();

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 << " ==| ";
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& videoFrameDesc )
{
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( videoFrameDesc );

for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
{
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/EssenceStream/OutputVideo.hpp
Original file line number Diff line number Diff line change
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& videoFrameDesc );

VideoDesc& getVideoDesc() { return _videoDesc; }

Expand Down
9 changes: 9 additions & 0 deletions src/AvTranscoder/EssenceStructures/VideoFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
5 changes: 5 additions & 0 deletions src/AvTranscoder/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ namespace avtranscoder

struct Ratio
{
Ratio()
: num( 0 )
, den( 0 )
{}

size_t num;
size_t den;
};
Expand Down