openh264: Run gst-indent over everything

This commit is contained in:
Sebastian Dröge 2014-10-03 13:54:22 +03:00
parent 09f5b9acec
commit 088cf16bf9
3 changed files with 862 additions and 782 deletions

View file

@ -56,12 +56,15 @@ static void gst_openh264dec_get_property(GObject *object, guint property_id,
static gboolean gst_openh264dec_start (GstVideoDecoder * decoder); static gboolean gst_openh264dec_start (GstVideoDecoder * decoder);
static gboolean gst_openh264dec_stop (GstVideoDecoder * decoder); static gboolean gst_openh264dec_stop (GstVideoDecoder * decoder);
static gboolean gst_openh264dec_set_format(GstVideoDecoder *decoder, GstVideoCodecState *state); static gboolean gst_openh264dec_set_format (GstVideoDecoder * decoder,
static gboolean gst_openh264dec_reset(GstVideoDecoder *decoder, gboolean hard); GstVideoCodecState * state);
static gboolean gst_openh264dec_reset (GstVideoDecoder * decoder,
gboolean hard);
static GstFlowReturn gst_openh264dec_finish (GstVideoDecoder * decoder); static GstFlowReturn gst_openh264dec_finish (GstVideoDecoder * decoder);
static GstFlowReturn gst_openh264dec_handle_frame (GstVideoDecoder * decoder, static GstFlowReturn gst_openh264dec_handle_frame (GstVideoDecoder * decoder,
GstVideoCodecFrame * frame); GstVideoCodecFrame * frame);
static gboolean gst_openh264dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query); static gboolean gst_openh264dec_decide_allocation (GstVideoDecoder * decoder,
GstQuery * query);
enum enum
{ {
@ -78,23 +81,28 @@ struct _GstOpenh264DecPrivate
/* pad templates */ /* pad templates */
static GstStaticPadTemplate gst_openh264dec_sink_template = GST_STATIC_PAD_TEMPLATE("sink", static GstStaticPadTemplate gst_openh264dec_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS("video/x-h264, stream-format=(string)byte-stream, alignment=(string)au")); GST_STATIC_CAPS
("video/x-h264, stream-format=(string)byte-stream, alignment=(string)au"));
static GstStaticPadTemplate gst_openh264dec_src_template = GST_STATIC_PAD_TEMPLATE("src", static GstStaticPadTemplate gst_openh264dec_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420"))); GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420")));
/* class initialization */ /* class initialization */
G_DEFINE_TYPE_WITH_CODE(GstOpenh264Dec, gst_openh264dec, GST_TYPE_VIDEO_DECODER, G_DEFINE_TYPE_WITH_CODE (GstOpenh264Dec, gst_openh264dec,
GST_DEBUG_CATEGORY_INIT(gst_openh264dec_debug_category, GST_TYPE_VIDEO_DECODER,
"openh264dec", 0, "debug category for openh264dec element")); GST_DEBUG_CATEGORY_INIT (gst_openh264dec_debug_category, "openh264dec", 0,
"debug category for openh264dec element"));
static void gst_openh264dec_class_init(GstOpenh264DecClass *klass) static void
gst_openh264dec_class_init (GstOpenh264DecClass * klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstVideoDecoderClass *video_decoder_class = GST_VIDEO_DECODER_CLASS (klass); GstVideoDecoderClass *video_decoder_class = GST_VIDEO_DECODER_CLASS (klass);
@ -108,21 +116,27 @@ static void gst_openh264dec_class_init(GstOpenh264DecClass *klass)
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass), gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
gst_static_pad_template_get (&gst_openh264dec_src_template)); gst_static_pad_template_get (&gst_openh264dec_src_template));
gst_element_class_set_static_metadata(GST_ELEMENT_CLASS(klass), "OpenH264 video decoder", "Decoder/Video", "OpenH264 video decoder", "Ericsson AB, http://www.ericsson.com"); gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
"OpenH264 video decoder", "Decoder/Video", "OpenH264 video decoder",
"Ericsson AB, http://www.ericsson.com");
gobject_class->set_property = gst_openh264dec_set_property; gobject_class->set_property = gst_openh264dec_set_property;
gobject_class->get_property = gst_openh264dec_get_property; gobject_class->get_property = gst_openh264dec_get_property;
video_decoder_class->start = GST_DEBUG_FUNCPTR (gst_openh264dec_start); video_decoder_class->start = GST_DEBUG_FUNCPTR (gst_openh264dec_start);
video_decoder_class->stop = GST_DEBUG_FUNCPTR (gst_openh264dec_stop); video_decoder_class->stop = GST_DEBUG_FUNCPTR (gst_openh264dec_stop);
video_decoder_class->set_format = GST_DEBUG_FUNCPTR(gst_openh264dec_set_format); video_decoder_class->set_format =
GST_DEBUG_FUNCPTR (gst_openh264dec_set_format);
video_decoder_class->reset = GST_DEBUG_FUNCPTR (gst_openh264dec_reset); video_decoder_class->reset = GST_DEBUG_FUNCPTR (gst_openh264dec_reset);
video_decoder_class->finish = GST_DEBUG_FUNCPTR (gst_openh264dec_finish); video_decoder_class->finish = GST_DEBUG_FUNCPTR (gst_openh264dec_finish);
video_decoder_class->handle_frame = GST_DEBUG_FUNCPTR(gst_openh264dec_handle_frame); video_decoder_class->handle_frame =
video_decoder_class->decide_allocation = GST_DEBUG_FUNCPTR(gst_openh264dec_decide_allocation); GST_DEBUG_FUNCPTR (gst_openh264dec_handle_frame);
video_decoder_class->decide_allocation =
GST_DEBUG_FUNCPTR (gst_openh264dec_decide_allocation);
} }
static void gst_openh264dec_init(GstOpenh264Dec *openh264dec) static void
gst_openh264dec_init (GstOpenh264Dec * openh264dec)
{ {
openh264dec->priv = GST_OPENH264DEC_GET_PRIVATE (openh264dec); openh264dec->priv = GST_OPENH264DEC_GET_PRIVATE (openh264dec);
openh264dec->priv->decoder = NULL; openh264dec->priv->decoder = NULL;
@ -131,7 +145,8 @@ static void gst_openh264dec_init(GstOpenh264Dec *openh264dec)
gst_video_decoder_set_needs_format (GST_VIDEO_DECODER (openh264dec), TRUE); gst_video_decoder_set_needs_format (GST_VIDEO_DECODER (openh264dec), TRUE);
} }
void gst_openh264dec_set_property(GObject *object, guint property_id, void
gst_openh264dec_set_property (GObject * object, guint property_id,
const GValue * value, GParamSpec * pspec) const GValue * value, GParamSpec * pspec)
{ {
GstOpenh264Dec *openh264dec = GST_OPENH264DEC (object); GstOpenh264Dec *openh264dec = GST_OPENH264DEC (object);
@ -145,7 +160,9 @@ void gst_openh264dec_set_property(GObject *object, guint property_id,
} }
} }
void gst_openh264dec_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) void
gst_openh264dec_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
{ {
GstOpenh264Dec *openh264dec = GST_OPENH264DEC (object); GstOpenh264Dec *openh264dec = GST_OPENH264DEC (object);
@ -158,14 +175,14 @@ void gst_openh264dec_get_property(GObject *object, guint property_id, GValue *va
} }
} }
static gboolean gst_openh264dec_start(GstVideoDecoder *decoder) static gboolean
gst_openh264dec_start (GstVideoDecoder * decoder)
{ {
GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder); GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder);
gint ret; gint ret;
SDecodingParam dec_param = { 0 }; SDecodingParam dec_param = { 0 };
if (openh264dec->priv->decoder != NULL) if (openh264dec->priv->decoder != NULL) {
{
openh264dec->priv->decoder->Uninitialize (); openh264dec->priv->decoder->Uninitialize ();
WelsDestroyDecoder (openh264dec->priv->decoder); WelsDestroyDecoder (openh264dec->priv->decoder);
openh264dec->priv->decoder = NULL; openh264dec->priv->decoder = NULL;
@ -179,12 +196,15 @@ static gboolean gst_openh264dec_start(GstVideoDecoder *decoder)
ret = openh264dec->priv->decoder->Initialize (&dec_param); ret = openh264dec->priv->decoder->Initialize (&dec_param);
GST_DEBUG_OBJECT(openh264dec, "openh264_dec_start called, openh264dec %sinitialized OK!", (ret != cmResultSuccess) ? "NOT " : ""); GST_DEBUG_OBJECT (openh264dec,
"openh264_dec_start called, openh264dec %sinitialized OK!",
(ret != cmResultSuccess) ? "NOT " : "");
return (ret == cmResultSuccess); return (ret == cmResultSuccess);
} }
static gboolean gst_openh264dec_stop(GstVideoDecoder *decoder) static gboolean
gst_openh264dec_stop (GstVideoDecoder * decoder)
{ {
GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder); GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder);
gint ret = TRUE; gint ret = TRUE;
@ -204,11 +224,14 @@ static gboolean gst_openh264dec_stop(GstVideoDecoder *decoder)
return ret; return ret;
} }
static gboolean gst_openh264dec_set_format(GstVideoDecoder *decoder, GstVideoCodecState *state) static gboolean
gst_openh264dec_set_format (GstVideoDecoder * decoder,
GstVideoCodecState * state)
{ {
GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder); GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder);
GST_DEBUG_OBJECT(openh264dec, "openh264_dec_set_format called, caps: %" GST_PTR_FORMAT, state->caps); GST_DEBUG_OBJECT (openh264dec,
"openh264_dec_set_format called, caps: %" GST_PTR_FORMAT, state->caps);
if (openh264dec->priv->input_state) { if (openh264dec->priv->input_state) {
gst_video_codec_state_unref (openh264dec->priv->input_state); gst_video_codec_state_unref (openh264dec->priv->input_state);
@ -219,7 +242,8 @@ static gboolean gst_openh264dec_set_format(GstVideoDecoder *decoder, GstVideoCod
return TRUE; return TRUE;
} }
static gboolean gst_openh264dec_reset(GstVideoDecoder *decoder, gboolean hard) static gboolean
gst_openh264dec_reset (GstVideoDecoder * decoder, gboolean hard)
{ {
GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder); GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder);
@ -254,7 +278,9 @@ get_oldest_pts_frame (GstVideoDecoder * decoder)
return oldest; return oldest;
} }
static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstVideoCodecFrame *frame) static GstFlowReturn
gst_openh264dec_handle_frame (GstVideoDecoder * decoder,
GstVideoCodecFrame * frame)
{ {
GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder); GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder);
GstMapInfo map_info; GstMapInfo map_info;
@ -275,21 +301,26 @@ static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstV
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
GST_LOG_OBJECT(openh264dec, "handle frame, %d", map_info.size > 4 ? map_info.data[4] & 0x1f : -1); GST_LOG_OBJECT (openh264dec, "handle frame, %d",
map_info.size > 4 ? map_info.data[4] & 0x1f : -1);
memset (&dst_buf_info, 0, sizeof (SBufferInfo)); memset (&dst_buf_info, 0, sizeof (SBufferInfo));
ret = openh264dec->priv->decoder->DecodeFrame2(map_info.data, map_info.size, yuvdata, &dst_buf_info); ret =
openh264dec->priv->decoder->DecodeFrame2 (map_info.data, map_info.size,
yuvdata, &dst_buf_info);
if (ret == dsNoParamSets) { if (ret == dsNoParamSets) {
GST_DEBUG_OBJECT (openh264dec, "Requesting a key unit"); GST_DEBUG_OBJECT (openh264dec, "Requesting a key unit");
gst_pad_push_event (GST_VIDEO_DECODER_SINK_PAD (decoder), gst_pad_push_event (GST_VIDEO_DECODER_SINK_PAD (decoder),
gst_video_event_new_upstream_force_key_unit(GST_CLOCK_TIME_NONE, FALSE, 0)); gst_video_event_new_upstream_force_key_unit (GST_CLOCK_TIME_NONE,
FALSE, 0));
} }
if (ret != dsErrorFree && ret != dsNoParamSets) { if (ret != dsErrorFree && ret != dsNoParamSets) {
GST_DEBUG_OBJECT (openh264dec, "Requesting a key unit"); GST_DEBUG_OBJECT (openh264dec, "Requesting a key unit");
gst_pad_push_event (GST_VIDEO_DECODER_SINK_PAD (decoder), gst_pad_push_event (GST_VIDEO_DECODER_SINK_PAD (decoder),
gst_video_event_new_upstream_force_key_unit(GST_CLOCK_TIME_NONE, FALSE, 0)); gst_video_event_new_upstream_force_key_unit (GST_CLOCK_TIME_NONE,
FALSE, 0));
GST_LOG_OBJECT (openh264dec, "error decoding nal, return code: %d", ret); GST_LOG_OBJECT (openh264dec, "error decoding nal, return code: %d", ret);
} }
@ -298,7 +329,9 @@ static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstV
frame = NULL; frame = NULL;
} else { } else {
memset (&dst_buf_info, 0, sizeof (SBufferInfo)); memset (&dst_buf_info, 0, sizeof (SBufferInfo));
ret = openh264dec->priv->decoder->DecodeFrame2(NULL, 0, yuvdata, &dst_buf_info); ret =
openh264dec->priv->decoder->DecodeFrame2 (NULL, 0, yuvdata,
&dst_buf_info);
if (ret != dsErrorFree) if (ret != dsErrorFree)
return GST_FLOW_EOS; return GST_FLOW_EOS;
} }
@ -320,17 +353,18 @@ static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstV
actual_width = dst_buf_info.UsrData.sSystemBuffer.iWidth; actual_width = dst_buf_info.UsrData.sSystemBuffer.iWidth;
actual_height = dst_buf_info.UsrData.sSystemBuffer.iHeight; actual_height = dst_buf_info.UsrData.sSystemBuffer.iHeight;
if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (openh264dec)) || actual_width != openh264dec->priv->width || actual_height != openh264dec->priv->height) { if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (openh264dec))
state = gst_video_decoder_set_output_state(decoder, || actual_width != openh264dec->priv->width
GST_VIDEO_FORMAT_I420, || actual_height != openh264dec->priv->height) {
actual_width, state =
actual_height, gst_video_decoder_set_output_state (decoder, GST_VIDEO_FORMAT_I420,
openh264dec->priv->input_state); actual_width, actual_height, openh264dec->priv->input_state);
openh264dec->priv->width = actual_width; openh264dec->priv->width = actual_width;
openh264dec->priv->height = actual_height; openh264dec->priv->height = actual_height;
if (!gst_video_decoder_negotiate (decoder)) { if (!gst_video_decoder_negotiate (decoder)) {
GST_ERROR_OBJECT(openh264dec, "Failed to negotiate with downstream elements"); GST_ERROR_OBJECT (openh264dec,
"Failed to negotiate with downstream elements");
return GST_FLOW_NOT_NEGOTIATED; return GST_FLOW_NOT_NEGOTIATED;
} }
} else { } else {
@ -343,7 +377,8 @@ static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstV
return flow_status; return flow_status;
} }
if (!gst_video_frame_map(&video_frame, &state->info, frame->output_buffer, GST_MAP_WRITE)) { if (!gst_video_frame_map (&video_frame, &state->info, frame->output_buffer,
GST_MAP_WRITE)) {
GST_ERROR_OBJECT (openh264dec, "Cannot map output buffer!"); GST_ERROR_OBJECT (openh264dec, "Cannot map output buffer!");
gst_video_codec_state_unref (state); gst_video_codec_state_unref (state);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
@ -354,7 +389,10 @@ static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstV
row_stride = GST_VIDEO_FRAME_COMP_STRIDE (&video_frame, i); row_stride = GST_VIDEO_FRAME_COMP_STRIDE (&video_frame, i);
component_width = GST_VIDEO_FRAME_COMP_WIDTH (&video_frame, i); component_width = GST_VIDEO_FRAME_COMP_WIDTH (&video_frame, i);
component_height = GST_VIDEO_FRAME_COMP_HEIGHT (&video_frame, i); component_height = GST_VIDEO_FRAME_COMP_HEIGHT (&video_frame, i);
src_width = i < 1 ? dst_buf_info.UsrData.sSystemBuffer.iStride[0] : dst_buf_info.UsrData.sSystemBuffer.iStride[1]; src_width =
i <
1 ? dst_buf_info.UsrData.sSystemBuffer.
iStride[0] : dst_buf_info.UsrData.sSystemBuffer.iStride[1];
for (row = 0; row < component_height; row++) { for (row = 0; row < component_height; row++) {
memcpy (p, yuvdata[i], component_width); memcpy (p, yuvdata[i], component_width);
p += row_stride; p += row_stride;
@ -367,7 +405,8 @@ static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstV
return gst_video_decoder_finish_frame (decoder, frame); return gst_video_decoder_finish_frame (decoder, frame);
} }
static GstFlowReturn gst_openh264dec_finish(GstVideoDecoder *decoder) static GstFlowReturn
gst_openh264dec_finish (GstVideoDecoder * decoder)
{ {
GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder); GstOpenh264Dec *openh264dec = GST_OPENH264DEC (decoder);
@ -383,15 +422,16 @@ static GstFlowReturn gst_openh264dec_finish(GstVideoDecoder *decoder)
return GST_FLOW_OK; return GST_FLOW_OK;
} }
static gboolean gst_openh264dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) static gboolean
gst_openh264dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query)
{ {
GstVideoCodecState *state; GstVideoCodecState *state;
GstBufferPool *pool; GstBufferPool *pool;
guint size, min, max; guint size, min, max;
GstStructure *config; GstStructure *config;
if (!GST_VIDEO_DECODER_CLASS (gst_openh264dec_parent_class)->decide_allocation (decoder, if (!GST_VIDEO_DECODER_CLASS (gst_openh264dec_parent_class)->decide_allocation
query)) (decoder, query))
return FALSE; return FALSE;
state = gst_video_decoder_get_output_state (decoder); state = gst_video_decoder_get_output_state (decoder);
@ -413,4 +453,3 @@ static gboolean gst_openh264dec_decide_allocation (GstVideoDecoder * decoder, Gs
return TRUE; return TRUE;
} }

View file

@ -58,9 +58,7 @@ gst_openh264enc_usage_type_get_type (void)
{0, NULL, NULL}, {0, NULL, NULL},
}; };
usage_type = usage_type = g_enum_register_static ("EUsageType", usage_types);
g_enum_register_static ("EUsageType",
usage_types);
} }
return usage_type; return usage_type;
@ -81,9 +79,7 @@ gst_openh264enc_rc_modes_get_type (void)
{0, NULL, NULL}, {0, NULL, NULL},
}; };
rc_modes_type = rc_modes_type = g_enum_register_static ("RC_MODES", rc_modes_types);
g_enum_register_static ("RC_MODES",
rc_modes_types);
} }
return rc_modes_type; return rc_modes_type;
@ -98,13 +94,17 @@ static void gst_openh264enc_get_property(GObject *object,
static void gst_openh264enc_finalize (GObject * object); static void gst_openh264enc_finalize (GObject * object);
static gboolean gst_openh264enc_start (GstVideoEncoder * encoder); static gboolean gst_openh264enc_start (GstVideoEncoder * encoder);
static gboolean gst_openh264enc_stop (GstVideoEncoder * encoder); static gboolean gst_openh264enc_stop (GstVideoEncoder * encoder);
static gboolean gst_openh264enc_set_format(GstVideoEncoder *encoder, GstVideoCodecState *state); static gboolean gst_openh264enc_set_format (GstVideoEncoder * encoder,
GstVideoCodecState * state);
static GstFlowReturn gst_openh264enc_handle_frame (GstVideoEncoder * encoder, static GstFlowReturn gst_openh264enc_handle_frame (GstVideoEncoder * encoder,
GstVideoCodecFrame * frame); GstVideoCodecFrame * frame);
static GstFlowReturn gst_openh264enc_finish (GstVideoEncoder * encoder); static GstFlowReturn gst_openh264enc_finish (GstVideoEncoder * encoder);
static gboolean gst_openh264enc_propose_allocation (GstVideoEncoder * encoder, GstQuery * query); static gboolean gst_openh264enc_propose_allocation (GstVideoEncoder * encoder,
static void gst_openh264enc_set_usage_type (GstOpenh264Enc *openh264enc, gint usage_type); GstQuery * query);
static void gst_openh264enc_set_rate_control (GstOpenh264Enc *openh264enc, gint rc_mode); static void gst_openh264enc_set_usage_type (GstOpenh264Enc * openh264enc,
gint usage_type);
static void gst_openh264enc_set_rate_control (GstOpenh264Enc * openh264enc,
gint rc_mode);
#define DEFAULT_BITRATE (128000) #define DEFAULT_BITRATE (128000)
@ -150,25 +150,30 @@ struct _GstOpenh264EncPrivate
/* pad templates */ /* pad templates */
static GstStaticPadTemplate gst_openh264enc_sink_template = GST_STATIC_PAD_TEMPLATE("sink", static GstStaticPadTemplate gst_openh264enc_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420")) GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420"))
); );
static GstStaticPadTemplate gst_openh264enc_src_template = GST_STATIC_PAD_TEMPLATE("src", static GstStaticPadTemplate gst_openh264enc_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS("video/x-h264, stream-format=(string)\"avc\", alignment=(string)\"au\", profile=(string)\"baseline\"") GST_STATIC_CAPS
("video/x-h264, stream-format=(string)\"avc\", alignment=(string)\"au\", profile=(string)\"baseline\"")
); );
/* class initialization */ /* class initialization */
G_DEFINE_TYPE_WITH_CODE(GstOpenh264Enc, gst_openh264enc, GST_TYPE_VIDEO_ENCODER, G_DEFINE_TYPE_WITH_CODE (GstOpenh264Enc, gst_openh264enc,
GST_TYPE_VIDEO_ENCODER,
GST_DEBUG_CATEGORY_INIT (gst_openh264enc_debug_category, "openh264enc", 0, GST_DEBUG_CATEGORY_INIT (gst_openh264enc_debug_category, "openh264enc", 0,
"debug category for openh264enc element")); "debug category for openh264enc element"));
static void gst_openh264enc_class_init(GstOpenh264EncClass *klass) static void
gst_openh264enc_class_init (GstOpenh264EncClass * klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstVideoEncoderClass *video_encoder_class = GST_VIDEO_ENCODER_CLASS (klass); GstVideoEncoderClass *video_encoder_class = GST_VIDEO_ENCODER_CLASS (klass);
@ -182,16 +187,21 @@ static void gst_openh264enc_class_init(GstOpenh264EncClass *klass)
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass), gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
gst_static_pad_template_get (&gst_openh264enc_sink_template)); gst_static_pad_template_get (&gst_openh264enc_sink_template));
gst_element_class_set_static_metadata(GST_ELEMENT_CLASS(klass), "OpenH264 video encoder", "Encoder/Video", "OpenH264 video encoder", "Ericsson AB, http://www.ericsson.com"); gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
"OpenH264 video encoder", "Encoder/Video", "OpenH264 video encoder",
"Ericsson AB, http://www.ericsson.com");
gobject_class->set_property = gst_openh264enc_set_property; gobject_class->set_property = gst_openh264enc_set_property;
gobject_class->get_property = gst_openh264enc_get_property; gobject_class->get_property = gst_openh264enc_get_property;
gobject_class->finalize = gst_openh264enc_finalize; gobject_class->finalize = gst_openh264enc_finalize;
video_encoder_class->start = GST_DEBUG_FUNCPTR (gst_openh264enc_start); video_encoder_class->start = GST_DEBUG_FUNCPTR (gst_openh264enc_start);
video_encoder_class->stop = GST_DEBUG_FUNCPTR (gst_openh264enc_stop); video_encoder_class->stop = GST_DEBUG_FUNCPTR (gst_openh264enc_stop);
video_encoder_class->set_format = GST_DEBUG_FUNCPTR(gst_openh264enc_set_format); video_encoder_class->set_format =
video_encoder_class->handle_frame = GST_DEBUG_FUNCPTR(gst_openh264enc_handle_frame); GST_DEBUG_FUNCPTR (gst_openh264enc_set_format);
video_encoder_class->propose_allocation = GST_DEBUG_FUNCPTR(gst_openh264enc_propose_allocation); video_encoder_class->handle_frame =
GST_DEBUG_FUNCPTR (gst_openh264enc_handle_frame);
video_encoder_class->propose_allocation =
GST_DEBUG_FUNCPTR (gst_openh264enc_propose_allocation);
video_encoder_class->finish = GST_DEBUG_FUNCPTR (gst_openh264enc_finish); video_encoder_class->finish = GST_DEBUG_FUNCPTR (gst_openh264enc_finish);
/* define properties */ /* define properties */
@ -216,8 +226,7 @@ static void gst_openh264enc_class_init(GstOpenh264EncClass *klass)
g_object_class_install_property (gobject_class, PROP_ENABLE_DENOISE, g_object_class_install_property (gobject_class, PROP_ENABLE_DENOISE,
g_param_spec_boolean ("enable-denoise", "Denoise Control", g_param_spec_boolean ("enable-denoise", "Denoise Control",
"Denoise control", "Denoise control",
FALSE, FALSE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
(GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_BITRATE, g_object_class_install_property (gobject_class, PROP_BITRATE,
g_param_spec_uint ("bitrate", "Bitrate", g_param_spec_uint ("bitrate", "Bitrate",
@ -238,7 +247,8 @@ static void gst_openh264enc_class_init(GstOpenh264EncClass *klass)
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
} }
static void gst_openh264enc_init(GstOpenh264Enc *openh264enc) static void
gst_openh264enc_init (GstOpenh264Enc * openh264enc)
{ {
openh264enc->priv = GST_OPENH264ENC_GET_PRIVATE (openh264enc); openh264enc->priv = GST_OPENH264ENC_GET_PRIVATE (openh264enc);
openh264enc->priv->gop_size = DEFAULT_GOP_SIZE; openh264enc->priv->gop_size = DEFAULT_GOP_SIZE;
@ -295,7 +305,8 @@ gst_openh264enc_set_rate_control (GstOpenh264Enc *openh264enc, gint rc_mode)
} }
} }
void gst_openh264enc_set_property(GObject *object, guint property_id, void
gst_openh264enc_set_property (GObject * object, guint property_id,
const GValue * value, GParamSpec * pspec) const GValue * value, GParamSpec * pspec)
{ {
GstOpenh264Enc *openh264enc = GST_OPENH264ENC (object); GstOpenh264Enc *openh264enc = GST_OPENH264ENC (object);
@ -337,7 +348,9 @@ void gst_openh264enc_set_property(GObject *object, guint property_id,
} }
} }
void gst_openh264enc_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) void
gst_openh264enc_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
{ {
GstOpenh264Enc *openh264enc = GST_OPENH264ENC (object); GstOpenh264Enc *openh264enc = GST_OPENH264ENC (object);
@ -378,7 +391,8 @@ void gst_openh264enc_get_property(GObject *object, guint property_id, GValue *va
} }
} }
void gst_openh264enc_finalize(GObject * object) void
gst_openh264enc_finalize (GObject * object)
{ {
GstOpenh264Enc *openh264enc = GST_OPENH264ENC (object); GstOpenh264Enc *openh264enc = GST_OPENH264ENC (object);
@ -394,7 +408,8 @@ void gst_openh264enc_finalize(GObject * object)
G_OBJECT_CLASS (gst_openh264enc_parent_class)->finalize (object); G_OBJECT_CLASS (gst_openh264enc_parent_class)->finalize (object);
} }
static gboolean gst_openh264enc_start(GstVideoEncoder *encoder) static gboolean
gst_openh264enc_start (GstVideoEncoder * encoder)
{ {
GstOpenh264Enc *openh264enc = GST_OPENH264ENC (encoder); GstOpenh264Enc *openh264enc = GST_OPENH264ENC (encoder);
GST_DEBUG_OBJECT (openh264enc, "start"); GST_DEBUG_OBJECT (openh264enc, "start");
@ -402,7 +417,8 @@ static gboolean gst_openh264enc_start(GstVideoEncoder *encoder)
return TRUE; return TRUE;
} }
static gboolean gst_openh264enc_stop(GstVideoEncoder *encoder) static gboolean
gst_openh264enc_stop (GstVideoEncoder * encoder)
{ {
GstOpenh264Enc *openh264enc; GstOpenh264Enc *openh264enc;
@ -426,7 +442,9 @@ static gboolean gst_openh264enc_stop(GstVideoEncoder *encoder)
} }
static gboolean gst_openh264enc_set_format(GstVideoEncoder *encoder, GstVideoCodecState *state) static gboolean
gst_openh264enc_set_format (GstVideoEncoder * encoder,
GstVideoCodecState * state)
{ {
GstOpenh264Enc *openh264enc = GST_OPENH264ENC (encoder); GstOpenh264Enc *openh264enc = GST_OPENH264ENC (encoder);
GstOpenh264EncPrivate *priv = openh264enc->priv; GstOpenh264EncPrivate *priv = openh264enc->priv;
@ -447,7 +465,8 @@ static gboolean gst_openh264enc_set_format(GstVideoEncoder *encoder, GstVideoCod
openh264enc->priv->frame_count = 0; openh264enc->priv->frame_count = 0;
debug_caps = gst_caps_to_string (state->caps); debug_caps = gst_caps_to_string (state->caps);
GST_DEBUG_OBJECT(openh264enc, "gst_e26d4_enc_set_format called, caps: %s", debug_caps); GST_DEBUG_OBJECT (openh264enc, "gst_e26d4_enc_set_format called, caps: %s",
debug_caps);
g_free (debug_caps); g_free (debug_caps);
gst_openh264enc_stop (encoder); gst_openh264enc_stop (encoder);
@ -517,13 +536,15 @@ static gboolean gst_openh264enc_set_format(GstVideoEncoder *encoder, GstVideoCod
nal_pps_length = bsInfo.sLayerInfo[0].pNalLengthInByte[1] - 4; nal_pps_length = bsInfo.sLayerInfo[0].pNalLengthInByte[1] - 4;
if (ret != cmResultSuccess) { if (ret != cmResultSuccess) {
GST_ELEMENT_ERROR(openh264enc, STREAM, ENCODE, ("Could not create headers"), ("Could not create SPS")); GST_ELEMENT_ERROR (openh264enc, STREAM, ENCODE,
("Could not create headers"), ("Could not create SPS"));
return FALSE; return FALSE;
} }
sps_tmp_buf = (guchar *) (g_memdup (nal_sps_data, nal_sps_length)); sps_tmp_buf = (guchar *) (g_memdup (nal_sps_data, nal_sps_length));
codec_data_tmp_buf = (guchar *)g_malloc(5 + 3 + nal_sps_length + 3 + nal_pps_length); codec_data_tmp_buf =
(guchar *) g_malloc (5 + 3 + nal_sps_length + 3 + nal_pps_length);
codec_data_tmp_buf[0] = 1; /* version 1 */ ; codec_data_tmp_buf[0] = 1; /* version 1 */ ;
codec_data_tmp_buf[1] = sps_tmp_buf[1]; /* profile */ codec_data_tmp_buf[1] = sps_tmp_buf[1]; /* profile */
codec_data_tmp_buf[2] = sps_tmp_buf[2]; /* profile constraints */ codec_data_tmp_buf[2] = sps_tmp_buf[2]; /* profile constraints */
@ -536,16 +557,22 @@ static gboolean gst_openh264enc_set_format(GstVideoEncoder *encoder, GstVideoCod
g_free (sps_tmp_buf); g_free (sps_tmp_buf);
codec_data_tmp_buf[8 + nal_sps_length] = 1; /* Number of PPS */ codec_data_tmp_buf[8 + nal_sps_length] = 1; /* Number of PPS */
GST_WRITE_UINT16_BE(codec_data_tmp_buf + 8 + nal_sps_length + 1, nal_pps_length); GST_WRITE_UINT16_BE (codec_data_tmp_buf + 8 + nal_sps_length + 1,
memcpy(codec_data_tmp_buf + 8 + nal_sps_length + 3, nal_pps_data, nal_pps_length); nal_pps_length);
memcpy (codec_data_tmp_buf + 8 + nal_sps_length + 3, nal_pps_data,
nal_pps_length);
GST_DEBUG_OBJECT(openh264enc, "Got SPS of size %d and PPS of size %d", nal_sps_length, nal_pps_length); GST_DEBUG_OBJECT (openh264enc, "Got SPS of size %d and PPS of size %d",
nal_sps_length, nal_pps_length);
codec_data = gst_buffer_new_wrapped(codec_data_tmp_buf, 5 + 3 + nal_sps_length + 3 + nal_pps_length); codec_data =
gst_buffer_new_wrapped (codec_data_tmp_buf,
5 + 3 + nal_sps_length + 3 + nal_pps_length);
outcaps = gst_caps_copy(gst_static_pad_template_get_caps(&gst_openh264enc_src_template)); outcaps =
gst_caps_set_simple(outcaps, gst_caps_copy (gst_static_pad_template_get_caps
"codec_data", GST_TYPE_BUFFER, codec_data, (&gst_openh264enc_src_template));
gst_caps_set_simple (outcaps, "codec_data", GST_TYPE_BUFFER, codec_data,
NULL); NULL);
gst_buffer_unref (codec_data); gst_buffer_unref (codec_data);
@ -555,15 +582,19 @@ static gboolean gst_openh264enc_set_format(GstVideoEncoder *encoder, GstVideoCod
return gst_video_encoder_negotiate (encoder); return gst_video_encoder_negotiate (encoder);
} }
static gboolean gst_openh264enc_propose_allocation (GstVideoEncoder * encoder, GstQuery * query) static gboolean
gst_openh264enc_propose_allocation (GstVideoEncoder * encoder, GstQuery * query)
{ {
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL); gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
return GST_VIDEO_ENCODER_CLASS (gst_openh264enc_parent_class)->propose_allocation (encoder, return
query); GST_VIDEO_ENCODER_CLASS (gst_openh264enc_parent_class)->propose_allocation
(encoder, query);
} }
static GstFlowReturn gst_openh264enc_handle_frame(GstVideoEncoder *encoder, GstVideoCodecFrame *frame) static GstFlowReturn
gst_openh264enc_handle_frame (GstVideoEncoder * encoder,
GstVideoCodecFrame * frame)
{ {
GstOpenh264Enc *openh264enc = GST_OPENH264ENC (encoder); GstOpenh264Enc *openh264enc = GST_OPENH264ENC (encoder);
SSourcePicture *src_pic = NULL; SSourcePicture *src_pic = NULL;
@ -590,11 +621,13 @@ static GstFlowReturn gst_openh264enc_handle_frame(GstVideoEncoder *encoder, GstV
openh264enc->priv->frame_count++; openh264enc->priv->frame_count++;
if (frame) { if (frame) {
if (G_UNLIKELY (openh264enc->priv->frame_count == 1)) { if (G_UNLIKELY (openh264enc->priv->frame_count == 1)) {
openh264enc->priv->time_per_frame = (GST_NSECOND / openh264enc->priv->framerate); openh264enc->priv->time_per_frame =
(GST_NSECOND / openh264enc->priv->framerate);
openh264enc->priv->previous_timestamp = frame->pts; openh264enc->priv->previous_timestamp = frame->pts;
} else { } else {
openh264enc->priv->time_per_frame = openh264enc->priv->time_per_frame * 0.8 + openh264enc->priv->time_per_frame =
(frame->pts - openh264enc->priv->previous_timestamp) * 0.2; openh264enc->priv->time_per_frame * 0.8 + (frame->pts -
openh264enc->priv->previous_timestamp) * 0.2;
openh264enc->priv->previous_timestamp = frame->pts; openh264enc->priv->previous_timestamp = frame->pts;
if (openh264enc->priv->frame_count % 10 == 0) { if (openh264enc->priv->frame_count % 10 == 0) {
fps = GST_SECOND / (gdouble) openh264enc->priv->time_per_frame; fps = GST_SECOND / (gdouble) openh264enc->priv->time_per_frame;
@ -613,7 +646,8 @@ static GstFlowReturn gst_openh264enc_handle_frame(GstVideoEncoder *encoder, GstV
} }
if (frame) { if (frame) {
gst_video_frame_map(&video_frame, &openh264enc->priv->input_state->info, frame->input_buffer, GST_MAP_READ); gst_video_frame_map (&video_frame, &openh264enc->priv->input_state->info,
frame->input_buffer, GST_MAP_READ);
src_pic->iPicWidth = GST_VIDEO_FRAME_WIDTH (&video_frame); src_pic->iPicWidth = GST_VIDEO_FRAME_WIDTH (&video_frame);
src_pic->iPicHeight = GST_VIDEO_FRAME_HEIGHT (&video_frame); src_pic->iPicHeight = GST_VIDEO_FRAME_HEIGHT (&video_frame);
src_pic->iStride[0] = GST_VIDEO_FRAME_COMP_STRIDE (&video_frame, 0); src_pic->iStride[0] = GST_VIDEO_FRAME_COMP_STRIDE (&video_frame, 0);
@ -626,7 +660,8 @@ static GstFlowReturn gst_openh264enc_handle_frame(GstVideoEncoder *encoder, GstV
force_keyframe = GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame); force_keyframe = GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame);
if (force_keyframe) { if (force_keyframe) {
openh264enc->priv->encoder->ForceIntraFrame (true); openh264enc->priv->encoder->ForceIntraFrame (true);
GST_DEBUG_OBJECT(openh264enc,"Got force key unit event, next frame coded as intra picture"); GST_DEBUG_OBJECT (openh264enc,
"Got force key unit event, next frame coded as intra picture");
} }
} }
@ -637,7 +672,8 @@ static GstFlowReturn gst_openh264enc_handle_frame(GstVideoEncoder *encoder, GstV
gst_video_frame_unmap (&video_frame); gst_video_frame_unmap (&video_frame);
gst_video_codec_frame_unref (frame); gst_video_codec_frame_unref (frame);
delete src_pic; delete src_pic;
GST_ELEMENT_ERROR(openh264enc, STREAM, ENCODE, ("Could not encode frame"), ("Openh264 returned %d", ret)); GST_ELEMENT_ERROR (openh264enc, STREAM, ENCODE,
("Could not encode frame"), ("Openh264 returned %d", ret));
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} else { } else {
return GST_FLOW_EOS; return GST_FLOW_EOS;
@ -667,7 +703,8 @@ static GstFlowReturn gst_openh264enc_handle_frame(GstVideoEncoder *encoder, GstV
* guess based on the input */ * guess based on the input */
frame = gst_video_encoder_get_oldest_frame (base_encoder); frame = gst_video_encoder_get_oldest_frame (base_encoder);
if (!frame) { if (!frame) {
GST_ELEMENT_ERROR(openh264enc, STREAM, ENCODE, ("Could not encode frame"), ("openh264enc returned %d", ret)); GST_ELEMENT_ERROR (openh264enc, STREAM, ENCODE, ("Could not encode frame"),
("openh264enc returned %d", ret));
gst_video_codec_frame_unref (frame); gst_video_codec_frame_unref (frame);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
@ -691,7 +728,8 @@ static GstFlowReturn gst_openh264enc_handle_frame(GstVideoEncoder *encoder, GstV
idr_length = bs_info->pNalLengthInByte[0] - 4; idr_length = bs_info->pNalLengthInByte[0] - 4;
tmp_buf_length = nal_sps_length + 2 + nal_pps_length + 2 + idr_length + 2; tmp_buf_length = nal_sps_length + 2 + nal_pps_length + 2 + idr_length + 2;
frame->output_buffer = gst_video_encoder_allocate_output_buffer (encoder, tmp_buf_length); frame->output_buffer =
gst_video_encoder_allocate_output_buffer (encoder, tmp_buf_length);
gst_buffer_map (frame->output_buffer, &map, GST_MAP_WRITE); gst_buffer_map (frame->output_buffer, &map, GST_MAP_WRITE);
GST_WRITE_UINT16_BE (map.data, nal_sps_length); GST_WRITE_UINT16_BE (map.data, nal_sps_length);
@ -700,8 +738,10 @@ static GstFlowReturn gst_openh264enc_handle_frame(GstVideoEncoder *encoder, GstV
GST_WRITE_UINT16_BE (map.data + nal_sps_length + 2, nal_pps_length); GST_WRITE_UINT16_BE (map.data + nal_sps_length + 2, nal_pps_length);
memcpy (map.data + nal_sps_length + 2 + 2, nal_pps_data, nal_pps_length); memcpy (map.data + nal_sps_length + 2 + 2, nal_pps_data, nal_pps_length);
GST_WRITE_UINT16_BE(map.data + nal_sps_length + 2 + nal_pps_length + 2 , idr_length); GST_WRITE_UINT16_BE (map.data + nal_sps_length + 2 + nal_pps_length + 2,
memcpy(map.data + nal_sps_length + 2 + nal_pps_length + 2 + 2, bs_info->pBsBuf + 4, idr_length); idr_length);
memcpy (map.data + nal_sps_length + 2 + nal_pps_length + 2 + 2,
bs_info->pBsBuf + 4, idr_length);
gst_buffer_unmap (frame->output_buffer, &map); gst_buffer_unmap (frame->output_buffer, &map);
@ -710,7 +750,8 @@ static GstFlowReturn gst_openh264enc_handle_frame(GstVideoEncoder *encoder, GstV
GstMapInfo map; GstMapInfo map;
tmp_buf_length = nal_size + 2; tmp_buf_length = nal_size + 2;
frame->output_buffer = gst_video_encoder_allocate_output_buffer (encoder, tmp_buf_length); frame->output_buffer =
gst_video_encoder_allocate_output_buffer (encoder, tmp_buf_length);
gst_buffer_map (frame->output_buffer, &map, GST_MAP_WRITE); gst_buffer_map (frame->output_buffer, &map, GST_MAP_WRITE);
GST_WRITE_UINT16_BE (map.data, nal_size); GST_WRITE_UINT16_BE (map.data, nal_size);
@ -721,12 +762,14 @@ static GstFlowReturn gst_openh264enc_handle_frame(GstVideoEncoder *encoder, GstV
GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT (frame); GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT (frame);
} }
GST_LOG_OBJECT(openh264enc, "openh264 picture %scoded OK!", (ret != cmResultSuccess) ? "NOT " : ""); GST_LOG_OBJECT (openh264enc, "openh264 picture %scoded OK!",
(ret != cmResultSuccess) ? "NOT " : "");
return gst_video_encoder_finish_frame (encoder, frame); return gst_video_encoder_finish_frame (encoder, frame);
} }
static GstFlowReturn gst_openh264enc_finish (GstVideoEncoder *encoder) static GstFlowReturn
gst_openh264enc_finish (GstVideoEncoder * encoder)
{ {
GstOpenh264Enc *openh264enc = GST_OPENH264ENC (encoder); GstOpenh264Enc *openh264enc = GST_OPENH264ENC (encoder);

View file

@ -38,19 +38,17 @@
static gboolean static gboolean
plugin_init (GstPlugin * plugin) plugin_init (GstPlugin * plugin)
{ {
gst_element_register(plugin, "openh264dec", GST_RANK_NONE, GST_TYPE_OPENH264DEC); gst_element_register (plugin, "openh264dec", GST_RANK_NONE,
gst_element_register(plugin, "openh264enc", GST_RANK_NONE, GST_TYPE_OPENH264ENC); GST_TYPE_OPENH264DEC);
gst_element_register (plugin, "openh264enc", GST_RANK_NONE,
GST_TYPE_OPENH264ENC);
return TRUE; return TRUE;
} }
GST_PLUGIN_DEFINE( GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MAJOR,
GST_VERSION_MINOR, GST_VERSION_MINOR,
openh264, openh264,
"OpenH264 encoder/decoder plugin", "OpenH264 encoder/decoder plugin",
plugin_init, plugin_init,
VERSION, VERSION, "BSD", "OpenWebRTC GStreamer plugins", "http://www.ericsson.com")
"BSD",
"OpenWebRTC GStreamer plugins",
"http://www.ericsson.com")