mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 12:32:29 +00:00
ext: caps are now set via GstEvent and not setcaps
This commit is contained in:
parent
97430ccbbc
commit
4a130c6a6c
3 changed files with 73 additions and 38 deletions
|
@ -102,42 +102,61 @@ gst_ffmpegdeinterlace_class_init (GstFFMpegDeinterlaceClass * klass)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_ffmpegdeinterlace_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||
gst_ffmpegdeinterlace_sink_event (GstPad * pad, GstEvent * event)
|
||||
{
|
||||
GstFFMpegDeinterlace *deinterlace =
|
||||
GST_FFMPEGDEINTERLACE (gst_pad_get_parent (pad));
|
||||
GstStructure *structure = gst_caps_get_structure (caps, 0);
|
||||
AVCodecContext *ctx;
|
||||
GstCaps *src_caps;
|
||||
gboolean ret;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
if (!gst_structure_get_int (structure, "width", &deinterlace->width))
|
||||
return FALSE;
|
||||
if (!gst_structure_get_int (structure, "height", &deinterlace->height))
|
||||
return FALSE;
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
case GST_EVENT_CAPS:
|
||||
{
|
||||
GstStructure *structure;
|
||||
AVCodecContext *ctx;
|
||||
GstCaps *caps, *src_caps;
|
||||
|
||||
ctx = avcodec_alloc_context ();
|
||||
ctx->width = deinterlace->width;
|
||||
ctx->height = deinterlace->height;
|
||||
ctx->pix_fmt = PIX_FMT_NB;
|
||||
gst_ffmpeg_caps_with_codectype (AVMEDIA_TYPE_VIDEO, caps, ctx);
|
||||
if (ctx->pix_fmt == PIX_FMT_NB) {
|
||||
av_free (ctx);
|
||||
return FALSE;
|
||||
gst_event_parse_caps (event, &caps);
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
|
||||
if (!gst_structure_get_int (structure, "width", &deinterlace->width) ||
|
||||
!gst_structure_get_int (structure, "height", &deinterlace->height)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
ctx = avcodec_alloc_context ();
|
||||
ctx->width = deinterlace->width;
|
||||
ctx->height = deinterlace->height;
|
||||
ctx->pix_fmt = PIX_FMT_NB;
|
||||
gst_ffmpeg_caps_with_codectype (AVMEDIA_TYPE_VIDEO, caps, ctx);
|
||||
if (ctx->pix_fmt == PIX_FMT_NB) {
|
||||
av_free (ctx);
|
||||
goto done;
|
||||
}
|
||||
|
||||
deinterlace->pixfmt = ctx->pix_fmt;
|
||||
|
||||
av_free (ctx);
|
||||
|
||||
deinterlace->to_size =
|
||||
avpicture_get_size (deinterlace->pixfmt, deinterlace->width,
|
||||
deinterlace->height);
|
||||
|
||||
src_caps = gst_caps_copy (caps);
|
||||
gst_event_unref (event);
|
||||
|
||||
gst_caps_set_simple (src_caps, "interlaced", G_TYPE_BOOLEAN, FALSE, NULL);
|
||||
event = gst_event_new_caps (src_caps);
|
||||
gst_caps_unref (src_caps);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
deinterlace->pixfmt = ctx->pix_fmt;
|
||||
ret = gst_pad_push_event (deinterlace->srcpad, event);
|
||||
|
||||
av_free (ctx);
|
||||
|
||||
deinterlace->to_size =
|
||||
avpicture_get_size (deinterlace->pixfmt, deinterlace->width,
|
||||
deinterlace->height);
|
||||
|
||||
src_caps = gst_caps_copy (caps);
|
||||
gst_caps_set_simple (src_caps, "interlaced", G_TYPE_BOOLEAN, FALSE, NULL);
|
||||
ret = gst_pad_set_caps (deinterlace->srcpad, src_caps);
|
||||
gst_caps_unref (src_caps);
|
||||
done:
|
||||
gst_object_unref (deinterlace);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -147,8 +166,8 @@ gst_ffmpegdeinterlace_init (GstFFMpegDeinterlace * deinterlace)
|
|||
{
|
||||
deinterlace->sinkpad =
|
||||
gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||
gst_pad_set_setcaps_function (deinterlace->sinkpad,
|
||||
gst_ffmpegdeinterlace_sink_setcaps);
|
||||
gst_pad_set_event_function (deinterlace->sinkpad,
|
||||
gst_ffmpegdeinterlace_sink_event);
|
||||
gst_pad_set_chain_function (deinterlace->sinkpad,
|
||||
gst_ffmpegdeinterlace_chain);
|
||||
gst_element_add_pad (GST_ELEMENT (deinterlace), deinterlace->sinkpad);
|
||||
|
|
|
@ -96,13 +96,14 @@ static void gst_ffmpegenc_base_init (GstFFMpegEncClass * klass);
|
|||
static void gst_ffmpegenc_init (GstFFMpegEnc * ffmpegenc);
|
||||
static void gst_ffmpegenc_finalize (GObject * object);
|
||||
|
||||
static gboolean gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps);
|
||||
static gboolean gst_ffmpegenc_setcaps (GstFFMpegEnc * ffmpegenc,
|
||||
GstCaps * caps);
|
||||
static GstCaps *gst_ffmpegenc_getcaps (GstPad * pad, GstCaps * filter);
|
||||
static GstFlowReturn gst_ffmpegenc_chain_video (GstPad * pad,
|
||||
GstBuffer * buffer);
|
||||
static GstFlowReturn gst_ffmpegenc_chain_audio (GstPad * pad,
|
||||
GstBuffer * buffer);
|
||||
static gboolean gst_ffmpegenc_event_video (GstPad * pad, GstEvent * event);
|
||||
static gboolean gst_ffmpegenc_event_sink (GstPad * pad, GstEvent * event);
|
||||
static gboolean gst_ffmpegenc_event_src (GstPad * pad, GstEvent * event);
|
||||
|
||||
static void gst_ffmpegenc_set_property (GObject * object,
|
||||
|
@ -242,7 +243,6 @@ gst_ffmpegenc_init (GstFFMpegEnc * ffmpegenc)
|
|||
|
||||
/* setup pads */
|
||||
ffmpegenc->sinkpad = gst_pad_new_from_template (oclass->sinktempl, "sink");
|
||||
gst_pad_set_setcaps_function (ffmpegenc->sinkpad, gst_ffmpegenc_setcaps);
|
||||
gst_pad_set_getcaps_function (ffmpegenc->sinkpad, gst_ffmpegenc_getcaps);
|
||||
ffmpegenc->srcpad = gst_pad_new_from_template (oclass->srctempl, "src");
|
||||
gst_pad_use_fixed_caps (ffmpegenc->srcpad);
|
||||
|
@ -255,10 +255,11 @@ gst_ffmpegenc_init (GstFFMpegEnc * ffmpegenc)
|
|||
ffmpegenc->file = NULL;
|
||||
ffmpegenc->delay = g_queue_new ();
|
||||
|
||||
gst_pad_set_event_function (ffmpegenc->sinkpad, gst_ffmpegenc_event_sink);
|
||||
|
||||
if (oclass->in_plugin->type == AVMEDIA_TYPE_VIDEO) {
|
||||
gst_pad_set_chain_function (ffmpegenc->sinkpad, gst_ffmpegenc_chain_video);
|
||||
/* so we know when to flush the buffers on EOS */
|
||||
gst_pad_set_event_function (ffmpegenc->sinkpad, gst_ffmpegenc_event_video);
|
||||
gst_pad_set_event_function (ffmpegenc->srcpad, gst_ffmpegenc_event_src);
|
||||
|
||||
ffmpegenc->bitrate = DEFAULT_VIDEO_BITRATE;
|
||||
|
@ -512,13 +513,12 @@ gst_ffmpegenc_getcaps (GstPad * pad, GstCaps * filter)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
|
||||
gst_ffmpegenc_setcaps (GstFFMpegEnc * ffmpegenc, GstCaps * caps)
|
||||
{
|
||||
GstCaps *other_caps;
|
||||
GstCaps *allowed_caps;
|
||||
GstCaps *icaps;
|
||||
enum PixelFormat pix_fmt;
|
||||
GstFFMpegEnc *ffmpegenc = (GstFFMpegEnc *) GST_PAD_PARENT (pad);
|
||||
GstFFMpegEncClass *oclass =
|
||||
(GstFFMpegEncClass *) G_OBJECT_GET_CLASS (ffmpegenc);
|
||||
|
||||
|
@ -1122,7 +1122,7 @@ flush:
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_ffmpegenc_event_video (GstPad * pad, GstEvent * event)
|
||||
gst_ffmpegenc_event_sink (GstPad * pad, GstEvent * event)
|
||||
{
|
||||
GstFFMpegEnc *ffmpegenc = (GstFFMpegEnc *) (GST_PAD_PARENT (pad));
|
||||
|
||||
|
@ -1141,6 +1141,15 @@ gst_ffmpegenc_event_video (GstPad * pad, GstEvent * event)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case GST_EVENT_CAPS:{
|
||||
GstCaps *caps;
|
||||
gst_event_parse_caps (event, &caps);
|
||||
if (!gst_ffmpegenc_setcaps (ffmpegenc, caps)) {
|
||||
gst_event_unref (event);
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -446,7 +446,6 @@ gst_ffmpegmux_request_new_pad (GstElement * element,
|
|||
gst_pad_set_event_function (pad,
|
||||
GST_DEBUG_FUNCPTR (gst_ffmpegmux_sink_event));
|
||||
|
||||
gst_pad_set_setcaps_function (pad, GST_DEBUG_FUNCPTR (gst_ffmpegmux_setcaps));
|
||||
gst_element_add_pad (element, pad);
|
||||
|
||||
/* AVStream needs to be created */
|
||||
|
@ -525,6 +524,13 @@ gst_ffmpegmux_sink_event (GstPad * pad, GstEvent * event)
|
|||
gst_tag_setter_merge_tags (setter, taglist, mode);
|
||||
break;
|
||||
}
|
||||
case GST_EVENT_CAPS:{
|
||||
GstCaps *caps;
|
||||
gst_event_parse_caps (event, &caps);
|
||||
if (!(res = gst_ffmpegmux_setcaps (pad, caps)))
|
||||
goto beach;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -532,6 +538,7 @@ gst_ffmpegmux_sink_event (GstPad * pad, GstEvent * event)
|
|||
/* chaining up to collectpads default event function */
|
||||
res = ffmpegmux->event_function (pad, event);
|
||||
|
||||
beach:
|
||||
gst_object_unref (ffmpegmux);
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue