static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){ const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); void *dst; if(!o || o->offset<=0) return NULL; if(o->max*den < num*intnum || o->min*den > num*intnum) { av_log(NULL, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range.\n", num, name); return NULL; } dst= ((uint8_t*)obj) + o->offset; switch(o->type){ case FF_OPT_TYPE_FLAGS: case FF_OPT_TYPE_INT: *(int *)dst= llrint(num/den)*intnum; break; case FF_OPT_TYPE_INT64: *(int64_t *)dst= llrint(num/den)*intnum; break; case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break; case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break; case FF_OPT_TYPE_RATIONAL: if((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den}; else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24); break; default: return NULL; } return o; }
/** * * @param buf a buffer which is used for returning non string values as strings, can be NULL * @param buf_len allocated length in bytes of buf */ const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len){ const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); void *dst; uint8_t *bin; int len, i; if(!o || o->offset<=0) return NULL; if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) return NULL; dst= ((uint8_t*)obj) + o->offset; if(o_out) *o_out= o; switch(o->type){ case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break; case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break; case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break; case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; case FF_OPT_TYPE_STRING: return *(void**)dst; case FF_OPT_TYPE_BINARY: len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *)); if(len >= (buf_len + 1)/2) return NULL; bin = *(uint8_t**)dst; for(i = 0; i < len; i++) snprintf(buf + i*2, 3, "%02X", bin[i]); break; default: return NULL; } return buf; }
AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, URLContext *handle, int packet_size) { AVFormatContext *rtpctx; int ret; AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); if (!rtp_format) return NULL; /* Allocate an AVFormatContext for each output stream */ rtpctx = avformat_alloc_context(); if (!rtpctx) return NULL; rtpctx->oformat = rtp_format; if (!av_new_stream(rtpctx, 0)) { av_free(rtpctx); return NULL; } /* Copy the max delay setting; the rtp muxer reads this. */ rtpctx->max_delay = s->max_delay; /* Copy other stream parameters. */ rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio; rtpctx->flags |= s->flags & AVFMT_FLAG_MP4A_LATM; av_set_parameters(rtpctx, NULL); /* Copy the rtpflags values straight through */ if (s->oformat->priv_class && av_find_opt(s->priv_data, "rtpflags", NULL, 0, 0)) av_set_int(rtpctx->priv_data, "rtpflags", av_get_int(s->priv_data, "rtpflags", NULL)); /* Set the synchronized start time. */ rtpctx->start_time_realtime = s->start_time_realtime; avcodec_copy_context(rtpctx->streams[0]->codec, st->codec); if (handle) { ffio_fdopen(&rtpctx->pb, handle); } else ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size); ret = avformat_write_header(rtpctx, NULL); if (ret) { if (handle) { avio_close(rtpctx->pb); } else { uint8_t *ptr; avio_close_dyn_buf(rtpctx->pb, &ptr); av_free(ptr); } avformat_free_context(rtpctx); return NULL; } return rtpctx; }
static int opt_default(const char *opt, const char *arg, AVCodecContext *avctx, int type) { int ret = 0; const AVOption *o = av_find_opt(avctx, opt, NULL, type, type); if (o != NULL) { ret = av_set_string3(avctx, opt, arg, 1, NULL); } return ret; }
int opt_default(const char *opt, const char *arg){ int type; int ret= 0; const AVOption *o= NULL; int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0}; for(type=0; type<AVMEDIA_TYPE_NB && ret>= 0; type++){ const AVOption *o2 = av_find_opt(avcodec_opts[0], opt, NULL, opt_types[type], opt_types[type]); if(o2) ret = av_set_string3(avcodec_opts[type], opt, arg, 1, &o); } if(!o) ret = av_set_string3(avformat_opts, opt, arg, 1, &o); if(!o && sws_opts) ret = av_set_string3(sws_opts, opt, arg, 1, &o); if(!o){ if(opt[0] == 'a') ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_AUDIO], opt+1, arg, 1, &o); else if(opt[0] == 'v') ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_VIDEO], opt+1, arg, 1, &o); else if(opt[0] == 's') ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], opt+1, arg, 1, &o); } if (o && ret < 0) { fprintf(stderr, "Invalid value '%s' for option '%s'\n", arg, opt); exit(1); } if (!o) { fprintf(stderr, "Unrecognized option '%s'\n", opt); exit(1); } // av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avcodec_opts, opt, NULL), (int)av_get_int(avcodec_opts, opt, NULL)); //FIXME we should always use avcodec_opts, ... for storing options so there will not be any need to keep track of what i set over this opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1)); opt_names[opt_name_count++]= o->name; if(avcodec_opts[0]->debug || avformat_opts->debug) av_log_set_level(AV_LOG_DEBUG); return 0; }
void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec) { int i; void *priv_ctx=NULL; if(!strcmp("AVCodecContext", (*(AVClass**)ctx)->class_name)){ AVCodecContext *avctx= ctx; if(codec && codec->priv_class && avctx->priv_data){ priv_ctx= avctx->priv_data; } } else if (!strcmp("AVFormatContext", (*(AVClass**)ctx)->class_name)) { AVFormatContext *avctx = ctx; if (avctx->oformat && avctx->oformat->priv_class) { priv_ctx = avctx->priv_data; } else if (avctx->iformat && avctx->iformat->priv_class) { priv_ctx = avctx->priv_data; } } for(i=0; i<opt_name_count; i++){ char buf[256]; const AVOption *opt; const char *str; if (priv_ctx) { if (av_find_opt(priv_ctx, opt_names[i], NULL, flags, flags)) { if (av_set_string3(priv_ctx, opt_names[i], opt_values[i], 1, NULL) < 0) { fprintf(stderr, "Invalid value '%s' for option '%s'\n", opt_names[i], opt_values[i]); exit(1); } } else goto global; } else { global: str = av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf)); /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */ if (str && ((opt->flags & flags) == flags)) av_set_string3(ctx, opt_names[i], str, 1, NULL); } } }
static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum){ const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); void *dst; if(!o || o->offset<=0) goto error; dst= ((uint8_t*)obj) + o->offset; if(o_out) *o_out= o; switch(o->type){ case FF_OPT_TYPE_FLAGS: *intnum= *(unsigned int*)dst;return 0; case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0; case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0; case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0; case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0; case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num; *den = ((AVRational*)dst)->den; return 0; } error: *den=*intnum=0; return -1; }
int opt_default(const char *opt, const char *arg){ int type; int ret= 0; const AVOption *o= NULL; int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0}; AVCodec *p = NULL; AVOutputFormat *oformat = NULL; AVInputFormat *iformat = NULL; while ((p = av_codec_next(p))) { AVClass *c = p->priv_class; if (c && av_find_opt(&c, opt, NULL, 0, 0)) break; } if (p) goto out; while ((oformat = av_oformat_next(oformat))) { const AVClass *c = oformat->priv_class; if (c && av_find_opt(&c, opt, NULL, 0, 0)) break; } if (oformat) goto out; while ((iformat = av_iformat_next(iformat))) { const AVClass *c = iformat->priv_class; if (c && av_find_opt(&c, opt, NULL, 0, 0)) break; } if (iformat) goto out; for(type=0; *avcodec_opts && type<AVMEDIA_TYPE_NB && ret>= 0; type++){ const AVOption *o2 = av_find_opt(avcodec_opts[0], opt, NULL, opt_types[type], opt_types[type]); if(o2) ret = av_set_string3(avcodec_opts[type], opt, arg, 1, &o); } if(!o && avformat_opts) ret = av_set_string3(avformat_opts, opt, arg, 1, &o); if(!o && sws_opts) ret = av_set_string3(sws_opts, opt, arg, 1, &o); if(!o){ if (opt[0] == 'a' && avcodec_opts[AVMEDIA_TYPE_AUDIO]) ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_AUDIO], opt+1, arg, 1, &o); else if(opt[0] == 'v' && avcodec_opts[AVMEDIA_TYPE_VIDEO]) ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_VIDEO], opt+1, arg, 1, &o); else if(opt[0] == 's' && avcodec_opts[AVMEDIA_TYPE_SUBTITLE]) ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], opt+1, arg, 1, &o); if (ret >= 0) opt += 1; } if (o && ret < 0) { fprintf(stderr, "Invalid value '%s' for option '%s'\n", arg, opt); exit(1); } if (!o) { fprintf(stderr, "Unrecognized option '%s'\n", opt); exit(1); } out: // av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avcodec_opts, opt, NULL), (int)av_get_int(avcodec_opts, opt, NULL)); opt_values= av_realloc(opt_values, sizeof(void*)*(opt_name_count+1)); opt_values[opt_name_count] = av_strdup(arg); opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1)); opt_names[opt_name_count++] = av_strdup(opt); if ((*avcodec_opts && avcodec_opts[0]->debug) || (avformat_opts && avformat_opts->debug)) av_log_set_level(AV_LOG_DEBUG); return 0; }
const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){ const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){ return set_all_opt(obj, o->unit, o->default_val); } if(!o || !val || o->offset<=0) return NULL; if(o->type == FF_OPT_TYPE_BINARY){ uint8_t **dst = (uint8_t **)(((uint8_t*)obj) + o->offset); int *lendst = (int *)(dst + 1); uint8_t *bin, *ptr; int len = strlen(val); av_freep(dst); *lendst = 0; if (len & 1) return NULL; len /= 2; ptr = bin = av_malloc(len); while (*val) { int a = hexchar2int(*val++); int b = hexchar2int(*val++); if (a < 0 || b < 0) { av_free(bin); return NULL; } *ptr++ = (a << 4) | b; } *dst = bin; *lendst = len; return o; } if(o->type != FF_OPT_TYPE_STRING){ int notfirst=0; for(;;){ int i; char buf[256]; int cmd=0; double d; const char *error = NULL; if(*val == '+' || *val == '-') cmd= *(val++); for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+' && val[i]!='-'; i++) buf[i]= val[i]; buf[i]=0; d = ff_eval2(buf, (double *)const_values, (const char **)const_names, NULL, NULL, NULL, NULL, NULL, &error); if(isnan(d)) { const AVOption *o_named= av_find_opt(obj, buf, o->unit, 0, 0); if(o_named && o_named->type == FF_OPT_TYPE_CONST) d= o_named->default_val; else if(!strcmp(buf, "default")) d= o->default_val; else if(!strcmp(buf, "max" )) d= o->max; else if(!strcmp(buf, "min" )) d= o->min; else if(!strcmp(buf, "none" )) d= 0; else if(!strcmp(buf, "all" )) d= ~0; else { if (error) av_log(NULL, AV_LOG_ERROR, "Unable to parse option value \"%s\": %s\n", val, error); return NULL; } } if(o->type == FF_OPT_TYPE_FLAGS){ if (cmd=='+') d= av_get_int(obj, name, NULL) | (int64_t)d; else if(cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d; }else{ if (cmd=='+') d= notfirst*av_get_double(obj, name, NULL) + d; else if(cmd=='-') d= notfirst*av_get_double(obj, name, NULL) - d; } if (!av_set_number(obj, name, d, 1, 1)) return NULL; val+= i; if(!*val) return o; notfirst=1; } return NULL; } if(alloc){ av_free(*(void**)(((uint8_t*)obj) + o->offset)); val= av_strdup(val); } memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val)); return o; }