remove unused logging macros.
[platform/adaptation/emulator/gst-plugins-emulator.git] / src / gstmarumem.c
1 /*
2  * GStreamer codec plugin for Tizen Emulator.
3  *
4  * Copyright (C) 2013 - 2014 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 #include "gstmarumem.h"
32
33 /*
34  *  codec data such as codec name, longname, media type and etc.
35  */
36 static int
37 _codec_info_data (CodecElement *codec, gpointer buffer)
38 {
39   int size = sizeof(size);
40
41   GST_INFO ("type: %d, name: %s", codec->codec_type, codec->name);
42
43   memcpy (buffer + size, &codec->codec_type, sizeof(codec->codec_type));
44   size += sizeof(codec->codec_type);
45
46   memcpy (buffer + size, codec->name, sizeof(codec->name));
47   size += sizeof(codec->name);
48
49   return size;
50 }
51
52 void
53 codec_init_data_to (CodecContext *ctx, CodecElement *codec, gpointer buffer)
54 {
55   int size = 0;
56
57   size = _codec_info_data (codec, buffer);
58
59   GST_INFO ("context_id: %d, name: %s, media type: %s",
60     ctx->index, codec->name, codec->media_type ? "audio" : "video");
61
62   memcpy (buffer + size, ctx, sizeof(CodecContext) - 12);
63   size += (sizeof(CodecContext) - 12);
64   memcpy (buffer + size, ctx->codecdata, ctx->codecdata_size);
65   size += ctx->codecdata_size;
66
67   // data length
68   size -= sizeof(size);
69   memcpy (buffer, &size, sizeof(size));
70 }
71
72 int
73 codec_init_data_from (CodecContext *ctx, int media_type, gpointer buffer)
74 {
75   int ret = 0, size = 0;
76
77   memcpy (&ret, buffer, sizeof(ret));
78   size = sizeof(ret);
79   if (ret < 0) {
80     return ret;
81   } else {
82     if (media_type == AVMEDIA_TYPE_AUDIO) {
83       memcpy (&ctx->audio.sample_fmt, buffer + size, sizeof(ctx->audio.sample_fmt));
84       size += sizeof(ctx->audio.sample_fmt);
85
86       memcpy (&ctx->audio.frame_size, buffer + size, sizeof(ctx->audio.frame_size));
87       size += sizeof(ctx->audio.frame_size);
88
89       memcpy(&ctx->audio.bits_per_sample_fmt, buffer + size, sizeof(ctx->audio.bits_per_sample_fmt));
90       size += sizeof(ctx->audio.bits_per_sample_fmt);
91     }
92   }
93
94   memcpy(&ctx->codecdata_size, buffer + size, sizeof(ctx->codecdata_size));
95   size += sizeof(ctx->codecdata_size);
96
97   GST_DEBUG ("codec_init. extradata_size %d", ctx->codecdata_size);
98   if (ctx->codecdata_size > 0) {
99     ctx->codecdata = g_malloc(ctx->codecdata_size);
100     memcpy(ctx->codecdata, buffer + size, ctx->codecdata_size);
101   }
102
103   return ret;
104 }
105
106 void
107 codec_decode_video_data_to (int in_size, int idx, int64_t in_offset,
108                           uint8_t *in_buf, gpointer buffer)
109 {
110   int size = 0;
111
112   size = sizeof(size);
113   memcpy (buffer + size, &in_size, sizeof(in_size));
114   size += sizeof(in_size);
115   memcpy (buffer + size, &idx, sizeof(idx));
116   size += sizeof(idx);
117   memcpy (buffer + size, &in_offset, sizeof(in_offset));
118   size += sizeof(in_offset);
119
120   if (in_size > 0) {
121     memcpy (buffer + size, in_buf, in_size);
122     size += in_size;
123   }
124
125   GST_DEBUG ("decode_video. inbuf_size: %d", in_size);
126
127   size -= sizeof(size);
128   memcpy (buffer, &size, sizeof(size));
129 }
130
131 int
132 codec_decode_video_data_from (int *got_picture_ptr, VideoData *video, gpointer buffer)
133 {
134   int size = 0, len = 0;
135
136   memcpy (&len, buffer, sizeof(len));
137   size = sizeof(len);
138   memcpy (got_picture_ptr, buffer + size, sizeof(*got_picture_ptr));
139   size += sizeof(*got_picture_ptr);
140   memcpy (video, buffer + size, sizeof(VideoData));
141
142   GST_DEBUG ("decode_video. len: %d, have_data: %d", len, *got_picture_ptr);
143
144   return len;
145 }
146
147 void
148 codec_decode_audio_data_to (int in_size, uint8_t *in_buf, gpointer buffer)
149 {
150   int size = 0;
151
152   size = sizeof(size);
153   memcpy (buffer + size, &in_size, sizeof(in_size));
154   size += sizeof(in_size);
155   if (in_size > 0) {
156     memcpy (buffer + size, in_buf, in_size);
157     size += in_size;
158   }
159
160   size -= sizeof(size);
161   memcpy (buffer, &size, sizeof(size));
162 }
163
164 int
165 codec_decode_audio_data_from (int *have_data, int16_t *samples,
166                               AudioData *audio, gpointer buffer)
167 {
168   int len = 0, size = 0;
169   int resample_size = 0;
170
171   memcpy (&len, buffer, sizeof(len));
172   size = sizeof(len);
173   memcpy (have_data, buffer + size, sizeof(*have_data));
174   size += sizeof(*have_data);
175
176   GST_DEBUG ("decode_audio. len %d, have_data %d", len, (*have_data));
177
178   if (*have_data) {
179     memcpy (&audio->sample_fmt, buffer + size, sizeof(audio->sample_fmt));
180     size += sizeof(audio->sample_fmt);
181
182     memcpy (&audio->sample_rate, buffer + size, sizeof(audio->sample_rate));
183     size += sizeof(audio->sample_rate);
184
185     memcpy (&audio->channels, buffer + size, sizeof(audio->channels));
186     size += sizeof(audio->channels);
187
188     memcpy (&audio->channel_layout, buffer + size, sizeof(audio->channel_layout));
189     size += sizeof(audio->channel_layout);
190
191     GST_DEBUG ("decode_audio. sample_fmt %d sample_rate %d, channels %d, ch_layout %lld",
192       audio->sample_fmt, audio->sample_rate, audio->channels, audio->channel_layout);
193
194     memcpy (&resample_size, buffer + size, sizeof(resample_size));
195     size += sizeof(resample_size);
196     memcpy (samples, buffer + size, resample_size);
197     size += resample_size;
198   }
199
200   return resample_size;
201 }
202
203 void
204 codec_encode_video_data_to (int in_size, int64_t in_timestamp,
205                             uint8_t *in_buf, gpointer buffer)
206 {
207   int size = 0;
208
209   size = sizeof(size);
210   memcpy (buffer + size, &in_size, sizeof(in_size));
211   size += sizeof(in_size);
212   memcpy (buffer + size, &in_timestamp, sizeof(in_timestamp));
213   size += sizeof(in_timestamp);
214   if (in_size > 0) {
215     memcpy (buffer + size, in_buf, in_size);
216     size += in_size;
217   }
218
219   size -= sizeof(size);
220   memcpy (buffer, &size, sizeof(size));
221 }
222
223 int
224 codec_encode_video_data_from (uint8_t *out_buf, int *coded_frame, int *is_keyframe, gpointer buffer)
225 {
226   int len = 0, size = 0;
227
228   memcpy (&len, buffer, sizeof(len));
229   size = sizeof(len);
230
231   GST_DEBUG ("encode_video. outbuf size: %d", len);
232
233   if (len > 0) {
234     memcpy (coded_frame, buffer + size, sizeof(int));
235     size += sizeof(int);
236     memcpy (is_keyframe, buffer + size, sizeof(int));
237     size += sizeof(int);
238     memcpy (out_buf, buffer + size, len);
239
240     GST_DEBUG ("coded_frame %d, is_keyframe: %d", *coded_frame, *is_keyframe);
241   }
242
243   return len;
244 }
245
246 void
247 codec_encode_audio_data_to (int in_size, int max_size, uint8_t *in_buf, int64_t timestamp, gpointer buffer)
248 {
249   int size = 0;
250
251   size = sizeof(size);
252   memcpy (buffer + size, &in_size, sizeof(in_size));
253   size += sizeof(in_size);
254
255   memcpy (buffer + size, &timestamp, sizeof(timestamp));
256   size += sizeof(timestamp);
257
258   if (in_size > 0) {
259     memcpy (buffer + size, in_buf, in_size);
260     size += in_size;
261   }
262
263   size -= sizeof(size);
264   memcpy (buffer, &size, sizeof(size));
265 }
266
267 int
268 codec_encode_audio_data_from (uint8_t *out_buf, gpointer buffer)
269 {
270   int len = 0, size = 0;
271
272   memcpy (&len, buffer, sizeof(len));
273   size = sizeof(len);
274   if (len > 0) {
275     memcpy (out_buf, buffer + size, len);
276   }
277
278   GST_DEBUG ("encode_audio. len: %d", len);
279
280   return len;
281 }