summaryrefslogtreecommitdiff
path: root/libavutil/opt.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-11-02 14:17:17 +0100
committerStefano Sabatini <stefasab@gmail.com>2012-11-03 12:14:26 +0100
commit481fdeeecfc2beafd7b87d6875839d428bd4e6b8 (patch)
tree4c6112ffa6d415bf25442bc39393487dc8470030 /libavutil/opt.c
parent7be09a91c2994131385f27c2f7726e04cf3841ce (diff)
lavu/opt: add AV_OPT_SAMPLE_FMT option
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r--libavutil/opt.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/libavutil/opt.c b/libavutil/opt.c
index ed475ecc92..d65f7f38a6 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -35,6 +35,7 @@
#include "parseutils.h"
#include "pixdesc.h"
#include "mathematics.h"
+#include "samplefmt.h"
#if FF_API_FIND_OPT
//FIXME order them and do a bin search
@@ -279,6 +280,22 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
}
*(enum AVPixelFormat *)dst = ret;
return 0;
+ case AV_OPT_TYPE_SAMPLE_FMT:
+ if (!val || !strcmp(val, "none")) {
+ ret = AV_SAMPLE_FMT_NONE;
+ } else {
+ ret = av_get_sample_fmt(val);
+ if (ret == AV_SAMPLE_FMT_NONE) {
+ char *tail;
+ ret = strtol(val, &tail, 0);
+ if (*tail || (unsigned)ret >= AV_SAMPLE_FMT_NB) {
+ av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as sample format\n", val);
+ return AVERROR(EINVAL);
+ }
+ }
+ }
+ *(enum AVSampleFormat *)dst = ret;
+ return 0;
}
av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
@@ -467,6 +484,9 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
case AV_OPT_TYPE_PIXEL_FMT:
ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
break;
+ case AV_OPT_TYPE_SAMPLE_FMT:
+ ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
+ break;
default:
return AVERROR(EINVAL);
}
@@ -642,6 +662,9 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
case AV_OPT_TYPE_PIXEL_FMT:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<pix_fmt>");
break;
+ case AV_OPT_TYPE_SAMPLE_FMT:
+ av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<sample_fmt>");
+ break;
case AV_OPT_TYPE_CONST:
default:
av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "");
@@ -992,6 +1015,7 @@ typedef struct TestContext
AVRational rational;
int w, h;
enum AVPixelFormat pix_fmt;
+ enum AVSampleFormat sample_fmt;
} TestContext;
#define OFFSET(x) offsetof(TestContext, x)
@@ -1011,6 +1035,7 @@ static const AVOption test_options[]= {
{"mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_MU}, INT_MIN, INT_MAX, 0, "flags" },
{"size", "set size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE,{0}, 0, 0 },
{"pix_fmt", "set pixfmt", OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT,{0}, 0, 0 },
+{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT,{0}, 0, 0 },
{NULL},
};
@@ -1058,6 +1083,9 @@ int main(void)
"pix_fmt=yuv420p",
"pix_fmt=2",
"pix_fmt=bogus",
+ "sample_fmt=s16",
+ "sample_fmt=2",
+ "sample_fmt=bogus",
};
test_ctx.class = &test_class;