2 * GStreamer codec plugin for Tizen Emulator.
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
7 * KiTae Kim <kt920.kim@samsung.com>
8 * SeokYeon Hwang <syeon.hwang@samsung.com>
9 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
37 #include <sys/ioctl.h>
41 #include "gstemulapi.h"
42 #include "gstemuldev.h"
46 gst_emul_codec_device_open (CodecDevice *dev)
49 // CodecDevMemInfo mem_info;
52 printf("enter: %s\n", __func__);
54 if ((fd = open(CODEC_DEV, O_RDWR)) < 0) {
55 perror("Failed to open codec device.");
59 // GST_DEBUG("succeeded to open %s. %d.\n", CODEC_DEV, fd);
60 printf("succeeded to open %s. %d.\n", CODEC_DEV, fd);
61 // memset(&mem_info, 0x00, sizeof(CodecDevMemInfo));
62 dev->mem_info.index = dev->buf_size;
64 ioctl(fd, CODEC_CMD_GET_DEVICE_MEM_INFO, &dev->mem_info);
67 printf("mem type: %d, index: %d, offset: %d\n",
68 dev->mem_info.type, dev->mem_info.index, dev->mem_info.offset);
71 mmapbuf = mmap (NULL, dev->buf_size, PROT_READ | PROT_WRITE,
72 MAP_SHARED, fd, dev->mem_info.offset);
74 perror("Failed to map device memory of codec.");
79 // GST_DEBUG("succeeded to map device memory.\n");
80 printf("succeeded to map device memory: %p.\n", mmapbuf);
84 printf("leave: %s\n", __func__);
90 gst_emul_codec_device_close (CodecDevice *dev)
95 printf("enter: %s\n", __func__);
99 GST_ERROR("Failed to get %s fd.\n", CODEC_DEV);
105 GST_ERROR("Failed to get mmaped memory address.\n");
109 // GST_DEBUG("Release memory region of %s.\n", CODEC_DEV);
110 CODEC_LOG(LOG, "Release memory region of %s.\n", CODEC_DEV);
112 if (munmap(mmapbuf, dev->buf_size) != 0) {
113 GST_ERROR("Failed to release memory region of %s.\n", CODEC_DEV);
117 ioctl(fd, CODEC_CMD_RELEASE_DEVICE_MEM, &dev->mem_info);
119 // GST_DEBUG("close %s.\n", CODEC_DEV);
120 CODEC_LOG(LOG, "close %s.\n", CODEC_DEV);
122 if (close(fd) != 0) {
123 GST_ERROR("Failed to close %s. fd: %d\n", CODEC_DEV, fd);
126 printf("leave: %s\n", __func__);
131 static GStaticMutex gst_avcodec_mutex = G_STATIC_MUTEX_INIT;
134 gst_emul_avcodec_open (CodecContext *ctx, CodecElement *codec, CodecDevice *dev)
138 g_static_mutex_lock (&gst_avcodec_mutex);
140 if (gst_emul_codec_device_open (dev) < 0) {
141 perror("failed to open device.\n");
144 ret = emul_avcodec_init (ctx, codec, dev);
145 g_static_mutex_unlock (&gst_avcodec_mutex);
151 gst_emul_avcodec_close (CodecContext *ctx, CodecDevice *dev)
155 g_static_mutex_lock (&gst_avcodec_mutex);
157 printf ("gst_emul_avcodec_close\n");
158 emul_avcodec_deinit (ctx, dev);
160 ret = gst_emul_codec_device_close (dev);
161 g_static_mutex_unlock (&gst_avcodec_mutex);