implemented decoding audio part, but needs to improve.
[platform/adaptation/emulator/gst-plugins-emulator.git] / src / gstemulcommon.h
1 /*
2  * GStreamer codec plugin for Tizen Emulator.
3  *
4  * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  * KiTae Kim <kt920.kim@samsung.com>
8  * SeokYeon Hwang <syeon.hwang@samsung.com>
9  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
10  *
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.
15  *
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.
20  *
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.
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  *
29  */
30
31 #ifndef __GST_EMUL_H__
32 #define __GST_EMUL_H__
33
34 #include <stdint.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <unistd.h>
39 #include <fcntl.h>
40 #include <sys/ioctl.h>
41 #include <sys/mman.h>
42 #include <glib.h>
43 #include <gst/gst.h>
44 #include "pixfmt.h"
45
46 GST_DEBUG_CATEGORY_EXTERN (emul_debug);
47 #define GST_CAT_DEFAULT emul_debug
48
49 G_BEGIN_DECLS
50
51 #define CODEC_DEV   "/dev/newcodec"
52 #define CODEC_VER   10
53
54 #define CODEC_PARAM_INIT(var) \
55   memset (&var, 0x00, sizeof(var))
56
57 #define CODEC_WRITE_TO_QEMU(fd, var, size) \
58   if (write (fd, var, size) < 0) { \
59     printf ("[%d] failed to copy data.\n", __LINE__); \
60   }
61
62 #define FF_INPUT_BUFFER_PADDING_SIZE  8
63 #define FF_MAX_AUDIO_FRAME_SIZE     192000 // 1 second of 48khz 32bit audio
64 #define FF_MIN_BUFFER_SIZE        16384
65
66 typedef struct _CodecIOParams {
67   uint32_t  api_index;
68   uint32_t  ctx_index;
69   uint32_t  file_index;
70   uint32_t  mem_index;
71   uint32_t  device_mem_offset;
72 } CodecIOParams;
73
74 typedef struct _CodecDevice {
75   int   fd;
76   void    *buf;
77   uint32_t  buf_size;
78 } CodecDevice;
79
80 typedef struct _CodecElement {
81   gchar   name[32];
82   gchar   longname[64];
83   uint16_t  codec_type;
84   uint16_t  media_type;
85 #if 0
86   union {
87     struct {
88       int8_t pix_fmts[8];
89     } video;
90     struct {
91       int8_t sample_fmts[8];
92     } audio;
93   } format;
94 #endif
95 } CodecElement;
96
97 typedef struct _VideoData {
98   int width, height;
99   int fps_n, fps_d;
100   int par_n, par_d;
101   int pix_fmt, bpp;
102 } VideoData;
103
104 typedef struct _AudioData {
105   int channels, sample_rate;
106   int bit_rate, block_align;
107   int depth, sample_fmt;
108   int64_t channel_layout;
109 } AudioData;
110
111 typedef struct _CodecContext {
112   uint8_t *codecdata;
113   int codecdata_size;
114
115   VideoData video;
116   AudioData audio;
117
118   CodecElement *codec;
119 } CodecContext;
120
121 enum CODEC_FUNC_TYPE {
122   CODEC_ELEMENT_INIT = 1,
123   CODEC_INIT,
124   CODEC_DEINIT,
125   CODEC_DECODE_VIDEO,
126   CODEC_ENCODE_VIDEO,
127   CODEC_DECODE_AUDIO,
128   CODEC_ENCODE_AUDIO,
129 };
130
131 enum CODEC_IO_CMD {
132   CODEC_CMD_GET_VERSION = 5,
133   CODEC_CMD_GET_DEVICE_MEM,
134   CODEC_CMD_SET_DEVICE_MEM,
135   CODEC_CMD_GET_MMAP_OFFSET,
136   CODEC_CMD_SET_MMAP_OFFSET,
137 };
138
139 enum CODEC_MEDIA_TYPE {
140   AVMEDIA_TYPE_UNKNOWN = -1,
141   AVMEDIA_TYPE_VIDEO,
142   AVMEDIA_TYPE_AUDIO,
143 };
144
145 enum CODEC_TYPE {
146   CODEC_TYPE_UNKNOWN = -1,
147   CODEC_TYPE_DECODE,
148   CODEC_TYPE_ENCODE,
149 };
150
151 enum SAMPLT_FORMAT {
152   SAMPLE_FMT_NONE = -1,
153   SAMPLE_FMT_U8,
154   SAMPLE_FMT_S16,
155   SAMPLE_FMT_S32,
156   SAMPLE_FMT_FLT,
157   SAMPLE_FMT_DBL,
158   SAMPLE_FMT_NB
159 };
160
161 /* Define codec types.
162  * e.g. FFmpeg, x264, libvpx and etc.
163  */
164 enum {
165   FFMPEG_TYPE = 1,
166 };
167
168 G_END_DECLS
169
170 #endif