Skip to content

Commit 0292ed4

Browse files
author
Clement Champetier
committed
common: rename ParamSet to Context
* Create the new Context class in new files (hpp + cpp): no reason to have it in common. * Get Context files in option folder.
1 parent a00e114 commit 0292ed4

File tree

9 files changed

+174
-137
lines changed

9 files changed

+174
-137
lines changed

src/AvTranscoder/common.cpp

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -6,118 +6,15 @@ extern "C" {
66
#endif
77
#include <libavcodec/avcodec.h>
88
#include <libavformat/avformat.h>
9-
#include <libavutil/opt.h>
109
#include <libavutil/error.h>
1110
}
1211

1312
#include <dirent.h>
1413
#include <iostream>
15-
#include <stdexcept>
16-
#include <sstream>
1714

1815
namespace avtranscoder
1916
{
2017

21-
void ParamSet::set( const std::string& key, const std::string& flag, const bool enable )
22-
{
23-
int error = 0;
24-
int64_t optVal;
25-
26-
const AVOption* flagOpt = av_opt_find( _objContext, flag.c_str(), key.c_str(), 0, 0 );
27-
28-
if( ! flagOpt )
29-
{
30-
throw std::runtime_error( "unknown flag " + flag );
31-
}
32-
33-
error = av_opt_get_int( _objContext, key.c_str(), AV_OPT_SEARCH_CHILDREN, &optVal );
34-
if( error != 0 )
35-
{
36-
char err[AV_ERROR_MAX_STRING_SIZE];
37-
av_strerror( error, err, AV_ERROR_MAX_STRING_SIZE );
38-
throw std::runtime_error( "unknown key " + key + ": " + err );
39-
}
40-
41-
if( enable )
42-
optVal = optVal | flagOpt->default_val.i64;
43-
else
44-
optVal = optVal &~ flagOpt->default_val.i64;
45-
46-
error = av_opt_set_int( _objContext, key.c_str(), optVal, AV_OPT_SEARCH_CHILDREN );
47-
if( error != 0 )
48-
{
49-
char err[AV_ERROR_MAX_STRING_SIZE];
50-
av_strerror( error, err, AV_ERROR_MAX_STRING_SIZE );
51-
throw std::runtime_error( "setting " + key + " parameter to " + flag + ": " + err );
52-
}
53-
}
54-
55-
void ParamSet::set( const std::string& key, const bool value )
56-
{
57-
int error = av_opt_set_int( _objContext, key.c_str(), value, AV_OPT_SEARCH_CHILDREN );
58-
if( error != 0 )
59-
{
60-
char err[AV_ERROR_MAX_STRING_SIZE];
61-
av_strerror( error, err, AV_ERROR_MAX_STRING_SIZE );
62-
throw std::runtime_error( "setting " + key + " parameter to " + ( value ? "true" : "false" ) + ": " + err );
63-
}
64-
}
65-
66-
void ParamSet::set( const std::string& key, const int value )
67-
{
68-
//const AVOption* flagOpt = av_opt_find( _objContext, key.c_str(), NULL, 0, AV_OPT_SEARCH_CHILDREN );
69-
70-
int error = av_opt_set_int( _objContext, key.c_str(), value, AV_OPT_SEARCH_CHILDREN );
71-
if( error != 0 )
72-
{
73-
std::ostringstream os;
74-
os << value;
75-
char err[AV_ERROR_MAX_STRING_SIZE];
76-
av_strerror( error, err, AV_ERROR_MAX_STRING_SIZE );
77-
throw std::runtime_error( "setting " + key + " parameter to " + os.str() + ": " + err );
78-
}
79-
}
80-
81-
void ParamSet::set( const std::string& key, const int num, const int den )
82-
{
83-
AVRational ratio;
84-
ratio.num = num;
85-
ratio.den = den;
86-
int error = av_opt_set_q( _objContext, key.c_str(), ratio, AV_OPT_SEARCH_CHILDREN );
87-
if( error != 0 )
88-
{
89-
std::ostringstream os;
90-
os << num << "/" << den;
91-
char err[AV_ERROR_MAX_STRING_SIZE];
92-
av_strerror( error, err, AV_ERROR_MAX_STRING_SIZE );
93-
throw std::runtime_error( "setting " + key + " parameter to " + os.str() + ": " + err );
94-
}
95-
}
96-
97-
void ParamSet::set( const std::string& key, const double value )
98-
{
99-
int error = av_opt_set_double( _objContext, key.c_str(), value, AV_OPT_SEARCH_CHILDREN );
100-
if( error != 0 )
101-
{
102-
std::ostringstream os;
103-
os << value;
104-
char err[AV_ERROR_MAX_STRING_SIZE];
105-
av_strerror( error, err, AV_ERROR_MAX_STRING_SIZE );
106-
throw std::runtime_error( "setting " + key + " parameter to " + os.str() + ": " + err );
107-
}
108-
}
109-
110-
void ParamSet::set( const std::string& key, const std::string& value )
111-
{
112-
int error = av_opt_set( _objContext, key.c_str(), value.c_str(), AV_OPT_SEARCH_CHILDREN );
113-
if( error != 0 )
114-
{
115-
char err[AV_ERROR_MAX_STRING_SIZE];
116-
av_strerror( error, err, AV_ERROR_MAX_STRING_SIZE );
117-
throw std::runtime_error( "setting " + key + " parameter to " + value + ": " + err );
118-
}
119-
}
120-
12118
void split( std::vector< std::string >& splitedString, const std::string& inputString, const std::string& splitChars )
12219
{
12320
char* part = strtok( const_cast<char*>( inputString.c_str() ), splitChars.c_str() );

src/AvTranscoder/common.hpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,6 @@ namespace avtranscoder
5353

5454
#define MAX_SWS_PLANE 4
5555

56-
class ParamSet
57-
{
58-
public:
59-
ParamSet( void* obj )
60-
: _objContext( obj )
61-
{}
62-
63-
void set( const std::string& key, const std::string& flag, const bool enable );
64-
void set( const std::string& key, const bool value );
65-
void set( const std::string& key, const int value );
66-
void set( const std::string& key, const int num, const int den );
67-
void set( const std::string& key, const double value );
68-
void set( const std::string& key, const std::string& value );
69-
70-
private:
71-
void* _objContext;
72-
};
73-
7456
void split( std::vector< std::string >& splitedString, const std::string& inputString, const std::string& splitChars = ";" );
7557
int getFilesInDir( const std::string& dir, std::vector< std::string >& files );
7658

src/AvTranscoder/essenceStream/AvInputVideo.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "AvInputVideo.hpp"
22

3+
#include <AvTranscoder/option/Context.hpp>
4+
#include <AvTranscoder/codedStream/AvInputStream.hpp>
5+
#include <AvTranscoder/essenceStructures/VideoFrame.hpp>
6+
37
extern "C" {
48
#ifndef __STDC_CONSTANT_MACROS
59
#define __STDC_CONSTANT_MACROS
@@ -10,9 +14,6 @@ extern "C" {
1014
#include <libavutil/pixdesc.h>
1115
}
1216

13-
#include <AvTranscoder/codedStream/AvInputStream.hpp>
14-
#include <AvTranscoder/essenceStructures/VideoFrame.hpp>
15-
1617
#include <stdexcept>
1718
#include <iostream>
1819

@@ -149,7 +150,7 @@ void AvInputVideo::flushDecoder()
149150

150151
void AvInputVideo::setProfile( const Profile::ProfileDesc& desc )
151152
{
152-
ParamSet paramSet( _codecContext );
153+
Context codecContext( _codecContext );
153154

154155
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
155156
{
@@ -160,7 +161,7 @@ void AvInputVideo::setProfile( const Profile::ProfileDesc& desc )
160161

161162
try
162163
{
163-
paramSet.set( (*it).first, (*it).second );
164+
codecContext.set( (*it).first, (*it).second );
164165
}
165166
catch( std::exception& e )
166167
{

src/AvTranscoder/essenceStream/AvOutputAudio.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "AvOutputAudio.hpp"
22

3+
#include <AvTranscoder/option/Context.hpp>
4+
35
extern "C" {
46
#ifndef __STDC_CONSTANT_MACROS
57
#define __STDC_CONSTANT_MACROS
@@ -184,7 +186,7 @@ void AvOutputAudio::setProfile( const Profile::ProfileDesc& desc, const AudioFra
184186

185187
static_cast<AudioDesc>( _codedDesc ).setAudioParameters( frameDesc );
186188

187-
ParamSet paramSet( _codedDesc.getCodecContext() );
189+
Context codecContext( _codedDesc.getCodecContext() );
188190

189191
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
190192
{
@@ -197,7 +199,7 @@ void AvOutputAudio::setProfile( const Profile::ProfileDesc& desc, const AudioFra
197199

198200
try
199201
{
200-
paramSet.set( (*it).first, (*it).second );
202+
codecContext.set( (*it).first, (*it).second );
201203
}
202204
catch( std::exception& e )
203205
{
@@ -218,7 +220,7 @@ void AvOutputAudio::setProfile( const Profile::ProfileDesc& desc, const AudioFra
218220

219221
try
220222
{
221-
paramSet.set( (*it).first, (*it).second );
223+
codecContext.set( (*it).first, (*it).second );
222224
}
223225
catch( std::exception& e )
224226
{

src/AvTranscoder/essenceStream/AvOutputVideo.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "AvOutputVideo.hpp"
22

3+
#include <AvTranscoder/option/Context.hpp>
4+
35
extern "C" {
46
#ifndef __STDC_CONSTANT_MACROS
57
#define __STDC_CONSTANT_MACROS
@@ -189,7 +191,7 @@ void AvOutputVideo::setProfile( const Profile::ProfileDesc& desc, const avtransc
189191

190192
static_cast<VideoDesc>( _codedDesc ).setImageParameters( frameDesc );
191193

192-
ParamSet paramSet( _codedDesc.getCodecContext() );
194+
Context codecContext( _codedDesc.getCodecContext() );
193195

194196
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
195197
{
@@ -203,7 +205,7 @@ void AvOutputVideo::setProfile( const Profile::ProfileDesc& desc, const avtransc
203205

204206
try
205207
{
206-
paramSet.set( (*it).first, (*it).second );
208+
codecContext.set( (*it).first, (*it).second );
207209
}
208210
catch( std::exception& e )
209211
{
@@ -225,7 +227,7 @@ void AvOutputVideo::setProfile( const Profile::ProfileDesc& desc, const avtransc
225227

226228
try
227229
{
228-
paramSet.set( (*it).first, (*it).second );
230+
codecContext.set( (*it).first, (*it).second );
229231
}
230232
catch( std::exception& e )
231233
{

src/AvTranscoder/file/InputFile.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "InputFile.hpp"
22

3+
#include <AvTranscoder/option/Context.hpp>
34
#include <AvTranscoder/mediaProperty/VideoStreamProperty.hpp>
45
#include <AvTranscoder/mediaProperty/AudioStreamProperty.hpp>
56
#include <AvTranscoder/mediaProperty/DataStreamProperty.hpp>
@@ -8,6 +9,7 @@
89
#include <AvTranscoder/mediaProperty/UnknownStreamProperty.hpp>
910

1011

12+
1113
extern "C" {
1214
#ifndef __STDC_CONSTANT_MACROS
1315
#define __STDC_CONSTANT_MACROS
@@ -215,7 +217,7 @@ bool InputFile::getReadStream( const size_t streamIndex )
215217

216218
void InputFile::setProfile( const Profile::ProfileDesc& desc )
217219
{
218-
ParamSet paramSet( _formatContext );
220+
Context formatContext( _formatContext );
219221

220222
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
221223
{
@@ -226,7 +228,7 @@ void InputFile::setProfile( const Profile::ProfileDesc& desc )
226228

227229
try
228230
{
229-
paramSet.set( (*it).first, (*it).second );
231+
formatContext.set( (*it).first, (*it).second );
230232
}
231233
catch( std::exception& e )
232234
{

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "OutputFile.hpp"
22

3+
#include <AvTranscoder/option/Context.hpp>
4+
35
extern "C" {
46
#ifndef __STDC_CONSTANT_MACROS
57
#define __STDC_CONSTANT_MACROS
@@ -236,7 +238,7 @@ void OutputFile::setProfile( const Profile::ProfileDesc& desc )
236238
}
237239
_outputFormat = av_guess_format( desc.find( Profile::avProfileFormat )->second.c_str(), _filename.c_str(), NULL);
238240

239-
ParamSet paramSet( _formatContext );
241+
Context formatContext( _formatContext );
240242

241243
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
242244
{
@@ -248,7 +250,7 @@ void OutputFile::setProfile( const Profile::ProfileDesc& desc )
248250

249251
try
250252
{
251-
paramSet.set( (*it).first, (*it).second );
253+
formatContext.set( (*it).first, (*it).second );
252254
}
253255
catch( std::exception& e )
254256
{
@@ -268,7 +270,7 @@ void OutputFile::setProfile( const Profile::ProfileDesc& desc )
268270

269271
try
270272
{
271-
paramSet.set( (*it).first, (*it).second );
273+
formatContext.set( (*it).first, (*it).second );
272274
}
273275
catch( std::exception& e )
274276
{

0 commit comments

Comments
 (0)