mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
rtpvp8: port to 0.11
This commit is contained in:
parent
2c5ea76bdc
commit
c6761daa27
4 changed files with 105 additions and 99 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* gst-rtp-vp8-depay.c - Source for GstRtpVP8Depay
|
* gstrtpvp8depay.c - Source for GstRtpVP8Depay
|
||||||
* Copyright (C) 2011 Sjoerd Simons <sjoerd@luon.net>
|
* Copyright (C) 2011 Sjoerd Simons <sjoerd@luon.net>
|
||||||
* Copyright (C) 2011 Collabora Ltd.
|
* Copyright (C) 2011 Collabora Ltd.
|
||||||
* Contact: Youness Alaoui <youness.alaoui@collabora.co.uk>
|
* Contact: Youness Alaoui <youness.alaoui@collabora.co.uk>
|
||||||
|
@ -29,8 +29,7 @@
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_rtp_vp8_depay_debug);
|
GST_DEBUG_CATEGORY_STATIC (gst_rtp_vp8_depay_debug);
|
||||||
#define GST_CAT_DEFAULT gst_rtp_vp8_depay_debug
|
#define GST_CAT_DEFAULT gst_rtp_vp8_depay_debug
|
||||||
|
|
||||||
GST_BOILERPLATE (GstRtpVP8Depay, gst_rtp_vp8_depay, GstBaseRTPDepayload,
|
G_DEFINE_TYPE (GstRtpVP8Depay, gst_rtp_vp8_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
|
||||||
GST_TYPE_BASE_RTP_DEPAYLOAD);
|
|
||||||
|
|
||||||
static GstStaticPadTemplate gst_rtp_vp8_depay_src_template =
|
static GstStaticPadTemplate gst_rtp_vp8_depay_src_template =
|
||||||
GST_STATIC_PAD_TEMPLATE ("src",
|
GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
@ -49,40 +48,36 @@ GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
"encoding-name = (string) \"VP8-DRAFT-IETF-01\""));
|
"encoding-name = (string) \"VP8-DRAFT-IETF-01\""));
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_rtp_vp8_depay_init (GstRtpVP8Depay * self, GstRtpVP8DepayClass * klass)
|
gst_rtp_vp8_depay_init (GstRtpVP8Depay * self)
|
||||||
{
|
{
|
||||||
self->adapter = gst_adapter_new ();
|
self->adapter = gst_adapter_new ();
|
||||||
self->started = FALSE;
|
self->started = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gst_rtp_vp8_depay_dispose (GObject * object);
|
static void gst_rtp_vp8_depay_dispose (GObject * object);
|
||||||
static GstBuffer *gst_rtp_vp8_depay_process (GstBaseRTPDepayload * depayload,
|
static GstBuffer *gst_rtp_vp8_depay_process (GstRTPBaseDepayload * depayload,
|
||||||
GstBuffer * buf);
|
GstBuffer * buf);
|
||||||
static gboolean gst_rtp_vp8_depay_set_caps (GstBaseRTPDepayload * depayload,
|
static gboolean gst_rtp_vp8_depay_set_caps (GstRTPBaseDepayload * depayload,
|
||||||
GstCaps * caps);
|
GstCaps * caps);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_rtp_vp8_depay_base_init (gpointer klass)
|
gst_rtp_vp8_depay_class_init (GstRtpVP8DepayClass * gst_rtp_vp8_depay_class)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (gst_rtp_vp8_depay_class);
|
||||||
|
GstElementClass *element_class = GST_ELEMENT_CLASS (gst_rtp_vp8_depay_class);
|
||||||
|
GstRTPBaseDepayloadClass *depay_class =
|
||||||
|
(GstRTPBaseDepayloadClass *) (gst_rtp_vp8_depay_class);
|
||||||
|
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&gst_rtp_vp8_depay_sink_template));
|
gst_static_pad_template_get (&gst_rtp_vp8_depay_sink_template));
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&gst_rtp_vp8_depay_src_template));
|
gst_static_pad_template_get (&gst_rtp_vp8_depay_src_template));
|
||||||
|
|
||||||
gst_element_class_set_details_simple (element_class, "RTP VP8 depayloader",
|
gst_element_class_set_metadata (element_class, "RTP VP8 depayloader",
|
||||||
"Codec/Depayloader/Network/RTP",
|
"Codec/Depayloader/Network/RTP",
|
||||||
"Extracts VP8 video from RTP packets)",
|
"Extracts VP8 video from RTP packets)",
|
||||||
"Sjoerd Simons <sjoerd@luon.net>");
|
"Sjoerd Simons <sjoerd@luon.net>");
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_rtp_vp8_depay_class_init (GstRtpVP8DepayClass * gst_rtp_vp8_depay_class)
|
|
||||||
{
|
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (gst_rtp_vp8_depay_class);
|
|
||||||
GstBaseRTPDepayloadClass *depay_class =
|
|
||||||
(GstBaseRTPDepayloadClass *) (gst_rtp_vp8_depay_class);
|
|
||||||
|
|
||||||
object_class->dispose = gst_rtp_vp8_depay_dispose;
|
object_class->dispose = gst_rtp_vp8_depay_dispose;
|
||||||
|
|
||||||
|
@ -104,18 +99,19 @@ gst_rtp_vp8_depay_dispose (GObject * object)
|
||||||
|
|
||||||
/* release any references held by the object here */
|
/* release any references held by the object here */
|
||||||
|
|
||||||
if (G_OBJECT_CLASS (parent_class)->dispose)
|
if (G_OBJECT_CLASS (gst_rtp_vp8_depay_parent_class)->dispose)
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (gst_rtp_vp8_depay_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstBuffer *
|
static GstBuffer *
|
||||||
gst_rtp_vp8_depay_process (GstBaseRTPDepayload * depay, GstBuffer * buf)
|
gst_rtp_vp8_depay_process (GstRTPBaseDepayload * depay, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstRtpVP8Depay *self = GST_RTP_VP8_DEPAY (depay);
|
GstRtpVP8Depay *self = GST_RTP_VP8_DEPAY (depay);
|
||||||
GstBuffer *payload;
|
GstBuffer *payload;
|
||||||
guint8 *data;
|
guint8 *data;
|
||||||
guint offset;
|
guint offset;
|
||||||
guint size = gst_rtp_buffer_get_payload_len (buf);
|
guint size;
|
||||||
|
GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
|
||||||
|
|
||||||
if (G_UNLIKELY (GST_BUFFER_IS_DISCONT (buf))) {
|
if (G_UNLIKELY (GST_BUFFER_IS_DISCONT (buf))) {
|
||||||
GST_LOG_OBJECT (self, "Discontinuity, flushing adapter");
|
GST_LOG_OBJECT (self, "Discontinuity, flushing adapter");
|
||||||
|
@ -123,17 +119,20 @@ gst_rtp_vp8_depay_process (GstBaseRTPDepayload * depay, GstBuffer * buf)
|
||||||
self->started = FALSE;
|
self->started = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gst_rtp_buffer_map (buf, GST_MAP_READ, &rtpbuffer);
|
||||||
|
size = gst_rtp_buffer_get_payload_len (&rtpbuffer);
|
||||||
|
|
||||||
/* At least one header and one vp8 byte */
|
/* At least one header and one vp8 byte */
|
||||||
if (G_UNLIKELY (size < 2))
|
if (G_UNLIKELY (size < 2))
|
||||||
goto too_small;
|
goto too_small;
|
||||||
|
|
||||||
data = gst_rtp_buffer_get_payload (buf);
|
data = gst_rtp_buffer_get_payload (&rtpbuffer);
|
||||||
|
|
||||||
if (G_UNLIKELY (!self->started)) {
|
if (G_UNLIKELY (!self->started)) {
|
||||||
/* Check if this is the start of a VP8 frame, otherwise bail */
|
/* Check if this is the start of a VP8 frame, otherwise bail */
|
||||||
/* S=1 and PartID= 0 */
|
/* S=1 and PartID= 0 */
|
||||||
if ((data[0] & 0x1F) != 0x10)
|
if ((data[0] & 0x1F) != 0x10)
|
||||||
return NULL;
|
goto done;
|
||||||
|
|
||||||
self->started = TRUE;
|
self->started = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -162,37 +161,41 @@ gst_rtp_vp8_depay_process (GstBaseRTPDepayload * depay, GstBuffer * buf)
|
||||||
if (G_UNLIKELY (offset >= size))
|
if (G_UNLIKELY (offset >= size))
|
||||||
goto too_small;
|
goto too_small;
|
||||||
|
|
||||||
payload = gst_rtp_buffer_get_payload_subbuffer (buf, offset, -1);
|
payload = gst_rtp_buffer_get_payload_subbuffer (&rtpbuffer, offset, -1);
|
||||||
gst_adapter_push (self->adapter, payload);
|
gst_adapter_push (self->adapter, payload);
|
||||||
|
|
||||||
/* Marker indicates that it was the last rtp packet for this frame */
|
/* Marker indicates that it was the last rtp packet for this frame */
|
||||||
if (gst_rtp_buffer_get_marker (buf)) {
|
if (gst_rtp_buffer_get_marker (&rtpbuffer)) {
|
||||||
GstBuffer *out;
|
GstBuffer *out;
|
||||||
|
|
||||||
out = gst_adapter_take_buffer (self->adapter,
|
out = gst_adapter_take_buffer (self->adapter,
|
||||||
gst_adapter_available (self->adapter));
|
gst_adapter_available (self->adapter));
|
||||||
|
|
||||||
self->started = FALSE;
|
self->started = FALSE;
|
||||||
|
gst_rtp_buffer_unmap (&rtpbuffer);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
gst_rtp_buffer_unmap (&rtpbuffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
too_small:
|
too_small:
|
||||||
GST_LOG_OBJECT (self, "Invalid rtp packet (too small), ignoring");
|
GST_LOG_OBJECT (self, "Invalid rtp packet (too small), ignoring");
|
||||||
gst_adapter_clear (self->adapter);
|
gst_adapter_clear (self->adapter);
|
||||||
self->started = FALSE;
|
self->started = FALSE;
|
||||||
return NULL;
|
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_rtp_vp8_depay_set_caps (GstBaseRTPDepayload * depayload, GstCaps * caps)
|
gst_rtp_vp8_depay_set_caps (GstRTPBaseDepayload * depayload, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstCaps *srccaps = gst_caps_new_simple ("video/x-vp8",
|
GstCaps *srccaps = gst_caps_new_simple ("video/x-vp8",
|
||||||
"framerate", GST_TYPE_FRACTION, 0, 1,
|
"framerate", GST_TYPE_FRACTION, 0, 1,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
|
gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
|
||||||
gst_caps_unref (srccaps);
|
gst_caps_unref (srccaps);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* gst-rtp-vp8-depay.h - Header for GstRtpVP8Depay
|
* gstrtpvp8depay.h - Header for GstRtpVP8Depay
|
||||||
* Copyright (C) 2011 Sjoerd Simons <sjoerd@luon.net>
|
* Copyright (C) 2011 Sjoerd Simons <sjoerd@luon.net>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
|
@ -22,19 +22,19 @@
|
||||||
|
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <gst/base/gstadapter.h>
|
#include <gst/base/gstadapter.h>
|
||||||
#include <gst/rtp/gstbasertpdepayload.h>
|
#include <gst/rtp/gstrtpbasedepayload.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS typedef struct _GstRtpVP8Depay GstRtpVP8Depay;
|
G_BEGIN_DECLS typedef struct _GstRtpVP8Depay GstRtpVP8Depay;
|
||||||
typedef struct _GstRtpVP8DepayClass GstRtpVP8DepayClass;
|
typedef struct _GstRtpVP8DepayClass GstRtpVP8DepayClass;
|
||||||
|
|
||||||
struct _GstRtpVP8DepayClass
|
struct _GstRtpVP8DepayClass
|
||||||
{
|
{
|
||||||
GstBaseRTPDepayloadClass parent_class;
|
GstRTPBaseDepayloadClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstRtpVP8Depay
|
struct _GstRtpVP8Depay
|
||||||
{
|
{
|
||||||
GstBaseRTPDepayload parent;
|
GstRTPBaseDepayload parent;
|
||||||
GstAdapter *adapter;
|
GstAdapter *adapter;
|
||||||
gboolean started;
|
gboolean started;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* gst-rtp-vp8-pay.c - Source for GstRtpVP8Pay
|
* gstrtpvp8pay.c - Source for GstRtpVP8Pay
|
||||||
* Copyright (C) 2011 Sjoerd Simons <sjoerd@luon.net>
|
* Copyright (C) 2011 Sjoerd Simons <sjoerd@luon.net>
|
||||||
* Copyright (C) 2011 Collabora Ltd.
|
* Copyright (C) 2011 Collabora Ltd.
|
||||||
* Contact: Youness Alaoui <youness.alaoui@collabora.co.uk>
|
* Contact: Youness Alaoui <youness.alaoui@collabora.co.uk>
|
||||||
|
@ -35,8 +35,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_rtp_vp8_pay_debug);
|
||||||
|
|
||||||
#define DEFAULT_PICTURE_ID_MODE VP8_PAY_PICTURE_ID_7BITS
|
#define DEFAULT_PICTURE_ID_MODE VP8_PAY_PICTURE_ID_7BITS
|
||||||
|
|
||||||
GST_BOILERPLATE (GstRtpVP8Pay, gst_rtp_vp8_pay, GstBaseRTPPayload,
|
G_DEFINE_TYPE (GstRtpVP8Pay, gst_rtp_vp8_pay, GST_TYPE_RTP_BASE_PAYLOAD);
|
||||||
GST_TYPE_BASE_RTP_PAYLOAD);
|
|
||||||
|
|
||||||
static GstStaticPadTemplate gst_rtp_vp8_pay_src_template =
|
static GstStaticPadTemplate gst_rtp_vp8_pay_src_template =
|
||||||
GST_STATIC_PAD_TEMPLATE ("src",
|
GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
@ -53,7 +52,7 @@ GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_STATIC_CAPS ("video/x-vp8"));
|
GST_STATIC_CAPS ("video/x-vp8"));
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_rtp_vp8_pay_init (GstRtpVP8Pay * obj, GstRtpVP8PayClass * klass)
|
gst_rtp_vp8_pay_init (GstRtpVP8Pay * obj)
|
||||||
{
|
{
|
||||||
/* TODO: Make it configurable */
|
/* TODO: Make it configurable */
|
||||||
obj->picture_id_mode = DEFAULT_PICTURE_ID_MODE;
|
obj->picture_id_mode = DEFAULT_PICTURE_ID_MODE;
|
||||||
|
@ -63,16 +62,20 @@ gst_rtp_vp8_pay_init (GstRtpVP8Pay * obj, GstRtpVP8PayClass * klass)
|
||||||
obj->picture_id = g_random_int_range (0, G_MAXUINT16) & 0x7FFF;
|
obj->picture_id = g_random_int_range (0, G_MAXUINT16) & 0x7FFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn gst_rtp_vp8_pay_handle_buffer (GstBaseRTPPayload * payload,
|
static GstFlowReturn gst_rtp_vp8_pay_handle_buffer (GstRTPBasePayload * payload,
|
||||||
GstBuffer * buffer);
|
GstBuffer * buffer);
|
||||||
static gboolean gst_rtp_vp8_pay_handle_event (GstPad * pad, GstEvent * event);
|
static gboolean gst_rtp_vp8_pay_sink_event (GstRTPBasePayload * payload,
|
||||||
static gboolean gst_rtp_vp8_pay_set_caps (GstBaseRTPPayload * payload,
|
GstEvent * event);
|
||||||
|
static gboolean gst_rtp_vp8_pay_set_caps (GstRTPBasePayload * payload,
|
||||||
GstCaps * caps);
|
GstCaps * caps);
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_rtp_vp8_pay_base_init (gpointer klass)
|
gst_rtp_vp8_pay_class_init (GstRtpVP8PayClass * gst_rtp_vp8_pay_class)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (gst_rtp_vp8_pay_class);
|
||||||
|
GstRTPBasePayloadClass *pay_class =
|
||||||
|
GST_RTP_BASE_PAYLOAD_CLASS (gst_rtp_vp8_pay_class);
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&gst_rtp_vp8_pay_sink_template));
|
gst_static_pad_template_get (&gst_rtp_vp8_pay_sink_template));
|
||||||
|
@ -82,16 +85,9 @@ gst_rtp_vp8_pay_base_init (gpointer klass)
|
||||||
gst_element_class_set_details_simple (element_class, "RTP VP8 payloader",
|
gst_element_class_set_details_simple (element_class, "RTP VP8 payloader",
|
||||||
"Codec/Payloader/Network/RTP",
|
"Codec/Payloader/Network/RTP",
|
||||||
"Puts VP8 video in RTP packets)", "Sjoerd Simons <sjoerd@luon.net>");
|
"Puts VP8 video in RTP packets)", "Sjoerd Simons <sjoerd@luon.net>");
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_rtp_vp8_pay_class_init (GstRtpVP8PayClass * gst_rtp_vp8_pay_class)
|
|
||||||
{
|
|
||||||
GstBaseRTPPayloadClass *pay_class =
|
|
||||||
GST_BASE_RTP_PAYLOAD_CLASS (gst_rtp_vp8_pay_class);
|
|
||||||
|
|
||||||
pay_class->handle_buffer = gst_rtp_vp8_pay_handle_buffer;
|
pay_class->handle_buffer = gst_rtp_vp8_pay_handle_buffer;
|
||||||
pay_class->handle_event = gst_rtp_vp8_pay_handle_event;
|
pay_class->sink_event = gst_rtp_vp8_pay_sink_event;
|
||||||
pay_class->set_caps = gst_rtp_vp8_pay_set_caps;
|
pay_class->set_caps = gst_rtp_vp8_pay_set_caps;
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_rtp_vp8_pay_debug, "rtpvp8pay", 0,
|
GST_DEBUG_CATEGORY_INIT (gst_rtp_vp8_pay_debug, "rtpvp8pay", 0,
|
||||||
|
@ -101,23 +97,27 @@ gst_rtp_vp8_pay_class_init (GstRtpVP8PayClass * gst_rtp_vp8_pay_class)
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_rtp_vp8_pay_parse_frame (GstRtpVP8Pay * self, GstBuffer * buffer)
|
gst_rtp_vp8_pay_parse_frame (GstRtpVP8Pay * self, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
GstBitReader *reader;
|
GstBitReader *reader = NULL;
|
||||||
|
guint8 *data;
|
||||||
|
gsize size;
|
||||||
int i;
|
int i;
|
||||||
gboolean keyframe;
|
gboolean keyframe;
|
||||||
guint32 partition0_size;
|
guint32 partition0_size;
|
||||||
guint8 version;
|
guint8 version;
|
||||||
guint8 tmp8 = 0;
|
guint8 tmp8 = 0;
|
||||||
guint8 *data;
|
|
||||||
guint8 partitions;
|
guint8 partitions;
|
||||||
guint offset;
|
guint offset;
|
||||||
BOOL_DECODER bc;
|
BOOL_DECODER bc;
|
||||||
|
guint8 *pdata;
|
||||||
|
|
||||||
reader = gst_bit_reader_new_from_buffer (buffer);
|
if (G_UNLIKELY (gst_buffer_get_size (buffer) < 3))
|
||||||
|
|
||||||
if (G_UNLIKELY (GST_BUFFER_SIZE (buffer) < 3))
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
data = GST_BUFFER_DATA (buffer);
|
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||||
|
if (data == NULL)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
reader = gst_bit_reader_new (data, size);
|
||||||
|
|
||||||
self->is_keyframe = keyframe = ((data[0] & 0x1) == 0);
|
self->is_keyframe = keyframe = ((data[0] & 0x1) == 0);
|
||||||
version = (data[0] >> 1) & 0x7;
|
version = (data[0] >> 1) & 0x7;
|
||||||
|
@ -154,8 +154,7 @@ gst_rtp_vp8_pay_parse_frame (GstRtpVP8Pay * self, GstBuffer * buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = keyframe ? 10 : 3;
|
offset = keyframe ? 10 : 3;
|
||||||
vp8dx_start_decode (&bc, GST_BUFFER_DATA (buffer) + offset,
|
vp8dx_start_decode (&bc, data + offset, size - offset);
|
||||||
GST_BUFFER_SIZE (buffer) - offset);
|
|
||||||
|
|
||||||
if (keyframe) {
|
if (keyframe) {
|
||||||
/* color space (1 bit) and clamping type (1 bit) */
|
/* color space (1 bit) and clamping type (1 bit) */
|
||||||
|
@ -226,11 +225,11 @@ gst_rtp_vp8_pay_parse_frame (GstRtpVP8Pay * self, GstBuffer * buffer)
|
||||||
partitions = 1 << tmp8;
|
partitions = 1 << tmp8;
|
||||||
|
|
||||||
/* Check if things are still sensible */
|
/* Check if things are still sensible */
|
||||||
if (partition0_size + (partitions - 1) * 3 >= GST_BUFFER_SIZE (buffer))
|
if (partition0_size + (partitions - 1) * 3 >= size)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* partition data is right after the mode partition */
|
/* partition data is right after the mode partition */
|
||||||
data = GST_BUFFER_DATA (buffer) + partition0_size;
|
pdata = data + partition0_size;
|
||||||
|
|
||||||
/* Set up mapping */
|
/* Set up mapping */
|
||||||
self->n_partitions = partitions + 1;
|
self->n_partitions = partitions + 1;
|
||||||
|
@ -239,29 +238,32 @@ gst_rtp_vp8_pay_parse_frame (GstRtpVP8Pay * self, GstBuffer * buffer)
|
||||||
|
|
||||||
self->partition_offset[1] = self->partition_size[0];
|
self->partition_offset[1] = self->partition_size[0];
|
||||||
for (i = 1; i < partitions; i++) {
|
for (i = 1; i < partitions; i++) {
|
||||||
guint size = (data[2] << 16 | data[1] << 8 | data[0]);
|
guint psize = (pdata[2] << 16 | pdata[1] << 8 | pdata[0]);
|
||||||
|
|
||||||
data += 3;
|
pdata += 3;
|
||||||
self->partition_size[i] = size;
|
self->partition_size[i] = psize;
|
||||||
self->partition_offset[i + 1] = self->partition_offset[i] + size;
|
self->partition_offset[i + 1] = self->partition_offset[i] + psize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that our partition offsets and sizes don't go outsize the buffer
|
/* Check that our partition offsets and sizes don't go outsize the buffer
|
||||||
* size. */
|
* size. */
|
||||||
if (self->partition_offset[i] >= GST_BUFFER_SIZE (buffer))
|
if (self->partition_offset[i] >= size)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
self->partition_size[i] = GST_BUFFER_SIZE (buffer)
|
self->partition_size[i] = size - self->partition_offset[i];
|
||||||
- self->partition_offset[i];
|
|
||||||
|
|
||||||
self->partition_offset[i + 1] = GST_BUFFER_SIZE (buffer);
|
self->partition_offset[i + 1] = size;
|
||||||
|
|
||||||
gst_bit_reader_free (reader);
|
gst_bit_reader_free (reader);
|
||||||
|
gst_buffer_unmap (buffer, data, size);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
GST_DEBUG ("Failed to parse frame");
|
GST_DEBUG ("Failed to parse frame");
|
||||||
|
if (reader) {
|
||||||
gst_bit_reader_free (reader);
|
gst_bit_reader_free (reader);
|
||||||
|
gst_buffer_unmap (buffer, data, size);
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,8 +299,8 @@ gst_rtp_vp8_calc_header_len (GstRtpVP8Pay * self)
|
||||||
static gsize
|
static gsize
|
||||||
gst_rtp_vp8_calc_payload_len (GstRtpVP8Pay * self)
|
gst_rtp_vp8_calc_payload_len (GstRtpVP8Pay * self)
|
||||||
{
|
{
|
||||||
GstBaseRTPPayload *payload = GST_BASE_RTP_PAYLOAD (self);
|
GstRTPBasePayload *payload = GST_RTP_BASE_PAYLOAD (self);
|
||||||
return gst_rtp_buffer_calc_payload_len (GST_BASE_RTP_PAYLOAD_MTU (payload) -
|
return gst_rtp_buffer_calc_payload_len (GST_RTP_BASE_PAYLOAD_MTU (payload) -
|
||||||
gst_rtp_vp8_calc_header_len (self), 0, 0);
|
gst_rtp_vp8_calc_header_len (self), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,9 +311,11 @@ gst_rtp_vp8_create_header_buffer (GstRtpVP8Pay * self, guint8 partid,
|
||||||
{
|
{
|
||||||
GstBuffer *out;
|
GstBuffer *out;
|
||||||
guint8 *p;
|
guint8 *p;
|
||||||
|
GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
|
||||||
|
|
||||||
out = gst_rtp_buffer_new_allocate (gst_rtp_vp8_calc_header_len (self), 0, 0);
|
out = gst_rtp_buffer_new_allocate (gst_rtp_vp8_calc_header_len (self), 0, 0);
|
||||||
p = gst_rtp_buffer_get_payload (out);
|
gst_rtp_buffer_map (out, GST_MAP_READWRITE, &rtpbuffer);
|
||||||
|
p = gst_rtp_buffer_get_payload (&rtpbuffer);
|
||||||
/* X=0,R=0,N=0,S=start,PartID=partid */
|
/* X=0,R=0,N=0,S=start,PartID=partid */
|
||||||
p[0] = (start << 4) | partid;
|
p[0] = (start << 4) | partid;
|
||||||
if (self->picture_id_mode != VP8_PAY_NO_PICTURE_ID) {
|
if (self->picture_id_mode != VP8_PAY_NO_PICTURE_ID) {
|
||||||
|
@ -329,10 +333,12 @@ gst_rtp_vp8_create_header_buffer (GstRtpVP8Pay * self, guint8 partid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_rtp_buffer_set_marker (out, mark);
|
gst_rtp_buffer_set_marker (&rtpbuffer, mark);
|
||||||
|
|
||||||
|
gst_rtp_buffer_unmap (&rtpbuffer);
|
||||||
|
|
||||||
GST_BUFFER_DURATION (out) = GST_BUFFER_DURATION (in);
|
GST_BUFFER_DURATION (out) = GST_BUFFER_DURATION (in);
|
||||||
GST_BUFFER_TIMESTAMP (out) = GST_BUFFER_TIMESTAMP (in);
|
GST_BUFFER_PTS (out) = GST_BUFFER_PTS (in);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -340,16 +346,17 @@ gst_rtp_vp8_create_header_buffer (GstRtpVP8Pay * self, guint8 partid,
|
||||||
|
|
||||||
static guint
|
static guint
|
||||||
gst_rtp_vp8_payload_next (GstRtpVP8Pay * self,
|
gst_rtp_vp8_payload_next (GstRtpVP8Pay * self,
|
||||||
GstBufferListIterator * it, guint offset, GstBuffer * buffer)
|
GstBufferList * list, guint offset, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
guint partition;
|
guint partition;
|
||||||
GstBuffer *header;
|
GstBuffer *header;
|
||||||
GstBuffer *sub;
|
GstBuffer *sub;
|
||||||
|
GstBuffer *out;
|
||||||
gboolean mark;
|
gboolean mark;
|
||||||
gsize remaining;
|
gsize remaining;
|
||||||
gsize available;
|
gsize available;
|
||||||
|
|
||||||
remaining = GST_BUFFER_SIZE (buffer) - offset;
|
remaining = gst_buffer_get_size (buffer) - offset;
|
||||||
available = gst_rtp_vp8_calc_payload_len (self);
|
available = gst_rtp_vp8_calc_payload_len (self);
|
||||||
if (available > remaining)
|
if (available > remaining)
|
||||||
available = remaining;
|
available = remaining;
|
||||||
|
@ -361,23 +368,22 @@ gst_rtp_vp8_payload_next (GstRtpVP8Pay * self,
|
||||||
/* whole set of partitions, payload them and done */
|
/* whole set of partitions, payload them and done */
|
||||||
header = gst_rtp_vp8_create_header_buffer (self, partition,
|
header = gst_rtp_vp8_create_header_buffer (self, partition,
|
||||||
offset == self->partition_offset[partition], mark, buffer);
|
offset == self->partition_offset[partition], mark, buffer);
|
||||||
sub = gst_buffer_create_sub (buffer, offset, available);
|
sub = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, offset, available);
|
||||||
|
|
||||||
gst_buffer_list_iterator_add_group (it);
|
out = gst_buffer_join (header, sub);
|
||||||
gst_buffer_list_iterator_add (it, header);
|
|
||||||
gst_buffer_list_iterator_add (it, sub);
|
|
||||||
|
|
||||||
return GST_BUFFER_SIZE (sub);
|
gst_buffer_list_insert (list, -1, out);
|
||||||
|
|
||||||
|
return available;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_rtp_vp8_pay_handle_buffer (GstBaseRTPPayload * payload, GstBuffer * buffer)
|
gst_rtp_vp8_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
GstRtpVP8Pay *self = GST_RTP_VP8_PAY (payload);
|
GstRtpVP8Pay *self = GST_RTP_VP8_PAY (payload);
|
||||||
GstFlowReturn ret;
|
GstFlowReturn ret;
|
||||||
GstBufferList *list;
|
GstBufferList *list;
|
||||||
GstBufferListIterator *it;
|
|
||||||
guint offset;
|
guint offset;
|
||||||
|
|
||||||
if (G_UNLIKELY (!gst_rtp_vp8_pay_parse_frame (self, buffer))) {
|
if (G_UNLIKELY (!gst_rtp_vp8_pay_parse_frame (self, buffer))) {
|
||||||
|
@ -386,13 +392,11 @@ gst_rtp_vp8_pay_handle_buffer (GstBaseRTPPayload * payload, GstBuffer * buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
list = gst_buffer_list_new ();
|
list = gst_buffer_list_new ();
|
||||||
it = gst_buffer_list_iterate (list);
|
|
||||||
|
|
||||||
for (offset = 0; offset < GST_BUFFER_SIZE (buffer);)
|
for (offset = 0; offset < gst_buffer_get_size (buffer);)
|
||||||
offset += gst_rtp_vp8_payload_next (self, it, offset, buffer);
|
offset += gst_rtp_vp8_payload_next (self, list, offset, buffer);
|
||||||
|
|
||||||
ret = gst_basertppayload_push_list (payload, list);
|
ret = gst_rtp_base_payload_push_list (payload, list);
|
||||||
gst_buffer_list_iterator_free (it);
|
|
||||||
|
|
||||||
/* Incremenent and wrap the picture id if it overflows */
|
/* Incremenent and wrap the picture id if it overflows */
|
||||||
if ((self->picture_id_mode == VP8_PAY_PICTURE_ID_7BITS &&
|
if ((self->picture_id_mode == VP8_PAY_PICTURE_ID_7BITS &&
|
||||||
|
@ -405,9 +409,9 @@ gst_rtp_vp8_pay_handle_buffer (GstBaseRTPPayload * payload, GstBuffer * buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_rtp_vp8_pay_handle_event (GstPad * pad, GstEvent * event)
|
gst_rtp_vp8_pay_sink_event (GstRTPBasePayload * payload, GstEvent * event)
|
||||||
{
|
{
|
||||||
GstRtpVP8Pay *self = GST_RTP_VP8_PAY (gst_pad_get_parent (pad));
|
GstRtpVP8Pay *self = GST_RTP_VP8_PAY (payload);
|
||||||
|
|
||||||
if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) {
|
if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) {
|
||||||
if (self->picture_id_mode == VP8_PAY_PICTURE_ID_7BITS)
|
if (self->picture_id_mode == VP8_PAY_PICTURE_ID_7BITS)
|
||||||
|
@ -416,17 +420,16 @@ gst_rtp_vp8_pay_handle_event (GstPad * pad, GstEvent * event)
|
||||||
self->picture_id = g_random_int_range (0, G_MAXUINT16) & 0x7FFF;
|
self->picture_id = g_random_int_range (0, G_MAXUINT16) & 0x7FFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_object_unref (self);
|
return GST_RTP_BASE_PAYLOAD_CLASS (gst_rtp_vp8_pay_parent_class)->sink_event
|
||||||
|
(payload, event);
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_rtp_vp8_pay_set_caps (GstBaseRTPPayload * payload, GstCaps * caps)
|
gst_rtp_vp8_pay_set_caps (GstRTPBasePayload * payload, GstCaps * caps)
|
||||||
{
|
{
|
||||||
gst_basertppayload_set_options (payload, "video", TRUE,
|
gst_rtp_base_payload_set_options (payload, "video", TRUE,
|
||||||
"VP8-DRAFT-IETF-01", 90000);
|
"VP8-DRAFT-IETF-01", 90000);
|
||||||
return gst_basertppayload_set_outcaps (payload, NULL);
|
return gst_rtp_base_payload_set_outcaps (payload, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* gst-rtp-vp8-pay.h - Header for GstRtpVP8Pay
|
* gstrtpvp8pay.h - Header for GstRtpVP8Pay
|
||||||
* Copyright (C) 2011 Sjoerd Simons <sjoerd@luon.net>
|
* Copyright (C) 2011 Sjoerd Simons <sjoerd@luon.net>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <gst/base/gstadapter.h>
|
#include <gst/base/gstadapter.h>
|
||||||
#include <gst/rtp/gstbasertppayload.h>
|
#include <gst/rtp/gstrtpbasepayload.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS typedef struct _GstRtpVP8Pay GstRtpVP8Pay;
|
G_BEGIN_DECLS typedef struct _GstRtpVP8Pay GstRtpVP8Pay;
|
||||||
typedef struct _GstRtpVP8PayClass GstRtpVP8PayClass;
|
typedef struct _GstRtpVP8PayClass GstRtpVP8PayClass;
|
||||||
|
@ -36,12 +36,12 @@ enum _PictureIDMode {
|
||||||
|
|
||||||
struct _GstRtpVP8PayClass
|
struct _GstRtpVP8PayClass
|
||||||
{
|
{
|
||||||
GstBaseRTPPayloadClass parent_class;
|
GstRTPBasePayloadClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstRtpVP8Pay
|
struct _GstRtpVP8Pay
|
||||||
{
|
{
|
||||||
GstBaseRTPPayload parent;
|
GstRTPBasePayload parent;
|
||||||
gboolean is_keyframe;
|
gboolean is_keyframe;
|
||||||
gint n_partitions;
|
gint n_partitions;
|
||||||
/* Treat frame header & tag & partition size block as the first partition,
|
/* Treat frame header & tag & partition size block as the first partition,
|
||||||
|
|
Loading…
Reference in a new issue