~binli/ubuntu/vivid/pulseaudio/load-extcon-module

« back to all changes in this revision

Viewing changes to debian/patches/0404-tagstruct-Add-type-_APPENDED.patch

  • Committer: Bin Li
  • Date: 2016-01-23 15:04:48 UTC
  • Revision ID: bin.li@canonical.com-20160123150448-5ockvw4p5xxntda4
init the 1:6.0-0ubuntu9.15 from silo 12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From adb577c905f2e930bdd2bfe630d6ca0ea286d6cb Mon Sep 17 00:00:00 2001
 
2
From: Peter Meerwald <p.meerwald@bct-electronic.com>
 
3
Date: Wed, 22 Oct 2014 14:59:11 +0200
 
4
Subject: [PATCH 4/5] tagstruct: Add type _APPENDED
 
5
 
 
6
add 128 bytes of storage in each tagstruct that will initially
 
7
be used; if this storage is exceeded the type changes to _DYNAMIC
 
8
 
 
9
v3: (thanks David Henningson)
 
10
* add comments explaining how memory is handled by different tagstruct types
 
11
v2: (thanks Alexander Patrakov)
 
12
* replace constant 100 with GROW_TAG_SIZE (the increment in with a dynamic tagstruct grows when extend()ed)
 
13
 
 
14
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
 
15
---
 
16
 src/pulsecore/tagstruct.c | 26 +++++++++++++++++++-------
 
17
 1 file changed, 19 insertions(+), 7 deletions(-)
 
18
 
 
19
diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c
 
20
index e78fb4a..4206509 100644
 
21
--- a/src/pulsecore/tagstruct.c
 
22
+++ b/src/pulsecore/tagstruct.c
 
23
@@ -39,6 +39,8 @@
 
24
 #include "tagstruct.h"
 
25
 
 
26
 #define MAX_TAG_SIZE (64*1024)
 
27
+#define MAX_APPENDED_SIZE 128
 
28
+#define GROW_TAG_SIZE 100
 
29
 
 
30
 struct pa_tagstruct {
 
31
     uint8_t *data;
 
32
@@ -46,19 +48,23 @@ struct pa_tagstruct {
 
33
     size_t rindex;
 
34
 
 
35
     enum {
 
36
-        PA_TAGSTRUCT_FIXED,
 
37
-        PA_TAGSTRUCT_DYNAMIC,
 
38
+        PA_TAGSTRUCT_FIXED, /* The tagstruct does not own the data, buffer was provided by caller. */
 
39
+        PA_TAGSTRUCT_DYNAMIC, /* Buffer owned by tagstruct, data must be freed. */
 
40
+        PA_TAGSTRUCT_APPENDED, /* Data points to appended buffer, used for small tagstructs. Will change to dynamic if needed. */
 
41
     } type;
 
42
+    union {
 
43
+        uint8_t appended[MAX_APPENDED_SIZE];
 
44
+    } per_type;
 
45
 };
 
46
 
 
47
 pa_tagstruct *pa_tagstruct_new(void) {
 
48
     pa_tagstruct*t;
 
49
 
 
50
     t = pa_xnew(pa_tagstruct, 1);
 
51
-    t->data = NULL;
 
52
-    t->allocated = t->length = 0;
 
53
-    t->rindex = 0;
 
54
-    t->type = PA_TAGSTRUCT_DYNAMIC;
 
55
+    t->data = t->per_type.appended;
 
56
+    t->allocated = MAX_APPENDED_SIZE;
 
57
+    t->length = t->rindex = 0;
 
58
+    t->type = PA_TAGSTRUCT_APPENDED;
 
59
 
 
60
     return t;
 
61
 }
 
62
@@ -92,7 +98,13 @@ static inline void extend(pa_tagstruct*t, size_t l) {
 
63
     if (t->length+l <= t->allocated)
 
64
         return;
 
65
 
 
66
-    t->data = pa_xrealloc(t->data, t->allocated = t->length+l+100);
 
67
+    if (t->type == PA_TAGSTRUCT_DYNAMIC)
 
68
+        t->data = pa_xrealloc(t->data, t->allocated = t->length + l + GROW_TAG_SIZE);
 
69
+    else if (t->type == PA_TAGSTRUCT_APPENDED) {
 
70
+        t->type = PA_TAGSTRUCT_DYNAMIC;
 
71
+        t->data = pa_xmalloc(t->allocated = t->length + l + GROW_TAG_SIZE);
 
72
+        memcpy(t->data, t->per_type.appended, t->length);
 
73
+    }
 
74
 }
 
75
 
 
76
 static void write_u8(pa_tagstruct *t, uint8_t u) {
 
77
-- 
 
78
2.1.4
 
79