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 GST_INFO ("type: %d, name: %s", codec->codec_type, codec->name);
45 memcpy (buffer + size, &codec->codec_type, sizeof(codec->codec_type));
46 size += sizeof(codec->codec_type);
48 memcpy (buffer + size, codec->name, sizeof(codec->name));
49 size += sizeof(codec->name);
51 CODEC_LOG (DEBUG, "leave, %s\n", __func__);
57 codec_init_data_to (CodecContext *ctx, CodecElement *codec, gpointer buffer)
61 CODEC_LOG (DEBUG, "enter, %s\n", __func__);
63 size = _codec_info_data (codec, buffer);
65 GST_INFO ("context_id: %d, name: %s, media type: %s",
66 ctx->index, codec->name, codec->media_type ? "audio" : "video");
68 memcpy (buffer + size, ctx, sizeof(CodecContext) - 12);
69 size += (sizeof(CodecContext) - 12);
70 memcpy (buffer + size, ctx->codecdata, ctx->codecdata_size);
71 size += ctx->codecdata_size;
75 memcpy (buffer, &size, sizeof(size));
77 CODEC_LOG (DEBUG, "leave, %s\n", __func__);
81 codec_init_data_from (CodecContext *ctx, int media_type, gpointer buffer)
83 int ret = 0, size = 0;
85 memcpy (&ret, buffer, sizeof(ret));
90 if (media_type == AVMEDIA_TYPE_AUDIO) {
91 memcpy (&ctx->audio.sample_fmt, buffer + size, sizeof(ctx->audio.sample_fmt));
92 size += sizeof(ctx->audio.sample_fmt);
94 memcpy (&ctx->audio.frame_size, buffer + size, sizeof(ctx->audio.frame_size));
95 size += sizeof(ctx->audio.frame_size);
97 memcpy(&ctx->audio.bits_per_sample_fmt, buffer + size, sizeof(ctx->audio.bits_per_sample_fmt));
98 size += sizeof(ctx->audio.bits_per_sample_fmt);
102 memcpy(&ctx->codecdata_size, buffer + size, sizeof(ctx->codecdata_size));
103 size += sizeof(ctx->codecdata_size);
105 GST_DEBUG ("codec_init. extradata_size %d", ctx->codecdata_size);
106 if (ctx->codecdata_size > 0) {
107 ctx->codecdata = g_malloc(ctx->codecdata_size);
108 memcpy(ctx->codecdata, buffer + size, ctx->codecdata_size);
115 codec_decode_video_data_to (int in_size, int idx, int64_t in_offset,
116 uint8_t *in_buf, gpointer buffer)
121 memcpy (buffer + size, &in_size, sizeof(in_size));
122 size += sizeof(in_size);
123 memcpy (buffer + size, &idx, sizeof(idx));
125 memcpy (buffer + size, &in_offset, sizeof(in_offset));
126 size += sizeof(in_offset);
129 memcpy (buffer + size, in_buf, in_size);
133 CODEC_LOG (DEBUG, "decode_video. inbuf_size: %d\n", in_size);
135 size -= sizeof(size);
136 memcpy (buffer, &size, sizeof(size));
140 codec_decode_video_data_from (int *got_picture_ptr, VideoData *video, gpointer buffer)
142 int size = 0, len = 0;
144 memcpy (&len, buffer, sizeof(len));
146 memcpy (got_picture_ptr, buffer + size, sizeof(*got_picture_ptr));
147 size += sizeof(*got_picture_ptr);
148 memcpy (video, buffer + size, sizeof(VideoData));
150 GST_DEBUG ("decode_video. len: %d, have_data: %d", len, *got_picture_ptr);
156 codec_decode_audio_data_to (int in_size, uint8_t *in_buf, gpointer buffer)
161 memcpy (buffer + size, &in_size, sizeof(in_size));
162 size += sizeof(in_size);
164 memcpy (buffer + size, in_buf, in_size);
168 size -= sizeof(size);
169 memcpy (buffer, &size, sizeof(size));
173 codec_decode_audio_data_from (int *have_data, int16_t *samples,
174 AudioData *audio, gpointer buffer)
176 int len = 0, size = 0;
177 int resample_size = 0;
179 memcpy (&len, buffer, sizeof(len));
181 memcpy (have_data, buffer + size, sizeof(*have_data));
182 size += sizeof(*have_data);
184 GST_DEBUG ("decode_audio. len %d, have_data %d", len, (*have_data));
187 memcpy (&audio->sample_fmt, buffer + size, sizeof(audio->sample_fmt));
188 size += sizeof(audio->sample_fmt);
190 memcpy (&audio->sample_rate, buffer + size, sizeof(audio->sample_rate));
191 size += sizeof(audio->sample_rate);
193 memcpy (&audio->channels, buffer + size, sizeof(audio->channels));
194 size += sizeof(audio->channels);
196 memcpy (&audio->channel_layout, buffer + size, sizeof(audio->channel_layout));
197 size += sizeof(audio->channel_layout);
199 GST_DEBUG ("decode_audio. sample_fmt %d sample_rate %d, channels %d, ch_layout %lld",
200 audio->sample_fmt, audio->sample_rate, audio->channels, audio->channel_layout);
202 memcpy (&resample_size, buffer + size, sizeof(resample_size));
203 size += sizeof(resample_size);
204 memcpy (samples, buffer + size, resample_size);
205 size += resample_size;
208 return resample_size;
212 codec_encode_video_data_to (int in_size, int64_t in_timestamp,
213 uint8_t *in_buf, gpointer buffer)
218 memcpy (buffer + size, &in_size, sizeof(in_size));
219 size += sizeof(in_size);
220 memcpy (buffer + size, &in_timestamp, sizeof(in_timestamp));
221 size += sizeof(in_timestamp);
223 memcpy (buffer + size, in_buf, in_size);
227 size -= sizeof(size);
228 memcpy (buffer, &size, sizeof(size));
232 codec_encode_video_data_from (uint8_t *out_buf, int *coded_frame, int *is_keyframe, gpointer buffer)
234 int len = 0, size = 0;
236 memcpy (&len, buffer, sizeof(len));
239 GST_DEBUG ("encode_video. outbuf size: %d", len);
242 memcpy (coded_frame, buffer + size, sizeof(int));
244 memcpy (is_keyframe, buffer + size, sizeof(int));
246 memcpy (out_buf, buffer + size, len);
248 GST_DEBUG ("coded_frame %d, is_keyframe: %d", *coded_frame, *is_keyframe);
255 codec_encode_audio_data_to (int in_size, int max_size, uint8_t *in_buf, int64_t timestamp, gpointer buffer)
260 memcpy (buffer + size, &in_size, sizeof(in_size));
261 size += sizeof(in_size);
263 memcpy (buffer + size, ×tamp, sizeof(timestamp));
264 size += sizeof(timestamp);
267 memcpy (buffer + size, in_buf, in_size);
271 size -= sizeof(size);
272 memcpy (buffer, &size, sizeof(size));
276 codec_encode_audio_data_from (uint8_t *out_buf, gpointer buffer)
278 int ret = 0, outbuf_size = 0, size = 0;
280 memcpy (&ret, buffer, sizeof(ret));
283 memcpy (&outbuf_size, buffer + size, sizeof(outbuf_size));
284 size += sizeof(outbuf_size);
285 if (outbuf_size > 0) {
286 memcpy (out_buf, buffer + size, outbuf_size);
290 GST_DEBUG ("encode_audio. ret: %d outbuf size: %d", ret, outbuf_size);