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