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 "gstmaruinterface.h"
42 #include "gstmarudevice.h"
44 static GStaticMutex gst_avcodec_mutex = G_STATIC_MUTEX_INIT;
46 #define CODEC_DEVICE_MEM_SIZE 32 * 1024 * 1024
48 gpointer device_mem = NULL;
53 gst_maru_codec_device_open (CodecDevice *dev, int media_type)
58 CODEC_LOG (DEBUG, "enter: %s\n", __func__);
60 CODEC_LOG (INFO, "before opening a device. %d\n", dev->fd);
61 if ((fd = open(CODEC_DEV, O_RDWR)) < 0) {
62 perror("Failed to open codec device.");
68 dev->buf_size = CODEC_DEVICE_MEM_SIZE;
71 CODEC_LOG (INFO, "succeeded to open %s. %d.\n", CODEC_DEV, fd);
72 dev->mem_info.index = dev->buf_size;
74 CODEC_LOG (DEBUG, "before mmap. buf_size: %d\n", dev->buf_size);
76 g_static_mutex_lock (&gst_avcodec_mutex);
78 device_mem = mmap (NULL, CODEC_DEVICE_MEM_SIZE, PROT_READ | PROT_WRITE,
80 if (device_mem == MAP_FAILED) {
81 perror("Failed to map device memory of codec.");
87 g_static_mutex_unlock (&gst_avcodec_mutex);
89 dev->buf = device_mem;
91 CODEC_LOG (INFO, "succeeded to map device memory: %p.\n", dev->buf);
95 CODEC_LOG (DEBUG, "leave: %s\n", __func__);
101 gst_maru_codec_device_close (CodecDevice *dev)
104 void *mmapbuf = NULL;
106 CODEC_LOG (DEBUG, "enter: %s\n", __func__);
110 GST_ERROR("Failed to get %s fd.\n", CODEC_DEV);
114 ioctl(fd, CODEC_CMD_RELEASE_BUFFER, &dev->mem_info.offset);
116 g_static_mutex_lock (&gst_avcodec_mutex);
119 CODEC_LOG (INFO, "Release memory region of %p.\n", device_mem);
120 if (munmap(device_mem, CODEC_DEVICE_MEM_SIZE) != 0) {
121 CODEC_LOG(ERR, "Failed to release memory region of %s.\n", CODEC_DEV);
126 g_static_mutex_unlock (&gst_avcodec_mutex);
130 CODEC_LOG (INFO, "close %s.\n", CODEC_DEV);
131 if (close(fd) != 0) {
132 GST_ERROR("Failed to close %s. fd: %d\n", CODEC_DEV, fd);
135 CODEC_LOG (DEBUG, "leave: %s\n", __func__);
141 gst_maru_avcodec_open (CodecContext *ctx,
148 if (gst_maru_codec_device_open (dev, codec->media_type) < 0) {
149 perror("failed to open device.\n");
153 g_static_mutex_lock (&gst_avcodec_mutex);
154 ret = codec_init (ctx, codec, dev);
155 g_static_mutex_unlock (&gst_avcodec_mutex);
161 gst_maru_avcodec_close (CodecContext *ctx, CodecDevice *dev)
165 CODEC_LOG (DEBUG, "gst_maru_avcodec_close\n");
167 g_static_mutex_lock (&gst_avcodec_mutex);
168 codec_deinit (ctx, dev);
169 g_static_mutex_unlock (&gst_avcodec_mutex);
171 ret = gst_maru_codec_device_close (dev);