1 /* 2 * Copyright (C) 2023 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_SUBTITLE_SINK_H 17 #define GST_SUBTITLE_SINK_H 18 19 #include <memory> 20 #include <gst/base/gstbasesink.h> 21 #include <gst/app/gstappsink.h> 22 #include "task_queue.h" 23 24 G_BEGIN_DECLS 25 26 #define GST_TYPE_SUBTITLE_SINK (gst_subtitle_sink_get_type()) 27 #define GST_SUBTITLE_SINK(obj) \ 28 (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_SUBTITLE_SINK, GstSubtitleSink)) 29 #define GST_SUBTITLE_SINK_CLASS(kclass) \ 30 (G_TYPE_CHECK_CLASS_CAST((kclass), GST_TYPE_SUBTITLE_SINK, GstSubtitleSinkClass)) 31 #define GST_IS_SUBTITLE_SINK(obj) \ 32 (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_SUBTITLE_SINK)) 33 #define GST_IS_SUBTITLE_SINK_CLASS(kclass) \ 34 (G_TYPE_CHECK_CLASS_TYPE((kclass), GST_TYPE_SUBTITLE_SINK)) 35 #define GST_SUBTITLE_SINK_CAST(obj) ((GstSubtitleSink*)(obj)) 36 #define GST_SUBTITLE_SINK_GET_CLASS(obj) \ 37 (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_SUBTITLE_SINK, GstSubtitleSinkClass)) 38 39 #ifndef GST_API_EXPORT 40 #define GST_API_EXPORT __attribute__((visibility("default"))) 41 #endif 42 43 using GstSubtitleSink = struct _GstSubtitleSink; 44 using GstSubtitleSinkClass = struct _GstSubtitleSinkClass; 45 using GstSubtitleSinkPrivate = struct _GstSubtitleSinkPrivate; 46 47 using GstSubtitleSinkCallbacks = struct { 48 GstFlowReturn (*new_sample)(GstBuffer *sample, gpointer user_data); 49 }; 50 51 struct _GstSubtitleSink { 52 GstAppSink appsink; 53 gboolean stop_render; 54 gboolean have_first_segment; 55 gboolean audio_segment_updated; 56 gboolean segment_updated; 57 gboolean is_changing_track; 58 gboolean enable_display; 59 gboolean need_send_empty_buffer; 60 gboolean have_first_filter; 61 GstBuffer *preroll_buffer; 62 guint64 track_changing_position; 63 guint64 init_position; 64 gdouble rate; 65 GCond segment_cond; 66 GMutex segment_mutex; 67 GstSegment segment; 68 GstSeekFlags seek_flags; 69 /* private */ 70 GstSubtitleSinkPrivate *priv; 71 }; 72 73 struct _GstSubtitleSinkClass { 74 GstAppSinkClass parent_class; 75 }; 76 77 GST_API_EXPORT GType gst_subtitle_sink_get_type(void); 78 79 /** 80 * @brief call this interface to set the notifiers for new_sample. 81 * 82 * @param subtitle_sink the sink element instance 83 * @param callbacks callbacks, refer to {@GstSubtitleSinkCallbacks} 84 * @param user_data will be passed to callbacks 85 * @param notify the function to be used to destroy the user_data when the subtitle_sink is disposed 86 * @return void. 87 */ 88 GST_API_EXPORT void gst_subtitle_sink_set_callback(GstSubtitleSink *subtitle_sink, 89 GstSubtitleSinkCallbacks *callbacks, gpointer user_data, GDestroyNotify notify); 90 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 91 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstSubtitleSink, gst_object_unref) 92 #endif 93 94 G_END_DECLS 95 #endif // GST_SUBTITLE_SINK_H 96