xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1 | /* GStreamer |
| 2 | * Copyright (C) 2022 <xuesong.jiang@amlogic.com> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public |
| 15 | * License along with this library; if not, write to the |
| 16 | * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, |
| 17 | * Boston, MA 02110-1335, USA. |
| 18 | */ |
| 19 | |
| 20 | #ifdef HAVE_CONFIG_H |
| 21 | #include "config.h" |
| 22 | #endif |
| 23 | |
| 24 | #include <sys/stat.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <errno.h> |
| 27 | #include <unistd.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | #include "gstamlv4l2object.h" |
| 31 | #include "gstamlv4l2videodec.h" |
| 32 | |
| 33 | #include <string.h> |
| 34 | #include <gst/gst-i18n-plugin.h> |
| 35 | #include <gst/allocators/gstdmabuf.h> |
| 36 | |
| 37 | GST_DEBUG_CATEGORY_STATIC(gst_aml_v4l2_video_dec_debug); |
| 38 | #define GST_CAT_DEFAULT gst_aml_v4l2_video_dec_debug |
zengliang.li | dcd4146 | 2024-06-19 16:05:12 +0800 | [diff] [blame] | 39 | #define GST_AML_V4L2_CC_IMPORT_QUARK gst_aml_v4l2_buffer_pool_cc_import_quark () |
| 40 | |
hanghang.luo | 36df285 | 2022-08-24 15:02:27 +0800 | [diff] [blame] | 41 | #ifndef ABSDIFF |
| 42 | #define ABSDIFF(a,b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) |
| 43 | #endif |
| 44 | |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 45 | #if GST_IMPORT_LGE_PROP |
| 46 | typedef struct _GstAmlResourceInfo |
| 47 | { |
| 48 | gchar *coretype; |
| 49 | gint videoport; |
| 50 | gint audioport; |
| 51 | gint maxwidth; |
| 52 | gint maxheight; |
| 53 | gint mixerport; |
| 54 | } GstAmlResourceInfo; |
| 55 | |
| 56 | struct _GstAmlV4l2VideoDecLgeCtxt |
| 57 | { |
| 58 | GstAmlResourceInfo res_info; |
| 59 | guint64 dec_size; |
| 60 | guint64 undec_size; |
| 61 | gchar *app_type; |
| 62 | gboolean clip_mode; |
| 63 | }; |
| 64 | #endif |
| 65 | |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 66 | typedef struct |
| 67 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 68 | gchar *device; |
| 69 | GstCaps *sink_caps; |
| 70 | GstCaps *src_caps; |
| 71 | const gchar *longname; |
| 72 | const gchar *description; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 73 | } GstAmlV4l2VideoDecCData; |
| 74 | |
| 75 | enum |
| 76 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 77 | PROP_0, |
| 78 | V4L2_STD_OBJECT_PROPS, |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 79 | #if GST_IMPORT_LGE_PROP |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 80 | LGE_RESOURCE_INFO, |
| 81 | LGE_DECODE_SIZE, |
| 82 | LGE_UNDECODE_SIZE, |
| 83 | LGE_APP_TYPE, |
| 84 | LGE_CLIP_MODE |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 85 | #endif |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 86 | }; |
| 87 | |
xuesong.jiang | 406ee30 | 2023-06-28 03:45:22 +0000 | [diff] [blame] | 88 | enum |
| 89 | { |
| 90 | SIGNAL_DECODED_PTS, |
le.han | 7e9c27d | 2024-08-08 08:10:46 +0000 | [diff] [blame] | 91 | SIGNAL_DECODED_ERROR_PTS, |
xuesong.jiang | 406ee30 | 2023-06-28 03:45:22 +0000 | [diff] [blame] | 92 | MAX_SIGNAL |
| 93 | }; |
| 94 | |
| 95 | static guint g_signals[MAX_SIGNAL]= {0}; |
| 96 | |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 97 | #define gst_aml_v4l2_video_dec_parent_class parent_class |
| 98 | G_DEFINE_ABSTRACT_TYPE(GstAmlV4l2VideoDec, gst_aml_v4l2_video_dec, |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 99 | GST_AML_TYPE_VIDEO_DECODER); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 100 | |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 101 | static GstFlowReturn gst_aml_v4l2_video_dec_finish(GstAmlVideoDecoder *decoder); |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 102 | #if GST_IMPORT_LGE_PROP |
| 103 | static void gst_aml_v4l2_video_dec_install_lge_properties_helper(GObjectClass *gobject_class); |
| 104 | #endif |
le.han | 44125c3 | 2024-09-03 07:55:57 +0000 | [diff] [blame] | 105 | static GstClockTime gst_aml_v4l2_video_dec_calc_output_buffer_pts(GstAmlVideoDecoder *decoder); |
| 106 | static GstClockTime gst_aml_v4l2_video_dec_calc_duration(GstAmlVideoDecoder *decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 107 | |
| 108 | static void |
| 109 | gst_aml_v4l2_video_dec_set_property(GObject *object, |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 110 | guint prop_id, const GValue * value, GParamSpec * pspec) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 111 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 112 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(object); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 113 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 114 | switch (prop_id) |
| 115 | { |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 116 | case PROP_CAPTURE_IO_MODE: |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 117 | case PROP_DUMP_FRAME_LOCATION: |
zengliang.li | dcd4146 | 2024-06-19 16:05:12 +0800 | [diff] [blame] | 118 | case PROP_CC_DATA: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 119 | if (!gst_aml_v4l2_object_set_property_helper(self->v4l2capture, |
| 120 | prop_id, value, pspec)) |
| 121 | { |
| 122 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 123 | } |
| 124 | break; |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 125 | #if GST_IMPORT_LGE_PROP |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 126 | case LGE_RESOURCE_INFO: |
| 127 | { |
| 128 | GST_DEBUG_OBJECT(self, "LGE up layer set res info"); |
| 129 | GstStructure *r_info = g_value_get_object(value); |
| 130 | if (r_info) |
| 131 | { |
| 132 | if (gst_structure_has_field(r_info, "coretype")) |
| 133 | { |
| 134 | if (self->lge_ctxt->res_info.coretype) |
| 135 | g_free(self->lge_ctxt->res_info.coretype); |
| 136 | self->lge_ctxt->res_info.coretype = g_strdup(gst_structure_get_string(r_info, "coretype")); |
| 137 | } |
| 138 | if (gst_structure_has_field(r_info, "videoport")) |
| 139 | gst_structure_get_int(r_info, "videoport", &(self->lge_ctxt->res_info.videoport)); |
| 140 | if (gst_structure_has_field(r_info, "audioport")) |
| 141 | gst_structure_get_int(r_info, "audioport", &(self->lge_ctxt->res_info.audioport)); |
| 142 | if (gst_structure_has_field(r_info, "maxwidth")) |
| 143 | gst_structure_get_int(r_info, "maxwidth", &(self->lge_ctxt->res_info.maxwidth)); |
| 144 | if (gst_structure_has_field(r_info, "maxheight")) |
| 145 | gst_structure_get_int(r_info, "maxheight", &(self->lge_ctxt->res_info.maxheight)); |
| 146 | if (gst_structure_has_field(r_info, "mixerport")) |
| 147 | gst_structure_get_int(r_info, "mixerport", &(self->lge_ctxt->res_info.mixerport)); |
| 148 | } |
| 149 | break; |
| 150 | } |
| 151 | case LGE_APP_TYPE: |
| 152 | { |
| 153 | GST_DEBUG_OBJECT(self, "LGE up layer set app type"); |
| 154 | if (self->lge_ctxt->app_type) |
| 155 | g_free(self->lge_ctxt->app_type); |
| 156 | self->lge_ctxt->app_type = g_strdup(g_value_get_string(value)); |
| 157 | break; |
| 158 | } |
| 159 | case LGE_CLIP_MODE: |
| 160 | { |
| 161 | GST_DEBUG_OBJECT(self, "LGE up layer set clip mode"); |
| 162 | self->lge_ctxt->clip_mode = g_strdup(g_value_get_boolean(value)); |
| 163 | break; |
| 164 | } |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 165 | #endif |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 166 | /* By default, only set on output */ |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 167 | default: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 168 | if (!gst_aml_v4l2_object_set_property_helper (self->v4l2output, |
| 169 | prop_id, value, pspec)) |
| 170 | { |
| 171 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 172 | } |
| 173 | break; |
| 174 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void |
| 178 | gst_aml_v4l2_video_dec_get_property(GObject *object, |
| 179 | guint prop_id, GValue *value, GParamSpec *pspec) |
| 180 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 181 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(object); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 182 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 183 | switch (prop_id) |
| 184 | { |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 185 | case PROP_CAPTURE_IO_MODE: |
zengliang.li | dcd4146 | 2024-06-19 16:05:12 +0800 | [diff] [blame] | 186 | case PROP_CC_DATA: |
fei.deng | af68276 | 2024-06-24 19:06:03 +0800 | [diff] [blame] | 187 | case PROP_DECODING_ERROR_FRAMES: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 188 | if (!gst_aml_v4l2_object_get_property_helper (self->v4l2capture, |
| 189 | prop_id, value, pspec)) |
| 190 | { |
| 191 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 192 | } |
| 193 | break; |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 194 | #if GST_IMPORT_LGE_PROP |
| 195 | case LGE_DECODE_SIZE: |
| 196 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 197 | GST_DEBUG_OBJECT(self, "LGE up layer get dec size"); |
| 198 | self->lge_ctxt->dec_size = -1; |
| 199 | g_value_set_int(value, self->lge_ctxt->dec_size); |
| 200 | break; |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 201 | } |
| 202 | case LGE_UNDECODE_SIZE: |
| 203 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 204 | GST_DEBUG_OBJECT(self, "LGE up layer get undec size"); |
| 205 | self->lge_ctxt->undec_size = -1; |
| 206 | g_value_set_int(value, self->lge_ctxt->undec_size); |
| 207 | break; |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 208 | } |
| 209 | #endif |
| 210 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 211 | /* By default read from output */ |
| 212 | default: |
| 213 | if (!gst_aml_v4l2_object_get_property_helper (self->v4l2output, |
| 214 | prop_id, value, pspec)) |
| 215 | { |
| 216 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 217 | } |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 218 | break; |
| 219 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 223 | gst_aml_v4l2_video_dec_open(GstAmlVideoDecoder *decoder) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 224 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 225 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 226 | GstCaps *codec_caps; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 227 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 228 | GST_DEBUG_OBJECT (self, "Opening"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 229 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 230 | if (!gst_aml_v4l2_object_open (self->v4l2output)) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 231 | goto failure; |
| 232 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 233 | if (!gst_aml_v4l2_object_open_shared (self->v4l2capture, self->v4l2output)) |
| 234 | goto failure; |
| 235 | |
| 236 | codec_caps = gst_pad_get_pad_template_caps (decoder->sinkpad); |
| 237 | self->probed_sinkcaps = gst_aml_v4l2_object_probe_caps (self->v4l2output, |
| 238 | codec_caps); |
| 239 | gst_caps_unref (codec_caps); |
| 240 | |
| 241 | if (gst_caps_is_empty (self->probed_sinkcaps)) |
| 242 | goto no_encoded_format; |
| 243 | |
| 244 | return TRUE; |
| 245 | |
| 246 | no_encoded_format: |
| 247 | GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS, |
| 248 | (_("Decoder on device %s has no supported input format"), |
| 249 | self->v4l2output->videodev), (NULL)); |
| 250 | goto failure; |
| 251 | |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 252 | failure: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 253 | if (GST_AML_V4L2_IS_OPEN (self->v4l2output)) |
| 254 | gst_aml_v4l2_object_close (self->v4l2output); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 255 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 256 | if (GST_AML_V4L2_IS_OPEN (self->v4l2capture)) |
| 257 | gst_aml_v4l2_object_close (self->v4l2capture); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 258 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 259 | gst_caps_replace (&self->probed_srccaps, NULL); |
| 260 | gst_caps_replace (&self->probed_sinkcaps, NULL); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 261 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 262 | return FALSE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 266 | gst_aml_v4l2_video_dec_close(GstAmlVideoDecoder *decoder) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 267 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 268 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 269 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 270 | GST_DEBUG_OBJECT (self, "Closing"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 271 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 272 | gst_aml_v4l2_object_close(self->v4l2output); |
| 273 | gst_aml_v4l2_object_close(self->v4l2capture); |
| 274 | gst_caps_replace (&self->probed_srccaps, NULL); |
| 275 | gst_caps_replace (&self->probed_sinkcaps, NULL); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 276 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 277 | return TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 281 | gst_aml_v4l2_video_dec_start(GstAmlVideoDecoder *decoder) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 282 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 283 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 284 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 285 | GST_DEBUG_OBJECT (self, "Starting"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 286 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 287 | gst_aml_v4l2_object_flush_start (self->v4l2output); |
| 288 | g_atomic_int_set (&self->active, TRUE); |
| 289 | self->output_flow = GST_FLOW_OK; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 290 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 291 | return TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 295 | gst_aml_v4l2_video_dec_stop(GstAmlVideoDecoder *decoder) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 296 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 297 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 298 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 299 | GST_DEBUG_OBJECT (self, "Stopping"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 300 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 301 | gst_aml_v4l2_object_flush_start (self->v4l2output); |
| 302 | gst_aml_v4l2_object_flush_start (self->v4l2capture); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 303 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 304 | /* Wait for capture thread to stop */ |
| 305 | gst_pad_stop_task (decoder->srcpad); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 306 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 307 | GST_AML_VIDEO_DECODER_STREAM_LOCK(decoder); |
| 308 | self->output_flow = GST_FLOW_OK; |
| 309 | GST_AML_VIDEO_DECODER_STREAM_UNLOCK(decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 310 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 311 | /* Should have been flushed already */ |
| 312 | g_assert (g_atomic_int_get (&self->active) == FALSE); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 313 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 314 | gst_aml_v4l2_object_stop(self->v4l2output); |
| 315 | gst_aml_v4l2_object_stop(self->v4l2capture); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 316 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 317 | if (self->input_state) |
| 318 | { |
| 319 | gst_aml_video_codec_state_unref(self->input_state); |
| 320 | self->input_state = NULL; |
| 321 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 322 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 323 | GST_DEBUG_OBJECT (self, "Stopped"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 324 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 325 | return TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 329 | gst_aml_v4l2_video_dec_codec_chg(GstAmlVideoDecoder *decoder, |
| 330 | GstAmlVideoCodecState *state) |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 331 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 332 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 333 | GstStructure *s_old = NULL; |
| 334 | GstStructure *s_new = NULL; |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 335 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 336 | // first play, must set foramt; |
| 337 | if (!self->input_state) |
| 338 | return TRUE; |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 339 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 340 | if (self->input_state->caps) |
| 341 | s_old = gst_caps_get_structure(self->input_state->caps,0); |
| 342 | if (state->caps) |
| 343 | s_new = gst_caps_get_structure(state->caps,0); |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 344 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 345 | if (s_new && s_old && strcmp(gst_structure_get_name(s_new),gst_structure_get_name(s_old))) |
| 346 | return TRUE; |
| 347 | return FALSE; |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 351 | gst_aml_v4l2_video_dec_res_chg(GstAmlVideoDecoder *decoder, |
| 352 | GstAmlVideoCodecState *state) |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 353 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 354 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 355 | gboolean ret = FALSE; |
| 356 | gint width_new = -1,height_new = -1,width_old = -1,height_old = -1; |
| 357 | GstStructure *s_old = NULL; |
| 358 | GstStructure *s_new = NULL; |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 359 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 360 | // first play, must set foramt; |
| 361 | if (!self->input_state) |
| 362 | { |
| 363 | ret = TRUE; |
| 364 | goto done; |
| 365 | } |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 366 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 367 | if (self->input_state->caps) |
| 368 | s_old = gst_caps_get_structure(self->input_state->caps,0); |
| 369 | if (state->caps) |
| 370 | s_new = gst_caps_get_structure(state->caps,0); |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 371 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 372 | if (s_new && gst_structure_has_field(s_new,"width") && gst_structure_has_field(s_new,"height")) |
| 373 | { |
| 374 | gst_structure_get_int(s_new,"width",&width_new); |
| 375 | gst_structure_get_int(s_new,"height",&height_new); |
| 376 | } |
| 377 | if (s_old && gst_structure_has_field(s_old,"width") && gst_structure_has_field(s_old,"height")) |
| 378 | { |
| 379 | gst_structure_get_int(s_old,"width",&width_old); |
| 380 | gst_structure_get_int(s_old,"height",&height_old); |
| 381 | } |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 382 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 383 | if (width_new != width_old || height_new != height_old) |
| 384 | ret = TRUE; |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 385 | |
| 386 | done: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 387 | GST_DEBUG_OBJECT(self, "ret is %d",ret); |
| 388 | return ret; |
hanghang.luo | 8e1225b | 2023-10-10 08:54:28 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 392 | gst_aml_v4l2_video_dec_set_format(GstAmlVideoDecoder *decoder, |
| 393 | GstAmlVideoCodecState *state) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 394 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 395 | GstAmlV4l2Error error = GST_AML_V4L2_ERROR_INIT; |
| 396 | gboolean ret = TRUE; |
| 397 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 398 | GstCaps *caps; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 399 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 400 | GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps); |
| 401 | if (self->input_state) |
| 402 | { |
| 403 | if (gst_aml_v4l2_video_dec_res_chg(decoder,state) || gst_aml_v4l2_video_dec_codec_chg(decoder,state)) |
| 404 | GST_DEBUG_OBJECT(self, "resolution or codec changed"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 405 | else |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 406 | goto done; |
| 407 | } |
| 408 | |
| 409 | GstCapsFeatures *const features = gst_caps_get_features(state->caps, 0); |
| 410 | GstStructure *s = gst_caps_get_structure(state->caps,0); |
| 411 | if (s && gst_structure_has_field(s,"format")) |
| 412 | { |
| 413 | if (!strcmp("XVID",gst_structure_get_string(s,"format"))) |
| 414 | { |
| 415 | GST_DEBUG_OBJECT(self, "This is a DIVX file, cannot support"); |
| 416 | ret = FALSE; |
| 417 | goto done; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if (gst_caps_features_contains(features, GST_CAPS_FEATURE_MEMORY_DMABUF)) |
| 422 | self->v4l2output->req_mode = GST_V4L2_IO_DMABUF_IMPORT; |
| 423 | |
| 424 | if (self->input_state) |
| 425 | { |
| 426 | if (gst_aml_v4l2_object_caps_equal(self->v4l2output, state->caps)) |
| 427 | { |
| 428 | GST_DEBUG_OBJECT (self, "Compatible caps"); |
| 429 | goto done; |
| 430 | } |
| 431 | |
| 432 | gst_aml_v4l2_video_dec_finish (decoder); |
| 433 | gst_aml_v4l2_object_stop (self->v4l2output); |
| 434 | |
| 435 | gst_aml_video_codec_state_unref(self->input_state); |
| 436 | self->input_state = NULL; |
| 437 | |
| 438 | /* The renegotiation flow don't blend with the base class flow. To properly |
| 439 | * stop the capture pool, if the buffers can't be orphaned, we need to |
| 440 | * reclaim our buffers, which will happend through the allocation query. |
| 441 | * The allocation query is triggered by gst_aml_video_decoder_negotiate() which |
| 442 | * requires the output caps to be set, but we can't know this information |
| 443 | * as we rely on the decoder, which requires the capture queue to be |
| 444 | * stopped. |
| 445 | * |
| 446 | * To workaround this issue, we simply run an allocation query with the |
| 447 | * old negotiated caps in order to drain/reclaim our buffers. That breaks |
| 448 | * the complexity and should not have much impact in performance since the |
| 449 | * following allocation query will happen on a drained pipeline and won't |
| 450 | * block. */ |
| 451 | if (self->v4l2capture->pool && |
| 452 | !gst_aml_v4l2_buffer_pool_orphan(&self->v4l2capture->pool)) |
| 453 | { |
| 454 | GstCaps *caps = gst_pad_get_current_caps (decoder->srcpad); |
| 455 | if (caps) |
| 456 | { |
| 457 | GstQuery *query = gst_query_new_allocation (caps, FALSE); |
| 458 | gst_pad_peer_query (decoder->srcpad, query); |
| 459 | gst_query_unref (query); |
| 460 | gst_caps_unref (caps); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | gst_aml_v4l2_object_stop (self->v4l2capture); |
| 465 | self->output_flow = GST_FLOW_OK; |
| 466 | } |
| 467 | if ((ret = gst_aml_v4l2_set_drm_mode(self->v4l2output)) == FALSE) |
| 468 | { |
| 469 | GST_ERROR_OBJECT(self, "config output drm mode error"); |
| 470 | goto done; |
| 471 | } |
| 472 | |
| 473 | if ((ret = gst_aml_v4l2_set_stream_mode(self->v4l2output)) == FALSE) |
| 474 | { |
| 475 | GST_ERROR_OBJECT(self, "config output stream mode error"); |
| 476 | goto done; |
| 477 | } |
| 478 | |
| 479 | if (!gst_aml_v4l2_object_set_format (self->v4l2output, state->caps, &error)) |
| 480 | { |
| 481 | GST_ERROR_OBJECT(self, "set format error"); |
| 482 | goto done; |
| 483 | } |
| 484 | |
| 485 | // MUST: aml v4l2 drive request set I frame after VIDIOC_S_FMT. |
| 486 | if ((ret = gst_aml_v4l2_set_I_frame_mode(self->v4l2output)) == FALSE) |
| 487 | { |
| 488 | GST_ERROR_OBJECT(self, "config I frame mode error"); |
| 489 | goto done; |
| 490 | } |
| 491 | |
| 492 | gst_caps_replace (&self->probed_srccaps, NULL); |
| 493 | self->probed_srccaps = gst_aml_v4l2_object_probe_caps (self->v4l2capture, |
| 494 | gst_aml_v4l2_object_get_raw_caps ()); |
| 495 | |
| 496 | if (gst_caps_is_empty (self->probed_srccaps)) |
| 497 | goto no_raw_format; |
| 498 | |
| 499 | caps = gst_caps_copy(self->probed_srccaps); |
| 500 | gst_caps_set_features_simple(caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF)); |
| 501 | gst_caps_append(self->probed_srccaps, caps); |
| 502 | if (ret) |
| 503 | self->input_state = gst_aml_video_codec_state_ref (state); |
| 504 | else |
| 505 | gst_aml_v4l2_error (self, &error); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 506 | |
| 507 | done: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 508 | return ret; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 509 | |
| 510 | no_raw_format: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 511 | GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS, |
| 512 | (_("Decoder on device %s has no supported output format"), |
| 513 | self->v4l2output->videodev), (NULL)); |
| 514 | return GST_FLOW_ERROR; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 518 | gst_aml_v4l2_video_dec_flush(GstAmlVideoDecoder *decoder) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 519 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 520 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 521 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 522 | GST_DEBUG_OBJECT(self, "Flushed"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 523 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 524 | /* Ensure the processing thread has stopped for the reverse playback |
| 525 | * discount case */ |
| 526 | if (gst_pad_get_task_state (decoder->srcpad) == GST_TASK_STARTED) |
| 527 | { |
| 528 | GST_AML_VIDEO_DECODER_STREAM_UNLOCK (decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 529 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 530 | gst_aml_v4l2_object_flush_start (self->v4l2output); |
| 531 | gst_aml_v4l2_object_flush_start (self->v4l2capture); |
| 532 | gst_pad_stop_task (decoder->srcpad); |
| 533 | GST_AML_VIDEO_DECODER_STREAM_LOCK (decoder); |
| 534 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 535 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 536 | self->output_flow = GST_FLOW_OK; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 537 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 538 | gst_aml_v4l2_object_flush_stop (self->v4l2output); |
| 539 | gst_aml_v4l2_object_flush_stop (self->v4l2capture); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 540 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 541 | if (self->v4l2output->pool) |
| 542 | gst_aml_v4l2_buffer_pool_flush (self->v4l2output->pool); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 543 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 544 | /* gst_aml_v4l2_buffer_pool_flush() calls streamon the capture pool and must be |
| 545 | * called after gst_aml_v4l2_object_flush_stop() stopped flushing the buffer |
| 546 | * pool. */ |
| 547 | if (self->v4l2capture->pool) |
| 548 | gst_aml_v4l2_buffer_pool_flush (self->v4l2capture->pool); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 549 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 550 | return TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 554 | gst_aml_v4l2_video_dec_negotiate(GstAmlVideoDecoder *decoder) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 555 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 556 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 557 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 558 | if (TRUE == self->v4l2output->is_svp) |
| 559 | { |
| 560 | GstStructure *s; |
| 561 | GstEvent *event; |
xuesong.jiang | 681d360 | 2022-06-24 21:23:35 +0800 | [diff] [blame] | 562 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 563 | s = gst_structure_new_empty ("IS_SVP"); |
| 564 | event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_STICKY, s); |
| 565 | GST_DEBUG_OBJECT(self, "before Send SVP Event :%p", event); |
| 566 | gst_pad_push_event (decoder->srcpad, event); |
| 567 | GST_DEBUG_OBJECT(self, "after Send SVP Event :%p", event); |
| 568 | } |
xuesong.jiang | 681d360 | 2022-06-24 21:23:35 +0800 | [diff] [blame] | 569 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 570 | /* We don't allow renegotiation without carefull disabling the pool */ |
| 571 | if (self->v4l2capture->pool && |
| 572 | gst_buffer_pool_is_active(GST_BUFFER_POOL(self->v4l2capture->pool))) |
| 573 | return TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 574 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 575 | return GST_AML_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static gboolean |
| 579 | gst_aml_v4l2_decoder_cmd(GstAmlV4l2Object *v4l2object, guint cmd, guint flags) |
| 580 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 581 | struct v4l2_decoder_cmd dcmd = { 0, }; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 582 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 583 | GST_DEBUG_OBJECT (v4l2object->element, |
| 584 | "sending v4l2 decoder command %u with flags %u", cmd, flags); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 585 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 586 | if (!GST_AML_V4L2_IS_OPEN (v4l2object)) |
| 587 | return FALSE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 588 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 589 | dcmd.cmd = cmd; |
| 590 | dcmd.flags = flags; |
| 591 | if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_DECODER_CMD, &dcmd) < 0) |
| 592 | goto dcmd_failed; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 593 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 594 | return TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 595 | |
| 596 | dcmd_failed: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 597 | if (errno == ENOTTY) |
| 598 | { |
| 599 | GST_INFO_OBJECT (v4l2object->element, |
| 600 | "Failed to send decoder command %u with flags %u for '%s'. (%s)", |
| 601 | cmd, flags, v4l2object->videodev, g_strerror (errno)); |
| 602 | } |
| 603 | else |
| 604 | { |
| 605 | GST_ERROR_OBJECT (v4l2object->element, |
| 606 | "Failed to send decoder command %u with flags %u for '%s'. (%s)", |
| 607 | cmd, flags, v4l2object->videodev, g_strerror (errno)); |
| 608 | } |
| 609 | return FALSE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | static GstFlowReturn |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 613 | gst_aml_v4l2_video_dec_finish(GstAmlVideoDecoder *decoder) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 614 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 615 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC (decoder); |
| 616 | GstFlowReturn ret = GST_FLOW_OK; |
| 617 | GstBuffer *buffer; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 618 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 619 | if (gst_pad_get_task_state (decoder->srcpad) != GST_TASK_STARTED) |
| 620 | goto done; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 621 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 622 | GST_DEBUG_OBJECT (self, "Finishing decoding"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 623 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 624 | GST_AML_VIDEO_DECODER_STREAM_UNLOCK (decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 625 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 626 | if (gst_aml_v4l2_decoder_cmd (self->v4l2output, V4L2_DEC_CMD_STOP, 0)) |
| 627 | { |
| 628 | GstTask *task = decoder->srcpad->task; |
| 629 | |
| 630 | /* If the decoder stop command succeeded, just wait until processing is |
| 631 | * finished */ |
| 632 | GST_DEBUG_OBJECT (self, "Waiting for decoder stop"); |
| 633 | GST_OBJECT_LOCK (task); |
| 634 | while (GST_TASK_STATE (task) == GST_TASK_STARTED) |
| 635 | GST_TASK_WAIT (task); |
| 636 | GST_OBJECT_UNLOCK (task); |
| 637 | |
| 638 | ret = GST_FLOW_FLUSHING; |
| 639 | } |
| 640 | else |
| 641 | { |
| 642 | /* otherwise keep queuing empty buffers until the processing thread has |
| 643 | * stopped, _pool_process() will return FLUSHING when that happened */ |
| 644 | while (ret == GST_FLOW_OK) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 645 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 646 | GST_DEBUG_OBJECT(self, "queue empty output buf"); |
| 647 | buffer = gst_buffer_new (); |
| 648 | ret = |
| 649 | gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &buffer); |
| 650 | gst_buffer_unref (buffer); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 651 | } |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 652 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 653 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 654 | /* and ensure the processing thread has stopped in case another error |
| 655 | * occurred. */ |
| 656 | gst_aml_v4l2_object_flush_start (self->v4l2capture); |
| 657 | gst_pad_stop_task (decoder->srcpad); |
| 658 | GST_AML_VIDEO_DECODER_STREAM_LOCK (decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 659 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 660 | if (ret == GST_FLOW_FLUSHING) |
| 661 | ret = self->output_flow; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 662 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 663 | /*if V4L2_DEC_CMD_STOP called,indicate decoder will stop. |
| 664 | should reset need_wait_event=true to wait source change event*/ |
| 665 | self->v4l2capture->need_wait_event = TRUE; |
| 666 | GST_DEBUG_OBJECT (decoder, "Done draining buffers"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 667 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 668 | /* TODO Shall we cleanup any reffed frame to workaround broken decoders ? */ |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 669 | |
| 670 | done: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 671 | return ret; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | static GstFlowReturn |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 675 | gst_aml_v4l2_video_dec_drain(GstAmlVideoDecoder *decoder) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 676 | { |
| 677 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 678 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 679 | GST_DEBUG_OBJECT (self, "Draining..."); |
| 680 | gst_aml_v4l2_video_dec_finish (decoder); |
| 681 | gst_aml_v4l2_video_dec_flush (decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 682 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 683 | return GST_FLOW_OK; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 684 | } |
| 685 | |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 686 | static GstAmlVideoCodecFrame * |
| 687 | gst_aml_v4l2_video_dec_get_right_frame_for_frame_mode(GstAmlVideoDecoder *decoder, GstClockTime pts) |
fei.deng | bee2086 | 2022-06-14 14:59:48 +0800 | [diff] [blame] | 688 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 689 | GstAmlVideoCodecFrame *frame = NULL; |
| 690 | GList *frames, *l; |
| 691 | gint count = 0; |
fei.deng | bee2086 | 2022-06-14 14:59:48 +0800 | [diff] [blame] | 692 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 693 | GST_LOG_OBJECT (decoder, "trace in with pts: %" GST_TIME_FORMAT, GST_TIME_ARGS(pts)); |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 694 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 695 | frames = gst_aml_video_decoder_get_frames(decoder); |
fei.deng | bee2086 | 2022-06-14 14:59:48 +0800 | [diff] [blame] | 696 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 697 | for (l = frames; l != NULL; l = l->next) |
| 698 | { |
| 699 | GstAmlVideoCodecFrame *f = l->data; |
fei.deng | e945847 | 2023-04-18 02:05:48 +0000 | [diff] [blame] | 700 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 701 | if (GST_CLOCK_TIME_IS_VALID(pts) && (ABSDIFF(f->pts,pts)) < 1000) { |
| 702 | frame = f; |
| 703 | } |
| 704 | count++; |
| 705 | } |
fei.deng | bee2086 | 2022-06-14 14:59:48 +0800 | [diff] [blame] | 706 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 707 | if (!frame) |
| 708 | { |
| 709 | for (l = frames; l != NULL; l = l->next) |
| 710 | { |
| 711 | GstAmlVideoCodecFrame *f = l->data; |
| 712 | if (!GST_CLOCK_TIME_IS_VALID(f->pts)) |
| 713 | { |
| 714 | frame = f; |
| 715 | GST_DEBUG("The pts of the expected output frame is invalid"); |
| 716 | break; |
| 717 | } |
| 718 | } |
| 719 | } |
zengliang.li | ddee2da | 2023-07-14 07:27:05 +0000 | [diff] [blame] | 720 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 721 | if (frame) |
| 722 | { |
| 723 | GST_LOG_OBJECT(decoder, |
| 724 | "frame %p is %d %" GST_TIME_FORMAT " and %d frames left", |
| 725 | frame, frame->system_frame_number, GST_TIME_ARGS(frame->pts), count - 1); |
| 726 | gst_aml_video_codec_frame_ref(frame); |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | GST_LOG_OBJECT(decoder, |
| 731 | "buffer %" GST_TIME_FORMAT " unmatch, create new frame", GST_TIME_ARGS(pts)); |
| 732 | frame = gst_aml_video_decoder_v4l2_new_frame (decoder); |
| 733 | } |
fei.deng | bee2086 | 2022-06-14 14:59:48 +0800 | [diff] [blame] | 734 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 735 | g_list_free_full(frames, (GDestroyNotify)gst_aml_video_codec_frame_unref); |
fei.deng | bee2086 | 2022-06-14 14:59:48 +0800 | [diff] [blame] | 736 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 737 | return frame; |
fei.deng | bee2086 | 2022-06-14 14:59:48 +0800 | [diff] [blame] | 738 | } |
| 739 | |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 740 | static GstAmlVideoCodecFrame * |
| 741 | gst_aml_v4l2_video_dec_get_right_frame_for_stream_mode(GstAmlVideoDecoder *decoder, GstClockTime pts) |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 742 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 743 | GstAmlVideoCodecFrame *frame = NULL; |
| 744 | GList *frames, *l; |
| 745 | guint frames_len = 0; |
| 746 | GST_LOG_OBJECT (decoder, "trace in with pts: %" GST_TIME_FORMAT, GST_TIME_ARGS(pts)); |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 747 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 748 | if (!(frames = gst_aml_video_decoder_get_frames(decoder))) |
| 749 | goto done; |
hanghang.luo | 4486d7d | 2024-07-24 10:06:35 +0800 | [diff] [blame] | 750 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 751 | frames_len = g_list_length(frames); |
| 752 | GST_LOG_OBJECT (decoder, "got frames list len:%d", frames_len); |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 753 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 754 | for (l = frames; l != NULL; l = l->next) |
| 755 | { |
| 756 | GstAmlVideoCodecFrame *f = l->data; |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 757 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 758 | if (GST_CLOCK_TIME_IS_VALID(pts) && (ABSDIFF(f->pts, pts)) < 1000) |
| 759 | { |
| 760 | /* found the right frame */ |
| 761 | GST_LOG_OBJECT(decoder, |
| 762 | "found frame %" GST_TIME_FORMAT "with pts %" GST_TIME_FORMAT, |
| 763 | GST_TIME_ARGS(f->pts), GST_TIME_ARGS(pts)); |
| 764 | frame = f; |
| 765 | break; |
| 766 | } |
| 767 | else if(GST_CLOCK_TIME_IS_VALID(pts) && (f->pts < pts)) |
| 768 | { |
| 769 | GST_LOG_OBJECT(decoder, |
| 770 | "stream mode drop frame %d %" GST_TIME_FORMAT, |
| 771 | f->system_frame_number, GST_TIME_ARGS(f->pts)); |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 772 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 773 | gst_aml_video_codec_frame_ref(f); |
| 774 | // gst_aml_video_decoder_drop_frame(decoder, f); |
| 775 | gst_aml_video_decoder_release_frame(decoder, f); |
| 776 | } |
| 777 | else |
| 778 | { |
| 779 | GST_LOG_OBJECT (decoder, "dbg"); |
| 780 | } |
| 781 | } |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 782 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 783 | if (frame) |
| 784 | { |
| 785 | guint l_len = 0; |
| 786 | l = gst_aml_video_decoder_get_frames(decoder); |
| 787 | l_len = g_list_length(l); |
| 788 | g_list_free_full(l, (GDestroyNotify)gst_aml_video_codec_frame_unref); |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 789 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 790 | GST_LOG_OBJECT(decoder, |
| 791 | "frame %p is %d %" GST_TIME_FORMAT " and %d frames left", |
| 792 | frame, frame->system_frame_number, GST_TIME_ARGS(frame->pts), l_len); |
| 793 | gst_aml_video_codec_frame_ref(frame); |
| 794 | } |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 795 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 796 | g_list_free_full(frames, (GDestroyNotify)gst_aml_video_codec_frame_unref); |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 797 | |
hanghang.luo | 4486d7d | 2024-07-24 10:06:35 +0800 | [diff] [blame] | 798 | done: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 799 | return frame; |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 800 | } |
| 801 | |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 802 | static GstAmlVideoCodecFrame * |
| 803 | gst_aml_v4l2_video_dec_get_right_frame(GstAmlVideoDecoder *decoder, GstClockTime pts) |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 804 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 805 | GstAmlV4l2VideoDec *self = (GstAmlV4l2VideoDec *)decoder; |
| 806 | if (self->v4l2output->stream_mode) |
| 807 | return gst_aml_v4l2_video_dec_get_right_frame_for_stream_mode(decoder, pts); |
| 808 | else |
| 809 | return gst_aml_v4l2_video_dec_get_right_frame_for_frame_mode(decoder, pts); |
xuesong.jiang | e24aef9 | 2023-06-16 06:39:10 +0000 | [diff] [blame] | 810 | } |
| 811 | |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 812 | static gboolean |
| 813 | gst_aml_v4l2_video_remove_padding(GstCapsFeatures *features, |
| 814 | GstStructure *structure, gpointer user_data) |
| 815 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 816 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(user_data); |
| 817 | GstVideoAlignment *align = &self->v4l2capture->align; |
| 818 | GstVideoInfo *info = &self->v4l2capture->info; |
| 819 | int width, height; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 820 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 821 | if (!gst_structure_get_int(structure, "width", &width)) |
| 822 | return TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 823 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 824 | if (!gst_structure_get_int(structure, "height", &height)) |
| 825 | return TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 826 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 827 | if (align->padding_left != 0 || align->padding_top != 0 || |
| 828 | height != info->height + align->padding_bottom) |
| 829 | return TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 830 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 831 | if (height == info->height + align->padding_bottom) |
| 832 | { |
| 833 | /* Some drivers may round up width to the padded with */ |
| 834 | if (width == info->width + align->padding_right) |
| 835 | gst_structure_set(structure, |
| 836 | "width", G_TYPE_INT, width - align->padding_right, |
| 837 | "height", G_TYPE_INT, height - align->padding_bottom, NULL); |
| 838 | /* Some drivers may keep visible width and only round up bytesperline */ |
| 839 | else if (width == info->width) |
| 840 | gst_structure_set(structure, |
| 841 | "height", G_TYPE_INT, height - align->padding_bottom, NULL); |
| 842 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 843 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 844 | return TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | static void |
sheng.liu | bcf036c | 2022-06-21 15:55:42 +0800 | [diff] [blame] | 848 | gst_v4l2_drop_event (GstAmlV4l2Object * v4l2object) |
sheng.liu | b56bbc5 | 2022-06-21 11:02:33 +0800 | [diff] [blame] | 849 | { |
| 850 | struct v4l2_event evt; |
| 851 | gint ret; |
| 852 | |
| 853 | memset (&evt, 0x00, sizeof (struct v4l2_event)); |
| 854 | ret = v4l2object->ioctl (v4l2object->video_fd, VIDIOC_DQEVENT, &evt); |
| 855 | if (ret < 0) |
| 856 | { |
| 857 | GST_DEBUG_OBJECT (v4l2object, "dqevent failed"); |
| 858 | return; |
| 859 | } |
| 860 | |
| 861 | switch (evt.type) |
| 862 | { |
| 863 | case V4L2_EVENT_SOURCE_CHANGE: |
| 864 | GST_DEBUG_OBJECT (v4l2object, "Drop GST_V4L2_FLOW_SOURCE_CHANGE"); |
| 865 | break; |
| 866 | case V4L2_EVENT_EOS: |
| 867 | GST_DEBUG_OBJECT (v4l2object, "Drop GST_V4L2_FLOW_LAST_BUFFER"); |
| 868 | break; |
| 869 | default: |
| 870 | break; |
| 871 | } |
| 872 | |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | static void |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 877 | gst_aml_v4l2_video_dec_set_output_status(GstAmlVideoDecoder *decoder,GstVideoInfo info) |
hanghang.luo | 2eec489 | 2023-07-18 06:44:42 +0000 | [diff] [blame] | 878 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 879 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 880 | GstAmlVideoCodecState *output_state; |
| 881 | struct v4l2_selection sel; |
| 882 | struct v4l2_rect *r = NULL; |
| 883 | GstStructure *s; |
| 884 | gint width = 0; |
| 885 | gint height = 0; |
| 886 | GST_DEBUG("%d %d",info.width, info.height); |
| 887 | output_state = gst_aml_video_decoder_set_output_state(decoder, |
| 888 | info.finfo->format, info.width, info.height, self->input_state); |
| 889 | memset(&sel, 0, sizeof(struct v4l2_selection)); |
| 890 | sel.type = self->v4l2capture->type; |
| 891 | sel.target = V4L2_SEL_TGT_COMPOSE_DEFAULT; |
| 892 | if (self->v4l2capture->ioctl(self->v4l2capture->video_fd, VIDIOC_G_SELECTION, &sel) >= 0) |
| 893 | { |
| 894 | r = &sel.r; |
| 895 | width = (r->width/2)*2; |
| 896 | height = (r->height/2)*2; |
| 897 | GST_DEBUG_OBJECT(self, "w:%d h:%d ",width,height); |
| 898 | } |
| 899 | else |
| 900 | GST_DEBUG_OBJECT(self, "iotcl error"); |
| 901 | if (output_state) |
| 902 | { |
| 903 | output_state->info.interlace_mode = info.interlace_mode; |
| 904 | output_state->allocation_caps =gst_video_info_to_caps(&info); |
| 905 | output_state->caps =gst_video_info_to_caps(&info); |
| 906 | s = gst_caps_get_structure(output_state->caps, 0); |
| 907 | if (s) |
hanghang.luo | 9b60a3c | 2023-08-01 16:01:47 +0000 | [diff] [blame] | 908 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 909 | gst_structure_set(s,"src_width",G_TYPE_INT,width,NULL); |
| 910 | gst_structure_set(s,"src_height",G_TYPE_INT,height,NULL); |
| 911 | gst_structure_set(s,"width",G_TYPE_INT,info.width,NULL); |
| 912 | gst_structure_set(s,"height",G_TYPE_INT,info.height,NULL); |
| 913 | GST_DEBUG_OBJECT(self, "output_state->caps: %" GST_PTR_FORMAT, output_state->caps); |
| 914 | gst_aml_video_codec_state_unref(output_state); |
hanghang.luo | 9b60a3c | 2023-08-01 16:01:47 +0000 | [diff] [blame] | 915 | } |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 916 | } |
hanghang.luo | 2eec489 | 2023-07-18 06:44:42 +0000 | [diff] [blame] | 917 | } |
| 918 | |
zengliang.li | dcd4146 | 2024-06-19 16:05:12 +0800 | [diff] [blame] | 919 | static GQuark |
| 920 | gst_aml_v4l2_buffer_pool_cc_import_quark (void) |
| 921 | { |
| 922 | static GQuark quark = 0; |
| 923 | |
| 924 | if (quark == 0) |
| 925 | quark = g_quark_from_string ("GstAmlV4l2BufferPoolCcUsePtrData"); |
| 926 | |
| 927 | return quark; |
| 928 | } |
| 929 | |
| 930 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 931 | foreach_cc_buffer_list_match_pts_func(GList *list , GstAmlVideoCodecFrame *frame) |
zengliang.li | dcd4146 | 2024-06-19 16:05:12 +0800 | [diff] [blame] | 932 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 933 | GList *l; |
| 934 | if (g_list_length (list) > 0) |
| 935 | { |
| 936 | for (l = list; l != NULL; l = l->next) |
zengliang.li | dcd4146 | 2024-06-19 16:05:12 +0800 | [diff] [blame] | 937 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 938 | GstBuffer *cc_buffer = l->data; |
| 939 | if (GST_BUFFER_TIMESTAMP (frame->output_buffer) == GST_BUFFER_TIMESTAMP (cc_buffer)) |
| 940 | { |
| 941 | gst_mini_object_set_qdata (GST_MINI_OBJECT (frame->output_buffer), GST_AML_V4L2_CC_IMPORT_QUARK, |
| 942 | gst_buffer_ref(cc_buffer), (GDestroyNotify) gst_buffer_unref); |
| 943 | #if 0 |
| 944 | //Debug code:dump cc data |
| 945 | GstMapInfo gst_map; |
| 946 | gst_buffer_map(cc_buffer,&gst_map,GST_MAP_READ); |
| 947 | int fd=open("/data/test/cc1.data",O_RDWR |O_CREAT|O_APPEND,0777); |
| 948 | if (gst_map.size>0) |
| 949 | write(fd,gst_map.data,gst_map.size); |
| 950 | close(fd); |
| 951 | gst_buffer_unmap(cc_buffer,&gst_map); |
| 952 | #endif |
| 953 | GST_DEBUG("match success"); |
| 954 | return TRUE; |
| 955 | } |
| 956 | else |
| 957 | { |
| 958 | GST_DEBUG("match fail"); |
| 959 | } |
zengliang.li | dcd4146 | 2024-06-19 16:05:12 +0800 | [diff] [blame] | 960 | } |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 961 | GST_WARNING("no match frame in the bufferlist"); |
| 962 | } |
| 963 | else |
| 964 | { |
| 965 | GST_WARNING("list is null,can not foreach"); |
| 966 | } |
| 967 | return FALSE; |
zengliang.li | dcd4146 | 2024-06-19 16:05:12 +0800 | [diff] [blame] | 968 | } |
| 969 | |
bo.xiao | 8e3054d | 2024-07-31 17:13:57 +0800 | [diff] [blame] | 970 | static GstClockTime |
le.han | 44125c3 | 2024-09-03 07:55:57 +0000 | [diff] [blame] | 971 | gst_aml_v4l2_video_dec_calc_output_buffer_pts(GstAmlVideoDecoder *decoder) |
bo.xiao | 8e3054d | 2024-07-31 17:13:57 +0800 | [diff] [blame] | 972 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 973 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 974 | GstClockTime pts = GST_CLOCK_TIME_NONE; |
bo.xiao | 8e3054d | 2024-07-31 17:13:57 +0800 | [diff] [blame] | 975 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 976 | if (GST_CLOCK_TIME_IS_VALID (self->last_out_pts) && GST_CLOCK_TIME_IS_VALID(self->frame_duration)) { |
| 977 | pts = self->last_out_pts + self->frame_duration; |
| 978 | GST_LOG_OBJECT (decoder, |
| 979 | "calculate PTS %" GST_TIME_FORMAT " by duration: %" GST_TIME_FORMAT, |
| 980 | GST_TIME_ARGS (pts), GST_TIME_ARGS (self->frame_duration)); |
| 981 | } |
| 982 | else |
| 983 | { |
| 984 | pts = 0; |
| 985 | GST_INFO_OBJECT (decoder,"Set PTS=0"); |
| 986 | } |
| 987 | return pts; |
bo.xiao | 8e3054d | 2024-07-31 17:13:57 +0800 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | static GstClockTime |
le.han | 44125c3 | 2024-09-03 07:55:57 +0000 | [diff] [blame] | 991 | gst_aml_v4l2_video_dec_calc_duration(GstAmlVideoDecoder *decoder) |
bo.xiao | 8e3054d | 2024-07-31 17:13:57 +0800 | [diff] [blame] | 992 | { |
| 993 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 994 | GstClockTime duration = GST_CLOCK_TIME_NONE; |
| 995 | gint fps_n, fps_d; |
| 996 | fps_n = gst_value_get_fraction_numerator(self->v4l2capture->fps); |
| 997 | fps_d = gst_value_get_fraction_denominator(self->v4l2capture->fps); |
| 998 | |
| 999 | if (fps_n != 0 && fps_d != 0) |
| 1000 | { |
| 1001 | duration = gst_util_uint64_scale (GST_SECOND, fps_d, fps_n); |
| 1002 | |
| 1003 | if (self->v4l2capture->info.interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED) |
| 1004 | { |
| 1005 | duration = duration / 2; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | GST_INFO_OBJECT (decoder,"framerate(fps_d: %d, fps_n: %d) -> frame_duration = %" GST_TIME_FORMAT, fps_d, fps_n, GST_TIME_ARGS(duration)); |
| 1010 | |
| 1011 | return duration; |
| 1012 | } |
| 1013 | |
hanghang.luo | 2eec489 | 2023-07-18 06:44:42 +0000 | [diff] [blame] | 1014 | static void |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 1015 | gst_aml_v4l2_video_dec_loop(GstAmlVideoDecoder *decoder) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1016 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1017 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 1018 | GstAmlV4l2BufferPool *v4l2_pool; |
| 1019 | GstAmlV4l2Error error = GST_AML_V4L2_ERROR_INIT; |
| 1020 | GstBufferPool *pool; |
| 1021 | GstAmlVideoCodecFrame *frame; |
| 1022 | GstBuffer *buffer = NULL; |
| 1023 | GstFlowReturn ret; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1024 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1025 | if (G_UNLIKELY (!GST_AML_V4L2_IS_ACTIVE (self->v4l2capture))) |
| 1026 | { |
| 1027 | GstVideoInfo info; |
| 1028 | GstCaps *acquired_caps, *available_caps, *caps, *filter; |
| 1029 | GstStructure *st; |
| 1030 | GST_DEBUG_OBJECT(self, "waitting source change event"); |
| 1031 | /* Wait until received SOURCE_CHANGE event to get right video format */ |
| 1032 | while (self->v4l2capture->can_wait_event && self->v4l2capture->need_wait_event) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1033 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1034 | ret = gst_aml_v4l2_object_dqevent (self->v4l2capture); |
| 1035 | if (ret == GST_AML_V4L2_FLOW_SOURCE_CHANGE) |
| 1036 | { |
| 1037 | //let flush start event blocked until capture buffer pool actived |
| 1038 | self->is_res_chg = TRUE; |
| 1039 | GST_DEBUG_OBJECT (self, "Received source change event"); |
| 1040 | break; |
| 1041 | } |
| 1042 | else if (ret == GST_AML_V4L2_FLOW_LAST_BUFFER) |
| 1043 | { |
| 1044 | GST_DEBUG_OBJECT (self, "Received eos event"); |
| 1045 | goto beach; |
| 1046 | } |
| 1047 | else if (ret != GST_FLOW_OK) |
| 1048 | { |
| 1049 | GST_ERROR_OBJECT (self, "dqevent error"); |
| 1050 | goto beach; |
| 1051 | } |
| 1052 | } |
| 1053 | self->v4l2capture->need_wait_event = FALSE; |
| 1054 | |
| 1055 | if (TRUE == self->v4l2output->is_svp) |
| 1056 | { |
| 1057 | GstPad *peer; |
| 1058 | GstStructure *s; |
| 1059 | GstEvent *event; |
| 1060 | |
| 1061 | peer = gst_pad_get_peer (decoder->srcpad); |
| 1062 | if (peer) |
| 1063 | { |
| 1064 | s = gst_structure_new_empty ("IS_SVP"); |
| 1065 | if (s) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1066 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1067 | event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s); |
| 1068 | gst_pad_send_event (peer, event); |
| 1069 | GST_DEBUG_OBJECT(self, "Send SVP Event"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1070 | } |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1071 | gst_object_unref (peer); |
| 1072 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1073 | } |
| 1074 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1075 | if (self->v4l2capture->need_drop_event) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1076 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1077 | // drop V4L2_EVENT_SOURCE_CHANGE |
| 1078 | gst_v4l2_drop_event(self->v4l2capture); |
| 1079 | self->v4l2capture->need_drop_event = FALSE; |
bo.xiao | 8e3054d | 2024-07-31 17:13:57 +0800 | [diff] [blame] | 1080 | } |
| 1081 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1082 | if (!gst_aml_v4l2_object_acquire_format (self->v4l2capture, &info)) |
| 1083 | goto not_negotiated; |
| 1084 | |
| 1085 | /* Create caps from the acquired format, remove the format field */ |
| 1086 | acquired_caps = gst_video_info_to_caps (&info); |
| 1087 | GST_DEBUG_OBJECT (self, "Acquired caps: %" GST_PTR_FORMAT, acquired_caps); |
| 1088 | st = gst_caps_get_structure (acquired_caps, 0); |
| 1089 | gst_structure_remove_fields (st, "format", "colorimetry", "chroma-site", NULL); |
| 1090 | |
| 1091 | /* Probe currently available pixel formats */ |
| 1092 | available_caps = gst_caps_copy (self->probed_srccaps); |
| 1093 | GST_DEBUG_OBJECT (self, "Available caps: %" GST_PTR_FORMAT, available_caps); |
| 1094 | |
| 1095 | /* Replace coded size with visible size, we want to negotiate visible size |
| 1096 | * with downstream, not coded size. */ |
| 1097 | gst_caps_map_in_place (available_caps, gst_aml_v4l2_video_remove_padding, self); |
| 1098 | |
| 1099 | filter = gst_caps_intersect_full (available_caps, acquired_caps, GST_CAPS_INTERSECT_FIRST); |
| 1100 | caps = gst_caps_copy(filter); |
| 1101 | gst_caps_set_features_simple(caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF)); |
| 1102 | gst_caps_append(filter, caps); |
| 1103 | |
| 1104 | GST_DEBUG_OBJECT (self, "Filtered caps: %" GST_PTR_FORMAT, filter); |
| 1105 | gst_caps_unref (acquired_caps); |
| 1106 | gst_caps_unref (available_caps); |
| 1107 | caps = gst_pad_peer_query_caps (decoder->srcpad, filter); |
| 1108 | gst_caps_unref (filter); |
| 1109 | |
| 1110 | GST_DEBUG_OBJECT (self, "Possible decoded caps: %" GST_PTR_FORMAT, caps); |
| 1111 | if (gst_caps_is_empty (caps)) |
bo.xiao | 8e3054d | 2024-07-31 17:13:57 +0800 | [diff] [blame] | 1112 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1113 | gst_caps_unref (caps); |
| 1114 | goto not_negotiated; |
bo.xiao | 8e3054d | 2024-07-31 17:13:57 +0800 | [diff] [blame] | 1115 | } |
| 1116 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1117 | /* Fixate pixel format */ |
| 1118 | caps = gst_caps_fixate (caps); |
bo.xiao | 8e3054d | 2024-07-31 17:13:57 +0800 | [diff] [blame] | 1119 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1120 | GST_DEBUG_OBJECT (self, "Chosen decoded caps: %" GST_PTR_FORMAT, caps); |
zengliang.li | dcd4146 | 2024-06-19 16:05:12 +0800 | [diff] [blame] | 1121 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1122 | /* Try to set negotiated format, on success replace acquired format */ |
| 1123 | if (gst_aml_v4l2_object_set_format (self->v4l2capture, caps, &error)) |
| 1124 | gst_video_info_from_caps (&info, caps); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1125 | else |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1126 | gst_aml_v4l2_clear_error (&error); |
| 1127 | gst_caps_unref (caps); |
| 1128 | gst_aml_v4l2_video_dec_set_output_status(decoder,info); |
| 1129 | if (!gst_aml_video_decoder_negotiate (decoder)) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1130 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1131 | if (GST_PAD_IS_FLUSHING (decoder->srcpad)) |
| 1132 | goto flushing; |
| 1133 | else |
| 1134 | goto not_negotiated; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1135 | } |
| 1136 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1137 | /* Ensure our internal pool is activated */ |
| 1138 | if (!gst_buffer_pool_set_active (GST_BUFFER_POOL (self->v4l2capture->pool), |
| 1139 | TRUE)) |
| 1140 | goto activate_failed; |
| 1141 | |
| 1142 | //cal duration when got resolution event |
| 1143 | self->frame_duration = gst_aml_v4l2_video_dec_calc_duration(decoder); |
| 1144 | |
| 1145 | g_mutex_lock(&self->res_chg_lock); |
| 1146 | GST_LOG_OBJECT(decoder, "signal resolution changed"); |
| 1147 | self->is_res_chg = FALSE; |
| 1148 | g_cond_signal(&self->res_chg_cond); |
| 1149 | g_mutex_unlock(&self->res_chg_lock); |
| 1150 | } |
| 1151 | |
| 1152 | GST_LOG_OBJECT (decoder, "Allocate output buffer"); |
| 1153 | v4l2_pool = GST_AML_V4L2_BUFFER_POOL(self->v4l2capture->pool); |
| 1154 | |
| 1155 | self->output_flow = GST_FLOW_OK; |
| 1156 | do |
| 1157 | { |
| 1158 | /* We cannot use the base class allotate helper since it taking the internal |
| 1159 | * stream lock. we know that the acquire may need to poll until more frames |
| 1160 | * comes in and holding this lock would prevent that. |
| 1161 | */ |
| 1162 | pool = gst_aml_video_decoder_get_buffer_pool (decoder); |
| 1163 | |
| 1164 | /* Pool may be NULL if we started going to READY state */ |
| 1165 | if (pool == NULL) |
| 1166 | { |
| 1167 | GST_WARNING_OBJECT(decoder, "gst_aml_video_decoder_get_buffer_pool goto beach"); |
| 1168 | ret = GST_FLOW_FLUSHING; |
| 1169 | goto beach; |
| 1170 | } |
| 1171 | |
| 1172 | ret = gst_buffer_pool_acquire_buffer (pool, &buffer, NULL); |
| 1173 | |
| 1174 | g_object_unref (pool); |
| 1175 | |
| 1176 | if (ret == GST_FLOW_OK && GST_BUFFER_FLAG_IS_SET(buffer,GST_AML_V4L2_BUFFER_FLAG_LAST_EMPTY)) { |
| 1177 | GST_LOG_OBJECT(decoder, "Get GST_AML_V4L2_FLOW_LAST_BUFFER"); |
| 1178 | self->v4l2capture->need_drop_event = TRUE; |
| 1179 | gst_aml_v4l2_buffer_pool_process(v4l2_pool, &buffer); |
| 1180 | if (self->is_res_chg) { |
| 1181 | //we must release last buffer |
| 1182 | gst_buffer_unref(buffer); |
| 1183 | //if resolution changed event received,we should set need_drop_event to false |
| 1184 | self->v4l2capture->need_drop_event = FALSE; |
| 1185 | gst_aml_v4l2_object_stop(self->v4l2capture); |
fei.deng | 2a06e04 | 2023-10-10 03:09:45 +0000 | [diff] [blame] | 1186 | //unblock flush start event |
| 1187 | g_mutex_lock(&self->res_chg_lock); |
| 1188 | self->is_res_chg = FALSE; |
| 1189 | g_cond_signal(&self->res_chg_cond); |
| 1190 | g_mutex_unlock(&self->res_chg_lock); |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1191 | return; |
| 1192 | } else { |
| 1193 | goto beach; |
| 1194 | } |
fei.deng | 2a06e04 | 2023-10-10 03:09:45 +0000 | [diff] [blame] | 1195 | } |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1196 | |
| 1197 | if (ret == GST_AML_V4L2_FLOW_CC_DATA) |
| 1198 | { |
| 1199 | GST_DEBUG_OBJECT(decoder, "already got cc data, just continue."); |
| 1200 | continue; |
| 1201 | } |
| 1202 | |
| 1203 | if (ret == GST_AML_V4L2_FLOW_UNKNOWN_EVENT) |
| 1204 | { |
| 1205 | GST_DEBUG_OBJECT(decoder, "unknow event, just continue."); |
| 1206 | continue; |
| 1207 | } |
| 1208 | |
| 1209 | if (ret == GST_AML_V4L2_FLOW_SOURCE_CHANGE) |
| 1210 | { |
| 1211 | GST_LOG_OBJECT(decoder, "Get GST_AML_V4L2_FLOW_SOURCE_CHANGE"); |
| 1212 | |
| 1213 | g_mutex_lock (&self->res_chg_lock); |
| 1214 | self->is_res_chg = TRUE; |
| 1215 | g_mutex_unlock (&self->res_chg_lock); |
| 1216 | return; |
| 1217 | } |
| 1218 | |
| 1219 | //decoding error happened |
| 1220 | if (ret == GST_AML_V4L2_FLOW_DECODING_ERROR) |
| 1221 | { |
| 1222 | GST_DEBUG("send error pts:%llu - %" GST_TIME_FORMAT, v4l2_pool->obj->error_frame_pts, GST_TIME_ARGS(v4l2_pool->obj->error_frame_pts)); |
| 1223 | g_signal_emit (self, g_signals[SIGNAL_DECODED_ERROR_PTS], 0, v4l2_pool->obj->error_frame_pts, NULL); |
| 1224 | g_signal_emit (self, g_signals[SIGNAL_DECODED_PTS], 0, v4l2_pool->obj->error_frame_pts); |
| 1225 | continue; |
| 1226 | } |
| 1227 | |
| 1228 | if (ret != GST_FLOW_OK) { |
| 1229 | GST_WARNING_OBJECT(decoder, "gst_buffer_pool_acquire_buffer goto beach ret:%d",ret); |
| 1230 | goto beach; |
| 1231 | } |
| 1232 | |
| 1233 | GST_LOG_OBJECT(decoder, "Process output buffer (switching flow outstanding num:%d)", self->v4l2capture->outstanding_buf_num); |
| 1234 | ret = gst_aml_v4l2_buffer_pool_process(v4l2_pool, &buffer); |
| 1235 | |
| 1236 | GST_DEBUG_OBJECT(decoder, "decoded pts:%lld - %" GST_TIME_FORMAT, GST_BUFFER_PTS(buffer), GST_TIME_ARGS(GST_BUFFER_PTS(buffer))); |
| 1237 | g_signal_emit (self, g_signals[SIGNAL_DECODED_PTS], 0, GST_BUFFER_PTS(buffer)); |
| 1238 | |
| 1239 | if (ret == GST_AML_V4L2_FLOW_SOURCE_CHANGE) |
| 1240 | { |
| 1241 | gst_aml_v4l2_object_stop (self->v4l2capture); |
| 1242 | return; |
| 1243 | } |
| 1244 | |
| 1245 | } while ((ret == GST_AML_V4L2_FLOW_CORRUPTED_BUFFER) || |
| 1246 | (ret == GST_AML_V4L2_FLOW_CC_DATA) || |
| 1247 | (ret == GST_AML_V4L2_FLOW_UNKNOWN_EVENT) || |
| 1248 | (ret == GST_AML_V4L2_FLOW_DECODING_ERROR)); |
| 1249 | |
| 1250 | if (ret != GST_FLOW_OK) |
| 1251 | goto beach; |
| 1252 | |
| 1253 | if (!GST_BUFFER_PTS_IS_VALID (buffer) |
| 1254 | || (GST_BUFFER_TIMESTAMP(buffer) == 0 && self->v4l2capture->info.interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED)) |
| 1255 | { |
| 1256 | GST_BUFFER_TIMESTAMP(buffer) = gst_aml_v4l2_video_dec_calc_output_buffer_pts(decoder); |
| 1257 | } |
| 1258 | |
| 1259 | if (self->v4l2capture->info.interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED) |
| 1260 | { |
| 1261 | GST_BUFFER_DURATION(buffer) = self->frame_duration; // got at resolution event. |
| 1262 | GST_BUFFER_FLAG_UNSET(buffer, GST_VIDEO_BUFFER_FLAG_INTERLACED); |
| 1263 | } |
| 1264 | |
| 1265 | frame = gst_aml_v4l2_video_dec_get_right_frame(decoder, GST_BUFFER_TIMESTAMP (buffer)); |
| 1266 | if (frame) |
| 1267 | { |
| 1268 | self->last_out_pts = GST_BUFFER_TIMESTAMP(buffer); |
| 1269 | frame->output_buffer = buffer; |
| 1270 | frame->pts = GST_BUFFER_TIMESTAMP(buffer); |
| 1271 | frame->duration = GST_BUFFER_DURATION(buffer); |
| 1272 | |
| 1273 | buffer = NULL; |
| 1274 | |
| 1275 | if (self->v4l2capture->enable_cc_data) |
| 1276 | { |
| 1277 | if (foreach_cc_buffer_list_match_pts_func(v4l2_pool->cc_buffer_list, frame)) |
| 1278 | { |
| 1279 | GST_DEBUG("cc buffer and frame bind success"); |
| 1280 | GstBuffer *cc_buffer = gst_mini_object_get_qdata (GST_MINI_OBJECT (frame->output_buffer), |
| 1281 | GST_AML_V4L2_CC_IMPORT_QUARK); |
| 1282 | #if 0 |
| 1283 | //Debug code:dump cc data |
| 1284 | GstMapInfo gst_map; |
| 1285 | gst_buffer_map(cc_buffer,&gst_map,GST_MAP_READ); |
| 1286 | int fd=open("/data/test/cc2.data",O_RDWR |O_CREAT|O_APPEND,0777); |
| 1287 | if (gst_map.size>0) |
| 1288 | write(fd,gst_map.data,gst_map.size); |
| 1289 | close(fd); |
| 1290 | gst_buffer_unmap(cc_buffer,&gst_map); |
| 1291 | #endif |
| 1292 | v4l2_pool->cc_buffer_list = g_list_remove(v4l2_pool->cc_buffer_list,cc_buffer); |
| 1293 | gst_buffer_unref(cc_buffer); |
| 1294 | } |
| 1295 | else |
| 1296 | { |
| 1297 | GST_WARNING("bufferlist is empty or no match frame in the bufferlist"); |
| 1298 | } |
| 1299 | } |
| 1300 | ret = gst_aml_video_decoder_finish_frame (decoder, frame); |
| 1301 | |
| 1302 | if (ret != GST_FLOW_OK) |
| 1303 | goto beach; |
| 1304 | } |
| 1305 | else |
| 1306 | { |
| 1307 | GST_WARNING_OBJECT(decoder, "Unmatch buffer, should be push, need refine"); |
| 1308 | //gst_pad_push (decoder->srcpad, buffer); |
| 1309 | gst_buffer_unref (buffer); |
| 1310 | } |
| 1311 | |
| 1312 | return; |
| 1313 | /* ERRORS */ |
| 1314 | not_negotiated: |
| 1315 | { |
| 1316 | GST_ERROR_OBJECT (self, "not negotiated"); |
| 1317 | ret = GST_FLOW_NOT_NEGOTIATED; |
| 1318 | goto beach; |
| 1319 | } |
| 1320 | activate_failed: |
| 1321 | { |
| 1322 | GST_ERROR_OBJECT (self, "Buffer pool activation failed"); |
| 1323 | GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS, |
| 1324 | (_("Failed to allocate required memory.")), |
| 1325 | ("Buffer pool activation failed")); |
| 1326 | ret = GST_FLOW_ERROR; |
| 1327 | goto beach; |
| 1328 | } |
| 1329 | flushing: |
| 1330 | { |
| 1331 | ret = GST_FLOW_FLUSHING; |
| 1332 | goto beach; |
| 1333 | } |
| 1334 | beach: |
| 1335 | GST_DEBUG_OBJECT (decoder, "Leaving output thread: %s", |
| 1336 | gst_flow_get_name (ret)); |
| 1337 | if (self->is_res_chg) { |
| 1338 | //unblock flush start event |
| 1339 | g_mutex_lock(&self->res_chg_lock); |
| 1340 | self->is_res_chg = FALSE; |
| 1341 | g_cond_signal(&self->res_chg_cond); |
| 1342 | g_mutex_unlock(&self->res_chg_lock); |
| 1343 | } |
| 1344 | gst_buffer_replace (&buffer, NULL); |
| 1345 | self->output_flow = ret; |
| 1346 | gst_aml_v4l2_object_flush_start (self->v4l2output); |
| 1347 | gst_pad_pause_task (decoder->srcpad); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | static GstFlowReturn |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1351 | gst_aml_v4l2_video_dec_handle_frame (GstAmlVideoDecoder * decoder, |
| 1352 | GstAmlVideoCodecFrame * frame) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1353 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1354 | GstAmlV4l2Error error = GST_AML_V4L2_ERROR_INIT; |
| 1355 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 1356 | GstBufferPool *pool = GST_BUFFER_POOL(self->v4l2output->pool); |
| 1357 | GstFlowReturn ret = GST_FLOW_OK; |
| 1358 | gboolean processed = FALSE; |
| 1359 | GstBuffer *tmp; |
| 1360 | GstTaskState task_state; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1361 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1362 | GST_DEBUG_OBJECT (self, "Handling frame %d", frame->system_frame_number); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1363 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1364 | if (G_UNLIKELY (!g_atomic_int_get (&self->active))) |
| 1365 | goto flushing; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1366 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1367 | if (G_UNLIKELY(!GST_CLOCK_TIME_IS_VALID(self->frame_duration))) |
| 1368 | self->frame_duration = frame->duration; |
le.han | 44125c3 | 2024-09-03 07:55:57 +0000 | [diff] [blame] | 1369 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1370 | if (G_UNLIKELY (!GST_AML_V4L2_IS_ACTIVE (self->v4l2output))) |
| 1371 | { |
| 1372 | if (!self->input_state) |
| 1373 | goto not_negotiated; |
| 1374 | if (!gst_aml_v4l2_object_set_format (self->v4l2output, self->input_state->caps, |
| 1375 | &error)) |
| 1376 | goto not_negotiated; |
| 1377 | } |
| 1378 | |
| 1379 | if (G_UNLIKELY (!GST_AML_V4L2_IS_ACTIVE (self->v4l2capture))) |
| 1380 | { |
| 1381 | GstBuffer *codec_data; |
| 1382 | GstCapsFeatures *features = NULL; |
| 1383 | |
| 1384 | features = gst_caps_get_features(self->input_state->caps, 0); |
| 1385 | if (features && gst_caps_features_contains(features, GST_CAPS_FEATURE_MEMORY_DMABUF) && self->v4l2output->secure_es) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1386 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1387 | GST_DEBUG_OBJECT(self, "Is SVP"); |
| 1388 | //TODO:need rm is_svp flag and just using secure_es flag |
| 1389 | self->v4l2output->is_svp = TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1390 | } |
| 1391 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1392 | GST_DEBUG_OBJECT (self, "Sending header"); |
| 1393 | |
| 1394 | codec_data = self->input_state->codec_data; |
| 1395 | |
| 1396 | /* We are running in byte-stream mode, so we don't know the headers, but |
| 1397 | * we need to send something, otherwise the decoder will refuse to |
| 1398 | * initialize. |
| 1399 | */ |
| 1400 | if (codec_data) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1401 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1402 | gst_buffer_ref (codec_data); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1403 | } |
| 1404 | else |
| 1405 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1406 | codec_data = gst_buffer_ref (frame->input_buffer); |
| 1407 | processed = TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1408 | } |
| 1409 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1410 | /* Ensure input internal pool is active */ |
| 1411 | if (!gst_buffer_pool_is_active (pool)) |
| 1412 | { |
| 1413 | GstStructure *config = gst_buffer_pool_get_config (pool); |
| 1414 | // guint min = MAX(self->v4l2output->min_buffers, GST_AML_V4L2_MIN_BUFFERS); |
| 1415 | // guint max = VIDEO_MAX_FRAME; |
| 1416 | // gst_buffer_pool_config_set_params (config, self->input_state->caps, |
| 1417 | // self->v4l2output->info.size, min, max); |
| 1418 | gst_buffer_pool_config_set_params(config, self->input_state->caps, self->v4l2output->info.size, self->v4l2output->min_buffers, self->v4l2output->min_buffers); |
| 1419 | |
| 1420 | /* There is no reason to refuse this config */ |
| 1421 | if (!gst_buffer_pool_set_config (pool, config)) |
| 1422 | goto activate_failed; |
| 1423 | GST_DEBUG_OBJECT(self, "setting output pool config to %" GST_PTR_FORMAT, config); |
| 1424 | |
| 1425 | if (!gst_buffer_pool_set_active (pool, TRUE)) |
| 1426 | goto activate_failed; |
| 1427 | } |
| 1428 | |
| 1429 | GST_AML_VIDEO_DECODER_STREAM_UNLOCK (decoder); |
| 1430 | ret = |
| 1431 | gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &codec_data); |
| 1432 | self->codec_data_inject = TRUE; |
| 1433 | GST_AML_VIDEO_DECODER_STREAM_LOCK (decoder); |
| 1434 | |
| 1435 | gst_buffer_unref (codec_data); |
| 1436 | |
| 1437 | /* For decoders G_FMT returns coded size, G_SELECTION returns visible size |
| 1438 | * in the compose rectangle. gst_aml_v4l2_object_acquire_format() checks both |
| 1439 | * and returns the visible size as with/height and the coded size as |
| 1440 | * padding. */ |
| 1441 | } |
| 1442 | |
| 1443 | task_state = gst_pad_get_task_state (GST_AML_VIDEO_DECODER_SRC_PAD (self)); |
| 1444 | if (task_state == GST_TASK_STOPPED || task_state == GST_TASK_PAUSED) |
| 1445 | { |
| 1446 | /* It's possible that the processing thread stopped due to an error */ |
| 1447 | if (self->output_flow != GST_FLOW_OK && |
| 1448 | self->output_flow != GST_FLOW_FLUSHING) |
| 1449 | { |
| 1450 | GST_DEBUG_OBJECT (self, "Processing loop stopped with error, leaving"); |
| 1451 | ret = self->output_flow; |
| 1452 | goto drop; |
| 1453 | } |
| 1454 | |
| 1455 | GST_DEBUG_OBJECT (self, "Starting decoding thread"); |
| 1456 | |
| 1457 | /* Start the processing task, when it quits, the task will disable input |
| 1458 | * processing to unlock input if draining, or prevent potential block */ |
| 1459 | self->output_flow = GST_FLOW_FLUSHING; |
| 1460 | /*reset poll and need_drop_event before start decoding loop thread*/ |
| 1461 | self->v4l2capture->need_drop_event = FALSE; |
| 1462 | gst_poll_set_flushing(self->v4l2capture->poll, FALSE); |
| 1463 | if (!gst_pad_start_task(decoder->srcpad, |
| 1464 | (GstTaskFunction) gst_aml_v4l2_video_dec_loop, self, NULL)) |
| 1465 | goto start_task_failed; |
| 1466 | } |
| 1467 | |
| 1468 | if (!processed) |
| 1469 | { |
| 1470 | GST_AML_VIDEO_DECODER_STREAM_UNLOCK (decoder); |
| 1471 | if (!self->codec_data_inject && self->input_state->codec_data) |
| 1472 | { |
| 1473 | ret = gst_aml_v4l2_buffer_pool_process |
| 1474 | (GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &self->input_state->codec_data); |
| 1475 | self->codec_data_inject = TRUE; |
| 1476 | if (ret != GST_FLOW_OK) |
| 1477 | goto send_codec_failed; |
| 1478 | } |
| 1479 | ret = |
| 1480 | gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &frame->input_buffer); |
| 1481 | GST_AML_VIDEO_DECODER_STREAM_LOCK (decoder); |
| 1482 | |
| 1483 | if (ret == GST_FLOW_FLUSHING) |
| 1484 | { |
| 1485 | if (gst_pad_get_task_state (GST_AML_VIDEO_DECODER_SRC_PAD (self)) != |
| 1486 | GST_TASK_STARTED) |
| 1487 | ret = self->output_flow; |
| 1488 | goto drop; |
| 1489 | } |
| 1490 | else if (ret != GST_FLOW_OK) |
| 1491 | { |
| 1492 | goto process_failed; |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | /* No need to keep input around */ |
| 1497 | tmp = frame->input_buffer; |
| 1498 | frame->input_buffer = gst_buffer_new (); |
| 1499 | gst_buffer_copy_into (frame->input_buffer, tmp, |
| 1500 | GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS | |
| 1501 | GST_BUFFER_COPY_META, 0, 0); |
| 1502 | gst_buffer_unref (tmp); |
| 1503 | |
| 1504 | gst_aml_video_codec_frame_unref (frame); |
| 1505 | return ret; |
| 1506 | |
| 1507 | /* ERRORS */ |
| 1508 | send_codec_failed: |
| 1509 | GST_ERROR_OBJECT(self, "send codec_date fialed.ret is %d",ret); |
| 1510 | goto drop; |
| 1511 | not_negotiated: |
| 1512 | { |
| 1513 | GST_ERROR_OBJECT (self, "not negotiated"); |
| 1514 | ret = GST_FLOW_NOT_NEGOTIATED; |
| 1515 | gst_aml_v4l2_error (self, &error); |
| 1516 | goto drop; |
| 1517 | } |
| 1518 | activate_failed: |
| 1519 | { |
| 1520 | GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS, |
| 1521 | (_("Failed to allocate required memory.")), |
| 1522 | ("Buffer pool activation failed")); |
| 1523 | ret = GST_FLOW_ERROR; |
| 1524 | goto drop; |
| 1525 | } |
| 1526 | flushing: |
| 1527 | { |
| 1528 | ret = GST_FLOW_FLUSHING; |
| 1529 | goto drop; |
| 1530 | } |
| 1531 | |
| 1532 | start_task_failed: |
| 1533 | { |
| 1534 | GST_ELEMENT_ERROR (self, RESOURCE, FAILED, |
| 1535 | (_("Failed to start decoding thread.")), (NULL)); |
| 1536 | ret = GST_FLOW_ERROR; |
| 1537 | goto drop; |
| 1538 | } |
| 1539 | process_failed: |
| 1540 | { |
| 1541 | GST_ELEMENT_ERROR (self, RESOURCE, FAILED, |
| 1542 | (_("Failed to process frame.")), |
| 1543 | ("Maybe be due to not enough memory or failing driver")); |
| 1544 | ret = GST_FLOW_ERROR; |
| 1545 | goto drop; |
| 1546 | } |
| 1547 | drop: |
| 1548 | { |
| 1549 | gst_aml_video_decoder_drop_frame (decoder, frame); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1550 | return ret; |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | static gboolean |
| 1555 | gst_aml_v4l2_video_dec_decide_allocation (GstAmlVideoDecoder * decoder, |
| 1556 | GstQuery * query) |
| 1557 | { |
| 1558 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC (decoder); |
| 1559 | GstClockTime latency; |
| 1560 | gboolean ret = FALSE; |
| 1561 | |
| 1562 | if (gst_aml_v4l2_object_decide_allocation (self->v4l2capture, query)) |
| 1563 | ret = GST_AML_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder, query); |
| 1564 | |
| 1565 | if (GST_CLOCK_TIME_IS_VALID (self->v4l2capture->duration)) |
| 1566 | { |
| 1567 | latency = self->v4l2capture->min_buffers * self->v4l2capture->duration; |
| 1568 | GST_DEBUG_OBJECT (self, "Setting latency: %" GST_TIME_FORMAT " (%" |
| 1569 | G_GUINT32_FORMAT " * %" G_GUINT64_FORMAT, GST_TIME_ARGS (latency), |
| 1570 | self->v4l2capture->min_buffers, self->v4l2capture->duration); |
| 1571 | gst_aml_video_decoder_set_latency (decoder, latency, latency); |
| 1572 | } |
| 1573 | else |
| 1574 | { |
| 1575 | GST_WARNING_OBJECT (self, "Duration invalid, not setting latency"); |
| 1576 | } |
| 1577 | |
| 1578 | return ret; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | static gboolean |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 1582 | gst_aml_v4l2_video_dec_src_query(GstAmlVideoDecoder *decoder, GstQuery *query) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1583 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1584 | gboolean ret = TRUE; |
| 1585 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC (decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1586 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1587 | switch (GST_QUERY_TYPE (query)) |
| 1588 | { |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1589 | case GST_QUERY_CAPS: |
| 1590 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1591 | GstCaps *filter, *result = NULL; |
| 1592 | GstPad *pad = GST_AML_VIDEO_DECODER_SRC_PAD (decoder); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1593 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1594 | gst_query_parse_caps (query, &filter); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1595 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1596 | if (self->probed_srccaps) |
| 1597 | result = gst_caps_ref (self->probed_srccaps); |
| 1598 | else |
| 1599 | result = gst_pad_get_pad_template_caps (pad); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1600 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1601 | if (filter) |
| 1602 | { |
| 1603 | GstCaps *tmp = result; |
| 1604 | result = |
| 1605 | gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST); |
| 1606 | gst_caps_unref (tmp); |
| 1607 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1608 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1609 | GST_DEBUG_OBJECT (self, "Returning src caps %" GST_PTR_FORMAT, result); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1610 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1611 | gst_query_set_caps_result (query, result); |
| 1612 | gst_caps_unref (result); |
| 1613 | break; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | default: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1617 | ret = GST_AML_VIDEO_DECODER_CLASS (parent_class)->src_query (decoder, query); |
| 1618 | break; |
| 1619 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1620 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1621 | return ret; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | static GstCaps * |
le.han | 02c38f0 | 2024-08-16 02:35:36 +0000 | [diff] [blame] | 1625 | gst_aml_v4l2_video_dec_sink_getcaps(GstAmlVideoDecoder *decoder, GstCaps *filter) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1626 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1627 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder); |
| 1628 | GstCaps *result; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1629 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1630 | result = gst_aml_video_decoder_proxy_getcaps (decoder, self->probed_sinkcaps, |
| 1631 | filter); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1632 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1633 | GST_DEBUG_OBJECT (self, "Returning sink caps %" GST_PTR_FORMAT, result); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1634 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1635 | return result; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | static gboolean |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1639 | gst_aml_v4l2_video_dec_sink_event (GstAmlVideoDecoder *decoder, GstEvent *event) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1640 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1641 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC (decoder); |
| 1642 | gboolean ret; |
| 1643 | GstEventType type = GST_EVENT_TYPE (event); |
| 1644 | GST_DEBUG_OBJECT (self, "received event %p %" GST_PTR_FORMAT, event, event); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1645 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1646 | switch (type) |
| 1647 | { |
xuesong.jiang | 406ee30 | 2023-06-28 03:45:22 +0000 | [diff] [blame] | 1648 | case GST_EVENT_STREAM_START: |
| 1649 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1650 | GstStructure *s; |
| 1651 | GstEvent *event; |
| 1652 | s = gst_structure_new("private_signal", "obj_ptr", G_TYPE_POINTER, self, "sig_name", G_TYPE_STRING, "decoded-pts", NULL); |
| 1653 | event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM, s); |
| 1654 | GST_DEBUG_OBJECT(self, "before Send private_signal Event :%p", event); |
| 1655 | gst_pad_push_event (decoder->sinkpad, event); |
| 1656 | GST_DEBUG_OBJECT(self, "after Send private_signal Event :%p", event); |
| 1657 | break; |
xuesong.jiang | 406ee30 | 2023-06-28 03:45:22 +0000 | [diff] [blame] | 1658 | } |
zengliang.li | 51f54b6 | 2023-10-10 12:14:49 +0000 | [diff] [blame] | 1659 | case GST_EVENT_CAPS: |
| 1660 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1661 | GstCaps *caps; |
| 1662 | GstStructure *structure; |
| 1663 | gint num, denom; |
zengliang.li | 51f54b6 | 2023-10-10 12:14:49 +0000 | [diff] [blame] | 1664 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1665 | gst_event_parse_caps (event, &caps); |
bo.xiao | 34e3620 | 2024-07-17 16:04:01 +0800 | [diff] [blame] | 1666 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1667 | structure= gst_caps_get_structure(caps, 0); |
| 1668 | if ( gst_structure_has_field(structure, "parsed") ) |
| 1669 | { |
| 1670 | gboolean parsed = TRUE; |
| 1671 | if ( gst_structure_get_boolean( structure, "parsed", &parsed ) ) |
zengliang.li | 51f54b6 | 2023-10-10 12:14:49 +0000 | [diff] [blame] | 1672 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1673 | self->v4l2output->stream_mode = !parsed; |
| 1674 | GST_DEBUG("frame parsed:%d, set stream_mode to %d", parsed, self->v4l2output->stream_mode); |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | if ( gst_structure_has_field(structure, "secure") ) |
| 1679 | { |
| 1680 | gboolean is_secure = FALSE; |
| 1681 | if ( gst_structure_get_boolean( structure, "secure", &is_secure ) ) |
| 1682 | { |
| 1683 | self->v4l2output->secure_es = is_secure; |
| 1684 | GST_DEBUG("is secure es:%d", self->v4l2output->secure_es); |
| 1685 | } |
| 1686 | } |
| 1687 | else |
| 1688 | { |
| 1689 | GstCapsFeatures *const features = gst_caps_get_features(caps, 0); |
| 1690 | if (features && gst_caps_features_contains(features, GST_CAPS_FEATURE_MEMORY_DMABUF)) |
| 1691 | { |
| 1692 | self->v4l2output->secure_es = TRUE; |
| 1693 | GST_DEBUG("If there is no secure field in caps, consider dma es is secure"); |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | if ( gst_structure_get_fraction( structure, "framerate", &num, &denom ) ) |
| 1698 | { |
| 1699 | if ( denom == 0 ) denom= 1; |
| 1700 | |
| 1701 | if (self->v4l2capture->fps) |
| 1702 | { |
| 1703 | g_value_unset(self->v4l2capture->fps); |
| 1704 | g_free(self->v4l2capture->fps); |
zengliang.li | 51f54b6 | 2023-10-10 12:14:49 +0000 | [diff] [blame] | 1705 | } |
sheng.liu | 641aa42 | 2023-12-26 07:05:59 +0000 | [diff] [blame] | 1706 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1707 | self->v4l2capture->fps = g_new0(GValue, 1); |
| 1708 | g_value_init(self->v4l2capture->fps, GST_TYPE_FRACTION); |
| 1709 | gst_value_set_fraction(self->v4l2capture->fps, num, denom); |
| 1710 | |
| 1711 | GST_DEBUG_OBJECT(self, "get framerate ratio %d:%d", num, denom); |
| 1712 | } |
| 1713 | |
| 1714 | if (( gst_structure_get_fraction( structure, "pixel-aspect-ratio", &num, &denom ) ) && |
| 1715 | ( !self->v4l2capture->have_set_par ) ) |
| 1716 | { |
| 1717 | if ( (num <= 0) || (denom <= 0) ) |
xuesong.jiang | 26749f3 | 2024-07-24 09:40:47 +0800 | [diff] [blame] | 1718 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1719 | num= denom= 1; |
xuesong.jiang | 578add2 | 2024-07-25 15:11:30 +0800 | [diff] [blame] | 1720 | } |
xuesong.jiang | 26749f3 | 2024-07-24 09:40:47 +0800 | [diff] [blame] | 1721 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1722 | if ( self->v4l2capture->par ) |
sheng.liu | db26f7d | 2024-01-22 11:24:23 +0000 | [diff] [blame] | 1723 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1724 | g_value_unset(self->v4l2capture->par); |
| 1725 | g_free(self->v4l2capture->par); |
sheng.liu | db26f7d | 2024-01-22 11:24:23 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1728 | self->v4l2capture->par = g_new0(GValue, 1); |
| 1729 | g_value_init(self->v4l2capture->par, GST_TYPE_FRACTION); |
| 1730 | gst_value_set_fraction(self->v4l2capture->par, num, denom); |
| 1731 | GST_DEBUG_OBJECT(self, "get pixel aspect ratio %d:%d", num, denom); |
| 1732 | } |
| 1733 | break; |
zengliang.li | 51f54b6 | 2023-10-10 12:14:49 +0000 | [diff] [blame] | 1734 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1735 | case GST_EVENT_FLUSH_START: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1736 | GST_DEBUG_OBJECT (self, "flush start"); |
xuesong.jiang | c5dac0f | 2023-02-01 14:42:24 +0800 | [diff] [blame] | 1737 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1738 | g_mutex_lock (&self->res_chg_lock); |
| 1739 | while (self->is_res_chg) |
| 1740 | { |
| 1741 | GST_LOG_OBJECT(decoder, "wait resolution change finish"); |
| 1742 | g_cond_wait(&self->res_chg_cond, &self->res_chg_lock); |
| 1743 | } |
| 1744 | g_mutex_unlock (&self->res_chg_lock); |
xuesong.jiang | c5dac0f | 2023-02-01 14:42:24 +0800 | [diff] [blame] | 1745 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1746 | self->last_out_pts = GST_CLOCK_TIME_NONE; |
| 1747 | gst_aml_v4l2_object_flush_start (self->v4l2output); |
| 1748 | gst_aml_v4l2_object_flush_start (self->v4l2capture); |
| 1749 | break; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1750 | default: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1751 | break; |
| 1752 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1753 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1754 | ret = GST_AML_VIDEO_DECODER_CLASS (parent_class)->sink_event (decoder, event); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1755 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1756 | switch (type) |
| 1757 | { |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1758 | case GST_EVENT_FLUSH_START: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1759 | /* The processing thread should stop now, wait for it */ |
| 1760 | gst_pad_stop_task (decoder->srcpad); |
| 1761 | self->codec_data_inject = FALSE; |
| 1762 | GST_DEBUG_OBJECT (self, "flush start done"); |
| 1763 | break; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1764 | default: |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1765 | break; |
| 1766 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1767 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1768 | return ret; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | static GstStateChangeReturn |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1772 | gst_aml_v4l2_video_dec_change_state (GstElement * element, |
| 1773 | GstStateChange transition) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1774 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1775 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(element); |
| 1776 | GstAmlVideoDecoder *decoder = GST_AML_VIDEO_DECODER(element); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1777 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1778 | GST_DEBUG_OBJECT(element, "change state from %s to %s", |
| 1779 | gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)), |
| 1780 | gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition))); |
bo.xiao | 8e3054d | 2024-07-31 17:13:57 +0800 | [diff] [blame] | 1781 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1782 | if (transition == GST_STATE_CHANGE_PAUSED_TO_READY) |
| 1783 | { |
| 1784 | g_atomic_int_set (&self->active, FALSE); |
| 1785 | gst_aml_v4l2_object_flush_start (self->v4l2output); |
| 1786 | gst_aml_v4l2_object_flush_start (self->v4l2capture); |
| 1787 | gst_pad_stop_task (decoder->srcpad); |
| 1788 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1789 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1790 | return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | static void |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1794 | gst_aml_v4l2_video_dec_dispose (GObject * object) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1795 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1796 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC (object); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1797 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1798 | gst_caps_replace (&self->probed_sinkcaps, NULL); |
| 1799 | gst_caps_replace (&self->probed_srccaps, NULL); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1800 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1801 | G_OBJECT_CLASS (parent_class)->dispose (object); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | static void |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1805 | gst_aml_v4l2_video_dec_finalize (GObject * object) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1806 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1807 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC (object); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1808 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1809 | gst_aml_v4l2_object_destroy (self->v4l2capture); |
| 1810 | gst_aml_v4l2_object_destroy (self->v4l2output); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1811 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1812 | g_mutex_clear(&self->res_chg_lock); |
| 1813 | g_cond_clear(&self->res_chg_cond); |
xuesong.jiang | c5dac0f | 2023-02-01 14:42:24 +0800 | [diff] [blame] | 1814 | |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 1815 | #if GST_IMPORT_LGE_PROP |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1816 | if (self->lge_ctxt) |
| 1817 | { |
| 1818 | if (self->lge_ctxt->app_type) |
| 1819 | g_free(self->lge_ctxt->app_type); |
| 1820 | if (self->lge_ctxt->res_info.coretype) |
| 1821 | g_free(self->lge_ctxt->res_info.coretype); |
| 1822 | free(self->lge_ctxt); |
| 1823 | } |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 1824 | |
| 1825 | #endif |
| 1826 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1827 | G_OBJECT_CLASS (parent_class)->finalize (object); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | static void |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1831 | gst_aml_v4l2_video_dec_init (GstAmlV4l2VideoDec * self) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1832 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1833 | /* V4L2 object are created in subinstance_init */ |
| 1834 | self->last_out_pts = GST_CLOCK_TIME_NONE; |
| 1835 | self->frame_duration = GST_CLOCK_TIME_NONE; |
| 1836 | self->is_secure_path = FALSE; |
| 1837 | self->is_res_chg = FALSE; |
| 1838 | self->codec_data_inject = FALSE; |
| 1839 | g_mutex_init(&self->res_chg_lock); |
| 1840 | g_cond_init(&self->res_chg_cond); |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 1841 | #if GST_IMPORT_LGE_PROP |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1842 | self->lge_ctxt = malloc(sizeof(GstAmlV4l2VideoDecLgeCtxt)); |
| 1843 | memset(self->lge_ctxt, 0, sizeof(GstAmlV4l2VideoDecLgeCtxt)); |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 1844 | #endif |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | static void |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1848 | gst_aml_v4l2_video_dec_subinstance_init (GTypeInstance * instance, gpointer g_class) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1849 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1850 | GstAmlV4l2VideoDecClass *klass = GST_AML_V4L2_VIDEO_DEC_CLASS (g_class); |
| 1851 | GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC (instance); |
| 1852 | GstAmlVideoDecoder *decoder = GST_AML_VIDEO_DECODER (instance); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1853 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1854 | gst_aml_video_decoder_set_packetized (decoder, TRUE); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1855 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1856 | self->v4l2output = gst_aml_v4l2_object_new (GST_ELEMENT (self), |
| 1857 | GST_OBJECT (GST_AML_VIDEO_DECODER_SINK_PAD (self)), |
| 1858 | V4L2_BUF_TYPE_VIDEO_OUTPUT, klass->default_device, |
| 1859 | gst_aml_v4l2_get_output, gst_aml_v4l2_set_output, NULL); |
| 1860 | self->v4l2output->no_initial_format = TRUE; |
| 1861 | self->v4l2output->keep_aspect = FALSE; |
| 1862 | self->v4l2output->is_svp = FALSE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1863 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1864 | self->v4l2capture = gst_aml_v4l2_object_new (GST_ELEMENT (self), |
| 1865 | GST_OBJECT (GST_AML_VIDEO_DECODER_SRC_PAD (self)), |
| 1866 | V4L2_BUF_TYPE_VIDEO_CAPTURE, klass->default_device, |
| 1867 | gst_aml_v4l2_get_input, gst_aml_v4l2_set_input, NULL); |
| 1868 | self->v4l2capture->need_wait_event = TRUE; |
| 1869 | self->v4l2capture->need_drop_event = FALSE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | static void |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1873 | gst_aml_v4l2_video_dec_class_init (GstAmlV4l2VideoDecClass * klass) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1874 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1875 | GstElementClass *element_class; |
| 1876 | GObjectClass *gobject_class; |
| 1877 | GstAmlVideoDecoderClass *video_decoder_class; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1878 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1879 | parent_class = g_type_class_peek_parent (klass); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1880 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1881 | element_class = (GstElementClass *) klass; |
| 1882 | gobject_class = (GObjectClass *) klass; |
| 1883 | video_decoder_class = (GstAmlVideoDecoderClass *) klass; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1884 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1885 | GST_DEBUG_CATEGORY_INIT (gst_aml_v4l2_video_dec_debug, "amlv4l2videodec", 0, |
| 1886 | "AML V4L2 Video Decoder"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1887 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1888 | gobject_class->dispose = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_dispose); |
| 1889 | gobject_class->finalize = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_finalize); |
| 1890 | gobject_class->set_property = |
| 1891 | GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_set_property); |
| 1892 | gobject_class->get_property = |
| 1893 | GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_get_property); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1894 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1895 | video_decoder_class->open = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_open); |
| 1896 | video_decoder_class->close = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_close); |
| 1897 | video_decoder_class->start = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_start); |
| 1898 | video_decoder_class->stop = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_stop); |
| 1899 | video_decoder_class->finish = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_finish); |
| 1900 | video_decoder_class->flush = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_flush); |
| 1901 | video_decoder_class->drain = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_drain); |
| 1902 | video_decoder_class->set_format = |
| 1903 | GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_set_format); |
| 1904 | video_decoder_class->negotiate = |
| 1905 | GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_negotiate); |
| 1906 | video_decoder_class->decide_allocation = |
| 1907 | GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_decide_allocation); |
| 1908 | /* FIXME propose_allocation or not ? */ |
| 1909 | video_decoder_class->handle_frame = |
| 1910 | GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_handle_frame); |
| 1911 | video_decoder_class->getcaps = |
| 1912 | GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_sink_getcaps); |
| 1913 | video_decoder_class->src_query = |
| 1914 | GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_src_query); |
| 1915 | video_decoder_class->sink_event = |
| 1916 | GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_sink_event); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1917 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1918 | element_class->change_state = |
| 1919 | GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_change_state); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1920 | |
xuesong.jiang | 406ee30 | 2023-06-28 03:45:22 +0000 | [diff] [blame] | 1921 | g_signals[SIGNAL_DECODED_PTS] = g_signal_new ("decoded-pts", |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1922 | G_TYPE_FROM_CLASS(GST_ELEMENT_CLASS(klass)), |
| 1923 | G_SIGNAL_RUN_LAST, |
| 1924 | 0, /* class offset */ |
| 1925 | NULL, /* accumulator */ |
| 1926 | NULL, /* accu data */ |
| 1927 | g_cclosure_marshal_generic, |
| 1928 | G_TYPE_NONE, |
| 1929 | 1, |
| 1930 | G_TYPE_UINT64); |
| 1931 | g_signals[SIGNAL_DECODED_ERROR_PTS] = g_signal_new ("decoded-error-pts", |
| 1932 | G_TYPE_FROM_CLASS(GST_ELEMENT_CLASS(klass)), |
| 1933 | G_SIGNAL_RUN_LAST, |
| 1934 | 0, /* class offset */ |
| 1935 | NULL, /* accumulator */ |
| 1936 | NULL, /* accu data */ |
| 1937 | g_cclosure_marshal_generic, |
| 1938 | G_TYPE_NONE, |
| 1939 | 1, |
| 1940 | G_TYPE_UINT64); |
xuesong.jiang | 406ee30 | 2023-06-28 03:45:22 +0000 | [diff] [blame] | 1941 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1942 | gst_aml_v4l2_object_install_m2m_properties_helper (gobject_class); |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 1943 | #if GST_IMPORT_LGE_PROP |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1944 | gst_aml_v4l2_video_dec_install_lge_properties_helper(gobject_class); |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 1945 | #endif |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | static void |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1949 | gst_aml_v4l2_video_dec_subclass_init (gpointer g_class, gpointer data) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1950 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1951 | GstAmlV4l2VideoDecClass *klass = GST_AML_V4L2_VIDEO_DEC_CLASS (g_class); |
| 1952 | GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); |
| 1953 | GstAmlV4l2VideoDecCData *cdata = data; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1954 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1955 | klass->default_device = cdata->device; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1956 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1957 | /* Note: gst_pad_template_new() take the floating ref from the caps */ |
| 1958 | gst_element_class_add_pad_template (element_class, |
| 1959 | gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, |
| 1960 | cdata->sink_caps)); |
| 1961 | gst_element_class_add_pad_template (element_class, |
| 1962 | gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, |
| 1963 | cdata->src_caps)); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1964 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1965 | gst_element_class_set_metadata (element_class, cdata->longname, |
| 1966 | "Codec/Decoder/Video/Hardware", cdata->description, |
| 1967 | "Xuesong Jiang <Xuesong.Jiang@amlogic.com>"); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1968 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1969 | gst_caps_unref (cdata->sink_caps); |
| 1970 | gst_caps_unref (cdata->src_caps); |
| 1971 | g_free (cdata); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | /* Probing functions */ |
| 1975 | gboolean |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1976 | gst_aml_v4l2_is_video_dec (GstCaps * sink_caps, GstCaps * src_caps) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1977 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1978 | gboolean ret = FALSE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1979 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1980 | if (gst_caps_is_subset (sink_caps, gst_aml_v4l2_object_get_codec_caps ()) |
| 1981 | && gst_caps_is_subset (src_caps, gst_aml_v4l2_object_get_raw_caps ())) |
| 1982 | ret = TRUE; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1983 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1984 | return ret; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | static gchar * |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1988 | gst_aml_v4l2_video_dec_set_metadata (GstStructure * s, GstAmlV4l2VideoDecCData * cdata, |
| 1989 | const gchar * basename) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1990 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1991 | gchar *codec_name = NULL; |
| 1992 | gchar *type_name = NULL; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 1993 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 1994 | #define SET_META(codec) \ |
| 1995 | G_STMT_START { \ |
| 1996 | cdata->longname = "AML V4L2 " codec " Decoder"; \ |
| 1997 | cdata->description = "Decodes " codec " streams via V4L2 API"; \ |
| 1998 | codec_name = g_ascii_strdown (codec, -1); \ |
| 1999 | } G_STMT_END |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 2000 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 2001 | if (gst_structure_has_name(s, "video/mjpeg")) |
| 2002 | { |
| 2003 | SET_META("MJPEG"); |
| 2004 | } |
| 2005 | else if (gst_structure_has_name (s, "video/mpeg")) |
| 2006 | { |
| 2007 | //include mpeg1, mpeg2, mpeg4 |
| 2008 | SET_META("MPEG4"); |
| 2009 | } |
| 2010 | else if (gst_structure_has_name (s, "video/x-h263")) |
| 2011 | { |
| 2012 | SET_META ("H263"); |
| 2013 | } |
| 2014 | else if (gst_structure_has_name (s, "video/x-fwht")) |
| 2015 | { |
| 2016 | SET_META ("FWHT"); |
| 2017 | } |
| 2018 | else if (gst_structure_has_name (s, "video/x-h264")) |
| 2019 | { |
| 2020 | SET_META ("H264"); |
| 2021 | } |
| 2022 | else if (gst_structure_has_name (s, "video/x-h265")) |
| 2023 | { |
| 2024 | SET_META ("H265"); |
| 2025 | } |
| 2026 | else if (gst_structure_has_name (s, "video/x-wmv")) |
| 2027 | { |
| 2028 | SET_META ("VC1"); |
| 2029 | } |
| 2030 | else if (gst_structure_has_name (s, "video/x-vp8")) |
| 2031 | { |
| 2032 | SET_META ("VP8"); |
| 2033 | } |
| 2034 | else if (gst_structure_has_name (s, "video/x-vp9")) |
| 2035 | { |
| 2036 | SET_META ("VP9"); |
| 2037 | } |
| 2038 | else if (gst_structure_has_name(s, "video/x-av1")) |
| 2039 | { |
| 2040 | SET_META("AV1"); |
| 2041 | } |
| 2042 | else if (gst_structure_has_name(s, "video/x-avs")) |
| 2043 | { |
| 2044 | SET_META("AVS"); |
| 2045 | } |
| 2046 | else if (gst_structure_has_name(s, "video/x-avs2")) |
| 2047 | { |
| 2048 | SET_META("AVS2"); |
| 2049 | } |
| 2050 | else if (gst_structure_has_name(s, "video/x-avs3")) |
| 2051 | { |
| 2052 | SET_META("AVS3"); |
| 2053 | } |
| 2054 | else if (gst_structure_has_name (s, "video/x-bayer")) |
| 2055 | { |
| 2056 | SET_META ("BAYER"); |
| 2057 | } |
| 2058 | else if (gst_structure_has_name (s, "video/x-sonix")) |
| 2059 | { |
| 2060 | SET_META ("SONIX"); |
| 2061 | } |
| 2062 | else if (gst_structure_has_name (s, "video/x-pwc1")) |
| 2063 | { |
| 2064 | SET_META ("PWC1"); |
| 2065 | } |
| 2066 | else if (gst_structure_has_name (s, "video/x-pwc2")) |
| 2067 | { |
| 2068 | SET_META ("PWC2"); |
| 2069 | } |
| 2070 | else |
| 2071 | { |
| 2072 | /* This code should be kept on sync with the exposed CODEC type of format |
| 2073 | * from gstamlv4l2object.c. This warning will only occur in case we forget |
| 2074 | * to also add a format here. */ |
| 2075 | gchar *s_str = gst_structure_to_string (s); |
| 2076 | g_warning ("Missing fixed name mapping for caps '%s', this is a GStreamer " |
| 2077 | "bug, please report at https://bugs.gnome.org", s_str); |
| 2078 | g_free (s_str); |
| 2079 | } |
| 2080 | |
| 2081 | if (codec_name) |
| 2082 | { |
| 2083 | type_name = g_strdup_printf ("amlv4l2%sdec", codec_name); |
| 2084 | if (g_type_from_name (type_name) != 0) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 2085 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 2086 | g_free (type_name); |
| 2087 | type_name = g_strdup_printf ("amlv4l2%s%sdec", basename, codec_name); |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 2088 | } |
| 2089 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 2090 | g_free (codec_name); |
| 2091 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 2092 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 2093 | return type_name; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 2094 | #undef SET_META |
| 2095 | } |
| 2096 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 2097 | void |
| 2098 | gst_aml_v4l2_video_dec_register(GstPlugin *plugin, const gchar *basename, |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 2099 | const gchar *device_path, GstCaps *sink_caps, GstCaps *src_caps) |
| 2100 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 2101 | gint i; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 2102 | |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 2103 | for (i = 0; i < gst_caps_get_size (sink_caps); i++) |
| 2104 | { |
| 2105 | GstAmlV4l2VideoDecCData *cdata; |
| 2106 | GstStructure *s; |
| 2107 | GTypeQuery type_query; |
| 2108 | GTypeInfo type_info = { 0, }; |
| 2109 | GType type, subtype; |
| 2110 | gchar *type_name; |
| 2111 | |
| 2112 | s = gst_caps_get_structure (sink_caps, i); |
| 2113 | |
| 2114 | cdata = g_new0 (GstAmlV4l2VideoDecCData, 1); |
| 2115 | cdata->device = g_strdup (device_path); |
| 2116 | cdata->sink_caps = gst_caps_new_empty (); |
| 2117 | gst_caps_append_structure (cdata->sink_caps, gst_structure_copy (s)); |
| 2118 | gst_caps_append_structure (cdata->sink_caps, gst_structure_copy (s)); |
| 2119 | gst_caps_set_features(cdata->sink_caps, 0, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF)); |
| 2120 | cdata->src_caps = gst_caps_copy(src_caps); |
| 2121 | gst_caps_set_features_simple(cdata->src_caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF)); |
| 2122 | gst_caps_append(cdata->src_caps, gst_caps_copy (src_caps)); |
| 2123 | type_name = gst_aml_v4l2_video_dec_set_metadata (s, cdata, basename); |
| 2124 | |
| 2125 | /* Skip over if we hit an unmapped type */ |
| 2126 | if (!type_name) |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 2127 | { |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 2128 | g_free (cdata); |
| 2129 | continue; |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 2130 | } |
bo.xiao | 857b868 | 2024-09-12 16:40:32 +0800 | [diff] [blame^] | 2131 | |
| 2132 | type = gst_aml_v4l2_video_dec_get_type (); |
| 2133 | g_type_query (type, &type_query); |
| 2134 | memset (&type_info, 0, sizeof (type_info)); |
| 2135 | type_info.class_size = type_query.class_size; |
| 2136 | type_info.instance_size = type_query.instance_size; |
| 2137 | type_info.class_init = gst_aml_v4l2_video_dec_subclass_init; |
| 2138 | type_info.class_data = cdata; |
| 2139 | type_info.instance_init = gst_aml_v4l2_video_dec_subinstance_init; |
| 2140 | |
| 2141 | subtype = g_type_register_static (type, type_name, &type_info, 0); |
| 2142 | if (!gst_element_register (plugin, type_name, GST_RANK_PRIMARY + 1, |
| 2143 | subtype)) |
| 2144 | GST_WARNING ("Failed to register plugin '%s'", type_name); |
| 2145 | |
| 2146 | g_free (type_name); |
| 2147 | } |
xuesong.jiang | ae1548e | 2022-05-06 16:38:46 +0800 | [diff] [blame] | 2148 | } |
xuesong.jiang | 61ea801 | 2022-05-12 15:38:17 +0800 | [diff] [blame] | 2149 | |
| 2150 | #if GST_IMPORT_LGE_PROP |
| 2151 | static void gst_aml_v4l2_video_dec_install_lge_properties_helper(GObjectClass *gobject_class) |
| 2152 | { |
| 2153 | g_object_class_install_property(gobject_class, LGE_RESOURCE_INFO, |
| 2154 | g_param_spec_object("resource-info", "resource-info", |
| 2155 | "After acquisition of H/W resources is completed, allocated resource information must be delivered to the decoder and the sink", |
| 2156 | GST_TYPE_STRUCTURE, |
| 2157 | G_PARAM_READABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); |
| 2158 | |
| 2159 | g_object_class_install_property(gobject_class, LGE_DECODE_SIZE, |
| 2160 | g_param_spec_uint64("decoded-size", "decoded-size", |
| 2161 | "The total amount of decoder element's decoded video es after constructing pipeline or flushing pipeline update unit is byte.", |
| 2162 | 0, G_MAXUINT64, |
| 2163 | 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 2164 | |
| 2165 | g_object_class_install_property(gobject_class, LGE_UNDECODE_SIZE, |
| 2166 | g_param_spec_uint64("undecoded-size", "undecoded-size", |
| 2167 | "video decoder element's total undecoded data update unit is byte.", |
| 2168 | 0, G_MAXUINT64, |
| 2169 | 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 2170 | |
| 2171 | g_object_class_install_property(gobject_class, LGE_APP_TYPE, |
| 2172 | g_param_spec_string("app-type", "app-type", |
| 2173 | "set application type.", |
| 2174 | "default_app", |
| 2175 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 2176 | |
| 2177 | g_object_class_install_property(gobject_class, LGE_CLIP_MODE, |
| 2178 | g_param_spec_boolean("clip-mode", "clip-mode", |
| 2179 | "When seeking, Content is moving faster for a while to skip frames.", |
| 2180 | FALSE, |
| 2181 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
| 2182 | } |
| 2183 | #endif |