codec_init_data_to (CodecContext *ctx, CodecElement *codec, gpointer buffer)
{
int size = 0;
+ /* copy VideoData, AudioData, bit_rate, codec_tag and codecdata_size
+ * into device memory. the size of codecdata is variable.
+ *
+ * below 3 points codec->codecData, codec->codec, codec.index and pointer size
+ * can be different between 32 bits and 64 bits. So, need to calculate on arch.
+ */
+ const size_t ctx_exclude_size = sizeof(CodecContext) - (sizeof(uintptr_t) * 3);
size = codec_element_data (codec, buffer);
GST_INFO ("context_id: %d, name: %s, media type: %s",
ctx->index, codec->name, codec->media_type ? "audio" : "video");
- // copy VideoData, AudioData, bit_rate, codec_tag and codecdata_size
- // into device memory. the size of codecdata is variable.
- memcpy (buffer + size, ctx, sizeof(CodecContext) - 12);
- size += (sizeof(CodecContext) - 12);
+ memcpy (buffer + size, ctx, ctx_exclude_size);
+ size += ctx_exclude_size;
memcpy (buffer + size, ctx->codecdata, ctx->codecdata_size);
size += ctx->codecdata_size;
GST_DEBUG ("codec_init. extradata_size %d", ctx->codecdata_size);
if (ctx->codecdata_size > 0) {
- ctx->codecdata = g_malloc(ctx->codecdata_size);
+ ctx->codecdata = g_malloc0(ctx->codecdata_size);
memcpy(ctx->codecdata, buffer + size, ctx->codecdata_size);
}