gst_x264_enc_reset (GstX264Enc * encoder)
{
encoder->x264enc = NULL;
- encoder->width = 0;
- encoder->height = 0;
+ gst_video_info_init (&encoder->info);
encoder->current_byte_stream = GST_X264_ENC_STREAM_FORMAT_FROM_PROPERTY;
+ gst_segment_init (&encoder->segment, GST_FORMAT_UNDEFINED);
GST_OBJECT_LOCK (encoder);
- encoder->i_type = X264_TYPE_AUTO;
- if (encoder->forcekeyunit_event)
- gst_event_unref (encoder->forcekeyunit_event);
- encoder->forcekeyunit_event = NULL;
+ gst_event_replace (&encoder->force_key_unit_event, NULL);
+ encoder->pending_key_unit_ts = GST_CLOCK_TIME_NONE;
GST_OBJECT_UNLOCK (encoder);
}
}
static gboolean
-gst_x264_enc_sink_event (GstPad * pad, GstEvent * event)
+gst_x264_enc_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
- gboolean ret;
+ gboolean ret = FALSE, forward = TRUE;
GstX264Enc *encoder;
- encoder = GST_X264_ENC (gst_pad_get_parent (pad));
+ encoder = GST_X264_ENC (parent);
switch (GST_EVENT_TYPE (event)) {
- case GST_EVENT_NEWSEGMENT:
+ case GST_EVENT_CAPS:
{
- gboolean update;
- gdouble rate, applied_rate;
- GstFormat format;
- gint64 start, stop, position;
-
- gst_event_parse_new_segment_full (event, &update, &rate, &applied_rate,
- &format, &start, &stop, &position);
- gst_segment_set_newsegment (&encoder->segment, update, rate, format,
- start, stop, position);
+ GstCaps *caps;
+
+ gst_event_parse_caps (event, &caps);
+ ret = gst_x264_enc_sink_set_caps (pad, caps);
+ forward = FALSE;
break;
}
++ case GST_EVENT_SEGMENT:
++ gst_event_copy_segment (event, &encoder->segment);
++ break;
+ case GST_EVENT_FLUSH_STOP:
+ gst_segment_init (&encoder->segment, GST_FORMAT_UNDEFINED);
+ break;
case GST_EVENT_EOS:
gst_x264_enc_flush_frames (encoder, TRUE);
break;
pic_in.img.i_csp = X264_CSP_I420;
pic_in.img.i_plane = 3;
for (i = 0; i < 3; i++) {
- pic_in.img.plane[i] = GST_BUFFER_DATA (buf) + encoder->offset[i];
- pic_in.img.i_stride[i] = encoder->stride[i];
+ pic_in.img.plane[i] = GST_VIDEO_FRAME_COMP_DATA (&frame, i);
+ pic_in.img.i_stride[i] = GST_VIDEO_FRAME_COMP_STRIDE (&frame, i);
}
- GST_OBJECT_LOCK (encoder);
- pic_in.i_type = encoder->i_type;
-
- /* Reset encoder forced picture type */
- encoder->i_type = X264_TYPE_AUTO;
- GST_OBJECT_UNLOCK (encoder);
-
+ pic_in.i_type = X264_TYPE_AUTO;
pic_in.i_pts = GST_BUFFER_TIMESTAMP (buf);
ret = gst_x264_enc_encode_frame (encoder, &pic_in, &i_nal, TRUE);
gint i;
#endif
int encoder_return;
- GstFlowReturn ret;
GstClockTime duration;
guint8 *data;
- GstEvent *forcekeyunit_event = NULL;
+ GstEvent *event = NULL;
if (G_UNLIKELY (encoder->x264enc == NULL))
return GST_FLOW_NOT_NEGOTIATED;
encoder_return = x264_encoder_encode (encoder->x264enc,
&nal, i_nal, pic_in, &pic_out);
- if (encoder_return < 0) {
- GST_ELEMENT_ERROR (encoder, STREAM, ENCODE, ("Encode x264 frame failed."),
- ("x264_encoder_encode return code=%d", encoder_return));
- ret = GST_FLOW_ERROR;
- goto out;
- }
+ if (encoder_return < 0)
+ goto encode_failed;
if (!*i_nal) {
- return GST_FLOW_OK;
+ ret = GST_FLOW_OK;
+ goto out;
}
#ifndef X264_ENC_NALS
i_size = 0;
} else {
GST_ELEMENT_ERROR (encoder, STREAM, ENCODE, (NULL),
("Timestamp queue empty."));
- return GST_FLOW_ERROR;
+ ret = GST_FLOW_ERROR;
+ goto out;
}
- if (!send)
- return GST_FLOW_OK;
+ if (!send) {
+ ret = GST_FLOW_OK;
+ goto out;
+ }
- ret = gst_pad_alloc_buffer (encoder->srcpad, GST_BUFFER_OFFSET_NONE,
- i_size, GST_PAD_CAPS (encoder->srcpad), &out_buf);
- if (ret != GST_FLOW_OK)
- goto out;
-
- memcpy (GST_BUFFER_DATA (out_buf), data, i_size);
- GST_BUFFER_SIZE (out_buf) = i_size;
+ out_buf = gst_buffer_new_allocate (NULL, i_size, 0);
+ gst_buffer_fill (out_buf, 0, data, i_size);
/* PTS */
/* FIXME ??: maybe use DTS here, since:
GST_BUFFER_FLAG_SET (out_buf, GST_BUFFER_FLAG_DELTA_UNIT);
}
- GST_OBJECT_LOCK (encoder);
- forcekeyunit_event = encoder->forcekeyunit_event;
- encoder->forcekeyunit_event = NULL;
- GST_OBJECT_UNLOCK (encoder);
- if (forcekeyunit_event) {
- gst_structure_set ((GstStructure *)
- gst_event_get_structure (forcekeyunit_event), "timestamp",
- G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (out_buf), NULL);
- gst_pad_push_event (encoder->srcpad, forcekeyunit_event);
- }
+ if (event)
+ gst_pad_push_event (encoder->srcpad, gst_event_ref (event));
- return gst_pad_push (encoder->srcpad, out_buf);
+ ret = gst_pad_push (encoder->srcpad, out_buf);
+
+ out:
+ if (event)
+ gst_event_unref (event);
+
+ return ret;
+
+ /* ERRORS */
+encode_failed:
+ {
+ GST_ELEMENT_ERROR (encoder, STREAM, ENCODE, ("Encode x264 frame failed."),
+ ("x264_encoder_encode return code=%d", encoder_return));
- return GST_FLOW_ERROR;
++ ret = GST_FLOW_ERROR;
++ goto out;
+ }
}
static void