2010-07-03 15:34:58 +00:00
|
|
|
/* VP8
|
2010-05-13 08:04:04 +00:00
|
|
|
* Copyright (C) 2006 David Schleef <ds@schleef.org>
|
|
|
|
* Copyright (C) 2008,2009,2010 Entropy Wave Inc
|
2010-05-18 12:28:55 +00:00
|
|
|
* Copyright (C) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
2010-05-13 08:04:04 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
2010-07-03 15:47:29 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-vp8dec
|
|
|
|
* @see_also: vp8enc, matroskademux
|
|
|
|
*
|
|
|
|
* This element decodes VP8 streams into raw video.
|
|
|
|
* <ulink url="http://www.webmproject.org">VP8</ulink> is a royalty-free
|
|
|
|
* video codec maintained by <ulink url="http://www.google.com/">Google
|
|
|
|
* </ulink>. It's the successor of On2 VP3, which was the base of the
|
|
|
|
* Theora video codec.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example pipeline</title>
|
|
|
|
* |[
|
|
|
|
* gst-launch -v filesrc location=videotestsrc.webm ! matroskademux ! vp8dec ! xvimagesink
|
|
|
|
* ]| This example pipeline will decode a WebM stream and decodes the VP8 video.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2010-05-21 06:13:06 +00:00
|
|
|
#ifdef HAVE_VP8_DECODER
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-07-03 15:34:58 +00:00
|
|
|
#include "gstvp8dec.h"
|
2010-05-19 15:13:17 +00:00
|
|
|
#include "gstvp8utils.h"
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-05-20 08:19:54 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vp8dec_debug);
|
2010-05-13 08:04:04 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_vp8dec_debug
|
|
|
|
|
2010-05-19 16:12:18 +00:00
|
|
|
#define DEFAULT_POST_PROCESSING FALSE
|
|
|
|
#define DEFAULT_POST_PROCESSING_FLAGS (VP8_DEBLOCK | VP8_DEMACROBLOCK)
|
|
|
|
#define DEFAULT_DEBLOCKING_LEVEL 4
|
|
|
|
#define DEFAULT_NOISE_LEVEL 0
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
enum
|
|
|
|
{
|
2010-05-19 16:12:18 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_POST_PROCESSING,
|
|
|
|
PROP_POST_PROCESSING_FLAGS,
|
|
|
|
PROP_DEBLOCKING_LEVEL,
|
|
|
|
PROP_NOISE_LEVEL
|
2010-05-13 08:04:04 +00:00
|
|
|
};
|
|
|
|
|
2010-05-19 16:12:18 +00:00
|
|
|
#define C_FLAGS(v) ((guint) v)
|
|
|
|
#define GST_VP8_DEC_TYPE_POST_PROCESSING_FLAGS (gst_vp8_dec_post_processing_flags_get_type())
|
|
|
|
static GType
|
|
|
|
gst_vp8_dec_post_processing_flags_get_type (void)
|
|
|
|
{
|
|
|
|
static const GFlagsValue values[] = {
|
|
|
|
{C_FLAGS (VP8_DEBLOCK), "Deblock", "deblock"},
|
|
|
|
{C_FLAGS (VP8_DEMACROBLOCK), "Demacroblock", "demacroblock"},
|
|
|
|
{C_FLAGS (VP8_ADDNOISE), "Add noise", "addnoise"},
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
static volatile GType id = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter ((gsize *) & id)) {
|
|
|
|
GType _id;
|
|
|
|
|
|
|
|
_id = g_flags_register_static ("GstVP8DecPostProcessingFlags", values);
|
|
|
|
|
|
|
|
g_once_init_leave ((gsize *) & id, _id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef C_FLAGS
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
static void gst_vp8_dec_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_vp8_dec_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
static gboolean gst_vp8_dec_start (GstBaseVideoDecoder * decoder);
|
|
|
|
static gboolean gst_vp8_dec_stop (GstBaseVideoDecoder * decoder);
|
2011-03-29 08:41:54 +00:00
|
|
|
static gboolean gst_vp8_dec_set_format (GstBaseVideoDecoder * decoder,
|
|
|
|
GstVideoState * state);
|
2010-05-13 08:04:04 +00:00
|
|
|
static gboolean gst_vp8_dec_reset (GstBaseVideoDecoder * decoder);
|
|
|
|
static GstFlowReturn gst_vp8_dec_parse_data (GstBaseVideoDecoder * decoder,
|
|
|
|
gboolean at_eos);
|
|
|
|
static GstFlowReturn gst_vp8_dec_handle_frame (GstBaseVideoDecoder * decoder,
|
2010-09-19 00:28:48 +00:00
|
|
|
GstVideoFrame * frame);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_vp8_dec_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-vp8")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_vp8_dec_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420"))
|
|
|
|
);
|
|
|
|
|
|
|
|
GST_BOILERPLATE (GstVP8Dec, gst_vp8_dec, GstBaseVideoDecoder,
|
|
|
|
GST_TYPE_BASE_VIDEO_DECODER);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp8_dec_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
2011-11-28 13:08:27 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_vp8_dec_src_template);
|
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_vp8_dec_sink_template);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
gst_element_class_set_details_simple (element_class,
|
|
|
|
"On2 VP8 Decoder",
|
|
|
|
"Codec/Decoder/Video",
|
|
|
|
"Decode VP8 video streams", "David Schleef <ds@entropywave.com>");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp8_dec_class_init (GstVP8DecClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstBaseVideoDecoderClass *base_video_decoder_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
base_video_decoder_class = GST_BASE_VIDEO_DECODER_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_vp8_dec_set_property;
|
|
|
|
gobject_class->get_property = gst_vp8_dec_get_property;
|
|
|
|
|
2010-05-19 16:12:18 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_POST_PROCESSING,
|
|
|
|
g_param_spec_boolean ("post-processing", "Post Processing",
|
|
|
|
"Enable post processing", DEFAULT_POST_PROCESSING,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_POST_PROCESSING_FLAGS,
|
|
|
|
g_param_spec_flags ("post-processing-flags", "Post Processing Flags",
|
|
|
|
"Flags to control post processing",
|
|
|
|
GST_VP8_DEC_TYPE_POST_PROCESSING_FLAGS, DEFAULT_POST_PROCESSING_FLAGS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DEBLOCKING_LEVEL,
|
|
|
|
g_param_spec_uint ("deblocking-level", "Deblocking Level",
|
|
|
|
"Deblocking level",
|
|
|
|
0, 16, DEFAULT_DEBLOCKING_LEVEL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_NOISE_LEVEL,
|
|
|
|
g_param_spec_uint ("noise-level", "Noise Level",
|
|
|
|
"Noise level",
|
|
|
|
0, 16, DEFAULT_NOISE_LEVEL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-04-01 20:13:55 +00:00
|
|
|
base_video_decoder_class->start = GST_DEBUG_FUNCPTR (gst_vp8_dec_start);
|
|
|
|
base_video_decoder_class->stop = GST_DEBUG_FUNCPTR (gst_vp8_dec_stop);
|
|
|
|
base_video_decoder_class->reset = GST_DEBUG_FUNCPTR (gst_vp8_dec_reset);
|
|
|
|
base_video_decoder_class->set_format =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vp8_dec_set_format);
|
|
|
|
base_video_decoder_class->parse_data =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vp8_dec_parse_data);
|
|
|
|
base_video_decoder_class->handle_frame =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vp8_dec_handle_frame);
|
2010-05-20 08:19:54 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vp8dec_debug, "vp8dec", 0, "VP8 Decoder");
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp8_dec_init (GstVP8Dec * gst_vp8_dec, GstVP8DecClass * klass)
|
|
|
|
{
|
2010-08-13 12:34:21 +00:00
|
|
|
GstBaseVideoDecoder *decoder = (GstBaseVideoDecoder *) gst_vp8_dec;
|
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_DEBUG_OBJECT (gst_vp8_dec, "gst_vp8_dec_init");
|
2010-08-13 12:34:21 +00:00
|
|
|
decoder->packetized = TRUE;
|
2010-05-19 16:12:18 +00:00
|
|
|
gst_vp8_dec->post_processing = DEFAULT_POST_PROCESSING;
|
|
|
|
gst_vp8_dec->post_processing_flags = DEFAULT_POST_PROCESSING_FLAGS;
|
|
|
|
gst_vp8_dec->deblocking_level = DEFAULT_DEBLOCKING_LEVEL;
|
|
|
|
gst_vp8_dec->noise_level = DEFAULT_NOISE_LEVEL;
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp8_dec_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2010-05-19 16:12:18 +00:00
|
|
|
GstVP8Dec *dec;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-07-03 15:47:29 +00:00
|
|
|
g_return_if_fail (GST_IS_VP8_DEC (object));
|
2010-05-19 16:12:18 +00:00
|
|
|
dec = GST_VP8_DEC (object);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_DEBUG_OBJECT (object, "gst_vp8_dec_set_property");
|
2010-05-13 08:04:04 +00:00
|
|
|
switch (prop_id) {
|
2010-05-19 16:12:18 +00:00
|
|
|
case PROP_POST_PROCESSING:
|
|
|
|
dec->post_processing = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case PROP_POST_PROCESSING_FLAGS:
|
|
|
|
dec->post_processing_flags = g_value_get_flags (value);
|
|
|
|
break;
|
|
|
|
case PROP_DEBLOCKING_LEVEL:
|
|
|
|
dec->deblocking_level = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
case PROP_NOISE_LEVEL:
|
|
|
|
dec->noise_level = g_value_get_uint (value);
|
|
|
|
break;
|
2010-05-13 08:04:04 +00:00
|
|
|
default:
|
2010-05-19 16:12:18 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp8_dec_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
2010-05-19 16:12:18 +00:00
|
|
|
GstVP8Dec *dec;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-07-03 15:47:29 +00:00
|
|
|
g_return_if_fail (GST_IS_VP8_DEC (object));
|
2010-05-19 16:12:18 +00:00
|
|
|
dec = GST_VP8_DEC (object);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2010-05-19 16:12:18 +00:00
|
|
|
case PROP_POST_PROCESSING:
|
|
|
|
g_value_set_boolean (value, dec->post_processing);
|
|
|
|
break;
|
|
|
|
case PROP_POST_PROCESSING_FLAGS:
|
|
|
|
g_value_set_flags (value, dec->post_processing_flags);
|
|
|
|
break;
|
|
|
|
case PROP_DEBLOCKING_LEVEL:
|
|
|
|
g_value_set_uint (value, dec->deblocking_level);
|
|
|
|
break;
|
|
|
|
case PROP_NOISE_LEVEL:
|
|
|
|
g_value_set_uint (value, dec->noise_level);
|
|
|
|
break;
|
2010-05-13 08:04:04 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vp8_dec_start (GstBaseVideoDecoder * decoder)
|
|
|
|
{
|
|
|
|
GstVP8Dec *gst_vp8_dec = GST_VP8_DEC (decoder);
|
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_DEBUG_OBJECT (gst_vp8_dec, "start");
|
2010-05-14 09:01:29 +00:00
|
|
|
gst_vp8_dec->decoder_inited = FALSE;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vp8_dec_stop (GstBaseVideoDecoder * base_video_decoder)
|
|
|
|
{
|
2010-05-18 12:28:55 +00:00
|
|
|
GstVP8Dec *gst_vp8_dec = GST_VP8_DEC (base_video_decoder);
|
2010-05-14 08:14:46 +00:00
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_DEBUG_OBJECT (gst_vp8_dec, "stop");
|
2010-05-18 12:28:55 +00:00
|
|
|
if (gst_vp8_dec->decoder_inited)
|
|
|
|
vpx_codec_destroy (&gst_vp8_dec->decoder);
|
|
|
|
gst_vp8_dec->decoder_inited = FALSE;
|
2010-05-13 08:04:04 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-03-29 08:41:54 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vp8_dec_set_format (GstBaseVideoDecoder * decoder, GstVideoState * state)
|
|
|
|
{
|
|
|
|
GstVP8Dec *gst_vp8_dec = GST_VP8_DEC (decoder);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (gst_vp8_dec, "set_format");
|
|
|
|
gst_vp8_dec->decoder_inited = FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vp8_dec_reset (GstBaseVideoDecoder * base_video_decoder)
|
|
|
|
{
|
|
|
|
GstVP8Dec *decoder;
|
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_DEBUG_OBJECT (base_video_decoder, "reset");
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
decoder = GST_VP8_DEC (base_video_decoder);
|
|
|
|
|
2010-05-18 12:28:55 +00:00
|
|
|
if (decoder->decoder_inited)
|
|
|
|
vpx_codec_destroy (&decoder->decoder);
|
2010-05-13 08:04:04 +00:00
|
|
|
decoder->decoder_inited = FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_vp8_dec_parse_data (GstBaseVideoDecoder * decoder, gboolean at_eos)
|
|
|
|
{
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp8_dec_send_tags (GstVP8Dec * dec)
|
|
|
|
{
|
|
|
|
GstTagList *list;
|
|
|
|
|
|
|
|
list = gst_tag_list_new ();
|
|
|
|
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_VIDEO_CODEC, "VP8 video", NULL);
|
|
|
|
|
|
|
|
gst_element_found_tags_for_pad (GST_ELEMENT (dec),
|
|
|
|
GST_BASE_VIDEO_CODEC_SRC_PAD (dec), list);
|
|
|
|
}
|
|
|
|
|
2010-05-19 12:46:48 +00:00
|
|
|
static void
|
|
|
|
gst_vp8_dec_image_to_buffer (GstVP8Dec * dec, const vpx_image_t * img,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
int stride, w, h, i;
|
|
|
|
guint8 *d;
|
2010-10-10 00:36:07 +00:00
|
|
|
GstVideoState *state = &GST_BASE_VIDEO_CODEC (dec)->state;
|
2010-05-19 12:46:48 +00:00
|
|
|
|
|
|
|
d = GST_BUFFER_DATA (buffer) +
|
2010-10-10 00:36:07 +00:00
|
|
|
gst_video_format_get_component_offset (state->format, 0,
|
|
|
|
state->width, state->height);
|
|
|
|
stride = gst_video_format_get_row_stride (state->format, 0, state->width);
|
|
|
|
h = gst_video_format_get_component_height (state->format, 0, state->height);
|
2010-05-19 12:46:48 +00:00
|
|
|
h = MIN (h, img->h);
|
2010-10-10 00:36:07 +00:00
|
|
|
w = gst_video_format_get_component_width (state->format, 0, state->width);
|
2010-05-19 12:46:48 +00:00
|
|
|
w = MIN (w, img->w);
|
|
|
|
|
|
|
|
for (i = 0; i < h; i++)
|
2010-05-26 04:52:15 +00:00
|
|
|
memcpy (d + i * stride,
|
|
|
|
img->planes[VPX_PLANE_Y] + i * img->stride[VPX_PLANE_Y], w);
|
2010-05-19 12:46:48 +00:00
|
|
|
|
|
|
|
d = GST_BUFFER_DATA (buffer) +
|
2010-10-10 00:36:07 +00:00
|
|
|
gst_video_format_get_component_offset (state->format, 1,
|
|
|
|
state->width, state->height);
|
|
|
|
stride = gst_video_format_get_row_stride (state->format, 1, state->width);
|
|
|
|
h = gst_video_format_get_component_height (state->format, 1, state->height);
|
2010-05-19 12:46:48 +00:00
|
|
|
h = MIN (h, img->h >> img->y_chroma_shift);
|
2010-10-10 00:36:07 +00:00
|
|
|
w = gst_video_format_get_component_width (state->format, 1, state->width);
|
2010-05-19 12:46:48 +00:00
|
|
|
w = MIN (w, img->w >> img->x_chroma_shift);
|
|
|
|
for (i = 0; i < h; i++)
|
2010-05-26 04:52:15 +00:00
|
|
|
memcpy (d + i * stride,
|
|
|
|
img->planes[VPX_PLANE_U] + i * img->stride[VPX_PLANE_U], w);
|
2010-05-19 12:46:48 +00:00
|
|
|
|
|
|
|
d = GST_BUFFER_DATA (buffer) +
|
2010-10-10 00:36:07 +00:00
|
|
|
gst_video_format_get_component_offset (state->format, 2,
|
|
|
|
state->width, state->height);
|
2010-05-19 12:46:48 +00:00
|
|
|
/* Same stride, height, width as above */
|
|
|
|
for (i = 0; i < h; i++)
|
2010-05-26 04:52:15 +00:00
|
|
|
memcpy (d + i * stride,
|
|
|
|
img->planes[VPX_PLANE_V] + i * img->stride[VPX_PLANE_V], w);
|
2010-05-19 12:46:48 +00:00
|
|
|
}
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
static GstFlowReturn
|
2010-09-19 00:28:48 +00:00
|
|
|
gst_vp8_dec_handle_frame (GstBaseVideoDecoder * decoder, GstVideoFrame * frame)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
|
|
|
GstVP8Dec *dec;
|
2010-05-19 21:02:19 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2010-05-19 15:13:17 +00:00
|
|
|
vpx_codec_err_t status;
|
2010-05-13 08:04:04 +00:00
|
|
|
vpx_codec_iter_t iter = NULL;
|
|
|
|
vpx_image_t *img;
|
2010-05-22 06:45:35 +00:00
|
|
|
long decoder_deadline = 0;
|
2010-09-19 00:28:48 +00:00
|
|
|
GstClockTimeDiff deadline;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_DEBUG_OBJECT (decoder, "handle_frame");
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
dec = GST_VP8_DEC (decoder);
|
|
|
|
|
|
|
|
if (!dec->decoder_inited) {
|
2010-05-18 12:28:55 +00:00
|
|
|
int flags = 0;
|
2010-05-14 08:14:46 +00:00
|
|
|
vpx_codec_stream_info_t stream_info;
|
2010-05-21 08:54:57 +00:00
|
|
|
vpx_codec_caps_t caps;
|
2010-10-10 00:36:07 +00:00
|
|
|
GstVideoState *state = &GST_BASE_VIDEO_CODEC (dec)->state;
|
2010-05-14 08:14:46 +00:00
|
|
|
|
2010-05-14 12:02:53 +00:00
|
|
|
memset (&stream_info, 0, sizeof (stream_info));
|
|
|
|
stream_info.sz = sizeof (stream_info);
|
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
status = vpx_codec_peek_stream_info (&vpx_codec_vp8_dx_algo,
|
2010-05-14 08:14:46 +00:00
|
|
|
GST_BUFFER_DATA (frame->sink_buffer),
|
|
|
|
GST_BUFFER_SIZE (frame->sink_buffer), &stream_info);
|
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
if (status != VPX_CODEC_OK || !stream_info.is_kf) {
|
|
|
|
GST_WARNING_OBJECT (decoder, "No keyframe, skipping");
|
2011-03-28 06:59:20 +00:00
|
|
|
gst_base_video_decoder_finish_frame (decoder, frame);
|
2010-05-14 08:14:46 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-10 00:36:07 +00:00
|
|
|
state->width = stream_info.w;
|
|
|
|
state->height = stream_info.h;
|
|
|
|
state->format = GST_VIDEO_FORMAT_I420;
|
2011-06-18 15:47:36 +00:00
|
|
|
if (state->par_n == 0 || state->par_d == 0) {
|
|
|
|
state->par_n = 1;
|
|
|
|
state->par_d = 1;
|
|
|
|
}
|
2010-05-14 09:01:29 +00:00
|
|
|
gst_vp8_dec_send_tags (dec);
|
2011-03-30 08:18:23 +00:00
|
|
|
gst_base_video_decoder_set_src_caps (decoder);
|
2010-05-18 12:28:55 +00:00
|
|
|
|
2010-05-21 08:54:57 +00:00
|
|
|
caps = vpx_codec_get_caps (&vpx_codec_vp8_dx_algo);
|
|
|
|
|
|
|
|
if (dec->post_processing) {
|
|
|
|
if (!(caps & VPX_CODEC_CAP_POSTPROC)) {
|
|
|
|
GST_WARNING_OBJECT (decoder,
|
|
|
|
"Decoder does not support post processing");
|
|
|
|
} else {
|
|
|
|
flags |= VPX_CODEC_USE_POSTPROC;
|
|
|
|
}
|
|
|
|
}
|
2010-05-19 16:12:18 +00:00
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
status =
|
2010-05-18 12:28:55 +00:00
|
|
|
vpx_codec_dec_init (&dec->decoder, &vpx_codec_vp8_dx_algo, NULL, flags);
|
2010-05-19 15:13:17 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
2010-05-18 12:28:55 +00:00
|
|
|
GST_ELEMENT_ERROR (dec, LIBRARY, INIT,
|
2010-05-19 15:13:17 +00:00
|
|
|
("Failed to initialize VP8 decoder"), ("%s",
|
|
|
|
gst_vpx_error_name (status)));
|
2010-05-18 12:28:55 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2010-05-19 16:12:18 +00:00
|
|
|
|
2010-05-21 08:54:57 +00:00
|
|
|
if ((caps & VPX_CODEC_CAP_POSTPROC) && dec->post_processing) {
|
2010-05-19 16:12:18 +00:00
|
|
|
vp8_postproc_cfg_t pp_cfg = { 0, };
|
|
|
|
|
|
|
|
pp_cfg.post_proc_flag = dec->post_processing_flags;
|
|
|
|
pp_cfg.deblocking_level = dec->deblocking_level;
|
|
|
|
pp_cfg.noise_level = dec->noise_level;
|
|
|
|
|
|
|
|
status = vpx_codec_control (&dec->decoder, VP8_SET_POSTPROC, &pp_cfg);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (dec, "Couldn't set postprocessing settings: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-14 09:01:29 +00:00
|
|
|
dec->decoder_inited = TRUE;
|
|
|
|
}
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-05-14 09:01:29 +00:00
|
|
|
if (!GST_BUFFER_FLAG_IS_SET (frame->sink_buffer, GST_BUFFER_FLAG_DELTA_UNIT))
|
|
|
|
gst_base_video_decoder_set_sync_point (decoder);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-09-19 00:28:48 +00:00
|
|
|
deadline = gst_base_video_decoder_get_max_decode_time (decoder, frame);
|
2010-05-22 06:45:35 +00:00
|
|
|
if (deadline < 0) {
|
|
|
|
decoder_deadline = 1;
|
|
|
|
} else if (deadline == G_MAXINT64) {
|
|
|
|
decoder_deadline = 0;
|
|
|
|
} else {
|
|
|
|
decoder_deadline = MAX (1, deadline / GST_MSECOND);
|
|
|
|
}
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
status = vpx_codec_decode (&dec->decoder,
|
|
|
|
GST_BUFFER_DATA (frame->sink_buffer),
|
2010-05-22 06:45:35 +00:00
|
|
|
GST_BUFFER_SIZE (frame->sink_buffer), NULL, decoder_deadline);
|
2010-05-13 08:04:04 +00:00
|
|
|
if (status) {
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_ELEMENT_ERROR (decoder, LIBRARY, ENCODE,
|
|
|
|
("Failed to decode frame"), ("%s", gst_vpx_error_name (status)));
|
2010-05-13 08:04:04 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-05-14 09:01:29 +00:00
|
|
|
img = vpx_codec_get_frame (&dec->decoder, &iter);
|
|
|
|
if (img) {
|
2010-05-21 18:53:36 +00:00
|
|
|
if (deadline < 0) {
|
|
|
|
GST_LOG_OBJECT (dec, "Skipping late frame (%f s past deadline)",
|
|
|
|
(double) -deadline / GST_SECOND);
|
2011-11-25 11:36:14 +00:00
|
|
|
gst_base_video_decoder_drop_frame (decoder, frame);
|
2010-05-21 18:53:36 +00:00
|
|
|
} else {
|
|
|
|
ret = gst_base_video_decoder_alloc_src_frame (decoder, frame);
|
|
|
|
|
|
|
|
if (ret == GST_FLOW_OK) {
|
|
|
|
gst_vp8_dec_image_to_buffer (dec, img, frame->src_buffer);
|
2011-04-01 20:13:00 +00:00
|
|
|
ret = gst_base_video_decoder_finish_frame (decoder, frame);
|
2010-05-21 18:53:36 +00:00
|
|
|
} else {
|
2011-03-28 06:59:20 +00:00
|
|
|
gst_base_video_decoder_finish_frame (decoder, frame);
|
2010-05-21 18:53:36 +00:00
|
|
|
}
|
2010-05-19 21:02:19 +00:00
|
|
|
}
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-05-19 12:46:48 +00:00
|
|
|
vpx_img_free (img);
|
|
|
|
|
|
|
|
while ((img = vpx_codec_get_frame (&dec->decoder, &iter))) {
|
|
|
|
GST_WARNING_OBJECT (decoder, "Multiple decoded frames... dropping");
|
2010-05-14 09:01:29 +00:00
|
|
|
vpx_img_free (img);
|
2010-05-19 12:46:48 +00:00
|
|
|
}
|
2010-05-16 08:36:12 +00:00
|
|
|
} else {
|
|
|
|
/* Invisible frame */
|
2012-01-04 10:05:48 +00:00
|
|
|
frame->decode_only = 1;
|
2011-03-28 06:59:20 +00:00
|
|
|
gst_base_video_decoder_finish_frame (decoder, frame);
|
2010-05-14 09:01:29 +00:00
|
|
|
}
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-05-20 08:19:54 +00:00
|
|
|
|
2010-05-20 14:49:03 +00:00
|
|
|
#endif /* HAVE_VP8_DECODER */
|