Skip to content

Commit c64929f

Browse files
author
Clement Champetier
committed
VideoFrame: split hpp/cpp
1 parent b9b4853 commit c64929f

File tree

2 files changed

+76
-51
lines changed

2 files changed

+76
-51
lines changed

src/AvTranscoder/frame/VideoFrame.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "VideoFrame.hpp"
2+
3+
extern "C" {
4+
#include <libavcodec/avcodec.h>
5+
#include <libavutil/pixdesc.h>
6+
}
7+
8+
#include <stdexcept>
9+
#include <stdlib.h>
10+
11+
namespace avtranscoder
12+
{
13+
14+
VideoFrameDesc::VideoFrameDesc( const size_t width, const size_t height, const AVPixelFormat pixelFormat )
15+
: _width( width )
16+
, _height( height )
17+
, _pixelFormat( pixelFormat )
18+
, _fps( 1.0 )
19+
{
20+
}
21+
VideoFrameDesc::VideoFrameDesc( const size_t width, const size_t height, const std::string& pixelFormat )
22+
: _width( width )
23+
, _height( height )
24+
, _pixelFormat( av_get_pix_fmt( pixelFormat.c_str() ) )
25+
, _fps( 1.0 )
26+
{
27+
}
28+
29+
std::string VideoFrameDesc::getPixelFormatName() const
30+
{
31+
const char* formatName = av_get_pix_fmt_name( _pixelFormat );
32+
return formatName ? std::string( formatName ) : "unknown pixel format";
33+
}
34+
35+
size_t VideoFrameDesc::getDataSize() const
36+
{
37+
if( _pixelFormat == AV_PIX_FMT_NONE )
38+
throw std::runtime_error( "incorrect pixel format" );
39+
40+
size_t size = avpicture_get_size( _pixelFormat, _width, _height );
41+
if( size == 0 )
42+
throw std::runtime_error( "unable to determine image buffer size" );
43+
44+
return size;
45+
}
46+
47+
void VideoFrameDesc::setPixelFormat( const std::string& pixelFormat )
48+
{
49+
_pixelFormat = av_get_pix_fmt( pixelFormat.c_str() );
50+
}
51+
52+
void VideoFrameDesc::setParameters( const ProfileLoader::Profile& profile )
53+
{
54+
// width
55+
if( profile.count( constants::avProfileWidth ) )
56+
setWidth( atoi( profile.find( constants::avProfileWidth )->second.c_str() ) );
57+
// height
58+
if( profile.count( constants::avProfileHeight ) )
59+
setHeight( atoi( profile.find( constants::avProfileHeight )->second.c_str() ) );
60+
// pixel format
61+
if( profile.count( constants::avProfilePixelFormat ) )
62+
setPixelFormat( profile.find( constants::avProfilePixelFormat )->second );
63+
// fps
64+
if( profile.count( constants::avProfileFrameRate ) )
65+
setFps( atof( profile.find( constants::avProfileFrameRate )->second.c_str() ) );
66+
}
67+
68+
}
69+
70+

src/AvTranscoder/frame/VideoFrame.hpp

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,33 @@
55
#include <AvTranscoder/ProfileLoader.hpp>
66

77
extern "C" {
8-
#include <libavcodec/avcodec.h>
98
#include <libavutil/pixfmt.h>
10-
#include <libavutil/pixdesc.h>
119
}
1210

13-
#include <stdexcept>
14-
#include <stdlib.h>
15-
1611
namespace avtranscoder
1712
{
1813

1914
class AvExport VideoFrameDesc
2015
{
2116
public:
22-
VideoFrameDesc( const size_t width = 0, const size_t height = 0, const AVPixelFormat pixelFormat = AV_PIX_FMT_NONE )
23-
: _width( width )
24-
, _height( height )
25-
, _pixelFormat( pixelFormat )
26-
, _fps( 1.0 )
27-
{
28-
}
29-
VideoFrameDesc( const size_t width, const size_t height, const std::string& pixelFormat )
30-
: _width( width )
31-
, _height( height )
32-
, _pixelFormat( av_get_pix_fmt( pixelFormat.c_str() ) )
33-
, _fps( 1.0 )
34-
{
35-
}
17+
VideoFrameDesc( const size_t width = 0, const size_t height = 0, const AVPixelFormat pixelFormat = AV_PIX_FMT_NONE );
18+
VideoFrameDesc( const size_t width, const size_t height, const std::string& pixelFormat );
3619

3720
size_t getWidth () const { return _width; }
3821
size_t getHeight() const { return _height; }
3922
AVPixelFormat getPixelFormat() const { return _pixelFormat; }
40-
std::string getPixelFormatName() const
41-
{
42-
const char* formatName = av_get_pix_fmt_name( _pixelFormat );
43-
return formatName ? std::string( formatName ) : "unknown pixel format";
44-
}
23+
std::string getPixelFormatName() const;
4524
double getFps() const { return _fps; }
4625

47-
size_t getDataSize() const
48-
{
49-
if( _pixelFormat == AV_PIX_FMT_NONE )
50-
throw std::runtime_error( "incorrect pixel format" );
51-
52-
size_t size = avpicture_get_size( _pixelFormat, _width, _height );
53-
if( size == 0 )
54-
throw std::runtime_error( "unable to determine image buffer size" );
55-
56-
return size;
57-
}
26+
size_t getDataSize() const;
5827

5928
void setWidth ( const size_t width ) { _width = width; }
6029
void setHeight( const size_t height ) { _height = height; }
61-
void setPixelFormat( const std::string& pixelFormat ) { _pixelFormat = av_get_pix_fmt( pixelFormat.c_str() ); }
30+
void setPixelFormat( const std::string& pixelFormat );
6231
void setPixelFormat( const AVPixelFormat pixelFormat ) { _pixelFormat = pixelFormat; }
6332
void setFps( const double fps ) { _fps = fps; }
6433

65-
void setParameters( const ProfileLoader::Profile& profile )
66-
{
67-
// width
68-
if( profile.count( constants::avProfileWidth ) )
69-
setWidth( atoi( profile.find( constants::avProfileWidth )->second.c_str() ) );
70-
// height
71-
if( profile.count( constants::avProfileHeight ) )
72-
setHeight( atoi( profile.find( constants::avProfileHeight )->second.c_str() ) );
73-
// pixel format
74-
if( profile.count( constants::avProfilePixelFormat ) )
75-
setPixelFormat( profile.find( constants::avProfilePixelFormat )->second );
76-
// fps
77-
if( profile.count( constants::avProfileFrameRate ) )
78-
setFps( atof( profile.find( constants::avProfileFrameRate )->second.c_str() ) );
79-
}
34+
void setParameters( const ProfileLoader::Profile& profile );
8035

8136
private:
8237
size_t _width;

0 commit comments

Comments
 (0)