blob: 633f0e50934a49181e8a150f81a1441570097c22 [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 { \
xuesong.jiang61ea8012022-05-12 15:38:17 +080044 GST_INFO("aml v4l2 dec locking"); \
xuesong.jiangae1548e2022-05-06 16:38:46 +080045 g_rec_mutex_lock(&GST_VIDEO_DECODER(decoder)->stream_lock); \
xuesong.jiang61ea8012022-05-12 15:38:17 +080046 GST_INFO("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 { \
xuesong.jiang252f6862022-05-07 14:53:41 +080054 GST_INFO("aml v4l2 dec unlocking"); \
xuesong.jiangae1548e2022-05-06 16:38:46 +080055 g_rec_mutex_unlock(&GST_VIDEO_DECODER(decoder)->stream_lock); \
xuesong.jiang61ea8012022-05-12 15:38:17 +080056 GST_INFO("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
405 ret = gst_aml_v4l2_object_set_format(self->v4l2output, state->caps, &error);
406
407 gst_caps_replace(&self->probed_srccaps, NULL);
408 self->probed_srccaps = gst_aml_v4l2_object_probe_caps(self->v4l2capture,
409 gst_aml_v4l2_object_get_raw_caps());
410
411 if (gst_caps_is_empty(self->probed_srccaps))
412 goto no_raw_format;
413
414 caps = gst_caps_copy(self->probed_srccaps);
415 gst_caps_set_features_simple(caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF));
416 gst_caps_append(self->probed_srccaps, caps);
417 if (ret)
418 self->input_state = gst_video_codec_state_ref(state);
419 else
420 gst_aml_v4l2_error(self, &error);
421
422done:
423 return ret;
424
425no_raw_format:
426 GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
427 (_("Decoder on device %s has no supported output format"),
428 self->v4l2output->videodev),
429 (NULL));
430 return GST_FLOW_ERROR;
431}
432
433static gboolean
434gst_aml_v4l2_video_dec_flush(GstVideoDecoder *decoder)
435{
436 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
437
438 GST_DEBUG_OBJECT(self, "Flushed");
439
440 /* Ensure the processing thread has stopped for the reverse playback
441 * discount case */
442 if (gst_pad_get_task_state(decoder->srcpad) == GST_TASK_STARTED)
443 {
444 GST_VIDEO_DECODER_STREAM_UNLOCK(decoder);
445
446 gst_aml_v4l2_object_unlock(self->v4l2output);
447 gst_aml_v4l2_object_unlock(self->v4l2capture);
448 gst_pad_stop_task(decoder->srcpad);
449 GST_VIDEO_DECODER_STREAM_LOCK(decoder);
450 }
451
452 self->output_flow = GST_FLOW_OK;
453
454 gst_aml_v4l2_object_unlock_stop(self->v4l2output);
455 gst_aml_v4l2_object_unlock_stop(self->v4l2capture);
456
457 if (self->v4l2output->pool)
458 gst_aml_v4l2_buffer_pool_flush(self->v4l2output->pool);
459
460 /* gst_aml_v4l2_buffer_pool_flush() calls streamon the capture pool and must be
461 * called after gst_aml_v4l2_object_unlock_stop() stopped flushing the buffer
462 * pool. */
463 if (self->v4l2capture->pool)
464 gst_aml_v4l2_buffer_pool_flush(self->v4l2capture->pool);
465
466 return TRUE;
467}
468
469static gboolean
470gst_aml_v4l2_video_dec_negotiate(GstVideoDecoder *decoder)
471{
472 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
473
xuesong.jiang681d3602022-06-24 21:23:35 +0800474 if (TRUE == self->v4l2output->is_svp)
475 {
476 GstStructure *s;
477 GstEvent *event;
478
479 s = gst_structure_new_empty ("IS_SVP");
480 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_STICKY, s);
481 GST_DEBUG_OBJECT(self, "before Send SVP Event :%p", event);
482 gst_pad_push_event (decoder->srcpad, event);
483 GST_DEBUG_OBJECT(self, "after Send SVP Event :%p", event);
484 }
485
xuesong.jiangae1548e2022-05-06 16:38:46 +0800486 /* We don't allow renegotiation without carefull disabling the pool */
487 if (self->v4l2capture->pool &&
488 gst_buffer_pool_is_active(GST_BUFFER_POOL(self->v4l2capture->pool)))
489 return TRUE;
490
491 return GST_VIDEO_DECODER_CLASS(parent_class)->negotiate(decoder);
492}
493
494static gboolean
495gst_aml_v4l2_decoder_cmd(GstAmlV4l2Object *v4l2object, guint cmd, guint flags)
496{
497 struct v4l2_decoder_cmd dcmd = {
498 0,
499 };
500
501 GST_DEBUG_OBJECT(v4l2object->element,
502 "sending v4l2 decoder command %u with flags %u", cmd, flags);
503
504 if (!GST_AML_V4L2_IS_OPEN(v4l2object))
505 return FALSE;
506
507 dcmd.cmd = cmd;
508 dcmd.flags = flags;
509 if (v4l2object->ioctl(v4l2object->video_fd, VIDIOC_DECODER_CMD, &dcmd) < 0)
510 goto dcmd_failed;
511
512 return TRUE;
513
514dcmd_failed:
515 if (errno == ENOTTY)
516 {
517 GST_INFO_OBJECT(v4l2object->element,
518 "Failed to send decoder command %u with flags %u for '%s'. (%s)",
519 cmd, flags, v4l2object->videodev, g_strerror(errno));
520 }
521 else
522 {
523 GST_ERROR_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 return FALSE;
528}
529
530static GstFlowReturn
531gst_aml_v4l2_video_dec_finish(GstVideoDecoder *decoder)
532{
533 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
534 GstFlowReturn ret = GST_FLOW_OK;
535 GstBuffer *buffer;
536
537 if (gst_pad_get_task_state(decoder->srcpad) != GST_TASK_STARTED)
538 goto done;
539
540 GST_DEBUG_OBJECT(self, "Finishing decoding");
541
542 GST_VIDEO_DECODER_STREAM_UNLOCK(decoder);
543
544 if (gst_aml_v4l2_decoder_cmd(self->v4l2output, V4L2_DEC_CMD_STOP, 0))
545 {
546 GstTask *task = decoder->srcpad->task;
547
548 /* If the decoder stop command succeeded, just wait until processing is
549 * finished */
550 GST_DEBUG_OBJECT(self, "Waiting for decoder stop");
551 GST_OBJECT_LOCK(task);
552 while (GST_TASK_STATE(task) == GST_TASK_STARTED)
553 GST_TASK_WAIT(task);
554 GST_OBJECT_UNLOCK(task);
555 ret = GST_FLOW_FLUSHING;
556 }
557 else
558 {
559 /* otherwise keep queuing empty buffers until the processing thread has
560 * stopped, _pool_process() will return FLUSHING when that happened */
561 while (ret == GST_FLOW_OK)
562 {
xuesong.jiangc5dac0f2023-02-01 14:42:24 +0800563 GST_DEBUG_OBJECT(self, "queue empty output buf");
xuesong.jiangae1548e2022-05-06 16:38:46 +0800564 buffer = gst_buffer_new();
565 ret =
566 gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &buffer);
567 gst_buffer_unref(buffer);
568 }
569 }
570
571 /* and ensure the processing thread has stopped in case another error
572 * occured. */
573 gst_aml_v4l2_object_unlock(self->v4l2capture);
574 gst_pad_stop_task(decoder->srcpad);
575 GST_VIDEO_DECODER_STREAM_LOCK(decoder);
576
577 if (ret == GST_FLOW_FLUSHING)
578 ret = self->output_flow;
579
580 GST_DEBUG_OBJECT(decoder, "Done draining buffers");
581
582 /* TODO Shall we cleanup any reffed frame to workaround broken decoders ? */
583
584done:
585 return ret;
586}
587
588static GstFlowReturn
589gst_aml_v4l2_video_dec_drain(GstVideoDecoder *decoder)
590{
591 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
592
593 GST_DEBUG_OBJECT(self, "Draining...");
594 gst_aml_v4l2_video_dec_finish(decoder);
595 gst_aml_v4l2_video_dec_flush(decoder);
596
597 return GST_FLOW_OK;
598}
599
600static GstVideoCodecFrame *
601gst_aml_v4l2_video_dec_get_oldest_frame(GstVideoDecoder *decoder)
602{
603 GstVideoCodecFrame *frame = NULL;
604 GList *frames, *l;
605 gint count = 0;
606
607 frames = gst_video_decoder_get_frames(decoder);
608
609 for (l = frames; l != NULL; l = l->next)
610 {
611 GstVideoCodecFrame *f = l->data;
612
613 if (!frame || (GST_CLOCK_TIME_IS_VALID(frame->pts) && GST_CLOCK_TIME_IS_VALID(f->pts) && (frame->pts > f->pts)))
614 frame = f;
615
616 count++;
617 }
618
619 if (frame)
620 {
621 GST_LOG_OBJECT(decoder,
622 "Oldest frame is %d %" GST_TIME_FORMAT " and %d frames left",
623 frame->system_frame_number, GST_TIME_ARGS(frame->pts), count - 1);
624 gst_video_codec_frame_ref(frame);
625 }
626
627 g_list_free_full(frames, (GDestroyNotify)gst_video_codec_frame_unref);
628
629 return frame;
630}
631
fei.dengbee20862022-06-14 14:59:48 +0800632static GstVideoCodecFrame *
633gst_aml_v4l2_video_dec_get_right_frame(GstVideoDecoder *decoder, GstClockTime pts)
634{
635 GstVideoCodecFrame *frame = NULL;
636 GList *frames, *l;
637 gint count = 0;
638
639 frames = gst_video_decoder_get_frames(decoder);
640
641 for (l = frames; l != NULL; l = l->next)
642 {
643 GstVideoCodecFrame *f = l->data;
xuesong.jiangc5dac0f2023-02-01 14:42:24 +0800644 if (GST_CLOCK_TIME_IS_VALID(pts) && (ABSDIFF(f->pts,pts)) < 1000) {
fei.dengbee20862022-06-14 14:59:48 +0800645 frame = f;
646 break;
647 } else {
648 if (!frame || (GST_CLOCK_TIME_IS_VALID(frame->pts) && GST_CLOCK_TIME_IS_VALID(f->pts) && (frame->pts > f->pts)))
649 frame = f;
650 }
651
652 count++;
653 }
654
655 if (frame)
656 {
657 GST_LOG_OBJECT(decoder,
658 "frame is %d %" GST_TIME_FORMAT " and %d frames left",
659 frame->system_frame_number, GST_TIME_ARGS(frame->pts), count - 1);
660 gst_video_codec_frame_ref(frame);
661 }
662
663 g_list_free_full(frames, (GDestroyNotify)gst_video_codec_frame_unref);
664
665 return frame;
666}
667
xuesong.jiangae1548e2022-05-06 16:38:46 +0800668static gboolean
669gst_aml_v4l2_video_remove_padding(GstCapsFeatures *features,
670 GstStructure *structure, gpointer user_data)
671{
672 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(user_data);
673 GstVideoAlignment *align = &self->v4l2capture->align;
674 GstVideoInfo *info = &self->v4l2capture->info;
675 int width, height;
676
677 if (!gst_structure_get_int(structure, "width", &width))
678 return TRUE;
679
680 if (!gst_structure_get_int(structure, "height", &height))
681 return TRUE;
682
683 if (align->padding_left != 0 || align->padding_top != 0 ||
684 height != info->height + align->padding_bottom)
685 return TRUE;
686
687 if (height == info->height + align->padding_bottom)
688 {
689 /* Some drivers may round up width to the padded with */
690 if (width == info->width + align->padding_right)
691 gst_structure_set(structure,
692 "width", G_TYPE_INT, width - align->padding_right,
693 "height", G_TYPE_INT, height - align->padding_bottom, NULL);
694 /* Some drivers may keep visible width and only round up bytesperline */
695 else if (width == info->width)
696 gst_structure_set(structure,
697 "height", G_TYPE_INT, height - align->padding_bottom, NULL);
698 }
699
700 return TRUE;
701}
702
703static void
sheng.liubcf036c2022-06-21 15:55:42 +0800704gst_v4l2_drop_event (GstAmlV4l2Object * v4l2object)
sheng.liub56bbc52022-06-21 11:02:33 +0800705{
706 struct v4l2_event evt;
707 gint ret;
708
709 memset (&evt, 0x00, sizeof (struct v4l2_event));
710 ret = v4l2object->ioctl (v4l2object->video_fd, VIDIOC_DQEVENT, &evt);
711 if (ret < 0)
712 {
713 GST_DEBUG_OBJECT (v4l2object, "dqevent failed");
714 return;
715 }
716
717 switch (evt.type)
718 {
719 case V4L2_EVENT_SOURCE_CHANGE:
720 GST_DEBUG_OBJECT (v4l2object, "Drop GST_V4L2_FLOW_SOURCE_CHANGE");
721 break;
722 case V4L2_EVENT_EOS:
723 GST_DEBUG_OBJECT (v4l2object, "Drop GST_V4L2_FLOW_LAST_BUFFER");
724 break;
725 default:
726 break;
727 }
728
729 return;
730}
731
732static void
xuesong.jiangae1548e2022-05-06 16:38:46 +0800733gst_aml_v4l2_video_dec_loop(GstVideoDecoder *decoder)
734{
735 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
736 GstAmlV4l2BufferPool *v4l2_pool;
737 GstAmlV4l2Error error = GST_AML_V4L2_ERROR_INIT;
738 GstBufferPool *pool;
739 GstVideoCodecFrame *frame;
740 GstBuffer *buffer = NULL;
741 GstFlowReturn ret;
742
743 if (G_UNLIKELY(!GST_AML_V4L2_IS_ACTIVE(self->v4l2capture)))
744 {
745 GstVideoInfo info;
746 GstVideoCodecState *output_state;
747 GstCaps *acquired_caps, *available_caps, *caps, *filter;
748 GstStructure *st;
749
750 GST_DEBUG_OBJECT(self, "waitting source change event");
751 /* Wait until received SOURCE_CHANGE event to get right video format */
752 while (self->v4l2capture->can_wait_event && self->v4l2capture->need_wait_event)
753 {
754 ret = gst_aml_v4l2_object_dqevent(self->v4l2capture);
755 if (ret == GST_AML_V4L2_FLOW_SOURCE_CHANGE)
756 {
757 GST_DEBUG_OBJECT(self, "Received source change event");
758 break;
759 }
760 else if (ret == GST_AML_V4L2_FLOW_LAST_BUFFER)
761 {
762 GST_DEBUG_OBJECT(self, "Received eos event");
763 goto beach;
764 }
765 else if (ret != GST_FLOW_OK)
766 {
767 GST_ERROR_OBJECT(self, "dqevent error");
768 goto beach;
769 }
770 }
771 self->v4l2capture->need_wait_event = FALSE;
772
sheng.liu0c77f6c2022-06-17 21:33:20 +0800773 if (TRUE == self->v4l2output->is_svp)
774 {
775 GstPad *peer;
776 GstStructure *s;
777 GstEvent *event;
778
779 peer = gst_pad_get_peer (decoder->srcpad);
780 if (peer)
781 {
782 s = gst_structure_new_empty ("IS_SVP");
783 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
784 gst_pad_send_event (peer, event);
785 GST_DEBUG_OBJECT(self, "Send SVP Event");
786 gst_object_unref (peer);
787 }
788 }
789
sheng.liub56bbc52022-06-21 11:02:33 +0800790 if (self->v4l2capture->need_drop_event)
791 {
792 // drop V4L2_EVENT_SOURCE_CHANGE
793 gst_v4l2_drop_event(self->v4l2capture);
794 self->v4l2capture->need_drop_event = FALSE;
795 }
796
xuesong.jiangae1548e2022-05-06 16:38:46 +0800797 if (!gst_aml_v4l2_object_acquire_format(self->v4l2capture, &info))
798 goto not_negotiated;
799
800 /* Create caps from the acquired format, remove the format field */
801 acquired_caps = gst_video_info_to_caps(&info);
802 GST_DEBUG_OBJECT(self, "Acquired caps: %" GST_PTR_FORMAT, acquired_caps);
803 st = gst_caps_get_structure(acquired_caps, 0);
804 gst_structure_remove_fields(st, "format", "colorimetry", "chroma-site",
805 NULL);
806
807 /* Probe currently available pixel formats */
808 available_caps = gst_caps_copy(self->probed_srccaps);
809 GST_DEBUG_OBJECT(self, "Available caps: %" GST_PTR_FORMAT, available_caps);
810
811 /* Replace coded size with visible size, we want to negotiate visible size
812 * with downstream, not coded size. */
813 gst_caps_map_in_place(available_caps, gst_aml_v4l2_video_remove_padding, self);
814
815 filter = gst_caps_intersect_full(available_caps, acquired_caps,
816 GST_CAPS_INTERSECT_FIRST);
817 caps = gst_caps_copy(filter);
818 gst_caps_set_features_simple(caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF));
819 gst_caps_append(filter, caps);
820
821 GST_DEBUG_OBJECT(self, "Filtered caps: %" GST_PTR_FORMAT, filter);
822 gst_caps_unref(acquired_caps);
823 gst_caps_unref(available_caps);
824 caps = gst_pad_peer_query_caps(decoder->srcpad, filter);
825 gst_caps_unref(filter);
826
827 GST_DEBUG_OBJECT(self, "Possible decoded caps: %" GST_PTR_FORMAT, caps);
828 if (gst_caps_is_empty(caps))
829 {
830 gst_caps_unref(caps);
831 goto not_negotiated;
832 }
833
834 /* Fixate pixel format */
835 caps = gst_caps_fixate(caps);
836
837 GST_DEBUG_OBJECT(self, "Chosen decoded caps: %" GST_PTR_FORMAT, caps);
838
839 /* Try to set negotiated format, on success replace acquired format */
840 if (gst_aml_v4l2_object_set_format(self->v4l2capture, caps, &error))
841 gst_video_info_from_caps(&info, caps);
842 else
843 gst_aml_v4l2_clear_error(&error);
844 gst_caps_unref(caps);
845
846 output_state = gst_video_decoder_set_output_state(decoder,
847 info.finfo->format, info.width, info.height, self->input_state);
848
849 /* Copy the rest of the information, there might be more in the future */
850 output_state->info.interlace_mode = info.interlace_mode;
851 gst_video_codec_state_unref(output_state);
852
853 if (!gst_video_decoder_negotiate(decoder))
854 {
855 if (GST_PAD_IS_FLUSHING(decoder->srcpad))
856 goto flushing;
857 else
858 goto not_negotiated;
859 }
860
861 /* Ensure our internal pool is activated */
862 if (!gst_buffer_pool_set_active(GST_BUFFER_POOL(self->v4l2capture->pool),
863 TRUE))
864 goto activate_failed;
xuesong.jiangc5dac0f2023-02-01 14:42:24 +0800865
866 g_mutex_lock(&self->res_chg_lock);
867 GST_LOG_OBJECT(decoder, "signal resolution changed");
868 self->is_res_chg = FALSE;
869 g_cond_signal(&self->res_chg_cond);
870 g_mutex_unlock(&self->res_chg_lock);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800871 }
872
873 GST_LOG_OBJECT(decoder, "Allocate output buffer");
874
875 v4l2_pool = GST_AML_V4L2_BUFFER_POOL(self->v4l2capture->pool);
876
877 self->output_flow = GST_FLOW_OK;
878 do
879 {
880 /* We cannot use the base class allotate helper since it taking the internal
881 * stream lock. we know that the acquire may need to poll until more frames
882 * comes in and holding this lock would prevent that.
883 */
884 pool = gst_video_decoder_get_buffer_pool(decoder);
885
886 /* Pool may be NULL if we started going to READY state */
887 if (pool == NULL)
888 {
fei.dengbee20862022-06-14 14:59:48 +0800889 GST_WARNING_OBJECT(decoder, "gst_video_decoder_get_buffer_pool goto beach");
xuesong.jiangae1548e2022-05-06 16:38:46 +0800890 ret = GST_FLOW_FLUSHING;
891 goto beach;
892 }
893
894 ret = gst_buffer_pool_acquire_buffer(pool, &buffer, NULL);
fei.dengccc89632022-07-15 19:10:17 +0800895 //calculate a new pts for interlace stream
896 if (ret == GST_FLOW_OK &&
897 self->v4l2capture->info.interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED)
898 {
899 //if buffer pts is valid, reduce 1/2 duration
900 if (GST_BUFFER_DURATION_IS_VALID(buffer))
901 {
902 GST_BUFFER_DURATION(buffer) = GST_BUFFER_DURATION(buffer)/2;
903 }
904 GST_BUFFER_FLAG_UNSET(buffer, GST_VIDEO_BUFFER_FLAG_INTERLACED);
905 //reset pts
fei.denga6ae3282022-07-15 19:50:30 +0800906 if (GST_BUFFER_TIMESTAMP (buffer) == 0LL || self->last_out_pts == GST_BUFFER_TIMESTAMP (buffer))
fei.dengccc89632022-07-15 19:10:17 +0800907 {
908 double rate = ((double)self->input_state->info.fps_n/(double)self->input_state->info.fps_d)*2;
909 GST_BUFFER_TIMESTAMP(buffer) = self->last_out_pts + 1000000000LL/rate;
910 }
911 }
912
xuesong.jiangae1548e2022-05-06 16:38:46 +0800913 g_object_unref(pool);
914
sheng.liu4e01a472022-06-21 15:38:25 +0800915 if (ret == GST_AML_V4L2_FLOW_LAST_BUFFER) {
sheng.liubcf036c2022-06-21 15:55:42 +0800916 GST_LOG_OBJECT(decoder, "Get GST_AML_V4L2_FLOW_LAST_BUFFER");
sheng.liub56bbc52022-06-21 11:02:33 +0800917 self->v4l2capture->need_drop_event = TRUE;
918 goto beach;
919 }
920
sheng.liu8d18ed22022-05-26 17:28:15 +0800921 if (ret == GST_AML_V4L2_FLOW_SOURCE_CHANGE)
922 {
923 GST_LOG_OBJECT(decoder, "Get GST_AML_V4L2_FLOW_SOURCE_CHANGE");
xuesong.jiangc5dac0f2023-02-01 14:42:24 +0800924
925 g_mutex_lock (&self->res_chg_lock);
926 self->is_res_chg = TRUE;
927 g_mutex_unlock (&self->res_chg_lock);
928
sheng.liu8d18ed22022-05-26 17:28:15 +0800929 gst_aml_v4l2_object_stop(self->v4l2capture);
930 return;
931 }
932
fei.dengbee20862022-06-14 14:59:48 +0800933 if (ret != GST_FLOW_OK) {
934 GST_WARNING_OBJECT(decoder, "gst_buffer_pool_acquire_buffer goto beach ret:%d",ret);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800935 goto beach;
fei.dengbee20862022-06-14 14:59:48 +0800936 }
xuesong.jiangae1548e2022-05-06 16:38:46 +0800937
xuesong.jiangc5dac0f2023-02-01 14:42:24 +0800938 GST_LOG_OBJECT(decoder, "Process output buffer (switching flow outstanding num:%d)", self->v4l2capture->outstanding_buf_num);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800939 ret = gst_aml_v4l2_buffer_pool_process(v4l2_pool, &buffer);
940 if (ret == GST_AML_V4L2_FLOW_SOURCE_CHANGE)
941 {
942 gst_aml_v4l2_object_stop(self->v4l2capture);
943 return;
944 }
945
946 } while (ret == GST_AML_V4L2_FLOW_CORRUPTED_BUFFER);
947
948 if (ret != GST_FLOW_OK)
949 goto beach;
950
fei.dengbee20862022-06-14 14:59:48 +0800951 frame = gst_aml_v4l2_video_dec_get_right_frame(decoder, GST_BUFFER_TIMESTAMP (buffer));
xuesong.jiangae1548e2022-05-06 16:38:46 +0800952 if (frame)
953 {
zengliang.li32cb11e2022-11-24 12:10:26 +0800954 if (!GST_CLOCK_TIME_IS_VALID(frame->pts))
955 {
956 double rate = ((double)self->input_state->info.fps_n/(double)self->input_state->info.fps_d);
957 GST_BUFFER_TIMESTAMP(buffer) = self->last_out_pts + 1000000000LL/rate;
958 }
fei.dengccc89632022-07-15 19:10:17 +0800959 self->last_out_pts = GST_BUFFER_TIMESTAMP(buffer);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800960 frame->output_buffer = buffer;
fei.dengccc89632022-07-15 19:10:17 +0800961 frame->pts = GST_BUFFER_TIMESTAMP(buffer);
962 frame->duration = GST_BUFFER_DURATION(buffer);
xuesong.jiangae1548e2022-05-06 16:38:46 +0800963 buffer = NULL;
964 ret = gst_video_decoder_finish_frame(decoder, frame);
965
966 if (ret != GST_FLOW_OK)
967 goto beach;
968 }
969 else
970 {
971 GST_WARNING_OBJECT(decoder, "Decoder is producing too many buffers");
972 gst_buffer_unref(buffer);
973 }
974
975 return;
976 /* ERRORS */
977not_negotiated:
978{
979 GST_ERROR_OBJECT(self, "not negotiated");
980 ret = GST_FLOW_NOT_NEGOTIATED;
981 goto beach;
982}
983activate_failed:
984{
985 GST_ERROR_OBJECT(self, "Buffer pool activation failed");
986 GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
987 (_("Failed to allocate required memory.")),
988 ("Buffer pool activation failed"));
989 ret = GST_FLOW_ERROR;
990 goto beach;
991}
992flushing:
993{
994 ret = GST_FLOW_FLUSHING;
995 goto beach;
996}
997beach:
998 GST_DEBUG_OBJECT(decoder, "Leaving output thread: %s",
999 gst_flow_get_name(ret));
1000
1001 gst_buffer_replace(&buffer, NULL);
1002 self->output_flow = ret;
1003 gst_aml_v4l2_object_unlock(self->v4l2output);
1004 gst_pad_pause_task(decoder->srcpad);
1005}
1006
1007static GstFlowReturn
1008gst_aml_v4l2_video_dec_handle_frame(GstVideoDecoder *decoder,
1009 GstVideoCodecFrame *frame)
1010{
1011 GstAmlV4l2Error error = GST_AML_V4L2_ERROR_INIT;
1012 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
1013 GstBufferPool *pool = GST_BUFFER_POOL(self->v4l2output->pool);
1014 GstFlowReturn ret = GST_FLOW_OK;
1015 gboolean processed = FALSE;
1016 GstBuffer *tmp;
1017 GstTaskState task_state;
1018 GstCaps *caps;
1019
1020 GST_DEBUG_OBJECT(self, "Handling frame %d", frame->system_frame_number);
1021
1022 if (G_UNLIKELY(!g_atomic_int_get(&self->active)))
1023 goto flushing;
1024
1025 if (G_UNLIKELY(!GST_AML_V4L2_IS_ACTIVE(self->v4l2output)))
1026 {
1027 if (!self->input_state)
1028 goto not_negotiated;
1029 if (!gst_aml_v4l2_object_set_format(self->v4l2output, self->input_state->caps,
1030 &error))
1031 goto not_negotiated;
1032 }
1033
1034 if (G_UNLIKELY(!GST_AML_V4L2_IS_ACTIVE(self->v4l2capture)))
1035 {
1036 GstBuffer *codec_data;
sheng.liu0c77f6c2022-06-17 21:33:20 +08001037 GstCapsFeatures *features = NULL;
1038
1039 features = gst_caps_get_features(self->input_state->caps, 0);
1040 if (features && gst_caps_features_contains(features, GST_CAPS_FEATURE_MEMORY_DMABUF))
1041 {
1042 GST_DEBUG_OBJECT(self, "Is SVP");
1043 self->v4l2output->is_svp = TRUE;
1044 }
xuesong.jiangae1548e2022-05-06 16:38:46 +08001045
1046 GST_DEBUG_OBJECT(self, "Sending header");
1047
1048 codec_data = self->input_state->codec_data;
1049
1050 /* We are running in byte-stream mode, so we don't know the headers, but
1051 * we need to send something, otherwise the decoder will refuse to
1052 * intialize.
1053 */
1054 if (codec_data)
1055 {
1056 gst_buffer_ref(codec_data);
1057 }
1058 else
1059 {
1060 codec_data = gst_buffer_ref(frame->input_buffer);
1061 processed = TRUE;
1062 }
1063
1064 /* Ensure input internal pool is active */
1065 if (!gst_buffer_pool_is_active(pool))
1066 {
1067 GstStructure *config = gst_buffer_pool_get_config(pool);
xuesong.jiangc5dac0f2023-02-01 14:42:24 +08001068 // guint min = MAX(self->v4l2output->min_buffers, GST_AML_V4L2_MIN_BUFFERS);
1069 // guint max = VIDEO_MAX_FRAME;
xuesong.jiangae1548e2022-05-06 16:38:46 +08001070 // gst_buffer_pool_config_set_params (config, self->input_state->caps,
1071 // self->v4l2output->info.size, min, max);
1072 gst_buffer_pool_config_set_params(config, self->input_state->caps, self->v4l2output->info.size, self->v4l2output->min_buffers, self->v4l2output->min_buffers);
1073
1074 /* There is no reason to refuse this config */
1075 if (!gst_buffer_pool_set_config(pool, config))
1076 goto activate_failed;
xuesong.jiangc5dac0f2023-02-01 14:42:24 +08001077 GST_DEBUG_OBJECT(self, "setting output pool config to %" GST_PTR_FORMAT, config);
xuesong.jiangae1548e2022-05-06 16:38:46 +08001078
1079 if (!gst_buffer_pool_set_active(pool, TRUE))
1080 goto activate_failed;
1081 }
1082
1083 GST_VIDEO_DECODER_STREAM_UNLOCK(decoder);
1084 ret =
1085 gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &codec_data);
1086 GST_VIDEO_DECODER_STREAM_LOCK(decoder);
1087
1088 gst_buffer_unref(codec_data);
1089
1090 /* For decoders G_FMT returns coded size, G_SELECTION returns visible size
1091 * in the compose rectangle. gst_aml_v4l2_object_acquire_format() checks both
1092 * and returns the visible size as with/height and the coded size as
1093 * padding. */
1094 }
1095
1096 task_state = gst_pad_get_task_state(GST_VIDEO_DECODER_SRC_PAD(self));
1097 if (task_state == GST_TASK_STOPPED || task_state == GST_TASK_PAUSED)
1098 {
1099 /* It's possible that the processing thread stopped due to an error */
1100 if (self->output_flow != GST_FLOW_OK &&
1101 self->output_flow != GST_FLOW_FLUSHING)
1102 {
1103 GST_DEBUG_OBJECT(self, "Processing loop stopped with error, leaving");
1104 ret = self->output_flow;
1105 goto drop;
1106 }
1107
1108 GST_DEBUG_OBJECT(self, "Starting decoding thread");
1109
1110 /* Start the processing task, when it quits, the task will disable input
1111 * processing to unlock input if draining, or prevent potential block */
1112 self->output_flow = GST_FLOW_FLUSHING;
1113 if (!gst_pad_start_task(decoder->srcpad,
1114 (GstTaskFunction)gst_aml_v4l2_video_dec_loop, self, NULL))
1115 goto start_task_failed;
1116 }
1117
1118 if (!processed)
1119 {
1120 GST_VIDEO_DECODER_STREAM_UNLOCK(decoder);
1121 ret =
1122 gst_aml_v4l2_buffer_pool_process(GST_AML_V4L2_BUFFER_POOL(self->v4l2output->pool), &frame->input_buffer);
1123 GST_VIDEO_DECODER_STREAM_LOCK(decoder);
1124
1125 if (ret == GST_FLOW_FLUSHING)
1126 {
1127 if (gst_pad_get_task_state(GST_VIDEO_DECODER_SRC_PAD(self)) !=
1128 GST_TASK_STARTED)
1129 ret = self->output_flow;
1130 goto drop;
1131 }
1132 else if (ret != GST_FLOW_OK)
1133 {
1134 goto process_failed;
1135 }
1136 }
1137
1138 /* No need to keep input arround */
1139 tmp = frame->input_buffer;
1140 frame->input_buffer = gst_buffer_new();
1141 gst_buffer_copy_into(frame->input_buffer, tmp,
1142 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS |
1143 GST_BUFFER_COPY_META,
1144 0, 0);
1145 gst_buffer_unref(tmp);
1146
1147 gst_video_codec_frame_unref(frame);
1148 return ret;
1149
1150 /* ERRORS */
1151not_negotiated:
1152{
1153 GST_ERROR_OBJECT(self, "not negotiated");
1154 ret = GST_FLOW_NOT_NEGOTIATED;
1155 gst_aml_v4l2_error(self, &error);
1156 goto drop;
1157}
1158activate_failed:
1159{
1160 GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
1161 (_("Failed to allocate required memory.")),
1162 ("Buffer pool activation failed"));
1163 ret = GST_FLOW_ERROR;
1164 goto drop;
1165}
1166flushing:
1167{
1168 ret = GST_FLOW_FLUSHING;
1169 goto drop;
1170}
1171
1172start_task_failed:
1173{
1174 GST_ELEMENT_ERROR(self, RESOURCE, FAILED,
1175 (_("Failed to start decoding thread.")), (NULL));
1176 ret = GST_FLOW_ERROR;
1177 goto drop;
1178}
1179process_failed:
1180{
1181 GST_ELEMENT_ERROR(self, RESOURCE, FAILED,
1182 (_("Failed to process frame.")),
1183 ("Maybe be due to not enough memory or failing driver"));
1184 ret = GST_FLOW_ERROR;
1185 goto drop;
1186}
1187drop:
1188{
1189 gst_video_decoder_drop_frame(decoder, frame);
1190 return ret;
1191}
1192}
1193
1194static gboolean
1195gst_aml_v4l2_video_dec_decide_allocation(GstVideoDecoder *decoder,
1196 GstQuery *query)
1197{
1198 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
1199 GstClockTime latency;
1200 gboolean ret = FALSE;
1201
1202 if (gst_aml_v4l2_object_decide_allocation(self->v4l2capture, query))
1203 ret = GST_VIDEO_DECODER_CLASS(parent_class)->decide_allocation(decoder, query);
1204
1205 if (GST_CLOCK_TIME_IS_VALID(self->v4l2capture->duration))
1206 {
1207 latency = self->v4l2capture->min_buffers * self->v4l2capture->duration;
1208 GST_DEBUG_OBJECT(self, "Setting latency: %" GST_TIME_FORMAT " (%" G_GUINT32_FORMAT " * %" G_GUINT64_FORMAT, GST_TIME_ARGS(latency),
1209 self->v4l2capture->min_buffers, self->v4l2capture->duration);
1210 gst_video_decoder_set_latency(decoder, latency, latency);
1211 }
1212 else
1213 {
1214 GST_WARNING_OBJECT(self, "Duration invalid, not setting latency");
1215 }
1216
1217 return ret;
1218}
1219
1220static gboolean
1221gst_aml_v4l2_video_dec_src_query(GstVideoDecoder *decoder, GstQuery *query)
1222{
1223 gboolean ret = TRUE;
1224 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
1225
1226 switch (GST_QUERY_TYPE(query))
1227 {
1228 case GST_QUERY_CAPS:
1229 {
1230 GstCaps *filter, *result = NULL;
1231 GstPad *pad = GST_VIDEO_DECODER_SRC_PAD(decoder);
1232
1233 gst_query_parse_caps(query, &filter);
1234
1235 if (self->probed_srccaps)
1236 result = gst_caps_ref(self->probed_srccaps);
1237 else
1238 result = gst_pad_get_pad_template_caps(pad);
1239
1240 if (filter)
1241 {
1242 GstCaps *tmp = result;
1243 result =
1244 gst_caps_intersect_full(filter, tmp, GST_CAPS_INTERSECT_FIRST);
1245 gst_caps_unref(tmp);
1246 }
1247
1248 GST_DEBUG_OBJECT(self, "Returning src caps %" GST_PTR_FORMAT, result);
1249
1250 gst_query_set_caps_result(query, result);
1251 gst_caps_unref(result);
1252 break;
1253 }
1254
1255 default:
1256 ret = GST_VIDEO_DECODER_CLASS(parent_class)->src_query(decoder, query);
1257 break;
1258 }
1259
1260 return ret;
1261}
1262
1263static GstCaps *
1264gst_aml_v4l2_video_dec_sink_getcaps(GstVideoDecoder *decoder, GstCaps *filter)
1265{
1266 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
1267 GstCaps *result;
1268
1269 result = gst_video_decoder_proxy_getcaps(decoder, self->probed_sinkcaps,
1270 filter);
1271
1272 GST_DEBUG_OBJECT(self, "Returning sink caps %" GST_PTR_FORMAT, result);
1273
1274 return result;
1275}
1276
1277static gboolean
1278gst_aml_v4l2_video_dec_sink_event(GstVideoDecoder *decoder, GstEvent *event)
1279{
1280 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(decoder);
1281 gboolean ret;
1282 GstEventType type = GST_EVENT_TYPE(event);
1283
1284 switch (type)
1285 {
1286 case GST_EVENT_FLUSH_START:
1287 GST_DEBUG_OBJECT(self, "flush start");
xuesong.jiangc5dac0f2023-02-01 14:42:24 +08001288
1289 g_mutex_lock (&self->res_chg_lock);
1290 while (self->is_res_chg)
1291 {
1292 GST_LOG_OBJECT(decoder, "wait resolution change finish");
1293 g_cond_wait(&self->res_chg_cond, &self->res_chg_lock);
1294 }
1295 g_mutex_unlock (&self->res_chg_lock);
1296
xuesong.jiangae1548e2022-05-06 16:38:46 +08001297 gst_aml_v4l2_object_unlock(self->v4l2output);
1298 gst_aml_v4l2_object_unlock(self->v4l2capture);
1299 break;
1300 default:
1301 break;
1302 }
1303
1304 ret = GST_VIDEO_DECODER_CLASS(parent_class)->sink_event(decoder, event);
1305
1306 switch (type)
1307 {
1308 case GST_EVENT_FLUSH_START:
1309 /* The processing thread should stop now, wait for it */
1310 gst_pad_stop_task(decoder->srcpad);
1311 GST_DEBUG_OBJECT(self, "flush start done");
1312 break;
1313 default:
1314 break;
1315 }
1316
1317 return ret;
1318}
1319
1320static GstStateChangeReturn
1321gst_aml_v4l2_video_dec_change_state(GstElement *element,
1322 GstStateChange transition)
1323{
1324 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(element);
1325 GstVideoDecoder *decoder = GST_VIDEO_DECODER(element);
1326
1327 if (transition == GST_STATE_CHANGE_PAUSED_TO_READY)
1328 {
1329 g_atomic_int_set(&self->active, FALSE);
1330 gst_aml_v4l2_object_unlock(self->v4l2output);
1331 gst_aml_v4l2_object_unlock(self->v4l2capture);
1332 gst_pad_stop_task(decoder->srcpad);
1333 }
1334
1335 return GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
1336}
1337
1338static void
1339gst_aml_v4l2_video_dec_dispose(GObject *object)
1340{
1341 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(object);
1342
1343 gst_caps_replace(&self->probed_sinkcaps, NULL);
1344 gst_caps_replace(&self->probed_srccaps, NULL);
1345
1346 G_OBJECT_CLASS(parent_class)->dispose(object);
1347}
1348
1349static void
1350gst_aml_v4l2_video_dec_finalize(GObject *object)
1351{
1352 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(object);
1353
1354 gst_aml_v4l2_object_destroy(self->v4l2capture);
1355 gst_aml_v4l2_object_destroy(self->v4l2output);
1356
xuesong.jiangc5dac0f2023-02-01 14:42:24 +08001357 g_mutex_clear(&self->res_chg_lock);
1358 g_cond_clear(&self->res_chg_cond);
1359
xuesong.jiang61ea8012022-05-12 15:38:17 +08001360#if GST_IMPORT_LGE_PROP
1361 if (self->lge_ctxt)
1362 {
1363 if (self->lge_ctxt->app_type)
1364 g_free(self->lge_ctxt->app_type);
1365 if (self->lge_ctxt->res_info.coretype)
1366 g_free(self->lge_ctxt->res_info.coretype);
1367 free(self->lge_ctxt);
1368 }
1369
1370#endif
1371
xuesong.jiangae1548e2022-05-06 16:38:46 +08001372 G_OBJECT_CLASS(parent_class)->finalize(object);
1373}
1374
1375static void
1376gst_aml_v4l2_video_dec_init(GstAmlV4l2VideoDec *self)
1377{
1378 /* V4L2 object are created in subinstance_init */
1379 self->is_secure_path = FALSE;
xuesong.jiangc5dac0f2023-02-01 14:42:24 +08001380 self->is_res_chg = FALSE;
1381 g_mutex_init(&self->res_chg_lock);
1382 g_cond_init(&self->res_chg_cond);
xuesong.jiang61ea8012022-05-12 15:38:17 +08001383#if GST_IMPORT_LGE_PROP
1384 self->lge_ctxt = malloc(sizeof(GstAmlV4l2VideoDecLgeCtxt));
1385 memset(self->lge_ctxt, 0, sizeof(GstAmlV4l2VideoDecLgeCtxt));
1386#endif
xuesong.jiangae1548e2022-05-06 16:38:46 +08001387}
1388
1389static void
1390gst_aml_v4l2_video_dec_subinstance_init(GTypeInstance *instance, gpointer g_class)
1391{
1392 GstAmlV4l2VideoDecClass *klass = GST_AML_V4L2_VIDEO_DEC_CLASS(g_class);
1393 GstAmlV4l2VideoDec *self = GST_AML_V4L2_VIDEO_DEC(instance);
1394 GstVideoDecoder *decoder = GST_VIDEO_DECODER(instance);
1395
1396 gst_video_decoder_set_packetized(decoder, TRUE);
1397
1398 self->v4l2output = gst_aml_v4l2_object_new(GST_ELEMENT(self),
1399 GST_OBJECT(GST_VIDEO_DECODER_SINK_PAD(self)),
1400 V4L2_BUF_TYPE_VIDEO_OUTPUT, klass->default_device,
1401 gst_aml_v4l2_get_output, gst_aml_v4l2_set_output, NULL);
1402 self->v4l2output->no_initial_format = TRUE;
1403 self->v4l2output->keep_aspect = FALSE;
sheng.liu0c77f6c2022-06-17 21:33:20 +08001404 self->v4l2output->is_svp = FALSE;
xuesong.jiangae1548e2022-05-06 16:38:46 +08001405
1406 self->v4l2capture = gst_aml_v4l2_object_new(GST_ELEMENT(self),
1407 GST_OBJECT(GST_VIDEO_DECODER_SRC_PAD(self)),
1408 V4L2_BUF_TYPE_VIDEO_CAPTURE, klass->default_device,
1409 gst_aml_v4l2_get_input, gst_aml_v4l2_set_input, NULL);
1410 self->v4l2capture->need_wait_event = TRUE;
sheng.liub56bbc52022-06-21 11:02:33 +08001411 self->v4l2capture->need_drop_event = FALSE;
xuesong.jiangae1548e2022-05-06 16:38:46 +08001412}
1413
1414static void
1415gst_aml_v4l2_video_dec_class_init(GstAmlV4l2VideoDecClass *klass)
1416{
1417 GstElementClass *element_class;
1418 GObjectClass *gobject_class;
1419 GstVideoDecoderClass *video_decoder_class;
1420
1421 parent_class = g_type_class_peek_parent(klass);
1422
1423 element_class = (GstElementClass *)klass;
1424 gobject_class = (GObjectClass *)klass;
1425 video_decoder_class = (GstVideoDecoderClass *)klass;
1426
1427 GST_DEBUG_CATEGORY_INIT(gst_aml_v4l2_video_dec_debug, "amlv4l2videodec", 0,
1428 "AML V4L2 Video Decoder");
1429
1430 gobject_class->dispose = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_dispose);
1431 gobject_class->finalize = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_finalize);
1432 gobject_class->set_property =
1433 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_set_property);
1434 gobject_class->get_property =
1435 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_get_property);
1436
1437 video_decoder_class->open = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_open);
1438 video_decoder_class->close = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_close);
1439 video_decoder_class->start = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_start);
1440 video_decoder_class->stop = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_stop);
1441 video_decoder_class->finish = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_finish);
1442 video_decoder_class->flush = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_flush);
1443 video_decoder_class->drain = GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_drain);
1444 video_decoder_class->set_format =
1445 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_set_format);
1446 video_decoder_class->negotiate =
1447 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_negotiate);
1448 video_decoder_class->decide_allocation =
1449 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_decide_allocation);
1450 /* FIXME propose_allocation or not ? */
1451 video_decoder_class->handle_frame =
1452 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_handle_frame);
1453 video_decoder_class->getcaps =
1454 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_sink_getcaps);
1455 video_decoder_class->src_query =
1456 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_src_query);
1457 video_decoder_class->sink_event =
1458 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_sink_event);
1459
1460 element_class->change_state =
1461 GST_DEBUG_FUNCPTR(gst_aml_v4l2_video_dec_change_state);
1462
1463 gst_aml_v4l2_object_install_m2m_properties_helper(gobject_class);
xuesong.jiang61ea8012022-05-12 15:38:17 +08001464#if GST_IMPORT_LGE_PROP
1465 gst_aml_v4l2_video_dec_install_lge_properties_helper(gobject_class);
1466#endif
xuesong.jiangae1548e2022-05-06 16:38:46 +08001467}
1468
1469static void
1470gst_aml_v4l2_video_dec_subclass_init(gpointer g_class, gpointer data)
1471{
1472 GstAmlV4l2VideoDecClass *klass = GST_AML_V4L2_VIDEO_DEC_CLASS(g_class);
1473 GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
1474 GstAmlV4l2VideoDecCData *cdata = data;
1475
1476 klass->default_device = cdata->device;
1477
1478 /* Note: gst_pad_template_new() take the floating ref from the caps */
1479 gst_element_class_add_pad_template(element_class,
1480 gst_pad_template_new("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
1481 cdata->sink_caps));
1482 gst_element_class_add_pad_template(element_class,
1483 gst_pad_template_new("src", GST_PAD_SRC, GST_PAD_ALWAYS,
1484 cdata->src_caps));
1485
1486 gst_element_class_set_metadata(element_class, cdata->longname,
1487 "Codec/Decoder/Video/Hardware", cdata->description,
1488 "Xuesong Jiang <Xuesong.Jiang@amlogic.com>");
1489
1490 gst_caps_unref(cdata->sink_caps);
1491 gst_caps_unref(cdata->src_caps);
1492 g_free(cdata);
1493}
1494
1495/* Probing functions */
1496gboolean
1497gst_aml_v4l2_is_video_dec(GstCaps *sink_caps, GstCaps *src_caps)
1498{
1499 gboolean ret = FALSE;
1500
1501 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()))
1502 ret = TRUE;
1503
1504 return ret;
1505}
1506
1507static gchar *
1508gst_aml_v4l2_video_dec_set_metadata(GstStructure *s, GstAmlV4l2VideoDecCData *cdata,
1509 const gchar *basename)
1510{
1511 gchar *codec_name = NULL;
1512 gchar *type_name = NULL;
1513 gboolean got_value = FALSE;
1514
1515#define SET_META(codec) \
1516 G_STMT_START \
1517 { \
1518 cdata->longname = "AML V4L2 " codec " Decoder"; \
1519 cdata->description = "Decodes " codec " streams via V4L2 API"; \
1520 codec_name = g_ascii_strdown(codec, -1); \
1521 } \
1522 G_STMT_END
1523
1524 if (gst_structure_has_name(s, "image/jpeg"))
1525 {
1526 SET_META("JPEG");
1527 }
1528 else if (gst_structure_has_name(s, "video/mpeg"))
1529 {
1530 gint mpegversion = 0;
1531 gint *list = NULL;
1532 got_value = gst_structure_get_int(s, "mpegversion", &mpegversion);
1533 if (FALSE == got_value)
1534 {
1535 got_value = gst_structure_get_list(s, "mpegversion", &list);
1536 if (TRUE == got_value && (1 == *list || 2 == *list))
1537 {
1538 SET_META("MPEG2");
1539 }
1540 else
1541 {
1542 SET_META("MPEG4");
1543 }
1544 }
1545 else
1546 {
1547 SET_META("MPEG4");
1548 }
1549 }
1550 else if (gst_structure_has_name(s, "video/x-h263"))
1551 {
1552 SET_META("H263");
1553 }
1554 else if (gst_structure_has_name(s, "video/x-fwht"))
1555 {
1556 SET_META("FWHT");
1557 }
1558 else if (gst_structure_has_name(s, "video/x-h264"))
1559 {
1560 SET_META("H264");
1561 }
1562 else if (gst_structure_has_name(s, "video/x-h265"))
1563 {
1564 SET_META("H265");
1565 }
1566 else if (gst_structure_has_name(s, "video/x-wmv"))
1567 {
1568 SET_META("VC1");
1569 }
1570 else if (gst_structure_has_name(s, "video/x-vp8"))
1571 {
1572 SET_META("VP8");
1573 }
1574 else if (gst_structure_has_name(s, "video/x-vp9"))
1575 {
1576 SET_META("VP9");
1577 }
1578 else if (gst_structure_has_name(s, "video/x-av1"))
1579 {
1580 SET_META("AV1");
1581 }
1582 else if (gst_structure_has_name(s, "video/x-bayer"))
1583 {
1584 SET_META("BAYER");
1585 }
1586 else if (gst_structure_has_name(s, "video/x-sonix"))
1587 {
1588 SET_META("SONIX");
1589 }
1590 else if (gst_structure_has_name(s, "video/x-pwc1"))
1591 {
1592 SET_META("PWC1");
1593 }
1594 else if (gst_structure_has_name(s, "video/x-pwc2"))
1595 {
1596 SET_META("PWC2");
1597 }
1598 else
1599 {
1600 /* This code should be kept on sync with the exposed CODEC type of format
1601 * from gstamlv4l2object.c. This warning will only occure in case we forget
1602 * to also add a format here. */
1603 gchar *s_str = gst_structure_to_string(s);
1604 g_warning("Missing fixed name mapping for caps '%s', this is a GStreamer "
1605 "bug, please report at https://bugs.gnome.org",
1606 s_str);
1607 g_free(s_str);
1608 }
1609
1610 if (codec_name)
1611 {
1612 type_name = g_strdup_printf("amlv4l2%sdec", codec_name);
1613 if (g_type_from_name(type_name) != 0)
1614 {
1615 g_free(type_name);
1616 type_name = g_strdup_printf("amlv4l2%s%sdec", basename, codec_name);
1617 }
1618
1619 g_free(codec_name);
1620 }
1621
1622 return type_name;
1623#undef SET_META
1624}
1625
1626void gst_aml_v4l2_video_dec_register(GstPlugin *plugin, const gchar *basename,
1627 const gchar *device_path, GstCaps *sink_caps, GstCaps *src_caps)
1628{
1629 gint i;
1630
1631 for (i = 0; i < gst_caps_get_size(sink_caps); i++)
1632 {
1633 GstAmlV4l2VideoDecCData *cdata;
1634 GstStructure *s;
1635 GTypeQuery type_query;
1636 GTypeInfo type_info = {
1637 0,
1638 };
1639 GType type, subtype;
1640 gchar *type_name;
1641
1642 s = gst_caps_get_structure(sink_caps, i);
1643
1644 cdata = g_new0(GstAmlV4l2VideoDecCData, 1);
1645 cdata->device = g_strdup(device_path);
1646 cdata->sink_caps = gst_caps_new_empty();
1647 gst_caps_append_structure(cdata->sink_caps, gst_structure_copy(s));
1648 gst_caps_append_structure(cdata->sink_caps, gst_structure_copy(s));
1649 gst_caps_set_features(cdata->sink_caps, 0, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF));
1650 cdata->src_caps = gst_caps_copy(src_caps);
1651 gst_caps_set_features_simple(cdata->src_caps, gst_caps_features_from_string(GST_CAPS_FEATURE_MEMORY_DMABUF));
1652 gst_caps_append(cdata->src_caps, gst_caps_copy(src_caps));
1653 type_name = gst_aml_v4l2_video_dec_set_metadata(s, cdata, basename);
1654
1655 /* Skip over if we hit an unmapped type */
1656 if (!type_name)
1657 {
1658 g_free(cdata);
1659 continue;
1660 }
1661
1662 type = gst_aml_v4l2_video_dec_get_type();
1663 g_type_query(type, &type_query);
1664 memset(&type_info, 0, sizeof(type_info));
1665 type_info.class_size = type_query.class_size;
1666 type_info.instance_size = type_query.instance_size;
1667 type_info.class_init = gst_aml_v4l2_video_dec_subclass_init;
1668 type_info.class_data = cdata;
1669 type_info.instance_init = gst_aml_v4l2_video_dec_subinstance_init;
1670
1671 subtype = g_type_register_static(type, type_name, &type_info, 0);
1672 if (!gst_element_register(plugin, type_name, GST_RANK_PRIMARY + 1,
1673 subtype))
1674 GST_WARNING("Failed to register plugin '%s'", type_name);
1675
1676 g_free(type_name);
1677 }
1678}
xuesong.jiang61ea8012022-05-12 15:38:17 +08001679
1680#if GST_IMPORT_LGE_PROP
1681static void gst_aml_v4l2_video_dec_install_lge_properties_helper(GObjectClass *gobject_class)
1682{
1683 g_object_class_install_property(gobject_class, LGE_RESOURCE_INFO,
1684 g_param_spec_object("resource-info", "resource-info",
1685 "After acquisition of H/W resources is completed, allocated resource information must be delivered to the decoder and the sink",
1686 GST_TYPE_STRUCTURE,
1687 G_PARAM_READABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
1688
1689 g_object_class_install_property(gobject_class, LGE_DECODE_SIZE,
1690 g_param_spec_uint64("decoded-size", "decoded-size",
1691 "The total amount of decoder element's decoded video es after constructing pipeline or flushing pipeline update unit is byte.",
1692 0, G_MAXUINT64,
1693 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1694
1695 g_object_class_install_property(gobject_class, LGE_UNDECODE_SIZE,
1696 g_param_spec_uint64("undecoded-size", "undecoded-size",
1697 "video decoder element's total undecoded data update unit is byte.",
1698 0, G_MAXUINT64,
1699 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1700
1701 g_object_class_install_property(gobject_class, LGE_APP_TYPE,
1702 g_param_spec_string("app-type", "app-type",
1703 "set application type.",
1704 "default_app",
1705 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1706
1707 g_object_class_install_property(gobject_class, LGE_CLIP_MODE,
1708 g_param_spec_boolean("clip-mode", "clip-mode",
1709 "When seeking, Content is moving faster for a while to skip frames.",
1710 FALSE,
1711 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1712}
1713#endif