[FFmpeg-devel] [PATCH 5/5] lavu/dict: add hashtable index.
Clément Bœsch
ubitux at gmail.com
Sun Apr 14 15:01:41 CEST 2013
On Sun, Apr 14, 2013 at 02:10:28PM +0200, Nicolas George wrote:
> Le quintidi 25 germinal, an CCXXI, Clement Boesch a écrit :
> > From a4b09dd6703b1f73bff3fcce15f8ef55946ecee4 Mon Sep 17 00:00:00 2001
> > From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
> > Date: Sun, 14 Apr 2013 03:05:00 +0200
> > Subject: [PATCH 5/5] lavu/dict: add hashtable index.
> >
> > ---
> > libavutil/dict.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++------
>
> Is there a specific performance problem you are trying to fix?
>
Not really, but I thought a simple ordered dict API with fast fetching
would be a good idea.
BTW, that code might get relevant with code like attached for instance...
--
Clément B.
-------------- next part --------------
From 3836447c7120c00332018a588f2bd209c6a04d31 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Sun, 14 Apr 2013 14:58:59 +0200
Subject: [PATCH] bprint: dict string interpolation.
---
libavutil/bprint.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
libavutil/bprint.h | 6 ++++++
2 files changed, 55 insertions(+)
diff --git a/libavutil/bprint.c b/libavutil/bprint.c
index fd7611a..3b34ecf 100644
--- a/libavutil/bprint.c
+++ b/libavutil/bprint.c
@@ -113,6 +113,43 @@ void av_bprintf(AVBPrint *buf, const char *fmt, ...)
av_bprint_grow(buf, extra_len);
}
+int av_bprint_dict_interpolate(AVBPrint *buf, const char *fmt, AVDictionary *dict)
+{
+ char *s = av_strdup(fmt);
+ char *start_s = s;
+
+ if (!s)
+ return AVERROR(ENOMEM);
+ while (*s) {
+ char *p;
+
+ if (s[0] == '%' && s[1] == '(') {
+ const char *key = s + 2;
+ char *close = strchr(key, ')');
+
+ if (close) {
+ const AVDictionaryEntry *e;
+
+ *close++ = 0;
+ e = av_dict_get(dict, key, NULL, AV_DICT_MATCH_CASE);
+ if (e)
+ av_bprintf(buf, "%s", e->value);
+ s = close;
+ continue;
+ }
+ }
+ p = strchr(s + 1, '%');
+ if (!p) {
+ av_bprintf(buf, "%s", s);
+ break;
+ }
+ av_bprintf(buf, "%.*s", (int)(p - s), s);
+ s = p;
+ }
+ av_free(start_s);
+ return 0;
+}
+
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
{
unsigned room, real_n;
@@ -290,6 +327,7 @@ int main(void)
AVBPrint b;
char buf[256];
struct tm testtime = { .tm_year = 100, .tm_mon = 11, .tm_mday = 20 };
+ AVDictionary *d = NULL;
av_bprint_init(&b, 0, -1);
bprint_pascal(&b, 5);
@@ -333,6 +371,17 @@ int main(void)
av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
printf("strftime truncated: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
+ av_dict_set(&d, "ts1", "0.4123", 0);
+ av_dict_set(&d, "ts2", "54.153", 0);
+ av_dict_set(&d, "filename", "FooBar", 0);
+ av_dict_set(&d, "ext", ".mpg", 0);
+ av_dict_set(&d, "ext", ".mp4", 0);
+ av_bprint_init(&b, 0, -1);
+ av_bprint_dict_interpolate(&b, "%(filename)_%(ts1)-%(ts2)_%(nokey)%(ext)", d);
+ printf("interpolated string: %s\n", b.str);
+ av_bprint_finalize(&b, NULL);
+ av_dict_free(&d);
+
return 0;
}
diff --git a/libavutil/bprint.h b/libavutil/bprint.h
index df78916..2dd91c7 100644
--- a/libavutil/bprint.h
+++ b/libavutil/bprint.h
@@ -23,6 +23,7 @@
#include "attributes.h"
#include "avstring.h"
+#include "dict.h"
/**
* Define a structure with extra padding to a fixed size
@@ -122,6 +123,11 @@ void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size);
void av_bprintf(AVBPrint *buf, const char *fmt, ...) av_printf_format(2, 3);
/**
+ * FIXME doc
+ */
+int av_bprint_dict_interpolate(AVBPrint *buf, const char *fmt, AVDictionary *dict);
+
+/**
* Append char c n times to a print buffer.
*/
void av_bprint_chars(AVBPrint *buf, char c, unsigned n);
--
1.8.2.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130414/9664e82b/attachment.asc>
More information about the ffmpeg-devel
mailing list