TuttleOFX
1
|
00001 #include "LibAV.hpp" 00002 00003 #include <boost/foreach.hpp> 00004 #include <boost/algorithm/string/predicate.hpp> 00005 00006 #include <map> 00007 00008 namespace tuttle { 00009 namespace plugin { 00010 namespace av { 00011 00012 template< typename IOPlugin > 00013 AVOptionPlugin<IOPlugin>::AVOptionPlugin( OfxImageEffectHandle handle ) 00014 : IOPlugin( handle ) 00015 { 00016 00017 } 00018 00019 template< typename IOPlugin > 00020 int AVOptionPlugin<IOPlugin>::convertIntWithOptionalUnit( const std::string& param, const std::string& stringValue ) 00021 { 00022 int intValue = 0; 00023 if( std::isdigit( stringValue[ stringValue.length()-1 ] ) ) 00024 { 00025 try 00026 { 00027 intValue = boost::lexical_cast<int>( stringValue ); 00028 } 00029 catch( ... ) 00030 { 00031 TUTTLE_LOG_ERROR( "avwriter: parameter " << param << " can't convert the value: " << stringValue ); 00032 } 00033 } 00034 else 00035 { 00036 char unit = stringValue[ stringValue.length()-1 ]; 00037 std::string val = stringValue; 00038 val.erase( val.length()-1 ,1 ); 00039 try 00040 { 00041 intValue = boost::lexical_cast<int>( val ); 00042 } 00043 catch( ... ) 00044 { 00045 TUTTLE_LOG_ERROR( "avwriter: parameter " << param << " can't convert the value: " << stringValue ); 00046 } 00047 00048 switch( unit ) 00049 { 00050 case 'k': 00051 intValue *= 1000; 00052 break; 00053 case 'M': 00054 intValue *= 1000 * 1000; 00055 break; 00056 case 'G': 00057 intValue *= 1000 * 1000 * 1000; 00058 break; 00059 default: 00060 TUTTLE_LOG_ERROR("avwriter: unknown unit " << unit << " for parameter " << param ); 00061 break; 00062 } 00063 } 00064 return intValue; 00065 } 00066 00067 template< typename IOPlugin > 00068 template< typename LibAVVideoRW > 00069 void AVOptionPlugin<IOPlugin>::setParameters( LibAVVideoRW& videoRW, const EAVParamType& type, void* av_class, int req_flags, int rej_flags ) 00070 { 00071 std::vector<OFX::ChoiceParam*> choices; 00072 std::vector<std::string> unit; 00073 std::vector<size_t> choiceValue; 00074 std::vector<const AVOption*> choiceOpt; 00075 std::map<std::string, size_t> choiceListWithCountOption; 00076 00077 std::vector<OFX::GroupParam*> groups; 00078 const AVOption *opt = NULL; 00079 00080 while( (opt = av_opt_next( av_class, opt) ) != NULL ) 00081 { 00082 if( !opt || 00083 !opt->name || 00084 (opt->flags & req_flags) != req_flags || 00085 (opt->flags & rej_flags) ) 00086 { 00087 continue; 00088 } 00089 00090 if( opt->unit && opt->type == AV_OPT_TYPE_FLAGS ) 00091 { 00092 std::string name = "g_"; 00093 name += opt->unit; 00094 OFX::GroupParam* curOpt = IOPlugin::fetchGroupParam( name ); 00095 groups.push_back( curOpt ); 00096 continue; 00097 } 00098 if( opt->unit && opt->type == AV_OPT_TYPE_INT ) 00099 { 00100 OFX::ChoiceParam* curOpt = IOPlugin::fetchChoiceParam( opt->name ); 00101 //TUTTLE_LOG_VAR3( TUTTLE_INFO, opt->name, opt->unit, curOpt->getValue() ); 00102 00103 choiceOpt.push_back( opt ); 00104 choices.push_back( curOpt ); 00105 unit.push_back( opt->unit ); 00106 choiceValue.push_back( curOpt->getValue() ); 00107 continue; 00108 } 00109 00110 switch( opt->type ) 00111 { 00112 case AV_OPT_TYPE_FLAGS: 00113 { 00114 OFX::BooleanParam* curOpt = IOPlugin::fetchBooleanParam( opt->name ); 00115 bool v = curOpt->getValue(); 00116 optionSet( videoRW, type, *opt, v ); 00117 break; 00118 } 00119 case AV_OPT_TYPE_INT: 00120 case AV_OPT_TYPE_INT64: 00121 { 00122 OFX::IntParam* curOpt = IOPlugin::fetchIntParam( opt->name ); 00123 int v = curOpt->getValue(); 00124 optionSet( videoRW, type, *opt, v ); 00125 break; 00126 } 00127 case AV_OPT_TYPE_DOUBLE: 00128 case AV_OPT_TYPE_FLOAT: 00129 { 00130 OFX::DoubleParam* curOpt = IOPlugin::fetchDoubleParam( opt->name ); 00131 double v = curOpt->getValue(); 00132 optionSet( videoRW, type, *opt, v ); 00133 break; 00134 } 00135 case AV_OPT_TYPE_STRING: 00136 { 00137 OFX::StringParam* curOpt = IOPlugin::fetchStringParam( opt->name ); 00138 std::string v = curOpt->getValue(); 00139 optionSet( videoRW, type, *opt, v ); 00140 break; 00141 } 00142 case AV_OPT_TYPE_RATIONAL: 00143 { 00144 OFX::Int2DParam* curOpt = IOPlugin::fetchInt2DParam( opt->name ); 00145 int vn = curOpt->getValue().x; 00146 int vd = curOpt->getValue().y; 00147 optionSet( videoRW, type, *opt, vn, vd ); 00148 break; 00149 } 00150 case AV_OPT_TYPE_BINARY: 00151 { 00152 OFX::StringParam* curOpt = IOPlugin::fetchStringParam( opt->name ); 00153 std::string v = curOpt->getValue(); 00154 optionSet( videoRW, type, *opt, v ); 00155 break; 00156 } 00157 case AV_OPT_TYPE_CONST: 00158 { 00159 break; 00160 } 00161 default: 00162 { 00163 TUTTLE_LOG_WARNING( "AudioVideo: undefined type for " << opt->name ); 00164 } 00165 } 00166 } 00167 00168 // adding enum values and flags in groups 00169 opt = NULL; 00170 while( (opt = av_opt_next( av_class, opt) ) != NULL ) 00171 { 00172 if( !opt || 00173 !opt->name || 00174 ( opt->flags & req_flags ) != req_flags || 00175 ( opt->flags & rej_flags ) || 00176 ( opt->unit && opt->type == AV_OPT_TYPE_FLAGS ) || 00177 ( opt->unit && opt->type == AV_OPT_TYPE_INT ) ) 00178 { 00179 continue; 00180 } 00181 00182 switch( opt->type ) 00183 { 00184 case AV_OPT_TYPE_CONST: 00185 { 00186 for( size_t i = 0; i < unit.size(); i++ ) 00187 { 00188 if( opt->unit == unit.at( i ) ) 00189 { 00190 //TUTTLE_LOG_INFO( "options " << opt->name << " to " << choices.at(i)->getName() ); 00191 00192 if( choiceListWithCountOption.find( choices.at(i)->getName() ) == choiceListWithCountOption.end() ) 00193 { 00194 choiceListWithCountOption[ choices.at(i)->getName() ] = 0; 00195 } 00196 else 00197 { 00198 choiceListWithCountOption[ choices.at(i)->getName() ] += 1; 00199 } 00200 00201 if( choiceListWithCountOption[ choices.at(i)->getName() ] == choiceValue.at(i) ) 00202 { 00203 int value = opt->default_val.i64; 00204 //TUTTLE_LOG_INFO( "options " << choices.at(i)->getName() << " = " << choiceValue.at(i) << " - " << opt->name << " (" << value << ")" ); 00205 optionSet( videoRW, type, *choiceOpt.at(i), value ); 00206 } 00207 } 00208 } 00209 BOOST_FOREACH( OFX::GroupParam* g, groups ) 00210 { 00211 std::string name = "g_"; 00212 name += opt->unit; 00213 if( name == g->getName() ) 00214 { 00215 OFX::BooleanParam* curOpt = IOPlugin::fetchBooleanParam( opt->name ); 00216 bool v = curOpt->getValue(); 00217 std::string optName = opt->unit; 00218 optionSet( videoRW, type, *opt, v, optName ); 00219 break; 00220 } 00221 } 00222 break; 00223 } 00224 default: 00225 { 00226 break; 00227 } 00228 } 00229 } 00230 } 00231 00232 template< typename IOPlugin > 00233 template< typename LibAVVideoRW > 00234 void AVOptionPlugin<IOPlugin>::setParameters( LibAVVideoRW& videoRW, const EAVParamType& type, const std::vector<AVPrivOption>& avPrivOpts, const std::string& codec ) 00235 { 00236 std::vector<OFX::GroupParam*> groups; 00237 00238 BOOST_FOREACH( AVPrivOption opt, avPrivOpts ) 00239 { 00240 if( opt.class_name != codec ) 00241 continue; 00242 00243 if( opt.o.unit && opt.o.type == AV_OPT_TYPE_FLAGS ) 00244 { 00245 std::string name = "g_"; 00246 name += opt.class_name; 00247 name += "_"; 00248 name += opt.o.unit; 00249 00250 OFX::GroupParam* curOpt = IOPlugin::fetchGroupParam( name ); 00251 groups.push_back( curOpt ); 00252 continue; 00253 } 00254 if( opt.o.unit && opt.o.type == AV_OPT_TYPE_INT ) 00255 { 00256 std::string name = opt.class_name; 00257 name += "_"; 00258 name += opt.o.name; 00259 00260 OFX::ChoiceParam* curOpt = IOPlugin::fetchChoiceParam( name ); 00261 int v = curOpt->getValue(); 00262 optionSet( videoRW, type, opt.o, v ); 00263 continue; 00264 } 00265 00266 std::string name = opt.class_name; 00267 name += "_"; 00268 name += opt.o.name; 00269 00270 switch( opt.o.type ) 00271 { 00272 case AV_OPT_TYPE_FLAGS: 00273 { 00274 OFX::BooleanParam* curOpt = IOPlugin::fetchBooleanParam( name ); 00275 bool v = curOpt->getValue(); 00276 optionSet( videoRW, type, opt.o, v ); 00277 break; 00278 } 00279 case AV_OPT_TYPE_INT: 00280 case AV_OPT_TYPE_INT64: 00281 { 00282 OFX::IntParam* curOpt = IOPlugin::fetchIntParam( name ); 00283 int v = curOpt->getValue(); 00284 optionSet( videoRW, type, opt.o, v ); 00285 break; 00286 } 00287 case AV_OPT_TYPE_DOUBLE: 00288 case AV_OPT_TYPE_FLOAT: 00289 { 00290 OFX::DoubleParam* curOpt = IOPlugin::fetchDoubleParam( name ); 00291 double v = curOpt->getValue(); 00292 optionSet( videoRW, type, opt.o, v ); 00293 break; 00294 } 00295 case AV_OPT_TYPE_STRING: 00296 { 00297 OFX::StringParam* curOpt = IOPlugin::fetchStringParam( name ); 00298 std::string v = curOpt->getValue(); 00299 optionSet( videoRW, type, opt.o, v ); 00300 break; 00301 } 00302 case AV_OPT_TYPE_RATIONAL: 00303 { 00304 OFX::Int2DParam* curOpt = IOPlugin::fetchInt2DParam( name ); 00305 int vn = curOpt->getValue().x; 00306 int vd = curOpt->getValue().y; 00307 optionSet( videoRW, type, opt.o, vn, vd ); 00308 break; 00309 } 00310 case AV_OPT_TYPE_BINARY: 00311 { 00312 OFX::StringParam* curOpt = IOPlugin::fetchStringParam( name ); 00313 std::string v = curOpt->getValue(); 00314 optionSet( videoRW, type, opt.o, v ); 00315 break; 00316 } 00317 case AV_OPT_TYPE_CONST: 00318 { 00319 break; 00320 } 00321 default: 00322 { 00323 TUTTLE_LOG_WARNING( "AudioVideo: undefined type for " << opt.o.name ); 00324 } 00325 } 00326 } 00327 00328 BOOST_FOREACH( AVPrivOption opt, avPrivOpts ) 00329 { 00330 switch( opt.o.type ) 00331 { 00332 case AV_OPT_TYPE_CONST: 00333 { 00334 BOOST_FOREACH( OFX::GroupParam* g, groups ) 00335 { 00336 std::string name = "g_"; 00337 name += opt.class_name; 00338 name += "_"; 00339 name += opt.o.unit; 00340 if( name == g->getName() ) 00341 { 00342 std::string name = "flags_"; 00343 name += opt.class_name; 00344 name += "_"; 00345 name += opt.o.name; 00346 00347 OFX::BooleanParam* curOpt = IOPlugin::fetchBooleanParam( name ); 00348 bool v = curOpt->getValue(); 00349 optionSet( videoRW, type, opt.o, v, opt.class_name ); 00350 break; 00351 } 00352 } 00353 break; 00354 } 00355 default: 00356 { 00357 break; 00358 } 00359 } 00360 } 00361 } 00362 00363 template< typename IOPlugin > 00364 void AVOptionPlugin<IOPlugin>::setParameters( const PresetParameters& parameters ) 00365 { 00366 BOOST_FOREACH( PresetParameters::value_type param, parameters ) 00367 { 00368 //TUTTLE_LOG_VAR2( TUTTLE_INFO, param.first, param.second ); 00369 if( IOPlugin::paramExists( param.first ) ) 00370 { 00371 std::string value = param.second.at( 0 ); 00372 switch( IOPlugin::getParamType( param.first ) ) 00373 { 00374 case OFX::eStringParam: 00375 { 00376 OFX::StringParam* fetchParam = IOPlugin::fetchStringParam( param.first ); 00377 fetchParam->setValue( value ); 00378 break; 00379 } 00380 case OFX::eIntParam: 00381 { 00382 OFX::IntParam* fetchParam = IOPlugin::fetchIntParam( param.first ); 00383 fetchParam->setValue( convertIntWithOptionalUnit( param.first, value ) ); 00384 break; 00385 } 00386 case OFX::eInt2DParam: 00387 { 00388 OFX::Int2DParam* fetchParam = IOPlugin::fetchInt2DParam( param.first ); 00389 if( param.second.size() == 2 ) 00390 { 00391 int x = convertIntWithOptionalUnit( param.first, param.second.at( 0 ) ); 00392 int y = convertIntWithOptionalUnit( param.first, param.second.at( 1 ) ); 00393 fetchParam->setValue( x, y ); 00394 } 00395 else 00396 { 00397 TUTTLE_LOG_WARNING( "avwriter: unable to set an 2D Int value with " << param.second.size() << " parameters." ); 00398 } 00399 break; 00400 } 00401 case OFX::eInt3DParam: 00402 { 00403 OFX::Int3DParam* fetchParam = IOPlugin::fetchInt3DParam( param.first ); 00404 if( param.second.size() == 3 ) 00405 { 00406 int x = convertIntWithOptionalUnit( param.first, param.second.at( 0 ) ); 00407 int y = convertIntWithOptionalUnit( param.first, param.second.at( 1 ) ); 00408 int z = convertIntWithOptionalUnit( param.first, param.second.at( 2 ) ); 00409 fetchParam->setValue( x, y, z ); 00410 } 00411 else 00412 { 00413 TUTTLE_LOG_WARNING( "avwriter: unable to set an 3D Int value with " << param.second.size() << " parameters." ); 00414 } 00415 break; 00416 } 00417 case OFX::eDoubleParam: 00418 { 00419 OFX::DoubleParam* fetchParam = IOPlugin::fetchDoubleParam( param.first ); 00420 try 00421 { 00422 double value = 0.0; 00423 value = boost::lexical_cast<double>( value ); 00424 fetchParam->setValue( value ); 00425 } 00426 catch( ... ) 00427 { 00428 TUTTLE_LOG_WARNING( "avwriter: parameter " << param.first << " can't convert the value: " << value ); 00429 } 00430 break; 00431 } 00432 case OFX::eDouble2DParam: 00433 { 00434 OFX::Double2DParam* fetchParam = IOPlugin::fetchDouble2DParam( param.first ); 00435 if( param.second.size() == 2 ) 00436 { 00437 try 00438 { 00439 double x = boost::lexical_cast<double>( param.second.at( 0 ) ); 00440 double y = boost::lexical_cast<double>( param.second.at( 1 ) ); 00441 fetchParam->setValue( x, y ); 00442 } 00443 catch( ... ) 00444 { 00445 TUTTLE_LOG_WARNING( "avwriter: parameter " << param.first << " can't convert the value: [" << param.second.at( 0 ) << ", " << param.second.at( 1 ) << "]" ); 00446 } 00447 } 00448 else 00449 { 00450 TUTTLE_LOG_WARNING("avwriter: unable to set an 2D Double value with " << param.second.size() << " parameters." ); 00451 } 00452 break; 00453 } 00454 case OFX::eDouble3DParam: 00455 { 00456 OFX::Double3DParam* fetchParam = IOPlugin::fetchDouble3DParam( param.first ); 00457 if( param.second.size() == 3 ) 00458 { 00459 try 00460 { 00461 double x = boost::lexical_cast<double>( param.second.at( 0 ) ); 00462 double y = boost::lexical_cast<double>( param.second.at( 1 ) ); 00463 double z = boost::lexical_cast<double>( param.second.at( 2 ) ); 00464 fetchParam->setValue( x, y, z ); 00465 } 00466 catch( ... ) 00467 { 00468 TUTTLE_LOG_WARNING( "avwriter: parameter " << param.first << " can't convert the value: [" << param.second.at( 0 ) << ", " << param.second.at( 1 ) << ", " << param.second.at( 2 ) << "]" ); 00469 } 00470 } 00471 else 00472 { 00473 TUTTLE_LOG_WARNING("avwriter: unable to set an 3D Double value with " << param.second.size() << " parameters." ); 00474 } 00475 break; 00476 } 00477 case OFX::eRGBParam: 00478 { 00479 OFX::RGBParam* fetchParam = IOPlugin::fetchRGBParam( param.first ); 00480 if( param.second.size() == 3 ) 00481 { 00482 try 00483 { 00484 double r = boost::lexical_cast<double>( param.second.at( 0 ) ); 00485 double g = boost::lexical_cast<double>( param.second.at( 1 ) ); 00486 double b = boost::lexical_cast<double>( param.second.at( 2 ) ); 00487 fetchParam->setValue( r, g, b ); 00488 } 00489 catch( ... ) 00490 { 00491 TUTTLE_LOG_WARNING( "avwriter: parameter " << param.first << " can't convert the value: [" << param.second.at( 0 ) << ", " << param.second.at( 1 ) << ", " << param.second.at( 2 ) << "]" ); 00492 } 00493 } 00494 else 00495 { 00496 TUTTLE_LOG_WARNING("avwriter: unable to set an RGB value with " << param.second.size() << " parameters." ); 00497 } 00498 break; 00499 } 00500 case OFX::eRGBAParam: 00501 { 00502 OFX::RGBAParam* fetchParam = IOPlugin::fetchRGBAParam( param.first ); 00503 if( param.second.size() == 4 ) 00504 { 00505 try 00506 { 00507 double r = boost::lexical_cast<double>( param.second.at( 0 ) ); 00508 double g = boost::lexical_cast<double>( param.second.at( 1 ) ); 00509 double b = boost::lexical_cast<double>( param.second.at( 2 ) ); 00510 double a = boost::lexical_cast<double>( param.second.at( 3 ) ); 00511 fetchParam->setValue( r, g, b, a ); 00512 } 00513 catch( ... ) 00514 { 00515 TUTTLE_LOG_WARNING( "avwriter: parameter " << param.first << " can't convert the value: [" << param.second.at( 0 ) << ", " << param.second.at( 1 ) << ", " << param.second.at( 2 ) << ", " << param.second.at( 3 ) << "]" ); 00516 } 00517 } 00518 else 00519 { 00520 TUTTLE_LOG_WARNING("avwriter: unable to set an RGBA value with " << param.second.size() << " parameters." ); 00521 } 00522 break; 00523 } 00524 case OFX::eBooleanParam: 00525 { 00526 OFX::BooleanParam* fetchParam = IOPlugin::fetchBooleanParam( param.first ); 00527 bool boolValue = ( value == "1" || boost::iequals(value, "y") || boost::iequals(value, "yes") || boost::iequals(value, "true") ); 00528 fetchParam->setValue( boolValue ); 00529 break; 00530 } 00531 case OFX::eChoiceParam: 00532 { 00533 OFX::ChoiceParam* fetchParam = IOPlugin::fetchChoiceParam( param.first ); 00534 int index = -1; 00535 for( int i = 0; i< fetchParam->getProps().propGetDimension( "OfxParamPropChoiceOption" ); i++ ) 00536 { 00537 if( fetchParam->getProps().propGetString( "OfxParamPropChoiceOption", i ) == value ) 00538 { 00539 index = i; 00540 break; 00541 } 00542 } 00543 if( index > -1 ) 00544 fetchParam->setValue( index ); 00545 else 00546 TUTTLE_LOG_WARNING( "avwriter: unable to find value " << value << " for parameter " << param.first ); 00547 break; 00548 } 00549 case OFX::ePushButtonParam: 00550 case OFX::eParametricParam: 00551 case OFX::eCustomParam: 00552 case OFX::eGroupParam: 00553 case OFX::ePageParam: 00554 case OFX::eCameraParam: 00555 default: 00556 { 00557 break; 00558 } 00559 } 00560 } 00561 else 00562 { 00563 TUTTLE_LOG_WARNING( "avwriter: parameter " << param.first << " not exist." ); 00564 } 00565 } 00566 } 00567 00568 template< typename IOPlugin > 00569 template< typename LibAVVideoRW > 00570 void AVOptionPlugin<IOPlugin>::optionSet( LibAVVideoRW& videoRW, const EAVParamType& type, const AVOption& opt, bool& value ) 00571 { 00572 int error = 0; 00573 switch( type ) 00574 { 00575 case eAVParamFormat: 00576 { 00577 error = av_opt_set_int( videoRW._avFormatOptions, opt.name, value, AV_OPT_SEARCH_CHILDREN ); 00578 break; 00579 } 00580 case eAVParamVideo: 00581 { 00582 error = av_opt_set_int( videoRW._stream->codec, opt.name, value, AV_OPT_SEARCH_CHILDREN ); 00583 break; 00584 } 00585 case eAVParamAudio: 00586 { 00587 error = 0; 00588 //av_opt_set_int( _avFormatOptions, opt.name, value, 0 ); 00589 break; 00590 } 00591 } 00592 if( error ) 00593 TUTTLE_LOG_WARNING( "avwriter: " << LibAV::libavError_toString( error ) << " : " << opt.name << " ( " << ( value ? "True" : "False" ) << " )" ); 00594 } 00595 00596 00597 template< typename IOPlugin > 00598 template< typename LibAVVideoRW > 00599 void AVOptionPlugin<IOPlugin>::optionSet( LibAVVideoRW& videoRW, const EAVParamType& type, const AVOption &opt, bool& value, std::string& valueToSetFlag ) 00600 { 00601 int error = 0; 00602 int64_t optVal; 00603 void* obj = NULL; 00604 switch( type ) 00605 { 00606 case eAVParamFormat: 00607 { 00608 obj = (void*) videoRW._avFormatOptions; 00609 break; 00610 } 00611 case eAVParamVideo: 00612 { 00613 obj = (void*) videoRW._stream->codec; 00614 break; 00615 } 00616 case eAVParamAudio: 00617 { 00618 //av_opt_set_int( _avFormatOptions, opt.name, value, 0 ); 00619 return; 00620 } 00621 } 00622 00623 error = av_opt_get_int( obj, opt.unit, AV_OPT_SEARCH_CHILDREN, &optVal ); 00624 00625 if( value ) 00626 optVal = optVal | (int64_t) opt.default_val.i64; 00627 else 00628 optVal = optVal &~(int64_t) opt.default_val.i64; 00629 00630 error = av_opt_set_int( obj, opt.unit, optVal, AV_OPT_SEARCH_CHILDREN ); 00631 00632 if( error ) 00633 TUTTLE_LOG_WARNING( "avwriter: " << LibAV::libavError_toString( error ) << " : " << valueToSetFlag << " ( " << opt.name << " = " << ( value ? "True" : "False" ) << " )" ); 00634 } 00635 00636 template< typename IOPlugin > 00637 template< typename LibAVVideoRW > 00638 void AVOptionPlugin<IOPlugin>::optionSet( LibAVVideoRW& videoRW, const EAVParamType& type, const AVOption& opt, int& value ) 00639 { 00640 int error = 0; 00641 switch( type ) 00642 { 00643 case eAVParamFormat: 00644 { 00645 error = av_opt_set_int( videoRW._avFormatOptions, opt.name, value, AV_OPT_SEARCH_CHILDREN ); 00646 break; 00647 } 00648 case eAVParamVideo: 00649 { 00650 00651 error = av_opt_set_int( videoRW._stream->codec, opt.name, value, AV_OPT_SEARCH_CHILDREN ); 00652 break; 00653 } 00654 case eAVParamAudio: 00655 { 00656 error = 0; 00657 //av_opt_set_int( _avFormatOptions, opt.name, value, 0 ); 00658 break; 00659 } 00660 } 00661 if( error ) 00662 TUTTLE_LOG_WARNING( "avwriter: " << LibAV::libavError_toString( error ) << " : " << opt.name << " ( " << value << " )" ); 00663 } 00664 00665 template< typename IOPlugin > 00666 template< typename LibAVVideoRW > 00667 void AVOptionPlugin<IOPlugin>::optionSet( LibAVVideoRW& videoRW, const EAVParamType& type, const AVOption &opt, double &value ) 00668 { 00669 int error = 0; 00670 switch( type ) 00671 { 00672 case eAVParamFormat: 00673 { 00674 error = av_opt_set_double( videoRW._avFormatOptions, opt.name, value, AV_OPT_SEARCH_CHILDREN ); 00675 break; 00676 } 00677 case eAVParamVideo: 00678 { 00679 error = av_opt_set_double( videoRW._stream->codec, opt.name, value, AV_OPT_SEARCH_CHILDREN ); 00680 break; 00681 } 00682 case eAVParamAudio: 00683 { 00684 error = 0; 00685 //av_opt_set_double( _avFormatOptions, opt.name, value, 0 ); 00686 break; 00687 } 00688 } 00689 if( error ) 00690 TUTTLE_LOG_WARNING( "avwriter: " << LibAV::libavError_toString( error ) << " : " << opt.name << " ( " << value << " )" ); 00691 } 00692 00693 template< typename IOPlugin > 00694 template< typename LibAVVideoRW > 00695 void AVOptionPlugin<IOPlugin>::optionSet( LibAVVideoRW& videoRW, const EAVParamType& type, const AVOption &opt, int &valueNum, int& valueDen ) 00696 { 00697 int error = 0; 00698 AVRational q; 00699 q.num = valueNum; 00700 q.den = valueDen; 00701 switch( type ) 00702 { 00703 case eAVParamFormat: 00704 { 00705 error = av_opt_set_q( videoRW._avFormatOptions, opt.name, q, AV_OPT_SEARCH_CHILDREN ); 00706 break; 00707 } 00708 case eAVParamVideo: 00709 { 00710 error = av_opt_set_q( videoRW._stream->codec, opt.name, q, AV_OPT_SEARCH_CHILDREN ); 00711 break; 00712 } 00713 case eAVParamAudio: 00714 { 00715 error = 0; 00716 //av_opt_set_q( _avFormatOptions, opt.name, q, 0 ); 00717 break; 00718 } 00719 } 00720 if( error ) 00721 TUTTLE_LOG_WARNING( "avwriter: " << LibAV::libavError_toString( error ) << " : " << opt.name << " ( " << valueNum << "/" << valueDen<< " )" ); 00722 } 00723 00724 template< typename IOPlugin > 00725 template< typename LibAVVideoRW > 00726 void AVOptionPlugin<IOPlugin>::optionSet( LibAVVideoRW& videoRW, const EAVParamType& type, const AVOption &opt, std::string &value ) 00727 { 00728 int error = 0; 00729 if( ! value.length() ) 00730 return; 00731 switch( type ) 00732 { 00733 case eAVParamFormat: 00734 { 00735 error = av_opt_set( videoRW._avFormatOptions, opt.name, value.c_str(), AV_OPT_SEARCH_CHILDREN ); 00736 break; 00737 } 00738 case eAVParamVideo: 00739 { 00740 error = av_opt_set( videoRW._stream->codec, opt.name, value.c_str(), AV_OPT_SEARCH_CHILDREN ); 00741 break; 00742 } 00743 case eAVParamAudio: 00744 { 00745 error = 0; 00746 //av_opt_set( _avFormatOptions, opt.name, value.c_str(), 0 ); 00747 break; 00748 } 00749 } 00750 if( error ) 00751 TUTTLE_LOG_WARNING( "avwriter: " << LibAV::libavError_toString( error ) << " : " << opt.name << " ( " << value << " )" ); 00752 } 00753 00754 00755 } 00756 } 00757 }