4 #include <libavutil/error.h>
5 #include <libavutil/mem.h>
15 : _avOption(&avOption)
16 , _avContext(avContext)
18 , _defaultChildIndex(0)
25 if(!unit.empty() && avType == AV_OPT_TYPE_FLAGS)
27 else if(!unit.empty() && (avType == AV_OPT_TYPE_INT || avType == AV_OPT_TYPE_INT64))
29 else if(!unit.empty() && avType == AV_OPT_TYPE_CONST)
34 case AV_OPT_TYPE_FLAGS:
39 case AV_OPT_TYPE_INT64:
43 case AV_OPT_TYPE_DOUBLE:
44 case AV_OPT_TYPE_FLOAT:
48 case AV_OPT_TYPE_STRING:
49 case AV_OPT_TYPE_BINARY:
53 case AV_OPT_TYPE_RATIONAL:
98 int error = av_opt_get_int(
_avContext,
getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val);
101 return out_val ?
true :
false;
107 int error = av_opt_get_int(
_avContext,
getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val);
116 int error = av_opt_get_double(
_avContext,
getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val);
124 void* out_val = av_malloc(128);
125 int error = av_opt_get(
_avContext,
getName().c_str(), AV_OPT_SEARCH_CHILDREN, (uint8_t**)&out_val);
127 std::string strValue(out_val ? reinterpret_cast<const char*>(out_val) :
"");
139 int error = av_opt_get_q(
_avContext,
getName().c_str(), AV_OPT_SEARCH_CHILDREN, &out_val);
142 return std::make_pair(out_val.num, out_val.den);
148 int error = av_opt_get_int(
_avContext,
getName().c_str(), AV_OPT_SEARCH_CHILDREN, &optVal);
152 optVal = optVal |
_avOption->default_val.i64;
154 optVal = optVal & ~
_avOption->default_val.i64;
156 error = av_opt_set_int(
_avContext,
getName().c_str(), optVal, AV_OPT_SEARCH_CHILDREN);
162 int error = av_opt_set_int(
_avContext,
getName().c_str(), value, AV_OPT_SEARCH_CHILDREN);
164 std::ostringstream os;
165 os << (value ?
"true" :
"false");
171 int error = av_opt_set_int(
_avContext,
getName().c_str(), value, AV_OPT_SEARCH_CHILDREN);
173 std::ostringstream os;
180 int error = av_opt_set_double(
_avContext,
getName().c_str(), value, AV_OPT_SEARCH_CHILDREN);
182 std::ostringstream os;
189 int error = av_opt_set(
_avContext,
getName().c_str(), value.c_str(), AV_OPT_SEARCH_CHILDREN);
198 int error = av_opt_set_q(
_avContext,
getName().c_str(), ratio, AV_OPT_SEARCH_CHILDREN);
200 std::ostringstream os;
201 os << num <<
"/" << den;
222 throw std::runtime_error(
"setting " +
getName() +
" parameter to " + optionValue +
": " +
232 std::multimap<std::string, std::string> optionUnitToParentName;
233 std::vector<Option> childOptions;
235 const AVOption* avOption = NULL;
238 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(51, 12, 0)
239 while((avOption = av_next_option(av_class, avOption)))
241 while((avOption = av_opt_next(av_class, avOption)))
244 if(!avOption || !avOption->name || (avOption->flags & req_flags) != req_flags)
249 Option option(*const_cast<AVOption*>(avOption), av_class);
253 childOptions.push_back(option);
257 outOptions.insert(std::make_pair(option.
getName(), option));
258 optionUnitToParentName.insert(std::make_pair(option.
getUnit(), option.
getName()));
263 for(std::vector<Option>::iterator itOption = childOptions.begin(); itOption != childOptions.end(); ++itOption)
265 bool parentFound =
false;
266 for(std::multimap<std::string, std::string>::iterator itUnit = optionUnitToParentName.begin();
267 itUnit != optionUnitToParentName.end(); ++itUnit)
269 if(itUnit->first == itOption->getUnit())
271 std::string nameParentOption = itUnit->second;
272 Option& parentOption = outOptions.at(nameParentOption);
279 if(itOption->getDefaultInt() == parentOption.
getDefaultInt())
290 LOG_WARN(
"Can't find a choice option for " << itOption->getName())
300 for(OptionMap::iterator it = optionMap.begin(); it != optionMap.end(); ++it)
301 outOptions.push_back(it->second);
Option(AVOption &avOption, void *avContext)
void setString(const std::string &value)
bool getDefaultBool() const
void loadOptions(OptionMap &outOptions, void *av_class, int req_flags)
std::string getDefaultString() const
std::map< std::string, Option > OptionMap
Key: option name / value: option.
std::vector< Option > OptionArray
std::pair< int, int > getRatio() const
void setInt(const int value)
void checkFFmpegGetOption(const int ffmpegReturnCode) const
Check the return value from FFmpeg functions.
std::string getDescriptionFromErrorCode(const int code)
Get the string description corresponding to the error code provided by ffmpeg/libav.
void setRatio(const int num, const int den)
AVOption * _avOption
Has link (no ownership)
std::string getName() const
EOptionBaseType getTypeFromAVOption(const std::string &unit, const AVOptionType avType)
void checkFFmpegSetOption(const int ffmpegReturnCode, const std::string &optionValue)
void setDefaultChildIndex(size_t index)
Wrapper of AVOption. Get its type to know what the option is about: Int, Double, Ratio, Choice... Parse its array of options to get the potential childs (Choice and Group).
std::vector< Option > _childOptions
void setDouble(const double value)
EOptionBaseType getType() const
double getDefaultDouble() const
void * _avContext
Pointer to the corresponding context. Need it to set and get the option values.
std::pair< int, int > getDefaultRatio() const
std::string getUnit() const
void setFlag(const std::string &flag, const bool enable)
void setBool(const bool value)
int getDefaultInt() const
const std::vector< Option > & getChilds() const
std::string getString() const
void appendChild(const Option &child)