2 * Copyright (C) 2020 Ognyan Tonchev <ognyan at axis dot com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include "gstbuffermemory.h"
23 gst_buffer_memory_map (GstBuffer * buffer, GstBufferMemoryMap * map)
27 g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
28 g_return_val_if_fail (map != NULL, FALSE);
30 if (gst_buffer_n_memory (buffer) == 0) {
31 GST_DEBUG ("no memory blocks in buffer");
35 mem = gst_buffer_get_memory (buffer, 0);
37 if (!gst_memory_map (mem, &map->map, GST_MAP_READ)) {
38 GST_ERROR ("failed to map memory");
39 gst_memory_unref (mem);
45 map->data = map->map.data;
46 map->size = map->map.size;
48 map->total_size = gst_buffer_get_size (buffer);
55 buffer_memory_map_next (GstBufferMemoryMap * map)
60 gst_memory_unmap (map->mem, &map->map);
61 gst_memory_unref (map->mem);
68 if (map->index >= gst_buffer_n_memory (map->buf)) {
69 GST_DEBUG ("no more memory blocks in buffer");
73 map->mem = gst_buffer_get_memory (map->buf, map->index);
75 if (!gst_memory_map (map->mem, &map->map, GST_MAP_READ)) {
76 GST_ERROR ("failed to map memory");
77 gst_memory_unref (map->mem);
82 map->data = map->map.data;
83 map->size = map->map.size;
89 gst_buffer_memory_advance_bytes (GstBufferMemoryMap * map, gsize size)
93 g_return_val_if_fail (map != NULL, FALSE);
97 while (offset >= map->size) {
99 GST_DEBUG ("switching memory");
100 if (!buffer_memory_map_next (map))
111 gst_buffer_memory_unmap (GstBufferMemoryMap * map)
113 g_return_if_fail (map != NULL);
116 gst_memory_unmap (map->mem, &map->map);
117 gst_memory_unref (map->mem);