const GstTSInfo *dec_info, gint64 in_offset, GstFlowReturn *ret);
static gboolean gst_marudec_open (GstMaruDec *marudec);
-static int gst_marudec_close (GstMaruDec *marudec);
+static void gst_marudec_close (GstMaruDec *marudec);
static const GstTSInfo *
return TRUE;
} else {
if (diff >= 0) {
-// if (marudec->waiting_for_key) {
if (0) {
res = FALSE;
}
-#if 0
- else {
- }
-#endif
GstClockTime stream_time, jitter;
GstMessage *qos_msg;
srccaps = gst_maru_codectype_to_audio_caps (NULL, codec->name, FALSE, codec);
break;
default:
- GST_LOG("unknown media type.\n");
+ GST_LOG("unknown media type");
break;
}
marudec->queued = NULL;
gst_segment_init (&marudec->segment, GST_FORMAT_TIME);
-
- marudec->dev = g_malloc0 (sizeof(CodecDevice));
- if (!marudec->dev) {
- GST_ERROR_OBJECT (marudec, "failed to allocate memory for CodecDevice");
- }
}
static void
{
GstMaruDec *marudec = (GstMaruDec *) object;
- if (marudec->context) {
- g_free (marudec->context);
- marudec->context = NULL;
- }
+ GST_DEBUG_OBJECT (marudec, "finalize object and release context");
+ g_free (marudec->context);
+ marudec->context = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
case GST_EVENT_FLUSH_STOP:
{
if (marudec->opened) {
+ GST_DEBUG_OBJECT (marudec, "flush decoded buffers");
interface->flush_buffers (marudec->context, marudec->dev);
}
gst_marudec_reset_ts (marudec);
gst_marudec_reset_qos (marudec);
-#if 0
- gst_marudec_flush_pcache (marudec);
- marudec->waiting_for_key = TRUE;
-#endif
gst_segment_init (&marudec->segment, GST_FORMAT_TIME);
clear_queued (marudec);
}
return ret;
}
- if (marudec->context->codec) {
+ if (marudec->opened) {
gst_marudec_drain (marudec);
}
GST_OBJECT_UNLOCK (marudec);
gst_marudec_drain (marudec);
GST_OBJECT_LOCK (marudec);
- gst_marudec_close (marudec);
}
+ gst_marudec_close (marudec);
GST_LOG_OBJECT (marudec, "size %dx%d", marudec->context->video.width,
marudec->context->video.height);
GST_DEBUG_OBJECT (marudec, "sink caps have pixel-aspect-ratio of %d:%d",
gst_value_get_fraction_numerator (par),
gst_value_get_fraction_denominator (par));
-
-#if 0 // TODO
- if (marudec->par) {
- g_free(marudec->par);
- }
- marudec->par = g_new0 (GValue, 1);
- gst_value_init_and_copy (marudec->par, par);
-#endif
}
fps = gst_structure_get_value (structure, "framerate");
if (!gst_marudec_open (marudec)) {
GST_DEBUG_OBJECT (marudec, "Failed to open");
-#if 0
- if (marudec->par) {
- g_free(marudec->par);
- marudec->par = NULL;
- }
-#endif
GST_OBJECT_UNLOCK (marudec);
gst_object_unref (marudec);
oclass = (GstMaruDecClass *) (G_OBJECT_GET_CLASS (marudec));
+ marudec->dev = g_try_malloc0 (sizeof(CodecDevice));
if (!marudec->dev) {
+ GST_ERROR_OBJECT (marudec, "failed to allocate memory for CodecDevice");
return FALSE;
}
- if (gst_maru_avcodec_open (marudec->context,
- oclass->codec, marudec->dev) < 0) {
- gst_marudec_close (marudec);
+ if (gst_maru_avcodec_open (marudec->context, oclass->codec, marudec->dev) < 0) {
+ g_free(marudec->dev);
+ marudec->dev = NULL;
GST_ERROR_OBJECT (marudec,
"maru_%sdec: Failed to open codec", oclass->codec->name);
return FALSE;
return TRUE;
}
-static int
+static void
gst_marudec_close (GstMaruDec *marudec)
{
- int ret = 0;
+ if (!marudec->opened) {
+ GST_DEBUG_OBJECT (marudec, "not opened yet");
+ return;
+ }
- if (marudec->context->codecdata) {
+ if (marudec->context) {
g_free(marudec->context->codecdata);
marudec->context->codecdata = NULL;
}
if (!marudec->dev) {
- return -1;
+ return;
}
- ret = gst_maru_avcodec_close (marudec->context, marudec->dev);
+ gst_maru_avcodec_close (marudec->context, marudec->dev);
+ marudec->opened = FALSE;
if (marudec->dev) {
g_free(marudec->dev);
marudec->dev = NULL;
}
-
- return ret;
}
GST_TYPE_FRACTION, marudec->format.video.fps_n,
marudec->format.video.fps_d, NULL);
}
-#if 0
- gst_marudec_add_pixel_aspect_ratio (marudec,
- gst_caps_get_structure (caps, 0));
-#endif
}
}
break;
decode = gst_marudec_do_qos (marudec, dec_info->timestamp, &mode_switch);
- if (decode) {
- // FIXME
- }
-
GST_DEBUG_OBJECT (marudec, "decode video: input buffer size %d", size);
len = interface->decode_video (marudec, data, size,
}
*ret = get_output_buffer (marudec, outbuf);
-
if (G_UNLIKELY (*ret != GST_FLOW_OK)) {
GST_DEBUG_OBJECT (marudec, "no output buffer");
len = -1;
GST_DEBUG_OBJECT (marudec, "return flow %d, out %p, len %d",
- *ret, *outbuf, len);
+ *ret, *outbuf, len);
return len;
}
return len;
}
- // GST_BUFFER_SIZE (*outbuf) = have_data;
GST_BUFFER_SIZE (*outbuf) = len;
if (GST_CLOCK_TIME_IS_VALID (dec_info->timestamp)) {
dec_info, &outbuf, ret);
if (outbuf == NULL && marudec->discont) {
GST_DEBUG_OBJECT (marudec, "no buffer but keeping timestamp");
-// marudec->clear_ts = FALSE;
}
break;
default:
}
discont = GST_BUFFER_IS_DISCONT (buffer);
-
- // FIXME
if (G_UNLIKELY (discont)) {
GST_DEBUG_OBJECT (marudec, "received DISCONT");
gst_marudec_drain (marudec);
-// gst_marudec_flush_pcache (marudec);
interface->flush_buffers (marudec->context, marudec->dev);
marudec->discont = TRUE;
gst_marudec_reset_ts (marudec);
}
-// marudec->clear_ts = TRUE;
oclass = (GstMaruDecClass *) (G_OBJECT_GET_CLASS (marudec));
-#if 0
- if (G_UNLIKELY (marudec->waiting_for_key)) {
- if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT) &&
- oclass->codec->media_type != AVMEDIA_TYPE_AUDIO) {
- // skip_keyframe
- }
- marudec->waiting_for_key = FALSE;
- }
-
- if (marudec->pcache) {
- GST_LOG_OBJECT (marudec, "join parse cache");
- buffer = gst_buffer_join (marudec->pcache, buffer);
- marudec->pcache = NULL;
- }
-#endif
in_timestamp = GST_BUFFER_TIMESTAMP (buffer);
in_duration = GST_BUFFER_DURATION (buffer);
in_offset = GST_BUFFER_OFFSET (buffer);
in_info = gst_ts_info_store (marudec, in_timestamp, in_duration, in_offset);
-
-#if 0
- if (in_timestamp != -1) {
- if (!marudec->reordered_in && marudec->last_in != -1) {
- if (in_timestamp < marudec->last_in) {
- GST_LOG_OBJECT (marudec, "detected reordered input timestamps");
- marudec->reordered_in = TRUE;
- marudec->last_diff = GST_CLOCK_TIME_NONE;
- } else if (in_timestamp > marudec->last_in) {
- GstClockTime diff;
- diff = in_timestamp - marudec->last_in;
- if (marudec->last_frames) {
- diff /= marudec->last_frames;
- }
-
- GST_LOG_OBJECT (marudec, "estimated duration %" GST_TIME_FORMAT " %u",
- GST_TIME_ARGS (diff), marudec->last_frames);
-
- marudec->last_diff = diff;
- }
- }
- marudec->last_in = in_timestamp;
- marudec->last_frames;
- }
-#endif
-
GST_LOG_OBJECT (marudec,
"Received new data of size %u, offset: %" G_GUINT64_FORMAT ", ts:%"
GST_TIME_FORMAT ", dur: %" GST_TIME_FORMAT ", info %d",
gst_marudec_frame (marudec, in_buf, in_size, &have_data, dec_info, in_offset, &ret);
-#if 0
- if (marudec->clear_ts) {
- in_timestamp = GST_CLOCK_TIME_NONE;
- in_duration = GST_CLOCK_TIME_NONE;
- in_offset = GST_BUFFER_OFFSET_NONE;
- in_info = GST_TS_INFO_NONE;
- } else {
- marudec->clear_ts = TRUE;
- }
-#endif
-
gst_buffer_unref (buffer);
return ret;
CodecIOParams ioparam = { 0, };
int ret = -1;
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
ioparam.api_index = api_index;
ioparam.ctx_index = ctx_index;
ioparam.mem_offset = mem_offset;
ret = ioctl(fd, CODEC_CMD_PUT_DATA_INTO_BUFFER, buffer_id);
}
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
-
return ret;
}
int ret = 0;
CodecBufferId opaque;
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
opaque.buffer_index = ctx_id;
opaque.buffer_size = buf_size;
*buffer = (gpointer)((uint32_t)device_mem + opaque.buffer_size);
GST_DEBUG ("device_mem %p, offset_size 0x%x", device_mem, opaque.buffer_size);
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
-
return ret;
}
int ret;
uint32_t offset = start - device_mem;
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
GST_DEBUG ("release device_mem start: %p, offset: 0x%x", start, offset);
ret = ioctl (fd, CODEC_CMD_RELEASE_BUFFER, &offset);
if (ret < 0) {
- GST_ERROR ("failed to release buffer\n");
+ GST_ERROR ("failed to release buffer");
}
-
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
}
static void
codec_buffer_free (gpointer start)
{
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
release_device_mem (device_fd, start);
-
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
}
static GstFlowReturn
CodecContext *ctx;
CodecDevice *dev;
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
*buf = gst_buffer_new ();
marudec = (GstMaruDec *)gst_pad_get_element_private(pad);
gst_buffer_set_caps (*buf, caps);
}
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
-
return GST_FLOW_OK;
}
CodecBufferId opaque;
int ret;
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
if (ioctl(dev->fd, CODEC_CMD_GET_CONTEXT_INDEX, &ctx->index) < 0) {
GST_ERROR ("failed to get a context index");
return -1;
release_device_mem(dev->fd, device_mem + opaque.buffer_size);
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
-
return opened;
}
static void
codec_deinit (CodecContext *ctx, CodecDevice *dev)
{
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
GST_INFO ("close context %d", ctx->index);
_codec_invoke_qemu (ctx->index, CODEC_DEINIT, 0, dev->fd, NULL);
-
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
}
static void
codec_flush_buffers (CodecContext *ctx, CodecDevice *dev)
{
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
GST_DEBUG ("flush buffers of context: %d", ctx->index);
_codec_invoke_qemu (ctx->index, CODEC_FLUSH_BUFFERS, 0, dev->fd, NULL);
-
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
}
static int
gpointer buffer = NULL;
CodecBufferId opaque = { 0, };
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer);
if (ret < 0) {
GST_ERROR ("failed to get available memory to write inbuf");
ret, *out_buf, len);
}
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
-
return len;
}
gpointer buffer = NULL;
CodecBufferId opaque;
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer);
if (ret < 0) {
GST_ERROR ("failed to get available memory to write inbuf");
release_device_mem(dev->fd, device_mem + opaque.buffer_size);
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
-
return len;
}
gpointer buffer = NULL;
CodecBufferId opaque;
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer);
if (ret < 0) {
GST_ERROR ("failed to small size of buffer");
release_device_mem(dev->fd, device_mem + opaque.buffer_size);
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
-
return len;
}
gpointer buffer = NULL;
CodecBufferId opaque;
- CODEC_LOG (DEBUG, "enter: %s\n", __func__);
-
ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer);
if (ret < 0) {
return -1;
release_device_mem(dev->fd, device_mem + opaque.buffer_size);
- CODEC_LOG (DEBUG, "leave: %s\n", __func__);
-
return ret;
}