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_MEM_SINK_H 17 #define GST_MEM_SINK_H 18 19 #include <gst/base/gstbasesink.h> 20 21 G_BEGIN_DECLS 22 23 #define GST_TYPE_MEM_SINK (gst_mem_sink_get_type()) 24 #define GST_MEM_SINK(obj) \ 25 (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_MEM_SINK, GstMemSink)) 26 #define GST_MEM_SINK_CLASS(klass) \ 27 (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_MEM_SINK, GstMemSinkClass)) 28 #define GST_IS_MEM_SINK(obj) \ 29 (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_MEM_SINK)) 30 #define GST_IS_MEM_SINK_CLASS(klass) \ 31 (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_MEM_SINK)) 32 #define GST_MEM_SINK_CAST(obj) ((GstMemSink*)(obj)) 33 #define GST_MEM_SINK_GET_CLASS(obj) \ 34 (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_MEM_SINK, GstMemSinkClass)) 35 36 #ifndef GST_API_EXPORT 37 #define GST_API_EXPORT __attribute__((visibility("default"))) 38 #endif 39 40 typedef struct _GstMemSink GstMemSink; 41 typedef struct _GstMemSinkClass GstMemSinkClass; 42 typedef struct _GstMemSinkPrivate GstMemSinkPrivate; 43 44 typedef struct { 45 void (*eos)(GstMemSink *mem_sink, gpointer user_data); 46 GstFlowReturn (*new_preroll)(GstMemSink *mem_sink, GstBuffer *preroll, gpointer user_data); 47 GstFlowReturn (*new_sample)(GstMemSink *mem_sink, GstBuffer *sample, gpointer user_data); 48 } GstMemSinkCallbacks; 49 50 struct _GstMemSink { 51 GstBaseSink basesink; 52 53 guint max_pool_capacity; /* max buffer count for buffer pool */ 54 guint wait_time; /* longest waiting time for single try to acquire buffer from buffer pool */ 55 56 /* < private > */ 57 GstMemSinkPrivate *priv; 58 }; 59 60 struct _GstMemSinkClass { 61 GstBaseSinkClass basesink_class; 62 63 gboolean (*do_propose_allocation) (GstMemSink *sink, GstQuery *query); 64 GstFlowReturn (*do_stream_render) (GstMemSink *sink, GstBuffer **buffer); 65 GstFlowReturn (*do_app_render) (GstMemSink *sink, GstBuffer *buffer, bool isPreroll); 66 }; 67 68 GST_API_EXPORT GType gst_mem_sink_get_type(void); 69 70 /** 71 * @brief call this interface to set the notifiers for new_preroll, new_sample and eos. 72 * 73 * @param mem_sink the sink element instance 74 * @param callbacks callbacks, refer to {@GstMemSinkCallbacks} 75 * @param user_data will be passed to callbacks 76 * @param notify the function to be used to destroy the user_data when the mem_sink is disposed 77 * @return GST_FLOW_OK if success, or error code. 78 */ 79 GST_API_EXPORT void gst_mem_sink_set_callback(GstMemSink *mem_sink, 80 GstMemSinkCallbacks *callbacks, 81 gpointer user_data, 82 GDestroyNotify notify); 83 84 /** 85 * @brief call this interface to indicate the app ends up the access of buffer, then 86 * the buffer can be release back to buffer pool. Call this function is not necessary, 87 * it is up to the sink and pool implementation and underlying memory type. 88 * 89 * @param mem_sink the sink element instance 90 * @param buffer the buffer will be rendered, allowd to be nullptr at certain situation. 91 * @return GST_FLOW_OK if success, or error code. 92 */ 93 GST_API_EXPORT GstFlowReturn gst_mem_sink_app_render(GstMemSink *mem_sink, GstBuffer *buffer); 94 95 /** 96 * @brief call this interface to indicate the app ends up the access of buffer, then 97 * the buffer can be release back to buffer pool. Call this function is not necessary, 98 * it is up to the sink and pool implementation and underlying memory type. 99 * 100 * @param mem_sink the sink element instance 101 * @param buffer the buffer will be rendered, allowd to be nullptr at certain situation. 102 * @return GST_FLOW_OK if success, or error code. 103 */ 104 GST_API_EXPORT GstFlowReturn gst_mem_sink_app_preroll_render(GstMemSink *mem_sink, GstBuffer *buffer); 105 106 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 107 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstMemSink, gst_object_unref) 108 #endif 109 110 G_END_DECLS 111 #endif 112