4e1a898cb3765b07dec68d84cafea6dc40f313fb
[platform/upstream/gstreamer.git] / gst-libs / gst / allocators / gstphysmemory.c
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 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "gstphysmemory.h"
25
26 G_DEFINE_INTERFACE (GstPhysMemoryAllocator, gst_phys_memory_allocator,
27     GST_TYPE_ALLOCATOR);
28
29 static void
30 gst_phys_memory_allocator_default_init (GstPhysMemoryAllocatorInterface * iface)
31 {
32 }
33
34 /**
35  * gst_is_phys_memory:
36  * @mem: a #GstMemory
37  *
38  * Returns: whether the memory at @mem is backed by physical memory
39  *
40  * Since: 1.14
41  */
42 gboolean
43 gst_is_phys_memory (GstMemory * mem)
44 {
45   return mem != NULL && mem->allocator != NULL
46       && g_type_is_a (G_OBJECT_TYPE (mem->allocator),
47       GST_TYPE_PHYS_MEMORY_ALLOCATOR);
48 }
49
50 /**
51  * gst_phys_memory_get_phys_addr:
52  * @mem: a #GstMemory
53  *
54  * Returns: Physical memory address that is backing @mem, or 0 if none
55  *
56  * Since: 1.14
57  */
58 guintptr
59 gst_phys_memory_get_phys_addr (GstMemory * mem)
60 {
61   GstPhysMemoryAllocatorInterface *iface;
62
63   g_return_val_if_fail (gst_is_phys_memory (mem), 0);
64
65   iface = GST_PHYS_MEMORY_ALLOCATOR_GET_INTERFACE (mem->allocator);
66   g_return_val_if_fail (iface->get_phys_addr != NULL, 0);
67
68   return iface->get_phys_addr ((GstPhysMemoryAllocator *) mem->allocator, mem);
69 }