1 /* Generic video compositor plugin 2 * Copyright (C) 2008 Wim Taymans <wim@fluendo.com> 3 * Copyright (C) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, write to the 17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef __GST_COMPOSITOR_H__ 22 #define __GST_COMPOSITOR_H__ 23 24 #include <gst/gst.h> 25 #include <gst/video/video.h> 26 #include <gst/video/gstvideoaggregator.h> 27 #include <gst/base/base.h> 28 29 #include "blend.h" 30 31 G_BEGIN_DECLS 32 33 #define GST_TYPE_COMPOSITOR (gst_compositor_get_type()) 34 G_DECLARE_FINAL_TYPE (GstCompositor, gst_compositor, GST, COMPOSITOR, 35 GstVideoAggregator) 36 37 #define GST_TYPE_COMPOSITOR_PAD (gst_compositor_pad_get_type()) 38 G_DECLARE_FINAL_TYPE (GstCompositorPad, gst_compositor_pad, GST, COMPOSITOR_PAD, 39 GstVideoAggregatorParallelConvertPad) 40 41 /** 42 * GstCompositorBackground: 43 * @COMPOSITOR_BACKGROUND_CHECKER: checker pattern background 44 * @COMPOSITOR_BACKGROUND_BLACK: solid color black background 45 * @COMPOSITOR_BACKGROUND_WHITE: solid color white background 46 * @COMPOSITOR_BACKGROUND_TRANSPARENT: background is left transparent and layers are composited using "A OVER B" composition rules. This is only applicable to AYUV and ARGB (and variants) as it preserves the alpha channel and allows for further mixing. 47 * 48 * The different backgrounds compositor can blend over. 49 */ 50 typedef enum 51 { 52 COMPOSITOR_BACKGROUND_CHECKER, 53 COMPOSITOR_BACKGROUND_BLACK, 54 COMPOSITOR_BACKGROUND_WHITE, 55 COMPOSITOR_BACKGROUND_TRANSPARENT, 56 } GstCompositorBackground; 57 58 /** 59 * GstCompositorOperator: 60 * @COMPOSITOR_OPERATOR_SOURCE: Copy the source over the destination, 61 * without the destination pixels. 62 * @COMPOSITOR_OPERATOR_OVER: Blend the source over the destination. 63 * @COMPOSITOR_OPERATOR_ADD: Similar to over but add the source and 64 * destination alpha. Requires output with alpha 65 * channel. 66 * 67 * The different blending operators that can be used by compositor. 68 * 69 * See https://www.cairographics.org/operators/ for some explanation and 70 * visualizations. 71 * 72 */ 73 typedef enum 74 { 75 COMPOSITOR_OPERATOR_SOURCE, 76 COMPOSITOR_OPERATOR_OVER, 77 COMPOSITOR_OPERATOR_ADD, 78 } GstCompositorOperator; 79 80 /** 81 * GstCompositorSizingPolicy: 82 * @COMPOSITOR_SIZING_POLICY_NONE: Scaling image without padding 83 * @COMPOSITOR_SIZING_POLICY_KEEP_ASPECT_RATIO: Scaling image to fit destination 84 * resolution with preserving aspect ratio. Resulting image will be centered 85 * in the configured destination rectangle and it might have padding area 86 * if aspect ratio of destination rectangle is different from that of 87 * input image. 88 * 89 * Since: 1.20 90 */ 91 typedef enum 92 { 93 COMPOSITOR_SIZING_POLICY_NONE, 94 COMPOSITOR_SIZING_POLICY_KEEP_ASPECT_RATIO, 95 } GstCompositorSizingPolicy; 96 97 /* copied from video-converter.c */ 98 typedef void (*GstParallelizedTaskFunc) (gpointer user_data); 99 100 typedef struct _GstParallelizedTaskRunner GstParallelizedTaskRunner; 101 102 struct _GstParallelizedTaskRunner 103 { 104 GstTaskPool *pool; 105 gboolean own_pool; 106 guint n_threads; 107 108 GstQueueArray *tasks; 109 110 GstParallelizedTaskFunc func; 111 gpointer *task_data; 112 113 GMutex lock; 114 gint n_todo; 115 116 gboolean async_tasks; 117 }; 118 119 /** 120 * GstCompositor: 121 * 122 * The opaque #GstCompositor structure. 123 */ 124 struct _GstCompositor 125 { 126 GstVideoAggregator videoaggregator; 127 GstCompositorBackground background; 128 129 /* Property to allow overriding the default behaviour of 130 * pad.width == 0 or pad.height == 0: by default it means the input 131 * image should be left unscaled in that dimension, but it may be desirable 132 * to have it simply mean the image should not be composited into the output 133 * image, for example when animating the property. 134 */ 135 gboolean zero_size_is_unscaled; 136 137 /* Max num of allowed for blending/rendering threads */ 138 guint max_threads; 139 140 /* The 'blend' compositing function does not preserve the alpha value of the 141 * background, while 'overlay' does; i.e., COMPOSITOR_OPERATOR_ADD is the 142 * same as COMPOSITOR_OPERATOR_OVER when using the 'blend' BlendFunction. */ 143 BlendFunction blend, overlay; 144 FillCheckerFunction fill_checker; 145 FillColorFunction fill_color; 146 147 GstParallelizedTaskRunner *blend_runner; 148 }; 149 150 /** 151 * GstCompositorPad: 152 * 153 * The opaque #GstCompositorPad structure. 154 */ 155 struct _GstCompositorPad 156 { 157 GstVideoAggregatorParallelConvertPad parent; 158 159 /* properties */ 160 gint xpos, ypos; 161 gint width, height; 162 gdouble alpha; 163 GstCompositorSizingPolicy sizing_policy; 164 165 GstCompositorOperator op; 166 167 /* offset values for xpos and ypos used when sizing-policy is equal to 168 * keep-aspect-ratio */ 169 gint x_offset; 170 gint y_offset; 171 }; 172 173 GST_ELEMENT_REGISTER_DECLARE (compositor); 174 175 G_END_DECLS 176 #endif /* __GST_COMPOSITOR_H__ */ 177