blob: 8a79d2e90ce2d3d6447834108572fc1f434e32ca [file] [log] [blame]
xuesong.jiangae1548e2022-05-06 16:38:46 +08001/* 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
37GST_DEBUG_CATEGORY_STATIC(gst_aml_v4l2_video_dec_debug);
38#define GST_CAT_DEFAULT gst_aml_v4l2_video_dec_debug
39
40#ifdef GST_VIDEO_DECODER_STREAM_LOCK
41#undef GST_VIDEO_DECODER_STREAM_LOCK
42#define GST_VIDEO_DECODER_STREAM_LOCK(decoder) \
43 { \
fei.denge9458472023-04-18 02:05:48 +000044 GST_TRACE("aml v4l2 dec locking"); \
xuesong.jiangae1548e2022-05-06 16:38:46 +080045 g_rec_mutex_lock(&GST_VIDEO_DECODER(decoder)->stream_lock); \
fei.denge9458472023-04-18 02:05:48 +000046 GST_TRACE("aml v4l2 dec locked"); \
xuesong.jiangae1548e2022-05-06 16:38:46 +080047 }
48#endif
49
50#ifdef GST_VIDEO_DECODER_STREAM_UNLOCK
51#undef GST_VIDEO_DECODER_STREAM_UNLOCK
52#define GST_VIDEO_DECODER_STREAM_UNLOCK(decoder) \
53 { \
fei.denge9458472023-04-18 02:05:48 +000054 GST_TRACE("aml v4l2 dec unlocking"); \
xuesong.jiangae1548e2022-05-06 16:38:46 +080055 g_rec_mutex_unlock(&GST_VIDEO_DECODER(decoder)->stream_lock); \
fei.denge9458472023-04-18 02:05:48 +000056 GST_TRACE("aml v4l2 dec unlocked"); \
xuesong.jiangae1548e2022-05-06 16:38:46 +080057 }
58#endif
xuesong.jiang61ea8012022-05-12 15:38:17 +080059
hanghang.luo36df2852022-08-24 15:02:27 +080060#ifndef ABSDIFF
61#define ABSDIFF(a,b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
62#endif
63
xuesong.jiang61ea8012022-05-12 15:38:17 +080064#if GST_IMPORT_LGE_PROP
65typedef struct _GstAmlResourceInfo
66{
67 gchar *coretype;
68 gint videoport;
69 gint audioport;
70 gint maxwidth;
71 gint maxheight;
72 gint mixerport;
73} GstAmlResourceInfo;
74
75struct _GstAmlV4l2VideoDecLgeCtxt
76{
77 GstAmlResourceInfo res_info;
78 guint64 dec_size;
79 guint64 undec_size;
80 gchar *app_type;
81 gboolean clip_mode;
82};
83#endif
84
xuesong.jiangae1548e2022-05-06 16:38:46 +080085typedef struct
86{
87 gchar *device;
88 GstCaps *sink_caps;
89 GstCaps *src_caps;
90 const gchar *longname;
91 const gchar *description;
92} GstAmlV4l2VideoDecCData;
93
94enum
95{
96 PROP_0,
xuesong.jiang61ea8012022-05-12 15:38:17 +080097 V4L2_STD_OBJECT_PROPS,
98#if GST_IMPORT_LGE_PROP
99 LGE_RESOURCE_INFO,
100 LGE_DECODE_SIZE,
101 LGE_UNDECODE_SIZE,
102 LGE_APP_TYPE,
103 LGE_CLIP_MODE
104#endif
xuesong.jiangae1548e2022-05-06 16:38:46 +0800105};
106
107#define gst_aml_v4l2_video_dec_parent_class parent_class
108G_DEFINE_ABSTRACT_TYPE(GstAmlV4l2VideoDec, gst_aml_v4l2_video_dec,
109 GST_TYPE_VIDEO_DECODER);
110
111static GstFlowReturn gst_aml_v4l2_video_dec_finish(GstVideoDecoder *decoder);
xuesong.jiang61ea8012022-05-12 15:38:17 +0800112#if GST_IMPORT_LGE_PROP
113static void gst_aml_v4l2_video_dec_install_lge_properties_helper(GObjectClass *gobject_class);
114#endif
xuesong.jiangae1548e2022-05-06 16:38:46 +0800115
116static void
117gst_aml_v4l2_video_dec_set_property(GObject *object,
118 guint prop_id, const GValue *value, GParamSpec *pspec)
119{
120 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(object);
121
122 switch (prop_id)
123 {
124 case PROP_CAPTURE_IO_MODE:
125 if (!gst_aml_v4l2_object_set_property_helper(self->v4l2capture,
126 prop_id, value, pspec))
127 {
128 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
129 }
130 break;
131 case PROP_DUMP_FRAME_LOCATION:
132 if (!gst_aml_v4l2_object_set_property_helper(self->v4l2capture,
133 prop_id, value, pspec))
134 {
135 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
136 }
137 break;
xuesong.jiang61ea8012022-05-12 15:38:17 +0800138#if GST_IMPORT_LGE_PROP
139 case LGE_RESOURCE_INFO:
140 {
141 GST_DEBUG_OBJECT(self, "LGE up layer set res info");
142 GstStructure *r_info = g_value_get_object(value);
143 if (r_info)
144 {
145 if (gst_structure_has_field(r_info, "coretype"))
146 {
147 if (self->lge_ctxt->res_info.coretype)
148 g_free(self->lge_ctxt->res_info.coretype);
149 self->lge_ctxt->res_info.coretype = g_strdup(gst_structure_get_string(r_info, "coretype"));
150 }
151 if (gst_structure_has_field(r_info, "videoport"))
152 gst_structure_get_int(r_info, "videoport", &(self->lge_ctxt->res_info.videoport));
153 if (gst_structure_has_field(r_info, "audioport"))
154 gst_structure_get_int(r_info, "audioport", &(self->lge_ctxt->res_info.audioport));
155 if (gst_structure_has_field(r_info, "maxwidth"))
156 gst_structure_get_int(r_info, "maxwidth", &(self->lge_ctxt->res_info.maxwidth));
157 if (gst_structure_has_field(r_info, "maxheight"))
158 gst_structure_get_int(r_info, "maxheight", &(self->lge_ctxt->res_info.maxheight));
159 if (gst_structure_has_field(r_info, "mixerport"))
160 gst_structure_get_int(r_info, "mixerport", &(self->lge_ctxt->res_info.mixerport));
161 }
162 break;
163 }
164 case LGE_APP_TYPE:
165 {
166 GST_DEBUG_OBJECT(self, "LGE up layer set app type");
167 if (self->lge_ctxt->app_type)
168 g_free(self->lge_ctxt->app_type);
169 self->lge_ctxt->app_type = g_strdup(g_value_get_string(value));
170 break;
171 }
172 case LGE_CLIP_MODE:
173 {
174 GST_DEBUG_OBJECT(self, "LGE up layer set clip mode");
175 self->lge_ctxt->clip_mode = g_strdup(g_value_get_boolean(value));
176 break;
177 }
178#endif
xuesong.jiangae1548e2022-05-06 16:38:46 +0800179 /* By default, only set on output */
180 default:
181 if (!gst_aml_v4l2_object_set_property_helper(self->v4l2output,
182 prop_id, value, pspec))
183 {
184 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
185 }
186 break;
187 }
188}
189
190static void
191gst_aml_v4l2_video_dec_get_property(GObject *object,
192 guint prop_id, GValue *value, GParamSpec *pspec)
193{
194 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(object);
195
196 switch (prop_id)
197 {
198 case PROP_CAPTURE_IO_MODE:
199 if (!gst_aml_v4l2_object_get_property_helper(self->v4l2capture,
200 prop_id, value, pspec))
201 {
202 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
203 }
204 break;
205
xuesong.jiang61ea8012022-05-12 15:38:17 +0800206#if GST_IMPORT_LGE_PROP
207 case LGE_DECODE_SIZE:
208 {
209 GST_DEBUG_OBJECT(self, "LGE up layer get dec size");
210 self->lge_ctxt->dec_size = -1;
211 g_value_set_int(value, self->lge_ctxt->dec_size);
212 break;
213 }
214 case LGE_UNDECODE_SIZE:
215 {
216 GST_DEBUG_OBJECT(self, "LGE up layer get undec size");
217 self->lge_ctxt->undec_size = -1;
218 g_value_set_int(value, self->lge_ctxt->undec_size);
219 break;
220 }
221#endif
222
xuesong.jiangae1548e2022-05-06 16:38:46 +0800223 /* By default read from output */
224 default:
225 if (!gst_aml_v4l2_object_get_property_helper(self->v4l2output,
226 prop_id, value, pspec))
227 {
228 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
229 }
230 break;
231 }
232}
233
234static gboolean
235gst_aml_v4l2_video_dec_open(GstVideoDecoder *decoder)
236{
237 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
238 GstCaps *codec_caps;
239
240 GST_DEBUG_OBJECT(self, "Opening");
241
242 if (!gst_aml_v4l2_object_open(self->v4l2output))
243 goto failure;
244
245 if (!gst_aml_v4l2_object_open_shared(self->v4l2capture, self->v4l2output))
246 goto failure;
247
248 codec_caps = gst_pad_get_pad_template_caps(decoder->sinkpad);
249 self->probed_sinkcaps = gst_aml_v4l2_object_probe_caps(self->v4l2output,
250 codec_caps);
251 gst_caps_unref(codec_caps);
252
253 if (gst_caps_is_empty(self->probed_sinkcaps))
254 goto no_encoded_format;
255
256 return TRUE;
257
258no_encoded_format:
259 GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
260 (_("Decoder on device %s has no supported input format"),
261 self->v4l2output->videodev),
262 (NULL));
263 goto failure;
264
265failure:
266 if (GST_AML_V4L2_IS_OPEN(self->v4l2output))
267 gst_aml_v4l2_object_close(self->v4l2output);
268
269 if (GST_AML_V4L2_IS_OPEN(self->v4l2capture))
270 gst_aml_v4l2_object_close(self->v4l2capture);
271
272 gst_caps_replace(&self->probed_srccaps, NULL);
273 gst_caps_replace(&self->probed_sinkcaps, NULL);
274
275 return FALSE;
276}
277
278static gboolean
279gst_aml_v4l2_video_dec_close(GstVideoDecoder *decoder)
280{
281 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
282
283 GST_DEBUG_OBJECT(self, "Closing");
284
285 gst_aml_v4l2_object_close(self->v4l2output);
286 gst_aml_v4l2_object_close(self->v4l2capture);
287 gst_caps_replace(&self->probed_srccaps, NULL);
288 gst_caps_replace(&self->probed_sinkcaps, NULL);
289
290 return TRUE;
291}
292
293static gboolean
294gst_aml_v4l2_video_dec_start(GstVideoDecoder *decoder)
295{
296 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
297
298 GST_DEBUG_OBJECT(self, "Starting");
299
300 gst_aml_v4l2_object_unlock(self->v4l2output);
301 g_atomic_int_set(&self->active, TRUE);
302 self->output_flow = GST_FLOW_OK;
303
304 return TRUE;
305}
306
307static gboolean
308gst_aml_v4l2_video_dec_stop(GstVideoDecoder *decoder)
309{
310 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
311
312 GST_DEBUG_OBJECT(self, "Stopping");
313
314 gst_aml_v4l2_object_unlock(self->v4l2output);
315 gst_aml_v4l2_object_unlock(self->v4l2capture);
316
317 /* Wait for capture thread to stop */
318 gst_pad_stop_task(decoder->srcpad);
319
320 GST_VIDEO_DECODER_STREAM_LOCK(decoder);
321 self->output_flow = GST_FLOW_OK;
322 GST_VIDEO_DECODER_STREAM_UNLOCK(decoder);
323
324 /* Should have been flushed already */
325 g_assert(g_atomic_int_get(&self->active) == FALSE);
326
327 gst_aml_v4l2_object_stop(self->v4l2output);
328 gst_aml_v4l2_object_stop(self->v4l2capture);
329
330 if (self->input_state)
331 {
332 gst_video_codec_state_unref(self->input_state);
333 self->input_state = NULL;
334 }
335
336 GST_DEBUG_OBJECT(self, "Stopped");
337
338 return TRUE;
339}
340
341static gboolean
342gst_aml_v4l2_video_dec_set_format(GstVideoDecoder *decoder,
343 GstVideoCodecState *state)
344{
345 GstAmlV4l2Error error = GST_AML_V4L2_ERROR_INIT;
346 gboolean ret = TRUE;
347 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
348 GstCaps *caps;
349
350 GST_DEBUG_OBJECT(self, "Setting format: %" GST_PTR_FORMAT, state->caps);
351 GstCapsFeatures *const features = gst_caps_get_features(state->caps, 0);
352
353 if (gst_caps_features_contains(features, GST_CAPS_FEATURE_MEMORY_DMABUF))
354 self->v4l2output->req_mode = GST_V4L2_IO_DMABUF_IMPORT;
355
356 if (self->input_state)
357 {
358 if (gst_aml_v4l2_object_caps_equal(self->v4l2output, state->caps))
359 {
360 GST_DEBUG_OBJECT(self, "Compatible caps");
361 goto done;
362 }
363 gst_video_codec_state_unref(self->input_state);
364 self->input_state = NULL;
365
366 gst_aml_v4l2_video_dec_finish(decoder);
367 gst_aml_v4l2_object_stop(self->v4l2output);
368
369 /* The renegotiation flow don't blend with the base class flow. To properly
370 * stop the capture pool, if the buffers can't be orphaned, we need to
371 * reclaim our buffers, which will happend through the allocation query.
372 * The allocation query is triggered by gst_video_decoder_negotiate() which
373 * requires the output caps to be set, but we can't know this information
374 * as we rely on the decoder, which requires the capture queue to be
375 * stopped.
376 *
377 * To workaround this issue, we simply run an allocation query with the
378 * old negotiated caps in order to drain/reclaim our buffers. That breaks
379 * the complexity and should not have much impact in performance since the
380 * following allocation query will happen on a drained pipeline and won't
381 * block. */
382 if (self->v4l2capture->pool &&
383 !gst_aml_v4l2_buffer_pool_orphan(&self->v4l2capture->pool))
384 {
385 GstCaps *caps = gst_pad_get_current_caps(decoder->srcpad);
386 if (caps)
387 {
388 GstQuery *query = gst_query_new_allocation(caps, FALSE);
389 gst_pad_peer_query(decoder->srcpad, query);
390 gst_query_unref(query);
391 gst_caps_unref(caps);
392 }
393 }
394
395 gst_aml_v4l2_object_stop(self->v4l2capture);
396 self->output_flow = GST_FLOW_OK;
397 }
398
399 if ((ret = gst_aml_v4l2_set_drm_mode(self->v4l2output)) == FALSE)
400 {
401 GST_ERROR_OBJECT(self, "config output drm mode error");
402 goto done;
403 }
404
xuesong.jiang22a9b112023-05-24 09:01:59 +0000405 if ((ret = gst_aml_v4l2_set_stream_mode(self->v4l2output)) == FALSE)
406 {
407 GST_ERROR_OBJECT(self, "config output stream mode error");
408 goto done;
409 }
410
xuesong.jiangae1548e2022-05-06 16:38:46 +0800411 ret = gst_aml_v4l2_object_set_format(self->v4l2output, state->caps, &error);
412
413 gst_caps_replace(&self->probed_srccaps, NULL);
414 self->probed_srccaps = gst_aml_v4l2_object_probe_caps(self->v4l2capture,
415 gst_aml_v4l2_object_get_raw_caps());
416
417 if (gst_caps_is_empty(self->probed_srccaps))
418 goto no_raw_format;
419
420 caps = gst_caps_copy(self->probed_srccaps);
421 gst_caps_set_features_simple(caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF));
422 gst_caps_append(self->probed_srccaps, caps);
423 if (ret)
424 self->input_state = gst_video_codec_state_ref(state);
425 else
426 gst_aml_v4l2_error(self, &error);
427
428done:
429 return ret;
430
431no_raw_format:
432 GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
433 (_("Decoder on device %s has no supported output format"),
434 self->v4l2output->videodev),
435 (NULL));
436 return GST_FLOW_ERROR;
437}
438
439static gboolean
440gst_aml_v4l2_video_dec_flush(GstVideoDecoder *decoder)
441{
442 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
443
444 GST_DEBUG_OBJECT(self, "Flushed");
445
446 /* Ensure the processing thread has stopped for the reverse playback
447 * discount case */
448 if (gst_pad_get_task_state(decoder->srcpad) == GST_TASK_STARTED)
449 {
450 GST_VIDEO_DECODER_STREAM_UNLOCK(decoder);
451
452 gst_aml_v4l2_object_unlock(self->v4l2output);
453 gst_aml_v4l2_object_unlock(self->v4l2capture);
454 gst_pad_stop_task(decoder->srcpad);
455 GST_VIDEO_DECODER_STREAM_LOCK(decoder);
456 }
457
458 self->output_flow = GST_FLOW_OK;
459
460 gst_aml_v4l2_object_unlock_stop(self->v4l2output);
461 gst_aml_v4l2_object_unlock_stop(self->v4l2capture);
462
463 if (self->v4l2output->pool)
464 gst_aml_v4l2_buffer_pool_flush(self->v4l2output->pool);
465
466 /* gst_aml_v4l2_buffer_pool_flush() calls streamon the capture pool and must be
467 * called after gst_aml_v4l2_object_unlock_stop() stopped flushing the buffer
468 * pool. */
469 if (self->v4l2capture->pool)
470 gst_aml_v4l2_buffer_pool_flush(self->v4l2capture->pool);
471
472 return TRUE;
473}
474
475static gboolean
476gst_aml_v4l2_video_dec_negotiate(GstVideoDecoder *decoder)
477{
478 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
479
xuesong.jiang681d3602022-06-24 21:23:35 +0800480 if (TRUE == self->v4l2output->is_svp)
481 {
482 GstStructure *s;
483 GstEvent *event;
484
485 s = gst_structure_new_empty ("IS_SVP");
486 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_STICKY, s);
487 GST_DEBUG_OBJECT(self, "before Send SVP Event :%p", event);
488 gst_pad_push_event (decoder->srcpad, event);
489 GST_DEBUG_OBJECT(self, "after Send SVP Event :%p", event);
490 }
491
xuesong.jiangae1548e2022-05-06 16:38:46 +0800492 /* We don't allow renegotiation without carefull disabling the pool */
493 if (self->v4l2capture->pool &&
494 gst_buffer_pool_is_active(GST_BUFFER_POOL(self->v4l2capture->pool)))
495 return TRUE;
496
497 return GST_VIDEO_DECODER_CLASS(parent_class)->negotiate(decoder);
498}
499
500static gboolean
501gst_aml_v4l2_decoder_cmd(GstAmlV4l2Object *v4l2object, guint cmd, guint flags)
502{
503 struct v4l2_decoder_cmd dcmd = {
504 0,
505 };
506
507 GST_DEBUG_OBJECT(v4l2object->element,
508 "sending v4l2 decoder command %u with flags %u", cmd, flags);
509
510 if (!GST_AML_V4L2_IS_OPEN(v4l2object))
511 return FALSE;
512
513 dcmd.cmd = cmd;
514 dcmd.flags = flags;
515 if (v4l2object->ioctl(v4l2object->video_fd, VIDIOC_DECODER_CMD, &dcmd) < 0)
516 goto dcmd_failed;
517
518 return TRUE;
519
520dcmd_failed:
521 if (errno == ENOTTY)
522 {
523 GST_INFO_OBJECT(v4l2object->element,
524 "Failed to send decoder command %u with flags %u for '%s'. (%s)",
525 cmd, flags, v4l2object->videodev, g_strerror(errno));
526 }
527 else
528 {
529 GST_ERROR_OBJECT(v4l2object->element,
530 "Failed to send decoder command %u with flags %u for '%s'. (%s)",
531 cmd, flags, v4l2object->videodev, g_strerror(errno));
532 }
533 return FALSE;
534}
535
536static GstFlowReturn
537gst_aml_v4l2_video_dec_finish(GstVideoDecoder *decoder)
538{
539 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
540 GstFlowReturn ret = GST_FLOW_OK;
541 GstBuffer *buffer;
542
543 if (gst_pad_get_task_state(decoder->srcpad) != GST_TASK_STARTED)
544 goto done;
545
546 GST_DEBUG_OBJECT(self, "Finishing decoding");
547
548 GST_VIDEO_DECODER_STREAM_UNLOCK(decoder);
549
550 if (gst_aml_v4l2_decoder_cmd(self->v4l2output, V4L2_DEC_CMD_STOP, 0))
551 {
552 GstTask *task = decoder->srcpad->task;
553
554 /* If the decoder stop command succeeded, just wait until processing is
555 * finished */
556 GST_DEBUG_OBJECT(self, "Waiting for decoder stop");
557 GST_OBJECT_LOCK(task);
558 while (GST_TASK_STATE(task) == GST_TASK_STARTED)
559 GST_TASK_WAIT(task);
560 GST_OBJECT_UNLOCK(task);
561 ret = GST_FLOW_FLUSHING;
562 }
563 else
564 {
565 /* otherwise keep queuing empty buffers until the processing thread has
566 * stopped, _pool_process() will return FLUSHING when that happened */
567 while (ret == GST_FLOW_OK)
568 {
xuesong.jiangc5dac0f2023-02-01 14:42:24 +0800569 GST_DEBUG_OBJECT(self, "queue empty output buf");
xuesong.jiangae1548e2022-05-06 16:38:46 +0800570 buffer = gst_buffer_new();
571 ret =
572 gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &buffer);
573 gst_buffer_unref(buffer);
574 }
575 }
576
577 /* and ensure the processing thread has stopped in case another error
578 * occured. */
579 gst_aml_v4l2_object_unlock(self->v4l2capture);
580 gst_pad_stop_task(decoder->srcpad);
581 GST_VIDEO_DECODER_STREAM_LOCK(decoder);
582
583 if (ret == GST_FLOW_FLUSHING)
584 ret = self->output_flow;
585
586 GST_DEBUG_OBJECT(decoder, "Done draining buffers");
587
588 /* TODO Shall we cleanup any reffed frame to workaround broken decoders ? */
589
590done:
591 return ret;
592}
593
594static GstFlowReturn
595gst_aml_v4l2_video_dec_drain(GstVideoDecoder *decoder)
596{
597 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
598
599 GST_DEBUG_OBJECT(self, "Draining...");
600 gst_aml_v4l2_video_dec_finish(decoder);
601 gst_aml_v4l2_video_dec_flush(decoder);
602
603 return GST_FLOW_OK;
604}
605
606static GstVideoCodecFrame *
607gst_aml_v4l2_video_dec_get_oldest_frame(GstVideoDecoder *decoder)
608{
609 GstVideoCodecFrame *frame = NULL;
610 GList *frames, *l;
611 gint count = 0;
612
613 frames = gst_video_decoder_get_frames(decoder);
614
615 for (l = frames; l != NULL; l = l->next)
616 {
617 GstVideoCodecFrame *f = l->data;
618
619 if (!frame || (GST_CLOCK_TIME_IS_VALID(frame->pts) && GST_CLOCK_TIME_IS_VALID(f->pts) && (frame->pts > f->pts)))
620 frame = f;
621
622 count++;
623 }
624
625 if (frame)
626 {
627 GST_LOG_OBJECT(decoder,
628 "Oldest frame is %d %" GST_TIME_FORMAT " and %d frames left",
629 frame->system_frame_number, GST_TIME_ARGS(frame->pts), count - 1);
630 gst_video_codec_frame_ref(frame);
631 }
632
633 g_list_free_full(frames, (GDestroyNotify)gst_video_codec_frame_unref);
634
635 return frame;
636}
637
fei.dengbee20862022-06-14 14:59:48 +0800638static GstVideoCodecFrame *
639gst_aml_v4l2_video_dec_get_right_frame(GstVideoDecoder *decoder, GstClockTime pts)
640{
641 GstVideoCodecFrame *frame = NULL;
642 GList *frames, *l;
643 gint count = 0;
644
645 frames = gst_video_decoder_get_frames(decoder);
646
647 for (l = frames; l != NULL; l = l->next)
648 {
649 GstVideoCodecFrame *f = l->data;
fei.denge9458472023-04-18 02:05:48 +0000650
xuesong.jiangc5dac0f2023-02-01 14:42:24 +0800651 if (GST_CLOCK_TIME_IS_VALID(pts) && (ABSDIFF(f->pts,pts)) < 1000) {
fei.dengbee20862022-06-14 14:59:48 +0800652 frame = f;
fei.dengbee20862022-06-14 14:59:48 +0800653 } else {
654 if (!frame || (GST_CLOCK_TIME_IS_VALID(frame->pts) && GST_CLOCK_TIME_IS_VALID(f->pts) && (frame->pts > f->pts)))
655 frame = f;
656 }
657
658 count++;
659 }
660
661 if (frame)
662 {
663 GST_LOG_OBJECT(decoder,
664 "frame is %d %" GST_TIME_FORMAT " and %d frames left",
665 frame->system_frame_number, GST_TIME_ARGS(frame->pts), count - 1);
666 gst_video_codec_frame_ref(frame);
667 }
668
669 g_list_free_full(frames, (GDestroyNotify)gst_video_codec_frame_unref);
670
671 return frame;
672}
673
xuesong.jiangae1548e2022-05-06 16:38:46 +0800674static gboolean
675gst_aml_v4l2_video_remove_padding(GstCapsFeatures *features,
676 GstStructure *structure, gpointer user_data)
677{
678 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(user_data);
679 GstVideoAlignment *align = &self->v4l2capture->align;
680 GstVideoInfo *info = &self->v4l2capture->info;
681 int width, height;
682
683 if (!gst_structure_get_int(structure, "width", &width))
684 return TRUE;
685
686 if (!gst_structure_get_int(structure, "height", &height))
687 return TRUE;
688
689 if (align->padding_left != 0 || align->padding_top != 0 ||
690 height != info->height + align->padding_bottom)
691 return TRUE;
692
693 if (height == info->height + align->padding_bottom)
694 {
695 /* Some drivers may round up width to the padded with */
696 if (width == info->width + align->padding_right)
697 gst_structure_set(structure,
698 "width", G_TYPE_INT, width - align->padding_right,
699 "height", G_TYPE_INT, height - align->padding_bottom, NULL);
700 /* Some drivers may keep visible width and only round up bytesperline */
701 else if (width == info->width)
702 gst_structure_set(structure,
703 "height", G_TYPE_INT, height - align->padding_bottom, NULL);
704 }
705
706 return TRUE;
707}
708
709static void
sheng.liubcf036c2022-06-21 15:55:42 +0800710gst_v4l2_drop_event (GstAmlV4l2Object * v4l2object)
sheng.liub56bbc52022-06-21 11:02:33 +0800711{
712 struct v4l2_event evt;
713 gint ret;
714
715 memset (&evt, 0x00, sizeof (struct v4l2_event));
716 ret = v4l2object->ioctl (v4l2object->video_fd, VIDIOC_DQEVENT, &evt);
717 if (ret < 0)
718 {
719 GST_DEBUG_OBJECT (v4l2object, "dqevent failed");
720 return;
721 }
722
723 switch (evt.type)
724 {
725 case V4L2_EVENT_SOURCE_CHANGE:
726 GST_DEBUG_OBJECT (v4l2object, "Drop GST_V4L2_FLOW_SOURCE_CHANGE");
727 break;
728 case V4L2_EVENT_EOS:
729 GST_DEBUG_OBJECT (v4l2object, "Drop GST_V4L2_FLOW_LAST_BUFFER");
730 break;
731 default:
732 break;
733 }
734
735 return;
736}
737
738static void
xuesong.jiangae1548e2022-05-06 16:38:46 +0800739gst_aml_v4l2_video_dec_loop(GstVideoDecoder *decoder)
740{
741 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
742 GstAmlV4l2BufferPool *v4l2_pool;
743 GstAmlV4l2Error error = GST_AML_V4L2_ERROR_INIT;
744 GstBufferPool *pool;
745 GstVideoCodecFrame *frame;
746 GstBuffer *buffer = NULL;
747 GstFlowReturn ret;
748
749 if (G_UNLIKELY(!GST_AML_V4L2_IS_ACTIVE(self->v4l2capture)))
750 {
751 GstVideoInfo info;
752 GstVideoCodecState *output_state;
xuesong.jiang282ca572023-05-05 09:03:32 +0000753 GstCaps *acquired_caps, *available_caps, *caps, *filter;
xuesong.jiangae1548e2022-05-06 16:38:46 +0800754 GstStructure *st;
755
756 GST_DEBUG_OBJECT(self, "waitting source change event");
757 /* Wait until received SOURCE_CHANGE event to get right video format */
758 while (self->v4l2capture->can_wait_event && self->v4l2capture->need_wait_event)
759 {
760 ret = gst_aml_v4l2_object_dqevent(self->v4l2capture);
761 if (ret == GST_AML_V4L2_FLOW_SOURCE_CHANGE)
762 {
763 GST_DEBUG_OBJECT(self, "Received source change event");
764 break;
765 }
766 else if (ret == GST_AML_V4L2_FLOW_LAST_BUFFER)
767 {
768 GST_DEBUG_OBJECT(self, "Received eos event");
769 goto beach;
770 }
771 else if (ret != GST_FLOW_OK)
772 {
773 GST_ERROR_OBJECT(self, "dqevent error");
774 goto beach;
775 }
776 }
777 self->v4l2capture->need_wait_event = FALSE;
778
sheng.liu0c77f6c2022-06-17 21:33:20 +0800779 if (TRUE == self->v4l2output->is_svp)
780 {
781 GstPad *peer;
782 GstStructure *s;
783 GstEvent *event;
784
785 peer = gst_pad_get_peer (decoder->srcpad);
786 if (peer)
787 {
788 s = gst_structure_new_empty ("IS_SVP");
789 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
790 gst_pad_send_event (peer, event);
791 GST_DEBUG_OBJECT(self, "Send SVP Event");
792 gst_object_unref (peer);
793 }
794 }
795
sheng.liub56bbc52022-06-21 11:02:33 +0800796 if (self->v4l2capture->need_drop_event)
797 {
798 // drop V4L2_EVENT_SOURCE_CHANGE
799 gst_v4l2_drop_event(self->v4l2capture);
800 self->v4l2capture->need_drop_event = FALSE;
801 }
802
xuesong.jiangae1548e2022-05-06 16:38:46 +0800803 if (!gst_aml_v4l2_object_acquire_format(self->v4l2capture, &info))
804 goto not_negotiated;
805
806 /* Create caps from the acquired format, remove the format field */
807 acquired_caps = gst_video_info_to_caps(&info);
808 GST_DEBUG_OBJECT(self, "Acquired caps: %" GST_PTR_FORMAT, acquired_caps);
809 st = gst_caps_get_structure(acquired_caps, 0);
xuesong.jiang282ca572023-05-05 09:03:32 +0000810 gst_structure_remove_fields(st, "format", "colorimetry", "chroma-site", NULL);
811
812 /* Probe currently available pixel formats */
813 available_caps = gst_caps_copy(self->probed_srccaps);
814 GST_DEBUG_OBJECT(self, "Available caps: %" GST_PTR_FORMAT, available_caps);
815
816 /* Replace coded size with visible size, we want to negotiate visible size
817 * with downstream, not coded size. */
818 gst_caps_map_in_place(available_caps, gst_aml_v4l2_video_remove_padding, self);
819
820 filter = gst_caps_intersect_full(available_caps, acquired_caps, GST_CAPS_INTERSECT_FIRST);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800821 caps = gst_caps_copy(filter);
822 gst_caps_set_features_simple(caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF));
823 gst_caps_append(filter, caps);
824
825 GST_DEBUG_OBJECT(self, "Filtered caps: %" GST_PTR_FORMAT, filter);
826 gst_caps_unref(acquired_caps);
xuesong.jiang282ca572023-05-05 09:03:32 +0000827 gst_caps_unref(available_caps);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800828 caps = gst_pad_peer_query_caps(decoder->srcpad, filter);
829 gst_caps_unref(filter);
830
831 GST_DEBUG_OBJECT(self, "Possible decoded caps: %" GST_PTR_FORMAT, caps);
832 if (gst_caps_is_empty(caps))
833 {
834 gst_caps_unref(caps);
835 goto not_negotiated;
836 }
837
838 /* Fixate pixel format */
839 caps = gst_caps_fixate(caps);
840
841 GST_DEBUG_OBJECT(self, "Chosen decoded caps: %" GST_PTR_FORMAT, caps);
842
843 /* Try to set negotiated format, on success replace acquired format */
844 if (gst_aml_v4l2_object_set_format(self->v4l2capture, caps, &error))
845 gst_video_info_from_caps(&info, caps);
846 else
847 gst_aml_v4l2_clear_error(&error);
848 gst_caps_unref(caps);
849
850 output_state = gst_video_decoder_set_output_state(decoder,
851 info.finfo->format, info.width, info.height, self->input_state);
852
853 /* Copy the rest of the information, there might be more in the future */
854 output_state->info.interlace_mode = info.interlace_mode;
855 gst_video_codec_state_unref(output_state);
856
857 if (!gst_video_decoder_negotiate(decoder))
858 {
859 if (GST_PAD_IS_FLUSHING(decoder->srcpad))
860 goto flushing;
861 else
862 goto not_negotiated;
863 }
864
865 /* Ensure our internal pool is activated */
866 if (!gst_buffer_pool_set_active(GST_BUFFER_POOL(self->v4l2capture->pool),
867 TRUE))
868 goto activate_failed;
xuesong.jiangc5dac0f2023-02-01 14:42:24 +0800869
870 g_mutex_lock(&self->res_chg_lock);
871 GST_LOG_OBJECT(decoder, "signal resolution changed");
872 self->is_res_chg = FALSE;
873 g_cond_signal(&self->res_chg_cond);
874 g_mutex_unlock(&self->res_chg_lock);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800875 }
876
877 GST_LOG_OBJECT(decoder, "Allocate output buffer");
878
879 v4l2_pool = GST_AML_V4L2_BUFFER_POOL(self->v4l2capture->pool);
880
881 self->output_flow = GST_FLOW_OK;
882 do
883 {
884 /* We cannot use the base class allotate helper since it taking the internal
885 * stream lock. we know that the acquire may need to poll until more frames
886 * comes in and holding this lock would prevent that.
887 */
888 pool = gst_video_decoder_get_buffer_pool(decoder);
889
890 /* Pool may be NULL if we started going to READY state */
891 if (pool == NULL)
892 {
fei.dengbee20862022-06-14 14:59:48 +0800893 GST_WARNING_OBJECT(decoder, "gst_video_decoder_get_buffer_pool goto beach");
xuesong.jiangae1548e2022-05-06 16:38:46 +0800894 ret = GST_FLOW_FLUSHING;
895 goto beach;
896 }
897
898 ret = gst_buffer_pool_acquire_buffer(pool, &buffer, NULL);
fei.dengccc89632022-07-15 19:10:17 +0800899 //calculate a new pts for interlace stream
900 if (ret == GST_FLOW_OK &&
901 self->v4l2capture->info.interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED)
902 {
903 //if buffer pts is valid, reduce 1/2 duration
904 if (GST_BUFFER_DURATION_IS_VALID(buffer))
905 {
906 GST_BUFFER_DURATION(buffer) = GST_BUFFER_DURATION(buffer)/2;
907 }
908 GST_BUFFER_FLAG_UNSET(buffer, GST_VIDEO_BUFFER_FLAG_INTERLACED);
909 //reset pts
fei.denga6ae3282022-07-15 19:50:30 +0800910 if (GST_BUFFER_TIMESTAMP (buffer) == 0LL || self->last_out_pts == GST_BUFFER_TIMESTAMP (buffer))
fei.dengccc89632022-07-15 19:10:17 +0800911 {
912 double rate = ((double)self->input_state->info.fps_n/(double)self->input_state->info.fps_d)*2;
913 GST_BUFFER_TIMESTAMP(buffer) = self->last_out_pts + 1000000000LL/rate;
914 }
915 }
916
xuesong.jiangae1548e2022-05-06 16:38:46 +0800917 g_object_unref(pool);
918
sheng.liu4e01a472022-06-21 15:38:25 +0800919 if (ret == GST_AML_V4L2_FLOW_LAST_BUFFER) {
sheng.liubcf036c2022-06-21 15:55:42 +0800920 GST_LOG_OBJECT(decoder, "Get GST_AML_V4L2_FLOW_LAST_BUFFER");
sheng.liub56bbc52022-06-21 11:02:33 +0800921 self->v4l2capture->need_drop_event = TRUE;
922 goto beach;
923 }
924
sheng.liu8d18ed22022-05-26 17:28:15 +0800925 if (ret == GST_AML_V4L2_FLOW_SOURCE_CHANGE)
926 {
927 GST_LOG_OBJECT(decoder, "Get GST_AML_V4L2_FLOW_SOURCE_CHANGE");
xuesong.jiangc5dac0f2023-02-01 14:42:24 +0800928
929 g_mutex_lock (&self->res_chg_lock);
930 self->is_res_chg = TRUE;
931 g_mutex_unlock (&self->res_chg_lock);
932
sheng.liu8d18ed22022-05-26 17:28:15 +0800933 gst_aml_v4l2_object_stop(self->v4l2capture);
934 return;
935 }
936
fei.dengbee20862022-06-14 14:59:48 +0800937 if (ret != GST_FLOW_OK) {
938 GST_WARNING_OBJECT(decoder, "gst_buffer_pool_acquire_buffer goto beach ret:%d",ret);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800939 goto beach;
fei.dengbee20862022-06-14 14:59:48 +0800940 }
xuesong.jiangae1548e2022-05-06 16:38:46 +0800941
xuesong.jiangc5dac0f2023-02-01 14:42:24 +0800942 GST_LOG_OBJECT(decoder, "Process output buffer (switching flow outstanding num:%d)", self->v4l2capture->outstanding_buf_num);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800943 ret = gst_aml_v4l2_buffer_pool_process(v4l2_pool, &buffer);
944 if (ret == GST_AML_V4L2_FLOW_SOURCE_CHANGE)
945 {
946 gst_aml_v4l2_object_stop(self->v4l2capture);
947 return;
948 }
949
950 } while (ret == GST_AML_V4L2_FLOW_CORRUPTED_BUFFER);
951
952 if (ret != GST_FLOW_OK)
953 goto beach;
954
fei.dengbee20862022-06-14 14:59:48 +0800955 frame = gst_aml_v4l2_video_dec_get_right_frame(decoder, GST_BUFFER_TIMESTAMP (buffer));
xuesong.jiangae1548e2022-05-06 16:38:46 +0800956 if (frame)
957 {
zengliang.li32cb11e2022-11-24 12:10:26 +0800958 if (!GST_CLOCK_TIME_IS_VALID(frame->pts))
959 {
960 double rate = ((double)self->input_state->info.fps_n/(double)self->input_state->info.fps_d);
961 GST_BUFFER_TIMESTAMP(buffer) = self->last_out_pts + 1000000000LL/rate;
962 }
fei.dengccc89632022-07-15 19:10:17 +0800963 self->last_out_pts = GST_BUFFER_TIMESTAMP(buffer);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800964 frame->output_buffer = buffer;
fei.dengccc89632022-07-15 19:10:17 +0800965 frame->pts = GST_BUFFER_TIMESTAMP(buffer);
966 frame->duration = GST_BUFFER_DURATION(buffer);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800967 buffer = NULL;
968 ret = gst_video_decoder_finish_frame(decoder, frame);
969
970 if (ret != GST_FLOW_OK)
971 goto beach;
972 }
973 else
974 {
975 GST_WARNING_OBJECT(decoder, "Decoder is producing too many buffers");
976 gst_buffer_unref(buffer);
977 }
978
979 return;
980 /* ERRORS */
981not_negotiated:
982{
983 GST_ERROR_OBJECT(self, "not negotiated");
984 ret = GST_FLOW_NOT_NEGOTIATED;
985 goto beach;
986}
987activate_failed:
988{
989 GST_ERROR_OBJECT(self, "Buffer pool activation failed");
990 GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
991 (_("Failed to allocate required memory.")),
992 ("Buffer pool activation failed"));
993 ret = GST_FLOW_ERROR;
994 goto beach;
995}
996flushing:
997{
998 ret = GST_FLOW_FLUSHING;
999 goto beach;
1000}
1001beach:
1002 GST_DEBUG_OBJECT(decoder, "Leaving output thread: %s",
1003 gst_flow_get_name(ret));
1004
1005 gst_buffer_replace(&buffer, NULL);
1006 self->output_flow = ret;
1007 gst_aml_v4l2_object_unlock(self->v4l2output);
1008 gst_pad_pause_task(decoder->srcpad);
1009}
1010
1011static GstFlowReturn
1012gst_aml_v4l2_video_dec_handle_frame(GstVideoDecoder *decoder,
1013 GstVideoCodecFrame *frame)
1014{
1015 GstAmlV4l2Error error = GST_AML_V4L2_ERROR_INIT;
1016 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
1017 GstBufferPool *pool = GST_BUFFER_POOL(self->v4l2output->pool);
1018 GstFlowReturn ret = GST_FLOW_OK;
1019 gboolean processed = FALSE;
1020 GstBuffer *tmp;
1021 GstTaskState task_state;
1022 GstCaps *caps;
1023
1024 GST_DEBUG_OBJECT(self, "Handling frame %d", frame->system_frame_number);
1025
1026 if (G_UNLIKELY(!g_atomic_int_get(&self->active)))
1027 goto flushing;
1028
1029 if (G_UNLIKELY(!GST_AML_V4L2_IS_ACTIVE(self->v4l2output)))
1030 {
1031 if (!self->input_state)
1032 goto not_negotiated;
1033 if (!gst_aml_v4l2_object_set_format(self->v4l2output, self->input_state->caps,
1034 &error))
1035 goto not_negotiated;
1036 }
1037
1038 if (G_UNLIKELY(!GST_AML_V4L2_IS_ACTIVE(self->v4l2capture)))
1039 {
1040 GstBuffer *codec_data;
sheng.liu0c77f6c2022-06-17 21:33:20 +08001041 GstCapsFeatures *features = NULL;
1042
1043 features = gst_caps_get_features(self->input_state->caps, 0);
1044 if (features && gst_caps_features_contains(features, GST_CAPS_FEATURE_MEMORY_DMABUF))
1045 {
1046 GST_DEBUG_OBJECT(self, "Is SVP");
1047 self->v4l2output->is_svp = TRUE;
1048 }
xuesong.jiangae1548e2022-05-06 16:38:46 +08001049
1050 GST_DEBUG_OBJECT(self, "Sending header");
1051
1052 codec_data = self->input_state->codec_data;
1053
1054 /* We are running in byte-stream mode, so we don't know the headers, but
1055 * we need to send something, otherwise the decoder will refuse to
1056 * intialize.
1057 */
1058 if (codec_data)
1059 {
1060 gst_buffer_ref(codec_data);
1061 }
1062 else
1063 {
1064 codec_data = gst_buffer_ref(frame->input_buffer);
1065 processed = TRUE;
1066 }
1067
1068 /* Ensure input internal pool is active */
1069 if (!gst_buffer_pool_is_active(pool))
1070 {
1071 GstStructure *config = gst_buffer_pool_get_config(pool);
xuesong.jiangc5dac0f2023-02-01 14:42:24 +08001072 // guint min = MAX(self->v4l2output->min_buffers, GST_AML_V4L2_MIN_BUFFERS);
1073 // guint max = VIDEO_MAX_FRAME;
xuesong.jiangae1548e2022-05-06 16:38:46 +08001074 // gst_buffer_pool_config_set_params (config, self->input_state->caps,
1075 // self->v4l2output->info.size, min, max);
1076 gst_buffer_pool_config_set_params(config, self->input_state->caps, self->v4l2output->info.size, self->v4l2output->min_buffers, self->v4l2output->min_buffers);
1077
1078 /* There is no reason to refuse this config */
1079 if (!gst_buffer_pool_set_config(pool, config))
1080 goto activate_failed;
xuesong.jiangc5dac0f2023-02-01 14:42:24 +08001081 GST_DEBUG_OBJECT(self, "setting output pool config to %" GST_PTR_FORMAT, config);
xuesong.jiangae1548e2022-05-06 16:38:46 +08001082
1083 if (!gst_buffer_pool_set_active(pool, TRUE))
1084 goto activate_failed;
1085 }
1086
1087 GST_VIDEO_DECODER_STREAM_UNLOCK(decoder);
1088 ret =
1089 gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &codec_data);
1090 GST_VIDEO_DECODER_STREAM_LOCK(decoder);
1091
1092 gst_buffer_unref(codec_data);
1093
1094 /* For decoders G_FMT returns coded size, G_SELECTION returns visible size
1095 * in the compose rectangle. gst_aml_v4l2_object_acquire_format() checks both
1096 * and returns the visible size as with/height and the coded size as
1097 * padding. */
1098 }
1099
1100 task_state = gst_pad_get_task_state(GST_VIDEO_DECODER_SRC_PAD(self));
1101 if (task_state == GST_TASK_STOPPED || task_state == GST_TASK_PAUSED)
1102 {
1103 /* It's possible that the processing thread stopped due to an error */
1104 if (self->output_flow != GST_FLOW_OK &&
1105 self->output_flow != GST_FLOW_FLUSHING)
1106 {
1107 GST_DEBUG_OBJECT(self, "Processing loop stopped with error, leaving");
1108 ret = self->output_flow;
1109 goto drop;
1110 }
1111
1112 GST_DEBUG_OBJECT(self, "Starting decoding thread");
1113
1114 /* Start the processing task, when it quits, the task will disable input
1115 * processing to unlock input if draining, or prevent potential block */
1116 self->output_flow = GST_FLOW_FLUSHING;
1117 if (!gst_pad_start_task(decoder->srcpad,
1118 (GstTaskFunction)gst_aml_v4l2_video_dec_loop, self, NULL))
1119 goto start_task_failed;
1120 }
1121
1122 if (!processed)
1123 {
1124 GST_VIDEO_DECODER_STREAM_UNLOCK(decoder);
1125 ret =
1126 gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &frame->input_buffer);
1127 GST_VIDEO_DECODER_STREAM_LOCK(decoder);
1128
1129 if (ret == GST_FLOW_FLUSHING)
1130 {
1131 if (gst_pad_get_task_state(GST_VIDEO_DECODER_SRC_PAD(self)) !=
1132 GST_TASK_STARTED)
1133 ret = self->output_flow;
1134 goto drop;
1135 }
1136 else if (ret != GST_FLOW_OK)
1137 {
1138 goto process_failed;
1139 }
1140 }
1141
1142 /* No need to keep input arround */
1143 tmp = frame->input_buffer;
1144 frame->input_buffer = gst_buffer_new();
1145 gst_buffer_copy_into(frame->input_buffer, tmp,
1146 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS |
1147 GST_BUFFER_COPY_META,
1148 0, 0);
1149 gst_buffer_unref(tmp);
1150
1151 gst_video_codec_frame_unref(frame);
1152 return ret;
1153
1154 /* ERRORS */
1155not_negotiated:
1156{
1157 GST_ERROR_OBJECT(self, "not negotiated");
1158 ret = GST_FLOW_NOT_NEGOTIATED;
1159 gst_aml_v4l2_error(self, &error);
1160 goto drop;
1161}
1162activate_failed:
1163{
1164 GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
1165 (_("Failed to allocate required memory.")),
1166 ("Buffer pool activation failed"));
1167 ret = GST_FLOW_ERROR;
1168 goto drop;
1169}
1170flushing:
1171{
1172 ret = GST_FLOW_FLUSHING;
1173 goto drop;
1174}
1175
1176start_task_failed:
1177{
1178 GST_ELEMENT_ERROR(self, RESOURCE, FAILED,
1179 (_("Failed to start decoding thread.")), (NULL));
1180 ret = GST_FLOW_ERROR;
1181 goto drop;
1182}
1183process_failed:
1184{
1185 GST_ELEMENT_ERROR(self, RESOURCE, FAILED,
1186 (_("Failed to process frame.")),
1187 ("Maybe be due to not enough memory or failing driver"));
1188 ret = GST_FLOW_ERROR;
1189 goto drop;
1190}
1191drop:
1192{
1193 gst_video_decoder_drop_frame(decoder, frame);
1194 return ret;
1195}
1196}
1197
1198static gboolean
1199gst_aml_v4l2_video_dec_decide_allocation(GstVideoDecoder *decoder,
1200 GstQuery *query)
1201{
1202 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
1203 GstClockTime latency;
1204 gboolean ret = FALSE;
1205
1206 if (gst_aml_v4l2_object_decide_allocation(self->v4l2capture, query))
1207 ret = GST_VIDEO_DECODER_CLASS(parent_class)->decide_allocation(decoder, query);
1208
1209 if (GST_CLOCK_TIME_IS_VALID(self->v4l2capture->duration))
1210 {
1211 latency = self->v4l2capture->min_buffers * self->v4l2capture->duration;
1212 GST_DEBUG_OBJECT(self, "Setting latency: %" GST_TIME_FORMAT " (%" G_GUINT32_FORMAT " * %" G_GUINT64_FORMAT, GST_TIME_ARGS(latency),
1213 self->v4l2capture->min_buffers, self->v4l2capture->duration);
1214 gst_video_decoder_set_latency(decoder, latency, latency);
1215 }
1216 else
1217 {
1218 GST_WARNING_OBJECT(self, "Duration invalid, not setting latency");
1219 }
1220
1221 return ret;
1222}
1223
1224static gboolean
1225gst_aml_v4l2_video_dec_src_query(GstVideoDecoder *decoder, GstQuery *query)
1226{
1227 gboolean ret = TRUE;
1228 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
1229
1230 switch (GST_QUERY_TYPE(query))
1231 {
1232 case GST_QUERY_CAPS:
1233 {
1234 GstCaps *filter, *result = NULL;
1235 GstPad *pad = GST_VIDEO_DECODER_SRC_PAD(decoder);
1236
1237 gst_query_parse_caps(query, &filter);
1238
1239 if (self->probed_srccaps)
1240 result = gst_caps_ref(self->probed_srccaps);
1241 else
1242 result = gst_pad_get_pad_template_caps(pad);
1243
1244 if (filter)
1245 {
1246 GstCaps *tmp = result;
1247 result =
1248 gst_caps_intersect_full(filter, tmp, GST_CAPS_INTERSECT_FIRST);
1249 gst_caps_unref(tmp);
1250 }
1251
1252 GST_DEBUG_OBJECT(self, "Returning src caps %" GST_PTR_FORMAT, result);
1253
1254 gst_query_set_caps_result(query, result);
1255 gst_caps_unref(result);
1256 break;
1257 }
1258
1259 default:
1260 ret = GST_VIDEO_DECODER_CLASS(parent_class)->src_query(decoder, query);
1261 break;
1262 }
1263
1264 return ret;
1265}
1266
1267static GstCaps *
1268gst_aml_v4l2_video_dec_sink_getcaps(GstVideoDecoder *decoder, GstCaps *filter)
1269{
1270 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
1271 GstCaps *result;
1272
1273 result = gst_video_decoder_proxy_getcaps(decoder, self->probed_sinkcaps,
1274 filter);
1275
1276 GST_DEBUG_OBJECT(self, "Returning sink caps %" GST_PTR_FORMAT, result);
1277
1278 return result;
1279}
1280
1281static gboolean
1282gst_aml_v4l2_video_dec_sink_event(GstVideoDecoder *decoder, GstEvent *event)
1283{
1284 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
1285 gboolean ret;
1286 GstEventType type = GST_EVENT_TYPE(event);
1287
1288 switch (type)
1289 {
1290 case GST_EVENT_FLUSH_START:
1291 GST_DEBUG_OBJECT(self, "flush start");
xuesong.jiangc5dac0f2023-02-01 14:42:24 +08001292
1293 g_mutex_lock (&self->res_chg_lock);
1294 while (self->is_res_chg)
1295 {
1296 GST_LOG_OBJECT(decoder, "wait resolution change finish");
1297 g_cond_wait(&self->res_chg_cond, &self->res_chg_lock);
1298 }
1299 g_mutex_unlock (&self->res_chg_lock);
1300
xuesong.jiangae1548e2022-05-06 16:38:46 +08001301 gst_aml_v4l2_object_unlock(self->v4l2output);
1302 gst_aml_v4l2_object_unlock(self->v4l2capture);
1303 break;
1304 default:
1305 break;
1306 }
1307
1308 ret = GST_VIDEO_DECODER_CLASS(parent_class)->sink_event(decoder, event);
1309
1310 switch (type)
1311 {
1312 case GST_EVENT_FLUSH_START:
1313 /* The processing thread should stop now, wait for it */
1314 gst_pad_stop_task(decoder->srcpad);
1315 GST_DEBUG_OBJECT(self, "flush start done");
1316 break;
1317 default:
1318 break;
1319 }
1320
1321 return ret;
1322}
1323
1324static GstStateChangeReturn
1325gst_aml_v4l2_video_dec_change_state(GstElement *element,
1326 GstStateChange transition)
1327{
1328 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(element);
1329 GstVideoDecoder *decoder = GST_VIDEO_DECODER(element);
1330
1331 if (transition == GST_STATE_CHANGE_PAUSED_TO_READY)
1332 {
1333 g_atomic_int_set(&self->active, FALSE);
1334 gst_aml_v4l2_object_unlock(self->v4l2output);
1335 gst_aml_v4l2_object_unlock(self->v4l2capture);
1336 gst_pad_stop_task(decoder->srcpad);
1337 }
1338
1339 return GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
1340}
1341
1342static void
1343gst_aml_v4l2_video_dec_dispose(GObject *object)
1344{
1345 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(object);
1346
1347 gst_caps_replace(&self->probed_sinkcaps, NULL);
1348 gst_caps_replace(&self->probed_srccaps, NULL);
1349
1350 G_OBJECT_CLASS(parent_class)->dispose(object);
1351}
1352
1353static void
1354gst_aml_v4l2_video_dec_finalize(GObject *object)
1355{
1356 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(object);
1357
1358 gst_aml_v4l2_object_destroy(self->v4l2capture);
1359 gst_aml_v4l2_object_destroy(self->v4l2output);
1360
xuesong.jiangc5dac0f2023-02-01 14:42:24 +08001361 g_mutex_clear(&self->res_chg_lock);
1362 g_cond_clear(&self->res_chg_cond);
1363
xuesong.jiang61ea8012022-05-12 15:38:17 +08001364#if GST_IMPORT_LGE_PROP
1365 if (self->lge_ctxt)
1366 {
1367 if (self->lge_ctxt->app_type)
1368 g_free(self->lge_ctxt->app_type);
1369 if (self->lge_ctxt->res_info.coretype)
1370 g_free(self->lge_ctxt->res_info.coretype);
1371 free(self->lge_ctxt);
1372 }
1373
1374#endif
1375
xuesong.jiangae1548e2022-05-06 16:38:46 +08001376 G_OBJECT_CLASS(parent_class)->finalize(object);
1377}
1378
1379static void
1380gst_aml_v4l2_video_dec_init(GstAmlV4l2VideoDec *self)
1381{
1382 /* V4L2 object are created in subinstance_init */
1383 self->is_secure_path = FALSE;
xuesong.jiangc5dac0f2023-02-01 14:42:24 +08001384 self->is_res_chg = FALSE;
1385 g_mutex_init(&self->res_chg_lock);
1386 g_cond_init(&self->res_chg_cond);
xuesong.jiang61ea8012022-05-12 15:38:17 +08001387#if GST_IMPORT_LGE_PROP
1388 self->lge_ctxt = malloc(sizeof(GstAmlV4l2VideoDecLgeCtxt));
1389 memset(self->lge_ctxt, 0, sizeof(GstAmlV4l2VideoDecLgeCtxt));
1390#endif
xuesong.jiangae1548e2022-05-06 16:38:46 +08001391}
1392
1393static void
1394gst_aml_v4l2_video_dec_subinstance_init(GTypeInstance *instance, gpointer g_class)
1395{
1396 GstAmlV4l2VideoDecClass *klass = GST_AML_V4L2_VIDEO_DEC_CLASS(g_class);
1397 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(instance);
1398 GstVideoDecoder *decoder = GST_VIDEO_DECODER(instance);
1399
1400 gst_video_decoder_set_packetized(decoder, TRUE);
1401
1402 self->v4l2output = gst_aml_v4l2_object_new(GST_ELEMENT(self),
1403 GST_OBJECT(GST_VIDEO_DECODER_SINK_PAD(self)),
1404 V4L2_BUF_TYPE_VIDEO_OUTPUT, klass->default_device,
1405 gst_aml_v4l2_get_output, gst_aml_v4l2_set_output, NULL);
1406 self->v4l2output->no_initial_format = TRUE;
1407 self->v4l2output->keep_aspect = FALSE;
sheng.liu0c77f6c2022-06-17 21:33:20 +08001408 self->v4l2output->is_svp = FALSE;
xuesong.jiangae1548e2022-05-06 16:38:46 +08001409
1410 self->v4l2capture = gst_aml_v4l2_object_new(GST_ELEMENT(self),
1411 GST_OBJECT(GST_VIDEO_DECODER_SRC_PAD(self)),
1412 V4L2_BUF_TYPE_VIDEO_CAPTURE, klass->default_device,
1413 gst_aml_v4l2_get_input, gst_aml_v4l2_set_input, NULL);
1414 self->v4l2capture->need_wait_event = TRUE;
sheng.liub56bbc52022-06-21 11:02:33 +08001415 self->v4l2capture->need_drop_event = FALSE;
xuesong.jiangae1548e2022-05-06 16:38:46 +08001416}
1417
1418static void
1419gst_aml_v4l2_video_dec_class_init(GstAmlV4l2VideoDecClass *klass)
1420{
1421 GstElementClass *element_class;
1422 GObjectClass *gobject_class;
1423 GstVideoDecoderClass *video_decoder_class;
1424
1425 parent_class = g_type_class_peek_parent(klass);
1426
1427 element_class = (GstElementClass *)klass;
1428 gobject_class = (GObjectClass *)klass;
1429 video_decoder_class = (GstVideoDecoderClass *)klass;
1430
1431 GST_DEBUG_CATEGORY_INIT(gst_aml_v4l2_video_dec_debug, "amlv4l2videodec", 0,
1432 "AML V4L2 Video Decoder");
1433
1434 gobject_class->dispose = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_dispose);
1435 gobject_class->finalize = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_finalize);
1436 gobject_class->set_property =
1437 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_set_property);
1438 gobject_class->get_property =
1439 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_get_property);
1440
1441 video_decoder_class->open = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_open);
1442 video_decoder_class->close = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_close);
1443 video_decoder_class->start = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_start);
1444 video_decoder_class->stop = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_stop);
1445 video_decoder_class->finish = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_finish);
1446 video_decoder_class->flush = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_flush);
1447 video_decoder_class->drain = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_drain);
1448 video_decoder_class->set_format =
1449 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_set_format);
1450 video_decoder_class->negotiate =
1451 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_negotiate);
1452 video_decoder_class->decide_allocation =
1453 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_decide_allocation);
1454 /* FIXME propose_allocation or not ? */
1455 video_decoder_class->handle_frame =
1456 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_handle_frame);
1457 video_decoder_class->getcaps =
1458 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_sink_getcaps);
1459 video_decoder_class->src_query =
1460 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_src_query);
1461 video_decoder_class->sink_event =
1462 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_sink_event);
1463
1464 element_class->change_state =
1465 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_change_state);
1466
1467 gst_aml_v4l2_object_install_m2m_properties_helper(gobject_class);
xuesong.jiang61ea8012022-05-12 15:38:17 +08001468#if GST_IMPORT_LGE_PROP
1469 gst_aml_v4l2_video_dec_install_lge_properties_helper(gobject_class);
1470#endif
xuesong.jiangae1548e2022-05-06 16:38:46 +08001471}
1472
1473static void
1474gst_aml_v4l2_video_dec_subclass_init(gpointer g_class, gpointer data)
1475{
1476 GstAmlV4l2VideoDecClass *klass = GST_AML_V4L2_VIDEO_DEC_CLASS(g_class);
1477 GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
1478 GstAmlV4l2VideoDecCData *cdata = data;
1479
1480 klass->default_device = cdata->device;
1481
1482 /* Note: gst_pad_template_new() take the floating ref from the caps */
1483 gst_element_class_add_pad_template(element_class,
1484 gst_pad_template_new("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
1485 cdata->sink_caps));
1486 gst_element_class_add_pad_template(element_class,
1487 gst_pad_template_new("src", GST_PAD_SRC, GST_PAD_ALWAYS,
1488 cdata->src_caps));
1489
1490 gst_element_class_set_metadata(element_class, cdata->longname,
1491 "Codec/Decoder/Video/Hardware", cdata->description,
1492 "Xuesong Jiang <Xuesong.Jiang@amlogic.com>");
1493
1494 gst_caps_unref(cdata->sink_caps);
1495 gst_caps_unref(cdata->src_caps);
1496 g_free(cdata);
1497}
1498
1499/* Probing functions */
1500gboolean
1501gst_aml_v4l2_is_video_dec(GstCaps *sink_caps, GstCaps *src_caps)
1502{
1503 gboolean ret = FALSE;
1504
1505 if (gst_caps_is_subset(sink_caps, gst_aml_v4l2_object_get_codec_caps()) && gst_caps_is_subset(src_caps, gst_aml_v4l2_object_get_raw_caps()))
1506 ret = TRUE;
1507
1508 return ret;
1509}
1510
1511static gchar *
1512gst_aml_v4l2_video_dec_set_metadata(GstStructure *s, GstAmlV4l2VideoDecCData *cdata,
1513 const gchar *basename)
1514{
1515 gchar *codec_name = NULL;
1516 gchar *type_name = NULL;
1517 gboolean got_value = FALSE;
1518
1519#define SET_META(codec) \
1520 G_STMT_START \
1521 { \
1522 cdata->longname = "AML V4L2 " codec " Decoder"; \
1523 cdata->description = "Decodes " codec " streams via V4L2 API"; \
1524 codec_name = g_ascii_strdown(codec, -1); \
1525 } \
1526 G_STMT_END
1527
1528 if (gst_structure_has_name(s, "image/jpeg"))
1529 {
1530 SET_META("JPEG");
1531 }
1532 else if (gst_structure_has_name(s, "video/mpeg"))
1533 {
1534 gint mpegversion = 0;
1535 gint *list = NULL;
1536 got_value = gst_structure_get_int(s, "mpegversion", &mpegversion);
1537 if (FALSE == got_value)
1538 {
1539 got_value = gst_structure_get_list(s, "mpegversion", &list);
1540 if (TRUE == got_value && (1 == *list || 2 == *list))
1541 {
1542 SET_META("MPEG2");
1543 }
1544 else
1545 {
1546 SET_META("MPEG4");
1547 }
1548 }
1549 else
1550 {
1551 SET_META("MPEG4");
1552 }
1553 }
1554 else if (gst_structure_has_name(s, "video/x-h263"))
1555 {
1556 SET_META("H263");
1557 }
1558 else if (gst_structure_has_name(s, "video/x-fwht"))
1559 {
1560 SET_META("FWHT");
1561 }
1562 else if (gst_structure_has_name(s, "video/x-h264"))
1563 {
1564 SET_META("H264");
1565 }
1566 else if (gst_structure_has_name(s, "video/x-h265"))
1567 {
1568 SET_META("H265");
1569 }
1570 else if (gst_structure_has_name(s, "video/x-wmv"))
1571 {
1572 SET_META("VC1");
1573 }
1574 else if (gst_structure_has_name(s, "video/x-vp8"))
1575 {
1576 SET_META("VP8");
1577 }
1578 else if (gst_structure_has_name(s, "video/x-vp9"))
1579 {
1580 SET_META("VP9");
1581 }
1582 else if (gst_structure_has_name(s, "video/x-av1"))
1583 {
1584 SET_META("AV1");
1585 }
1586 else if (gst_structure_has_name(s, "video/x-bayer"))
1587 {
1588 SET_META("BAYER");
1589 }
1590 else if (gst_structure_has_name(s, "video/x-sonix"))
1591 {
1592 SET_META("SONIX");
1593 }
1594 else if (gst_structure_has_name(s, "video/x-pwc1"))
1595 {
1596 SET_META("PWC1");
1597 }
1598 else if (gst_structure_has_name(s, "video/x-pwc2"))
1599 {
1600 SET_META("PWC2");
1601 }
1602 else
1603 {
1604 /* This code should be kept on sync with the exposed CODEC type of format
1605 * from gstamlv4l2object.c. This warning will only occure in case we forget
1606 * to also add a format here. */
1607 gchar *s_str = gst_structure_to_string(s);
1608 g_warning("Missing fixed name mapping for caps '%s', this is a GStreamer "
1609 "bug, please report at https://bugs.gnome.org",
1610 s_str);
1611 g_free(s_str);
1612 }
1613
1614 if (codec_name)
1615 {
1616 type_name = g_strdup_printf("amlv4l2%sdec", codec_name);
1617 if (g_type_from_name(type_name) != 0)
1618 {
1619 g_free(type_name);
1620 type_name = g_strdup_printf("amlv4l2%s%sdec", basename, codec_name);
1621 }
1622
1623 g_free(codec_name);
1624 }
1625
1626 return type_name;
1627#undef SET_META
1628}
1629
1630void gst_aml_v4l2_video_dec_register(GstPlugin *plugin, const gchar *basename,
1631 const gchar *device_path, GstCaps *sink_caps, GstCaps *src_caps)
1632{
1633 gint i;
1634
1635 for (i = 0; i < gst_caps_get_size(sink_caps); i++)
1636 {
1637 GstAmlV4l2VideoDecCData *cdata;
1638 GstStructure *s;
1639 GTypeQuery type_query;
1640 GTypeInfo type_info = {
1641 0,
1642 };
1643 GType type, subtype;
1644 gchar *type_name;
1645
1646 s = gst_caps_get_structure(sink_caps, i);
1647
1648 cdata = g_new0(GstAmlV4l2VideoDecCData, 1);
1649 cdata->device = g_strdup(device_path);
1650 cdata->sink_caps = gst_caps_new_empty();
1651 gst_caps_append_structure(cdata->sink_caps, gst_structure_copy(s));
1652 gst_caps_append_structure(cdata->sink_caps, gst_structure_copy(s));
1653 gst_caps_set_features(cdata->sink_caps, 0, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF));
1654 cdata->src_caps = gst_caps_copy(src_caps);
1655 gst_caps_set_features_simple(cdata->src_caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF));
1656 gst_caps_append(cdata->src_caps, gst_caps_copy(src_caps));
1657 type_name = gst_aml_v4l2_video_dec_set_metadata(s, cdata, basename);
1658
1659 /* Skip over if we hit an unmapped type */
1660 if (!type_name)
1661 {
1662 g_free(cdata);
1663 continue;
1664 }
1665
1666 type = gst_aml_v4l2_video_dec_get_type();
1667 g_type_query(type, &type_query);
1668 memset(&type_info, 0, sizeof(type_info));
1669 type_info.class_size = type_query.class_size;
1670 type_info.instance_size = type_query.instance_size;
1671 type_info.class_init = gst_aml_v4l2_video_dec_subclass_init;
1672 type_info.class_data = cdata;
1673 type_info.instance_init = gst_aml_v4l2_video_dec_subinstance_init;
1674
1675 subtype = g_type_register_static(type, type_name, &type_info, 0);
1676 if (!gst_element_register(plugin, type_name, GST_RANK_PRIMARY + 1,
1677 subtype))
1678 GST_WARNING("Failed to register plugin '%s'", type_name);
1679
1680 g_free(type_name);
1681 }
1682}
xuesong.jiang61ea8012022-05-12 15:38:17 +08001683
1684#if GST_IMPORT_LGE_PROP
1685static void gst_aml_v4l2_video_dec_install_lge_properties_helper(GObjectClass *gobject_class)
1686{
1687 g_object_class_install_property(gobject_class, LGE_RESOURCE_INFO,
1688 g_param_spec_object("resource-info", "resource-info",
1689 "After acquisition of H/W resources is completed, allocated resource information must be delivered to the decoder and the sink",
1690 GST_TYPE_STRUCTURE,
1691 G_PARAM_READABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
1692
1693 g_object_class_install_property(gobject_class, LGE_DECODE_SIZE,
1694 g_param_spec_uint64("decoded-size", "decoded-size",
1695 "The total amount of decoder element's decoded video es after constructing pipeline or flushing pipeline update unit is byte.",
1696 0, G_MAXUINT64,
1697 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1698
1699 g_object_class_install_property(gobject_class, LGE_UNDECODE_SIZE,
1700 g_param_spec_uint64("undecoded-size", "undecoded-size",
1701 "video decoder element's total undecoded data update unit is byte.",
1702 0, G_MAXUINT64,
1703 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1704
1705 g_object_class_install_property(gobject_class, LGE_APP_TYPE,
1706 g_param_spec_string("app-type", "app-type",
1707 "set application type.",
1708 "default_app",
1709 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1710
1711 g_object_class_install_property(gobject_class, LGE_CLIP_MODE,
1712 g_param_spec_boolean("clip-mode", "clip-mode",
1713 "When seeking, Content is moving faster for a while to skip frames.",
1714 FALSE,
1715 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1716}
1717#endif