• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef GST_PRODUCER_SURFACE_POOL_H
17 #define GST_PRODUCER_SURFACE_POOL_H
18 
19 #include <gst/gst.h>
20 #include <gst/video/video-info.h>
21 #include "surface.h"
22 #include "gst_surface_allocator.h"
23 #include "display_type.h"
24 
25 G_BEGIN_DECLS
26 
27 #define GST_TYPE_PRODUCER_SURFACE_POOL (gst_producer_surface_pool_get_type())
28 #define GST_PRODUCER_SURFACE_POOL(obj) \
29     (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_PRODUCER_SURFACE_POOL, GstProducerSurfacePool))
30 #define GST_PRODUCER_SURFACE_POOL_CLASS(klass) \
31     (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_PRODUCER_SURFACE_POOL, GstProducerSurfacePoolClass))
32 #define GST_IS_SURFACE_POOL(obj) \
33     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_PRODUCER_SURFACE_POOL))
34 #define GST_IS_SURFACE_POOL_CLASS(klass) \
35     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_PRODUCER_SURFACE_POOL))
36 #define GST_PRODUCER_SURFACE_POOL_CAST(obj) ((GstProducerSurfacePool*)(obj))
37 
38 using ProSurfaceNewBuffer = GstFlowReturn (*)(GstBuffer *buffer, gpointer user_data);
39 using ProSurfaceOnDestroy = void (*)(gpointer user_data);
40 
41 typedef struct _GstProducerSurfacePool GstProducerSurfacePool;
42 typedef struct _GstProducerSurfacePoolClass GstProducerSurfacePoolClass;
43 
44 struct _GstProducerSurfacePool {
45     GstBufferPool basepool;
46     OHOS::sptr<OHOS::Surface> surface;
47     gboolean started;
48     GstSurfaceAllocator *allocator;
49     GstAllocationParams params;
50     PixelFormat format;
51     GstVideoInfo info;
52     guint minBuffers;
53     guint maxBuffers;
54     GMutex lock;
55     GCond cond;
56     GList *preAllocated;
57     guint freeBufCnt;
58     guint64 usage;
59     GstTask *task;
60     GRecMutex taskLock;
61     timeval beginTime;
62     timeval endTime;
63     int32_t callCnt;
64     gboolean isDynamicCached;
65     guint cachedBuffers;
66     guint scale_type;
67     ProSurfaceNewBuffer newBuffer;
68     gpointer userdata;
69     gboolean isHardwareDec;
70     ProSurfaceOnDestroy onDestroy;
71 };
72 
73 struct _GstProducerSurfacePoolClass {
74     GstBufferPoolClass basepool_class;
75 };
76 
77 GST_API_EXPORT GType gst_producer_surface_pool_get_type(void);
78 
79 GST_API_EXPORT GstProducerSurfacePool *gst_producer_surface_pool_new(void);
80 
81 GST_API_EXPORT gboolean gst_producer_surface_pool_set_surface(GstProducerSurfacePool *pool,
82     OHOS::sptr<OHOS::Surface> surface);
83 
84 GST_API_EXPORT gboolean gst_producer_surface_pool_flush_buffer(GstProducerSurfacePool *pool,
85     OHOS::sptr<OHOS::SurfaceBuffer>& buffer, int32_t fence, OHOS::BufferFlushConfig &config);
86 
87 GST_API_EXPORT gboolean gst_producer_surface_pool_set_callback(GstBufferPool *pool,
88     ProSurfaceNewBuffer callback, gpointer userdata, ProSurfaceOnDestroy onDestroy);
89 
90 G_END_DECLS
91 
92 #endif