• 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_SURFACE_ALLOCATOR_H
17 #define GST_SURFACE_ALLOCATOR_H
18 
19 #include <gst/gst.h>
20 #include "display_type.h"
21 #include "gst_surface_memory.h"
22 
23 G_BEGIN_DECLS
24 
25 #define GST_TYPE_SURFACE_ALLOCATOR (gst_surface_allocator_get_type())
26 #define GST_SURFACE_ALLOCATOR(obj) \
27     (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_SURFACE_ALLOCATOR, GstSurfaceAllocator))
28 #define GST_SURFACE_ALLOCATOR_CLASS(klass) \
29     (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_SURFACE_ALLOCATOR, GstSurfaceAllocatorClass))
30 #define GST_IS_SURFACE_ALLOCATOR(obj) \
31     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_SURFACE_ALLOCATOR))
32 #define GST_IS_SURFACE_ALLOCATOR_CLASS(klass) \
33     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_SURFACE_ALLOCATOR))
34 #define GST_SURFACE_ALLOCATOR_CAST(obj) ((GstSurfaceAllocator*)(obj))
35 
36 #ifndef GST_API_EXPORT
37 #define GST_API_EXPORT __attribute__((visibility("default")))
38 #endif
39 
40 typedef struct _GstSurfaceAllocator GstSurfaceAllocator;
41 typedef struct _GstSurfaceAllocatorClass GstSurfaceAllocatorClass;
42 
43 class AllocatorWrap : public OHOS::NoCopyable {
44 public:
AllocatorWrap(GstSurfaceAllocator & owner)45     explicit AllocatorWrap(GstSurfaceAllocator &owner) : owner_(owner) {}
46     ~AllocatorWrap() = default;
47     OHOS::GSError OnBufferReleased(OHOS::sptr<OHOS::SurfaceBuffer> &buffer);
48 private:
49     GstSurfaceAllocator &owner_;
50 };
51 
52 struct _GstSurfaceAllocator {
53     GstAllocator parent;
54     OHOS::sptr<OHOS::Surface> surface;
55     GMutex lock;
56     GCond cond;
57     int32_t requestBufferNum;
58     int32_t flushBufferNum;
59     int32_t cacheBufferNum;
60     int32_t totalBufferNum;
61     gboolean clean;
62     AllocatorWrap *allocatorWrap;
63     gboolean isCallbackMode;
64 };
65 
66 struct _GstSurfaceAllocatorClass {
67     GstAllocatorClass parent;
68 };
69 
70 GST_API_EXPORT GType gst_surface_allocator_get_type(void);
71 
72 GST_API_EXPORT GstSurfaceAllocator *gst_surface_allocator_new();
73 
74 gboolean gst_surface_allocator_set_surface(GstSurfaceAllocator *allocator, OHOS::sptr<OHOS::Surface> surface);
75 
76 typedef struct _GstSurfaceAllocParam {
77     gint width;
78     gint height;
79     PixelFormat format;
80     guint64 usage;
81     gboolean dont_wait;
82     guint scale_type;
83 } GstSurfaceAllocParam;
84 
85 GstSurfaceMemory *gst_surface_allocator_alloc(GstSurfaceAllocator *allocator, GstSurfaceAllocParam param);
86 
87 void gst_surface_allocator_free(GstSurfaceAllocator *allocator, GstSurfaceMemory *memory);
88 
89 gboolean gst_surface_allocator_flush_buffer(GstSurfaceAllocator *allocator, OHOS::sptr<OHOS::SurfaceBuffer>& buffer,
90     int32_t fence, OHOS::BufferFlushConfig &config);
91 
92 gboolean gst_surface_allocator_set_queue_size(GstSurfaceAllocator *allocator, int32_t size);
93 
94 void gst_surface_allocator_clean_cache(GstSurfaceAllocator *allocator);
95 
96 G_END_DECLS
97 
98 #endif
99