mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-20 08:41:07 +00:00
basevideoencoder: Use a temporary GstVideoState until the subclass accepted the caps
Also store the caps in the GstVideoState and assume a PAR of 1/1 instead of 0/1 if no PAR is specified in the caps.
This commit is contained in:
parent
a960e72efa
commit
2dbd24ca84
1 changed files with 43 additions and 46 deletions
|
@ -108,6 +108,8 @@
|
||||||
#include "gstbasevideoencoder.h"
|
#include "gstbasevideoencoder.h"
|
||||||
#include "gstbasevideoutils.h"
|
#include "gstbasevideoutils.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY (basevideoencoder_debug);
|
GST_DEBUG_CATEGORY (basevideoencoder_debug);
|
||||||
#define GST_CAT_DEFAULT basevideoencoder_debug
|
#define GST_CAT_DEFAULT basevideoencoder_debug
|
||||||
|
|
||||||
|
@ -263,11 +265,9 @@ gst_base_video_encoder_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
GstBaseVideoEncoder *base_video_encoder;
|
GstBaseVideoEncoder *base_video_encoder;
|
||||||
GstBaseVideoEncoderClass *base_video_encoder_class;
|
GstBaseVideoEncoderClass *base_video_encoder_class;
|
||||||
GstStructure *structure;
|
GstStructure *structure;
|
||||||
GstVideoState *state;
|
GstVideoState *state, tmp_state;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
gboolean changed = FALSE, u, v;
|
gboolean changed = FALSE;
|
||||||
GstVideoFormat fmt;
|
|
||||||
gint w, h, num, den;
|
|
||||||
|
|
||||||
base_video_encoder = GST_BASE_VIDEO_ENCODER (gst_pad_get_parent (pad));
|
base_video_encoder = GST_BASE_VIDEO_ENCODER (gst_pad_get_parent (pad));
|
||||||
base_video_encoder_class =
|
base_video_encoder_class =
|
||||||
|
@ -279,58 +279,49 @@ gst_base_video_encoder_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
GST_DEBUG_OBJECT (base_video_encoder, "setcaps %" GST_PTR_FORMAT, caps);
|
GST_DEBUG_OBJECT (base_video_encoder, "setcaps %" GST_PTR_FORMAT, caps);
|
||||||
|
|
||||||
state = &GST_BASE_VIDEO_CODEC (base_video_encoder)->state;
|
state = &GST_BASE_VIDEO_CODEC (base_video_encoder)->state;
|
||||||
|
memset (&tmp_state, 0, sizeof (tmp_state));
|
||||||
|
|
||||||
|
tmp_state.caps = gst_caps_ref (caps);
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
|
|
||||||
ret = gst_video_format_parse_caps (caps, &fmt, &w, &h);
|
ret =
|
||||||
|
gst_video_format_parse_caps (caps, &tmp_state.format, &tmp_state.width,
|
||||||
|
&tmp_state.height);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
if (fmt != state->format || w != state->width || h != state->height) {
|
changed = (tmp_state.format != state->format
|
||||||
changed = TRUE;
|
|| tmp_state.width != state->width || tmp_state.height != state->height);
|
||||||
state->format = fmt;
|
|
||||||
state->width = w;
|
|
||||||
state->height = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
num = 0;
|
if (!gst_video_parse_caps_framerate (caps, &tmp_state.fps_n,
|
||||||
den = 1;
|
&tmp_state.fps_d)) {
|
||||||
gst_video_parse_caps_framerate (caps, &num, &den);
|
tmp_state.fps_n = 0;
|
||||||
if (den == 0) {
|
tmp_state.fps_d = 1;
|
||||||
num = 0;
|
|
||||||
den = 1;
|
|
||||||
}
|
|
||||||
if (num != state->fps_n || den != state->fps_d) {
|
|
||||||
changed = TRUE;
|
|
||||||
state->fps_n = num;
|
|
||||||
state->fps_d = den;
|
|
||||||
}
|
}
|
||||||
|
changed = changed || (tmp_state.fps_n != state->fps_n
|
||||||
|
|| tmp_state.fps_d != state->fps_d);
|
||||||
|
|
||||||
num = 0;
|
if (!gst_video_parse_caps_pixel_aspect_ratio (caps, &tmp_state.par_n,
|
||||||
den = 1;
|
&tmp_state.par_d)) {
|
||||||
gst_video_parse_caps_pixel_aspect_ratio (caps, &num, &den);
|
tmp_state.par_n = 1;
|
||||||
if (den == 0) {
|
tmp_state.par_d = 1;
|
||||||
num = 0;
|
|
||||||
den = 1;
|
|
||||||
}
|
|
||||||
if (num != state->par_n || den != state->par_d) {
|
|
||||||
changed = TRUE;
|
|
||||||
state->par_n = num;
|
|
||||||
state->par_d = den;
|
|
||||||
}
|
}
|
||||||
|
changed = changed || (tmp_state.par_n != state->par_n
|
||||||
|
|| tmp_state.par_d != state->par_d);
|
||||||
|
|
||||||
u = gst_structure_get_boolean (structure, "interlaced", &v);
|
tmp_state.have_interlaced =
|
||||||
if (u != state->have_interlaced || v != state->interlaced) {
|
gst_structure_get_boolean (structure, "interlaced",
|
||||||
changed = TRUE;
|
&tmp_state.interlaced);
|
||||||
state->have_interlaced = u;
|
changed = changed || (tmp_state.have_interlaced != state->have_interlaced
|
||||||
state->interlaced = v;
|
|| tmp_state.interlaced != state->interlaced);
|
||||||
}
|
|
||||||
|
|
||||||
state->bytes_per_picture =
|
tmp_state.bytes_per_picture =
|
||||||
gst_video_format_get_size (state->format, state->width, state->height);
|
gst_video_format_get_size (tmp_state.format, tmp_state.width,
|
||||||
state->clean_width = state->width;
|
tmp_state.height);
|
||||||
state->clean_height = state->height;
|
tmp_state.clean_width = tmp_state.width;
|
||||||
state->clean_offset_left = 0;
|
tmp_state.clean_height = tmp_state.height;
|
||||||
state->clean_offset_top = 0;
|
tmp_state.clean_offset_left = 0;
|
||||||
|
tmp_state.clean_offset_top = 0;
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
/* arrange draining pending frames */
|
/* arrange draining pending frames */
|
||||||
|
@ -338,11 +329,17 @@ gst_base_video_encoder_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
|
|
||||||
/* and subclass should be ready to configure format at any time around */
|
/* and subclass should be ready to configure format at any time around */
|
||||||
if (base_video_encoder_class->set_format)
|
if (base_video_encoder_class->set_format)
|
||||||
ret = base_video_encoder_class->set_format (base_video_encoder, state);
|
ret =
|
||||||
|
base_video_encoder_class->set_format (base_video_encoder, &tmp_state);
|
||||||
|
if (ret) {
|
||||||
|
gst_caps_replace (&state->caps, NULL);
|
||||||
|
*state = tmp_state;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* no need to stir things up */
|
/* no need to stir things up */
|
||||||
GST_DEBUG_OBJECT (base_video_encoder,
|
GST_DEBUG_OBJECT (base_video_encoder,
|
||||||
"new video format identical to configured format");
|
"new video format identical to configured format");
|
||||||
|
gst_caps_unref (tmp_state.caps);
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue