Mercurial > mplayer.hg
annotate stream/realrtsp/xbuffer.c @ 30567:f6a690ddbd12
Ignore .ho files in loader/wine/.
author | diego |
---|---|
date | Wed, 17 Feb 2010 21:38:09 +0000 |
parents | ce0122361a39 |
children |
rev | line source |
---|---|
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
19271
diff
changeset
|
1 /* |
9922 | 2 * xbuffer code |
3 * | |
4 * Includes a minimalistic replacement for xine_buffer functions used in | |
5 * Real streaming code. Only function needed by this code are implemented. | |
6 * | |
7 * Most code comes from xine_buffer.c Copyright (C) 2002 the xine project | |
8 * | |
9 * WARNING: do not mix original xine_buffer functions with this code! | |
10 * xbuffers behave like xine_buffers, but are not byte-compatible with them. | |
11 * You must take care of pointers returned by xbuffers functions (no macro to | |
12 * do it automatically) | |
13 * | |
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
14 * This file is part of MPlayer. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
15 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
16 * MPlayer is free software; you can redistribute it and/or modify |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
17 * it under the terms of the GNU General Public License as published by |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
18 * the Free Software Foundation; either version 2 of the License, or |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
19 * (at your option) any later version. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
20 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
21 * MPlayer is distributed in the hope that it will be useful, |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
24 * GNU General Public License for more details. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
25 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
26 * You should have received a copy of the GNU General Public License along |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
27 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
28 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
9922 | 29 */ |
30 | |
31 #include <stdlib.h> | |
10232 | 32 #include <string.h> |
9922 | 33 #include <inttypes.h> |
34 #include "xbuffer.h" | |
35 | |
36 | |
37 typedef struct { | |
38 uint32_t size; | |
39 uint32_t chunk_size; | |
40 } xbuffer_header_t; | |
41 | |
42 #define XBUFFER_HEADER_SIZE sizeof (xbuffer_header_t) | |
43 | |
44 | |
45 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
19271
diff
changeset
|
46 void *xbuffer_init(int chunk_size) { |
9922 | 47 uint8_t *data=calloc(1,chunk_size+XBUFFER_HEADER_SIZE); |
48 | |
49 xbuffer_header_t *header=(xbuffer_header_t*)data; | |
50 | |
51 header->size=chunk_size; | |
52 header->chunk_size=chunk_size; | |
53 | |
54 return data+XBUFFER_HEADER_SIZE; | |
55 } | |
56 | |
57 | |
58 | |
59 void *xbuffer_free(void *buf) { | |
60 if (!buf) { | |
61 return NULL; | |
62 } | |
63 | |
64 free(((uint8_t*)buf)-XBUFFER_HEADER_SIZE); | |
65 | |
66 return NULL; | |
67 } | |
68 | |
69 | |
70 | |
71 void *xbuffer_copyin(void *buf, int index, const void *data, int len) { | |
72 if (!buf || !data) { | |
73 return NULL; | |
74 } | |
75 | |
76 buf = xbuffer_ensure_size(buf, index+len); | |
77 memcpy(((uint8_t*)buf)+index, data, len); | |
78 | |
79 return buf; | |
80 } | |
81 | |
82 | |
83 | |
84 void *xbuffer_ensure_size(void *buf, int size) { | |
85 xbuffer_header_t *xbuf; | |
86 int new_size; | |
87 | |
88 if (!buf) { | |
89 return 0; | |
90 } | |
91 | |
92 xbuf = ((xbuffer_header_t*)(((uint8_t*)buf)-XBUFFER_HEADER_SIZE)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
19271
diff
changeset
|
93 |
9922 | 94 if (xbuf->size < size) { |
95 new_size = size + xbuf->chunk_size - (size % xbuf->chunk_size); | |
96 xbuf->size = new_size; | |
97 buf = ((uint8_t*)realloc(((uint8_t*)buf)-XBUFFER_HEADER_SIZE, | |
98 new_size+XBUFFER_HEADER_SIZE)) + XBUFFER_HEADER_SIZE; | |
99 } | |
100 | |
101 return buf; | |
102 } | |
12266 | 103 |
104 | |
105 | |
106 void *xbuffer_strcat(void *buf, char *data) { | |
107 | |
108 if (!buf || !data) { | |
109 return NULL; | |
110 } | |
111 | |
112 buf = xbuffer_ensure_size(buf, strlen(buf)+strlen(data)+1); | |
113 | |
114 strcat(buf, data); | |
115 | |
116 return buf; | |
117 } |