if (!gst_va_decoder_close (base->decoder))
return FALSE;
- if (base->output_state)
- gst_video_codec_state_unref (base->output_state);
- base->output_state = NULL;
+ g_clear_pointer (&base->output_state, gst_video_codec_state_unref);
+ g_clear_pointer (&base->input_state, gst_video_codec_state_unref);
if (base->other_pool)
gst_buffer_pool_set_active (base->other_pool, FALSE);
(element))->set_context (element, context);
}
+static gboolean
+gst_va_base_dec_negotiate (GstVideoDecoder * decoder)
+{
+ GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
+
+ /* Ignore downstream renegotiation request. */
+ if (!base->need_negotiation)
+ return TRUE;
+
+ base->need_negotiation = FALSE;
+
+ if (!gst_va_decoder_config_is_equal (base->decoder, base->profile,
+ base->rt_format, base->width, base->height)) {
+ if (gst_va_decoder_is_open (base->decoder) &&
+ !gst_va_decoder_close (base->decoder))
+ return FALSE;
+ if (!gst_va_decoder_open (base->decoder, base->profile, base->rt_format))
+ return FALSE;
+ if (!gst_va_decoder_set_frame_size (base->decoder, base->width,
+ base->height))
+ return FALSE;
+ }
+
+ if (!gst_va_base_dec_set_output_state (base))
+ return FALSE;
+
+ return GST_VIDEO_DECODER_CLASS (GST_VA_BASE_DEC_GET_PARENT_CLASS (decoder))
+ ->negotiate (decoder);
+}
+
void
gst_va_base_dec_init (GstVaBaseDec * base, GstDebugCategory * cat)
{
base->debug_category = cat;
+ gst_video_info_init (&base->output_info);
}
void
decoder_class->sink_query = GST_DEBUG_FUNCPTR (gst_va_base_dec_sink_query);
decoder_class->decide_allocation =
GST_DEBUG_FUNCPTR (gst_va_base_dec_decide_allocation);
+ decoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_va_base_dec_negotiate);
g_object_class_install_property (object_class, GST_VA_DEC_PROP_DEVICE_PATH,
g_param_spec_string ("device-path", "Device Path",
src_vinfo = &base->output_state->info;
gst_video_info_set_format (&dest_vinfo, GST_VIDEO_INFO_FORMAT (src_vinfo),
- base->width, base->height);
+ GST_VIDEO_INFO_WIDTH (src_vinfo), GST_VIDEO_INFO_HEIGHT (src_vinfo));
ret = gst_buffer_pool_acquire_buffer (base->other_pool, &buffer, NULL);
if (ret != GST_FLOW_OK)
} else {
/* gst_video_frame_copy can crop this, but does not know, so let
* make it think it's all right */
- GST_VIDEO_INFO_WIDTH (&src_frame.info) = base->width;
- GST_VIDEO_INFO_HEIGHT (&src_frame.info) = base->height;
+ GST_VIDEO_INFO_WIDTH (&src_frame.info) = GST_VIDEO_INFO_WIDTH (src_vinfo);
+ GST_VIDEO_INFO_HEIGHT (&src_frame.info) = GST_VIDEO_INFO_HEIGHT (src_vinfo);
if (!gst_video_frame_copy (&dest_frame, &src_frame)) {
gst_video_frame_unmap (&src_frame);
return gst_video_decoder_allocate_output_frame (vdec, frame);
return GST_FLOW_OK;
}
+
+gboolean
+gst_va_base_dec_set_output_state (GstVaBaseDec * base)
+{
+ GstVideoDecoder *decoder = GST_VIDEO_DECODER (base);
+ GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
+ GstCapsFeatures *capsfeatures = NULL;
+ GstVideoInfo *info = &base->output_info;
+
+ if (base->output_state)
+ gst_video_codec_state_unref (base->output_state);
+
+ gst_va_base_dec_get_preferred_format_and_caps_features (base, &format,
+ &capsfeatures);
+ if (format == GST_VIDEO_FORMAT_UNKNOWN)
+ return FALSE;
+
+ base->output_state =
+ gst_video_decoder_set_interlaced_output_state (decoder, format,
+ GST_VIDEO_INFO_INTERLACE_MODE (info), GST_VIDEO_INFO_WIDTH (info),
+ GST_VIDEO_INFO_HEIGHT (info), base->input_state);
+
+ /* set caps feature */
+ base->output_state->caps = gst_video_info_to_caps (&base->output_state->info);
+ if (capsfeatures)
+ gst_caps_set_features_simple (base->output_state->caps, capsfeatures);
+
+ GST_INFO_OBJECT (base, "Negotiated caps %" GST_PTR_FORMAT,
+ base->output_state->caps);
+
+ return TRUE;
+}
VAProfile profile;
guint rt_format;
+ /* coded or max resolution */
gint width;
gint height;
guint min_buffers;
+ GstVideoInfo output_info;
GstVideoCodecState *output_state;
+ GstVideoCodecState *input_state;
GstBufferPool *other_pool;
gboolean need_valign;
GstVideoBufferFlags buffer_flags);
GstFlowReturn gst_va_base_dec_prepare_output_frame (GstVaBaseDec * base,
GstVideoCodecFrame * frame);
+gboolean gst_va_base_dec_set_output_state (GstVaBaseDec * base);
G_END_DECLS
{
GstVaBaseDec parent;
- gint coded_width;
- gint coded_height;
gint dpb_size;
/* Used to fill VAPictureParameterBufferH264.ReferenceFrames */
{
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVaH264Dec *self = GST_VA_H264_DEC (decoder);
+ GstVideoInfo *info = &base->output_info;
VAProfile profile;
gint display_width;
gint display_height;
rt_format, sps->width, sps->height)) {
base->profile = profile;
base->rt_format = rt_format;
- self->coded_width = sps->width;
- self->coded_height = sps->height;
+ base->width = sps->width;
+ base->height = sps->height;
negotiation_needed = TRUE;
GST_INFO_OBJECT (self, "Format changed to %s [%x] (%dx%d)",
- gst_va_profile_name (profile), rt_format, self->coded_width,
- self->coded_height);
+ gst_va_profile_name (profile), rt_format, base->width, base->height);
}
- if (base->width != display_width || base->height != display_height) {
- base->width = display_width;
- base->height = display_height;
+ if (GST_VIDEO_INFO_WIDTH (info) != display_width ||
+ GST_VIDEO_INFO_HEIGHT (info) != display_height) {
+ GST_VIDEO_INFO_WIDTH (info) = display_width;
+ GST_VIDEO_INFO_HEIGHT (info) = display_height;
negotiation_needed = TRUE;
- GST_INFO_OBJECT (self, "Resolution changed to %dx%d", base->width,
- base->height);
+ GST_INFO_OBJECT (self, "Resolution changed to %dx%d",
+ GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info));
}
interlaced = !sps->frame_mbs_only_flag;
if (self->interlaced != interlaced) {
self->interlaced = interlaced;
-
+ GST_VIDEO_INFO_INTERLACE_MODE (info) = interlaced ?
+ GST_VIDEO_INTERLACE_MODE_MIXED : GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
negotiation_needed = TRUE;
GST_INFO_OBJECT (self, "Interlaced mode changed to %d", interlaced);
}
- base->need_valign = base->width < self->coded_width
- || base->height < self->coded_height;
+ base->need_valign = GST_VIDEO_INFO_WIDTH (info) < base->width ||
+ GST_VIDEO_INFO_HEIGHT (info) < base->height;
if (base->need_valign) {
/* *INDENT-OFF* */
if (base->valign.padding_left != padding_left ||
}
base->min_buffers = self->dpb_size + 4; /* dpb size + scratch surfaces */
-
base->need_negotiation = negotiation_needed;
+ g_clear_pointer (&base->input_state, gst_video_codec_state_unref);
+ base->input_state = gst_video_codec_state_ref (decoder->input_state);
return GST_FLOW_OK;
}
return caps;
}
-static gboolean
-gst_va_h264_dec_negotiate (GstVideoDecoder * decoder)
-{
- GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
- GstVaH264Dec *self = GST_VA_H264_DEC (decoder);
- GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
- GstCapsFeatures *capsfeatures = NULL;
- GstH264Decoder *h264dec = GST_H264_DECODER (decoder);
-
- /* Ignore downstream renegotiation request. */
- if (!base->need_negotiation)
- return TRUE;
-
- base->need_negotiation = FALSE;
-
- if (gst_va_decoder_is_open (base->decoder)
- && !gst_va_decoder_close (base->decoder))
- return FALSE;
-
- if (!gst_va_decoder_open (base->decoder, base->profile, base->rt_format))
- return FALSE;
-
- if (!gst_va_decoder_set_frame_size (base->decoder, self->coded_width,
- self->coded_height))
- return FALSE;
-
- if (base->output_state)
- gst_video_codec_state_unref (base->output_state);
-
- gst_va_base_dec_get_preferred_format_and_caps_features (base, &format,
- &capsfeatures);
- if (format == GST_VIDEO_FORMAT_UNKNOWN)
- return FALSE;
-
- base->output_state =
- gst_video_decoder_set_output_state (decoder, format,
- base->width, base->height, h264dec->input_state);
- if (self->interlaced)
- base->output_state->info.interlace_mode = GST_VIDEO_INTERLACE_MODE_MIXED;
-
- base->output_state->caps = gst_video_info_to_caps (&base->output_state->info);
- if (capsfeatures)
- gst_caps_set_features_simple (base->output_state->caps, capsfeatures);
-
- GST_INFO_OBJECT (self, "Negotiated caps %" GST_PTR_FORMAT,
- base->output_state->caps);
-
- return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
-}
-
static void
gst_va_h264_dec_dispose (GObject * object)
{
gobject_class->dispose = gst_va_h264_dec_dispose;
decoder_class->getcaps = GST_DEBUG_FUNCPTR (gst_va_h264_dec_getcaps);
- decoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_va_h264_dec_negotiate);
h264decoder_class->new_sequence =
GST_DEBUG_FUNCPTR (gst_va_h264_dec_new_sequence);
{
GstVaBaseDec parent;
- gint coded_width;
- gint coded_height;
gint dpb_size;
VAPictureParameterBufferHEVCExtension pic_param;
{
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVaH265Dec *self = GST_VA_H265_DEC (decoder);
+ GstVideoInfo *info = &base->output_info;
VAProfile profile;
gint display_width;
gint display_height;
rt_format, sps->width, sps->height)) {
base->profile = profile;
base->rt_format = rt_format;
- self->coded_width = sps->width;
- self->coded_height = sps->height;
+ base->width = sps->width;
+ base->height = sps->height;
negotiation_needed = TRUE;
GST_INFO_OBJECT (self, "Format changed to %s [%x] (%dx%d)",
- gst_va_profile_name (profile), rt_format, self->coded_width,
- self->coded_height);
+ gst_va_profile_name (profile), rt_format, base->width, base->height);
}
- if (base->width != display_width || base->height != display_height) {
- base->width = display_width;
- base->height = display_height;
+ if (GST_VIDEO_INFO_WIDTH (info) != display_width ||
+ GST_VIDEO_INFO_HEIGHT (info) != display_height) {
+ GST_VIDEO_INFO_WIDTH (info) = display_width;
+ GST_VIDEO_INFO_HEIGHT (info) = display_height;
negotiation_needed = TRUE;
- GST_INFO_OBJECT (self, "Resolution changed to %dx%d", base->width,
- base->height);
+ GST_INFO_OBJECT (self, "Resolution changed to %dx%d",
+ GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info));
}
- base->need_valign = base->width < self->coded_width
- || base->height < self->coded_height;
+ base->need_valign = GST_VIDEO_INFO_WIDTH (info) < base->width ||
+ GST_VIDEO_INFO_HEIGHT (info) < base->height;
if (base->need_valign) {
/* *INDENT-OFF* */
if (base->valign.padding_left != padding_left ||
}
base->min_buffers = self->dpb_size + 4; /* dpb size + scratch surfaces */
-
base->need_negotiation = negotiation_needed;
+ g_clear_pointer (&base->input_state, gst_video_codec_state_unref);
+ base->input_state = gst_video_codec_state_ref (decoder->input_state);
{
/* FIXME: We don't have parser API for sps_range_extension, so
return caps;
}
-static gboolean
-gst_va_h265_dec_negotiate (GstVideoDecoder * decoder)
-{
- GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
- GstVaH265Dec *self = GST_VA_H265_DEC (decoder);
- GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
- GstCapsFeatures *capsfeatures = NULL;
- GstH265Decoder *h265dec = GST_H265_DECODER (decoder);
-
- /* Ignore downstream renegotiation request. */
- if (!base->need_negotiation)
- return TRUE;
-
- base->need_negotiation = FALSE;
-
- if (gst_va_decoder_is_open (base->decoder)
- && !gst_va_decoder_close (base->decoder))
- return FALSE;
-
- if (!gst_va_decoder_open (base->decoder, base->profile, base->rt_format))
- return FALSE;
-
- if (!gst_va_decoder_set_frame_size (base->decoder, self->coded_width,
- self->coded_height))
- return FALSE;
-
- if (base->output_state)
- gst_video_codec_state_unref (base->output_state);
-
- gst_va_base_dec_get_preferred_format_and_caps_features (base, &format,
- &capsfeatures);
- if (format == GST_VIDEO_FORMAT_UNKNOWN)
- return FALSE;
-
- base->output_state =
- gst_video_decoder_set_output_state (decoder, format,
- base->width, base->height, h265dec->input_state);
-
- base->output_state->caps = gst_video_info_to_caps (&base->output_state->info);
- if (capsfeatures)
- gst_caps_set_features_simple (base->output_state->caps, capsfeatures);
-
- GST_INFO_OBJECT (self, "Negotiated caps %" GST_PTR_FORMAT,
- base->output_state->caps);
-
- return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
-}
-
static void
gst_va_h265_dec_dispose (GObject * object)
{
gobject_class->dispose = gst_va_h265_dec_dispose;
decoder_class->getcaps = GST_DEBUG_FUNCPTR (gst_va_h265_dec_getcaps);
- decoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_va_h265_dec_negotiate);
h265decoder_class->new_sequence =
GST_DEBUG_FUNCPTR (gst_va_h265_dec_new_sequence);
static const gchar *sink_caps_str = "video/x-mpeg2";
-static gboolean
-gst_va_mpeg2_dec_negotiate (GstVideoDecoder * decoder)
-{
- GstCapsFeatures *capsfeatures = NULL;
- GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
- GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
- GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
- GstMpeg2Decoder *mpeg2dec = GST_MPEG2_DECODER (decoder);
-
- /* Ignore downstream renegotiation request. */
- if (!base->need_negotiation)
- return TRUE;
-
- base->need_negotiation = FALSE;
-
- if (gst_va_decoder_is_open (base->decoder)
- && !gst_va_decoder_close (base->decoder))
- return FALSE;
-
- if (!gst_va_decoder_open (base->decoder, base->profile, base->rt_format))
- return FALSE;
-
- if (!gst_va_decoder_set_frame_size (base->decoder, base->width, base->height))
- return FALSE;
-
- if (base->output_state)
- gst_video_codec_state_unref (base->output_state);
-
- gst_va_base_dec_get_preferred_format_and_caps_features (base, &format,
- &capsfeatures);
- if (format == GST_VIDEO_FORMAT_UNKNOWN)
- return FALSE;
-
- base->output_state =
- gst_video_decoder_set_output_state (decoder, format,
- base->width, base->height, mpeg2dec->input_state);
-
- if (!self->progressive)
- base->output_state->info.interlace_mode = GST_VIDEO_INTERLACE_MODE_MIXED;
-
- base->output_state->caps = gst_video_info_to_caps (&base->output_state->info);
- if (capsfeatures)
- gst_caps_set_features_simple (base->output_state->caps, capsfeatures);
-
- GST_INFO_OBJECT (self, "Negotiated caps %" GST_PTR_FORMAT,
- base->output_state->caps);
-
- return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
-}
-
static VAProfile
_map_profile (GstMpegVideoProfile profile)
{
{
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
+ GstVideoInfo *info = &base->output_info;
VAProfile profile;
GstMpegVideoProfile mpeg_profile;
gboolean negotiation_needed = FALSE;
rt_format, width, height)) {
base->profile = profile;
base->rt_format = rt_format;
- base->width = width;
- base->height = height;
+ GST_VIDEO_INFO_WIDTH (info) = base->width = width;
+ GST_VIDEO_INFO_HEIGHT (info) = base->height = height;
negotiation_needed = TRUE;
progressive = seq_ext ? seq_ext->progressive : 1;
if (self->progressive != progressive) {
self->progressive = progressive;
-
+ GST_VIDEO_INFO_INTERLACE_MODE (info) = progressive ?
+ GST_VIDEO_INTERLACE_MODE_PROGRESSIVE : GST_VIDEO_INTERLACE_MODE_MIXED;
negotiation_needed = TRUE;
GST_INFO_OBJECT (self, "Interlaced mode changed to %d", !progressive);
}
base->need_valign = FALSE;
-
base->min_buffers = 2 + 4; /* max num pic references + scratch surfaces */
-
base->need_negotiation = negotiation_needed;
+ g_clear_pointer (&base->input_state, gst_video_codec_state_unref);
+ base->input_state = gst_video_codec_state_ref (decoder->input_state);
return GST_FLOW_OK;
}
GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GstMpeg2DecoderClass *mpeg2decoder_class = GST_MPEG2_DECODER_CLASS (g_class);
- GstVideoDecoderClass *decoder_class = GST_VIDEO_DECODER_CLASS (g_class);
struct CData *cdata = class_data;
gchar *long_name;
gobject_class->dispose = gst_va_mpeg2_dec_dispose;
- decoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_negotiate);
-
mpeg2decoder_class->new_sequence =
GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_new_sequence);
mpeg2decoder_class->new_picture =
static const gchar *sink_caps_str = "video/x-vp8";
-static gboolean
-gst_va_vp8_dec_negotiate (GstVideoDecoder * decoder)
-{
- GstCapsFeatures *capsfeatures = NULL;
- GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
- GstVaVp8Dec *self = GST_VA_VP8_DEC (decoder);
- GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
- GstVp8Decoder *vp8dec = GST_VP8_DECODER (decoder);
-
- /* Ignore downstream renegotiation request. */
- if (!base->need_negotiation)
- return TRUE;
-
- base->need_negotiation = FALSE;
-
- if (gst_va_decoder_is_open (base->decoder)
- && !gst_va_decoder_close (base->decoder))
- return FALSE;
-
- if (!gst_va_decoder_open (base->decoder, base->profile, base->rt_format))
- return FALSE;
-
- if (!gst_va_decoder_set_frame_size (base->decoder, base->width, base->height))
- return FALSE;
-
- if (base->output_state)
- gst_video_codec_state_unref (base->output_state);
-
- gst_va_base_dec_get_preferred_format_and_caps_features (base, &format,
- &capsfeatures);
- if (format == GST_VIDEO_FORMAT_UNKNOWN)
- return FALSE;
-
- base->output_state =
- gst_video_decoder_set_output_state (decoder, format,
- base->width, base->height, vp8dec->input_state);
-
- base->output_state->caps = gst_video_info_to_caps (&base->output_state->info);
- if (capsfeatures)
- gst_caps_set_features_simple (base->output_state->caps, capsfeatures);
-
- GST_INFO_OBJECT (self, "Negotiated caps %" GST_PTR_FORMAT,
- base->output_state->caps);
-
- return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
-}
-
static VAProfile
_get_profile (GstVaVp8Dec * self, const GstVp8FrameHdr * frame_hdr)
{
{
GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
GstVaVp8Dec *self = GST_VA_VP8_DEC (decoder);
+ GstVideoInfo *info = &base->output_info;
VAProfile profile;
guint rt_format;
gboolean negotiation_needed = FALSE;
if (!gst_va_decoder_config_is_equal (base->decoder, profile,
rt_format, frame_hdr->width, frame_hdr->height)) {
base->profile = profile;
- base->width = frame_hdr->width;
- base->height = frame_hdr->height;
+ GST_VIDEO_INFO_WIDTH (info) = base->width = frame_hdr->width;
+ GST_VIDEO_INFO_HEIGHT (info) = base->height = frame_hdr->height;
base->rt_format = rt_format;
negotiation_needed = TRUE;
}
base->min_buffers = 3 + 4; /* max num pic references + scratch surfaces */
-
base->need_negotiation = negotiation_needed;
+ g_clear_pointer (&base->input_state, gst_video_codec_state_unref);
+ base->input_state = gst_video_codec_state_ref (decoder->input_state);
return GST_FLOW_OK;
}
GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GstVp8DecoderClass *vp8decoder_class = GST_VP8_DECODER_CLASS (g_class);
- GstVideoDecoderClass *decoder_class = GST_VIDEO_DECODER_CLASS (g_class);
struct CData *cdata = class_data;
gchar *long_name;
gobject_class->dispose = gst_va_vp8_dec_dispose;
- decoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_va_vp8_dec_negotiate);
-
vp8decoder_class->new_sequence =
GST_DEBUG_FUNCPTR (gst_va_vp8_dec_new_sequence);
vp8decoder_class->new_picture =