diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-07-09 02:06:40 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-07-09 02:06:40 +0200 |
commit | 58257ea29e0716a50dc742959de876606ed22416 (patch) | |
tree | a4949244816d4eb7a4231b1798b54bea4a79d4e5 /libavutil | |
parent | 971c04066c601bdd38ed5e8eb585d2f5ba211fe2 (diff) | |
parent | bda168d2b0210dda84f1a9d32c8aa4653d1674d5 (diff) | |
download | ffmpeg-58257ea29e0716a50dc742959de876606ed22416.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master: (28 commits)
mp3enc: write a xing frame containing number of frames in the file
lavf: update AVStream.nb_frames when muxing.
ffmpeg: remove unused variables from InputStream.
doc: update ffmpeg -ar and -ac documentation to reflect reality.
ffmpeg: remove pointless if (nb_input_files)
ffmpeg: merge input_files_ts_offset into input_files.
ffmpeg: merge input_codecs into input_streams.
ffmpeg: drop AV prefixes from struct names.
ffmpeg: deprecate loop_input and loop_output options
gif: add loop private option.
img2: add loop private option.
AVOptions: in av_opt_find() don't return named constants unless unit is specified.
x11grab: replace undocumented nomouse hackery with a private option.
dict: extend documentation.
lls: whitespace cosmetics
docs: Use proper markup for a literal command line option
docs: Remove a remark that isn't relevant any longer
docs: Explain how to regenerate import libraries with MSVC tools
docs: Mention that libraries for MSVC can be built with a cross compiler
docs: Remove old docs that mention setting up a build environment with lib.exe
...
Conflicts:
doc/ffmpeg.texi
doc/general.texi
ffmpeg.c
libavcodec/Makefile
libavcodec/dnxhddata.c
libavformat/mp3enc.c
libavformat/utils.c
libavutil/Makefile
tests/copycooker.sh
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/Makefile | 3 | ||||
-rw-r--r-- | libavutil/dict.h | 39 | ||||
-rw-r--r-- | libavutil/lls.c | 133 | ||||
-rw-r--r-- | libavutil/opt.c | 5 |
4 files changed, 115 insertions, 65 deletions
diff --git a/libavutil/Makefile b/libavutil/Makefile index ad2a3eeee5..5ff5cb8e79 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -77,7 +77,8 @@ OBJS-$(ARCH_ARM) += arm/cpu.o OBJS-$(ARCH_PPC) += ppc/cpu.o OBJS-$(ARCH_X86) += x86/cpu.o -TESTPROGS = adler32 aes base64 cpu crc des eval lls md5 pca sha tree +TESTPROGS = adler32 aes avstring base64 cpu crc des eval file lfg lls \ + md5 opt pca parseutils rational sha tree TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo DIRS = arm bfin sh4 x86 diff --git a/libavutil/dict.h b/libavutil/dict.h index 3982b0dae9..84f58ec473 100644 --- a/libavutil/dict.h +++ b/libavutil/dict.h @@ -31,10 +31,42 @@ #ifndef AVUTIL_DICT_H #define AVUTIL_DICT_H +/** + * @defgroup dict_api Public Dictionary API + * @{ + * Dictionaries are used for storing key:value pairs. To create + * an AVDictionary, simply pass an address of a NULL pointer to + * av_dict_set(). NULL can be used as an empty dictionary wherever + * a pointer to an AVDictionary is required. + * Use av_dict_get() to retrieve an entry or iterate over all + * entries and finally av_dict_free() to free the dictionary + * and all its contents. + * + * @code + * AVDictionary *d = NULL; // "create" an empty dictionary + * av_dict_set(&d, "foo", "bar", 0); // add an entry + * + * char *k = av_strdup("key"); // if your strings are already allocated, + * char *v = av_strdup("value"); // you can avoid copying them like this + * av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL); + * + * AVDictionaryEntry *t = NULL; + * while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) { + * <....> // iterate over all entries in d + * } + * + * av_dict_free(&d); + * @endcode + * + * @} + */ + #define AV_DICT_MATCH_CASE 1 #define AV_DICT_IGNORE_SUFFIX 2 -#define AV_DICT_DONT_STRDUP_KEY 4 -#define AV_DICT_DONT_STRDUP_VAL 8 +#define AV_DICT_DONT_STRDUP_KEY 4 /**< Take ownership of a key that's been + allocated with av_malloc() and children. */ +#define AV_DICT_DONT_STRDUP_VAL 8 /**< Take ownership of a value that's been + allocated with av_malloc() and chilren. */ #define AV_DICT_DONT_OVERWRITE 16 ///< Don't overwrite existing entries. #define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no delimiter is added, the strings are simply concatenated. */ @@ -80,7 +112,8 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags); /** - * Free all the memory allocated for an AVDictionary struct. + * Free all the memory allocated for an AVDictionary struct + * and all keys and values. */ void av_dict_free(AVDictionary **m); diff --git a/libavutil/lls.c b/libavutil/lls.c index 3855792760..5f59db6ea3 100644 --- a/libavutil/lls.c +++ b/libavutil/lls.c @@ -30,76 +30,88 @@ #include "lls.h" -void av_init_lls(LLSModel *m, int indep_count){ +void av_init_lls(LLSModel *m, int indep_count) +{ memset(m, 0, sizeof(LLSModel)); - - m->indep_count= indep_count; + m->indep_count = indep_count; } -void av_update_lls(LLSModel *m, double *var, double decay){ - int i,j; +void av_update_lls(LLSModel *m, double *var, double decay) +{ + int i, j; - for(i=0; i<=m->indep_count; i++){ - for(j=i; j<=m->indep_count; j++){ + for (i = 0; i <= m->indep_count; i++) { + for (j = i; j <= m->indep_count; j++) { m->covariance[i][j] *= decay; - m->covariance[i][j] += var[i]*var[j]; + m->covariance[i][j] += var[i] * var[j]; } } } -void av_solve_lls(LLSModel *m, double threshold, int min_order){ - int i,j,k; - double (*factor)[MAX_VARS+1]= (void*)&m->covariance[1][0]; - double (*covar )[MAX_VARS+1]= (void*)&m->covariance[1][1]; - double *covar_y = m->covariance[0]; - int count= m->indep_count; - - for(i=0; i<count; i++){ - for(j=i; j<count; j++){ - double sum= covar[i][j]; - - for(k=i-1; k>=0; k--) - sum -= factor[i][k]*factor[j][k]; - - if(i==j){ - if(sum < threshold) - sum= 1.0; - factor[i][i]= sqrt(sum); - }else - factor[j][i]= sum / factor[i][i]; +void av_solve_lls(LLSModel *m, double threshold, int min_order) +{ + int i, j, k; + double (*factor)[MAX_VARS + 1] = (void *) &m->covariance[1][0]; + double (*covar) [MAX_VARS + 1] = (void *) &m->covariance[1][1]; + double *covar_y = m->covariance[0]; + int count = m->indep_count; + + for (i = 0; i < count; i++) { + for (j = i; j < count; j++) { + double sum = covar[i][j]; + + for (k = i - 1; k >= 0; k--) + sum -= factor[i][k] * factor[j][k]; + + if (i == j) { + if (sum < threshold) + sum = 1.0; + factor[i][i] = sqrt(sum); + } else { + factor[j][i] = sum / factor[i][i]; + } } } - for(i=0; i<count; i++){ - double sum= covar_y[i+1]; - for(k=i-1; k>=0; k--) - sum -= factor[i][k]*m->coeff[0][k]; - m->coeff[0][i]= sum / factor[i][i]; + + for (i = 0; i < count; i++) { + double sum = covar_y[i + 1]; + + for (k = i - 1; k >= 0; k--) + sum -= factor[i][k] * m->coeff[0][k]; + + m->coeff[0][i] = sum / factor[i][i]; } - for(j=count-1; j>=min_order; j--){ - for(i=j; i>=0; i--){ - double sum= m->coeff[0][i]; - for(k=i+1; k<=j; k++) - sum -= factor[k][i]*m->coeff[j][k]; - m->coeff[j][i]= sum / factor[i][i]; + for (j = count - 1; j >= min_order; j--) { + for (i = j; i >= 0; i--) { + double sum = m->coeff[0][i]; + + for (k = i + 1; k <= j; k++) + sum -= factor[k][i] * m->coeff[j][k]; + + m->coeff[j][i] = sum / factor[i][i]; } - m->variance[j]= covar_y[0]; - for(i=0; i<=j; i++){ - double sum= m->coeff[j][i]*covar[i][i] - 2*covar_y[i+1]; - for(k=0; k<i; k++) - sum += 2*m->coeff[j][k]*covar[k][i]; - m->variance[j] += m->coeff[j][i]*sum; + m->variance[j] = covar_y[0]; + + for (i = 0; i <= j; i++) { + double sum = m->coeff[j][i] * covar[i][i] - 2 * covar_y[i + 1]; + + for (k = 0; k < i; k++) + sum += 2 * m->coeff[j][k] * covar[k][i]; + + m->variance[j] += m->coeff[j][i] * sum; } } } -double av_evaluate_lls(LLSModel *m, double *param, int order){ +double av_evaluate_lls(LLSModel *m, double *param, int order) +{ int i; - double out= 0; + double out = 0; - for(i=0; i<=order; i++) - out+= param[i]*m->coeff[order][i]; + for (i = 0; i <= order; i++) + out += param[i] * m->coeff[order][i]; return out; } @@ -109,26 +121,29 @@ double av_evaluate_lls(LLSModel *m, double *param, int order){ #include <stdlib.h> #include <stdio.h> -int main(void){ +int main(void) +{ LLSModel m; int i, order; av_init_lls(&m, 3); - for(i=0; i<100; i++){ + for (i = 0; i < 100; i++) { double var[4]; double eval; - var[0] = (rand() / (double)RAND_MAX - 0.5)*2; - var[1] = var[0] + rand() / (double)RAND_MAX - 0.5; - var[2] = var[1] + rand() / (double)RAND_MAX - 0.5; - var[3] = var[2] + rand() / (double)RAND_MAX - 0.5; + + var[0] = (rand() / (double) RAND_MAX - 0.5) * 2; + var[1] = var[0] + rand() / (double) RAND_MAX - 0.5; + var[2] = var[1] + rand() / (double) RAND_MAX - 0.5; + var[3] = var[2] + rand() / (double) RAND_MAX - 0.5; av_update_lls(&m, var, 0.99); av_solve_lls(&m, 0.001, 0); - for(order=0; order<3; order++){ - eval= av_evaluate_lls(&m, var+1, order); + for (order = 0; order < 3; order++) { + eval = av_evaluate_lls(&m, var + 1, order); printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n", - var[0], order, eval, sqrt(m.variance[order] / (i+1)), - m.coeff[order][0], m.coeff[order][1], m.coeff[order][2]); + var[0], order, eval, sqrt(m.variance[order] / (i + 1)), + m.coeff[order][0], m.coeff[order][1], + m.coeff[order][2]); } } return 0; diff --git a/libavutil/opt.c b/libavutil/opt.c index 60fc307c0e..609167ef62 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -575,8 +575,9 @@ const AVOption *av_opt_find(void *obj, const char *name, const char *unit, return o; while (o = av_next_option(obj, o)) { - if (!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) && - (o->flags & opt_flags) == opt_flags) + if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags && + ((!unit && o->type != FF_OPT_TYPE_CONST) || + (unit && o->unit && !strcmp(o->unit, unit)))) return o; } return NULL; |