[pulseaudio-discuss] [PATCH RFC 04/17] tagstruct: Add type _APPENDED
Peter Meerwald
pmeerw at pmeerw.net
Fri Oct 24 14:21:28 PDT 2014
From: Peter Meerwald <p.meerwald at bct-electronic.com>
add 128 bytes of storage in each tagstruct that will initially
be used; if this storage is exceeded the type changes to _DYNAMIC
Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
src/pulsecore/tagstruct.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c
index 834a972..d2efffa 100644
--- a/src/pulsecore/tagstruct.c
+++ b/src/pulsecore/tagstruct.c
@@ -41,6 +41,7 @@
#include "tagstruct.h"
#define MAX_TAG_SIZE (64*1024)
+#define MAX_APPENDED_SIZE 128
struct pa_tagstruct {
uint8_t *data;
@@ -50,17 +51,21 @@ struct pa_tagstruct {
enum {
PA_TAGSTRUCT_FIXED,
PA_TAGSTRUCT_DYNAMIC,
+ PA_TAGSTRUCT_APPENDED,
} type;
+ union {
+ uint8_t appended[MAX_APPENDED_SIZE];
+ } per_type;
};
pa_tagstruct *pa_tagstruct_new(void) {
pa_tagstruct*t;
t = pa_xnew(pa_tagstruct, 1);
- t->data = NULL;
- t->allocated = t->length = 0;
- t->rindex = 0;
- t->type = PA_TAGSTRUCT_DYNAMIC;
+ t->data = t->per_type.appended;
+ t->allocated = MAX_APPENDED_SIZE;
+ t->length = t->rindex = 0;
+ t->type = PA_TAGSTRUCT_APPENDED;
return t;
}
@@ -94,7 +99,13 @@ static void extend(pa_tagstruct*t, size_t l) {
if (t->length+l <= t->allocated)
return;
- t->data = pa_xrealloc(t->data, t->allocated = t->length+l+100);
+ if (t->type == PA_TAGSTRUCT_DYNAMIC)
+ t->data = pa_xrealloc(t->data, t->allocated = t->length+l+100);
+ else if (t->type == PA_TAGSTRUCT_APPENDED) {
+ t->type = PA_TAGSTRUCT_DYNAMIC;
+ t->data = pa_xmalloc(t->allocated = t->length+l+100);
+ memcpy(t->data, t->per_type.appended, t->length);
+ }
}
void pa_tagstruct_puts(pa_tagstruct*t, const char *s) {
--
1.9.1
More information about the pulseaudio-discuss
mailing list