mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
ext/mpeg2dec/gstmpeg2dec.c: Can't use gst_pad_alloc_buffer*() when we are going to crop the image before sending it o...
Original commit message from CVS: * ext/mpeg2dec/gstmpeg2dec.c: (gst_mpeg2dec_alloc_sized_buf), (gst_mpeg2dec_alloc_buffer): Can't use gst_pad_alloc_buffer*() when we are going to crop the image before sending it out. Downstream basetransform-based elements will complain about the wrong unit size otherwise (when not operating in passthrough-mode at least). Const-ify some static variables and do some minor clean-ups. Use I420 macros for size/offsets (not really necessary in this particular context, but this kind of code gets copy'n'pasted).
This commit is contained in:
parent
7780db0401
commit
8a3cf8eb23
2 changed files with 62 additions and 45 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
2006-04-13 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
|
* ext/mpeg2dec/gstmpeg2dec.c: (gst_mpeg2dec_alloc_sized_buf),
|
||||||
|
(gst_mpeg2dec_alloc_buffer):
|
||||||
|
Can't use gst_pad_alloc_buffer*() when we are going to crop
|
||||||
|
the image before sending it out. Downstream basetransform-based
|
||||||
|
elements will complain about the wrong unit size otherwise
|
||||||
|
(when not operating in passthrough-mode at least).
|
||||||
|
Const-ify some static variables and do some minor clean-ups.
|
||||||
|
Use I420 macros for size/offsets (not really necessary in this
|
||||||
|
particular context, but this kind of code gets copy'n'pasted).
|
||||||
|
|
||||||
2006-04-13 Tim-Philipp Müller <tim at centricular dot net>
|
2006-04-13 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
* gst/mpegstream/gstmpegpacketize.c: (gst_mpeg_packetize_put),
|
* gst/mpegstream/gstmpegpacketize.c: (gst_mpeg_packetize_put),
|
||||||
|
|
|
@ -43,37 +43,23 @@ GST_DEBUG_CATEGORY_STATIC (mpeg2dec_debug);
|
||||||
#define GST_CAT_DEFAULT (mpeg2dec_debug)
|
#define GST_CAT_DEFAULT (mpeg2dec_debug)
|
||||||
|
|
||||||
/* table with framerates expressed as fractions */
|
/* table with framerates expressed as fractions */
|
||||||
static gint fpss[][2] = { {24000, 1001},
|
static const gint fpss[][2] = { {24000, 1001},
|
||||||
{24, 1}, {25, 1}, {30000, 1001},
|
{24, 1}, {25, 1}, {30000, 1001},
|
||||||
{30, 1}, {50, 1}, {60000, 1001},
|
{30, 1}, {50, 1}, {60000, 1001},
|
||||||
{60, 1}, {0, 1}
|
{60, 1}, {0, 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* frame periods */
|
/* frame periods */
|
||||||
static guint frame_periods[] = {
|
static const guint frame_periods[] = {
|
||||||
1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000, 0
|
1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/* elementfactory information */
|
/* elementfactory information */
|
||||||
static GstElementDetails gst_mpeg2dec_details = {
|
static const GstElementDetails gst_mpeg2dec_details =
|
||||||
"mpeg1 and mpeg2 video decoder",
|
GST_ELEMENT_DETAILS ("mpeg1 and mpeg2 video decoder",
|
||||||
"Codec/Decoder/Video",
|
"Codec/Decoder/Video",
|
||||||
"Uses libmpeg2 to decode MPEG video streams",
|
"Uses libmpeg2 to decode MPEG video streams",
|
||||||
"Wim Taymans <wim.taymans@chello.be>",
|
"Wim Taymans <wim.taymans@chello.be>");
|
||||||
};
|
|
||||||
|
|
||||||
/* Mpeg2dec signals and args */
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
/* FILL ME */
|
|
||||||
LAST_SIGNAL
|
|
||||||
};
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
ARG_0
|
|
||||||
/* FILL ME */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* error out after receiving MAX_ERROR_COUNT STATE_INVALID return value
|
/* error out after receiving MAX_ERROR_COUNT STATE_INVALID return value
|
||||||
* from mpeg2_parse. -1 means never error out
|
* from mpeg2_parse. -1 means never error out
|
||||||
|
@ -479,20 +465,41 @@ crop_buffer (GstMpeg2dec * mpeg2dec, GstBuffer ** buf)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
gst_mpeg2dec_alloc_sized_buf (GstMpeg2dec * mpeg2dec, guint size,
|
||||||
|
GstBuffer ** obuf)
|
||||||
|
{
|
||||||
|
GstFlowReturn ret;
|
||||||
|
|
||||||
|
if (mpeg2dec->decoded_width == mpeg2dec->width &&
|
||||||
|
mpeg2dec->decoded_height == mpeg2dec->height) {
|
||||||
|
ret = gst_pad_alloc_buffer_and_set_caps (mpeg2dec->srcpad,
|
||||||
|
GST_BUFFER_OFFSET_NONE, size, GST_PAD_CAPS (mpeg2dec->srcpad), obuf);
|
||||||
|
} else {
|
||||||
|
/* can't use gst_pad_alloc_buffer() here because the output buffer will
|
||||||
|
* be cropped and basetransform-based elements will complain about
|
||||||
|
* the wrong unit size when not operating in passthrough mode */
|
||||||
|
*obuf = gst_buffer_new_and_alloc (size);
|
||||||
|
gst_buffer_set_caps (*obuf, GST_PAD_CAPS (mpeg2dec->srcpad));
|
||||||
|
ret = GST_FLOW_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, gint64 offset,
|
gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, gint64 offset,
|
||||||
GstBuffer ** obuf)
|
GstBuffer ** obuf)
|
||||||
{
|
{
|
||||||
GstBuffer *outbuf = NULL;
|
GstBuffer *outbuf = NULL;
|
||||||
gint size = mpeg2dec->decoded_width * mpeg2dec->decoded_height;
|
gint size;
|
||||||
guint8 *buf[3], *out = NULL;
|
guint8 *buf[3], *out = NULL;
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
|
|
||||||
if (mpeg2dec->format == MPEG2DEC_FORMAT_I422) {
|
if (mpeg2dec->format == MPEG2DEC_FORMAT_I422) {
|
||||||
ret =
|
size = mpeg2dec->decoded_width * mpeg2dec->decoded_height;
|
||||||
gst_pad_alloc_buffer_and_set_caps (mpeg2dec->srcpad,
|
|
||||||
GST_BUFFER_OFFSET_NONE, size * 2, GST_PAD_CAPS (mpeg2dec->srcpad),
|
ret = gst_mpeg2dec_alloc_sized_buf (mpeg2dec, size * 2, &outbuf);
|
||||||
&outbuf);
|
|
||||||
if (ret != GST_FLOW_OK)
|
if (ret != GST_FLOW_OK)
|
||||||
goto no_buffer;
|
goto no_buffer;
|
||||||
|
|
||||||
|
@ -503,24 +510,28 @@ gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, gint64 offset,
|
||||||
buf[2] = buf[1] + size / 2;
|
buf[2] = buf[1] + size / 2;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ret =
|
size = I420_SIZE (mpeg2dec->decoded_width, mpeg2dec->decoded_height);
|
||||||
gst_pad_alloc_buffer_and_set_caps (mpeg2dec->srcpad,
|
|
||||||
GST_BUFFER_OFFSET_NONE, (size * 3) / 2, GST_PAD_CAPS (mpeg2dec->srcpad),
|
ret = gst_mpeg2dec_alloc_sized_buf (mpeg2dec, size, &outbuf);
|
||||||
&outbuf);
|
|
||||||
if (ret != GST_FLOW_OK)
|
if (ret != GST_FLOW_OK)
|
||||||
goto no_buffer;
|
goto no_buffer;
|
||||||
|
|
||||||
out = GST_BUFFER_DATA (outbuf);
|
out = GST_BUFFER_DATA (outbuf);
|
||||||
|
|
||||||
buf[0] = out;
|
|
||||||
if (mpeg2dec->format == MPEG2DEC_FORMAT_I420) {
|
if (mpeg2dec->format == MPEG2DEC_FORMAT_I420) {
|
||||||
buf[0] = out;
|
buf[0] = out +
|
||||||
buf[1] = buf[0] + size;
|
I420_Y_OFFSET (mpeg2dec->decoded_width, mpeg2dec->decoded_height);
|
||||||
buf[2] = buf[1] + size / 4;
|
buf[1] = out +
|
||||||
|
I420_U_OFFSET (mpeg2dec->decoded_width, mpeg2dec->decoded_height);
|
||||||
|
buf[2] = out +
|
||||||
|
I420_V_OFFSET (mpeg2dec->decoded_width, mpeg2dec->decoded_height);
|
||||||
} else {
|
} else {
|
||||||
buf[0] = out;
|
buf[0] = out +
|
||||||
buf[2] = buf[0] + size;
|
I420_Y_OFFSET (mpeg2dec->decoded_width, mpeg2dec->decoded_height);
|
||||||
buf[1] = buf[2] + size / 4;
|
buf[1] = out +
|
||||||
|
I420_V_OFFSET (mpeg2dec->decoded_width, mpeg2dec->decoded_height);
|
||||||
|
buf[2] = out +
|
||||||
|
I420_U_OFFSET (mpeg2dec->decoded_width, mpeg2dec->decoded_height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,14 +541,7 @@ gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, gint64 offset,
|
||||||
* because we need it for indexing */
|
* because we need it for indexing */
|
||||||
GST_BUFFER_OFFSET (outbuf) = offset;
|
GST_BUFFER_OFFSET (outbuf) = offset;
|
||||||
|
|
||||||
done:
|
|
||||||
if (ret != GST_FLOW_OK) {
|
|
||||||
outbuf = NULL; /* just to asure NULL return, looking the path
|
|
||||||
above it happens only when gst_pad_alloc_buffer_and_set_caps
|
|
||||||
fails to alloc outbf */
|
|
||||||
}
|
|
||||||
*obuf = outbuf;
|
*obuf = outbuf;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
|
@ -548,7 +552,8 @@ no_buffer:
|
||||||
("Failed to allocate memory for buffer, reason %s",
|
("Failed to allocate memory for buffer, reason %s",
|
||||||
gst_flow_get_name (ret)));
|
gst_flow_get_name (ret)));
|
||||||
}
|
}
|
||||||
goto done;
|
*obuf = NULL;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue