2 * Copyright (C) 2008 David Schleef <ds@schleef.org>
3 * Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
4 * Copyright (C) 2011 Nokia Corporation. All rights reserved.
5 * Contact: Stefan Kost <stefan.kost@nokia.com>
6 * Copyright (C) 2012 Collabora Ltd.
7 * Author : Edward Hervey <edward@collabora.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 * SECTION:gstvideodecoder
27 * @short_description: Base class for video decoders
30 * This base class is for video decoders turning encoded data into raw video
33 * The GstVideoDecoder base class and derived subclasses should cooperate as
37 * <itemizedlist><title>Configuration</title>
39 * Initially, GstVideoDecoder calls @start when the decoder element
40 * is activated, which allows the subclass to perform any global setup.
43 * GstVideoDecoder calls @set_format to inform the subclass of caps
44 * describing input video data that it is about to receive, including
45 * possibly configuration data.
46 * While unlikely, it might be called more than once, if changing input
47 * parameters require reconfiguration.
50 * Incoming data buffers are processed as needed, described in Data
54 * GstVideoDecoder calls @stop at end of all processing.
60 * <title>Data processing</title>
62 * The base class gathers input data, and optionally allows subclass
63 * to parse this into subsequently manageable chunks, typically
64 * corresponding to and referred to as 'frames'.
67 * Each input frame is provided in turn to the subclass' @handle_frame
69 * The ownership of the frame is given to the @handle_frame callback.
72 * If codec processing results in decoded data, the subclass should call
73 * @gst_video_decoder_finish_frame to have decoded data pushed.
74 * downstream. Otherwise, the subclass must call
75 * @gst_video_decoder_drop_frame, to allow the base class to do timestamp
76 * and offset tracking, and possibly to requeue the frame for a later
77 * attempt in the case of reverse playback.
82 * <itemizedlist><title>Shutdown phase</title>
84 * The GstVideoDecoder class calls @stop to inform the subclass that data
85 * parsing will be stopped.
90 * <itemizedlist><title>Additional Notes</title>
92 * <itemizedlist><title>Seeking/Flushing</title>
94 * When the pipeline is seeked or otherwise flushed, the subclass is
95 * informed via a call to its @reset callback, with the hard parameter
96 * set to true. This indicates the subclass should drop any internal data
97 * queues and timestamps and prepare for a fresh set of buffers to arrive
98 * for parsing and decoding.
103 * <itemizedlist><title>End Of Stream</title>
105 * At end-of-stream, the subclass @parse function may be called some final
106 * times with the at_eos parameter set to true, indicating that the element
107 * should not expect any more data to be arriving, and it should parse and
108 * remaining frames and call gst_video_decoder_have_frame() if possible.
116 * The subclass is responsible for providing pad template caps for
117 * source and sink pads. The pads need to be named "sink" and "src". It also
118 * needs to provide information about the ouptput caps, when they are known.
119 * This may be when the base class calls the subclass' @set_format function,
120 * though it might be during decoding, before calling
121 * @gst_video_decoder_finish_frame. This is done via
122 * @gst_video_decoder_set_output_state
124 * The subclass is also responsible for providing (presentation) timestamps
125 * (likely based on corresponding input ones). If that is not applicable
126 * or possible, the base class provides limited framerate based interpolation.
128 * Similarly, the base class provides some limited (legacy) seeking support
129 * if specifically requested by the subclass, as full-fledged support
130 * should rather be left to upstream demuxer, parser or alike. This simple
131 * approach caters for seeking and duration reporting using estimated input
132 * bitrates. To enable it, a subclass should call
133 * @gst_video_decoder_set_estimate_rate to enable handling of incoming
136 * The base class provides some support for reverse playback, in particular
137 * in case incoming data is not packetized or upstream does not provide
138 * fragments on keyframe boundaries. However, the subclass should then be
139 * prepared for the parsing and frame processing stage to occur separately
140 * (in normal forward processing, the latter immediately follows the former),
141 * The subclass also needs to ensure the parsing stage properly marks
142 * keyframes, unless it knows the upstream elements will do so properly for
145 * The bare minimum that a functional subclass needs to implement is:
147 * <listitem><para>Provide pad templates</para></listitem>
149 * Inform the base class of output caps via
150 * @gst_video_decoder_set_output_state
153 * Parse input data, if it is not considered packetized from upstream
154 * Data will be provided to @parse which should invoke
155 * @gst_video_decoder_add_to_frame and @gst_video_decoder_have_frame to
156 * separate the data belonging to each video frame.
159 * Accept data in @handle_frame and provide decoded results to
160 * @gst_video_decoder_finish_frame, or call @gst_video_decoder_drop_frame.
171 * * Add a flag/boolean for I-frame-only/image decoders so we can do extra
172 * features, like applying QoS on input (as opposed to after the frame is
174 * * Add a flag/boolean for decoders that require keyframes, so the base
175 * class can automatically discard non-keyframes before one has arrived
176 * * Detect reordered frame/timestamps and fix the pts/dts
177 * * Support for GstIndex (or shall we not care ?)
178 * * Calculate actual latency based on input/output timestamp/frame_number
179 * and if it exceeds the recorded one, save it and emit a GST_MESSAGE_LATENCY
180 * * Emit latency message when it changes
184 /* Implementation notes:
185 * The Video Decoder base class operates in 2 primary processing modes, depending
186 * on whether forward or reverse playback is requested.
189 * * Incoming buffer -> @parse() -> add_to_frame()/have_frame() ->
190 * handle_frame() -> push downstream
192 * Reverse playback is more complicated, since it involves gathering incoming
193 * data regions as we loop backwards through the upstream data. The processing
194 * concept (using incoming buffers as containing one frame each to simplify
197 * Upstream data we want to play:
198 * Buffer encoded order: 1 2 3 4 5 6 7 8 9 EOS
200 * Groupings: AAAAAAA BBBBBBB CCCCCCC
203 * Buffer reception order: 7 8 9 4 5 6 1 2 3 EOS
205 * Discont flag: D D D
207 * - Each Discont marks a discont in the decoding order.
208 * - The keyframes mark where we can start decoding.
210 * Initially, we prepend incoming buffers to the gather queue. Whenever the
211 * discont flag is set on an incoming buffer, the gather queue is flushed out
212 * before the new buffer is collected.
214 * The above data will be accumulated in the gather queue like this:
216 * gather queue: 9 8 7
219 * Whe buffer 4 is received (with a DISCONT), we flush the gather queue like
223 * take head of queue and prepend to parse queue (this reverses the
224 * sequence, so parse queue is 7 -> 8 -> 9)
226 * Next, we process the parse queue, which now contains all un-parsed packets
227 * (including any leftover ones from the previous decode section)
229 * for each buffer now in the parse queue:
230 * Call the subclass parse function, prepending each resulting frame to
231 * the parse_gather queue. Buffers which precede the first one that
232 * produces a parsed frame are retained in the parse queue for
233 * re-processing on the next cycle of parsing.
235 * The parse_gather queue now contains frame objects ready for decoding,
237 * parse_gather: 9 -> 8 -> 7
239 * while (parse_gather)
240 * Take the head of the queue and prepend it to the decode queue
241 * If the frame was a keyframe, process the decode queue
242 * decode is now 7-8-9
244 * Processing the decode queue results in frames with attached output buffers
245 * stored in the 'output_queue' ready for outputting in reverse order.
247 * After we flushed the gather queue and parsed it, we add 4 to the (now empty)
248 * gather queue. We get the following situation:
251 * decode queue: 7 8 9
253 * After we received 5 (Keyframe) and 6:
255 * gather queue: 6 5 4
256 * decode queue: 7 8 9
258 * When we receive 1 (DISCONT) which triggers a flush of the gather queue:
260 * Copy head of the gather queue (6) to decode queue:
263 * decode queue: 6 7 8 9
265 * Copy head of the gather queue (5) to decode queue. This is a keyframe so we
266 * can start decoding.
269 * decode queue: 5 6 7 8 9
271 * Decode frames in decode queue, store raw decoded data in output queue, we
272 * can take the head of the decode queue and prepend the decoded result in the
277 * output queue: 9 8 7 6 5
279 * Now output all the frames in the output queue, picking a frame from the
282 * Copy head of the gather queue (4) to decode queue, we flushed the gather
283 * queue and can now store input buffer in the gather queue:
288 * When we receive EOS, the queue looks like:
290 * gather queue: 3 2 1
293 * Fill decode queue, first keyframe we copy is 2:
296 * decode queue: 2 3 4
302 * output queue: 4 3 2
304 * Leftover buffer 1 cannot be decoded and must be discarded.
307 #include "gstvideodecoder.h"
308 #include "gstvideoutils.h"
309 #include "gstvideoutilsprivate.h"
311 #include <gst/video/video.h>
312 #include <gst/video/video-event.h>
313 #include <gst/video/gstvideopool.h>
314 #include <gst/video/gstvideometa.h>
317 GST_DEBUG_CATEGORY (videodecoder_debug);
318 #define GST_CAT_DEFAULT videodecoder_debug
320 #define GST_VIDEO_DECODER_GET_PRIVATE(obj) \
321 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_VIDEO_DECODER, \
322 GstVideoDecoderPrivate))
324 struct _GstVideoDecoderPrivate
326 /* FIXME introduce a context ? */
329 GstAllocator *allocator;
330 GstAllocationParams params;
334 GstAdapter *input_adapter;
335 /* assembles current frame */
336 GstAdapter *output_adapter;
338 /* Whether we attempt to convert newsegment from bytes to
339 * time using a bitrate estimation */
340 gboolean do_estimate_rate;
342 /* Whether input is considered packetized or not */
348 gboolean had_output_data;
349 gboolean had_input_data;
351 gboolean needs_format;
352 /* input_segment are output_segment identical */
353 gboolean in_out_segment_sync;
355 /* ... being tracked here;
356 * only available during parsing */
357 GstVideoCodecFrame *current_frame;
358 /* events that should apply to the current frame */
359 GList *current_frame_events;
360 /* events that should be pushed before the next frame */
361 GList *pending_events;
363 /* relative offset of input data */
364 guint64 input_offset;
365 /* relative offset of frame */
366 guint64 frame_offset;
367 /* tracking ts and offsets */
370 /* last outgoing ts */
371 GstClockTime last_timestamp_out;
372 /* incoming pts - dts */
373 GstClockTime pts_delta;
374 gboolean reordered_output;
376 /* reverse playback */
381 /* collected parsed frames */
383 /* frames to be handled == decoded */
385 /* collected output - of buffer objects, not frames */
386 GList *output_queued;
389 /* base_picture_number is the picture number of the reference picture */
390 guint64 base_picture_number;
391 /* combine with base_picture_number, framerate and calcs to yield (presentation) ts */
392 GstClockTime base_timestamp;
394 /* FIXME : reorder_depth is never set */
396 int distance_from_sync;
398 guint32 system_frame_number;
399 guint32 decode_frame_number;
401 GList *frames; /* Protected with OBJECT_LOCK */
402 GstVideoCodecState *input_state;
403 GstVideoCodecState *output_state; /* OBJECT_LOCK and STREAM_LOCK */
404 gboolean output_state_changed;
407 gdouble proportion; /* OBJECT_LOCK */
408 GstClockTime earliest_time; /* OBJECT_LOCK */
409 GstClockTime qos_frame_duration; /* OBJECT_LOCK */
411 /* qos messages: frames dropped/processed */
415 /* Outgoing byte size ? */
422 /* upstream stream tags (global tags are passed through as-is) */
423 GstTagList *upstream_tags;
427 GstTagMergeMode tags_merge_mode;
429 gboolean tags_changed;
432 gboolean use_default_pad_acceptcaps;
435 static GstElementClass *parent_class = NULL;
436 static void gst_video_decoder_class_init (GstVideoDecoderClass * klass);
437 static void gst_video_decoder_init (GstVideoDecoder * dec,
438 GstVideoDecoderClass * klass);
440 static void gst_video_decoder_finalize (GObject * object);
442 static gboolean gst_video_decoder_setcaps (GstVideoDecoder * dec,
444 static gboolean gst_video_decoder_sink_event (GstPad * pad, GstObject * parent,
446 static gboolean gst_video_decoder_src_event (GstPad * pad, GstObject * parent,
448 static GstFlowReturn gst_video_decoder_chain (GstPad * pad, GstObject * parent,
450 static gboolean gst_video_decoder_sink_query (GstPad * pad, GstObject * parent,
452 static GstStateChangeReturn gst_video_decoder_change_state (GstElement *
453 element, GstStateChange transition);
454 static gboolean gst_video_decoder_src_query (GstPad * pad, GstObject * parent,
456 static void gst_video_decoder_reset (GstVideoDecoder * decoder, gboolean full,
457 gboolean flush_hard);
459 static GstFlowReturn gst_video_decoder_decode_frame (GstVideoDecoder * decoder,
460 GstVideoCodecFrame * frame);
462 static void gst_video_decoder_push_event_list (GstVideoDecoder * decoder,
464 static GstClockTime gst_video_decoder_get_frame_duration (GstVideoDecoder *
465 decoder, GstVideoCodecFrame * frame);
466 static GstVideoCodecFrame *gst_video_decoder_new_frame (GstVideoDecoder *
468 static GstFlowReturn gst_video_decoder_clip_and_push_buf (GstVideoDecoder *
469 decoder, GstBuffer * buf);
470 static GstFlowReturn gst_video_decoder_flush_parse (GstVideoDecoder * dec,
473 static void gst_video_decoder_clear_queues (GstVideoDecoder * dec);
475 static gboolean gst_video_decoder_sink_event_default (GstVideoDecoder * decoder,
477 static gboolean gst_video_decoder_src_event_default (GstVideoDecoder * decoder,
479 static gboolean gst_video_decoder_decide_allocation_default (GstVideoDecoder *
480 decoder, GstQuery * query);
481 static gboolean gst_video_decoder_propose_allocation_default (GstVideoDecoder *
482 decoder, GstQuery * query);
483 static gboolean gst_video_decoder_negotiate_default (GstVideoDecoder * decoder);
484 static GstFlowReturn gst_video_decoder_parse_available (GstVideoDecoder * dec,
485 gboolean at_eos, gboolean new_buffer);
486 static gboolean gst_video_decoder_negotiate_unlocked (GstVideoDecoder *
488 static gboolean gst_video_decoder_sink_query_default (GstVideoDecoder * decoder,
490 static gboolean gst_video_decoder_src_query_default (GstVideoDecoder * decoder,
493 static gboolean gst_video_decoder_transform_meta_default (GstVideoDecoder *
494 decoder, GstVideoCodecFrame * frame, GstMeta * meta);
496 /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
497 * method to get to the padtemplates */
499 gst_video_decoder_get_type (void)
501 static volatile gsize type = 0;
503 if (g_once_init_enter (&type)) {
505 static const GTypeInfo info = {
506 sizeof (GstVideoDecoderClass),
509 (GClassInitFunc) gst_video_decoder_class_init,
512 sizeof (GstVideoDecoder),
514 (GInstanceInitFunc) gst_video_decoder_init,
517 _type = g_type_register_static (GST_TYPE_ELEMENT,
518 "GstVideoDecoder", &info, G_TYPE_FLAG_ABSTRACT);
519 g_once_init_leave (&type, _type);
525 gst_video_decoder_class_init (GstVideoDecoderClass * klass)
527 GObjectClass *gobject_class;
528 GstElementClass *gstelement_class;
530 gobject_class = G_OBJECT_CLASS (klass);
531 gstelement_class = GST_ELEMENT_CLASS (klass);
533 GST_DEBUG_CATEGORY_INIT (videodecoder_debug, "videodecoder", 0,
534 "Base Video Decoder");
536 parent_class = g_type_class_peek_parent (klass);
537 g_type_class_add_private (klass, sizeof (GstVideoDecoderPrivate));
539 gobject_class->finalize = gst_video_decoder_finalize;
541 gstelement_class->change_state =
542 GST_DEBUG_FUNCPTR (gst_video_decoder_change_state);
544 klass->sink_event = gst_video_decoder_sink_event_default;
545 klass->src_event = gst_video_decoder_src_event_default;
546 klass->decide_allocation = gst_video_decoder_decide_allocation_default;
547 klass->propose_allocation = gst_video_decoder_propose_allocation_default;
548 klass->negotiate = gst_video_decoder_negotiate_default;
549 klass->sink_query = gst_video_decoder_sink_query_default;
550 klass->src_query = gst_video_decoder_src_query_default;
551 klass->transform_meta = gst_video_decoder_transform_meta_default;
555 gst_video_decoder_init (GstVideoDecoder * decoder, GstVideoDecoderClass * klass)
557 GstPadTemplate *pad_template;
560 GST_DEBUG_OBJECT (decoder, "gst_video_decoder_init");
562 decoder->priv = GST_VIDEO_DECODER_GET_PRIVATE (decoder);
565 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "sink");
566 g_return_if_fail (pad_template != NULL);
568 decoder->sinkpad = pad = gst_pad_new_from_template (pad_template, "sink");
570 gst_pad_set_chain_function (pad, GST_DEBUG_FUNCPTR (gst_video_decoder_chain));
571 gst_pad_set_event_function (pad,
572 GST_DEBUG_FUNCPTR (gst_video_decoder_sink_event));
573 gst_pad_set_query_function (pad,
574 GST_DEBUG_FUNCPTR (gst_video_decoder_sink_query));
575 gst_element_add_pad (GST_ELEMENT (decoder), decoder->sinkpad);
578 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "src");
579 g_return_if_fail (pad_template != NULL);
581 decoder->srcpad = pad = gst_pad_new_from_template (pad_template, "src");
583 gst_pad_set_event_function (pad,
584 GST_DEBUG_FUNCPTR (gst_video_decoder_src_event));
585 gst_pad_set_query_function (pad,
586 GST_DEBUG_FUNCPTR (gst_video_decoder_src_query));
587 gst_element_add_pad (GST_ELEMENT (decoder), decoder->srcpad);
589 gst_segment_init (&decoder->input_segment, GST_FORMAT_TIME);
590 gst_segment_init (&decoder->output_segment, GST_FORMAT_TIME);
592 g_rec_mutex_init (&decoder->stream_lock);
594 decoder->priv->input_adapter = gst_adapter_new ();
595 decoder->priv->output_adapter = gst_adapter_new ();
596 decoder->priv->packetized = TRUE;
597 decoder->priv->needs_format = FALSE;
599 decoder->priv->min_latency = 0;
600 decoder->priv->max_latency = 0;
602 gst_video_decoder_reset (decoder, TRUE, TRUE);
606 gst_video_rawvideo_convert (GstVideoCodecState * state,
607 GstFormat src_format, gint64 src_value,
608 GstFormat * dest_format, gint64 * dest_value)
610 gboolean res = FALSE;
614 g_return_val_if_fail (dest_format != NULL, FALSE);
615 g_return_val_if_fail (dest_value != NULL, FALSE);
617 if (src_format == *dest_format || src_value == 0 || src_value == -1) {
618 *dest_value = src_value;
622 vidsize = GST_VIDEO_INFO_SIZE (&state->info);
623 fps_n = GST_VIDEO_INFO_FPS_N (&state->info);
624 fps_d = GST_VIDEO_INFO_FPS_D (&state->info);
626 if (src_format == GST_FORMAT_BYTES &&
627 *dest_format == GST_FORMAT_DEFAULT && vidsize) {
628 /* convert bytes to frames */
629 *dest_value = gst_util_uint64_scale_int (src_value, 1, vidsize);
631 } else if (src_format == GST_FORMAT_DEFAULT &&
632 *dest_format == GST_FORMAT_BYTES && vidsize) {
633 /* convert bytes to frames */
634 *dest_value = src_value * vidsize;
636 } else if (src_format == GST_FORMAT_DEFAULT &&
637 *dest_format == GST_FORMAT_TIME && fps_n) {
638 /* convert frames to time */
639 *dest_value = gst_util_uint64_scale (src_value, GST_SECOND * fps_d, fps_n);
641 } else if (src_format == GST_FORMAT_TIME &&
642 *dest_format == GST_FORMAT_DEFAULT && fps_d) {
643 /* convert time to frames */
644 *dest_value = gst_util_uint64_scale (src_value, fps_n, GST_SECOND * fps_d);
646 } else if (src_format == GST_FORMAT_TIME &&
647 *dest_format == GST_FORMAT_BYTES && fps_d && vidsize) {
648 /* convert time to bytes */
649 *dest_value = gst_util_uint64_scale (src_value,
650 fps_n * (guint64) vidsize, GST_SECOND * fps_d);
652 } else if (src_format == GST_FORMAT_BYTES &&
653 *dest_format == GST_FORMAT_TIME && fps_n && vidsize) {
654 /* convert bytes to time */
655 *dest_value = gst_util_uint64_scale (src_value,
656 GST_SECOND * fps_d, fps_n * (guint64) vidsize);
664 gst_video_encoded_video_convert (gint64 bytes, gint64 time,
665 GstFormat src_format, gint64 src_value, GstFormat * dest_format,
668 gboolean res = FALSE;
670 g_return_val_if_fail (dest_format != NULL, FALSE);
671 g_return_val_if_fail (dest_value != NULL, FALSE);
673 if (G_UNLIKELY (src_format == *dest_format || src_value == 0 ||
676 *dest_value = src_value;
680 if (bytes <= 0 || time <= 0) {
681 GST_DEBUG ("not enough metadata yet to convert");
685 switch (src_format) {
686 case GST_FORMAT_BYTES:
687 switch (*dest_format) {
688 case GST_FORMAT_TIME:
689 *dest_value = gst_util_uint64_scale (src_value, time, bytes);
696 case GST_FORMAT_TIME:
697 switch (*dest_format) {
698 case GST_FORMAT_BYTES:
699 *dest_value = gst_util_uint64_scale (src_value, bytes, time);
707 GST_DEBUG ("unhandled conversion from %d to %d", src_format,
716 static GstVideoCodecState *
717 _new_input_state (GstCaps * caps)
719 GstVideoCodecState *state;
720 GstStructure *structure;
721 const GValue *codec_data;
723 state = g_slice_new0 (GstVideoCodecState);
724 state->ref_count = 1;
725 gst_video_info_init (&state->info);
726 if (G_UNLIKELY (!gst_video_info_from_caps (&state->info, caps)))
728 state->caps = gst_caps_ref (caps);
730 structure = gst_caps_get_structure (caps, 0);
732 codec_data = gst_structure_get_value (structure, "codec_data");
733 if (codec_data && G_VALUE_TYPE (codec_data) == GST_TYPE_BUFFER)
734 state->codec_data = GST_BUFFER (g_value_dup_boxed (codec_data));
740 g_slice_free (GstVideoCodecState, state);
745 static GstVideoCodecState *
746 _new_output_state (GstVideoFormat fmt, guint width, guint height,
747 GstVideoCodecState * reference)
749 GstVideoCodecState *state;
751 state = g_slice_new0 (GstVideoCodecState);
752 state->ref_count = 1;
753 gst_video_info_init (&state->info);
754 gst_video_info_set_format (&state->info, fmt, width, height);
757 GstVideoInfo *tgt, *ref;
760 ref = &reference->info;
762 /* Copy over extra fields from reference state */
763 tgt->interlace_mode = ref->interlace_mode;
764 tgt->flags = ref->flags;
765 /* only copy values that are not unknown so that we don't override the
766 * defaults. subclasses should really fill these in when they know. */
767 if (ref->chroma_site)
768 tgt->chroma_site = ref->chroma_site;
769 if (ref->colorimetry.range)
770 tgt->colorimetry.range = ref->colorimetry.range;
771 if (ref->colorimetry.matrix)
772 tgt->colorimetry.matrix = ref->colorimetry.matrix;
773 if (ref->colorimetry.transfer)
774 tgt->colorimetry.transfer = ref->colorimetry.transfer;
775 if (ref->colorimetry.primaries)
776 tgt->colorimetry.primaries = ref->colorimetry.primaries;
777 GST_DEBUG ("reference par %d/%d fps %d/%d",
778 ref->par_n, ref->par_d, ref->fps_n, ref->fps_d);
779 tgt->par_n = ref->par_n;
780 tgt->par_d = ref->par_d;
781 tgt->fps_n = ref->fps_n;
782 tgt->fps_d = ref->fps_d;
783 tgt->views = ref->views;
784 if (GST_VIDEO_INFO_MULTIVIEW_MODE (ref) != GST_VIDEO_MULTIVIEW_MODE_NONE) {
785 GST_VIDEO_INFO_MULTIVIEW_MODE (tgt) = GST_VIDEO_INFO_MULTIVIEW_MODE (ref);
786 GST_VIDEO_INFO_MULTIVIEW_FLAGS (tgt) =
787 GST_VIDEO_INFO_MULTIVIEW_FLAGS (ref);
791 GST_DEBUG ("reference par %d/%d fps %d/%d",
792 state->info.par_n, state->info.par_d,
793 state->info.fps_n, state->info.fps_d);
799 gst_video_decoder_setcaps (GstVideoDecoder * decoder, GstCaps * caps)
801 GstVideoDecoderClass *decoder_class;
802 GstVideoCodecState *state;
805 decoder_class = GST_VIDEO_DECODER_GET_CLASS (decoder);
807 GST_DEBUG_OBJECT (decoder, "setcaps %" GST_PTR_FORMAT, caps);
809 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
811 if (decoder->priv->input_state) {
812 GST_DEBUG_OBJECT (decoder,
813 "Checking if caps changed old %" GST_PTR_FORMAT " new %" GST_PTR_FORMAT,
814 decoder->priv->input_state->caps, caps);
815 if (gst_caps_is_equal (decoder->priv->input_state->caps, caps))
816 goto caps_not_changed;
819 state = _new_input_state (caps);
821 if (G_UNLIKELY (state == NULL))
824 if (decoder_class->set_format)
825 ret = decoder_class->set_format (decoder, state);
830 if (decoder->priv->input_state)
831 gst_video_codec_state_unref (decoder->priv->input_state);
832 decoder->priv->input_state = state;
834 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
840 GST_DEBUG_OBJECT (decoder, "Caps did not change - ignore");
841 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
848 GST_WARNING_OBJECT (decoder, "Failed to parse caps");
849 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
855 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
856 GST_WARNING_OBJECT (decoder, "Subclass refused caps");
857 gst_video_codec_state_unref (state);
863 gst_video_decoder_finalize (GObject * object)
865 GstVideoDecoder *decoder;
867 decoder = GST_VIDEO_DECODER (object);
869 GST_DEBUG_OBJECT (object, "finalize");
871 g_rec_mutex_clear (&decoder->stream_lock);
873 if (decoder->priv->input_adapter) {
874 g_object_unref (decoder->priv->input_adapter);
875 decoder->priv->input_adapter = NULL;
877 if (decoder->priv->output_adapter) {
878 g_object_unref (decoder->priv->output_adapter);
879 decoder->priv->output_adapter = NULL;
882 if (decoder->priv->input_state)
883 gst_video_codec_state_unref (decoder->priv->input_state);
884 if (decoder->priv->output_state)
885 gst_video_codec_state_unref (decoder->priv->output_state);
887 if (decoder->priv->pool) {
888 gst_object_unref (decoder->priv->pool);
889 decoder->priv->pool = NULL;
892 if (decoder->priv->allocator) {
893 gst_object_unref (decoder->priv->allocator);
894 decoder->priv->allocator = NULL;
897 G_OBJECT_CLASS (parent_class)->finalize (object);
900 /* hard == FLUSH, otherwise discont */
902 gst_video_decoder_flush (GstVideoDecoder * dec, gboolean hard)
904 GstVideoDecoderClass *klass = GST_VIDEO_DECODER_GET_CLASS (dec);
905 GstFlowReturn ret = GST_FLOW_OK;
907 GST_LOG_OBJECT (dec, "flush hard %d", hard);
909 /* Inform subclass */
911 GST_FIXME_OBJECT (dec, "GstVideoDecoder::reset() is deprecated");
912 klass->reset (dec, hard);
918 /* and get (re)set for the sequel */
919 gst_video_decoder_reset (dec, FALSE, hard);
925 gst_video_decoder_create_merged_tags_event (GstVideoDecoder * dec)
927 GstTagList *merged_tags;
929 GST_LOG_OBJECT (dec, "upstream : %" GST_PTR_FORMAT, dec->priv->upstream_tags);
930 GST_LOG_OBJECT (dec, "decoder : %" GST_PTR_FORMAT, dec->priv->tags);
931 GST_LOG_OBJECT (dec, "mode : %d", dec->priv->tags_merge_mode);
934 gst_tag_list_merge (dec->priv->upstream_tags, dec->priv->tags,
935 dec->priv->tags_merge_mode);
937 GST_DEBUG_OBJECT (dec, "merged : %" GST_PTR_FORMAT, merged_tags);
939 if (merged_tags == NULL)
942 if (gst_tag_list_is_empty (merged_tags)) {
943 gst_tag_list_unref (merged_tags);
947 return gst_event_new_tag (merged_tags);
951 gst_video_decoder_push_event (GstVideoDecoder * decoder, GstEvent * event)
953 switch (GST_EVENT_TYPE (event)) {
954 case GST_EVENT_SEGMENT:
958 gst_event_copy_segment (event, &segment);
960 GST_DEBUG_OBJECT (decoder, "segment %" GST_SEGMENT_FORMAT, &segment);
962 if (segment.format != GST_FORMAT_TIME) {
963 GST_DEBUG_OBJECT (decoder, "received non TIME newsegment");
967 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
968 decoder->output_segment = segment;
969 decoder->priv->in_out_segment_sync =
970 gst_segment_is_equal (&decoder->input_segment, &segment);
971 decoder->priv->last_timestamp_out = GST_CLOCK_TIME_NONE;
972 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
979 GST_DEBUG_OBJECT (decoder, "pushing event %s",
980 gst_event_type_get_name (GST_EVENT_TYPE (event)));
982 return gst_pad_push_event (decoder->srcpad, event);
986 gst_video_decoder_parse_available (GstVideoDecoder * dec, gboolean at_eos,
989 GstVideoDecoderClass *decoder_class = GST_VIDEO_DECODER_GET_CLASS (dec);
990 GstVideoDecoderPrivate *priv = dec->priv;
991 GstFlowReturn ret = GST_FLOW_OK;
992 gsize was_available, available;
995 available = gst_adapter_available (priv->input_adapter);
997 while (available || new_buffer) {
999 /* current frame may have been parsed and handled,
1000 * so we need to set up a new one when asking subclass to parse */
1001 if (priv->current_frame == NULL)
1002 priv->current_frame = gst_video_decoder_new_frame (dec);
1004 was_available = available;
1005 ret = decoder_class->parse (dec, priv->current_frame,
1006 priv->input_adapter, at_eos);
1007 if (ret != GST_FLOW_OK)
1010 /* if the subclass returned success (GST_FLOW_OK), it is expected
1011 * to have collected and submitted a frame, i.e. it should have
1012 * called gst_video_decoder_have_frame(), or at least consumed a
1013 * few bytes through gst_video_decoder_add_to_frame().
1015 * Otherwise, this is an implementation bug, and we error out
1016 * after 2 failed attempts */
1017 available = gst_adapter_available (priv->input_adapter);
1018 if (!priv->current_frame || available != was_available)
1020 else if (++inactive == 2)
1021 goto error_inactive;
1029 GST_ERROR_OBJECT (dec, "Failed to consume data. Error in subclass?");
1030 return GST_FLOW_ERROR;
1034 static GstFlowReturn
1035 gst_video_decoder_drain_out (GstVideoDecoder * dec, gboolean at_eos)
1037 GstVideoDecoderClass *decoder_class = GST_VIDEO_DECODER_GET_CLASS (dec);
1038 GstVideoDecoderPrivate *priv = dec->priv;
1039 GstFlowReturn ret = GST_FLOW_OK;
1041 GST_VIDEO_DECODER_STREAM_LOCK (dec);
1043 if (dec->input_segment.rate > 0.0) {
1044 /* Forward mode, if unpacketized, give the child class
1045 * a final chance to flush out packets */
1046 if (!priv->packetized) {
1047 ret = gst_video_decoder_parse_available (dec, TRUE, FALSE);
1051 if (decoder_class->finish)
1052 ret = decoder_class->finish (dec);
1054 if (decoder_class->drain) {
1055 ret = decoder_class->drain (dec);
1057 GST_FIXME_OBJECT (dec, "Sub-class should implement drain()");
1061 /* Reverse playback mode */
1062 ret = gst_video_decoder_flush_parse (dec, TRUE);
1065 GST_VIDEO_DECODER_STREAM_UNLOCK (dec);
1071 _flush_events (GstPad * pad, GList * events)
1075 for (tmp = events; tmp; tmp = tmp->next) {
1076 if (GST_EVENT_TYPE (tmp->data) != GST_EVENT_EOS &&
1077 GST_EVENT_TYPE (tmp->data) != GST_EVENT_SEGMENT &&
1078 GST_EVENT_IS_STICKY (tmp->data)) {
1079 gst_pad_store_sticky_event (pad, GST_EVENT_CAST (tmp->data));
1081 gst_event_unref (tmp->data);
1083 g_list_free (events);
1088 /* Must be called holding the GST_VIDEO_DECODER_STREAM_LOCK */
1090 gst_video_decoder_negotiate_default_caps (GstVideoDecoder * decoder)
1092 GstCaps *caps, *templcaps;
1093 GstVideoCodecState *state;
1097 GstStructure *structure;
1099 templcaps = gst_pad_get_pad_template_caps (decoder->srcpad);
1100 caps = gst_pad_peer_query_caps (decoder->srcpad, templcaps);
1102 gst_caps_unref (templcaps);
1107 if (!caps || gst_caps_is_empty (caps) || gst_caps_is_any (caps))
1110 GST_LOG_OBJECT (decoder, "peer caps %" GST_PTR_FORMAT, caps);
1112 /* before fixating, try to use whatever upstream provided */
1113 caps = gst_caps_make_writable (caps);
1114 caps_size = gst_caps_get_size (caps);
1115 if (decoder->priv->input_state && decoder->priv->input_state->caps) {
1116 GstCaps *sinkcaps = decoder->priv->input_state->caps;
1117 GstStructure *structure = gst_caps_get_structure (sinkcaps, 0);
1122 if (gst_structure_get_int (structure, "width", &width)) {
1123 for (i = 0; i < caps_size; i++) {
1124 gst_structure_set (gst_caps_get_structure (caps, i), "width",
1125 G_TYPE_INT, width, NULL);
1129 if (gst_structure_get_int (structure, "height", &height)) {
1130 for (i = 0; i < caps_size; i++) {
1131 gst_structure_set (gst_caps_get_structure (caps, i), "height",
1132 G_TYPE_INT, height, NULL);
1136 if (gst_structure_get_fraction (structure, "framerate", &fps_n, &fps_d)) {
1137 for (i = 0; i < caps_size; i++) {
1138 gst_structure_set (gst_caps_get_structure (caps, i), "framerate",
1139 GST_TYPE_FRACTION, fps_n, fps_d, NULL);
1143 if (gst_structure_get_fraction (structure, "pixel-aspect-ratio", &par_n,
1145 for (i = 0; i < caps_size; i++) {
1146 gst_structure_set (gst_caps_get_structure (caps, i),
1147 "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
1152 for (i = 0; i < caps_size; i++) {
1153 structure = gst_caps_get_structure (caps, i);
1154 /* Random 1280x720@30 for fixation */
1155 gst_structure_fixate_field_nearest_int (structure, "width", 1280);
1156 gst_structure_fixate_field_nearest_int (structure, "height", 720);
1157 gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
1158 if (gst_structure_has_field (structure, "pixel-aspect-ratio")) {
1159 gst_structure_fixate_field_nearest_fraction (structure,
1160 "pixel-aspect-ratio", 1, 1);
1162 gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1166 caps = gst_caps_fixate (caps);
1167 structure = gst_caps_get_structure (caps, 0);
1169 if (!caps || !gst_video_info_from_caps (&info, caps))
1172 GST_INFO_OBJECT (decoder,
1173 "Chose default caps %" GST_PTR_FORMAT " for initial gap", caps);
1175 gst_video_decoder_set_output_state (decoder, info.finfo->format,
1176 info.width, info.height, decoder->priv->input_state);
1177 gst_video_codec_state_unref (state);
1178 gst_caps_unref (caps);
1185 gst_caps_unref (caps);
1191 gst_video_decoder_sink_event_default (GstVideoDecoder * decoder,
1194 GstVideoDecoderPrivate *priv;
1195 gboolean ret = FALSE;
1196 gboolean forward_immediate = FALSE;
1198 priv = decoder->priv;
1200 switch (GST_EVENT_TYPE (event)) {
1201 case GST_EVENT_STREAM_START:
1203 GstFlowReturn flow_ret = GST_FLOW_OK;
1205 flow_ret = gst_video_decoder_drain_out (decoder, FALSE);
1206 ret = (flow_ret == GST_FLOW_OK);
1208 GST_DEBUG_OBJECT (decoder, "received STREAM_START. Clearing taglist");
1209 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
1210 /* Flush upstream tags after a STREAM_START */
1211 if (priv->upstream_tags) {
1212 gst_tag_list_unref (priv->upstream_tags);
1213 priv->upstream_tags = NULL;
1214 priv->tags_changed = TRUE;
1216 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
1218 /* Forward STREAM_START immediately. Everything is drained after
1219 * the STREAM_START event and we can forward this event immediately
1220 * now without having buffers out of order.
1222 forward_immediate = TRUE;
1225 case GST_EVENT_CAPS:
1229 gst_event_parse_caps (event, &caps);
1230 ret = gst_video_decoder_setcaps (decoder, caps);
1231 gst_event_unref (event);
1235 case GST_EVENT_SEGMENT_DONE:
1237 GstFlowReturn flow_ret = GST_FLOW_OK;
1239 flow_ret = gst_video_decoder_drain_out (decoder, TRUE);
1240 ret = (flow_ret == GST_FLOW_OK);
1242 /* Forward SEGMENT_DONE immediately. This is required
1243 * because no buffer or serialized event might come
1244 * after SEGMENT_DONE and nothing could trigger another
1245 * _finish_frame() call.
1247 * The subclass can override this behaviour by overriding
1248 * the ::sink_event() vfunc and not chaining up to the
1249 * parent class' ::sink_event() until a later time.
1251 forward_immediate = TRUE;
1256 GstFlowReturn flow_ret = GST_FLOW_OK;
1258 flow_ret = gst_video_decoder_drain_out (decoder, TRUE);
1259 ret = (flow_ret == GST_FLOW_OK);
1261 /* Error out even if EOS was ok when we had input, but no output */
1262 if (ret && priv->had_input_data && !priv->had_output_data) {
1263 GST_ELEMENT_ERROR (decoder, STREAM, DECODE,
1264 ("No valid frames decoded before end of stream"),
1265 ("no valid frames found"));
1268 /* Forward EOS immediately. This is required because no
1269 * buffer or serialized event will come after EOS and
1270 * nothing could trigger another _finish_frame() call.
1272 * The subclass can override this behaviour by overriding
1273 * the ::sink_event() vfunc and not chaining up to the
1274 * parent class' ::sink_event() until a later time.
1276 forward_immediate = TRUE;
1281 GstFlowReturn flow_ret = GST_FLOW_OK;
1282 gboolean needs_reconfigure = FALSE;
1284 GList *frame_events;
1286 flow_ret = gst_video_decoder_drain_out (decoder, FALSE);
1287 ret = (flow_ret == GST_FLOW_OK);
1289 /* Ensure we have caps before forwarding the event */
1290 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
1291 if (!decoder->priv->output_state) {
1292 if (!gst_video_decoder_negotiate_default_caps (decoder)) {
1293 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
1294 GST_ELEMENT_ERROR (decoder, STREAM, FORMAT, (NULL),
1295 ("Decoder output not negotiated before GAP event."));
1296 forward_immediate = TRUE;
1299 needs_reconfigure = TRUE;
1302 needs_reconfigure = gst_pad_check_reconfigure (decoder->srcpad)
1303 || needs_reconfigure;
1304 if (decoder->priv->output_state_changed || needs_reconfigure) {
1305 if (!gst_video_decoder_negotiate_unlocked (decoder)) {
1306 GST_WARNING_OBJECT (decoder, "Failed to negotiate with downstream");
1307 gst_pad_mark_reconfigure (decoder->srcpad);
1311 GST_DEBUG_OBJECT (decoder, "Pushing all pending serialized events"
1313 events = decoder->priv->pending_events;
1314 frame_events = decoder->priv->current_frame_events;
1315 decoder->priv->pending_events = NULL;
1316 decoder->priv->current_frame_events = NULL;
1318 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
1320 gst_video_decoder_push_event_list (decoder, events);
1321 gst_video_decoder_push_event_list (decoder, frame_events);
1323 /* Forward GAP immediately. Everything is drained after
1324 * the GAP event and we can forward this event immediately
1325 * now without having buffers out of order.
1327 forward_immediate = TRUE;
1330 case GST_EVENT_CUSTOM_DOWNSTREAM:
1333 GstFlowReturn flow_ret = GST_FLOW_OK;
1335 if (gst_video_event_parse_still_frame (event, &in_still)) {
1337 GST_DEBUG_OBJECT (decoder, "draining current data for still-frame");
1338 flow_ret = gst_video_decoder_drain_out (decoder, FALSE);
1339 ret = (flow_ret == GST_FLOW_OK);
1341 /* Forward STILL_FRAME immediately. Everything is drained after
1342 * the STILL_FRAME event and we can forward this event immediately
1343 * now without having buffers out of order.
1345 forward_immediate = TRUE;
1349 case GST_EVENT_SEGMENT:
1353 gst_event_copy_segment (event, &segment);
1355 if (segment.format == GST_FORMAT_TIME) {
1356 GST_DEBUG_OBJECT (decoder,
1357 "received TIME SEGMENT %" GST_SEGMENT_FORMAT, &segment);
1361 GST_DEBUG_OBJECT (decoder,
1362 "received SEGMENT %" GST_SEGMENT_FORMAT, &segment);
1364 /* handle newsegment as a result from our legacy simple seeking */
1365 /* note that initial 0 should convert to 0 in any case */
1366 if (priv->do_estimate_rate &&
1367 gst_pad_query_convert (decoder->sinkpad, GST_FORMAT_BYTES,
1368 segment.start, GST_FORMAT_TIME, &start)) {
1369 /* best attempt convert */
1370 /* as these are only estimates, stop is kept open-ended to avoid
1371 * premature cutting */
1372 GST_DEBUG_OBJECT (decoder,
1373 "converted to TIME start %" GST_TIME_FORMAT,
1374 GST_TIME_ARGS (start));
1375 segment.start = start;
1376 segment.stop = GST_CLOCK_TIME_NONE;
1377 segment.time = start;
1379 gst_event_unref (event);
1380 event = gst_event_new_segment (&segment);
1382 goto newseg_wrong_format;
1386 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
1388 priv->base_timestamp = GST_CLOCK_TIME_NONE;
1389 priv->base_picture_number = 0;
1391 decoder->input_segment = segment;
1392 decoder->priv->in_out_segment_sync = FALSE;
1394 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
1397 case GST_EVENT_FLUSH_STOP:
1401 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
1402 for (l = priv->frames; l; l = l->next) {
1403 GstVideoCodecFrame *frame = l->data;
1405 frame->events = _flush_events (decoder->srcpad, frame->events);
1407 priv->current_frame_events = _flush_events (decoder->srcpad,
1408 decoder->priv->current_frame_events);
1410 /* well, this is kind of worse than a DISCONT */
1411 gst_video_decoder_flush (decoder, TRUE);
1412 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
1413 /* Forward FLUSH_STOP immediately. This is required because it is
1414 * expected to be forwarded immediately and no buffers are queued
1417 forward_immediate = TRUE;
1424 gst_event_parse_tag (event, &tags);
1426 if (gst_tag_list_get_scope (tags) == GST_TAG_SCOPE_STREAM) {
1427 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
1428 if (priv->upstream_tags != tags) {
1429 if (priv->upstream_tags)
1430 gst_tag_list_unref (priv->upstream_tags);
1431 priv->upstream_tags = gst_tag_list_ref (tags);
1432 GST_INFO_OBJECT (decoder, "upstream tags: %" GST_PTR_FORMAT, tags);
1434 gst_event_unref (event);
1435 event = gst_video_decoder_create_merged_tags_event (decoder);
1436 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
1446 /* Forward non-serialized events immediately, and all other
1447 * events which can be forwarded immediately without potentially
1448 * causing the event to go out of order with other events and
1449 * buffers as decided above.
1452 if (!GST_EVENT_IS_SERIALIZED (event) || forward_immediate) {
1453 ret = gst_video_decoder_push_event (decoder, event);
1455 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
1456 decoder->priv->current_frame_events =
1457 g_list_prepend (decoder->priv->current_frame_events, event);
1458 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
1465 newseg_wrong_format:
1467 GST_DEBUG_OBJECT (decoder, "received non TIME newsegment");
1468 gst_event_unref (event);
1475 gst_video_decoder_sink_event (GstPad * pad, GstObject * parent,
1478 GstVideoDecoder *decoder;
1479 GstVideoDecoderClass *decoder_class;
1480 gboolean ret = FALSE;
1482 decoder = GST_VIDEO_DECODER (parent);
1483 decoder_class = GST_VIDEO_DECODER_GET_CLASS (decoder);
1485 GST_DEBUG_OBJECT (decoder, "received event %d, %s", GST_EVENT_TYPE (event),
1486 GST_EVENT_TYPE_NAME (event));
1488 if (decoder_class->sink_event)
1489 ret = decoder_class->sink_event (decoder, event);
1494 /* perform upstream byte <-> time conversion (duration, seeking)
1495 * if subclass allows and if enough data for moderately decent conversion */
1496 static inline gboolean
1497 gst_video_decoder_do_byte (GstVideoDecoder * dec)
1499 return dec->priv->do_estimate_rate && (dec->priv->bytes_out > 0)
1500 && (dec->priv->time > GST_SECOND);
1504 gst_video_decoder_do_seek (GstVideoDecoder * dec, GstEvent * event)
1508 GstSeekType start_type, end_type;
1510 gint64 start, start_time, end_time;
1511 GstSegment seek_segment;
1514 gst_event_parse_seek (event, &rate, &format, &flags, &start_type,
1515 &start_time, &end_type, &end_time);
1517 /* we'll handle plain open-ended flushing seeks with the simple approach */
1519 GST_DEBUG_OBJECT (dec, "unsupported seek: rate");
1523 if (start_type != GST_SEEK_TYPE_SET) {
1524 GST_DEBUG_OBJECT (dec, "unsupported seek: start time");
1528 if ((end_type != GST_SEEK_TYPE_SET && end_type != GST_SEEK_TYPE_NONE) ||
1529 (end_type == GST_SEEK_TYPE_SET && end_time != GST_CLOCK_TIME_NONE)) {
1530 GST_DEBUG_OBJECT (dec, "unsupported seek: end time");
1534 if (!(flags & GST_SEEK_FLAG_FLUSH)) {
1535 GST_DEBUG_OBJECT (dec, "unsupported seek: not flushing");
1539 memcpy (&seek_segment, &dec->output_segment, sizeof (seek_segment));
1540 gst_segment_do_seek (&seek_segment, rate, format, flags, start_type,
1541 start_time, end_type, end_time, NULL);
1542 start_time = seek_segment.position;
1544 if (!gst_pad_query_convert (dec->sinkpad, GST_FORMAT_TIME, start_time,
1545 GST_FORMAT_BYTES, &start)) {
1546 GST_DEBUG_OBJECT (dec, "conversion failed");
1550 seqnum = gst_event_get_seqnum (event);
1551 event = gst_event_new_seek (1.0, GST_FORMAT_BYTES, flags,
1552 GST_SEEK_TYPE_SET, start, GST_SEEK_TYPE_NONE, -1);
1553 gst_event_set_seqnum (event, seqnum);
1555 GST_DEBUG_OBJECT (dec, "seeking to %" GST_TIME_FORMAT " at byte offset %"
1556 G_GINT64_FORMAT, GST_TIME_ARGS (start_time), start);
1558 return gst_pad_push_event (dec->sinkpad, event);
1562 gst_video_decoder_src_event_default (GstVideoDecoder * decoder,
1565 GstVideoDecoderPrivate *priv;
1566 gboolean res = FALSE;
1568 priv = decoder->priv;
1570 GST_DEBUG_OBJECT (decoder,
1571 "received event %d, %s", GST_EVENT_TYPE (event),
1572 GST_EVENT_TYPE_NAME (event));
1574 switch (GST_EVENT_TYPE (event)) {
1575 case GST_EVENT_SEEK:
1580 GstSeekType start_type, stop_type;
1582 gint64 tstart, tstop;
1585 gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
1587 seqnum = gst_event_get_seqnum (event);
1589 /* upstream gets a chance first */
1590 if ((res = gst_pad_push_event (decoder->sinkpad, event)))
1593 /* if upstream fails for a time seek, maybe we can help if allowed */
1594 if (format == GST_FORMAT_TIME) {
1595 if (gst_video_decoder_do_byte (decoder))
1596 res = gst_video_decoder_do_seek (decoder, event);
1600 /* ... though a non-time seek can be aided as well */
1601 /* First bring the requested format to time */
1603 gst_pad_query_convert (decoder->srcpad, format, start,
1604 GST_FORMAT_TIME, &tstart)))
1607 gst_pad_query_convert (decoder->srcpad, format, stop,
1608 GST_FORMAT_TIME, &tstop)))
1611 /* then seek with time on the peer */
1612 event = gst_event_new_seek (rate, GST_FORMAT_TIME,
1613 flags, start_type, tstart, stop_type, tstop);
1614 gst_event_set_seqnum (event, seqnum);
1616 res = gst_pad_push_event (decoder->sinkpad, event);
1623 GstClockTimeDiff diff;
1624 GstClockTime timestamp;
1626 gst_event_parse_qos (event, &type, &proportion, &diff, ×tamp);
1628 GST_OBJECT_LOCK (decoder);
1629 priv->proportion = proportion;
1630 if (G_LIKELY (GST_CLOCK_TIME_IS_VALID (timestamp))) {
1631 if (G_UNLIKELY (diff > 0)) {
1632 priv->earliest_time = timestamp + 2 * diff + priv->qos_frame_duration;
1634 priv->earliest_time = timestamp + diff;
1637 priv->earliest_time = GST_CLOCK_TIME_NONE;
1639 GST_OBJECT_UNLOCK (decoder);
1641 GST_DEBUG_OBJECT (decoder,
1642 "got QoS %" GST_TIME_FORMAT ", %" GST_STIME_FORMAT ", %g",
1643 GST_TIME_ARGS (timestamp), GST_STIME_ARGS (diff), proportion);
1645 res = gst_pad_push_event (decoder->sinkpad, event);
1649 res = gst_pad_push_event (decoder->sinkpad, event);
1656 GST_DEBUG_OBJECT (decoder, "could not convert format");
1661 gst_video_decoder_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
1663 GstVideoDecoder *decoder;
1664 GstVideoDecoderClass *decoder_class;
1665 gboolean ret = FALSE;
1667 decoder = GST_VIDEO_DECODER (parent);
1668 decoder_class = GST_VIDEO_DECODER_GET_CLASS (decoder);
1670 GST_DEBUG_OBJECT (decoder, "received event %d, %s", GST_EVENT_TYPE (event),
1671 GST_EVENT_TYPE_NAME (event));
1673 if (decoder_class->src_event)
1674 ret = decoder_class->src_event (decoder, event);
1680 gst_video_decoder_src_query_default (GstVideoDecoder * dec, GstQuery * query)
1682 GstPad *pad = GST_VIDEO_DECODER_SRC_PAD (dec);
1683 gboolean res = TRUE;
1685 GST_LOG_OBJECT (dec, "handling query: %" GST_PTR_FORMAT, query);
1687 switch (GST_QUERY_TYPE (query)) {
1688 case GST_QUERY_POSITION:
1693 /* upstream gets a chance first */
1694 if ((res = gst_pad_peer_query (dec->sinkpad, query))) {
1695 GST_LOG_OBJECT (dec, "returning peer response");
1699 /* we start from the last seen time */
1700 time = dec->priv->last_timestamp_out;
1701 /* correct for the segment values */
1702 time = gst_segment_to_stream_time (&dec->output_segment,
1703 GST_FORMAT_TIME, time);
1705 GST_LOG_OBJECT (dec,
1706 "query %p: our time: %" GST_TIME_FORMAT, query, GST_TIME_ARGS (time));
1708 /* and convert to the final format */
1709 gst_query_parse_position (query, &format, NULL);
1710 if (!(res = gst_pad_query_convert (pad, GST_FORMAT_TIME, time,
1714 gst_query_set_position (query, format, value);
1716 GST_LOG_OBJECT (dec,
1717 "query %p: we return %" G_GINT64_FORMAT " (format %u)", query, value,
1721 case GST_QUERY_DURATION:
1725 /* upstream in any case */
1726 if ((res = gst_pad_query_default (pad, GST_OBJECT (dec), query)))
1729 gst_query_parse_duration (query, &format, NULL);
1730 /* try answering TIME by converting from BYTE if subclass allows */
1731 if (format == GST_FORMAT_TIME && gst_video_decoder_do_byte (dec)) {
1734 if (gst_pad_peer_query_duration (dec->sinkpad, GST_FORMAT_BYTES,
1736 GST_LOG_OBJECT (dec, "upstream size %" G_GINT64_FORMAT, value);
1737 if (gst_pad_query_convert (dec->sinkpad,
1738 GST_FORMAT_BYTES, value, GST_FORMAT_TIME, &value)) {
1739 gst_query_set_duration (query, GST_FORMAT_TIME, value);
1746 case GST_QUERY_CONVERT:
1748 GstFormat src_fmt, dest_fmt;
1749 gint64 src_val, dest_val;
1751 GST_DEBUG_OBJECT (dec, "convert query");
1753 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
1754 GST_OBJECT_LOCK (dec);
1755 if (dec->priv->output_state != NULL)
1756 res = gst_video_rawvideo_convert (dec->priv->output_state,
1757 src_fmt, src_val, &dest_fmt, &dest_val);
1760 GST_OBJECT_UNLOCK (dec);
1763 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
1766 case GST_QUERY_LATENCY:
1769 GstClockTime min_latency, max_latency;
1771 res = gst_pad_peer_query (dec->sinkpad, query);
1773 gst_query_parse_latency (query, &live, &min_latency, &max_latency);
1774 GST_DEBUG_OBJECT (dec, "Peer qlatency: live %d, min %"
1775 GST_TIME_FORMAT " max %" GST_TIME_FORMAT, live,
1776 GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
1778 GST_OBJECT_LOCK (dec);
1779 min_latency += dec->priv->min_latency;
1780 if (max_latency == GST_CLOCK_TIME_NONE
1781 || dec->priv->max_latency == GST_CLOCK_TIME_NONE)
1782 max_latency = GST_CLOCK_TIME_NONE;
1784 max_latency += dec->priv->max_latency;
1785 GST_OBJECT_UNLOCK (dec);
1787 gst_query_set_latency (query, live, min_latency, max_latency);
1792 res = gst_pad_query_default (pad, GST_OBJECT (dec), query);
1797 GST_ERROR_OBJECT (dec, "query failed");
1802 gst_video_decoder_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
1804 GstVideoDecoder *decoder;
1805 GstVideoDecoderClass *decoder_class;
1806 gboolean ret = FALSE;
1808 decoder = GST_VIDEO_DECODER (parent);
1809 decoder_class = GST_VIDEO_DECODER_GET_CLASS (decoder);
1811 GST_DEBUG_OBJECT (decoder, "received query %d, %s", GST_QUERY_TYPE (query),
1812 GST_QUERY_TYPE_NAME (query));
1814 if (decoder_class->src_query)
1815 ret = decoder_class->src_query (decoder, query);
1821 * gst_video_decoder_proxy_getcaps:
1822 * @decoder: a #GstVideoDecoder
1823 * @caps: (allow-none): initial caps
1824 * @filter: (allow-none): filter caps
1826 * Returns caps that express @caps (or sink template caps if @caps == NULL)
1827 * restricted to resolution/format/... combinations supported by downstream
1830 * Returns: (transfer full): a #GstCaps owned by caller
1835 gst_video_decoder_proxy_getcaps (GstVideoDecoder * decoder, GstCaps * caps,
1838 return __gst_video_element_proxy_getcaps (GST_ELEMENT_CAST (decoder),
1839 GST_VIDEO_DECODER_SINK_PAD (decoder),
1840 GST_VIDEO_DECODER_SRC_PAD (decoder), caps, filter);
1844 gst_video_decoder_sink_getcaps (GstVideoDecoder * decoder, GstCaps * filter)
1846 GstVideoDecoderClass *klass;
1849 klass = GST_VIDEO_DECODER_GET_CLASS (decoder);
1852 caps = klass->getcaps (decoder, filter);
1854 caps = gst_video_decoder_proxy_getcaps (decoder, NULL, filter);
1856 GST_LOG_OBJECT (decoder, "Returning caps %" GST_PTR_FORMAT, caps);
1862 gst_video_decoder_sink_query_default (GstVideoDecoder * decoder,
1865 GstPad *pad = GST_VIDEO_DECODER_SINK_PAD (decoder);
1866 GstVideoDecoderPrivate *priv;
1867 gboolean res = FALSE;
1869 priv = decoder->priv;
1871 GST_LOG_OBJECT (decoder, "handling query: %" GST_PTR_FORMAT, query);
1873 switch (GST_QUERY_TYPE (query)) {
1874 case GST_QUERY_CONVERT:
1876 GstFormat src_fmt, dest_fmt;
1877 gint64 src_val, dest_val;
1879 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
1880 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
1882 gst_video_encoded_video_convert (priv->bytes_out, priv->time, src_fmt,
1883 src_val, &dest_fmt, &dest_val);
1884 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
1887 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
1890 case GST_QUERY_ALLOCATION:{
1891 GstVideoDecoderClass *klass = GST_VIDEO_DECODER_GET_CLASS (decoder);
1893 if (klass->propose_allocation)
1894 res = klass->propose_allocation (decoder, query);
1897 case GST_QUERY_CAPS:{
1898 GstCaps *filter, *caps;
1900 gst_query_parse_caps (query, &filter);
1901 caps = gst_video_decoder_sink_getcaps (decoder, filter);
1902 gst_query_set_caps_result (query, caps);
1903 gst_caps_unref (caps);
1907 case GST_QUERY_ACCEPT_CAPS:{
1908 if (decoder->priv->use_default_pad_acceptcaps) {
1910 gst_pad_query_default (GST_VIDEO_DECODER_SINK_PAD (decoder),
1911 GST_OBJECT_CAST (decoder), query);
1914 GstCaps *allowed_caps;
1915 GstCaps *template_caps;
1918 gst_query_parse_accept_caps (query, &caps);
1920 template_caps = gst_pad_get_pad_template_caps (pad);
1921 accept = gst_caps_is_subset (caps, template_caps);
1922 gst_caps_unref (template_caps);
1926 gst_pad_query_caps (GST_VIDEO_DECODER_SINK_PAD (decoder), caps);
1928 accept = gst_caps_can_intersect (caps, allowed_caps);
1930 gst_caps_unref (allowed_caps);
1933 gst_query_set_accept_caps_result (query, accept);
1939 res = gst_pad_query_default (pad, GST_OBJECT (decoder), query);
1946 GST_DEBUG_OBJECT (decoder, "query failed");
1952 gst_video_decoder_sink_query (GstPad * pad, GstObject * parent,
1955 GstVideoDecoder *decoder;
1956 GstVideoDecoderClass *decoder_class;
1957 gboolean ret = FALSE;
1959 decoder = GST_VIDEO_DECODER (parent);
1960 decoder_class = GST_VIDEO_DECODER_GET_CLASS (decoder);
1962 GST_DEBUG_OBJECT (decoder, "received query %d, %s", GST_QUERY_TYPE (query),
1963 GST_QUERY_TYPE_NAME (query));
1965 if (decoder_class->sink_query)
1966 ret = decoder_class->sink_query (decoder, query);
1971 typedef struct _Timestamp Timestamp;
1977 GstClockTime duration;
1981 timestamp_free (Timestamp * ts)
1983 g_slice_free (Timestamp, ts);
1987 gst_video_decoder_add_timestamp (GstVideoDecoder * decoder, GstBuffer * buffer)
1989 GstVideoDecoderPrivate *priv = decoder->priv;
1992 ts = g_slice_new (Timestamp);
1994 GST_LOG_OBJECT (decoder,
1995 "adding PTS %" GST_TIME_FORMAT " DTS %" GST_TIME_FORMAT
1996 " (offset:%" G_GUINT64_FORMAT ")",
1997 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
1998 GST_TIME_ARGS (GST_BUFFER_DTS (buffer)), priv->input_offset);
2000 ts->offset = priv->input_offset;
2001 ts->pts = GST_BUFFER_PTS (buffer);
2002 ts->dts = GST_BUFFER_DTS (buffer);
2003 ts->duration = GST_BUFFER_DURATION (buffer);
2005 priv->timestamps = g_list_append (priv->timestamps, ts);
2009 gst_video_decoder_get_timestamp_at_offset (GstVideoDecoder *
2010 decoder, guint64 offset, GstClockTime * pts, GstClockTime * dts,
2011 GstClockTime * duration)
2013 #ifndef GST_DISABLE_GST_DEBUG
2014 guint64 got_offset = 0;
2019 *pts = GST_CLOCK_TIME_NONE;
2020 *dts = GST_CLOCK_TIME_NONE;
2021 *duration = GST_CLOCK_TIME_NONE;
2023 g = decoder->priv->timestamps;
2026 if (ts->offset <= offset) {
2027 #ifndef GST_DISABLE_GST_DEBUG
2028 got_offset = ts->offset;
2032 *duration = ts->duration;
2034 decoder->priv->timestamps = g_list_remove (decoder->priv->timestamps, ts);
2035 timestamp_free (ts);
2041 GST_LOG_OBJECT (decoder,
2042 "got PTS %" GST_TIME_FORMAT " DTS %" GST_TIME_FORMAT " @ offs %"
2043 G_GUINT64_FORMAT " (wanted offset:%" G_GUINT64_FORMAT ")",
2044 GST_TIME_ARGS (*pts), GST_TIME_ARGS (*dts), got_offset, offset);
2048 gst_video_decoder_clear_queues (GstVideoDecoder * dec)
2050 GstVideoDecoderPrivate *priv = dec->priv;
2052 g_list_free_full (priv->output_queued,
2053 (GDestroyNotify) gst_mini_object_unref);
2054 priv->output_queued = NULL;
2056 g_list_free_full (priv->gather, (GDestroyNotify) gst_mini_object_unref);
2057 priv->gather = NULL;
2058 g_list_free_full (priv->decode, (GDestroyNotify) gst_video_codec_frame_unref);
2059 priv->decode = NULL;
2060 g_list_free_full (priv->parse, (GDestroyNotify) gst_mini_object_unref);
2062 g_list_free_full (priv->parse_gather,
2063 (GDestroyNotify) gst_video_codec_frame_unref);
2064 priv->parse_gather = NULL;
2065 g_list_free_full (priv->frames, (GDestroyNotify) gst_video_codec_frame_unref);
2066 priv->frames = NULL;
2070 gst_video_decoder_reset (GstVideoDecoder * decoder, gboolean full,
2071 gboolean flush_hard)
2073 GstVideoDecoderPrivate *priv = decoder->priv;
2075 GST_DEBUG_OBJECT (decoder, "reset full %d", full);
2077 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
2079 if (full || flush_hard) {
2080 gst_segment_init (&decoder->input_segment, GST_FORMAT_UNDEFINED);
2081 gst_segment_init (&decoder->output_segment, GST_FORMAT_UNDEFINED);
2082 gst_video_decoder_clear_queues (decoder);
2083 decoder->priv->in_out_segment_sync = TRUE;
2085 if (priv->current_frame) {
2086 gst_video_codec_frame_unref (priv->current_frame);
2087 priv->current_frame = NULL;
2090 g_list_free_full (priv->current_frame_events,
2091 (GDestroyNotify) gst_event_unref);
2092 priv->current_frame_events = NULL;
2093 g_list_free_full (priv->pending_events, (GDestroyNotify) gst_event_unref);
2094 priv->pending_events = NULL;
2096 priv->error_count = 0;
2097 priv->max_errors = GST_VIDEO_DECODER_MAX_ERRORS;
2098 priv->had_output_data = FALSE;
2099 priv->had_input_data = FALSE;
2101 GST_OBJECT_LOCK (decoder);
2102 priv->earliest_time = GST_CLOCK_TIME_NONE;
2103 priv->proportion = 0.5;
2104 GST_OBJECT_UNLOCK (decoder);
2108 if (priv->input_state)
2109 gst_video_codec_state_unref (priv->input_state);
2110 priv->input_state = NULL;
2111 GST_OBJECT_LOCK (decoder);
2112 if (priv->output_state)
2113 gst_video_codec_state_unref (priv->output_state);
2114 priv->output_state = NULL;
2116 priv->qos_frame_duration = 0;
2117 GST_OBJECT_UNLOCK (decoder);
2120 gst_tag_list_unref (priv->tags);
2122 priv->tags_merge_mode = GST_TAG_MERGE_APPEND;
2123 if (priv->upstream_tags) {
2124 gst_tag_list_unref (priv->upstream_tags);
2125 priv->upstream_tags = NULL;
2127 priv->tags_changed = FALSE;
2128 priv->reordered_output = FALSE;
2131 priv->processed = 0;
2133 priv->decode_frame_number = 0;
2134 priv->base_picture_number = 0;
2137 GST_DEBUG_OBJECT (decoder, "deactivate pool %" GST_PTR_FORMAT,
2139 gst_buffer_pool_set_active (priv->pool, FALSE);
2140 gst_object_unref (priv->pool);
2144 if (priv->allocator) {
2145 gst_object_unref (priv->allocator);
2146 priv->allocator = NULL;
2150 priv->discont = TRUE;
2152 priv->base_timestamp = GST_CLOCK_TIME_NONE;
2153 priv->last_timestamp_out = GST_CLOCK_TIME_NONE;
2154 priv->pts_delta = GST_CLOCK_TIME_NONE;
2156 priv->input_offset = 0;
2157 priv->frame_offset = 0;
2158 gst_adapter_clear (priv->input_adapter);
2159 gst_adapter_clear (priv->output_adapter);
2160 g_list_free_full (priv->timestamps, (GDestroyNotify) timestamp_free);
2161 priv->timestamps = NULL;
2163 priv->bytes_out = 0;
2166 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
2169 static GstFlowReturn
2170 gst_video_decoder_chain_forward (GstVideoDecoder * decoder,
2171 GstBuffer * buf, gboolean at_eos)
2173 GstVideoDecoderPrivate *priv;
2174 GstVideoDecoderClass *klass;
2175 GstFlowReturn ret = GST_FLOW_OK;
2177 klass = GST_VIDEO_DECODER_GET_CLASS (decoder);
2178 priv = decoder->priv;
2180 g_return_val_if_fail (priv->packetized || klass->parse, GST_FLOW_ERROR);
2182 if (priv->current_frame == NULL)
2183 priv->current_frame = gst_video_decoder_new_frame (decoder);
2185 if (GST_BUFFER_PTS_IS_VALID (buf) && !priv->packetized) {
2186 gst_video_decoder_add_timestamp (decoder, buf);
2188 priv->input_offset += gst_buffer_get_size (buf);
2190 if (priv->packetized) {
2191 if (!GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
2192 GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (priv->current_frame);
2195 priv->current_frame->input_buffer = buf;
2197 if (decoder->input_segment.rate < 0.0) {
2198 priv->parse_gather =
2199 g_list_prepend (priv->parse_gather, priv->current_frame);
2201 ret = gst_video_decoder_decode_frame (decoder, priv->current_frame);
2203 priv->current_frame = NULL;
2205 gst_adapter_push (priv->input_adapter, buf);
2207 ret = gst_video_decoder_parse_available (decoder, at_eos, TRUE);
2210 if (ret == GST_VIDEO_DECODER_FLOW_NEED_DATA)
2216 static GstFlowReturn
2217 gst_video_decoder_flush_decode (GstVideoDecoder * dec)
2219 GstVideoDecoderPrivate *priv = dec->priv;
2220 GstFlowReturn res = GST_FLOW_OK;
2223 GST_DEBUG_OBJECT (dec, "flushing buffers to decode");
2225 walk = priv->decode;
2228 GstVideoCodecFrame *frame = (GstVideoCodecFrame *) (walk->data);
2230 GST_DEBUG_OBJECT (dec, "decoding frame %p buffer %p, PTS %" GST_TIME_FORMAT
2231 ", DTS %" GST_TIME_FORMAT, frame, frame->input_buffer,
2232 GST_TIME_ARGS (GST_BUFFER_PTS (frame->input_buffer)),
2233 GST_TIME_ARGS (GST_BUFFER_DTS (frame->input_buffer)));
2237 priv->decode = g_list_delete_link (priv->decode, walk);
2239 /* decode buffer, resulting data prepended to queue */
2240 res = gst_video_decoder_decode_frame (dec, frame);
2241 if (res != GST_FLOW_OK)
2250 /* gst_video_decoder_flush_parse is called from the
2251 * chain_reverse() function when a buffer containing
2252 * a DISCONT - indicating that reverse playback
2253 * looped back to the next data block, and therefore
2254 * all available data should be fed through the
2255 * decoder and frames gathered for reversed output
2257 static GstFlowReturn
2258 gst_video_decoder_flush_parse (GstVideoDecoder * dec, gboolean at_eos)
2260 GstVideoDecoderPrivate *priv = dec->priv;
2261 GstFlowReturn res = GST_FLOW_OK;
2263 GstVideoDecoderClass *decoder_class;
2265 decoder_class = GST_VIDEO_DECODER_GET_CLASS (dec);
2267 GST_DEBUG_OBJECT (dec, "flushing buffers to parsing");
2269 /* Reverse the gather list, and prepend it to the parse list,
2270 * then flush to parse whatever we can */
2271 priv->gather = g_list_reverse (priv->gather);
2272 priv->parse = g_list_concat (priv->gather, priv->parse);
2273 priv->gather = NULL;
2275 /* clear buffer and decoder state */
2276 gst_video_decoder_flush (dec, FALSE);
2280 GstBuffer *buf = GST_BUFFER_CAST (walk->data);
2281 GList *next = walk->next;
2283 GST_DEBUG_OBJECT (dec, "parsing buffer %p, PTS %" GST_TIME_FORMAT
2284 ", DTS %" GST_TIME_FORMAT, buf, GST_TIME_ARGS (GST_BUFFER_PTS (buf)),
2285 GST_TIME_ARGS (GST_BUFFER_DTS (buf)));
2287 /* parse buffer, resulting frames prepended to parse_gather queue */
2288 gst_buffer_ref (buf);
2289 res = gst_video_decoder_chain_forward (dec, buf, at_eos);
2291 /* if we generated output, we can discard the buffer, else we
2292 * keep it in the queue */
2293 if (priv->parse_gather) {
2294 GST_DEBUG_OBJECT (dec, "parsed buffer to %p", priv->parse_gather->data);
2295 priv->parse = g_list_delete_link (priv->parse, walk);
2296 gst_buffer_unref (buf);
2298 GST_DEBUG_OBJECT (dec, "buffer did not decode, keeping");
2303 walk = priv->parse_gather;
2305 GstVideoCodecFrame *frame = (GstVideoCodecFrame *) (walk->data);
2308 /* this is reverse playback, check if we need to apply some segment
2309 * to the output before decoding, as during decoding the segment.rate
2310 * must be used to determine if a buffer should be pushed or added to
2311 * the output list for reverse pushing.
2313 * The new segment is not immediately pushed here because we must
2314 * wait for negotiation to happen before it can be pushed to avoid
2315 * pushing a segment before caps event. Negotiation only happens
2316 * when finish_frame is called.
2318 for (walk2 = frame->events; walk2;) {
2320 GstEvent *event = walk2->data;
2322 walk2 = g_list_next (walk2);
2323 if (GST_EVENT_TYPE (event) <= GST_EVENT_SEGMENT) {
2325 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
2328 GST_DEBUG_OBJECT (dec, "Segment at frame %p %" GST_TIME_FORMAT,
2329 frame, GST_TIME_ARGS (GST_BUFFER_PTS (frame->input_buffer)));
2330 gst_event_copy_segment (event, &segment);
2331 if (segment.format == GST_FORMAT_TIME) {
2332 dec->output_segment = segment;
2333 dec->priv->in_out_segment_sync =
2334 gst_segment_is_equal (&dec->input_segment, &segment);
2337 dec->priv->pending_events =
2338 g_list_append (dec->priv->pending_events, event);
2339 frame->events = g_list_delete_link (frame->events, cur);
2346 /* now we can process frames. Start by moving each frame from the parse_gather
2347 * to the decode list, reverse the order as we go, and stopping when/if we
2348 * copy a keyframe. */
2349 GST_DEBUG_OBJECT (dec, "checking parsed frames for a keyframe to decode");
2350 walk = priv->parse_gather;
2352 GstVideoCodecFrame *frame = (GstVideoCodecFrame *) (walk->data);
2354 /* remove from the gather list */
2355 priv->parse_gather = g_list_remove_link (priv->parse_gather, walk);
2357 /* move it to the front of the decode queue */
2358 priv->decode = g_list_concat (walk, priv->decode);
2360 /* if we copied a keyframe, flush and decode the decode queue */
2361 if (GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) {
2362 GST_DEBUG_OBJECT (dec, "found keyframe %p with PTS %" GST_TIME_FORMAT
2363 ", DTS %" GST_TIME_FORMAT, frame,
2364 GST_TIME_ARGS (GST_BUFFER_PTS (frame->input_buffer)),
2365 GST_TIME_ARGS (GST_BUFFER_DTS (frame->input_buffer)));
2366 res = gst_video_decoder_flush_decode (dec);
2367 if (res != GST_FLOW_OK)
2370 /* We need to tell the subclass to drain now.
2371 * We prefer the drain vfunc, but for backward-compat
2372 * we use a finish() vfunc if drain isn't implemented */
2373 if (decoder_class->drain) {
2374 GST_DEBUG_OBJECT (dec, "Draining");
2375 res = decoder_class->drain (dec);
2376 } else if (decoder_class->finish) {
2377 GST_FIXME_OBJECT (dec, "Sub-class should implement drain(). "
2378 "Calling finish() for backwards-compat");
2379 res = decoder_class->finish (dec);
2382 if (res != GST_FLOW_OK)
2385 /* now send queued data downstream */
2386 walk = priv->output_queued;
2388 GstBuffer *buf = GST_BUFFER_CAST (walk->data);
2390 if (G_LIKELY (res == GST_FLOW_OK)) {
2391 /* avoid stray DISCONT from forward processing,
2392 * which have no meaning in reverse pushing */
2393 GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
2395 /* Last chance to calculate a timestamp as we loop backwards
2396 * through the list */
2397 if (GST_BUFFER_TIMESTAMP (buf) != GST_CLOCK_TIME_NONE)
2398 priv->last_timestamp_out = GST_BUFFER_TIMESTAMP (buf);
2399 else if (priv->last_timestamp_out != GST_CLOCK_TIME_NONE &&
2400 GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE) {
2401 GST_BUFFER_TIMESTAMP (buf) =
2402 priv->last_timestamp_out - GST_BUFFER_DURATION (buf);
2403 priv->last_timestamp_out = GST_BUFFER_TIMESTAMP (buf);
2404 GST_LOG_OBJECT (dec,
2405 "Calculated TS %" GST_TIME_FORMAT " working backwards",
2406 GST_TIME_ARGS (priv->last_timestamp_out));
2409 res = gst_video_decoder_clip_and_push_buf (dec, buf);
2411 gst_buffer_unref (buf);
2414 priv->output_queued =
2415 g_list_delete_link (priv->output_queued, priv->output_queued);
2416 walk = priv->output_queued;
2419 /* clear buffer and decoder state again
2420 * before moving to the previous keyframe */
2421 gst_video_decoder_flush (dec, FALSE);
2424 walk = priv->parse_gather;
2431 static GstFlowReturn
2432 gst_video_decoder_chain_reverse (GstVideoDecoder * dec, GstBuffer * buf)
2434 GstVideoDecoderPrivate *priv = dec->priv;
2435 GstFlowReturn result = GST_FLOW_OK;
2437 /* if we have a discont, move buffers to the decode list */
2438 if (!buf || GST_BUFFER_IS_DISCONT (buf)) {
2439 GST_DEBUG_OBJECT (dec, "received discont");
2441 /* parse and decode stuff in the gather and parse queues */
2442 result = gst_video_decoder_flush_parse (dec, FALSE);
2445 if (G_LIKELY (buf)) {
2446 GST_DEBUG_OBJECT (dec, "gathering buffer %p of size %" G_GSIZE_FORMAT ", "
2447 "PTS %" GST_TIME_FORMAT ", DTS %" GST_TIME_FORMAT ", dur %"
2448 GST_TIME_FORMAT, buf, gst_buffer_get_size (buf),
2449 GST_TIME_ARGS (GST_BUFFER_PTS (buf)),
2450 GST_TIME_ARGS (GST_BUFFER_DTS (buf)),
2451 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
2453 /* add buffer to gather queue */
2454 priv->gather = g_list_prepend (priv->gather, buf);
2460 static GstFlowReturn
2461 gst_video_decoder_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
2463 GstVideoDecoder *decoder;
2464 GstFlowReturn ret = GST_FLOW_OK;
2466 decoder = GST_VIDEO_DECODER (parent);
2468 if (G_UNLIKELY (!decoder->priv->input_state && decoder->priv->needs_format))
2469 goto not_negotiated;
2471 GST_LOG_OBJECT (decoder,
2472 "chain PTS %" GST_TIME_FORMAT ", DTS %" GST_TIME_FORMAT " duration %"
2473 GST_TIME_FORMAT " size %" G_GSIZE_FORMAT,
2474 GST_TIME_ARGS (GST_BUFFER_PTS (buf)),
2475 GST_TIME_ARGS (GST_BUFFER_DTS (buf)),
2476 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), gst_buffer_get_size (buf));
2478 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
2481 * requiring the pad to be negotiated makes it impossible to use
2482 * oggdemux or filesrc ! decoder */
2484 if (decoder->input_segment.format == GST_FORMAT_UNDEFINED) {
2486 GstSegment *segment = &decoder->input_segment;
2488 GST_WARNING_OBJECT (decoder,
2489 "Received buffer without a new-segment. "
2490 "Assuming timestamps start from 0.");
2492 gst_segment_init (segment, GST_FORMAT_TIME);
2494 event = gst_event_new_segment (segment);
2496 decoder->priv->current_frame_events =
2497 g_list_prepend (decoder->priv->current_frame_events, event);
2500 decoder->priv->had_input_data = TRUE;
2502 if (decoder->input_segment.rate > 0.0)
2503 ret = gst_video_decoder_chain_forward (decoder, buf, FALSE);
2505 ret = gst_video_decoder_chain_reverse (decoder, buf);
2507 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
2513 GST_ELEMENT_ERROR (decoder, CORE, NEGOTIATION, (NULL),
2514 ("decoder not initialized"));
2515 gst_buffer_unref (buf);
2516 return GST_FLOW_NOT_NEGOTIATED;
2520 static GstStateChangeReturn
2521 gst_video_decoder_change_state (GstElement * element, GstStateChange transition)
2523 GstVideoDecoder *decoder;
2524 GstVideoDecoderClass *decoder_class;
2525 GstStateChangeReturn ret;
2527 decoder = GST_VIDEO_DECODER (element);
2528 decoder_class = GST_VIDEO_DECODER_GET_CLASS (element);
2530 switch (transition) {
2531 case GST_STATE_CHANGE_NULL_TO_READY:
2532 /* open device/library if needed */
2533 if (decoder_class->open && !decoder_class->open (decoder))
2536 case GST_STATE_CHANGE_READY_TO_PAUSED:
2537 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
2538 gst_video_decoder_reset (decoder, TRUE, TRUE);
2539 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
2541 /* Initialize device/library if needed */
2542 if (decoder_class->start && !decoder_class->start (decoder))
2549 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
2551 switch (transition) {
2552 case GST_STATE_CHANGE_PAUSED_TO_READY:{
2553 gboolean stopped = TRUE;
2555 if (decoder_class->stop)
2556 stopped = decoder_class->stop (decoder);
2558 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
2559 gst_video_decoder_reset (decoder, TRUE, TRUE);
2560 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
2567 case GST_STATE_CHANGE_READY_TO_NULL:
2568 /* close device/library if needed */
2569 if (decoder_class->close && !decoder_class->close (decoder))
2581 GST_ELEMENT_ERROR (decoder, LIBRARY, INIT, (NULL),
2582 ("Failed to open decoder"));
2583 return GST_STATE_CHANGE_FAILURE;
2588 GST_ELEMENT_ERROR (decoder, LIBRARY, INIT, (NULL),
2589 ("Failed to start decoder"));
2590 return GST_STATE_CHANGE_FAILURE;
2595 GST_ELEMENT_ERROR (decoder, LIBRARY, INIT, (NULL),
2596 ("Failed to stop decoder"));
2597 return GST_STATE_CHANGE_FAILURE;
2602 GST_ELEMENT_ERROR (decoder, LIBRARY, INIT, (NULL),
2603 ("Failed to close decoder"));
2604 return GST_STATE_CHANGE_FAILURE;
2608 static GstVideoCodecFrame *
2609 gst_video_decoder_new_frame (GstVideoDecoder * decoder)
2611 GstVideoDecoderPrivate *priv = decoder->priv;
2612 GstVideoCodecFrame *frame;
2614 frame = g_slice_new0 (GstVideoCodecFrame);
2616 frame->ref_count = 1;
2618 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
2619 frame->system_frame_number = priv->system_frame_number;
2620 priv->system_frame_number++;
2621 frame->decode_frame_number = priv->decode_frame_number;
2622 priv->decode_frame_number++;
2624 frame->dts = GST_CLOCK_TIME_NONE;
2625 frame->pts = GST_CLOCK_TIME_NONE;
2626 frame->duration = GST_CLOCK_TIME_NONE;
2627 frame->events = priv->current_frame_events;
2628 priv->current_frame_events = NULL;
2630 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
2632 GST_LOG_OBJECT (decoder, "Created new frame %p (sfn:%d)",
2633 frame, frame->system_frame_number);
2639 gst_video_decoder_push_event_list (GstVideoDecoder * decoder, GList * events)
2643 /* events are stored in reverse order */
2644 for (l = g_list_last (events); l; l = g_list_previous (l)) {
2645 GST_LOG_OBJECT (decoder, "pushing %s event", GST_EVENT_TYPE_NAME (l->data));
2646 gst_video_decoder_push_event (decoder, l->data);
2648 g_list_free (events);
2652 gst_video_decoder_prepare_finish_frame (GstVideoDecoder *
2653 decoder, GstVideoCodecFrame * frame, gboolean dropping)
2655 GstVideoDecoderPrivate *priv = decoder->priv;
2656 GList *l, *events = NULL;
2659 #ifndef GST_DISABLE_GST_DEBUG
2660 GST_LOG_OBJECT (decoder, "n %d in %" G_GSIZE_FORMAT " out %" G_GSIZE_FORMAT,
2661 g_list_length (priv->frames),
2662 gst_adapter_available (priv->input_adapter),
2663 gst_adapter_available (priv->output_adapter));
2666 sync = GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame);
2668 GST_LOG_OBJECT (decoder,
2669 "finish frame %p (#%d) sync:%d PTS:%" GST_TIME_FORMAT " DTS:%"
2671 frame, frame->system_frame_number,
2672 sync, GST_TIME_ARGS (frame->pts), GST_TIME_ARGS (frame->dts));
2674 /* Push all pending events that arrived before this frame */
2675 for (l = priv->frames; l; l = l->next) {
2676 GstVideoCodecFrame *tmp = l->data;
2679 events = g_list_concat (events, tmp->events);
2687 if (dropping || !decoder->priv->output_state) {
2688 /* Push before the next frame that is not dropped */
2689 decoder->priv->pending_events =
2690 g_list_concat (decoder->priv->pending_events, events);
2692 gst_video_decoder_push_event_list (decoder, decoder->priv->pending_events);
2693 decoder->priv->pending_events = NULL;
2695 gst_video_decoder_push_event_list (decoder, events);
2698 /* Check if the data should not be displayed. For example altref/invisible
2699 * frame in vp8. In this case we should not update the timestamps. */
2700 if (GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY (frame))
2703 /* If the frame is meant to be output but we don't have an output_buffer
2704 * we have a problem :) */
2705 if (G_UNLIKELY ((frame->output_buffer == NULL) && !dropping))
2706 goto no_output_buffer;
2708 if (GST_CLOCK_TIME_IS_VALID (frame->pts)) {
2709 if (frame->pts != priv->base_timestamp) {
2710 GST_DEBUG_OBJECT (decoder,
2711 "sync timestamp %" GST_TIME_FORMAT " diff %" GST_STIME_FORMAT,
2712 GST_TIME_ARGS (frame->pts),
2713 GST_STIME_ARGS (GST_CLOCK_DIFF (frame->pts,
2714 decoder->output_segment.start)));
2715 priv->base_timestamp = frame->pts;
2716 priv->base_picture_number = frame->decode_frame_number;
2720 if (frame->duration == GST_CLOCK_TIME_NONE) {
2721 frame->duration = gst_video_decoder_get_frame_duration (decoder, frame);
2722 GST_LOG_OBJECT (decoder,
2723 "Guessing duration %" GST_TIME_FORMAT " for frame...",
2724 GST_TIME_ARGS (frame->duration));
2727 /* PTS is expected montone ascending,
2728 * so a good guess is lowest unsent DTS */
2730 GstClockTime min_ts = GST_CLOCK_TIME_NONE;
2731 GstVideoCodecFrame *oframe = NULL;
2732 gboolean seen_none = FALSE;
2734 /* some maintenance regardless */
2735 for (l = priv->frames; l; l = l->next) {
2736 GstVideoCodecFrame *tmp = l->data;
2738 if (!GST_CLOCK_TIME_IS_VALID (tmp->abidata.ABI.ts)) {
2743 if (!GST_CLOCK_TIME_IS_VALID (min_ts) || tmp->abidata.ABI.ts < min_ts) {
2744 min_ts = tmp->abidata.ABI.ts;
2748 /* save a ts if needed */
2749 if (oframe && oframe != frame) {
2750 oframe->abidata.ABI.ts = frame->abidata.ABI.ts;
2753 /* and set if needed;
2754 * valid delta means we have reasonable DTS input */
2755 /* also, if we ended up reordered, means this approach is conflicting
2756 * with some sparse existing PTS, and so it does not work out */
2757 if (!priv->reordered_output &&
2758 !GST_CLOCK_TIME_IS_VALID (frame->pts) && !seen_none &&
2759 GST_CLOCK_TIME_IS_VALID (priv->pts_delta)) {
2760 frame->pts = min_ts + priv->pts_delta;
2761 GST_DEBUG_OBJECT (decoder,
2762 "no valid PTS, using oldest DTS %" GST_TIME_FORMAT,
2763 GST_TIME_ARGS (frame->pts));
2766 /* some more maintenance, ts2 holds PTS */
2767 min_ts = GST_CLOCK_TIME_NONE;
2769 for (l = priv->frames; l; l = l->next) {
2770 GstVideoCodecFrame *tmp = l->data;
2772 if (!GST_CLOCK_TIME_IS_VALID (tmp->abidata.ABI.ts2)) {
2777 if (!GST_CLOCK_TIME_IS_VALID (min_ts) || tmp->abidata.ABI.ts2 < min_ts) {
2778 min_ts = tmp->abidata.ABI.ts2;
2782 /* save a ts if needed */
2783 if (oframe && oframe != frame) {
2784 oframe->abidata.ABI.ts2 = frame->abidata.ABI.ts2;
2787 /* if we detected reordered output, then PTS are void,
2788 * however those were obtained; bogus input, subclass etc */
2789 if (priv->reordered_output && !seen_none) {
2790 GST_DEBUG_OBJECT (decoder, "invalidating PTS");
2791 frame->pts = GST_CLOCK_TIME_NONE;
2794 if (!GST_CLOCK_TIME_IS_VALID (frame->pts) && !seen_none) {
2795 frame->pts = min_ts;
2796 GST_DEBUG_OBJECT (decoder,
2797 "no valid PTS, using oldest PTS %" GST_TIME_FORMAT,
2798 GST_TIME_ARGS (frame->pts));
2803 if (frame->pts == GST_CLOCK_TIME_NONE) {
2804 /* Last ditch timestamp guess: Just add the duration to the previous
2805 * frame. If it's the first frame, just use the segment start. */
2806 if (frame->duration != GST_CLOCK_TIME_NONE) {
2807 if (GST_CLOCK_TIME_IS_VALID (priv->last_timestamp_out))
2808 frame->pts = priv->last_timestamp_out + frame->duration;
2810 frame->pts = decoder->output_segment.start;
2811 GST_LOG_OBJECT (decoder,
2812 "Guessing timestamp %" GST_TIME_FORMAT " for frame...",
2813 GST_TIME_ARGS (frame->pts));
2814 } else if (sync && frame->dts != GST_CLOCK_TIME_NONE) {
2815 frame->pts = frame->dts;
2816 GST_LOG_OBJECT (decoder,
2817 "Setting DTS as PTS %" GST_TIME_FORMAT " for frame...",
2818 GST_TIME_ARGS (frame->pts));
2822 if (GST_CLOCK_TIME_IS_VALID (priv->last_timestamp_out)) {
2823 if (frame->pts < priv->last_timestamp_out) {
2824 GST_WARNING_OBJECT (decoder,
2825 "decreasing timestamp (%" GST_TIME_FORMAT " < %"
2826 GST_TIME_FORMAT ")",
2827 GST_TIME_ARGS (frame->pts), GST_TIME_ARGS (priv->last_timestamp_out));
2828 priv->reordered_output = TRUE;
2829 /* make it a bit less weird downstream */
2830 frame->pts = priv->last_timestamp_out;
2834 if (GST_CLOCK_TIME_IS_VALID (frame->pts))
2835 priv->last_timestamp_out = frame->pts;
2842 GST_ERROR_OBJECT (decoder, "No buffer to output !");
2847 * gst_video_decoder_release_frame:
2848 * @dec: a #GstVideoDecoder
2849 * @frame: (transfer full): the #GstVideoCodecFrame to release
2851 * Similar to gst_video_decoder_drop_frame(), but simply releases @frame
2852 * without any processing other than removing it from list of pending frames,
2853 * after which it is considered finished and released.
2858 gst_video_decoder_release_frame (GstVideoDecoder * dec,
2859 GstVideoCodecFrame * frame)
2863 /* unref once from the list */
2864 GST_VIDEO_DECODER_STREAM_LOCK (dec);
2865 link = g_list_find (dec->priv->frames, frame);
2867 gst_video_codec_frame_unref (frame);
2868 dec->priv->frames = g_list_delete_link (dec->priv->frames, link);
2870 if (frame->events) {
2871 dec->priv->pending_events =
2872 g_list_concat (dec->priv->pending_events, frame->events);
2873 frame->events = NULL;
2875 GST_VIDEO_DECODER_STREAM_UNLOCK (dec);
2877 /* unref because this function takes ownership */
2878 gst_video_codec_frame_unref (frame);
2882 * gst_video_decoder_drop_frame:
2883 * @dec: a #GstVideoDecoder
2884 * @frame: (transfer full): the #GstVideoCodecFrame to drop
2886 * Similar to gst_video_decoder_finish_frame(), but drops @frame in any
2887 * case and posts a QoS message with the frame's details on the bus.
2888 * In any case, the frame is considered finished and released.
2890 * Returns: a #GstFlowReturn, usually GST_FLOW_OK.
2893 gst_video_decoder_drop_frame (GstVideoDecoder * dec, GstVideoCodecFrame * frame)
2895 GstClockTime stream_time, jitter, earliest_time, qostime, timestamp;
2896 GstSegment *segment;
2897 GstMessage *qos_msg;
2900 GST_LOG_OBJECT (dec, "drop frame %p", frame);
2902 GST_VIDEO_DECODER_STREAM_LOCK (dec);
2904 gst_video_decoder_prepare_finish_frame (dec, frame, TRUE);
2906 GST_DEBUG_OBJECT (dec, "dropping frame %" GST_TIME_FORMAT,
2907 GST_TIME_ARGS (frame->pts));
2909 dec->priv->dropped++;
2911 /* post QoS message */
2912 GST_OBJECT_LOCK (dec);
2913 proportion = dec->priv->proportion;
2914 earliest_time = dec->priv->earliest_time;
2915 GST_OBJECT_UNLOCK (dec);
2917 timestamp = frame->pts;
2918 segment = &dec->output_segment;
2919 if (G_UNLIKELY (segment->format == GST_FORMAT_UNDEFINED))
2920 segment = &dec->input_segment;
2922 gst_segment_to_stream_time (segment, GST_FORMAT_TIME, timestamp);
2923 qostime = gst_segment_to_running_time (segment, GST_FORMAT_TIME, timestamp);
2924 jitter = GST_CLOCK_DIFF (qostime, earliest_time);
2926 gst_message_new_qos (GST_OBJECT_CAST (dec), FALSE, qostime, stream_time,
2927 timestamp, GST_CLOCK_TIME_NONE);
2928 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
2929 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
2930 dec->priv->processed, dec->priv->dropped);
2931 gst_element_post_message (GST_ELEMENT_CAST (dec), qos_msg);
2933 /* now free the frame */
2934 gst_video_decoder_release_frame (dec, frame);
2936 GST_VIDEO_DECODER_STREAM_UNLOCK (dec);
2942 gst_video_decoder_transform_meta_default (GstVideoDecoder *
2943 decoder, GstVideoCodecFrame * frame, GstMeta * meta)
2945 const GstMetaInfo *info = meta->info;
2946 const gchar *const *tags;
2948 tags = gst_meta_api_type_get_tags (info->api);
2950 if (!tags || (g_strv_length ((gchar **) tags) == 1
2951 && gst_meta_api_type_has_tag (info->api,
2952 g_quark_from_string (GST_META_TAG_VIDEO_STR))))
2960 GstVideoDecoder *decoder;
2961 GstVideoCodecFrame *frame;
2965 foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
2967 CopyMetaData *data = user_data;
2968 GstVideoDecoder *decoder = data->decoder;
2969 GstVideoDecoderClass *klass = GST_VIDEO_DECODER_GET_CLASS (decoder);
2970 GstVideoCodecFrame *frame = data->frame;
2971 const GstMetaInfo *info = (*meta)->info;
2972 gboolean do_copy = FALSE;
2974 if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)) {
2975 /* never call the transform_meta with memory specific metadata */
2976 GST_DEBUG_OBJECT (decoder, "not copying memory specific metadata %s",
2977 g_type_name (info->api));
2979 } else if (klass->transform_meta) {
2980 do_copy = klass->transform_meta (decoder, frame, *meta);
2981 GST_DEBUG_OBJECT (decoder, "transformed metadata %s: copy: %d",
2982 g_type_name (info->api), do_copy);
2985 /* we only copy metadata when the subclass implemented a transform_meta
2986 * function and when it returns %TRUE */
2988 GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
2989 GST_DEBUG_OBJECT (decoder, "copy metadata %s", g_type_name (info->api));
2990 /* simply copy then */
2991 info->transform_func (frame->output_buffer, *meta, inbuf,
2992 _gst_meta_transform_copy, ©_data);
2998 * gst_video_decoder_finish_frame:
2999 * @decoder: a #GstVideoDecoder
3000 * @frame: (transfer full): a decoded #GstVideoCodecFrame
3002 * @frame should have a valid decoded data buffer, whose metadata fields
3003 * are then appropriately set according to frame data and pushed downstream.
3004 * If no output data is provided, @frame is considered skipped.
3005 * In any case, the frame is considered finished and released.
3007 * After calling this function the output buffer of the frame is to be
3008 * considered read-only. This function will also change the metadata
3011 * Returns: a #GstFlowReturn resulting from sending data downstream
3014 gst_video_decoder_finish_frame (GstVideoDecoder * decoder,
3015 GstVideoCodecFrame * frame)
3017 GstFlowReturn ret = GST_FLOW_OK;
3018 GstVideoDecoderClass *decoder_class = GST_VIDEO_DECODER_GET_CLASS (decoder);
3019 GstVideoDecoderPrivate *priv = decoder->priv;
3020 GstBuffer *output_buffer;
3021 gboolean needs_reconfigure = FALSE;
3023 GST_LOG_OBJECT (decoder, "finish frame %p", frame);
3025 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3027 needs_reconfigure = gst_pad_check_reconfigure (decoder->srcpad);
3028 if (G_UNLIKELY (priv->output_state_changed || (priv->output_state
3029 && needs_reconfigure))) {
3030 if (!gst_video_decoder_negotiate_unlocked (decoder)) {
3031 gst_pad_mark_reconfigure (decoder->srcpad);
3032 if (GST_PAD_IS_FLUSHING (decoder->srcpad))
3033 ret = GST_FLOW_FLUSHING;
3035 ret = GST_FLOW_NOT_NEGOTIATED;
3040 gst_video_decoder_prepare_finish_frame (decoder, frame, FALSE);
3043 if (priv->tags_changed) {
3044 GstEvent *tags_event;
3046 tags_event = gst_video_decoder_create_merged_tags_event (decoder);
3048 if (tags_event != NULL)
3049 gst_video_decoder_push_event (decoder, tags_event);
3051 priv->tags_changed = FALSE;
3054 /* no buffer data means this frame is skipped */
3055 if (!frame->output_buffer || GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY (frame)) {
3056 GST_DEBUG_OBJECT (decoder, "skipping frame %" GST_TIME_FORMAT,
3057 GST_TIME_ARGS (frame->pts));
3061 output_buffer = frame->output_buffer;
3063 GST_BUFFER_FLAG_UNSET (output_buffer, GST_BUFFER_FLAG_DELTA_UNIT);
3065 GST_BUFFER_PTS (output_buffer) = frame->pts;
3066 GST_BUFFER_DTS (output_buffer) = GST_CLOCK_TIME_NONE;
3067 GST_BUFFER_DURATION (output_buffer) = frame->duration;
3069 GST_BUFFER_OFFSET (output_buffer) = GST_BUFFER_OFFSET_NONE;
3070 GST_BUFFER_OFFSET_END (output_buffer) = GST_BUFFER_OFFSET_NONE;
3072 if (priv->discont) {
3073 GST_BUFFER_FLAG_SET (output_buffer, GST_BUFFER_FLAG_DISCONT);
3074 priv->discont = FALSE;
3077 if (decoder_class->transform_meta) {
3078 if (G_LIKELY (frame->input_buffer)) {
3081 data.decoder = decoder;
3083 gst_buffer_foreach_meta (frame->input_buffer, foreach_metadata, &data);
3085 GST_WARNING_OBJECT (decoder,
3086 "Can't copy metadata because input frame disappeared");
3090 /* Get an additional ref to the buffer, which is going to be pushed
3091 * downstream, the original ref is owned by the frame
3093 * FIXME: clip_and_push_buf() changes buffer metadata but the buffer
3094 * might have a refcount > 1 */
3095 output_buffer = gst_buffer_ref (output_buffer);
3097 /* Release frame so the buffer is writable when we push it downstream
3098 * if possible, i.e. if the subclass does not hold additional references
3101 gst_video_decoder_release_frame (decoder, frame);
3104 if (decoder->output_segment.rate < 0.0) {
3105 GST_LOG_OBJECT (decoder, "queued frame");
3106 priv->output_queued = g_list_prepend (priv->output_queued, output_buffer);
3108 ret = gst_video_decoder_clip_and_push_buf (decoder, output_buffer);
3113 gst_video_decoder_release_frame (decoder, frame);
3114 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3118 /* With stream lock, takes the frame reference */
3119 static GstFlowReturn
3120 gst_video_decoder_clip_and_push_buf (GstVideoDecoder * decoder, GstBuffer * buf)
3122 GstFlowReturn ret = GST_FLOW_OK;
3123 GstVideoDecoderPrivate *priv = decoder->priv;
3124 guint64 start, stop;
3125 guint64 cstart, cstop;
3126 GstSegment *segment;
3127 GstClockTime duration;
3129 /* Check for clipping */
3130 start = GST_BUFFER_PTS (buf);
3131 duration = GST_BUFFER_DURATION (buf);
3133 /* store that we have valid decoded data */
3134 priv->had_output_data = TRUE;
3136 stop = GST_CLOCK_TIME_NONE;
3138 if (GST_CLOCK_TIME_IS_VALID (start) && GST_CLOCK_TIME_IS_VALID (duration)) {
3139 stop = start + duration;
3140 } else if (GST_CLOCK_TIME_IS_VALID (start)
3141 && !GST_CLOCK_TIME_IS_VALID (duration)) {
3142 /* If we don't clip away buffers that far before the segment we
3143 * can cause the pipeline to lockup. This can happen if audio is
3144 * properly clipped, and thus the audio sink does not preroll yet
3145 * but the video sink prerolls because we already outputted a
3146 * buffer here... and then queues run full.
3148 * In the worst case we will clip one buffer too many here now if no
3149 * framerate is given, no buffer duration is given and the actual
3150 * framerate is lower than 25fps */
3151 stop = start + 40 * GST_MSECOND;
3154 segment = &decoder->output_segment;
3155 if (gst_segment_clip (segment, GST_FORMAT_TIME, start, stop, &cstart, &cstop)) {
3156 GST_BUFFER_PTS (buf) = cstart;
3158 if (stop != GST_CLOCK_TIME_NONE && GST_CLOCK_TIME_IS_VALID (duration))
3159 GST_BUFFER_DURATION (buf) = cstop - cstart;
3161 GST_LOG_OBJECT (decoder,
3162 "accepting buffer inside segment: %" GST_TIME_FORMAT " %"
3163 GST_TIME_FORMAT " seg %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT
3164 " time %" GST_TIME_FORMAT,
3165 GST_TIME_ARGS (cstart),
3166 GST_TIME_ARGS (cstop),
3167 GST_TIME_ARGS (segment->start), GST_TIME_ARGS (segment->stop),
3168 GST_TIME_ARGS (segment->time));
3170 GST_LOG_OBJECT (decoder,
3171 "dropping buffer outside segment: %" GST_TIME_FORMAT
3172 " %" GST_TIME_FORMAT
3173 " seg %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT
3174 " time %" GST_TIME_FORMAT,
3175 GST_TIME_ARGS (start), GST_TIME_ARGS (stop),
3176 GST_TIME_ARGS (segment->start),
3177 GST_TIME_ARGS (segment->stop), GST_TIME_ARGS (segment->time));
3178 /* only check and return EOS if upstream still
3179 * in the same segment and interested as such */
3180 if (decoder->priv->in_out_segment_sync) {
3181 if (segment->rate >= 0) {
3182 if (GST_BUFFER_PTS (buf) >= segment->stop)
3184 } else if (GST_BUFFER_PTS (buf) < segment->start) {
3188 gst_buffer_unref (buf);
3192 /* update rate estimate */
3193 priv->bytes_out += gst_buffer_get_size (buf);
3194 if (GST_CLOCK_TIME_IS_VALID (duration)) {
3195 priv->time += duration;
3197 /* FIXME : Use difference between current and previous outgoing
3198 * timestamp, and relate to difference between current and previous
3200 /* better none than nothing valid */
3201 priv->time = GST_CLOCK_TIME_NONE;
3204 GST_DEBUG_OBJECT (decoder, "pushing buffer %p of size %" G_GSIZE_FORMAT ", "
3205 "PTS %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf,
3206 gst_buffer_get_size (buf),
3207 GST_TIME_ARGS (GST_BUFFER_PTS (buf)),
3208 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
3210 /* we got data, so note things are looking up again, reduce
3211 * the error count, if there is one */
3212 if (G_UNLIKELY (priv->error_count))
3213 priv->error_count = 0;
3215 ret = gst_pad_push (decoder->srcpad, buf);
3222 * gst_video_decoder_add_to_frame:
3223 * @decoder: a #GstVideoDecoder
3224 * @n_bytes: the number of bytes to add
3226 * Removes next @n_bytes of input data and adds it to currently parsed frame.
3229 gst_video_decoder_add_to_frame (GstVideoDecoder * decoder, int n_bytes)
3231 GstVideoDecoderPrivate *priv = decoder->priv;
3234 GST_LOG_OBJECT (decoder, "add %d bytes to frame", n_bytes);
3239 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3240 if (gst_adapter_available (priv->output_adapter) == 0) {
3241 priv->frame_offset =
3242 priv->input_offset - gst_adapter_available (priv->input_adapter);
3244 buf = gst_adapter_take_buffer (priv->input_adapter, n_bytes);
3246 gst_adapter_push (priv->output_adapter, buf);
3247 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3251 * gst_video_decoder_get_pending_frame_size:
3252 * @decoder: a #GstVideoDecoder
3254 * Returns the number of bytes previously added to the current frame
3255 * by calling gst_video_decoder_add_to_frame().
3257 * Returns: The number of bytes pending for the current frame
3262 gst_video_decoder_get_pending_frame_size (GstVideoDecoder * decoder)
3264 GstVideoDecoderPrivate *priv = decoder->priv;
3267 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3268 ret = gst_adapter_available (priv->output_adapter);
3269 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3271 GST_LOG_OBJECT (decoder, "Current pending frame has %" G_GSIZE_FORMAT "bytes",
3278 gst_video_decoder_get_frame_duration (GstVideoDecoder * decoder,
3279 GstVideoCodecFrame * frame)
3281 GstVideoCodecState *state = decoder->priv->output_state;
3283 /* it's possible that we don't have a state yet when we are dropping the
3284 * initial buffers */
3286 return GST_CLOCK_TIME_NONE;
3288 if (state->info.fps_d == 0 || state->info.fps_n == 0) {
3289 return GST_CLOCK_TIME_NONE;
3292 /* FIXME: For interlaced frames this needs to take into account
3293 * the number of valid fields in the frame
3296 return gst_util_uint64_scale (GST_SECOND, state->info.fps_d,
3301 * gst_video_decoder_have_frame:
3302 * @decoder: a #GstVideoDecoder
3304 * Gathers all data collected for currently parsed frame, gathers corresponding
3305 * metadata and passes it along for further processing, i.e. @handle_frame.
3307 * Returns: a #GstFlowReturn
3310 gst_video_decoder_have_frame (GstVideoDecoder * decoder)
3312 GstVideoDecoderPrivate *priv = decoder->priv;
3315 GstClockTime pts, dts, duration;
3316 GstFlowReturn ret = GST_FLOW_OK;
3318 GST_LOG_OBJECT (decoder, "have_frame");
3320 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3322 n_available = gst_adapter_available (priv->output_adapter);
3324 buffer = gst_adapter_take_buffer (priv->output_adapter, n_available);
3326 buffer = gst_buffer_new_and_alloc (0);
3329 priv->current_frame->input_buffer = buffer;
3331 gst_video_decoder_get_timestamp_at_offset (decoder,
3332 priv->frame_offset, &pts, &dts, &duration);
3334 GST_BUFFER_PTS (buffer) = pts;
3335 GST_BUFFER_DTS (buffer) = dts;
3336 GST_BUFFER_DURATION (buffer) = duration;
3338 GST_LOG_OBJECT (decoder, "collected frame size %d, "
3339 "PTS %" GST_TIME_FORMAT ", DTS %" GST_TIME_FORMAT ", dur %"
3340 GST_TIME_FORMAT, n_available, GST_TIME_ARGS (pts), GST_TIME_ARGS (dts),
3341 GST_TIME_ARGS (duration));
3343 /* In reverse playback, just capture and queue frames for later processing */
3344 if (decoder->output_segment.rate < 0.0) {
3345 priv->parse_gather =
3346 g_list_prepend (priv->parse_gather, priv->current_frame);
3348 /* Otherwise, decode the frame, which gives away our ref */
3349 ret = gst_video_decoder_decode_frame (decoder, priv->current_frame);
3351 /* Current frame is gone now, either way */
3352 priv->current_frame = NULL;
3354 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3359 /* Pass the frame in priv->current_frame through the
3360 * handle_frame() callback for decoding and passing to gvd_finish_frame(),
3361 * or dropping by passing to gvd_drop_frame() */
3362 static GstFlowReturn
3363 gst_video_decoder_decode_frame (GstVideoDecoder * decoder,
3364 GstVideoCodecFrame * frame)
3366 GstVideoDecoderPrivate *priv = decoder->priv;
3367 GstVideoDecoderClass *decoder_class;
3368 GstFlowReturn ret = GST_FLOW_OK;
3370 decoder_class = GST_VIDEO_DECODER_GET_CLASS (decoder);
3372 /* FIXME : This should only have to be checked once (either the subclass has an
3373 * implementation, or it doesn't) */
3374 g_return_val_if_fail (decoder_class->handle_frame != NULL, GST_FLOW_ERROR);
3376 frame->distance_from_sync = priv->distance_from_sync;
3377 priv->distance_from_sync++;
3378 frame->pts = GST_BUFFER_PTS (frame->input_buffer);
3379 frame->dts = GST_BUFFER_DTS (frame->input_buffer);
3380 frame->duration = GST_BUFFER_DURATION (frame->input_buffer);
3382 /* For keyframes, PTS = DTS + constant_offset, usually 0 to 3 frame
3384 /* FIXME upstream can be quite wrong about the keyframe aspect,
3385 * so we could be going off here as well,
3386 * maybe let subclass decide if it really is/was a keyframe */
3387 if (GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame) &&
3388 GST_CLOCK_TIME_IS_VALID (frame->pts)
3389 && GST_CLOCK_TIME_IS_VALID (frame->dts)) {
3390 /* just in case they are not equal as might ideally be,
3391 * e.g. quicktime has a (positive) delta approach */
3392 priv->pts_delta = frame->pts - frame->dts;
3393 GST_DEBUG_OBJECT (decoder, "PTS delta %d ms",
3394 (gint) (priv->pts_delta / GST_MSECOND));
3397 frame->abidata.ABI.ts = frame->dts;
3398 frame->abidata.ABI.ts2 = frame->pts;
3400 GST_LOG_OBJECT (decoder, "PTS %" GST_TIME_FORMAT ", DTS %" GST_TIME_FORMAT,
3401 GST_TIME_ARGS (frame->pts), GST_TIME_ARGS (frame->dts));
3402 GST_LOG_OBJECT (decoder, "dist %d", frame->distance_from_sync);
3404 gst_video_codec_frame_ref (frame);
3405 priv->frames = g_list_append (priv->frames, frame);
3407 if (g_list_length (priv->frames) > 10) {
3408 GST_DEBUG_OBJECT (decoder, "decoder frame list getting long: %d frames,"
3409 "possible internal leaking?", g_list_length (priv->frames));
3413 gst_segment_to_running_time (&decoder->input_segment, GST_FORMAT_TIME,
3416 /* do something with frame */
3417 ret = decoder_class->handle_frame (decoder, frame);
3418 if (ret != GST_FLOW_OK)
3419 GST_DEBUG_OBJECT (decoder, "flow error %s", gst_flow_get_name (ret));
3421 /* the frame has either been added to parse_gather or sent to
3422 handle frame so there is no need to unref it */
3428 * gst_video_decoder_get_output_state:
3429 * @decoder: a #GstVideoDecoder
3431 * Get the #GstVideoCodecState currently describing the output stream.
3433 * Returns: (transfer full): #GstVideoCodecState describing format of video data.
3435 GstVideoCodecState *
3436 gst_video_decoder_get_output_state (GstVideoDecoder * decoder)
3438 GstVideoCodecState *state = NULL;
3440 GST_OBJECT_LOCK (decoder);
3441 if (decoder->priv->output_state)
3442 state = gst_video_codec_state_ref (decoder->priv->output_state);
3443 GST_OBJECT_UNLOCK (decoder);
3449 * gst_video_decoder_set_output_state:
3450 * @decoder: a #GstVideoDecoder
3451 * @fmt: a #GstVideoFormat
3452 * @width: The width in pixels
3453 * @height: The height in pixels
3454 * @reference: (allow-none) (transfer none): An optional reference #GstVideoCodecState
3456 * Creates a new #GstVideoCodecState with the specified @fmt, @width and @height
3457 * as the output state for the decoder.
3458 * Any previously set output state on @decoder will be replaced by the newly
3461 * If the subclass wishes to copy over existing fields (like pixel aspec ratio,
3462 * or framerate) from an existing #GstVideoCodecState, it can be provided as a
3465 * If the subclass wishes to override some fields from the output state (like
3466 * pixel-aspect-ratio or framerate) it can do so on the returned #GstVideoCodecState.
3468 * The new output state will only take effect (set on pads and buffers) starting
3469 * from the next call to #gst_video_decoder_finish_frame().
3471 * Returns: (transfer full): the newly configured output state.
3473 GstVideoCodecState *
3474 gst_video_decoder_set_output_state (GstVideoDecoder * decoder,
3475 GstVideoFormat fmt, guint width, guint height,
3476 GstVideoCodecState * reference)
3478 GstVideoDecoderPrivate *priv = decoder->priv;
3479 GstVideoCodecState *state;
3481 GST_DEBUG_OBJECT (decoder, "fmt:%d, width:%d, height:%d, reference:%p",
3482 fmt, width, height, reference);
3484 /* Create the new output state */
3485 state = _new_output_state (fmt, width, height, reference);
3487 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3489 GST_OBJECT_LOCK (decoder);
3490 /* Replace existing output state by new one */
3491 if (priv->output_state)
3492 gst_video_codec_state_unref (priv->output_state);
3493 priv->output_state = gst_video_codec_state_ref (state);
3495 if (priv->output_state != NULL && priv->output_state->info.fps_n > 0) {
3496 priv->qos_frame_duration =
3497 gst_util_uint64_scale (GST_SECOND, priv->output_state->info.fps_d,
3498 priv->output_state->info.fps_n);
3500 priv->qos_frame_duration = 0;
3502 priv->output_state_changed = TRUE;
3503 GST_OBJECT_UNLOCK (decoder);
3505 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3512 * gst_video_decoder_get_oldest_frame:
3513 * @decoder: a #GstVideoDecoder
3515 * Get the oldest pending unfinished #GstVideoCodecFrame
3517 * Returns: (transfer full): oldest pending unfinished #GstVideoCodecFrame.
3519 GstVideoCodecFrame *
3520 gst_video_decoder_get_oldest_frame (GstVideoDecoder * decoder)
3522 GstVideoCodecFrame *frame = NULL;
3524 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3525 if (decoder->priv->frames)
3526 frame = gst_video_codec_frame_ref (decoder->priv->frames->data);
3527 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3529 return (GstVideoCodecFrame *) frame;
3533 * gst_video_decoder_get_frame:
3534 * @decoder: a #GstVideoDecoder
3535 * @frame_number: system_frame_number of a frame
3537 * Get a pending unfinished #GstVideoCodecFrame
3539 * Returns: (transfer full): pending unfinished #GstVideoCodecFrame identified by @frame_number.
3541 GstVideoCodecFrame *
3542 gst_video_decoder_get_frame (GstVideoDecoder * decoder, int frame_number)
3545 GstVideoCodecFrame *frame = NULL;
3547 GST_DEBUG_OBJECT (decoder, "frame_number : %d", frame_number);
3549 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3550 for (g = decoder->priv->frames; g; g = g->next) {
3551 GstVideoCodecFrame *tmp = g->data;
3553 if (tmp->system_frame_number == frame_number) {
3554 frame = gst_video_codec_frame_ref (tmp);
3558 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3564 * gst_video_decoder_get_frames:
3565 * @decoder: a #GstVideoDecoder
3567 * Get all pending unfinished #GstVideoCodecFrame
3569 * Returns: (transfer full) (element-type GstVideoCodecFrame): pending unfinished #GstVideoCodecFrame.
3572 gst_video_decoder_get_frames (GstVideoDecoder * decoder)
3576 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3577 frames = g_list_copy (decoder->priv->frames);
3578 g_list_foreach (frames, (GFunc) gst_video_codec_frame_ref, NULL);
3579 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3585 gst_video_decoder_decide_allocation_default (GstVideoDecoder * decoder,
3588 GstCaps *outcaps = NULL;
3589 GstBufferPool *pool = NULL;
3590 guint size, min, max;
3591 GstAllocator *allocator = NULL;
3592 GstAllocationParams params;
3593 GstStructure *config;
3594 gboolean update_pool, update_allocator;
3597 gst_query_parse_allocation (query, &outcaps, NULL);
3598 gst_video_info_init (&vinfo);
3600 gst_video_info_from_caps (&vinfo, outcaps);
3602 /* we got configuration from our peer or the decide_allocation method,
3604 if (gst_query_get_n_allocation_params (query) > 0) {
3605 /* try the allocator */
3606 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
3607 update_allocator = TRUE;
3610 gst_allocation_params_init (¶ms);
3611 update_allocator = FALSE;
3614 if (gst_query_get_n_allocation_pools (query) > 0) {
3615 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
3616 size = MAX (size, vinfo.size);
3623 update_pool = FALSE;
3627 /* no pool, we can make our own */
3628 GST_DEBUG_OBJECT (decoder, "no pool, making new pool");
3629 pool = gst_video_buffer_pool_new ();
3633 config = gst_buffer_pool_get_config (pool);
3634 gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
3635 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
3637 GST_DEBUG_OBJECT (decoder,
3638 "setting config %" GST_PTR_FORMAT " in pool %" GST_PTR_FORMAT, config,
3640 if (!gst_buffer_pool_set_config (pool, config)) {
3641 config = gst_buffer_pool_get_config (pool);
3643 /* If change are not acceptable, fallback to generic pool */
3644 if (!gst_buffer_pool_config_validate_params (config, outcaps, size, min,
3646 GST_DEBUG_OBJECT (decoder, "unsuported pool, making new pool");
3648 gst_object_unref (pool);
3649 pool = gst_video_buffer_pool_new ();
3650 gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
3651 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
3654 if (!gst_buffer_pool_set_config (pool, config))
3658 if (update_allocator)
3659 gst_query_set_nth_allocation_param (query, 0, allocator, ¶ms);
3661 gst_query_add_allocation_param (query, allocator, ¶ms);
3663 gst_object_unref (allocator);
3666 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
3668 gst_query_add_allocation_pool (query, pool, size, min, max);
3671 gst_object_unref (pool);
3677 gst_object_unref (allocator);
3679 gst_object_unref (pool);
3680 GST_ELEMENT_ERROR (decoder, RESOURCE, SETTINGS,
3681 ("Failed to configure the buffer pool"),
3682 ("Configuration is most likely invalid, please report this issue."));
3687 gst_video_decoder_propose_allocation_default (GstVideoDecoder * decoder,
3694 gst_video_decoder_negotiate_pool (GstVideoDecoder * decoder, GstCaps * caps)
3696 GstVideoDecoderClass *klass;
3697 GstQuery *query = NULL;
3698 GstBufferPool *pool = NULL;
3699 GstAllocator *allocator;
3700 GstAllocationParams params;
3701 gboolean ret = TRUE;
3703 klass = GST_VIDEO_DECODER_GET_CLASS (decoder);
3705 query = gst_query_new_allocation (caps, TRUE);
3707 GST_DEBUG_OBJECT (decoder, "do query ALLOCATION");
3709 if (!gst_pad_peer_query (decoder->srcpad, query)) {
3710 GST_DEBUG_OBJECT (decoder, "didn't get downstream ALLOCATION hints");
3713 g_assert (klass->decide_allocation != NULL);
3714 ret = klass->decide_allocation (decoder, query);
3716 GST_DEBUG_OBJECT (decoder, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, ret,
3720 goto no_decide_allocation;
3722 /* we got configuration from our peer or the decide_allocation method,
3724 if (gst_query_get_n_allocation_params (query) > 0) {
3725 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
3728 gst_allocation_params_init (¶ms);
3731 if (gst_query_get_n_allocation_pools (query) > 0)
3732 gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
3735 gst_object_unref (allocator);
3737 goto no_decide_allocation;
3740 if (decoder->priv->allocator)
3741 gst_object_unref (decoder->priv->allocator);
3742 decoder->priv->allocator = allocator;
3743 decoder->priv->params = params;
3745 if (decoder->priv->pool) {
3746 /* do not set the bufferpool to inactive here, it will be done
3747 * on its finalize function. As videodecoder do late renegotiation
3748 * it might happen that some element downstream is already using this
3749 * same bufferpool and deactivating it will make it fail.
3750 * Happens when a downstream element changes from passthrough to
3751 * non-passthrough and gets this same bufferpool to use */
3752 GST_DEBUG_OBJECT (decoder, "unref pool %" GST_PTR_FORMAT,
3753 decoder->priv->pool);
3754 gst_object_unref (decoder->priv->pool);
3756 decoder->priv->pool = pool;
3759 GST_DEBUG_OBJECT (decoder, "activate pool %" GST_PTR_FORMAT, pool);
3760 gst_buffer_pool_set_active (pool, TRUE);
3764 gst_query_unref (query);
3769 no_decide_allocation:
3771 GST_WARNING_OBJECT (decoder, "Subclass failed to decide allocation");
3777 gst_video_decoder_negotiate_default (GstVideoDecoder * decoder)
3779 GstVideoCodecState *state = decoder->priv->output_state;
3780 gboolean ret = TRUE;
3781 GstVideoCodecFrame *frame;
3785 GST_DEBUG_OBJECT (decoder,
3786 "Trying to negotiate the pool with out setting the o/p format");
3787 ret = gst_video_decoder_negotiate_pool (decoder, NULL);
3791 g_return_val_if_fail (GST_VIDEO_INFO_WIDTH (&state->info) != 0, FALSE);
3792 g_return_val_if_fail (GST_VIDEO_INFO_HEIGHT (&state->info) != 0, FALSE);
3794 GST_DEBUG_OBJECT (decoder, "output_state par %d/%d fps %d/%d",
3795 state->info.par_n, state->info.par_d,
3796 state->info.fps_n, state->info.fps_d);
3798 if (state->caps == NULL)
3799 state->caps = gst_video_info_to_caps (&state->info);
3800 if (state->allocation_caps == NULL)
3801 state->allocation_caps = gst_caps_ref (state->caps);
3803 GST_DEBUG_OBJECT (decoder, "setting caps %" GST_PTR_FORMAT, state->caps);
3805 /* Push all pending pre-caps events of the oldest frame before
3807 frame = decoder->priv->frames ? decoder->priv->frames->data : NULL;
3808 if (frame || decoder->priv->current_frame_events) {
3812 events = &frame->events;
3814 events = &decoder->priv->current_frame_events;
3817 for (l = g_list_last (*events); l;) {
3818 GstEvent *event = GST_EVENT (l->data);
3821 if (GST_EVENT_TYPE (event) < GST_EVENT_CAPS) {
3822 gst_video_decoder_push_event (decoder, event);
3825 *events = g_list_delete_link (*events, tmp);
3832 prevcaps = gst_pad_get_current_caps (decoder->srcpad);
3833 if (!prevcaps || !gst_caps_is_equal (prevcaps, state->caps)) {
3835 GST_DEBUG_OBJECT (decoder, "decoder src pad has currently NULL caps");
3837 ret = gst_pad_set_caps (decoder->srcpad, state->caps);
3840 GST_DEBUG_OBJECT (decoder,
3841 "current src pad and output state caps are the same");
3844 gst_caps_unref (prevcaps);
3848 decoder->priv->output_state_changed = FALSE;
3849 /* Negotiate pool */
3850 ret = gst_video_decoder_negotiate_pool (decoder, state->allocation_caps);
3857 gst_video_decoder_negotiate_unlocked (GstVideoDecoder * decoder)
3859 GstVideoDecoderClass *klass = GST_VIDEO_DECODER_GET_CLASS (decoder);
3860 gboolean ret = TRUE;
3862 if (G_LIKELY (klass->negotiate))
3863 ret = klass->negotiate (decoder);
3869 * gst_video_decoder_negotiate:
3870 * @decoder: a #GstVideoDecoder
3872 * Negotiate with downstream elements to currently configured #GstVideoCodecState.
3873 * Unmark GST_PAD_FLAG_NEED_RECONFIGURE in any case. But mark it again if
3876 * Returns: #TRUE if the negotiation succeeded, else #FALSE.
3879 gst_video_decoder_negotiate (GstVideoDecoder * decoder)
3881 GstVideoDecoderClass *klass;
3882 gboolean ret = TRUE;
3884 g_return_val_if_fail (GST_IS_VIDEO_DECODER (decoder), FALSE);
3886 klass = GST_VIDEO_DECODER_GET_CLASS (decoder);
3888 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3889 gst_pad_check_reconfigure (decoder->srcpad);
3890 if (klass->negotiate) {
3891 ret = klass->negotiate (decoder);
3893 gst_pad_mark_reconfigure (decoder->srcpad);
3895 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3901 * gst_video_decoder_allocate_output_buffer:
3902 * @decoder: a #GstVideoDecoder
3904 * Helper function that allocates a buffer to hold a video frame for @decoder's
3905 * current #GstVideoCodecState.
3907 * You should use gst_video_decoder_allocate_output_frame() instead of this
3908 * function, if possible at all.
3910 * Returns: (transfer full): allocated buffer, or NULL if no buffer could be
3911 * allocated (e.g. when downstream is flushing or shutting down)
3914 gst_video_decoder_allocate_output_buffer (GstVideoDecoder * decoder)
3917 GstBuffer *buffer = NULL;
3918 gboolean needs_reconfigure = FALSE;
3920 GST_DEBUG ("alloc src buffer");
3922 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3923 needs_reconfigure = gst_pad_check_reconfigure (decoder->srcpad);
3924 if (G_UNLIKELY (!decoder->priv->output_state
3925 || decoder->priv->output_state_changed || needs_reconfigure)) {
3926 if (!gst_video_decoder_negotiate_unlocked (decoder)) {
3927 if (decoder->priv->output_state) {
3928 GST_DEBUG_OBJECT (decoder, "Failed to negotiate, fallback allocation");
3929 gst_pad_mark_reconfigure (decoder->srcpad);
3932 GST_DEBUG_OBJECT (decoder, "Failed to negotiate, output_buffer=NULL");
3933 goto failed_allocation;
3938 flow = gst_buffer_pool_acquire_buffer (decoder->priv->pool, &buffer, NULL);
3940 if (flow != GST_FLOW_OK) {
3941 GST_INFO_OBJECT (decoder, "couldn't allocate output buffer, flow %s",
3942 gst_flow_get_name (flow));
3943 if (decoder->priv->output_state && decoder->priv->output_state->info.size)
3946 goto failed_allocation;
3948 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3953 GST_INFO_OBJECT (decoder,
3954 "Fallback allocation, creating new buffer which doesn't belongs to any buffer pool");
3956 gst_buffer_new_allocate (NULL, decoder->priv->output_state->info.size,
3960 GST_ERROR_OBJECT (decoder, "Failed to allocate the buffer..");
3961 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
3967 * gst_video_decoder_allocate_output_frame:
3968 * @decoder: a #GstVideoDecoder
3969 * @frame: a #GstVideoCodecFrame
3971 * Helper function that allocates a buffer to hold a video frame for @decoder's
3972 * current #GstVideoCodecState. Subclass should already have configured video
3973 * state and set src pad caps.
3975 * The buffer allocated here is owned by the frame and you should only
3976 * keep references to the frame, not the buffer.
3978 * Returns: %GST_FLOW_OK if an output buffer could be allocated
3981 gst_video_decoder_allocate_output_frame (GstVideoDecoder *
3982 decoder, GstVideoCodecFrame * frame)
3984 GstFlowReturn flow_ret;
3985 GstVideoCodecState *state;
3987 gboolean needs_reconfigure = FALSE;
3989 g_return_val_if_fail (decoder->priv->output_state, GST_FLOW_NOT_NEGOTIATED);
3990 g_return_val_if_fail (frame->output_buffer == NULL, GST_FLOW_ERROR);
3992 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
3994 state = decoder->priv->output_state;
3995 if (state == NULL) {
3996 g_warning ("Output state should be set before allocating frame");
3999 num_bytes = GST_VIDEO_INFO_SIZE (&state->info);
4000 if (num_bytes == 0) {
4001 g_warning ("Frame size should not be 0");
4005 needs_reconfigure = gst_pad_check_reconfigure (decoder->srcpad);
4006 if (G_UNLIKELY (decoder->priv->output_state_changed || needs_reconfigure)) {
4007 if (!gst_video_decoder_negotiate_unlocked (decoder)) {
4008 GST_DEBUG_OBJECT (decoder, "Failed to negotiate, fallback allocation");
4009 gst_pad_mark_reconfigure (decoder->srcpad);
4013 GST_LOG_OBJECT (decoder, "alloc buffer size %d", num_bytes);
4015 flow_ret = gst_buffer_pool_acquire_buffer (decoder->priv->pool,
4016 &frame->output_buffer, NULL);
4018 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
4023 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
4024 return GST_FLOW_ERROR;
4028 * gst_video_decoder_get_max_decode_time:
4029 * @decoder: a #GstVideoDecoder
4030 * @frame: a #GstVideoCodecFrame
4032 * Determines maximum possible decoding time for @frame that will
4033 * allow it to decode and arrive in time (as determined by QoS events).
4034 * In particular, a negative result means decoding in time is no longer possible
4035 * and should therefore occur as soon/skippy as possible.
4037 * Returns: max decoding time.
4040 gst_video_decoder_get_max_decode_time (GstVideoDecoder *
4041 decoder, GstVideoCodecFrame * frame)
4043 GstClockTimeDiff deadline;
4044 GstClockTime earliest_time;
4046 GST_OBJECT_LOCK (decoder);
4047 earliest_time = decoder->priv->earliest_time;
4048 if (GST_CLOCK_TIME_IS_VALID (earliest_time)
4049 && GST_CLOCK_TIME_IS_VALID (frame->deadline))
4050 deadline = GST_CLOCK_DIFF (earliest_time, frame->deadline);
4052 deadline = G_MAXINT64;
4054 GST_LOG_OBJECT (decoder, "earliest %" GST_TIME_FORMAT
4055 ", frame deadline %" GST_TIME_FORMAT ", deadline %" GST_STIME_FORMAT,
4056 GST_TIME_ARGS (earliest_time), GST_TIME_ARGS (frame->deadline),
4057 GST_STIME_ARGS (deadline));
4059 GST_OBJECT_UNLOCK (decoder);
4065 * gst_video_decoder_get_qos_proportion:
4066 * @decoder: a #GstVideoDecoder
4067 * current QoS proportion, or %NULL
4069 * Returns: The current QoS proportion.
4074 gst_video_decoder_get_qos_proportion (GstVideoDecoder * decoder)
4078 g_return_val_if_fail (GST_IS_VIDEO_DECODER (decoder), 1.0);
4080 GST_OBJECT_LOCK (decoder);
4081 proportion = decoder->priv->proportion;
4082 GST_OBJECT_UNLOCK (decoder);
4088 _gst_video_decoder_error (GstVideoDecoder * dec, gint weight,
4089 GQuark domain, gint code, gchar * txt, gchar * dbg, const gchar * file,
4090 const gchar * function, gint line)
4093 GST_WARNING_OBJECT (dec, "error: %s", txt);
4095 GST_WARNING_OBJECT (dec, "error: %s", dbg);
4096 dec->priv->error_count += weight;
4097 dec->priv->discont = TRUE;
4098 if (dec->priv->max_errors >= 0 &&
4099 dec->priv->error_count > dec->priv->max_errors) {
4100 gst_element_message_full (GST_ELEMENT (dec), GST_MESSAGE_ERROR,
4101 domain, code, txt, dbg, file, function, line);
4102 return GST_FLOW_ERROR;
4111 * gst_video_decoder_set_max_errors:
4112 * @dec: a #GstVideoDecoder
4113 * @num: max tolerated errors
4115 * Sets numbers of tolerated decoder errors, where a tolerated one is then only
4116 * warned about, but more than tolerated will lead to fatal error. You can set
4117 * -1 for never returning fatal errors. Default is set to
4118 * GST_VIDEO_DECODER_MAX_ERRORS.
4120 * The '-1' option was added in 1.4
4123 gst_video_decoder_set_max_errors (GstVideoDecoder * dec, gint num)
4125 g_return_if_fail (GST_IS_VIDEO_DECODER (dec));
4127 dec->priv->max_errors = num;
4131 * gst_video_decoder_get_max_errors:
4132 * @dec: a #GstVideoDecoder
4134 * Returns: currently configured decoder tolerated error count.
4137 gst_video_decoder_get_max_errors (GstVideoDecoder * dec)
4139 g_return_val_if_fail (GST_IS_VIDEO_DECODER (dec), 0);
4141 return dec->priv->max_errors;
4145 * gst_video_decoder_set_needs_format:
4146 * @dec: a #GstVideoDecoder
4147 * @enabled: new state
4149 * Configures decoder format needs. If enabled, subclass needs to be
4150 * negotiated with format caps before it can process any data. It will then
4151 * never be handed any data before it has been configured.
4152 * Otherwise, it might be handed data without having been configured and
4153 * is then expected being able to do so either by default
4154 * or based on the input data.
4159 gst_video_decoder_set_needs_format (GstVideoDecoder * dec, gboolean enabled)
4161 g_return_if_fail (GST_IS_VIDEO_DECODER (dec));
4163 dec->priv->needs_format = enabled;
4167 * gst_video_decoder_get_needs_format:
4168 * @dec: a #GstVideoDecoder
4170 * Queries decoder required format handling.
4172 * Returns: %TRUE if required format handling is enabled.
4177 gst_video_decoder_get_needs_format (GstVideoDecoder * dec)
4181 g_return_val_if_fail (GST_IS_VIDEO_DECODER (dec), FALSE);
4183 result = dec->priv->needs_format;
4189 * gst_video_decoder_set_packetized:
4190 * @decoder: a #GstVideoDecoder
4191 * @packetized: whether the input data should be considered as packetized.
4193 * Allows baseclass to consider input data as packetized or not. If the
4194 * input is packetized, then the @parse method will not be called.
4197 gst_video_decoder_set_packetized (GstVideoDecoder * decoder,
4198 gboolean packetized)
4200 decoder->priv->packetized = packetized;
4204 * gst_video_decoder_get_packetized:
4205 * @decoder: a #GstVideoDecoder
4207 * Queries whether input data is considered packetized or not by the
4210 * Returns: TRUE if input data is considered packetized.
4213 gst_video_decoder_get_packetized (GstVideoDecoder * decoder)
4215 return decoder->priv->packetized;
4219 * gst_video_decoder_set_estimate_rate:
4220 * @dec: a #GstVideoDecoder
4221 * @enabled: whether to enable byte to time conversion
4223 * Allows baseclass to perform byte to time estimated conversion.
4226 gst_video_decoder_set_estimate_rate (GstVideoDecoder * dec, gboolean enabled)
4228 g_return_if_fail (GST_IS_VIDEO_DECODER (dec));
4230 dec->priv->do_estimate_rate = enabled;
4234 * gst_video_decoder_get_estimate_rate:
4235 * @dec: a #GstVideoDecoder
4237 * Returns: currently configured byte to time conversion setting
4240 gst_video_decoder_get_estimate_rate (GstVideoDecoder * dec)
4242 g_return_val_if_fail (GST_IS_VIDEO_DECODER (dec), 0);
4244 return dec->priv->do_estimate_rate;
4248 * gst_video_decoder_set_latency:
4249 * @decoder: a #GstVideoDecoder
4250 * @min_latency: minimum latency
4251 * @max_latency: maximum latency
4253 * Lets #GstVideoDecoder sub-classes tell the baseclass what the decoder
4254 * latency is. Will also post a LATENCY message on the bus so the pipeline
4255 * can reconfigure its global latency.
4258 gst_video_decoder_set_latency (GstVideoDecoder * decoder,
4259 GstClockTime min_latency, GstClockTime max_latency)
4261 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
4262 g_return_if_fail (max_latency >= min_latency);
4264 GST_OBJECT_LOCK (decoder);
4265 decoder->priv->min_latency = min_latency;
4266 decoder->priv->max_latency = max_latency;
4267 GST_OBJECT_UNLOCK (decoder);
4269 gst_element_post_message (GST_ELEMENT_CAST (decoder),
4270 gst_message_new_latency (GST_OBJECT_CAST (decoder)));
4274 * gst_video_decoder_get_latency:
4275 * @decoder: a #GstVideoDecoder
4276 * @min_latency: (out) (allow-none): address of variable in which to store the
4277 * configured minimum latency, or %NULL
4278 * @max_latency: (out) (allow-none): address of variable in which to store the
4279 * configured mximum latency, or %NULL
4281 * Query the configured decoder latency. Results will be returned via
4282 * @min_latency and @max_latency.
4285 gst_video_decoder_get_latency (GstVideoDecoder * decoder,
4286 GstClockTime * min_latency, GstClockTime * max_latency)
4288 GST_OBJECT_LOCK (decoder);
4290 *min_latency = decoder->priv->min_latency;
4292 *max_latency = decoder->priv->max_latency;
4293 GST_OBJECT_UNLOCK (decoder);
4297 * gst_video_decoder_merge_tags:
4298 * @decoder: a #GstVideoDecoder
4299 * @tags: (allow-none): a #GstTagList to merge, or NULL to unset
4300 * previously-set tags
4301 * @mode: the #GstTagMergeMode to use, usually #GST_TAG_MERGE_REPLACE
4303 * Sets the audio decoder tags and how they should be merged with any
4304 * upstream stream tags. This will override any tags previously-set
4305 * with gst_audio_decoder_merge_tags().
4307 * Note that this is provided for convenience, and the subclass is
4308 * not required to use this and can still do tag handling on its own.
4313 gst_video_decoder_merge_tags (GstVideoDecoder * decoder,
4314 const GstTagList * tags, GstTagMergeMode mode)
4316 g_return_if_fail (GST_IS_VIDEO_DECODER (decoder));
4317 g_return_if_fail (tags == NULL || GST_IS_TAG_LIST (tags));
4318 g_return_if_fail (tags == NULL || mode != GST_TAG_MERGE_UNDEFINED);
4320 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
4321 if (decoder->priv->tags != tags) {
4322 if (decoder->priv->tags) {
4323 gst_tag_list_unref (decoder->priv->tags);
4324 decoder->priv->tags = NULL;
4325 decoder->priv->tags_merge_mode = GST_TAG_MERGE_APPEND;
4328 decoder->priv->tags = gst_tag_list_ref ((GstTagList *) tags);
4329 decoder->priv->tags_merge_mode = mode;
4332 GST_DEBUG_OBJECT (decoder, "set decoder tags to %" GST_PTR_FORMAT, tags);
4333 decoder->priv->tags_changed = TRUE;
4335 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
4339 * gst_video_decoder_get_buffer_pool:
4340 * @decoder: a #GstVideoDecoder
4342 * Returns: (transfer full): the instance of the #GstBufferPool used
4343 * by the decoder; free it after use it
4346 gst_video_decoder_get_buffer_pool (GstVideoDecoder * decoder)
4348 g_return_val_if_fail (GST_IS_VIDEO_DECODER (decoder), NULL);
4350 if (decoder->priv->pool)
4351 return gst_object_ref (decoder->priv->pool);
4357 * gst_video_decoder_get_allocator:
4358 * @decoder: a #GstVideoDecoder
4359 * @allocator: (out) (allow-none) (transfer full): the #GstAllocator
4361 * @params: (out) (allow-none) (transfer full): the
4362 * #GstAllocatorParams of @allocator
4364 * Lets #GstVideoDecoder sub-classes to know the memory @allocator
4365 * used by the base class and its @params.
4367 * Unref the @allocator after use it.
4370 gst_video_decoder_get_allocator (GstVideoDecoder * decoder,
4371 GstAllocator ** allocator, GstAllocationParams * params)
4373 g_return_if_fail (GST_IS_VIDEO_DECODER (decoder));
4376 *allocator = decoder->priv->allocator ?
4377 gst_object_ref (decoder->priv->allocator) : NULL;
4380 *params = decoder->priv->params;
4384 * gst_video_decoder_set_use_default_pad_acceptcaps:
4385 * @decoder: a #GstVideoDecoder
4386 * @use: if the default pad accept-caps query handling should be used
4388 * Lets #GstVideoDecoder sub-classes decide if they want the sink pad
4389 * to use the default pad query handler to reply to accept-caps queries.
4391 * By setting this to true it is possible to further customize the default
4392 * handler with %GST_PAD_SET_ACCEPT_INTERSECT and
4393 * %GST_PAD_SET_ACCEPT_TEMPLATE
4398 gst_video_decoder_set_use_default_pad_acceptcaps (GstVideoDecoder * decoder,
4401 decoder->priv->use_default_pad_acceptcaps = use;