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;
175 memcpy (&len, buffer, sizeof(len));
177 memcpy (have_data, buffer + size, sizeof(*have_data));
178 size += sizeof(*have_data);
180 CODEC_LOG (DEBUG, "decode_audio. len %d, have_data %d\n",
184 memcpy (&audio->sample_rate, buffer + size, sizeof(audio->sample_rate));
185 size += sizeof(audio->sample_rate);
187 memcpy (&audio->channels, buffer + size, sizeof(audio->channels));
188 size += sizeof(audio->channels);
190 memcpy (&audio->channel_layout, buffer + size, sizeof(audio->channel_layout));
191 size += sizeof(audio->channel_layout);
193 CODEC_LOG (DEBUG, "decode_audio. sample_rate %d, channels %d, ch_layout %lld\n", audio->sample_rate, audio->channels, audio->channel_layout);
195 memcpy (samples, buffer + size, (*have_data));
202 codec_encode_video_data_to (int in_size, int64_t in_timestamp,
203 uint8_t *in_buf, gpointer buffer)
208 memcpy (buffer + size, &in_size, sizeof(in_size));
209 size += sizeof(in_size);
210 memcpy (buffer + size, &in_timestamp, sizeof(in_timestamp));
211 size += sizeof(in_timestamp);
213 memcpy (buffer + size, in_buf, in_size);
217 size -= sizeof(size);
218 memcpy (buffer, &size, sizeof(size));
222 codec_encode_video_data_from (uint8_t *out_buf, gpointer buffer)
224 int len = 0, size = 0;
226 memcpy (&len, buffer, sizeof(len));
229 CODEC_LOG (DEBUG, "encode_video. outbuf size: %d\n", len);
231 memcpy (out_buf, buffer + size, len);
232 // dev->mem_info.offset = opaque.buffer_size;
239 codec_encode_audio_data_to (int in_size, int max_size, uint8_t *in_buf, gpointer buffer)
244 memcpy (buffer + size, &in_size, sizeof(in_size));
245 size += sizeof(in_size);
246 memcpy (buffer + size, &max_size, sizeof(max_size));
247 size += sizeof(max_size);
250 memcpy (buffer + size, in_buf, in_size);
254 size -= sizeof(size);
255 memcpy (buffer, &size, sizeof(size));
259 codec_encode_audio_data_from (uint8_t *out_buf, gpointer buffer)
261 int len = 0, size = 0;
263 memcpy (&len, buffer, sizeof(len));
266 memcpy (out_buf, buffer + size, len);
269 CODEC_LOG (DEBUG, "encode_audio. outbuf size: %d\n", len);