2 * GStreamer codec plugin for Tizen Emulator.
4 * Copyright (C) 2013 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, uint8_t *device_buf)
41 CODEC_LOG (DEBUG, "enter, %s\n", __func__);
43 CODEC_LOG (DEBUG, "type: %d, name: %s\n", codec->codec_type, codec->name);
44 memcpy (device_buf, &codec->codec_type, sizeof(codec->codec_type));
45 size = sizeof(codec->codec_type);
47 memcpy (device_buf + size, codec->name, sizeof(codec->name));
48 size += sizeof(codec->name);
50 CODEC_LOG (DEBUG, "leave, %s\n", __func__);
56 _codec_init_meta_to (CodecContext *ctx,
62 CODEC_LOG (DEBUG, "enter, %s\n", __func__);
64 size = _codec_info_data (codec, device_buf);
66 CODEC_LOG (INFO, "context_id: %d, name: %s, media type: %s\n",
67 ctx->index, codec->name, codec->media_type ? "AUDIO" : "VIDEO");
69 CODEC_LOG (DEBUG, "init. write data to qemu, size: %d\n", size);
70 memcpy (device_buf + size, ctx, sizeof(CodecContext) - 12);
71 size += (sizeof(CodecContext) - 12);
72 memcpy (device_buf + size, ctx->codecdata, ctx->codecdata_size);
74 CODEC_LOG (DEBUG, "leave, %s\n", __func__);
78 _codec_init_meta_from (CodecContext *ctx,
82 int ret = 0, size = 0;
84 CODEC_LOG (DEBUG, "after init. read data from device.\n");
86 memcpy (&ret, device_buf, sizeof(ret));
89 if (media_type == AVMEDIA_TYPE_AUDIO) {
90 AudioData audio = { 0 };
93 memcpy(&audio, device_buf + size, sizeof(AudioData));
94 ctx->audio.sample_fmt = audio.sample_fmt;
95 ctx->audio.frame_size = audio.frame_size;
96 ctx->audio.bits_per_sample_fmt = audio.bits_per_sample_fmt;
99 "audio sample_fmt: %d\n", *(int *)(device_buf + size));
101 memcpy(&ctx->audio.sample_fmt, device_buf + size, sizeof(audio.sample_fmt));
102 size += sizeof(audio.sample_fmt);
103 memcpy(&ctx->audio.frame_size, device_buf + size, sizeof(audio.frame_size));
104 size += sizeof(audio.frame_size);
105 memcpy(&ctx->audio.bits_per_sample_fmt, device_buf + size, sizeof(audio.bits_per_sample_fmt));
108 "after init. audio sample_fmt: %d\n", ctx->audio.sample_fmt);
111 CODEC_LOG (ERR, "failed to open codec context\n");
118 _codec_decode_video_meta_to (int in_size, int idx, int64_t in_offset, uint8_t *device_buf)
120 memcpy (device_buf, &in_size, sizeof(in_size));
121 memcpy (device_buf + sizeof(in_size), &idx, sizeof(idx));
122 memcpy (device_buf + sizeof(idx), &in_offset, sizeof(in_offset));
126 _codec_decode_video_inbuf (uint8_t *in_buf, int in_size, uint8_t *device_buf)
130 memcpy(device_buf, &in_size, sizeof(in_size));
131 size = sizeof(in_size);
133 memcpy (device_buf + size, in_buf, in_size);
136 CODEC_LOG (DEBUG, "decode_video. inbuf_size: %d\n", in_size);
140 _codec_decode_video_meta_from (VideoData *video,
141 int *got_picture_ptr,
144 int len = 0, size = 0;
146 CODEC_LOG (DEBUG, "decode_video. read data from qemu.\n");
148 memcpy (&len, device_buf, sizeof(len));
150 memcpy (got_picture_ptr,
151 device_buf + size, sizeof(*got_picture_ptr));
152 size += sizeof(*got_picture_ptr);
153 memcpy (video, device_buf + size, sizeof(VideoData));
155 CODEC_LOG (DEBUG, "decode_video. len: %d, have_data: %d\n",
156 len, *got_picture_ptr);
162 _codec_decode_audio_meta_to (int in_size, uint8_t *device_buf)
164 memcpy (device_buf, &in_size, sizeof(in_size));
169 _codec_decode_audio_inbuf (uint8_t *in_buf, int in_size, uint8_t *device_buf)
173 memcpy (device_buf, &in_size, sizeof(in_size));
174 size = sizeof(in_size);
176 memcpy (device_buf + size, in_buf, in_size);
179 CODEC_LOG (DEBUG, "decode_audio. inbuf_size: %d\n", in_size);
183 _codec_decode_audio_meta_from (AudioData *audio, int *frame_size_ptr,
186 int len = 0, size = 0;
188 CODEC_LOG (DEBUG, "decode_audio. read data from device.\n");
190 memcpy (&audio->sample_rate,
191 device_buf, sizeof(audio->sample_rate));
192 size = sizeof(audio->sample_rate);
193 memcpy (&audio->channels,
194 device_buf + size, sizeof(audio->channels));
195 size += sizeof(audio->channels);
196 memcpy (&audio->channel_layout,
197 device_buf + size, sizeof(audio->channel_layout));
198 size += sizeof(audio->channel_layout);
199 memcpy (&len, device_buf + size, sizeof(len));
201 memcpy (frame_size_ptr, device_buf + size, sizeof(*frame_size_ptr));
203 CODEC_LOG (DEBUG, "decode_audio. len: %d, frame_size: %d\n",
204 len, (*frame_size_ptr));
210 _codec_decode_audio_outbuf (int outbuf_size, int16_t *samples, uint8_t *device_buf)
212 CODEC_LOG (DEBUG, "decode_audio. read outbuf %d\n", outbuf_size);
213 memcpy (samples, device_buf, outbuf_size);
217 _codec_encode_video_meta_to (int in_size, int64_t in_timestamp, uint8_t *device_buf)
219 CODEC_LOG (DEBUG, "encode_video. write data to device.\n");
221 memcpy (device_buf, &in_size, sizeof(in_size));
222 memcpy (device_buf + sizeof(in_size), &in_timestamp, sizeof(in_timestamp));
226 _codec_encode_video_inbuf (uint8_t *in_buf, int in_size, uint8_t *device_buf)
230 memcpy ((uint8_t *)device_buf, &in_size, sizeof(in_size));
231 size += sizeof(in_size);
233 memcpy (device_buf + size, in_buf, in_size);
235 CODEC_LOG (DEBUG, "encode_video. inbuf_size: %d\n", in_size);
239 _codec_encode_video_outbuf (int len, uint8_t *out_buf, uint8_t *device_buf)
243 CODEC_LOG (DEBUG, "encode_video. read data from device.\n");
245 // memcpy (&len, device_buf, sizeof(len));
246 // size = sizeof(len);
247 memcpy (out_buf, device_buf, len);
253 _codec_encode_audio_meta_to (int max_size, int in_size, uint8_t *device_buf)
257 CODEC_LOG (DEBUG, "encode_audio. write data to device.\n");
259 memcpy (device_buf, &in_size, sizeof(in_size));
260 size = sizeof(in_size);
261 memcpy (device_buf + size, &max_size, sizeof(max_size));
265 _codec_encode_audio_inbuf (uint8_t *in_buf, int in_size, uint8_t *device_buf)
269 memcpy (device_buf, &in_size, sizeof(in_size));
270 size = sizeof(in_size);
272 memcpy (device_buf + size, in_buf, in_size);
274 CODEC_LOG (DEBUG, "encode_audio. inbuf_size: %d\n", in_size);
278 _codec_encode_audio_outbuf (uint8_t *out_buf, uint8_t *device_buf)
282 CODEC_LOG (DEBUG, "encode_audio. read data from device\n");
284 memcpy (&len, (uint8_t *)device_buf, sizeof(len));
286 memcpy (out_buf, (uint8_t *)device_buf + size, len);