2010-05-13 08:04:04 +00:00
|
|
|
/* VP8
|
|
|
|
* Copyright (C) 2006 David Schleef <ds@schleef.org>
|
|
|
|
* Copyright (C) 2010 Entropy Wave Inc
|
2012-09-14 21:41:48 +00:00
|
|
|
* Copyright (C) 2010-2012 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
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-05-13 08:04:04 +00:00
|
|
|
*
|
|
|
|
*/
|
2010-07-03 15:47:29 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-vp8enc
|
|
|
|
* @see_also: vp8dec, webmmux, oggmux
|
|
|
|
*
|
|
|
|
* This element encodes raw video into a VP8 stream.
|
|
|
|
* <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.
|
|
|
|
*
|
2012-09-16 14:03:06 +00:00
|
|
|
* To control the quality of the encoding, the #GstVP8Enc::target-bitrate,
|
|
|
|
* #GstVP8Enc::min-quantizer, #GstVP8Enc::max-quantizer or #GstVP8Enc::cq-level
|
|
|
|
* properties can be used. Which one is used depends on the mode selected by
|
|
|
|
* the #GstVP8Enc::end-usage property.
|
|
|
|
* See <ulink url="http://www.webmproject.org/docs/encoder-parameters/">Encoder Parameters</ulink>
|
|
|
|
* for explanation, examples for useful encoding parameters and more details
|
|
|
|
* on the encoding parameters.
|
2010-07-03 15:47:29 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example pipeline</title>
|
|
|
|
* |[
|
2015-05-10 10:05:00 +00:00
|
|
|
* gst-launch-1.0 -v videotestsrc num-buffers=1000 ! vp8enc ! webmmux ! filesink location=videotestsrc.webm
|
2010-07-03 15:47:29 +00:00
|
|
|
* ]| This example pipeline will encode a test video source to VP8 muxed in an
|
|
|
|
* WebM container.
|
|
|
|
* </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_ENCODER
|
|
|
|
|
2012-09-25 12:43:15 +00:00
|
|
|
/* glib decided in 2.32 it would be a great idea to deprecated GValueArray without
|
|
|
|
* providing an alternative
|
|
|
|
*
|
|
|
|
* See https://bugzilla.gnome.org/show_bug.cgi?id=667228
|
|
|
|
* */
|
|
|
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2010-05-14 08:30:18 +00:00
|
|
|
#include <gst/tag/tag.h>
|
2012-12-12 17:35:04 +00:00
|
|
|
#include <gst/video/video.h>
|
2010-05-13 08:04:04 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
#include "gstvp8utils.h"
|
2010-07-03 15:34:58 +00:00
|
|
|
#include "gstvp8enc.h"
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-05-20 08:19:54 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vp8enc_debug);
|
2010-05-13 08:04:04 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_vp8enc_debug
|
|
|
|
|
2010-05-14 08:30:18 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
vpx_image_t *image;
|
|
|
|
GList *invisible;
|
2012-05-16 12:04:28 +00:00
|
|
|
} GstVP8EncUserData;
|
2010-05-14 08:30:18 +00:00
|
|
|
|
2011-07-09 09:31:02 +00:00
|
|
|
static void
|
|
|
|
_gst_mini_object_unref0 (GstMiniObject * obj)
|
|
|
|
{
|
|
|
|
if (obj)
|
|
|
|
gst_mini_object_unref (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 12:04:28 +00:00
|
|
|
gst_vp8_enc_user_data_free (GstVP8EncUserData * user_data)
|
2011-07-09 09:31:02 +00:00
|
|
|
{
|
2012-05-16 12:04:28 +00:00
|
|
|
if (user_data->image)
|
|
|
|
g_slice_free (vpx_image_t, user_data->image);
|
2011-07-09 09:31:02 +00:00
|
|
|
|
2012-05-16 12:04:28 +00:00
|
|
|
g_list_foreach (user_data->invisible, (GFunc) _gst_mini_object_unref0, NULL);
|
|
|
|
g_list_free (user_data->invisible);
|
|
|
|
g_slice_free (GstVP8EncUserData, user_data);
|
2011-07-09 09:31:02 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static vpx_codec_iface_t *gst_vp8_enc_get_algo (GstVPXEnc * enc);
|
|
|
|
static gboolean gst_vp8_enc_enable_scaling (GstVPXEnc * enc);
|
|
|
|
static void gst_vp8_enc_set_image_format (GstVPXEnc * enc, vpx_image_t * image);
|
|
|
|
static GstCaps *gst_vp8_enc_get_new_simple_caps (GstVPXEnc * enc);
|
|
|
|
static void gst_vp8_enc_set_stream_info (GstVPXEnc * enc, GstCaps * caps,
|
|
|
|
GstVideoInfo * info);
|
|
|
|
static void *gst_vp8_enc_process_frame_user_data (GstVPXEnc * enc,
|
|
|
|
GstVideoCodecFrame * frame);
|
|
|
|
static GstFlowReturn gst_vp8_enc_handle_invisible_frame_buffer (GstVPXEnc * enc,
|
|
|
|
void *user_data, GstBuffer * buffer);
|
|
|
|
static void gst_vp8_enc_set_frame_user_data (GstVPXEnc * enc,
|
|
|
|
GstVideoCodecFrame * frame, vpx_image_t * image);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
static GstFlowReturn gst_vp8_enc_pre_push (GstVideoEncoder * encoder,
|
|
|
|
GstVideoCodecFrame * frame);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_vp8_enc_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2015-04-01 23:01:49 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-raw, "
|
|
|
|
"format = (string) \"I420\", "
|
|
|
|
"width = (int) [1, 16383], "
|
|
|
|
"height = (int) [1, 16383], framerate = (fraction) [ 0/1, MAX ]")
|
2010-05-13 08:04:04 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_vp8_enc_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-09-15 18:23:13 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-vp8, " "profile = (string) {0, 1, 2, 3}")
|
2010-05-13 08:04:04 +00:00
|
|
|
);
|
|
|
|
|
2012-05-28 14:05:21 +00:00
|
|
|
#define parent_class gst_vp8_enc_parent_class
|
2015-09-24 07:27:00 +00:00
|
|
|
G_DEFINE_TYPE (GstVP8Enc, gst_vp8_enc, GST_TYPE_VPX_ENC);
|
2011-11-03 13:01:41 +00:00
|
|
|
|
2010-05-18 12:47:54 +00:00
|
|
|
static void
|
2011-11-03 13:01:41 +00:00
|
|
|
gst_vp8_enc_class_init (GstVP8EncClass * klass)
|
2010-05-18 12:47:54 +00:00
|
|
|
{
|
2012-05-28 14:05:21 +00:00
|
|
|
GstElementClass *element_class;
|
2012-04-24 09:08:41 +00:00
|
|
|
GstVideoEncoderClass *video_encoder_class;
|
2015-09-24 07:27:00 +00:00
|
|
|
GstVPXEncClass *vpx_encoder_class;
|
2010-05-18 12:47:54 +00:00
|
|
|
|
2012-05-28 14:05:21 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
2012-04-24 09:08:41 +00:00
|
|
|
video_encoder_class = GST_VIDEO_ENCODER_CLASS (klass);
|
2015-09-24 07:27:00 +00:00
|
|
|
vpx_encoder_class = GST_VPX_ENC_CLASS (klass);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
|
2012-09-16 13:32:24 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_vp8_enc_src_template));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_vp8_enc_sink_template));
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-10-17 16:03:39 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2010-05-13 08:04:04 +00:00
|
|
|
"On2 VP8 Encoder",
|
|
|
|
"Codec/Encoder/Video",
|
2012-09-14 21:41:48 +00:00
|
|
|
"Encode VP8 video streams", "David Schleef <ds@entropywave.com>, "
|
|
|
|
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
video_encoder_class->pre_push = gst_vp8_enc_pre_push;
|
2011-07-10 01:53:24 +00:00
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
vpx_encoder_class->get_algo = gst_vp8_enc_get_algo;
|
|
|
|
vpx_encoder_class->enable_scaling = gst_vp8_enc_enable_scaling;
|
|
|
|
vpx_encoder_class->set_image_format = gst_vp8_enc_set_image_format;
|
|
|
|
vpx_encoder_class->get_new_vpx_caps = gst_vp8_enc_get_new_simple_caps;
|
|
|
|
vpx_encoder_class->set_stream_info = gst_vp8_enc_set_stream_info;
|
|
|
|
vpx_encoder_class->process_frame_user_data =
|
|
|
|
gst_vp8_enc_process_frame_user_data;
|
|
|
|
vpx_encoder_class->handle_invisible_frame_buffer =
|
|
|
|
gst_vp8_enc_handle_invisible_frame_buffer;
|
|
|
|
vpx_encoder_class->set_frame_user_data = gst_vp8_enc_set_frame_user_data;
|
2013-03-06 13:17:54 +00:00
|
|
|
|
2010-05-20 08:19:54 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vp8enc_debug, "vp8enc", 0, "VP8 Encoder");
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-28 14:05:21 +00:00
|
|
|
gst_vp8_enc_init (GstVP8Enc * gst_vp8_enc)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
2012-09-17 07:16:39 +00:00
|
|
|
vpx_codec_err_t status;
|
2015-09-24 07:27:00 +00:00
|
|
|
GstVPXEnc *gst_vpx_enc = GST_VPX_ENC (gst_vp8_enc);
|
|
|
|
GST_DEBUG_OBJECT (gst_vp8_enc, "gst_vp8_enc_init");
|
2012-09-17 07:16:39 +00:00
|
|
|
status =
|
2015-09-24 07:27:00 +00:00
|
|
|
vpx_codec_enc_config_default (gst_vp8_enc_get_algo (gst_vpx_enc),
|
|
|
|
&gst_vpx_enc->cfg, 0);
|
2012-09-17 07:16:39 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
2015-09-24 07:27:00 +00:00
|
|
|
GST_ERROR_OBJECT (gst_vpx_enc,
|
2012-09-17 07:16:39 +00:00
|
|
|
"Failed to get default encoder configuration: %s",
|
|
|
|
gst_vpx_error_name (status));
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_vpx_enc->have_default_config = FALSE;
|
2012-09-17 07:40:41 +00:00
|
|
|
} else {
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_vpx_enc->have_default_config = TRUE;
|
2012-09-17 07:40:41 +00:00
|
|
|
}
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static vpx_codec_iface_t *
|
|
|
|
gst_vp8_enc_get_algo (GstVPXEnc * enc)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
2015-09-24 07:27:00 +00:00
|
|
|
return &vpx_codec_vp8_cx_algo;
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_vp8_enc_enable_scaling (GstVPXEnc * enc)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-09 15:46:02 +00:00
|
|
|
static void
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_vp8_enc_set_image_format (GstVPXEnc * enc, vpx_image_t * image)
|
2015-03-09 15:46:02 +00:00
|
|
|
{
|
2011-03-24 12:59:35 +00:00
|
|
|
image->fmt = VPX_IMG_FMT_I420;
|
|
|
|
image->bps = 12;
|
|
|
|
image->x_chroma_shift = image->y_chroma_shift = 1;
|
2015-09-24 07:27:00 +00:00
|
|
|
}
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_vp8_enc_get_new_simple_caps (GstVPXEnc * enc)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
gchar *profile_str = g_strdup_printf ("%d", enc->cfg.g_profile);
|
2012-09-14 22:04:07 +00:00
|
|
|
caps = gst_caps_new_simple ("video/x-vp8",
|
2012-09-15 18:23:13 +00:00
|
|
|
"profile", G_TYPE_STRING, profile_str, NULL);
|
|
|
|
g_free (profile_str);
|
2015-09-24 07:27:00 +00:00
|
|
|
return caps;
|
|
|
|
}
|
2012-09-15 18:23:13 +00:00
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static void
|
|
|
|
gst_vp8_enc_set_stream_info (GstVPXEnc * enc, GstCaps * caps,
|
|
|
|
GstVideoInfo * info)
|
|
|
|
{
|
|
|
|
GstStructure *s;
|
|
|
|
GstVideoEncoder *video_encoder;
|
|
|
|
GstBuffer *stream_hdr, *vorbiscomment;
|
|
|
|
const GstTagList *iface_tags;
|
|
|
|
GValue array = { 0, };
|
|
|
|
GValue value = { 0, };
|
|
|
|
guint8 *data = NULL;
|
|
|
|
GstMapInfo map;
|
|
|
|
|
|
|
|
video_encoder = GST_VIDEO_ENCODER (enc);
|
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
/* put buffers in a fixed list */
|
|
|
|
g_value_init (&array, GST_TYPE_ARRAY);
|
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
|
|
|
|
|
|
|
/* Create Ogg stream-info */
|
|
|
|
stream_hdr = gst_buffer_new_and_alloc (26);
|
|
|
|
gst_buffer_map (stream_hdr, &map, GST_MAP_WRITE);
|
|
|
|
data = map.data;
|
|
|
|
|
|
|
|
GST_WRITE_UINT8 (data, 0x4F);
|
|
|
|
GST_WRITE_UINT32_BE (data + 1, 0x56503830); /* "VP80" */
|
|
|
|
GST_WRITE_UINT8 (data + 5, 0x01); /* stream info header */
|
|
|
|
GST_WRITE_UINT8 (data + 6, 1); /* Major version 1 */
|
|
|
|
GST_WRITE_UINT8 (data + 7, 0); /* Minor version 0 */
|
|
|
|
GST_WRITE_UINT16_BE (data + 8, GST_VIDEO_INFO_WIDTH (info));
|
|
|
|
GST_WRITE_UINT16_BE (data + 10, GST_VIDEO_INFO_HEIGHT (info));
|
|
|
|
GST_WRITE_UINT24_BE (data + 12, GST_VIDEO_INFO_PAR_N (info));
|
|
|
|
GST_WRITE_UINT24_BE (data + 15, GST_VIDEO_INFO_PAR_D (info));
|
|
|
|
GST_WRITE_UINT32_BE (data + 18, GST_VIDEO_INFO_FPS_N (info));
|
|
|
|
GST_WRITE_UINT32_BE (data + 22, GST_VIDEO_INFO_FPS_D (info));
|
|
|
|
|
|
|
|
gst_buffer_unmap (stream_hdr, &map);
|
|
|
|
|
|
|
|
GST_BUFFER_FLAG_SET (stream_hdr, GST_BUFFER_FLAG_HEADER);
|
|
|
|
gst_value_set_buffer (&value, stream_hdr);
|
|
|
|
gst_value_array_append_value (&array, &value);
|
|
|
|
g_value_unset (&value);
|
|
|
|
gst_buffer_unref (stream_hdr);
|
|
|
|
|
|
|
|
iface_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (video_encoder));
|
|
|
|
if (iface_tags) {
|
|
|
|
vorbiscomment =
|
|
|
|
gst_tag_list_to_vorbiscomment_buffer (iface_tags,
|
|
|
|
(const guint8 *) "OVP80\2 ", 7,
|
|
|
|
"Encoded with GStreamer vp8enc " PACKAGE_VERSION);
|
|
|
|
|
|
|
|
GST_BUFFER_FLAG_SET (vorbiscomment, GST_BUFFER_FLAG_HEADER);
|
2011-08-12 10:08:08 +00:00
|
|
|
|
2010-05-19 19:34:42 +00:00
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_value_set_buffer (&value, vorbiscomment);
|
2010-05-19 19:34:42 +00:00
|
|
|
gst_value_array_append_value (&array, &value);
|
|
|
|
g_value_unset (&value);
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_buffer_unref (vorbiscomment);
|
2010-05-19 19:34:42 +00:00
|
|
|
}
|
2010-05-14 08:30:18 +00:00
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_structure_set_value (s, "streamheader", &array);
|
|
|
|
g_value_unset (&array);
|
2012-07-26 17:31:14 +00:00
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static void *
|
|
|
|
gst_vp8_enc_process_frame_user_data (GstVPXEnc * enc,
|
|
|
|
GstVideoCodecFrame * frame)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
2012-05-16 12:04:28 +00:00
|
|
|
GstVP8EncUserData *user_data;
|
2016-01-20 11:41:33 +00:00
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
user_data = gst_video_codec_frame_get_user_data (frame);
|
2016-01-20 11:41:33 +00:00
|
|
|
|
|
|
|
if (!user_data) {
|
|
|
|
GST_ERROR_OBJECT (enc, "Have no frame user data");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
if (user_data->image)
|
|
|
|
g_slice_free (vpx_image_t, user_data->image);
|
|
|
|
user_data->image = NULL;
|
|
|
|
return user_data;
|
2011-03-24 11:50:23 +00:00
|
|
|
}
|
|
|
|
|
2011-07-21 06:03:51 +00:00
|
|
|
static GstFlowReturn
|
2015-09-24 07:27:00 +00:00
|
|
|
gst_vp8_enc_handle_invisible_frame_buffer (GstVPXEnc * enc, void *user_data,
|
|
|
|
GstBuffer * buffer)
|
2011-03-24 11:50:23 +00:00
|
|
|
{
|
2015-09-24 07:27:00 +00:00
|
|
|
GstVP8EncUserData *vp8_user_data = (GstVP8EncUserData *) user_data;
|
2016-01-20 11:41:33 +00:00
|
|
|
|
|
|
|
if (!vp8_user_data) {
|
|
|
|
GST_ERROR_OBJECT (enc, "Have no frame user data");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
vp8_user_data->invisible = g_list_append (vp8_user_data->invisible, buffer);
|
2016-01-20 11:41:33 +00:00
|
|
|
|
2011-07-21 06:03:51 +00:00
|
|
|
return GST_FLOW_OK;
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
static void
|
|
|
|
gst_vp8_enc_set_frame_user_data (GstVPXEnc * enc, GstVideoCodecFrame * frame,
|
|
|
|
vpx_image_t * image)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
2012-05-16 12:04:28 +00:00
|
|
|
GstVP8EncUserData *user_data;
|
|
|
|
user_data = g_slice_new0 (GstVP8EncUserData);
|
|
|
|
user_data->image = image;
|
|
|
|
gst_video_codec_frame_set_user_data (frame, user_data,
|
|
|
|
(GDestroyNotify) gst_vp8_enc_user_data_free);
|
2015-09-24 07:27:00 +00:00
|
|
|
return;
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 08:30:18 +00:00
|
|
|
static guint64
|
|
|
|
_to_granulepos (guint64 frame_end_number, guint inv_count, guint keyframe_dist)
|
|
|
|
{
|
|
|
|
guint64 granulepos;
|
|
|
|
guint inv;
|
|
|
|
|
|
|
|
inv = (inv_count == 0) ? 0x3 : inv_count - 1;
|
|
|
|
|
|
|
|
granulepos = (frame_end_number << 32) | (inv << 30) | (keyframe_dist << 3);
|
|
|
|
return granulepos;
|
|
|
|
}
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
static GstFlowReturn
|
2012-04-24 09:08:41 +00:00
|
|
|
gst_vp8_enc_pre_push (GstVideoEncoder * video_encoder,
|
|
|
|
GstVideoCodecFrame * frame)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
2010-05-14 08:30:18 +00:00
|
|
|
GstVP8Enc *encoder;
|
2015-09-24 07:27:00 +00:00
|
|
|
GstVPXEnc *vpx_enc;
|
2010-05-14 08:30:18 +00:00
|
|
|
GstBuffer *buf;
|
2012-04-24 09:08:41 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2012-05-16 12:04:28 +00:00
|
|
|
GstVP8EncUserData *user_data = gst_video_codec_frame_get_user_data (frame);
|
2010-05-14 08:30:18 +00:00
|
|
|
GList *l;
|
|
|
|
gint inv_count;
|
2012-04-24 09:08:41 +00:00
|
|
|
GstVideoInfo *info;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_DEBUG_OBJECT (video_encoder, "pre_push");
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
encoder = GST_VP8_ENC (video_encoder);
|
2015-09-24 07:27:00 +00:00
|
|
|
vpx_enc = GST_VPX_ENC (encoder);
|
2010-05-14 08:30:18 +00:00
|
|
|
|
2015-09-24 07:27:00 +00:00
|
|
|
info = &vpx_enc->input_state->info;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-05-16 12:04:28 +00:00
|
|
|
g_assert (user_data != NULL);
|
2010-06-12 07:02:29 +00:00
|
|
|
|
2012-05-16 12:04:28 +00:00
|
|
|
for (inv_count = 0, l = user_data->invisible; l; inv_count++, l = l->next) {
|
2010-07-10 14:51:53 +00:00
|
|
|
buf = l->data;
|
|
|
|
l->data = NULL;
|
2010-05-14 08:30:18 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
/* FIXME : All of this should have already been handled by base classes, no ? */
|
2012-05-16 12:04:28 +00:00
|
|
|
if (l == user_data->invisible
|
|
|
|
&& GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) {
|
2010-05-14 08:30:18 +00:00
|
|
|
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
encoder->keyframe_distance = 0;
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
encoder->keyframe_distance++;
|
|
|
|
}
|
2010-07-10 14:51:53 +00:00
|
|
|
|
2012-10-02 18:51:29 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DECODE_ONLY);
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buf) = GST_BUFFER_TIMESTAMP (frame->output_buffer);
|
2011-06-26 13:15:54 +00:00
|
|
|
GST_BUFFER_DURATION (buf) = 0;
|
2013-03-06 13:17:54 +00:00
|
|
|
if (GST_VIDEO_INFO_FPS_D (info) == 0 || GST_VIDEO_INFO_FPS_N (info) == 0) {
|
|
|
|
GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE;
|
|
|
|
GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE;
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_OFFSET_END (buf) =
|
|
|
|
_to_granulepos (frame->presentation_frame_number + 1,
|
|
|
|
inv_count, encoder->keyframe_distance);
|
|
|
|
GST_BUFFER_OFFSET (buf) =
|
|
|
|
gst_util_uint64_scale (frame->presentation_frame_number + 1,
|
|
|
|
GST_SECOND * GST_VIDEO_INFO_FPS_D (info),
|
|
|
|
GST_VIDEO_INFO_FPS_N (info));
|
|
|
|
}
|
2010-07-10 14:51:53 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
ret = gst_pad_push (GST_VIDEO_ENCODER_SRC_PAD (video_encoder), buf);
|
2010-07-10 14:51:53 +00:00
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder, "flow error %d", ret);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
buf = frame->output_buffer;
|
2010-07-10 14:51:53 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
/* FIXME : All of this should have already been handled by base classes, no ? */
|
2012-05-16 12:04:28 +00:00
|
|
|
if (!user_data->invisible && GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) {
|
2010-07-10 14:51:53 +00:00
|
|
|
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
encoder->keyframe_distance = 0;
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
encoder->keyframe_distance++;
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 13:17:54 +00:00
|
|
|
if (GST_VIDEO_INFO_FPS_D (info) == 0 || GST_VIDEO_INFO_FPS_N (info) == 0) {
|
|
|
|
GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE;
|
|
|
|
GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE;
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_OFFSET_END (buf) =
|
|
|
|
_to_granulepos (frame->presentation_frame_number + 1, 0,
|
|
|
|
encoder->keyframe_distance);
|
|
|
|
GST_BUFFER_OFFSET (buf) =
|
|
|
|
gst_util_uint64_scale (frame->presentation_frame_number + 1,
|
|
|
|
GST_SECOND * GST_VIDEO_INFO_FPS_D (info), GST_VIDEO_INFO_FPS_N (info));
|
|
|
|
}
|
2010-12-01 02:43:24 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_LOG_OBJECT (video_encoder, "src ts: %" GST_TIME_FORMAT,
|
2012-01-24 10:22:46 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
|
|
|
|
|
2010-05-14 08:30:18 +00:00
|
|
|
done:
|
2010-05-13 08:04:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2010-05-18 12:47:54 +00:00
|
|
|
|
2010-05-20 14:49:03 +00:00
|
|
|
#endif /* HAVE_VP8_ENCODER */
|