clean-up source
[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 extern int device_version;
52
53 enum codec_log_level {
54   ERR,
55   WARN,
56   INFO,
57   DEBUG,
58 };
59
60 #define CODEC_DEV   "/dev/brillcodec"
61 #define CODEC_VER   2
62
63 #define CHECK_VERSION(version)        (device_version > version)
64
65 #define CODEC_LOG(level, fmt, ...) \
66   do { \
67     if (level <= INFO) \
68       printf("[gst-maru][%s:%d] " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
69   } while (0)
70
71 #define FF_INPUT_BUFFER_PADDING_SIZE  8
72 #define FF_MAX_AUDIO_FRAME_SIZE       192000 // 1 second of 48khz 32bit audio
73 #define FF_MIN_BUFFER_SIZE            16384
74
75 #define GEN_MASK(x) ((1<<(x))-1)
76 #define ROUND_UP_X(v, x) (((v) + GEN_MASK(x)) & ~GEN_MASK(x))
77 #define ROUND_UP_2(x) ROUND_UP_X(x, 1)
78 #define ROUND_UP_4(x) ROUND_UP_X(x, 2)
79 #define ROUND_UP_8(x) ROUND_UP_X(x, 3)
80 #define DIV_ROUND_UP_X(v, x) (((v) + GEN_MASK(x)) >> (x))
81
82 typedef struct _CodecDevice {
83   int       fd;
84   uint8_t   *buf;
85   uint32_t  buf_size;
86 } CodecDevice;
87
88 typedef struct _CodecElement {
89   int32_t codec_type;
90   int32_t media_type;
91   gchar name[32];
92   gchar longname[64];
93   union {
94     int32_t pix_fmts[4];
95     int32_t sample_fmts[4];
96   };
97 } CodecElement;
98
99 typedef struct _VideoData {
100   int32_t width, height;
101   int32_t fps_n, fps_d;
102   int32_t par_n, par_d;
103   int32_t pix_fmt, bpp;
104   int32_t ticks_per_frame;
105 } VideoData;
106
107 typedef struct _AudioData {
108   int32_t channels, sample_rate;
109   int32_t block_align, depth;
110   int32_t sample_fmt, frame_size;
111   int32_t bits_per_sample_fmt, reserved;
112   int64_t channel_layout;
113 } AudioData;
114
115 typedef struct _CodecContext {
116   VideoData video;
117   AudioData audio;
118
119   int32_t bit_rate;
120   int32_t codec_tag;
121
122   int32_t codecdata_size;
123   uint8_t *codecdata;
124
125   CodecElement *codec;
126   int32_t index;
127 } CodecContext;
128
129 enum CODEC_FUNC_TYPE {
130   CODEC_INIT = 0,
131   CODEC_DECODE_VIDEO,
132   CODEC_ENCODE_VIDEO,
133   CODEC_DECODE_AUDIO,
134   CODEC_ENCODE_AUDIO,
135   CODEC_PICTURE_COPY,
136   CODEC_DEINIT,
137   CODEC_FLUSH_BUFFERS,
138 };
139
140 enum CODEC_IO_CMD {
141   CODEC_CMD_GET_VERSION = 20,
142   CODEC_CMD_GET_ELEMENT,
143   CODEC_CMD_GET_CONTEXT_INDEX,
144   CODEC_CMD_GET_ELEMENT_DATA,
145   CODEC_CMD_PUT_DATA_INTO_BUFFER = 40,
146   CODEC_CMD_SECURE_BUFFER,
147   CODEC_CMD_TRY_SECURE_BUFFER,
148   CODEC_CMD_RELEASE_BUFFER,
149   CODEC_CMD_INVOKE_API_AND_RELEASE_BUFFER,
150 };
151
152 enum CODEC_MEDIA_TYPE {
153   AVMEDIA_TYPE_UNKNOWN = -1,
154   AVMEDIA_TYPE_VIDEO,
155   AVMEDIA_TYPE_AUDIO,
156 };
157
158 enum CODEC_TYPE {
159   CODEC_TYPE_UNKNOWN = -1,
160   CODEC_TYPE_DECODE,
161   CODEC_TYPE_ENCODE,
162 };
163
164 enum AUDIO_SAMPLE_FORMAT {
165   SAMPLE_FMT_NONE = -1,
166   SAMPLE_FMT_U8,
167   SAMPLE_FMT_S16,
168   SAMPLE_FMT_S32,
169   SAMPLE_FMT_FLT,
170   SAMPLE_FMT_DBL,
171
172   SAMPLE_FMT_U8P,
173   SAMPLE_FMT_S16P,
174   SAMPLE_FMT_S32P,
175   SAMPLE_FMT_FLTP,
176   SAMPLE_FMT_DBLP,
177   SAMPLE_FMT_NB
178 };
179
180 G_END_DECLS
181 #endif