Skip to content

Refactoring & clean #29

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
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
8 changes: 4 additions & 4 deletions app/avTranscoder/avTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )

// init video decoders
InputVideo inputVideo( input.getStream( 0 ) );
ImageDesc imageDesc = input.getStream( 0 ).getVideoDesc().getImageDesc();
Image sourceImage( imageDesc );
VideoFrameDesc VideoFrameDesc = input.getStream( 0 ).getVideoDesc().getVideoFrameDesc();
VideoFrame sourceImage( VideoFrameDesc );

// init video encoder
OutputVideo outputVideo;
outputVideo.setProfile( profile.getProfile( "xdcamhd422" ), imageDesc );
Image imageToEncode( outputVideo.getVideoDesc().getImageDesc() );
outputVideo.setProfile( profile.getProfile( "xdcamhd422" ), VideoFrameDesc );
VideoFrame imageToEncode( outputVideo.getVideoDesc().getVideoFrameDesc() );

DataStream codedImage;

Expand Down
18 changes: 9 additions & 9 deletions app/avplay/AvReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AvReader : public Reader

m_inputVideo->setup();

m_sourceImage = new avtranscoder::Image( m_inputFile.getStream( m_videoStream ).getVideoDesc().getImageDesc() );
m_sourceImage = new avtranscoder::VideoFrame( m_inputFile.getStream( m_videoStream ).getVideoDesc().getVideoFrameDesc() );

pixel.setBitsPerPixel( getComponents() * getBitDepth() );
pixel.setComponents( getComponents() );
Expand All @@ -38,13 +38,13 @@ class AvReader : public Reader
pixel.setAlpha( false );
pixel.setPlanar( false );

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

imageDescToDisplay.setPixel( pixel.findPixel() );
VideoFrameDescToDisplay.setPixel( pixel.findPixel() );

m_imageToDisplay = new avtranscoder::Image( imageDescToDisplay );
m_imageToDisplay = new avtranscoder::VideoFrame( VideoFrameDescToDisplay );
}

~AvReader()
Expand Down Expand Up @@ -106,11 +106,11 @@ class AvReader : public Reader

avtranscoder::InputVideo* m_inputVideo;

avtranscoder::Image* m_sourceImage;
avtranscoder::Image* m_imageToDisplay;
avtranscoder::VideoFrame* m_sourceImage;
avtranscoder::VideoFrame* m_imageToDisplay;

avtranscoder::Pixel pixel;
avtranscoder::ImageDesc imageDescToDisplay;
avtranscoder::VideoFrameDesc VideoFrameDescToDisplay;

avtranscoder::VideoEssenceTransform m_videoEssenceTransform;
size_t m_videoStream;
Expand Down
2 changes: 1 addition & 1 deletion app/presetChecker/presetChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main( int argc, char** argv )
if( profile.find( avtranscoder::Profile::avProfileType )->second == avtranscoder::Profile::avProfileTypeVideo )
{
avtranscoder::OutputVideo outputVideo;
outputVideo.setProfile( profile, outputVideo.getVideoDesc().getImageDesc() );
outputVideo.setProfile( profile, outputVideo.getVideoDesc().getVideoFrameDesc() );
}

if( profile.find( avtranscoder::Profile::avProfileType )->second == avtranscoder::Profile::avProfileTypeAudio )
Expand Down
3 changes: 0 additions & 3 deletions src/AvTranscoder/CodedStream/AvInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ extern "C" {

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/pixdesc.h>
#include <libavutil/avstring.h>
}

#include <stdexcept>
Expand Down
2 changes: 2 additions & 0 deletions src/AvTranscoder/CodedStream/AvInputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "InputStream.hpp"

#include <AvTranscoder/CodedStructures/DataStreamDesc.hpp>

