From b0970a69d11919b41c19a2901d4a7c2cf0b4ba2f Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 14 May 2012 15:44:30 -0700 Subject: fate: document TARGET_EXEC and its usage TARGET_EXEC allows running FATE on simulators, remote targets and memory checkers. Also document a known issue with Wine and mixed Unix/Windows line ending. --- doc/fate.texi | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/fate.texi b/doc/fate.texi index b69301ac84..4b0250582b 100644 --- a/doc/fate.texi +++ b/doc/fate.texi @@ -29,6 +29,9 @@ To inform the build system about the testsuite location, pass @var{SAMPLES} Make variable or the @var{LIBAV_SAMPLES} environment variable to a suitable value. +To use a custom wrapper to run the test, pass @option{--target-exec} to +@command{configure} or set the @var{TARGET_EXEC} Make variable. + The dataset is available through @command{rsync}, is possible to fetch the current sample using the straight rsync command or through a specific @ref{Makefile target}. @@ -57,7 +60,7 @@ Shortcut to download the fate test samples to the specified testsuite location. Run the FATE test suite (requires the fate-suite dataset). @end table -@section Fate Makefile variables +@section FATE Makefile variables @table @option @item V Verbosity level, can be set to 0, 1 or 2. @@ -77,6 +80,8 @@ Specify how many threads to use while running regression tests, it is quite useful to detect thread-related regressions. @item CPUFLAGS Specify a mask to be applied to autodetected CPU flags. +@item TARGET_EXEC +Specify or override the wrapper used to run the tests. @end table @example @@ -131,6 +136,11 @@ makeopts= # extra options passed to 'make' # stdout, defaults to 'tar c' @end example +@section Special Instances +The @var{TARGET_EXEC} option provides a way to run FATE wrapped in +@command{valgrind}, @command{qemu-user} or @command{wine} or on remote targets +through @command{ssh}. + @section Submitting Reports In order to send reports you need to create an @command{ssh} key and send it to @email{root@@libav.org}. -- cgit v1.2.3 From c6eeb9b7b6bbf5d0f507cad522ed5a4f929de14f Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 14 May 2012 17:24:27 -0700 Subject: rtmp: fix url parsing The application component can have a subcomponent to specify the application instance even if it doesn't have a ":" in the playpath. --- doc/protocols.texi | 2 +- libavformat/rtmpproto.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index d6e12f73e3..172184e501 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -164,7 +164,7 @@ content across a TCP/IP network. The required syntax is: @example -rtmp://@var{server}[:@var{port}][/@var{app}][/@var{playpath}] +rtmp://@var{server}[:@var{port}][/@var{app}][/@var{instance}][/@var{playpath}] @end example The accepted parameters are: diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 9af4584226..807e899f34 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -1037,9 +1037,10 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) fname = next; rt->app[0] = '\0'; } else { + // make sure we do not mismatch a playpath for an application instance char *c = strchr(p + 1, ':'); fname = strchr(p + 1, '/'); - if (!fname || c < fname) { + if (!fname || (c && c < fname)) { fname = p + 1; av_strlcpy(rt->app, path + 1, p - path); } else { -- cgit v1.2.3 From beb33fca697e4a7ecfe1661d0699a0d55f23f03a Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 25 May 2012 11:47:06 -0700 Subject: avprobe: improve formatting Do not use decimals if not needed. --- avprobe.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/avprobe.c b/avprobe.c index 6182875d91..5df6937db5 100644 --- a/avprobe.c +++ b/avprobe.c @@ -90,11 +90,12 @@ static char *value_string(char *buf, int buf_size, double val, const char *unit) val /= pow(10, index * 3); prefix_string = decimal_unit_prefixes[index]; } - - snprintf(buf, buf_size, "%.3f %s%s", val, prefix_string, + snprintf(buf, buf_size, "%.*f%s%s", + index ? 3 : 0, val, + prefix_string, show_value_unit ? unit : ""); } else { - snprintf(buf, buf_size, "%f %s", val, show_value_unit ? unit : ""); + snprintf(buf, buf_size, "%f%s", val, show_value_unit ? unit : ""); } return buf; -- cgit v1.2.3 From 3a8c95f730732b9f1ffacdbfbf79a01b202a67af Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 17 May 2012 18:02:57 -0700 Subject: avprobe: output proper INI format Make the output valid INI serialization. --- avprobe.c | 502 ++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 393 insertions(+), 109 deletions(-) diff --git a/avprobe.c b/avprobe.c index 5df6937db5..f3bb437b1e 100644 --- a/avprobe.c +++ b/avprobe.c @@ -64,6 +64,262 @@ void exit_program(int ret) exit(ret); } +/* + * The output is structured in array and objects that might contain items + * Array could require the objects within to not be named. + * Object could require the items within to be named. + * + * For flat representation the name of each section is saved on prefix so it + * can be rendered in order to represent nested structures (e.g. array of + * objects for the packets list). + * + * Within an array each element can need an unique identifier or an index. + * + * Nesting level is accounted separately. + */ + +typedef enum { + ARRAY, + OBJECT +} ProbeElementType; + +typedef struct { + const char *name; + ProbeElementType type; + int64_t index; + int64_t nb_elems; +} ProbeElement; + +typedef struct { + ProbeElement *prefix; + int level; +} OutputContext; + +static AVIOContext *probe_out = NULL; +static OutputContext octx; + +/* + * Default format, INI + * + * - all key and values are utf8 + * - '.' is the subgroup separator + * - newlines and the following characters are escaped + * - '\' is the escape character + * - '#' is the comment + * - '=' is the key/value separators + * - ':' is not used but usually parsed as key/value separator + */ + +static void ini_print_header(void) +{ + avio_printf(probe_out, "# avprobe output\n\n"); +} +static void ini_print_footer(void) +{ + avio_w8(probe_out, '\n'); +} + +static void ini_escape_print(const char *s) +{ + int i = 0; + char c = 0; + + while (c = s[i++]) { + switch (c) { + case '\r': avio_printf(probe_out, "%s", "\\r"); break; + case '\n': avio_printf(probe_out, "%s", "\\n"); break; + case '\f': avio_printf(probe_out, "%s", "\\f"); break; + case '\b': avio_printf(probe_out, "%s", "\\b"); break; + case '\t': avio_printf(probe_out, "%s", "\\t"); break; + case '\\': + case '#' : + case '=' : + case ':' : avio_w8(probe_out, '\\'); + default: + if ((unsigned char)c < 32) + avio_printf(probe_out, "\\x00%02x", c & 0xff); + else + avio_w8(probe_out, c); + break; + } + } +} + +static void ini_print_array_header(const char *name) +{ + if (octx.prefix[octx.level -1].nb_elems) + avio_printf(probe_out, "\n"); +} + +static void ini_print_object_header(const char *name) +{ + int i; + ProbeElement *el = octx.prefix + octx.level -1; + + if (el->nb_elems) + avio_printf(probe_out, "\n"); + + avio_printf(probe_out, "["); + + for (i = 1; i < octx.level; i++) { + el = octx.prefix + i; + avio_printf(probe_out, "%s.", el->name); + if (el->index >= 0) + avio_printf(probe_out, "%"PRId64".", el->index); + } + + avio_printf(probe_out, "%s", name); + if (el && el->type == ARRAY) + avio_printf(probe_out, ".%"PRId64"", el->nb_elems); + avio_printf(probe_out, "]\n"); +} + +static void ini_print_integer(const char *key, int64_t value) +{ + ini_escape_print(key); + avio_printf(probe_out, "=%"PRId64"\n", value); +} + + +static void ini_print_string(const char *key, const char *value) +{ + ini_escape_print(key); + avio_printf(probe_out, "="); + ini_escape_print(value); + avio_w8(probe_out, '\n'); +} + +/* + * Simple Formatter for single entries. + */ + +static void show_format_entry_integer(const char *key, int64_t value) +{ + if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) { + if (nb_fmt_entries_to_show > 1) + avio_printf(probe_out, "%s=", key); + avio_printf(probe_out, "%"PRId64"\n", value); + } +} + +static void show_format_entry_string(const char *key, const char *value) +{ + if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) { + if (nb_fmt_entries_to_show > 1) + avio_printf(probe_out, "%s=", key); + avio_printf(probe_out, "%s\n", value); + } +} + + +void (*print_header)(void) = ini_print_header; +void (*print_footer)(void) = ini_print_footer; + +void (*print_array_header) (const char *name) = ini_print_array_header; +void (*print_array_footer) (const char *name); +void (*print_object_header)(const char *name) = ini_print_object_header; +void (*print_object_footer)(const char *name); + +void (*print_integer) (const char *key, int64_t value) = ini_print_integer; +void (*print_string) (const char *key, const char *value) = ini_print_string; + + +static void probe_group_enter(const char *name, int type) +{ + int64_t count = -1; + + octx.prefix = + av_realloc(octx.prefix, sizeof(ProbeElement) * (octx.level + 1)); + + if (!octx.prefix || !name) { + fprintf(stderr, "Out of memory\n"); + exit(1); + } + + if (octx.level) { + ProbeElement *parent = octx.prefix + octx.level -1; + if (parent->type == ARRAY) + count = parent->nb_elems; + parent->nb_elems++; + } + + octx.prefix[octx.level++] = (ProbeElement){name, type, count, 0}; +} + +static void probe_group_leave(void) +{ + --octx.level; +} + +static void probe_header(void) +{ + if (print_header) + print_header(); + probe_group_enter("root", OBJECT); +} + +static void probe_footer(void) +{ + if (print_footer) + print_footer(); + probe_group_leave(); +} + + +static void probe_array_header(const char *name) +{ + if (print_array_header) + print_array_header(name); + + probe_group_enter(name, ARRAY); +} + +static void probe_array_footer(const char *name) +{ + probe_group_leave(); + if (print_array_footer) + print_array_footer(name); +} + +static void probe_object_header(const char *name) +{ + if (print_object_header) + print_object_header(name); + + probe_group_enter(name, OBJECT); +} + +static void probe_object_footer(const char *name) +{ + probe_group_leave(); + if (print_object_footer) + print_object_footer(name); +} + +static void probe_int(const char *key, int64_t value) +{ + print_integer(key, value); + octx.prefix[octx.level -1].nb_elems++; +} + +static void probe_str(const char *key, const char *value) +{ + print_string(key, value); + octx.prefix[octx.level -1].nb_elems++; +} + +static void probe_dict(AVDictionary *dict, const char *name) +{ + AVDictionaryEntry *entry = NULL; + if (!dict) + return; + probe_object_header(name); + while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) { + probe_str(entry->key, entry->value); + } + probe_object_footer(name); +} + static char *value_string(char *buf, int buf_size, double val, const char *unit) { if (unit == unit_second_str && use_value_sexagesimal_format) { @@ -113,7 +369,7 @@ static char *time_value_string(char *buf, int buf_size, int64_t val, return buf; } -static char *ts_value_string (char *buf, int buf_size, int64_t ts) +static char *ts_value_string(char *buf, int buf_size, int64_t ts) { if (ts == AV_NOPTS_VALUE) { snprintf(buf, buf_size, "N/A"); @@ -124,6 +380,21 @@ static char *ts_value_string (char *buf, int buf_size, int64_t ts) return buf; } +static char *rational_string(char *buf, int buf_size, const char *sep, + const AVRational *rat) +{ + snprintf(buf, buf_size, "%d%s%d", rat->num, sep, rat->den); + return buf; +} + +static char *tag_string(char *buf, int buf_size, int tag) +{ + snprintf(buf, buf_size, "0x%04x", tag); + return buf; +} + + + static const char *media_type_string(enum AVMediaType media_type) { switch (media_type) { @@ -141,25 +412,25 @@ static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt) char val_str[128]; AVStream *st = fmt_ctx->streams[pkt->stream_index]; - printf("[PACKET]\n"); - printf("codec_type=%s\n", media_type_string(st->codec->codec_type)); - printf("stream_index=%d\n", pkt->stream_index); - printf("pts=%s\n", ts_value_string(val_str, sizeof(val_str), pkt->pts)); - printf("pts_time=%s\n", time_value_string(val_str, sizeof(val_str), - pkt->pts, &st->time_base)); - printf("dts=%s\n", ts_value_string(val_str, sizeof(val_str), pkt->dts)); - printf("dts_time=%s\n", time_value_string(val_str, sizeof(val_str), - pkt->dts, &st->time_base)); - printf("duration=%s\n", ts_value_string(val_str, sizeof(val_str), - pkt->duration)); - printf("duration_time=%s\n", time_value_string(val_str, sizeof(val_str), - pkt->duration, - &st->time_base)); - printf("size=%s\n", value_string(val_str, sizeof(val_str), - pkt->size, unit_byte_str)); - printf("pos=%"PRId64"\n", pkt->pos); - printf("flags=%c\n", pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_'); - printf("[/PACKET]\n"); + probe_object_header("packet"); + probe_str("codec_type", media_type_string(st->codec->codec_type)); + probe_int("stream_index", pkt->stream_index); + probe_str("pts", ts_value_string(val_str, sizeof(val_str), pkt->pts)); + probe_str("pts_time", time_value_string(val_str, sizeof(val_str), + pkt->pts, &st->time_base)); + probe_str("dts", ts_value_string(val_str, sizeof(val_str), pkt->dts)); + probe_str("dts_time", time_value_string(val_str, sizeof(val_str), + pkt->dts, &st->time_base)); + probe_str("duration", ts_value_string(val_str, sizeof(val_str), + pkt->duration)); + probe_str("duration_time", time_value_string(val_str, sizeof(val_str), + pkt->duration, + &st->time_base)); + probe_str("size", value_string(val_str, sizeof(val_str), + pkt->size, unit_byte_str)); + probe_int("pos", pkt->pos); + probe_str("flags", pkt->flags & AV_PKT_FLAG_KEY ? "K" : "_"); + probe_object_footer("packet"); } static void show_packets(AVFormatContext *fmt_ctx) @@ -167,9 +438,10 @@ static void show_packets(AVFormatContext *fmt_ctx) AVPacket pkt; av_init_packet(&pkt); - + probe_array_header("packets"); while (!av_read_frame(fmt_ctx, &pkt)) show_packet(fmt_ctx, &pkt); + probe_array_footer("packets"); } static void show_stream(AVFormatContext *fmt_ctx, int stream_idx) @@ -178,138 +450,120 @@ static void show_stream(AVFormatContext *fmt_ctx, int stream_idx) AVCodecContext *dec_ctx; AVCodec *dec; char val_str[128]; - AVDictionaryEntry *tag = NULL; AVRational display_aspect_ratio; - printf("[STREAM]\n"); + probe_object_header("stream"); - printf("index=%d\n", stream->index); + probe_int("index", stream->index); if ((dec_ctx = stream->codec)) { if ((dec = dec_ctx->codec)) { - printf("codec_name=%s\n", dec->name); - printf("codec_long_name=%s\n", dec->long_name); + probe_str("codec_name", dec->name); + probe_str("codec_long_name", dec->long_name); } else { - printf("codec_name=unknown\n"); + probe_str("codec_name", "unknown"); } - printf("codec_type=%s\n", media_type_string(dec_ctx->codec_type)); - printf("codec_time_base=%d/%d\n", - dec_ctx->time_base.num, dec_ctx->time_base.den); + probe_str("codec_type", media_type_string(dec_ctx->codec_type)); + probe_str("codec_time_base", + rational_string(val_str, sizeof(val_str), + "/", &dec_ctx->time_base)); /* print AVI/FourCC tag */ av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag); - printf("codec_tag_string=%s\n", val_str); - printf("codec_tag=0x%04x\n", dec_ctx->codec_tag); + probe_str("codec_tag_string", val_str); + probe_str("codec_tag", tag_string(val_str, sizeof(val_str), + dec_ctx->codec_tag)); switch (dec_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: - printf("width=%d\n", dec_ctx->width); - printf("height=%d\n", dec_ctx->height); - printf("has_b_frames=%d\n", dec_ctx->has_b_frames); + probe_int("width", dec_ctx->width); + probe_int("height", dec_ctx->height); + probe_int("has_b_frames", dec_ctx->has_b_frames); if (dec_ctx->sample_aspect_ratio.num) { - printf("sample_aspect_ratio=%d:%d\n", - dec_ctx->sample_aspect_ratio.num, - dec_ctx->sample_aspect_ratio.den); + probe_str("sample_aspect_ratio", + rational_string(val_str, sizeof(val_str), ":", + &dec_ctx->sample_aspect_ratio)); av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, dec_ctx->width * dec_ctx->sample_aspect_ratio.num, dec_ctx->height * dec_ctx->sample_aspect_ratio.den, 1024*1024); - printf("display_aspect_ratio=%d:%d\n", - display_aspect_ratio.num, display_aspect_ratio.den); + probe_str("display_aspect_ratio", + rational_string(val_str, sizeof(val_str), ":", + &display_aspect_ratio)); } - printf("pix_fmt=%s\n", - dec_ctx->pix_fmt != PIX_FMT_NONE ? av_pix_fmt_descriptors[dec_ctx->pix_fmt].name + probe_str("pix_fmt", + dec_ctx->pix_fmt != PIX_FMT_NONE ? av_pix_fmt_descriptors[dec_ctx->pix_fmt].name : "unknown"); - printf("level=%d\n", dec_ctx->level); + probe_int("level", dec_ctx->level); break; case AVMEDIA_TYPE_AUDIO: - printf("sample_rate=%s\n", value_string(val_str, sizeof(val_str), - dec_ctx->sample_rate, - unit_hertz_str)); - printf("channels=%d\n", dec_ctx->channels); - printf("bits_per_sample=%d\n", - av_get_bits_per_sample(dec_ctx->codec_id)); + probe_str("sample_rate", + value_string(val_str, sizeof(val_str), + dec_ctx->sample_rate, + unit_hertz_str)); + probe_int("channels", dec_ctx->channels); + probe_int("bits_per_sample", + av_get_bits_per_sample(dec_ctx->codec_id)); break; } } else { - printf("codec_type=unknown\n"); + probe_str("codec_type", "unknown"); } if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) - printf("id=0x%x\n", stream->id); - printf("r_frame_rate=%d/%d\n", - stream->r_frame_rate.num, stream->r_frame_rate.den); - printf("avg_frame_rate=%d/%d\n", - stream->avg_frame_rate.num, stream->avg_frame_rate.den); - printf("time_base=%d/%d\n", - stream->time_base.num, stream->time_base.den); - printf("start_time=%s\n", - time_value_string(val_str, sizeof(val_str), - stream->start_time, &stream->time_base)); - printf("duration=%s\n", - time_value_string(val_str, sizeof(val_str), - stream->duration, &stream->time_base)); + probe_int("id", stream->id); + probe_str("r_frame_rate", + rational_string(val_str, sizeof(val_str), "/", + &stream->r_frame_rate)); + probe_str("avg_frame_rate", + rational_string(val_str, sizeof(val_str), "/", + &stream->avg_frame_rate)); + probe_str("time_base", + rational_string(val_str, sizeof(val_str), "/", + &stream->time_base)); + probe_str("start_time", + time_value_string(val_str, sizeof(val_str), + stream->start_time, &stream->time_base)); + probe_str("duration", + time_value_string(val_str, sizeof(val_str), + stream->duration, &stream->time_base)); if (stream->nb_frames) - printf("nb_frames=%"PRId64"\n", stream->nb_frames); - - while ((tag = av_dict_get(stream->metadata, "", tag, - AV_DICT_IGNORE_SUFFIX))) - printf("TAG:%s=%s\n", tag->key, tag->value); + probe_int("nb_frames", stream->nb_frames); - printf("[/STREAM]\n"); -} + probe_dict(stream->metadata, "tags"); -static void print_format_entry(const char *tag, - const char *val) -{ - if (!fmt_entries_to_show) { - if (tag) { - printf("%s=%s\n", tag, val); - } else { - printf("%s\n", val); - } - } else if (tag && av_dict_get(fmt_entries_to_show, tag, NULL, 0)) { - if (nb_fmt_entries_to_show > 1) - printf("%s=", tag); - printf("%s\n", val); - } + probe_object_footer("stream"); } static void show_format(AVFormatContext *fmt_ctx) { - AVDictionaryEntry *tag = NULL; char val_str[128]; int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1; - print_format_entry(NULL, "[FORMAT]"); - print_format_entry("filename", fmt_ctx->filename); - snprintf(val_str, sizeof(val_str) - 1, "%d", fmt_ctx->nb_streams); - print_format_entry("nb_streams", val_str); - print_format_entry("format_name", fmt_ctx->iformat->name); - print_format_entry("format_long_name", fmt_ctx->iformat->long_name); - print_format_entry("start_time", + probe_object_header("format"); + probe_str("filename", fmt_ctx->filename); + probe_int("nb_streams", fmt_ctx->nb_streams); + probe_str("format_name", fmt_ctx->iformat->name); + probe_str("format_long_name", fmt_ctx->iformat->long_name); + probe_str("start_time", time_value_string(val_str, sizeof(val_str), fmt_ctx->start_time, &AV_TIME_BASE_Q)); - print_format_entry("duration", + probe_str("duration", time_value_string(val_str, sizeof(val_str), fmt_ctx->duration, &AV_TIME_BASE_Q)); - print_format_entry("size", + probe_str("size", size >= 0 ? value_string(val_str, sizeof(val_str), size, unit_byte_str) : "unknown"); - print_format_entry("bit_rate", + probe_str("bit_rate", value_string(val_str, sizeof(val_str), fmt_ctx->bit_rate, unit_bit_per_second_str)); - while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, - AV_DICT_IGNORE_SUFFIX))) { - snprintf(val_str, sizeof(val_str) - 1, "TAG:%s", tag->key); - print_format_entry(val_str, tag->value); - } + probe_dict(fmt_ctx->metadata, "tags"); - print_format_entry(NULL, "[/FORMAT]"); + probe_object_footer("format"); } static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename) @@ -378,15 +632,18 @@ static int probe_file(const char *filename) if ((ret = open_input_file(&fmt_ctx, filename))) return ret; - if (do_show_packets) - show_packets(fmt_ctx); + if (do_show_format) + show_format(fmt_ctx); - if (do_show_streams) + if (do_show_streams) { + probe_array_header("streams"); for (i = 0; i < fmt_ctx->nb_streams; i++) show_stream(fmt_ctx, i); + probe_array_footer("streams"); + } - if (do_show_format) - show_format(fmt_ctx); + if (do_show_packets) + show_packets(fmt_ctx); close_input_file(&fmt_ctx); return 0; @@ -413,6 +670,15 @@ static int opt_show_format_entry(const char *opt, const char *arg) { do_show_format = 1; nb_fmt_entries_to_show++; + print_header = NULL; + print_footer = NULL; + print_array_header = NULL; + print_array_footer = NULL; + print_object_header = NULL; + print_object_footer = NULL; + + print_integer = show_format_entry_integer; + print_string = show_format_entry_string; av_dict_set(&fmt_entries_to_show, arg, "", 0); return 0; } @@ -470,9 +736,21 @@ static const OptionDef options[] = { { NULL, }, }; +static int probe_buf_write(void *opaque, uint8_t *buf, int buf_size) +{ + printf("%.*s", buf_size, buf); + return 0; +} + +#define AVP_BUFFSIZE 4096 + int main(int argc, char **argv) { int ret; + uint8_t *buffer = av_malloc(AVP_BUFFSIZE); + + if (!buffer) + exit(1); parse_loglevel(argc, argv, options); av_register_all(); @@ -494,10 +772,16 @@ int main(int argc, char **argv) exit(1); } - ret = probe_file(input_filename); + probe_out = avio_alloc_context(buffer, AVP_BUFFSIZE, 1, NULL, NULL, + probe_buf_write, NULL); + if (!probe_out) + exit(1); - uninit_opts(); - av_dict_free(&fmt_entries_to_show); + probe_header(); + ret = probe_file(input_filename); + probe_footer(); + avio_flush(probe_out); + avio_close(probe_out); avformat_network_deinit(); -- cgit v1.2.3 From 0d242a7713c795c4f4b8df8cac38f128aa3a811e Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 24 May 2012 12:22:29 -0700 Subject: avprobe: provide JSON output JSON usage is quite widespread. --- avprobe.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/avprobe.c b/avprobe.c index f3bb437b1e..53138943ee 100644 --- a/avprobe.c +++ b/avprobe.c @@ -97,6 +97,7 @@ typedef struct { static AVIOContext *probe_out = NULL; static OutputContext octx; +#define AVP_INDENT() avio_printf(probe_out, "%*c", octx.level * 2, ' ') /* * Default format, INI @@ -189,6 +190,96 @@ static void ini_print_string(const char *key, const char *value) avio_w8(probe_out, '\n'); } +/* + * Alternate format, JSON + */ + +static void json_print_header(void) +{ + avio_printf(probe_out, "{"); +} +static void json_print_footer(void) +{ + avio_printf(probe_out, "}\n"); +} + +static void json_print_array_header(const char *name) +{ + if (octx.prefix[octx.level -1].nb_elems) + avio_printf(probe_out, ",\n"); + AVP_INDENT(); + avio_printf(probe_out, "\"%s\" : ", name); + avio_printf(probe_out, "[\n"); +} + +static void json_print_array_footer(const char *name) +{ + avio_printf(probe_out, "\n"); + AVP_INDENT(); + avio_printf(probe_out, "]"); +} + +static void json_print_object_header(const char *name) +{ + if (octx.prefix[octx.level -1].nb_elems) + avio_printf(probe_out, ",\n"); + AVP_INDENT(); + if (octx.prefix[octx.level -1].type == OBJECT) + avio_printf(probe_out, "\"%s\" : ", name); + avio_printf(probe_out, "{\n"); +} + +static void json_print_object_footer(const char *name) +{ + avio_printf(probe_out, "\n"); + AVP_INDENT(); + avio_printf(probe_out, "}"); +} + +static void json_print_integer(const char *key, int64_t value) +{ + if (octx.prefix[octx.level -1].nb_elems) + avio_printf(probe_out, ",\n"); + AVP_INDENT(); + avio_printf(probe_out, "\"%s\" : %"PRId64"", key, value); +} + +static void json_escape_print(const char *s) +{ + int i = 0; + char c = 0; + + while (c = s[i++]) { + switch (c) { + case '\r': avio_printf(probe_out, "%s", "\\r"); break; + case '\n': avio_printf(probe_out, "%s", "\\n"); break; + case '\f': avio_printf(probe_out, "%s", "\\f"); break; + case '\b': avio_printf(probe_out, "%s", "\\b"); break; + case '\t': avio_printf(probe_out, "%s", "\\t"); break; + case '\\': + case '"' : avio_w8(probe_out, '\\'); + default: + if ((unsigned char)c < 32) + avio_printf(probe_out, "\\u00%02x", c & 0xff); + else + avio_w8(probe_out, c); + break; + } + } +} + +static void json_print_string(const char *key, const char *value) +{ + if (octx.prefix[octx.level -1].nb_elems) + avio_printf(probe_out, ",\n"); + AVP_INDENT(); + avio_w8(probe_out, '\"'); + json_escape_print(key); + avio_printf(probe_out, "\" : \""); + json_escape_print(value); + avio_w8(probe_out, '\"'); +} + /* * Simple Formatter for single entries. */ @@ -666,6 +757,34 @@ static int opt_format(const char *opt, const char *arg) return 0; } +static void opt_output_format(const char *opt, const char *arg) +{ + + if (!strcmp(arg, "json")) { + print_header = json_print_header; + print_footer = json_print_footer; + print_array_header = json_print_array_header; + print_array_footer = json_print_array_footer; + print_object_header = json_print_object_header; + print_object_footer = json_print_object_footer; + + print_integer = json_print_integer; + print_string = json_print_string; + } else + if (!strcmp(arg, "ini")) { + print_header = ini_print_header; + print_footer = ini_print_footer; + print_array_header = ini_print_array_header; + print_object_header = ini_print_object_header; + + print_integer = ini_print_integer; + print_string = ini_print_string; + } else { + av_log(NULL, AV_LOG_ERROR, "Unsupported formatter %s\n", arg); + exit(1); + } +} + static int opt_show_format_entry(const char *opt, const char *arg) { do_show_format = 1; @@ -716,6 +835,7 @@ static void opt_pretty(void) static const OptionDef options[] = { #include "cmdutils_common_opts.h" { "f", HAS_ARG, {(void*)opt_format}, "force format", "format" }, + { "of", HAS_ARG, {(void*)&opt_output_format}, "output the document either as ini or json", "output_format" }, { "unit", OPT_BOOL, {(void*)&show_value_unit}, "show unit of the displayed values" }, { "prefix", OPT_BOOL, {(void*)&use_value_prefix}, -- cgit v1.2.3 From 6a6c2a94c516b691dee4a0800efa76fc073aacbb Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 25 May 2012 12:57:36 -0700 Subject: avprobe: update documentation Update the documentation according to the latest changes --- doc/avprobe.texi | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/doc/avprobe.texi b/doc/avprobe.texi index 67c5e20813..9c28125784 100644 --- a/doc/avprobe.texi +++ b/doc/avprobe.texi @@ -41,19 +41,8 @@ Options are used to list some of the formats supported by avprobe or for specifying which information to display, and for setting how avprobe will show it. -avprobe output is designed to be easily parsable by a textual filter, -and consists of one or more sections of the form: -@example -[SECTION] -key1=val1 -... -keyN=valN -[/SECTION] -@end example - -Metadata tags stored in the container or in the streams are recognized -and printed in the corresponding "FORMAT" or "STREAM" section, and -are prefixed by the string "TAG:". +avprobe output is designed to be easily parsable by any INI or JSON +parsers. @c man end @@ -69,6 +58,10 @@ are prefixed by the string "TAG:". @item -f @var{format} Force format to use. +@item -of @var{formatter} +Use a specific formatter to output the document, either @var{ini} or +@var{json} available. + @item -unit Show the unit of the displayed values. -- cgit v1.2.3 From f4dd6465e9f82ff631cf356f9972a081ebadd4e0 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 25 May 2012 12:58:58 -0700 Subject: avprobe: changelog entry --- Changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 252cd9ee09..822f062d83 100644 --- a/Changelog +++ b/Changelog @@ -21,7 +21,7 @@ version : - add fps filter - audio split filter - audio mix filter - +- avprobe output is now standard INI or JSON. version 0.8: -- cgit v1.2.3 From 39e29aa019fe076f96a1461a194e82bc20f6e9ef Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Fri, 25 May 2012 22:16:06 +0300 Subject: cosmetics: Fix indentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/sapenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c index ca133f561f..0c3e95edd6 100644 --- a/libavformat/sapenc.c +++ b/libavformat/sapenc.c @@ -209,7 +209,7 @@ static int sap_write_header(AVFormatContext *s) pos += strlen(&sap->ann[pos]) + 1; if (av_sdp_create(contexts, s->nb_streams, &sap->ann[pos], - sap->ann_size - pos)) { + sap->ann_size - pos)) { ret = AVERROR_INVALIDDATA; goto fail; } -- cgit v1.2.3 From 70026be8e52460776f8023f35cdad3e854e752ae Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 25 May 2012 15:19:50 -0700 Subject: avprobe: fix function prototype Make opt_output_format return the correct value. --- avprobe.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/avprobe.c b/avprobe.c index 53138943ee..f809e46ae1 100644 --- a/avprobe.c +++ b/avprobe.c @@ -757,7 +757,7 @@ static int opt_format(const char *opt, const char *arg) return 0; } -static void opt_output_format(const char *opt, const char *arg) +static int opt_output_format(const char *opt, const char *arg) { if (!strcmp(arg, "json")) { @@ -781,8 +781,9 @@ static void opt_output_format(const char *opt, const char *arg) print_string = ini_print_string; } else { av_log(NULL, AV_LOG_ERROR, "Unsupported formatter %s\n", arg); - exit(1); + return AVERROR(EINVAL); } + return 0; } static int opt_show_format_entry(const char *opt, const char *arg) -- cgit v1.2.3 From b1d22dc52f678bc137b2bf76135ab6849366c292 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Fri, 25 May 2012 15:34:12 -0700 Subject: avprobe: display the codec profile in show_stream() Signed-off-by: Luca Barbato --- avprobe.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/avprobe.c b/avprobe.c index f809e46ae1..ae2eb205e5 100644 --- a/avprobe.c +++ b/avprobe.c @@ -540,6 +540,7 @@ static void show_stream(AVFormatContext *fmt_ctx, int stream_idx) AVStream *stream = fmt_ctx->streams[stream_idx]; AVCodecContext *dec_ctx; AVCodec *dec; + const char *profile; char val_str[128]; AVRational display_aspect_ratio; @@ -566,6 +567,10 @@ static void show_stream(AVFormatContext *fmt_ctx, int stream_idx) probe_str("codec_tag", tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag)); + /* print profile, if there is one */ + if (dec && (profile = av_get_profile_name(dec, dec_ctx->profile))) + probe_str("profile", profile); + switch (dec_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: probe_int("width", dec_ctx->width); -- cgit v1.2.3 From 2dcb21a95d67c7d1027344abefff57b0fdaa4e33 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sat, 26 May 2012 00:18:01 +0300 Subject: rtpenc: Expose the ssrc as an avoption MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows the caller to set it, and allows the caller to query what it was set to. Signed-off-by: Martin Storsjö --- libavformat/rtpenc.c | 4 +++- libavformat/version.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c index 29fc2f4aa7..71eeb7e32f 100644 --- a/libavformat/rtpenc.c +++ b/libavformat/rtpenc.c @@ -33,6 +33,7 @@ static const AVOption options[] = { FF_RTP_FLAG_OPTS(RTPMuxContext, flags) { "payload_type", "Specify RTP payload type", offsetof(RTPMuxContext, payload_type), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, 127, AV_OPT_FLAG_ENCODING_PARAM }, + { "ssrc", "Stream identifier", offsetof(RTPMuxContext, ssrc), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM }, { NULL }, }; @@ -101,7 +102,8 @@ static int rtp_write_header(AVFormatContext *s1) s->base_timestamp = av_get_random_seed(); s->timestamp = s->base_timestamp; s->cur_timestamp = 0; - s->ssrc = av_get_random_seed(); + if (!s->ssrc) + s->ssrc = av_get_random_seed(); s->first_packet = 1; s->first_rtcp_ntp_time = ff_ntp_time(); if (s1->start_time_realtime) diff --git a/libavformat/version.h b/libavformat/version.h index 7bd0b8e5f5..b00701eefa 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,7 +31,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 54 #define LIBAVFORMAT_VERSION_MINOR 3 -#define LIBAVFORMAT_VERSION_MICRO 0 +#define LIBAVFORMAT_VERSION_MICRO 1 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- cgit v1.2.3 From 93cef6f923d9842b647665f3b42342fa71887a18 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sat, 26 May 2012 00:40:54 +0300 Subject: rtpenc_chain: Free the URLContext on failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If an URLContext is passed in, its ownership is given to this function, and is either owned by the returned AVFormatContext on a successful return, or freed on failure. Signed-off-by: Martin Storsjö --- libavformat/rtpenc_chain.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libavformat/rtpenc_chain.c b/libavformat/rtpenc_chain.c index 16b38d69e5..3b5ea6c586 100644 --- a/libavformat/rtpenc_chain.c +++ b/libavformat/rtpenc_chain.c @@ -28,25 +28,23 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, URLContext *handle, int packet_size) { - AVFormatContext *rtpctx; + AVFormatContext *rtpctx = NULL; int ret; AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); uint8_t *rtpflags; AVDictionary *opts = NULL; if (!rtp_format) - return NULL; + goto fail; /* Allocate an AVFormatContext for each output stream */ rtpctx = avformat_alloc_context(); if (!rtpctx) - return NULL; + goto fail; rtpctx->oformat = rtp_format; - if (!avformat_new_stream(rtpctx, NULL)) { - av_free(rtpctx); - return NULL; - } + if (!avformat_new_stream(rtpctx, NULL)) + goto fail; /* Pass the interrupt callback on */ rtpctx->interrupt_callback = s->interrupt_callback; /* Copy the max delay setting; the rtp muxer reads this. */ @@ -82,4 +80,10 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, } return rtpctx; + +fail: + av_free(rtpctx); + if (handle) + ffurl_close(handle); + return NULL; } -- cgit v1.2.3 From 68c813081b48aaa910cd2e7832314a529c4c4a36 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Fri, 25 May 2012 22:26:00 +0300 Subject: rtpenc_chain: Return an error code instead of just a plain pointer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also check the return value in sapenc. Signed-off-by: Martin Storsjö --- libavformat/movenchint.c | 6 +++--- libavformat/rtpenc_chain.c | 23 +++++++++++++++-------- libavformat/rtpenc_chain.h | 4 ++-- libavformat/rtsp.c | 8 +++++--- libavformat/sapenc.c | 6 ++++-- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c index 579d040f64..5ef90f154a 100644 --- a/libavformat/movenchint.c +++ b/libavformat/movenchint.c @@ -43,9 +43,9 @@ int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) track->enc->codec_type = AVMEDIA_TYPE_DATA; track->enc->codec_tag = track->tag; - track->rtp_ctx = ff_rtp_chain_mux_open(s, src_st, NULL, - RTP_MAX_PACKET_SIZE); - if (!track->rtp_ctx) + ret = ff_rtp_chain_mux_open(&track->rtp_ctx, s, src_st, NULL, + RTP_MAX_PACKET_SIZE); + if (ret < 0) goto fail; /* Copy the RTP AVStream timebase back to the hint AVStream */ diff --git a/libavformat/rtpenc_chain.c b/libavformat/rtpenc_chain.c index 3b5ea6c586..3742099314 100644 --- a/libavformat/rtpenc_chain.c +++ b/libavformat/rtpenc_chain.c @@ -25,8 +25,8 @@ #include "avio_internal.h" #include "libavutil/opt.h" -AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, - URLContext *handle, int packet_size) +int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s, + AVStream *st, URLContext *handle, int packet_size) { AVFormatContext *rtpctx = NULL; int ret; @@ -34,17 +34,23 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, uint8_t *rtpflags; AVDictionary *opts = NULL; - if (!rtp_format) + if (!rtp_format) { + ret = AVERROR(ENOSYS); goto fail; + } /* Allocate an AVFormatContext for each output stream */ rtpctx = avformat_alloc_context(); - if (!rtpctx) + if (!rtpctx) { + ret = AVERROR(ENOMEM); goto fail; + } rtpctx->oformat = rtp_format; - if (!avformat_new_stream(rtpctx, NULL)) + if (!avformat_new_stream(rtpctx, NULL)) { + ret = AVERROR(ENOMEM); goto fail; + } /* Pass the interrupt callback on */ rtpctx->interrupt_callback = s->interrupt_callback; /* Copy the max delay setting; the rtp muxer reads this. */ @@ -76,14 +82,15 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, av_free(ptr); } avformat_free_context(rtpctx); - return NULL; + return ret; } - return rtpctx; + *out = rtpctx; + return 0; fail: av_free(rtpctx); if (handle) ffurl_close(handle); - return NULL; + return ret; } diff --git a/libavformat/rtpenc_chain.h b/libavformat/rtpenc_chain.h index 6bdddcfe99..66b9e4cd0a 100644 --- a/libavformat/rtpenc_chain.h +++ b/libavformat/rtpenc_chain.h @@ -25,7 +25,7 @@ #include "avformat.h" #include "url.h" -AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, - URLContext *handle, int packet_size); +int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s, + AVStream *st, URLContext *handle, int packet_size); #endif /* AVFORMAT_RTPENC_CHAIN_H */ diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 31eb4befd6..f53aadf191 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -606,11 +606,13 @@ static int rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st) s->ctx_flags |= AVFMTCTX_NOHEADER; if (s->oformat && CONFIG_RTSP_MUXER) { - rtsp_st->transport_priv = ff_rtp_chain_mux_open(s, st, - rtsp_st->rtp_handle, - RTSP_TCP_MAX_PACKET_SIZE); + int ret = ff_rtp_chain_mux_open(&rtsp_st->transport_priv, s, st, + rtsp_st->rtp_handle, + RTSP_TCP_MAX_PACKET_SIZE); /* Ownership of rtp_handle is passed to the rtp mux context */ rtsp_st->rtp_handle = NULL; + if (ret < 0) + return ret; } else if (rt->transport == RTSP_TRANSPORT_RDT && CONFIG_RTPDEC) rtsp_st->transport_priv = ff_rdt_parse_open(s, st->index, rtsp_st->dynamic_protocol_context, diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c index 0c3e95edd6..7e84a3fb99 100644 --- a/libavformat/sapenc.c +++ b/libavformat/sapenc.c @@ -150,8 +150,10 @@ static int sap_write_header(AVFormatContext *s) ret = AVERROR(EIO); goto fail; } - s->streams[i]->priv_data = contexts[i] = - ff_rtp_chain_mux_open(s, s->streams[i], fd, 0); + ret = ff_rtp_chain_mux_open(&contexts[i], s, s->streams[i], fd, 0); + if (ret < 0) + goto fail; + s->streams[i]->priv_data = contexts[i]; av_strlcpy(contexts[i]->filename, url, sizeof(contexts[i]->filename)); } -- cgit v1.2.3 From a1a6cdc26e465fc65e641ab31ef47d263b624568 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sat, 26 May 2012 00:55:56 +0300 Subject: avconv: Display the error returned by avformat_write_header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- avconv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/avconv.c b/avconv.c index 5506869d3d..5861f1bbf2 100644 --- a/avconv.c +++ b/avconv.c @@ -2863,8 +2863,12 @@ static int transcode_init(void) for (i = 0; i < nb_output_files; i++) { oc = output_files[i]->ctx; oc->interrupt_callback = int_cb; - if (avformat_write_header(oc, &output_files[i]->opts) < 0) { - snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i); + if ((ret = avformat_write_header(oc, &output_files[i]->opts)) < 0) { + char errbuf[128]; + const char *errbuf_ptr = errbuf; + if (av_strerror(ret, errbuf, sizeof(errbuf)) < 0) + errbuf_ptr = strerror(AVUNERROR(ret)); + snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?): %s", i, errbuf_ptr); ret = AVERROR(EINVAL); goto dump_format; } -- cgit v1.2.3 From 154486f9adc621e620dacd76d78c30a02cc1dcd3 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 25 May 2012 12:32:39 +0200 Subject: opt: Add av_opt_set_bin() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce a new function to set binary data through AVOption, avoiding having to convert the binary data to a string inbetween. Signed-off-by: Martin Storsjö --- doc/APIchanges | 3 +++ libavutil/avutil.h | 2 +- libavutil/opt.c | 29 +++++++++++++++++++++++++++++ libavutil/opt.h | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 18105c55ba..dca33aa0eb 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2012-05-25 - e0e0793 - lavu 51.31.0 - opt.h + Add av_opt_set_bin() + 2012-05-xx - xxxxxxx - lavf 54.3.0 Add AVFMT_TS_NONSTRICT format flag to indicate that a muxer supports non-increasing monotone timestamps. diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 3e51357ae6..1c8e0767df 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -152,7 +152,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 51 -#define LIBAVUTIL_VERSION_MINOR 30 +#define LIBAVUTIL_VERSION_MINOR 31 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/libavutil/opt.c b/libavutil/opt.c index 7c53024d25..af8df7a2eb 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -316,6 +316,35 @@ int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags) return set_number(obj, name, val.num, val.den, 1, search_flags); } +int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags) +{ + void *target_obj; + const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); + uint8_t *ptr; + uint8_t **dst; + int *lendst; + + if (!o || !target_obj) + return AVERROR_OPTION_NOT_FOUND; + + if (o->type != AV_OPT_TYPE_BINARY) + return AVERROR(EINVAL); + + ptr = av_malloc(len); + if (!ptr) + return AVERROR(ENOMEM); + + dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset); + lendst = (int *)(dst + 1); + + av_free(*dst); + *dst = ptr; + *lendst = len; + memcpy(ptr, val, len); + + return 0; +} + #if FF_API_OLD_AVOPTIONS /** * diff --git a/libavutil/opt.h b/libavutil/opt.h index 19549408e2..8f800fcf98 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -560,6 +560,7 @@ int av_opt_set (void *obj, const char *name, const char *val, int search_f int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags); int av_opt_set_double(void *obj, const char *name, double val, int search_flags); int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags); +int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, int search_flags); /** * @} */ -- cgit v1.2.3