Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
gstreamer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
luzpaz
gstreamer
Commits
ebb14d95
Commit
ebb14d95
authored
Mar 30, 2011
by
Wim Taymans
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
buffer: more API tweaks
_trim -> _resize _create_sub -> copy_region
parent
cf4117b2
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
115 additions
and
122 deletions
+115
-122
gst/gstbuffer.c
gst/gstbuffer.c
+30
-40
gst/gstbuffer.h
gst/gstbuffer.h
+9
-12
gst/gstcompat.h
gst/gstcompat.h
+2
-0
gst/gstmemory.c
gst/gstmemory.c
+21
-20
gst/gstmemory.h
gst/gstmemory.h
+14
-14
libs/gst/base/gstadapter.c
libs/gst/base/gstadapter.c
+3
-3
libs/gst/base/gstbasetransform.c
libs/gst/base/gstbasetransform.c
+2
-2
libs/gst/base/gstcollectpads.c
libs/gst/base/gstcollectpads.c
+2
-1
plugins/elements/gstcapsfilter.c
plugins/elements/gstcapsfilter.c
+2
-2
plugins/elements/gstfakesrc.c
plugins/elements/gstfakesrc.c
+3
-1
tests/check/gst/gstbuffer.c
tests/check/gst/gstbuffer.c
+17
-17
tests/check/gst/gstmeta.c
tests/check/gst/gstmeta.c
+2
-2
tests/check/libs/adapter.c
tests/check/libs/adapter.c
+4
-4
win32/common/libgstreamer.def
win32/common/libgstreamer.def
+4
-4
No files found.
gst/gstbuffer.c
View file @
ebb14d95
...
...
@@ -26,10 +26,10 @@
* @see_also: #GstPad, #GstMiniObject
*
* Buffers are the basic unit of data transfer in GStreamer. The #GstBuffer
* type provides all the state necessary to define
a region of memory as part
*
of a stream. Sub-buffers are also supported, allowing a smaller region of a
*
buffer to become its own buffer, with mechanisms in place to ensure that
* neither memory space goes away prematurely.
* type provides all the state necessary to define
the regions of memory as
*
part of a stream. Region copies are also supported, allowing a smaller
*
region of a buffer to become its own buffer, with mechanisms in place to
*
ensure that
neither memory space goes away prematurely.
*
* Buffers are usually created with gst_buffer_new(). After a buffer has been
* created one will typically allocate memory for it and set the size of the
...
...
@@ -85,33 +85,29 @@
* next element.
*
* To efficiently create a smaller buffer out of an existing one, you can
* use gst_buffer_c
reate_sub
().
* use gst_buffer_c
opy_region
().
*
* If a plug-in wants to modify the buffer data in-place, it should first obtain
* a buffer that is safe to modify by using gst_buffer_make_writable(). This
* function is optimized so that a copy will only be made when it is necessary.
*
* A plugin that only wishes to modify the metadata of a buffer, such as the
* offset, timestamp or caps, should use gst_buffer_make_metadata_writable(),
* which will create a subbuffer of the original buffer to ensure the caller
* has sole ownership, and not copy the buffer data.
* If a plug-in wants to modify the buffer data or metadata in-place, it should
* first obtain a buffer that is safe to modify by using
* gst_buffer_make_writable(). This function is optimized so that a copy will
* only be made when it is necessary.
*
* Several flags of the buffer can be set and unset with the
* GST_BUFFER_FLAG_SET() and GST_BUFFER_FLAG_UNSET() macros. Use
* GST_BUFFER_FLAG_IS_SET() to test if a certain #GstBufferFlag is set.
*
* Buffers can be efficiently merged into a larger buffer with
* gst_buffer_
merge() and gst_buffer_span() if
the gst_buffer_is_span_fast()
* gst_buffer_
span(), which avoids memory copies when
the gst_buffer_is_span_fast()
* function returns TRUE.
*
* An element should either unref the buffer or push it out on a src pad
* using gst_pad_push() (see #GstPad).
*
* Buffers are usually freed by unreffing them with gst_buffer_unref(). When
* the refcount drops to 0, any data pointed to by
GST_BUFFER_MALLOCDATA() will
*
also be freed
.
* the refcount drops to 0, any data pointed to by
the buffer is unreffed as
*
well
.
*
* Last reviewed on
August 11th, 2006 (0.10.1
0)
* Last reviewed on
March 30, 2011 (0.11.
0)
*/
#include "gst_private.h"
...
...
@@ -318,7 +314,7 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
len
=
GST_BUFFER_MEM_LEN
(
src
);
left
=
size
;
/* copy and
subbuffer
*/
/* copy and
make regions of the memory
*/
for
(
i
=
0
;
i
<
len
&&
left
>
0
;
i
++
)
{
mem
=
GST_BUFFER_MEM_PTR
(
src
,
i
);
bsize
=
gst_memory_get_sizes
(
mem
,
NULL
);
...
...
@@ -332,7 +328,7 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
tocopy
=
MIN
(
bsize
-
offset
,
left
);
if
(
tocopy
<
bsize
)
{
/* we need to clip something */
mem
=
gst_memory_s
ub
(
mem
,
offset
,
tocopy
);
mem
=
gst_memory_s
hare
(
mem
,
offset
,
tocopy
);
}
else
{
mem
=
gst_memory_ref
(
mem
);
}
...
...
@@ -547,7 +543,7 @@ gst_buffer_new_and_alloc (guint size)
gst_memory_unmap (mem, data, asize);
/* strip off the buffer */
gst_memory_
trim
(mem, sizeof (GstBufferImpl), size);
gst_memory_
resize
(mem, sizeof (GstBufferImpl), size);
newbuf = GST_BUFFER_CAST (data);
...
...
@@ -697,7 +693,7 @@ gst_buffer_get_size (GstBuffer * buffer)
}
/**
* gst_buffer_
trim
:
* gst_buffer_
resize
:
* @buffer: a #GstBuffer.
* @offset: the new offset
* @size: the new size
...
...
@@ -705,7 +701,7 @@ gst_buffer_get_size (GstBuffer * buffer)
* Set the total size of the buffer
*/
void
gst_buffer_
trim
(
GstBuffer
*
buffer
,
gsize
offset
,
gsize
size
)
gst_buffer_
resize
(
GstBuffer
*
buffer
,
gsize
offset
,
gsize
size
)
{
guint
len
;
guint
si
,
di
;
...
...
@@ -741,10 +737,10 @@ gst_buffer_trim (GstBuffer * buffer, gsize offset, gsize size)
if
(
tocopy
<
bsize
)
{
/* we need to clip something */
if
(
GST_MEMORY_IS_WRITABLE
(
mem
))
{
gst_memory_
trim
(
mem
,
offset
,
tocopy
);
gst_memory_
resize
(
mem
,
offset
,
tocopy
);
}
else
{
GstMemory
*
tmp
;
tmp
=
gst_memory_s
ub
(
mem
,
offset
,
tocopy
);
tmp
=
gst_memory_s
hare
(
mem
,
offset
,
tocopy
);
gst_memory_unref
(
mem
);
mem
=
tmp
;
}
...
...
@@ -1035,7 +1031,7 @@ gst_buffer_set_caps (GstBuffer * buffer, GstCaps * caps)
}
/**
* gst_buffer_c
reate_sub
:
* gst_buffer_c
opy_region
:
* @parent: a #GstBuffer.
* @offset: the offset into parent #GstBuffer at which the new sub-buffer
* begins.
...
...
@@ -1056,28 +1052,22 @@ gst_buffer_set_caps (GstBuffer * buffer, GstCaps * caps)
* invalid.
*/
GstBuffer
*
gst_buffer_create_sub
(
GstBuffer
*
buffer
,
gsize
offset
,
gsize
size
)
gst_buffer_copy_region
(
GstBuffer
*
buffer
,
GstBufferCopyFlags
flags
,
gsize
offset
,
gsize
size
)
{
GstBuffer
*
subbuffer
;
gsize
bufsize
;
GstBuffer
*
copy
;
g_return_val_if_fail
(
buffer
!=
NULL
,
NULL
);
g_return_val_if_fail
(
buffer
->
mini_object
.
refcount
>
0
,
NULL
);
bufsize
=
gst_buffer_get_size
(
buffer
);
g_return_val_if_fail
(
bufsize
>=
offset
,
NULL
);
if
(
size
==
-
1
)
size
=
bufsize
-
offset
;
g_return_val_if_fail
(
bufsize
>=
offset
+
size
,
NULL
);
/* create the new buffer */
subbuffer
=
gst_buffer_new
();
copy
=
gst_buffer_new
();
GST_CAT_LOG
(
GST_CAT_BUFFER
,
"new
subbuffer
%p of %p %"
G_GSIZE_FORMAT
"-%"
G_GSIZE_FORMAT
,
subbuffer
,
buffer
,
offset
,
size
);
GST_CAT_LOG
(
GST_CAT_BUFFER
,
"new
region copy
%p of %p %"
G_GSIZE_FORMAT
"-%"
G_GSIZE_FORMAT
,
copy
,
buffer
,
offset
,
size
);
gst_buffer_copy_into
(
subbuffer
,
buffer
,
GST_BUFFER_COPY_ALL
,
offset
,
size
);
gst_buffer_copy_into
(
copy
,
buffer
,
flags
,
offset
,
size
);
return
subbuffer
;
return
copy
;
}
static
gboolean
...
...
@@ -1129,7 +1119,7 @@ _gst_buffer_arr_span (GstMemory ** mem[], gsize len[], guint n, gsize offset,
if
(
!
writable
&&
_gst_buffer_arr_is_span_fast
(
mem
,
len
,
n
,
&
poffset
,
&
parent
))
{
span
=
gst_memory_s
ub
(
parent
,
offset
+
poffset
,
size
);
span
=
gst_memory_s
hare
(
parent
,
offset
+
poffset
,
size
);
}
else
{
gsize
count
,
left
;
guint8
*
dest
,
*
ptr
;
...
...
gst/gstbuffer.h
View file @
ebb14d95
...
...
@@ -237,13 +237,12 @@ typedef enum {
/**
* GstBuffer:
* @mini_object: the parent structure
* @
data: pointer to the buffer data
* @
size: size of buffer data
* @
pool: pointer to the pool owner of the buffer
* @
caps: the #GstCaps describing the data format in this buffer
* @timestamp: timestamp of the buffer, can be #GST_CLOCK_TIME_NONE when the
* timestamp is not known or relevant.
* @duration: duration in time of the buffer data, can be #GST_CLOCK_TIME_NONE
* when the duration is not known or relevant.
* @caps: the #GstCaps describing the data format in this buffer
* @offset: a media specific offset for the buffer data.
* For video frames, this is the frame number of this buffer.
* For audio samples, this is the offset of the first sample in this buffer.
...
...
@@ -251,11 +250,6 @@ typedef enum {
* byte in this buffer.
* @offset_end: the last offset contained in this buffer. It has the same
* format as @offset.
* @malloc_data: a pointer to the allocated memory associated with this buffer.
* When the buffer is freed, this data will freed with @free_func.
* @free_func: a custom function that will be called with @malloc_data, defaults
* to g_free(). Since 0.10.22.
* @parent: the parent buffer if this is a subbuffer. Since 0.10.26.
*
* The structure of a #GstBuffer. Use the associated macros to access the public
* variables.
...
...
@@ -302,7 +296,7 @@ void gst_buffer_extract (GstBuffer *buffer, gsize offset,
gpointer
dest
,
gsize
size
);
gsize
gst_buffer_get_size
(
GstBuffer
*
buffer
);
void
gst_buffer_
trim
(
GstBuffer
*
buffer
,
gsize
offset
,
gsize
size
);
void
gst_buffer_
resize
(
GstBuffer
*
buffer
,
gsize
offset
,
gsize
size
);
/**
* gst_buffer_remove_memory:
...
...
@@ -312,7 +306,7 @@ void gst_buffer_trim (GstBuffer *buffer, gsize offset, gsi
* Set the size of @b to @s. This will remove or trim the memory blocks
* in the buffer.
*/
#define gst_buffer_set_size(b,s) gst_buffer_
trim
((b), 0, (s))
#define gst_buffer_set_size(b,s) gst_buffer_
resize
((b), 0, (s))
/* getting memory */
gpointer
gst_buffer_map
(
GstBuffer
*
buffer
,
gsize
*
size
,
gsize
*
maxsize
,
...
...
@@ -386,6 +380,7 @@ gst_buffer_copy (const GstBuffer * buf)
/**
* GstBufferCopyFlags:
* @GST_BUFFER_COPY_NONE: copy nothing
* @GST_BUFFER_COPY_FLAGS: flag indicating that buffer flags should be copied
* @GST_BUFFER_COPY_TIMESTAMPS: flag indicating that buffer timestamp, duration,
* offset and offset_end should be copied
...
...
@@ -399,6 +394,7 @@ gst_buffer_copy (const GstBuffer * buf)
* function to specify which items should be copied.
*/
typedef
enum
{
GST_BUFFER_COPY_NONE
=
0
,
GST_BUFFER_COPY_FLAGS
=
(
1
<<
0
),
GST_BUFFER_COPY_TIMESTAMPS
=
(
1
<<
1
),
GST_BUFFER_COPY_CAPS
=
(
1
<<
2
),
...
...
@@ -474,8 +470,9 @@ G_STMT_START { \
GstCaps
*
gst_buffer_get_caps
(
GstBuffer
*
buffer
);
void
gst_buffer_set_caps
(
GstBuffer
*
buffer
,
GstCaps
*
caps
);
/* creating a subbuffer */
GstBuffer
*
gst_buffer_create_sub
(
GstBuffer
*
parent
,
gsize
offset
,
gsize
size
);
/* creating a region */
GstBuffer
*
gst_buffer_copy_region
(
GstBuffer
*
parent
,
GstBufferCopyFlags
flags
,
gsize
offset
,
gsize
size
);
/* span, two buffers, intelligently */
gboolean
gst_buffer_is_span_fast
(
GstBuffer
*
buf1
,
GstBuffer
*
buf2
);
...
...
gst/gstcompat.h
View file @
ebb14d95
...
...
@@ -47,6 +47,8 @@ G_BEGIN_DECLS
#define gst_pad_get_caps_reffed(p) gst_pad_get_caps(p)
#define gst_pad_peer_get_caps_reffed(p) gst_pad_peer_get_caps(p)
//#define gst_buffer_create_sub(b,o,s) gst_buffer_copy_region(b,GST_BUFFER_COPY_ALL,o,s)
#ifndef GST_DISABLE_DEPRECATED
#endif
/* not GST_DISABLE_DEPRECATED */
...
...
gst/gstmemory.c
View file @
ebb14d95
...
...
@@ -44,14 +44,14 @@ typedef struct
}
GstMemoryDefault
;
static
const
GstMemoryImpl
*
_default_mem_impl
;
static
const
GstMemoryImpl
*
_default_s
ub
_impl
;
static
const
GstMemoryImpl
*
_default_s
hare
_impl
;
static
void
_default_mem_init
(
GstMemoryDefault
*
mem
,
GstMemoryFlags
flags
,
GstMemory
*
parent
,
gsize
slice_size
,
gpointer
data
,
GFreeFunc
free_func
,
gsize
maxsize
,
gsize
offset
,
gsize
size
)
{
mem
->
mem
.
impl
=
data
?
_default_mem_impl
:
_default_s
ub
_impl
;
mem
->
mem
.
impl
=
data
?
_default_mem_impl
:
_default_s
hare
_impl
;
mem
->
mem
.
flags
=
flags
;
mem
->
mem
.
refcount
=
1
;
mem
->
mem
.
parent
=
parent
?
gst_memory_ref
(
parent
)
:
NULL
;
...
...
@@ -114,7 +114,7 @@ _default_mem_get_sizes (GstMemoryDefault * mem, gsize * maxsize)
}
static
void
_default_mem_
trim
(
GstMemoryDefault
*
mem
,
gsize
offset
,
gsize
size
)
_default_mem_
resize
(
GstMemoryDefault
*
mem
,
gsize
offset
,
gsize
size
)
{
g_return_if_fail
(
size
+
mem
->
offset
+
offset
<=
mem
->
maxsize
);
...
...
@@ -135,7 +135,7 @@ _default_mem_map (GstMemoryDefault * mem, gsize * size, gsize * maxsize,
}
static
gpointer
_default_s
ub
_map
(
GstMemoryDefault
*
mem
,
gsize
*
size
,
gsize
*
maxsize
,
_default_s
hare
_map
(
GstMemoryDefault
*
mem
,
gsize
*
size
,
gsize
*
maxsize
,
GstMapFlags
flags
)
{
guint8
*
data
;
...
...
@@ -158,7 +158,7 @@ _default_mem_unmap (GstMemoryDefault * mem, gpointer data, gsize size)
}
static
gboolean
_default_s
ub
_unmap
(
GstMemoryDefault
*
mem
,
gpointer
data
,
gsize
size
)
_default_s
hare
_unmap
(
GstMemoryDefault
*
mem
,
gpointer
data
,
gsize
size
)
{
gboolean
res
;
guint8
*
ptr
=
data
;
...
...
@@ -197,7 +197,7 @@ _default_mem_copy (GstMemoryDefault * mem, gsize offset, gsize size)
}
static
GstMemoryDefault
*
_default_mem_s
ub
(
GstMemoryDefault
*
mem
,
gsize
offset
,
gsize
size
)
_default_mem_s
hare
(
GstMemoryDefault
*
mem
,
gsize
offset
,
gsize
size
)
{
GstMemoryDefault
*
sub
;
GstMemory
*
parent
;
...
...
@@ -244,7 +244,7 @@ _fallback_copy (GstMemory * mem, gsize offset, gsize size)
}
static
GstMemory
*
_fallback_s
ub
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
)
_fallback_s
hare
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
)
{
GstMemoryDefault
*
sub
;
GstMemory
*
parent
;
...
...
@@ -268,19 +268,19 @@ _gst_memory_init (void)
{
static
const
GstMemoryInfo
_mem_info
=
{
(
GstMemoryGetSizesFunction
)
_default_mem_get_sizes
,
(
GstMemory
TrimFunction
)
_default_mem_trim
,
(
GstMemory
ResizeFunction
)
_default_mem_resize
,
(
GstMemoryMapFunction
)
_default_mem_map
,
(
GstMemoryUnmapFunction
)
_default_mem_unmap
,
(
GstMemoryFreeFunction
)
_default_mem_free
,
(
GstMemoryCopyFunction
)
_default_mem_copy
,
(
GstMemoryS
ubFunction
)
_default_mem_sub
,
(
GstMemoryS
hareFunction
)
_default_mem_share
,
(
GstMemoryIsSpanFunction
)
_default_mem_is_span
};
static
const
GstMemoryInfo
_s
ub
_info
=
{
static
const
GstMemoryInfo
_s
hare
_info
=
{
(
GstMemoryGetSizesFunction
)
_default_mem_get_sizes
,
(
GstMemory
TrimFunction
)
_default_mem_trim
,
(
GstMemoryMapFunction
)
_default_s
ub
_map
,
(
GstMemoryUnmapFunction
)
_default_s
ub
_unmap
,
(
GstMemory
ResizeFunction
)
_default_mem_resize
,
(
GstMemoryMapFunction
)
_default_s
hare
_map
,
(
GstMemoryUnmapFunction
)
_default_s
hare
_unmap
,
(
GstMemoryFreeFunction
)
_default_mem_free
,
NULL
,
NULL
,
...
...
@@ -288,7 +288,8 @@ _gst_memory_init (void)
};
_default_mem_impl
=
gst_memory_register
(
"GstMemoryDefault"
,
&
_mem_info
);
_default_sub_impl
=
gst_memory_register
(
"GstMemorySubbuffer"
,
&
_sub_info
);
_default_share_impl
=
gst_memory_register
(
"GstMemorySharebuffer"
,
&
_share_info
);
}
/**
...
...
@@ -309,7 +310,7 @@ gst_memory_register (const gchar * name, const GstMemoryInfo * info)
g_return_val_if_fail
(
name
!=
NULL
,
NULL
);
g_return_val_if_fail
(
info
!=
NULL
,
NULL
);
g_return_val_if_fail
(
info
->
get_sizes
!=
NULL
,
NULL
);
g_return_val_if_fail
(
info
->
trim
!=
NULL
,
NULL
);
g_return_val_if_fail
(
info
->
resize
!=
NULL
,
NULL
);
g_return_val_if_fail
(
info
->
map
!=
NULL
,
NULL
);
g_return_val_if_fail
(
info
->
unmap
!=
NULL
,
NULL
);
g_return_val_if_fail
(
info
->
free
!=
NULL
,
NULL
);
...
...
@@ -318,7 +319,7 @@ gst_memory_register (const gchar * name, const GstMemoryInfo * info)
impl
->
name
=
g_quark_from_string
(
name
);
impl
->
info
=
*
info
;
INSTALL_FALLBACK
(
copy
);
INSTALL_FALLBACK
(
s
ub
);
INSTALL_FALLBACK
(
s
hare
);
INSTALL_FALLBACK
(
is_span
);
GST_DEBUG
(
"register
\"
%s
\"
of size %"
G_GSIZE_FORMAT
,
name
);
...
...
@@ -437,19 +438,19 @@ gst_memory_copy (GstMemory * mem, gsize offset, gsize size)
}
void
gst_memory_
trim
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
)
gst_memory_
resize
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
)
{
g_return_if_fail
(
mem
!=
NULL
);
mem
->
impl
->
info
.
trim
(
mem
,
offset
,
size
);
mem
->
impl
->
info
.
resize
(
mem
,
offset
,
size
);
}
GstMemory
*
gst_memory_s
ub
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
)
gst_memory_s
hare
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
)
{
g_return_val_if_fail
(
mem
!=
NULL
,
NULL
);
return
mem
->
impl
->
info
.
s
ub
(
mem
,
offset
,
size
);
return
mem
->
impl
->
info
.
s
hare
(
mem
,
offset
,
size
);
}
gboolean
...
...
gst/gstmemory.h
View file @
ebb14d95
...
...
@@ -46,7 +46,7 @@ typedef enum {
* GstMemory:
* @impl: pointer to the #GstMemoryImpl
* @refcount: refcount
* @paret: parent memory block
* @pare
n
t: parent memory block
*
* Base structure for memory implementations. Custom memory will put this structure
* as the first member of their structure.
...
...
@@ -73,18 +73,17 @@ typedef enum {
*/
#define GST_MEMORY_TRACE_NAME "GstMemory"
typedef
gsize
(
*
GstMemoryGetSizesFunction
)
(
GstMemory
*
mem
,
gsize
*
maxsize
);
typedef
gpointer
(
*
GstMemoryMapFunction
)
(
GstMemory
*
mem
,
gsize
*
size
,
gsize
*
maxsize
,
GstMapFlags
flags
);
typedef
gboolean
(
*
GstMemoryUnmapFunction
)
(
GstMemory
*
mem
,
gpointer
data
,
gsize
size
);
typedef
gsize
(
*
GstMemoryGetSizesFunction
)
(
GstMemory
*
mem
,
gsize
*
maxsize
);
typedef
void
(
*
GstMemoryResizeFunction
)
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
);
typedef
gpointer
(
*
GstMemoryMapFunction
)
(
GstMemory
*
mem
,
gsize
*
size
,
gsize
*
maxsize
,
GstMapFlags
flags
);
typedef
gboolean
(
*
GstMemoryUnmapFunction
)
(
GstMemory
*
mem
,
gpointer
data
,
gsize
size
);
typedef
void
(
*
GstMemoryFreeFunction
)
(
GstMemory
*
mem
);
typedef
GstMemory
*
(
*
GstMemoryCopyFunction
)
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
);
typedef
void
(
*
GstMemoryTrimFunction
)
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
);
typedef
GstMemory
*
(
*
GstMemorySubFunction
)
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
);
typedef
gboolean
(
*
GstMemoryIsSpanFunction
)
(
GstMemory
*
mem1
,
GstMemory
*
mem2
,
gsize
*
offset
);
typedef
GstMemory
*
(
*
GstMemoryShareFunction
)
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
);
typedef
gboolean
(
*
GstMemoryIsSpanFunction
)
(
GstMemory
*
mem1
,
GstMemory
*
mem2
,
gsize
*
offset
);
/**
* GstMemoryInfo:
...
...
@@ -94,13 +93,13 @@ typedef gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1, GstMemory *mem2
*/
struct
_GstMemoryInfo
{
GstMemoryGetSizesFunction
get_sizes
;
GstMemory
TrimFunction
trim
;
GstMemory
ResizeFunction
resize
;
GstMemoryMapFunction
map
;
GstMemoryUnmapFunction
unmap
;
GstMemoryFreeFunction
free
;
GstMemoryCopyFunction
copy
;
GstMemoryS
ubFunction
sub
;
GstMemoryS
hareFunction
share
;
GstMemoryIsSpanFunction
is_span
;
};
...
...
@@ -119,7 +118,7 @@ void gst_memory_unref (GstMemory *mem);
/* getting/setting memory properties */
gsize
gst_memory_get_sizes
(
GstMemory
*
mem
,
gsize
*
maxsize
);
void
gst_memory_
trim
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
);
void
gst_memory_
resize
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
);
/* retriveing data */
gpointer
gst_memory_map
(
GstMemory
*
mem
,
gsize
*
size
,
gsize
*
maxsize
,
...
...
@@ -128,10 +127,11 @@ gboolean gst_memory_unmap (GstMemory *mem, gpointer data, gsize size);
/* copy and subregions */
GstMemory
*
gst_memory_copy
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
);
GstMemory
*
gst_memory_s
ub
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
);
GstMemory
*
gst_memory_s
hare
(
GstMemory
*
mem
,
gsize
offset
,
gsize
size
);
/* span memory */
gboolean
gst_memory_is_span
(
GstMemory
*
mem1
,
GstMemory
*
mem2
,
gsize
*
offset
);
GstMemory
*
gst_memory_span
(
GstMemory
**
mem1
,
gsize
len1
,
gsize
offset
,
GstMemory
**
mem2
,
gsize
len2
,
gsize
size
);
...
...
libs/gst/base/gstadapter.c
View file @
ebb14d95
...
...
@@ -716,9 +716,9 @@ gst_adapter_take_buffer (GstAdapter * adapter, gsize nbytes)
buffer
=
gst_buffer_ref
(
cur
);
goto
done
;
}
else
if
(
hsize
>=
nbytes
+
skip
)
{
GST_LOG_OBJECT
(
adapter
,
"providing buffer of %d bytes via
sub-buffer
"
,
GST_LOG_OBJECT
(
adapter
,
"providing buffer of %d bytes via
region copy
"
,
nbytes
);
buffer
=
gst_buffer_c
reate_sub
(
cur
,
skip
,
nbytes
);
buffer
=
gst_buffer_c
opy_region
(
cur
,
GST_BUFFER_COPY_ALL
,
skip
,
nbytes
);
goto
done
;
}
...
...
@@ -728,7 +728,7 @@ gst_adapter_take_buffer (GstAdapter * adapter, gsize nbytes)
if
(
gst_buffer_get_size
(
cur
)
>=
nbytes
+
skip
)
{
GST_LOG_OBJECT
(
adapter
,
"providing buffer of %d bytes via sub-buffer"
,
nbytes
);
buffer
=
gst_buffer_c
reate_sub
(
cur
,
skip
,
nbytes
);
buffer
=
gst_buffer_c
opy_region
(
cur
,
GST_BUFFER_COPY_ALL
,
skip
,
nbytes
);
goto
done
;
}
}
...
...
libs/gst/base/gstbasetransform.c
View file @
ebb14d95
...
...
@@ -1598,9 +1598,9 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
if
(
setcaps
||
copymeta
)
{
GST_DEBUG_OBJECT
(
trans
,
"setcaps %d, copymeta %d"
,
setcaps
,
copymeta
);
if
(
!
gst_buffer_is_writable
(
*
out_buf
))
{
GST_DEBUG_OBJECT
(
trans
,
"buffer
metadata
%p not writable"
,
*
out_buf
);
GST_DEBUG_OBJECT
(
trans
,
"buffer %p not writable"
,
*
out_buf
);
if
(
in_buf
==
*
out_buf
)
*
out_buf
=
gst_buffer_c
reate_sub
(
in_buf
,
0
,
insize
);
*
out_buf
=
gst_buffer_c
opy
(
in_buf
);
else
*
out_buf
=
gst_buffer_make_writable
(
*
out_buf
);
}
...
...
libs/gst/base/gstcollectpads.c
View file @
ebb14d95
...
...
@@ -923,7 +923,8 @@ gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data,
if
(
data
->
pos
==
0
&&
readsize
==
bufsize
)
return
gst_buffer_ref
(
buffer
);
else
return
gst_buffer_create_sub
(
buffer
,
data
->
pos
,
readsize
);
return
gst_buffer_copy_region
(
buffer
,
GST_BUFFER_COPY_ALL
,
data
->
pos
,
readsize
);
}
/**
...
...
plugins/elements/gstcapsfilter.c
View file @
ebb14d95
...
...
@@ -341,7 +341,7 @@ gst_capsfilter_prepare_buf (GstBaseTransform * trans, GstBuffer * input,
gst_buffer_ref
(
input
);
}
else
{
GST_DEBUG_OBJECT
(
trans
,
"Creating sub-buffer and setting caps"
);
*
buf
=
gst_buffer_c
reate_sub
(
input
,
0
,
gst_buffer_get_size
(
input
)
);
*
buf
=
gst_buffer_c
opy
(
input
);
gst_buffer_set_caps
(
*
buf
,
caps
);
}
}
else
{
...
...
@@ -373,7 +373,7 @@ gst_capsfilter_prepare_buf (GstBaseTransform * trans, GstBuffer * input,
*
buf
=
input
;
}
else
{
GST_DEBUG_OBJECT
(
trans
,
"Creating sub-buffer and setting caps"
);
*
buf
=
gst_buffer_c
reate_sub
(
input
,
0
,
gst_buffer_get_size
(
input
)
);
*
buf
=
gst_buffer_c
opy
(
input
);
}
GST_BUFFER_CAPS
(
*
buf
)
=
out_caps
;
...
...
plugins/elements/gstfakesrc.c
View file @
ebb14d95
...
...
@@ -741,7 +741,9 @@ gst_fake_src_create_buffer (GstFakeSrc * src, gsize * bufsize)
}
/* see if it's large enough */
if
((
src
->
parentsize
-
src
->
parentoffset
)
>=
size
)
{
buf
=
gst_buffer_create_sub
(
src
->
parent
,
src
->
parentoffset
,
size
);
buf
=
gst_buffer_copy_region
(
src
->
parent
,
GST_BUFFER_COPY_ALL
,
src
->
parentoffset
,
size
);
src
->
parentoffset
+=
size
;
}
else
{
/* the parent is useless now */
...
...
tests/check/gst/gstbuffer.c
View file @
ebb14d95
...
...
@@ -98,8 +98,8 @@ GST_START_TEST (test_subbuffer)
GST_BUFFER_OFFSET
(
buffer
)
=
3
;
GST_BUFFER_OFFSET_END
(
buffer
)
=
4
;
sub
=
gst_buffer_c
reate_sub
(
buffer
,
1
,
2
);
fail_if
(
sub
==
NULL
,
"c
reate_sub
of buffer returned NULL"
);
sub
=
gst_buffer_c
opy_region
(
buffer
,
GST_BUFFER_COPY_ALL
,
1
,
2
);
fail_if
(
sub
==
NULL
,
"c
opy region
of buffer returned NULL"
);
sdata
=
gst_buffer_map
(
sub
,
&
ssize
,
NULL
,
GST_MAP_READ
);
fail_unless
(
ssize
==
2
,
"subbuffer has wrong size"
);
...
...
@@ -116,8 +116,8 @@ GST_START_TEST (test_subbuffer)
gst_buffer_unref
(
sub
);
/* create a subbuffer of size 0 */
sub
=
gst_buffer_c
reate_sub
(
buffer
,
1
,
0
);
fail_if
(
sub
==
NULL
,
"c
reate_sub
of buffer returned NULL"
);
sub
=
gst_buffer_c
opy_region
(
buffer
,
GST_BUFFER_COPY_ALL
,
1
,
0
);
fail_if
(
sub
==
NULL
,
"c
opy_region
of buffer returned NULL"
);
sdata
=
gst_buffer_map
(
sub
,
&
ssize
,
NULL
,
GST_MAP_READ
);
fail_unless
(
ssize
==
0
,
"subbuffer has wrong size"
);
fail_unless
(
memcmp
(
data
+
1
,
sdata
,
0
)
==
0
,
...
...
@@ -128,8 +128,8 @@ GST_START_TEST (test_subbuffer)
/* test if metadata is coppied, not a complete buffer copy so only the
* timestamp and offset fields are copied. */
sub
=
gst_buffer_c
reate_sub
(
buffer
,
0
,
1
);
fail_if
(
sub
==
NULL
,
"c
reate_sub
of buffer returned NULL"
);
sub
=
gst_buffer_c
opy_region
(
buffer
,
GST_BUFFER_COPY_ALL
,
0
,
1
);
fail_if
(
sub
==
NULL
,
"c
opy_region
of buffer returned NULL"
);
fail_unless
(
gst_buffer_get_size
(
sub
)
==
1
,
"subbuffer has wrong size"
);
fail_unless
(
GST_BUFFER_TIMESTAMP
(
sub
)
==
1
,
"subbuffer has wrong timestamp"
);
...
...
@@ -141,8 +141,8 @@ GST_START_TEST (test_subbuffer)
/* test if metadata is coppied, a complete buffer is copied so all the timing
* fields should be copied. */
sub
=
gst_buffer_c
reate_sub
(
buffer
,
0
,
4
);
fail_if
(
sub
==
NULL
,
"c
reate_sub
of buffer returned NULL"
);
sub
=
gst_buffer_c
opy_region
(
buffer
,
GST_BUFFER_COPY_ALL
,
0
,
4
);
fail_if
(
sub
==
NULL
,
"c
opy_region
of buffer returned NULL"
);
fail_unless
(
gst_buffer_get_size
(
sub
)
==
4
,
"subbuffer has wrong size"
);
fail_unless
(
GST_BUFFER_TIMESTAMP
(
sub
)
==
1
,
"subbuffer has wrong timestamp"
);
...
...
@@ -166,11 +166,11 @@ GST_START_TEST (test_is_span_fast)
buffer
=
gst_buffer_new_and_alloc
(
4
);
sub1
=
gst_buffer_c
reate_sub
(
buffer
,
0
,
2
);
fail_if
(
sub1
==
NULL
,
"c
reate_sub
of buffer returned NULL"
);
sub1
=
gst_buffer_c
opy_region
(
buffer
,
GST_BUFFER_COPY_ALL
,
0
,
2
);
fail_if
(
sub1
==
NULL
,
"c
opy_region
of buffer returned NULL"
);
sub2
=
gst_buffer_c
reate_sub
(
buffer
,
2
,
2
);
fail_if
(
sub2
==
NULL
,
"c
reate_sub
of buffer returned NULL"
);
sub2
=
gst_buffer_c
opy_region
(
buffer
,
GST_BUFFER_COPY_ALL
,
2
,
2
);
fail_if
(
sub2
==
NULL
,
"c
opy_region
of buffer returned NULL"
);
fail_if
(
gst_buffer_is_span_fast
(
buffer
,
sub2
)
==
TRUE
,
"a parent buffer can't be span_fasted"
);
...
...
@@ -206,11 +206,11 @@ GST_START_TEST (test_span)
ASSERT_CRITICAL
(
gst_buffer_span
(
NULL
,
1
,
buffer
,
2
));
ASSERT_CRITICAL
(
gst_buffer_span
(
buffer
,
0
,
buffer
,
10
));
sub1
=
gst_buffer_c
reate_sub
(
buffer
,
0
,
2
);
fail_if
(
sub1
==
NULL
,
"c
reate_sub
of buffer returned NULL"
);
sub1
=
gst_buffer_c
opy_region
(
buffer
,
GST_BUFFER_COPY_ALL
,
0
,
2
);
fail_if
(
sub1
==
NULL
,
"c
opy_region
of buffer returned NULL"
);
sub2
=
gst_buffer_c
reate_sub
(
buffer
,
2
,
2
);
fail_if
(
sub2
==
NULL
,
"c
reate_sub
of buffer returned NULL"
);
sub2
=
gst_buffer_c
opy_region
(
buffer
,
GST_BUFFER_COPY_ALL
,
2
,
2
);
fail_if
(
sub2
==
NULL
,
"c
opy_region
of buffer returned NULL"
);
ASSERT_BUFFER_REFCOUNT
(
buffer
,
"parent"
,
1
);
ASSERT_BUFFER_REFCOUNT
(
sub1
,
"sub1"
,
1
);
...
...
@@ -339,7 +339,7 @@ GST_START_TEST (test_subbuffer_make_writable)
/* create sub-buffer of read-only buffer and make it writable */
buf
=
create_read_only_buffer
();
sub_buf
=
gst_buffer_c
reate_sub
(
buf
,
0
,
8
);
sub_buf
=
gst_buffer_c
opy_region
(
buf
,
GST_BUFFER_COPY_ALL
,
0
,
8
);
data
=
gst_buffer_map
(
sub_buf
,
&
size
,
NULL
,
GST_MAP_WRITE
);
fail_if
(
data
==
NULL
);
...
...
tests/check/gst/gstmeta.c
View file @
ebb14d95
...
...
@@ -157,7 +157,7 @@ GST_START_TEST (test_meta_test)
gst_buffer_unref
(
copy
);
/* make subbuffer */
subbuf
=
gst_buffer_c
reate_sub
(
buffer
,
0
,
1
);
subbuf
=
gst_buffer_c
opy_region
(
buffer
,
GST_BUFFER_COPY_ALL
,
0
,
1
);
/* get metadata of the buffer */