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 GMutex gst_avcodec_mutex;
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)
57 CODEC_LOG (DEBUG, "enter: %s\n", __func__);
59 CODEC_LOG (INFO, "before opening a device. %d\n", dev->fd);
60 if ((fd = open(CODEC_DEV, O_RDWR)) < 0) {
61 perror("Failed to open codec device.");
67 dev->buf_size = CODEC_DEVICE_MEM_SIZE;
70 CODEC_LOG (INFO, "succeeded to open %s. %d.\n", CODEC_DEV, fd);
71 dev->mem_info.index = dev->buf_size;
73 CODEC_LOG (DEBUG, "before mmap. buf_size: %d\n", dev->buf_size);
75 g_mutex_lock (&gst_avcodec_mutex);
77 device_mem = mmap (NULL, CODEC_DEVICE_MEM_SIZE, PROT_READ | PROT_WRITE,
79 if (device_mem == MAP_FAILED) {
80 perror("Failed to map device memory of codec.");
82 g_mutex_unlock (&gst_avcodec_mutex);
87 g_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)
105 CODEC_LOG (DEBUG, "enter: %s\n", __func__);
109 GST_ERROR("Failed to get %s fd.\n", CODEC_DEV);
113 ioctl(fd, CODEC_CMD_RELEASE_BUFFER, &dev->mem_info.offset);
115 g_mutex_lock (&gst_avcodec_mutex);
118 CODEC_LOG (INFO, "Release memory region of %p.\n", device_mem);
119 if (munmap(device_mem, CODEC_DEVICE_MEM_SIZE) != 0) {
120 CODEC_LOG(ERR, "Failed to release memory region of %s.\n", CODEC_DEV);
125 g_mutex_unlock (&gst_avcodec_mutex);
129 CODEC_LOG (INFO, "close %s.\n", CODEC_DEV);
130 if (close(fd) != 0) {
131 GST_ERROR("Failed to close %s. fd: %d\n", CODEC_DEV, fd);
134 CODEC_LOG (DEBUG, "leave: %s\n", __func__);
140 gst_maru_avcodec_open (CodecContext *ctx,
147 if (gst_maru_codec_device_open (dev, codec->media_type) < 0) {
148 perror("failed to open device.\n");
152 g_mutex_lock (&gst_avcodec_mutex);
153 ret = codec_init (ctx, codec, dev);
154 g_mutex_unlock (&gst_avcodec_mutex);
160 gst_maru_avcodec_close (CodecContext *ctx, CodecDevice *dev)
164 CODEC_LOG (DEBUG, "gst_maru_avcodec_close\n");
166 g_mutex_lock (&gst_avcodec_mutex);
167 codec_deinit (ctx, dev);
168 g_mutex_unlock (&gst_avcodec_mutex);
170 ret = gst_maru_codec_device_close (dev);