1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "gst_video_shmem_pool.h"
17 #include "gst_shmem_allocator_old.h"
18
19 #define gst_video_shmem_pool_parent_class parent_class
20 G_DEFINE_TYPE (GstVideoShMemPool, gst_video_shmem_pool, GST_TYPE_VIDEO_BUFFER_POOL);
21
gst_video_shmem_pool_get_options(GstBufferPool * pool)22 static const gchar **gst_video_shmem_pool_get_options (GstBufferPool *pool)
23 {
24 (void)pool;
25 static const gchar *options[] = { GST_BUFFER_POOL_OPTION_VIDEO_META, nullptr };
26 return options;
27 }
28
gst_video_shmem_pool_set_config(GstBufferPool * pool,GstStructure * config)29 static gboolean gst_video_shmem_pool_set_config(GstBufferPool *pool, GstStructure *config)
30 {
31 GstVideoShMemPool *vpool = GST_VIDEO_SHMEM_POOL_CAST(pool);
32 g_return_val_if_fail(vpool != nullptr, FALSE);
33
34 GstAllocator *allocator = nullptr;
35 (void)gst_buffer_pool_config_get_allocator(config, &allocator, nullptr);
36 if (!(allocator && GST_IS_SHMEM_ALLOCATOR_OLD(allocator))) {
37 GST_WARNING_OBJECT(pool, "no valid allocator in pool");
38 return FALSE;
39 }
40
41 return GST_BUFFER_POOL_CLASS(parent_class)->set_config(pool, config);
42 }
43
gst_video_shmem_pool_finalize(GObject * obj)44 static void gst_video_shmem_pool_finalize(GObject *obj)
45 {
46 g_return_if_fail(obj != nullptr);
47
48 G_OBJECT_CLASS(parent_class)->finalize(obj);
49 }
50
gst_video_shmem_pool_class_init(GstVideoShMemPoolClass * klass)51 static void gst_video_shmem_pool_class_init (GstVideoShMemPoolClass *klass)
52 {
53 g_return_if_fail(klass != nullptr);
54 GstBufferPoolClass *poolClass = GST_BUFFER_POOL_CLASS(klass);
55 g_return_if_fail(poolClass != nullptr);
56 GObjectClass *gobjectClass = G_OBJECT_CLASS(klass);
57 g_return_if_fail(gobjectClass != nullptr);
58
59 gobjectClass->finalize = gst_video_shmem_pool_finalize;
60 poolClass->get_options = gst_video_shmem_pool_get_options;
61 poolClass->set_config = gst_video_shmem_pool_set_config;
62 }
63
gst_video_shmem_pool_init(GstVideoShMemPool * pool)64 static void gst_video_shmem_pool_init (GstVideoShMemPool *pool)
65 {
66 (void)pool;
67 }
68
gst_video_shmem_pool_new()69 GstBufferPool *gst_video_shmem_pool_new()
70 {
71 GstBufferPool *pool = GST_BUFFER_POOL_CAST(g_object_new(
72 GST_TYPE_VIDEO_SHMEM_POOL, "name", "VidShMemPool", nullptr));
73 (void)gst_object_ref_sink(pool);
74
75 return pool;
76 }
77