namespace avtranscoder
{

Expand Down
1 change: 0 additions & 1 deletion src/AvTranscoder/CodedStream/AvOutputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <AvTranscoder/File/OutputFile.hpp>

#include <cassert>
#include <iostream>

namespace avtranscoder
{
Expand Down
6 changes: 3 additions & 3 deletions src/AvTranscoder/CodedStream/InputStream.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef _AV_TRANSCODER_CODED_STREAM_INPUT_STREAM_HPP_
#define _AV_TRANSCODER_CODED_STREAM_INPUT_STREAM_HPP_

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

namespace avtranscoder
{
Expand Down
6 changes: 3 additions & 3 deletions src/AvTranscoder/CodedStream/OutputStream.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef _AV_TRANSCODER_CODED_STREAM_OUTPUT_STREAM_HPP_
#define _AV_TRANSCODER_CODED_STREAM_OUTPUT_STREAM_HPP_

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

namespace avtranscoder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ namespace avtranscoder
{

AudioDesc::AudioDesc( const std::string& codecName )
: EssenceDesc( codecName )
: CodedDesc( codecName )
{
}

AudioDesc::AudioDesc( const AVCodecID codecId )
: EssenceDesc( codecId )
: CodedDesc( codecId )
{
}

AudioDesc::AudioDesc( const EssenceDesc& essenceDesc )
: EssenceDesc( essenceDesc.getCodecId() )
AudioDesc::AudioDesc( const CodedDesc& essenceDesc )
: CodedDesc( essenceDesc.getCodecId() )
{
m_codec = essenceDesc.getCodec();
m_codecContext = essenceDesc.getCodecContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,22 @@

#include <string>

extern "C" {
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
#include <libavcodec/avcodec.h>
}

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

#include "CodedDesc.hpp"

class AVCodec;

namespace avtranscoder
{

class AvExport AudioDesc : public EssenceDesc
class AvExport AudioDesc : public CodedDesc
{
public:
AudioDesc( const std::string& codecName = "" );
AudioDesc( const AVCodecID codecId );
AudioDesc( const EssenceDesc& essenceDesc );
AudioDesc( const CodedDesc& essenceDesc );

AudioFrameDesc getFrameDesc() const;
const size_t getSampleRate() const;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "EssenceDesc.hpp"
#include "CodedDesc.hpp"

extern "C" {
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
#include <libavutil/error.h>
}
Expand All @@ -15,48 +16,48 @@ extern "C" {

namespace avtranscoder {

EssenceDesc::EssenceDesc( const std::string& codecName )
CodedDesc::CodedDesc( const std::string& codecName )
: m_codec( NULL )
, m_codecContext( NULL )
{
if( codecName.size() )
setCodec( codecName );
}

EssenceDesc::EssenceDesc( const AVCodecID codecId )
CodedDesc::CodedDesc( const AVCodecID codecId )
: m_codec( NULL )
, m_codecContext( NULL )
{
setCodec( codecId );
}

std::string EssenceDesc::getCodecName() const
std::string CodedDesc::getCodecName() const
{
assert( m_codecContext != NULL );
return avcodec_descriptor_get( m_codecContext->codec_id )->name;
}

AVCodecID EssenceDesc::getCodecId() const
AVCodecID CodedDesc::getCodecId() const
{
assert( m_codecContext != NULL );
return m_codecContext->codec_id;
}

void EssenceDesc::setCodec( const std::string& codecName )
void CodedDesc::setCodec( const std::string& codecName )
{
avcodec_register_all(); // Warning: should be called only once
m_codec = avcodec_find_encoder_by_name( codecName.c_str() );
initCodecContext();
}

void EssenceDesc::setCodec( const AVCodecID codecId )
void CodedDesc::setCodec( const AVCodecID codecId )
{
avcodec_register_all(); // Warning: should be called only once
m_codec = avcodec_find_encoder( codecId );
initCodecContext();
}

void EssenceDesc::initCodecContext( )
void CodedDesc::initCodecContext( )
{
if( m_codec == NULL )
{
Expand All @@ -75,7 +76,7 @@ void EssenceDesc::initCodecContext( )
}
}

void EssenceDesc::set( const std::string& key, const std::string& flag, const bool enable )
void CodedDesc::set( const std::string& key, const std::string& flag, const bool enable )
{
int error = 0;
int64_t optVal;
Expand Down Expand Up @@ -112,7 +113,7 @@ void EssenceDesc::set( const std::string& key, const std::string& flag, const bo
}
}

void EssenceDesc::set( const std::string& key, const bool value )
void CodedDesc::set( const std::string& key, const bool value )
{
int error = av_opt_set_int( m_codecContext, key.c_str(), value, AV_OPT_SEARCH_CHILDREN );
if( error != 0 )
Expand All @@ -124,7 +125,7 @@ void EssenceDesc::set( const std::string& key, const bool value )
}
}

void EssenceDesc::set( const std::string& key, const int value )
void CodedDesc::set( const std::string& key, const int value )
{
//const AVOption* flagOpt = av_opt_find( m_codecContext, key.c_str(), NULL, 0, AV_OPT_SEARCH_CHILDREN );

Expand All @@ -140,7 +141,7 @@ void EssenceDesc::set( const std::string& key, const int value )
}
}

void EssenceDesc::set( const std::string& key, const int num, const int den )
void CodedDesc::set( const std::string& key, const int num, const int den )
{
AVRational ratio;
ratio.num = num;
Expand All @@ -157,7 +158,7 @@ void EssenceDesc::set( const std::string& key, const int num, const int den )
}
}

void EssenceDesc::set( const std::string& key, const double value )
void CodedDesc::set( const std::string& key, const double value )
{
int error = av_opt_set_double( m_codecContext, key.c_str(), value, AV_OPT_SEARCH_CHILDREN );
if( error != 0 )
Expand All @@ -171,7 +172,7 @@ void EssenceDesc::set( const std::string& key, const double value )
}
}

void EssenceDesc::set( const std::string& key, const std::string& value )
void CodedDesc::set( const std::string& key, const std::string& value )
{
int error = av_opt_set( m_codecContext, key.c_str(), value.c_str(), AV_OPT_SEARCH_CHILDREN );
if( error != 0 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,21 @@

#include <string>

extern "C" {
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
#include <libavcodec/avcodec.h>
}

#include <AvTranscoder/common.hpp>

class AVCodec;
class AVCodecContext;

namespace avtranscoder
{

class AvExport EssenceDesc
class AvExport CodedDesc
{
public:
EssenceDesc( const std::string& codecName );
EssenceDesc( const AVCodecID codecId );
CodedDesc( const std::string& codecName );
CodedDesc( const AVCodecID codecId );

virtual ~EssenceDesc() {}
virtual ~CodedDesc() {}

std::string getCodecName() const;
AVCodecID getCodecId() const;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
#ifndef _AV_TRANSCODER_DATA_DATA_STREAM_DESC_HPP_
#define _AV_TRANSCODER_DATA_DATA_STREAM_DESC_HPP_

#include <string>
#include <vector>

extern "C" {
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
#include <libavcodec/avcodec.h>
}
#include <cstring>

namespace avtranscoder
{
Expand Down
Loading