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 GST_INFO ("type: %d, name: %s", codec->codec_type, codec->name);
43 memcpy (buffer + size, &codec->codec_type, sizeof(codec->codec_type));
44 size += sizeof(codec->codec_type);
46 memcpy (buffer + size, codec->name, sizeof(codec->name));
47 size += sizeof(codec->name);
53 codec_init_data_to (CodecContext *ctx, CodecElement *codec, gpointer buffer)
57 size = _codec_info_data (codec, buffer);
59 GST_INFO ("context_id: %d, name: %s, media type: %s",
60 ctx->index, codec->name, codec->media_type ? "audio" : "video");
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;
69 memcpy (buffer, &size, sizeof(size));
73 codec_init_data_from (CodecContext *ctx, int media_type, gpointer buffer)
75 int ret = 0, size = 0;
77 memcpy (&ret, buffer, sizeof(ret));
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);
86 memcpy (&ctx->audio.frame_size, buffer + size, sizeof(ctx->audio.frame_size));
87 size += sizeof(ctx->audio.frame_size);
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);
94 memcpy(&ctx->codecdata_size, buffer + size, sizeof(ctx->codecdata_size));
95 size += sizeof(ctx->codecdata_size);
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);
107 codec_decode_video_data_to (int in_size, int idx, int64_t in_offset,
108 uint8_t *in_buf, gpointer buffer)
113 memcpy (buffer + size, &in_size, sizeof(in_size));
114 size += sizeof(in_size);
115 memcpy (buffer + size, &idx, sizeof(idx));
117 memcpy (buffer + size, &in_offset, sizeof(in_offset));
118 size += sizeof(in_offset);
121 memcpy (buffer + size, in_buf, in_size);
125 GST_DEBUG ("decode_video. inbuf_size: %d", in_size);
127 size -= sizeof(size);
128 memcpy (buffer, &size, sizeof(size));
132 codec_decode_video_data_from (int *got_picture_ptr, VideoData *video, gpointer buffer)
134 int size = 0, len = 0;
136 memcpy (&len, buffer, 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));
142 GST_DEBUG ("decode_video. len: %d, have_data: %d", len, *got_picture_ptr);
148 codec_decode_audio_data_to (int in_size, uint8_t *in_buf, gpointer buffer)
153 memcpy (buffer + size, &in_size, sizeof(in_size));
154 size += sizeof(in_size);
156 memcpy (buffer + size, in_buf, in_size);
160 size -= sizeof(size);
161 memcpy (buffer, &size, sizeof(size));
165 codec_decode_audio_data_from (int *have_data, int16_t *samples,
166 AudioData *audio, gpointer buffer)
168 int len = 0, size = 0;
169 int resample_size = 0;
171 memcpy (&len, buffer, sizeof(len));
173 memcpy (have_data, buffer + size, sizeof(*have_data));
174 size += sizeof(*have_data);
176 GST_DEBUG ("decode_audio. len %d, have_data %d", len, (*have_data));
179 memcpy (&audio->sample_fmt, buffer + size, sizeof(audio->sample_fmt));
180 size += sizeof(audio->sample_fmt);
182 memcpy (&audio->sample_rate, buffer + size, sizeof(audio->sample_rate));
183 size += sizeof(audio->sample_rate);
185 memcpy (&audio->channels, buffer + size, sizeof(audio->channels));
186 size += sizeof(audio->channels);
188 memcpy (&audio->channel_layout, buffer + size, sizeof(audio->channel_layout));
189 size += sizeof(audio->channel_layout);
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);
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;
200 return resample_size;
204 codec_encode_video_data_to (int in_size, int64_t in_timestamp,
205 uint8_t *in_buf, gpointer buffer)
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);
215 memcpy (buffer + size, in_buf, in_size);
219 size -= sizeof(size);
220 memcpy (buffer, &size, sizeof(size));
224 codec_encode_video_data_from (uint8_t *out_buf, int *coded_frame, int *is_keyframe, gpointer buffer)
226 int len = 0, size = 0;
228 memcpy (&len, buffer, sizeof(len));
231 GST_DEBUG ("encode_video. outbuf size: %d", len);
234 memcpy (coded_frame, buffer + size, sizeof(int));
236 memcpy (is_keyframe, buffer + size, sizeof(int));
238 memcpy (out_buf, buffer + size, len);
240 GST_DEBUG ("coded_frame %d, is_keyframe: %d", *coded_frame, *is_keyframe);
247 codec_encode_audio_data_to (int in_size, int max_size, uint8_t *in_buf, int64_t timestamp, gpointer buffer)
252 memcpy (buffer + size, &in_size, sizeof(in_size));
253 size += sizeof(in_size);
255 memcpy (buffer + size, ×tamp, sizeof(timestamp));
256 size += sizeof(timestamp);
259 memcpy (buffer + size, in_buf, in_size);
263 size -= sizeof(size);
264 memcpy (buffer, &size, sizeof(size));
268 codec_encode_audio_data_from (uint8_t *out_buf, gpointer buffer)
270 int len = 0, size = 0;
272 memcpy (&len, buffer, sizeof(len));
275 memcpy (out_buf, buffer + size, len);
278 GST_DEBUG ("encode_audio. len: %d", len);