e7ab644d226142699dd115ff61470e8195579051
[platform/adaptation/emulator/gst-plugins-emulator.git] / src / gstmaru.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_MARU_H__
32 #define __GST_MARU_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 (maru_debug);
47 #define GST_CAT_DEFAULT maru_debug
48
49 G_BEGIN_DECLS
50
51 enum codec_log_level {
52   ERR,
53   WARN,
54   INFO,
55   DEBUG,
56 };
57
58 #define CODEC_DEV   "/dev/brillcodec"
59 #define CODEC_VER   1
60
61 #define CODEC_LOG(level, fmt, ...) \
62   do { \
63     if (level <= INFO) \
64       printf("[gst-maru][%d] " fmt, __LINE__, ##__VA_ARGS__); \
65   } while (0)
66
67 #define FF_INPUT_BUFFER_PADDING_SIZE  8
68 #define FF_MAX_AUDIO_FRAME_SIZE     192000 // 1 second of 48khz 32bit audio
69 #define FF_MIN_BUFFER_SIZE        16384
70
71 #define GEN_MASK(x) ((1<<(x))-1)
72 #define ROUND_UP_X(v, x) (((v) + GEN_MASK(x)) & ~GEN_MASK(x))
73 #define ROUND_UP_2(x) ROUND_UP_X(x, 1)
74 #define ROUND_UP_4(x) ROUND_UP_X(x, 2)
75 #define ROUND_UP_8(x) ROUND_UP_X(x, 3)
76 #define DIV_ROUND_UP_X(v, x) (((v) + GEN_MASK(x)) >> (x))
77
78 typedef struct _CodecIOParams {
79   int32_t   api_index;
80   int32_t   ctx_index;
81   uint32_t  mem_offset;
82 } CodecIOParams;
83
84 typedef struct _CodecDeviceMem {
85   uint32_t  index;
86   uint32_t  offset;
87 } CodecDeviceMem;
88
89 typedef struct _CodecDevice {
90   int       fd;
91   uint8_t   *buf;
92   uint32_t  buf_size;
93   CodecDeviceMem mem_info;
94 } CodecDevice;
95
96 typedef struct _CodecElement {
97   int32_t codec_type;
98   int32_t media_type;
99   gchar name[32];
100   gchar longname[64];
101   union {
102     int32_t pix_fmts[4];
103     int32_t sample_fmts[4];
104   };
105 } CodecElement;
106
107 typedef struct _VideoData {
108   int32_t width, height;
109   int32_t fps_n, fps_d;
110   int32_t par_n, par_d;
111   int32_t pix_fmt, bpp;
112   int32_t ticks_per_frame;
113 } VideoData;
114
115 typedef struct _AudioData {
116   int32_t channels, sample_rate;
117   int32_t block_align, depth;
118   int32_t sample_fmt, frame_size;
119   int32_t bits_per_sample_fmt;
120   int64_t channel_layout;
121 } AudioData;
122
123 typedef struct _CodecContext {
124 //  union {
125     VideoData video;
126     AudioData audio;
127 //  };
128
129   int32_t bit_rate;
130   int32_t codec_tag;
131
132   int32_t codecdata_size;
133   uint8_t *codecdata;
134
135   CodecElement *codec;
136   int32_t index;
137 } CodecContext;
138
139 enum CODEC_FUNC_TYPE {
140   CODEC_INIT = 0,
141   CODEC_DECODE_VIDEO,
142   CODEC_ENCODE_VIDEO,
143   CODEC_DECODE_AUDIO,
144   CODEC_ENCODE_AUDIO,
145   CODEC_PICTURE_COPY,
146   CODEC_DEINIT,
147 };
148
149 #if 0
150 enum CODEC_IO_CMD {
151   CODEC_CMD_COPY_TO_DEVICE_MEM = 5,
152   CODEC_CMD_COPY_FROM_DEVICE_MEM,
153   CODEC_CMD_GET_VERSION = 20,
154   CODEC_CMD_GET_ELEMENT,
155   CODEC_CMD_GET_CONTEXT_INDEX,
156   CODEC_CMD_SECURE_MEMORY = 30,
157   CODEC_CMD_RELEASE_MEMORY,
158   CODEC_CMD_USE_DEVICE_MEM,
159   CODEC_CMD_REQ_FROM_SMALL_MEMORY,
160   CODEC_CMD_REQ_FROM_MEDIUM_MEMORY,
161   CODEC_CMD_REQ_FROM_LARGE_MEMORY,
162   CODEC_CMD_S_SECURE_BUFFER,
163   CODEC_CMD_M_SECURE_BUFFER,
164   CODEC_CMD_L_SECURE_BUFFER,
165 };
166 #endif
167
168 enum CODEC_IO_CMD {
169   CODEC_CMD_GET_VERSION = 20,
170   CODEC_CMD_GET_ELEMENT,
171   CODEC_CMD_GET_CONTEXT_INDEX,
172   CODEC_CMD_USE_DEVICE_MEM = 40,
173   CODEC_CMD_GET_DATA_FROM_SMALL_BUFFER,
174   CODEC_CMD_GET_DATA_FROM_MEDIUM_BUFFER,
175   CODEC_CMD_GET_DATA_FROM_LARGE_BUFFER,
176   CODEC_CMD_SECURE_SMALL_BUFFER,
177   CODEC_CMD_SECURE_MEDIUM_BUFFER,
178   CODEC_CMD_SECURE_LARGE_BUFFER,
179   CODEC_CMD_RELEASE_BUFFER,
180 };
181
182
183 enum CODEC_MEDIA_TYPE {
184   AVMEDIA_TYPE_UNKNOWN = -1,
185   AVMEDIA_TYPE_VIDEO,
186   AVMEDIA_TYPE_AUDIO,
187 };
188
189 enum CODEC_TYPE {
190   CODEC_TYPE_UNKNOWN = -1,
191   CODEC_TYPE_DECODE,
192   CODEC_TYPE_ENCODE,
193 };
194
195 enum SAMPLT_FORMAT {
196   SAMPLE_FMT_NONE = -1,
197   SAMPLE_FMT_U8,
198   SAMPLE_FMT_S16,
199   SAMPLE_FMT_S32,
200   SAMPLE_FMT_FLT,
201   SAMPLE_FMT_DBL,
202   SAMPLE_FMT_NB
203 };
204
205 G_END_DECLS
206 #endif