}
static GstFlowReturn
-gst_mfc_dec_queue_input (GstMFCDec * self, GstBuffer * inbuf)
+gst_mfc_dec_queue_input (GstMFCDec * self, GstVideoCodecFrame * frame)
{
GstFlowReturn ret = GST_FLOW_OK;
gint mfc_ret;
guint8 *mfc_inbuf_data;
gint mfc_inbuf_size;
GstMapInfo map;
+ struct timeval timestamp;
GST_DEBUG_OBJECT (self, "Dequeueing input");
g_assert (mfc_inbuf != NULL);
- if (inbuf) {
- gst_buffer_map (inbuf, &map, GST_MAP_READ);
+ if (frame) {
+ gst_buffer_map (frame->input_buffer, &map, GST_MAP_READ);
mfc_inbuf_data = (guint8 *) mfc_buffer_get_input_data (mfc_inbuf);
g_assert (mfc_inbuf_data != NULL);
memcpy (mfc_inbuf_data, map.data, map.size);
mfc_buffer_set_input_size (mfc_inbuf, map.size);
- gst_buffer_unmap (inbuf, &map);
+ gst_buffer_unmap (frame->input_buffer, &map);
+
+ timestamp.tv_usec = 0;
+ timestamp.tv_sec = frame->system_frame_number;
} else {
GST_DEBUG_OBJECT (self, "Passing EOS input buffer");
mfc_buffer_set_input_size (mfc_inbuf, 0);
+ timestamp.tv_usec = 0;
+ timestamp.tv_sec = -1;
}
- if ((mfc_ret = mfc_dec_enqueue_input (self->context, mfc_inbuf)) < 0)
+ if ((mfc_ret =
+ mfc_dec_enqueue_input (self->context, mfc_inbuf, ×tamp)) < 0)
goto enqueue_error;
done:
GST_ELEMENT_ERROR (self, STREAM, FORMAT, ("Too large input frames"),
("Maximum size %d, got %d", mfc_inbuf_size, map.size));
ret = GST_FLOW_ERROR;
- gst_buffer_unmap (inbuf, &map);
+ gst_buffer_unmap (frame->input_buffer, &map);
goto done;
}
}
}
-static GstVideoCodecFrame *
-gst_mfc_dec_get_earliest_frame (GstMFCDec * self)
-{
- GstVideoCodecFrame *frame = NULL;
- GList *frames, *l;
-
- frames = gst_video_decoder_get_frames (GST_VIDEO_DECODER (self));
-
- for (l = frames; l; l = l->next) {
- GstVideoCodecFrame *tmp = (GstVideoCodecFrame *) l->data;
-
- if (!frame) {
- frame = tmp;
- } else if (frame->pts > tmp->pts) {
- gst_video_codec_frame_unref (frame);
- frame = tmp;
- } else {
- gst_video_codec_frame_unref (tmp);
- }
- }
-
- g_list_free (frames);
-
- return frame;
-}
-
static gboolean
gst_mfc_dec_negotiate (GstVideoDecoder * decoder)
{
gint64 deadline;
Fimc *fimc = NULL;
GstVideoFrame vframe;
+ struct timeval timestamp;
if (!self->initialized) {
GST_DEBUG_OBJECT (self, "Initializing decoder");
state = gst_video_decoder_get_output_state (GST_VIDEO_DECODER (self));
}
- if ((mfc_ret = mfc_dec_dequeue_output (self->context, &mfc_outbuf)) < 0) {
+ if ((mfc_ret =
+ mfc_dec_dequeue_output (self->context, &mfc_outbuf,
+ ×tamp)) < 0) {
if (mfc_ret == -2) {
GST_DEBUG_OBJECT (self, "Timeout dequeueing output, trying again");
- mfc_ret = mfc_dec_dequeue_output (self->context, &mfc_outbuf);
+ mfc_ret =
+ mfc_dec_dequeue_output (self->context, &mfc_outbuf, ×tamp);
}
if (mfc_ret < 0)
g_assert (mfc_outbuf != NULL);
- /* FIXME: Replace this by gst_video_decoder_get_frame() with an ID */
- frame = gst_mfc_dec_get_earliest_frame (self);
+ frame = NULL;
+ if (timestamp.tv_sec != -1)
+ frame =
+ gst_video_decoder_get_frame (GST_VIDEO_DECODER (self),
+ timestamp.tv_sec);
if (frame) {
deadline =
GST_DEBUG_OBJECT (self, "Handling frame");
- /* FIXME: Would be good to assign an ID to input frames */
- if (frame->pts == GST_CLOCK_TIME_NONE) {
- GST_ERROR_OBJECT (self, "Only PTS timestamped streams supported so far");
- gst_video_codec_frame_unref (frame);
- return GST_FLOW_ERROR;
- }
-
- if ((ret =
- gst_mfc_dec_queue_input (self, frame->input_buffer)) != GST_FLOW_OK) {
+ if ((ret = gst_mfc_dec_queue_input (self, frame)) != GST_FLOW_OK) {
gst_video_codec_frame_unref (frame);
return ret;
}
free(ctx);
}
-int mfc_dec_enqueue_input(struct mfc_dec_context *ctx, struct mfc_buffer *buffer)
+int mfc_dec_enqueue_input(struct mfc_dec_context *ctx, struct mfc_buffer *buffer, struct timeval *timestamp)
{
struct v4l2_plane planes[NUM_INPUT_PLANES] = {
[0] = {
},
};
+ if (timestamp)
+ qbuf.timestamp = *timestamp;
+
if (ioctl(ctx->fd, VIDIOC_QBUF, &qbuf) < 0) {
GST_ERROR ("Enqueuing of input buffer %d failed; prev state: %d",
buffer->index, buffer->state);
return 0;
}
-int mfc_dec_dequeue_output(struct mfc_dec_context *ctx, struct mfc_buffer **buffer)
+int mfc_dec_dequeue_output(struct mfc_dec_context *ctx, struct mfc_buffer **buffer, struct timeval *timestamp)
{
int i;
struct v4l2_plane planes[NUM_OUTPUT_PLANES];
ctx->output_buffer[qbuf.index].plane[i].bytesused = qbuf.m.planes[i].bytesused;
*buffer = &(ctx->output_buffer[qbuf.index]);
+
+ if (timestamp)
+ *timestamp = qbuf.timestamp;
+
ctx->output_frames_available--;
return 0;
}
struct mfc_buffer *buffer;
/* Make sure there is room for the decode to finish */
if (mfc_dec_output_available(ctx) || force_dequeue_output) {
- if (mfc_dec_dequeue_output(ctx, &buffer) < 0)
+ if (mfc_dec_dequeue_output(ctx, &buffer, NULL) < 0)
return -1;
if (mfc_dec_enqueue_output(ctx, buffer) < 0)
return -1;