As flushing buffer while decoding video, it makes internal buffers of avcodec flush.
If it is not used properly, it might cause an error during seeking operation.
Change-Id: I967e566527bc5d18c88b91f0cfcc0e58cc1e120d
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
+* Fri Oct 18 02:41:49 UTC 2013 Kitae Kim <kt920.kim@samsung.com>
+- added flush_buffer routine in decoder.
+
* Tue Oct 15 04:51:30 UTC 2013 Kitae Kim <kt920.kim@samsung.com>
- fixed prevent issues.
Name: gst-plugins-emulator
-Version: 0.1.10
+Version: 0.1.11
Release: 2
Summary: GStreamer Streaming-media framework plug-in for Tizen emulator.
Group: TO_BE/FILLED_IN
CODEC_ENCODE_AUDIO,
CODEC_PICTURE_COPY,
CODEC_DEINIT,
+ CODEC_FLUSH_BUFFERS,
};
-#if 0
-enum CODEC_IO_CMD {
- CODEC_CMD_COPY_TO_DEVICE_MEM = 5,
- CODEC_CMD_COPY_FROM_DEVICE_MEM,
- CODEC_CMD_GET_VERSION = 20,
- CODEC_CMD_GET_ELEMENT,
- CODEC_CMD_GET_CONTEXT_INDEX,
- CODEC_CMD_SECURE_MEMORY = 30,
- CODEC_CMD_RELEASE_MEMORY,
- CODEC_CMD_USE_DEVICE_MEM,
- CODEC_CMD_REQ_FROM_SMALL_MEMORY,
- CODEC_CMD_REQ_FROM_MEDIUM_MEMORY,
- CODEC_CMD_REQ_FROM_LARGE_MEMORY,
- CODEC_CMD_S_SECURE_BUFFER,
- CODEC_CMD_M_SECURE_BUFFER,
- CODEC_CMD_L_SECURE_BUFFER,
-};
-#endif
-
enum CODEC_IO_CMD {
CODEC_CMD_GET_VERSION = 20,
CODEC_CMD_GET_ELEMENT,
CODEC_CMD_RELEASE_BUFFER,
};
-
enum CODEC_MEDIA_TYPE {
AVMEDIA_TYPE_UNKNOWN = -1,
AVMEDIA_TYPE_VIDEO,
// if (marudec->waiting_for_key) {
if (0) {
res = FALSE;
- } else {
}
+#if 0
+ else {
+ }
+#endif
GstClockTime stream_time, jitter;
GstMessage *qos_msg;
oclass = (GstMaruDecClass *) (G_OBJECT_GET_CLASS (marudec));
- // TODO: drain
+ CODEC_LOG (DEBUG, "drain frame\n");
#if 1
{
gint have_data, len, try = 0;
break;
case GST_EVENT_FLUSH_STOP:
{
-#if 0
if (marudec->opened) {
- // TODO: what does avcodec_flush_buffers do?
- maru_avcodec_flush_buffers (marudec->context, marudec->dev);
+ codec_flush_buffers (marudec->context, marudec->dev);
}
-#endif
+
gst_marudec_reset_ts (marudec);
gst_marudec_reset_qos (marudec);
#if 0
return GST_FLOW_ERROR;
}
- CODEC_LOG (DEBUG, "outbuf size of decoded video: %d\n", pict_size);
+ CODEC_LOG (DEBUG, "outbuf size of decoded video: %d\n", pict_size);
- if (pict_size < (256 * 1024)) {
- /* GstPadBufferAllocFunction is mostly overridden by elements that can
- * provide a hardware buffer in order to avoid additional memcpy operations.
- */
+ if (pict_size < (256 * 1024)) {
+ /* GstPadBufferAllocFunction is mostly overridden by elements that can
+ * provide a hardware buffer in order to avoid additional memcpy operations.
+ */
gst_pad_set_bufferalloc_function(
GST_PAD_PEER(marudec->srcpad),
(GstPadBufferAllocFunction) codec_buffer_alloc);
- } else {
- CODEC_LOG (DEBUG, "request a large size of memory\n");
- }
+ } else {
+ CODEC_LOG (DEBUG, "request large size of memory. pict_size: %d\n", pict_size);
+ }
ret = gst_pad_alloc_buffer_and_set_caps (marudec->srcpad,
GST_BUFFER_OFFSET_NONE, pict_size,
codec_decode_video (marudec->context, data, size,
dec_info->idx, in_offset, outbuf,
&have_data, marudec->dev);
-
+#if 0
+ // skip_frame
if (!decode) {
- // skip_frame
}
-
+#endif
GST_DEBUG_OBJECT (marudec, "after decode: len %d, have_data %d",
len, have_data);
#endif
if (len < 0 || have_data <= 0) {
+// if (len < 0) { // have_data <= 0) {
GST_DEBUG_OBJECT (marudec, "return flow %d, out %p, len %d",
*ret, *outbuf, len);
+
+ CODEC_LOG (DEBUG,
+ "return flow %d, out %p, len %d, have_data: %d\n",
+ *ret, *outbuf, len, have_data);
+
return len;
}
discont = GST_BUFFER_IS_DISCONT (buffer);
-// FIXME
+ // FIXME
if (G_UNLIKELY (discont)) {
GST_DEBUG_OBJECT (marudec, "received DISCONT");
gst_marudec_drain (marudec);
// gst_marudec_flush_pcache (marudec);
-// maru_avcodec_flush buffers (marudec->context, marudec->dev);
+ codec_flush_buffers (marudec->context, marudec->dev);
marudec->discont = TRUE;
gst_marudec_reset_ts (marudec);
}
{
CodecIOParams ioparam;
+ CODEC_LOG (DEBUG, "enter: %s\n", __func__);
+
memset(&ioparam, 0, sizeof(ioparam));
ioparam.api_index = api_index;
ioparam.ctx_index = ctx_index;
ioparam.mem_offset = mem_offset;
if (write (fd, &ioparam, 1) < 0) {
- fprintf (stderr, "%s, failed to write copy data.\n", __func__);
+ CODEC_LOG (ERR, "failed to write input data\n");
}
+
+ CODEC_LOG (DEBUG, "leave: %s\n", __func__);
}
static struct mem_info
static void
release_device_mem (gpointer start)
{
- int ret;
+ int ret;
uint32_t offset = start - device_mem;
CODEC_LOG (DEBUG, "enter: %s\n", __func__);
CODEC_LOG (DEBUG, "leave: %s\n", __func__);
}
+void
+codec_flush_buffers (CodecContext *ctx, CodecDevice *dev)
+{
+ int fd;
+ void *mmapbuf = NULL;
+
+ CODEC_LOG (DEBUG, "enter: %s\n", __func__);
+
+ fd = dev->fd;
+ if (fd < 0) {
+ GST_ERROR ("failed to get %s fd.\n", CODEC_DEV);
+ return;
+ }
+
+ mmapbuf = dev->buf;
+ if (!mmapbuf) {
+ GST_ERROR ("failed to get mmaped memory address.\n");
+ return;
+ }
+
+ CODEC_LOG (DEBUG, "flush buffers. context index: %d\n", ctx->index);
+ _codec_write_to_qemu (ctx->index, CODEC_FLUSH_BUFFERS, 0, fd);
+
+ CODEC_LOG (DEBUG, "leave: %s\n", __func__);
+}
+
int
codec_decode_video (CodecContext *ctx, uint8_t *in_buf, int in_size,
gint idx, gint64 in_offset, GstBuffer **out_buf,
_codec_decode_video_inbuf (in_buf, in_size, mmapbuf + mem_offset);
dev->mem_info.offset = mem_offset;
+
_codec_write_to_qemu (ctx->index, CODEC_DECODE_VIDEO, mem_offset, fd);
// after decoding video, no need to get outbuf.
CODEC_LOG (DEBUG, "pict_size: %d\n", pict_size);
-// if (pict_size < MEDIUM_BUFFER) {
if (pict_size < (SMALL_BUFFER)) {
dev->mem_info.offset = (uint32_t)pict - (uint32_t)mmapbuf;
CODEC_LOG (DEBUG, "pict: %p , device_mem: %p\n", pict, mmapbuf);
_codec_write_to_qemu (ctx->index, CODEC_PICTURE_COPY,
dev->mem_info.offset, fd);
-// if (pict_size < MEDIUM_BUFFER) {
if (pict_size < SMALL_BUFFER) {
CODEC_LOG (DEBUG,
"set the mem_offset as outbuf: 0x%x\n", dev->mem_info.offset);
ret = ioctl (fd, CODEC_CMD_USE_DEVICE_MEM, &(dev->mem_info.offset));
if (ret < 0) {
- // FIXME:
+ // FIXME:
}
} else if (pict_size < MEDIUM_BUFFER) {
uint32_t mem_offset = 0;
- CODEC_LOG (DEBUG, "require to use medium size of memory\n");
+ CODEC_LOG (DEBUG, "need to use medium size of memory\n");
ret = ioctl (fd, CODEC_CMD_GET_DATA_FROM_MEDIUM_BUFFER, &mem_offset);
if (ret < 0) {
ret = ioctl(fd, CODEC_CMD_RELEASE_BUFFER, &mem_offset);
if (ret < 0) {
- CODEC_LOG (ERR, "failed release used memory\n");
+ CODEC_LOG (ERR, "failed to release used memory\n");
}
} else {
uint32_t mem_offset = 0;
- CODEC_LOG (DEBUG, "require to use large size of memory\n");
+ CODEC_LOG (DEBUG, "need to use large size of memory\n");
ret = ioctl (fd, CODEC_CMD_GET_DATA_FROM_LARGE_BUFFER, &mem_offset);
if (ret < 0) {
ret = ioctl(fd, CODEC_CMD_RELEASE_BUFFER, &mem_offset);
if (ret < 0) {
- CODEC_LOG (ERR, "failed release used memory\n");
+ CODEC_LOG (ERR, "failed to release used memory\n");
}
}
codec_picture_copy (CodecContext *ctx, uint8_t *pict,
uint32_t pict_size, CodecDevice *dev);
+void
+codec_flush_buffers (CodecContext *ctx, CodecDevice *dev);
+
GstFlowReturn
codec_buffer_alloc (GstPad *pad, guint64 offset,
guint size, GstCaps *caps, GstBuffer **buf);