2 * GStreamer codec plugin for Tizen Emulator.
4 * Copyright (C) 2013 - 2014 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.
31 #include "gstmarumem.h"
34 * codec data such as codec name, longname, media type and etc.
37 _codec_info_data (CodecElement *codec, gpointer buffer)
39 int size = sizeof(size);
41 CODEC_LOG (DEBUG, "enter, %s\n", __func__);
43 CODEC_LOG (DEBUG, "type: %d, name: %s\n", codec->codec_type, codec->name);
44 memcpy (buffer + size, &codec->codec_type, sizeof(codec->codec_type));
45 size += sizeof(codec->codec_type);
47 memcpy (buffer + size, codec->name, sizeof(codec->name));
48 size += sizeof(codec->name);
50 CODEC_LOG (DEBUG, "leave, %s\n", __func__);
56 codec_init_data_to (CodecContext *ctx, CodecElement *codec, gpointer buffer)
60 CODEC_LOG (DEBUG, "enter, %s\n", __func__);
62 size = _codec_info_data (codec, buffer);
64 CODEC_LOG (INFO, "context_id: %d, name: %s, media type: %s\n",
65 ctx->index, codec->name, codec->media_type ? "AUDIO" : "VIDEO");
67 memcpy (buffer + size, ctx, sizeof(CodecContext) - 12);
68 size += (sizeof(CodecContext) - 12);
69 memcpy (buffer + size, ctx->codecdata, ctx->codecdata_size);
70 size += ctx->codecdata_size;
74 memcpy (buffer, &size, sizeof(size));
76 CODEC_LOG (DEBUG, "leave, %s\n", __func__);
80 codec_init_data_from (CodecContext *ctx, int media_type, gpointer buffer)
82 int ret = 0, size = 0;
84 CODEC_LOG (DEBUG, "after init. read data from device.\n");
86 memcpy (&ret, buffer, sizeof(ret));
91 if (media_type == AVMEDIA_TYPE_AUDIO) {
92 memcpy (&ctx->audio.sample_fmt, buffer + size, sizeof(ctx->audio.sample_fmt));
93 size += sizeof(ctx->audio.sample_fmt);
95 memcpy (&ctx->audio.frame_size, buffer + size, sizeof(ctx->audio.frame_size));
96 size += sizeof(ctx->audio.frame_size);
98 memcpy(&ctx->audio.bits_per_sample_fmt, buffer + size, sizeof(ctx->audio.bits_per_sample_fmt));
101 memcpy (&ctx->audio, buffer + size, sizeof(ctx->audio));
104 CODEC_LOG (DEBUG, "video type\n");
112 codec_decode_video_data_to (int in_size, int idx, int64_t in_offset,
113 uint8_t *in_buf, gpointer buffer)
118 memcpy (buffer + size, &in_size, sizeof(in_size));
119 size += sizeof(in_size);
120 memcpy (buffer + size, &idx, sizeof(idx));
122 memcpy (buffer + size, &in_offset, sizeof(in_offset));
123 size += sizeof(in_offset);
126 memcpy (buffer + size, in_buf, in_size);
130 CODEC_LOG (DEBUG, "decode_video. inbuf_size: %d\n", in_size);
132 size -= sizeof(size);
133 memcpy (buffer, &size, sizeof(size));
137 codec_decode_video_data_from (int *got_picture_ptr, VideoData *video, gpointer buffer)
139 int size = 0, len = 0;
141 memcpy (&len, buffer, sizeof(len));
143 memcpy (got_picture_ptr, buffer + size, sizeof(*got_picture_ptr));
144 size += sizeof(*got_picture_ptr);
145 memcpy (video, buffer + size, sizeof(VideoData));
147 CODEC_LOG (DEBUG, "decode_video. len: %d, have_data: %d\n", len, *got_picture_ptr);
153 codec_decode_audio_data_to (int in_size, uint8_t *in_buf, gpointer buffer)
158 memcpy (buffer + size, &in_size, sizeof(in_size));
159 size += sizeof(in_size);
161 memcpy (buffer + size, in_buf, in_size);
165 size -= sizeof(size);
166 memcpy (buffer, &size, sizeof(size));
170 codec_decode_audio_data_from (int *have_data, int16_t *samples,
171 AudioData *audio, gpointer buffer)
173 int len = 0, size = 0;
174 int resample_size = 0;
176 memcpy (&len, buffer, sizeof(len));
178 memcpy (have_data, buffer + size, sizeof(*have_data));
179 size += sizeof(*have_data);
181 GST_DEBUG ("decode_audio. len %d, have_data %d", len, (*have_data));
184 memcpy (&audio->sample_fmt, buffer + size, sizeof(audio->sample_fmt));
185 size += sizeof(audio->sample_fmt);
187 memcpy (&audio->sample_rate, buffer + size, sizeof(audio->sample_rate));
188 size += sizeof(audio->sample_rate);
190 memcpy (&audio->channels, buffer + size, sizeof(audio->channels));
191 size += sizeof(audio->channels);
193 memcpy (&audio->channel_layout, buffer + size, sizeof(audio->channel_layout));
194 size += sizeof(audio->channel_layout);
196 GST_DEBUG ("decode_audio. sample_fmt %d sample_rate %d, channels %d, ch_layout %lld",
197 audio->sample_fmt, audio->sample_rate, audio->channels, audio->channel_layout);
199 memcpy (&resample_size, buffer + size, sizeof(resample_size));
200 size += sizeof(resample_size);
201 memcpy (samples, buffer + size, resample_size);
205 return resample_size;
209 codec_encode_video_data_to (int in_size, int64_t in_timestamp,
210 uint8_t *in_buf, gpointer buffer)
215 memcpy (buffer + size, &in_size, sizeof(in_size));
216 size += sizeof(in_size);
217 memcpy (buffer + size, &in_timestamp, sizeof(in_timestamp));
218 size += sizeof(in_timestamp);
220 memcpy (buffer + size, in_buf, in_size);
224 size -= sizeof(size);
225 memcpy (buffer, &size, sizeof(size));
229 codec_encode_video_data_from (uint8_t *out_buf, int *coded_frame, int *is_keyframe, gpointer buffer)
231 int len = 0, size = 0;
233 memcpy (&len, buffer, sizeof(len));
236 CODEC_LOG (DEBUG, "encode_video. outbuf size: %d\n", len);
238 memcpy (coded_frame, buffer + size, sizeof(int));
240 memcpy (is_keyframe, buffer + size, sizeof(int));
242 memcpy (out_buf, buffer + size, len);
244 GST_DEBUG ("coded_frame %d, is_keyframe: %d", *coded_frame, *is_keyframe);
251 codec_encode_audio_data_to (int in_size, int max_size, uint8_t *in_buf, gpointer buffer)
256 memcpy (buffer + size, &in_size, sizeof(in_size));
257 size += sizeof(in_size);
258 memcpy (buffer + size, &max_size, sizeof(max_size));
259 size += sizeof(max_size);
262 memcpy (buffer + size, in_buf, in_size);
266 size -= sizeof(size);
267 memcpy (buffer, &size, sizeof(size));
271 codec_encode_audio_data_from (uint8_t *out_buf, gpointer buffer)
273 int len = 0, size = 0;
275 memcpy (&len, buffer, sizeof(len));
278 memcpy (out_buf, buffer + size, len);
281 CODEC_LOG (DEBUG, "encode_audio. outbuf size: %d\n", len);