• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
3  *
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.
8  *
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.
13  *
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 /**
21  * SECTION:gstphysmemoryallocator
22  * @title: GstPhysMemoryAllocator
23  * @short_description: Interface for allocators that pass around physical memory addresses
24  * @see_also: #GstMemory
25  *
26  * Since: 1.14
27  */
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 #include "gstphysmemory.h"
33 
34 G_DEFINE_INTERFACE (GstPhysMemoryAllocator, gst_phys_memory_allocator,
35     GST_TYPE_ALLOCATOR);
36 
37 static void
gst_phys_memory_allocator_default_init(GstPhysMemoryAllocatorInterface * iface)38 gst_phys_memory_allocator_default_init (GstPhysMemoryAllocatorInterface * iface)
39 {
40 }
41 
42 /**
43  * gst_is_phys_memory:
44  * @mem: a #GstMemory
45  *
46  * Returns: whether the memory at @mem is backed by physical memory
47  *
48  * Since: 1.14
49  */
50 gboolean
gst_is_phys_memory(GstMemory * mem)51 gst_is_phys_memory (GstMemory * mem)
52 {
53   return mem != NULL && mem->allocator != NULL
54       && g_type_is_a (G_OBJECT_TYPE (mem->allocator),
55       GST_TYPE_PHYS_MEMORY_ALLOCATOR);
56 }
57 
58 /**
59  * gst_phys_memory_get_phys_addr:
60  * @mem: a #GstMemory
61  *
62  * Returns: Physical memory address that is backing @mem, or 0 if none
63  *
64  * Since: 1.14
65  */
66 guintptr
gst_phys_memory_get_phys_addr(GstMemory * mem)67 gst_phys_memory_get_phys_addr (GstMemory * mem)
68 {
69   GstPhysMemoryAllocatorInterface *iface;
70 
71   g_return_val_if_fail (gst_is_phys_memory (mem), 0);
72 
73   iface = GST_PHYS_MEMORY_ALLOCATOR_GET_IFACE (mem->allocator);
74   g_return_val_if_fail (iface->get_phys_addr != NULL, 0);
75 
76   return iface->get_phys_addr ((GstPhysMemoryAllocator *) mem->allocator, mem);
77 }
78