#include <gst/gst.h>
#include <gst/gstelement.h>
#include <gst/app/gstappsrc.h>
+#include <gst/pbutils/pbutils.h>
+#include <gst/tag/tag.h>
/*
* Internal Implementation
static gboolean __mc_gst_init_gstreamer();
static int _mc_output_media_packet_new(mc_gst_core_t *core, bool video, bool encoder, media_format_mimetype_e out_mime);
-static mc_ret_e _mc_gst_create_pipeline(mc_gst_core_t *core, gchar *factory_name);
+static mc_ret_e _mc_gst_create_pipeline(mc_gst_core_t *core, const gchar *factory_name);
static mc_ret_e _mc_gst_destroy_pipeline(mc_gst_core_t *core);
static void __mc_gst_buffer_add(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer data);
static int __mc_output_buffer_finalize_cb(media_packet_h packet, int error_code, void *user_data);
-static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *mcbuffer, bool codec_config);
-static gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h fmt);
+static gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h format);
static GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t *core, media_packet_h packet, bool codec_config);
static int _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *mcbuffer);
-static gchar *__mc_get_gst_input_format(media_packet_h packet, bool is_hw);
+static gchar *__mc_get_gst_input_format(media_format_mimetype_e mimetype, bool is_hw);
static GstMCBuffer *__mc_gst_make_media_packet(mc_gst_core_t *core, GstBuffer *buffer);
static gboolean __mc_gst_bus_callback(GstBus *bus, GstMessage *msg, gpointer data);
static GstBusSyncReply __mc_gst_bus_sync_callback(GstBus *bus, GstMessage *msg, gpointer data);
-static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet_h packet);
+static GstMemory *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, GstMCBuffer *mcbuffer);
static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t *core, media_packet_h packet, uint64_t size);
static void __mc_input_buffer_finalize_cb(GstMCBuffer *buffer);
static int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint streamheader_size);
static gint __gst_handle_core_error(mc_gst_core_t *core, int code);
static const gchar * _mc_error_to_string(mc_ret_e err);
static const gchar * _mc_bit_to_string(int bit);
-static int _mc_get_support_bit_from_format(media_format_mimetype_e format);
static int _mc_link_vtable(mc_gst_core_t *core, mediacodec_codec_type_e id, gboolean is_encoder, gboolean is_hw);
static int _mc_gst_flush_buffers(mc_gst_core_t *core);
static void _mc_send_eos_signal(mc_gst_core_t *core);
static void _mc_wait_for_eos(mc_gst_core_t *core);
static int _mc_get_mime(mc_gst_core_t *core);
+static int _mc_set_codec_data(mc_gst_core_t *core, GstMCBuffer *mcbuffer, bool codec_config);
+GstCaps *_mc_gst_vid_caps_new(mc_gst_core_t *core, mediacodec_codec_type_e codec_id, gint index);
+GstCaps *_mc_gst_aud_caps_new(mc_gst_core_t *core, mediacodec_codec_type_e codec_id, gint index);
+static int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer);
+static int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer);
+
+static int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer);
+static int __mc_fill_input_buffer_with_adec_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer);
+static int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer);
+
+static int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer);
+static int __mc_fill_aenc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer);
+static int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer);
+static int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer);
+
+static mc_gst_core_t *mc_gst_core_new();
+static void mc_gst_core_free(mc_gst_core_t *core);
+
+static mc_gst_port_t *mc_gst_port_new(mc_gst_core_t *core);
+static void mc_gst_port_free(mc_gst_port_t *port);
/* video vtable */
-int(*vdec_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer};
-int(*venc_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer};
+__attribute__((unused))
+static int(*vdec_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer};
+static int(*venc_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer};
-int(*vdec_h264_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W H.264 Decoder Vtable */
+static int(*vdec_h264_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W H.264 Decoder Vtable */
&__mc_fill_vdec_packet_with_output_buffer};
-int(*vdec_mpeg4_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W MPEG4 Decoder Vtable */
+static int(*vdec_mpeg4_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W MPEG4 Decoder Vtable */
&__mc_fill_vdec_packet_with_output_buffer};
-int(*vdec_h263_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W MPEG4 Decoder Vtable */
+static int(*vdec_h263_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W MPEG4 Decoder Vtable */
&__mc_fill_vdec_packet_with_output_buffer};
-int(*vdec_h264_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W H.264 Decoder Vtable */
+static int(*vdec_h264_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W H.264 Decoder Vtable */
&__mc_fill_vdec_packet_with_output_buffer};
-int(*vdec_mpeg4_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W MPEG4 Decoder Vtable */
+static int(*vdec_mpeg4_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W MPEG4 Decoder Vtable */
&__mc_fill_vdec_packet_with_output_buffer};
-int(*vdec_h263_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W MPEG4 Decoder Vtable */
+static int(*vdec_h263_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W MPEG4 Decoder Vtable */
&__mc_fill_vdec_packet_with_output_buffer};
-int(*venc_mpeg4_sw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* S/W MPEG4 Encoder Vtable */
+static int(*venc_mpeg4_sw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* S/W MPEG4 Encoder Vtable */
&__mc_fill_venc_packet_with_output_buffer};
-int(*venc_h263_sw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* S/W MPEG4 Encoder Vtable */
+static int(*venc_h263_sw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* S/W MPEG4 Encoder Vtable */
&__mc_fill_venc_packet_with_output_buffer};
-int(*venc_h264_hw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* H/W H.264 Encoder Vtable */
+static int(*venc_h264_hw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* H/W H.264 Encoder Vtable */
&__mc_fill_venc_packet_with_output_buffer};
-int(*venc_mpeg4_hw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* H/W MPEG4 Encoder Vtable */
+static int(*venc_mpeg4_hw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* H/W MPEG4 Encoder Vtable */
&__mc_fill_venc_packet_with_output_buffer};
-int(*venc_h263_hw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* H/W MPEG4 Encoder Vtable */
+static int(*venc_h263_hw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* H/W MPEG4 Encoder Vtable */
&__mc_fill_venc_packet_with_output_buffer};
-int(*aenc_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer};
-int(*adec_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer};
+__attribute__((unused))
+static int(*aenc_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer};
+
+static int(*adec_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer};
-int(*aenc_aac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AAC LC Encoder vtable */
+static int(*aenc_aac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AAC LC Encoder vtable */
&__mc_fill_aenc_packet_with_output_buffer};
-int(*adec_aac_vtable[])() = {&__mc_fill_input_buffer_with_adec_packet, /* AAC LC Decoder Vtable */
+static int(*adec_aac_vtable[])() = {&__mc_fill_input_buffer_with_adec_packet, /* AAC LC Decoder Vtable */
&__mc_fill_packet_with_output_buffer};
-int(*adec_aacv12_vtable[])() = {&__mc_fill_input_buffer_with_adec_packet, /* AAC HE Decoder Vtable */
+static int(*adec_aacv12_vtable[])() = {&__mc_fill_input_buffer_with_adec_packet, /* AAC HE Decoder Vtable */
&__mc_fill_packet_with_output_buffer};
-int(*adec_mp3_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* MP3 Decoder Vtable */
+static int(*adec_mp3_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* MP3 Decoder Vtable */
&__mc_fill_packet_with_output_buffer};
-int(*adec_amrnb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-NB Decoder Vtable */
+static int(*adec_amrnb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-NB Decoder Vtable */
&__mc_fill_packet_with_output_buffer};
-int(*adec_amrwb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-WB Decoder Vtable */
+static int(*adec_amrwb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-WB Decoder Vtable */
&__mc_fill_packet_with_output_buffer};
-int(*aenc_amrnb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-NB Encoder Vtable */
+static int(*aenc_amrnb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-NB Encoder Vtable */
&__mc_fill_packet_with_output_buffer};
-int(*adec_vorbis_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* VORBIS Decoder Vtable */
+static int(*adec_vorbis_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* VORBIS Decoder Vtable */
&__mc_fill_packet_with_output_buffer};
-int(*adec_flac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* FLAC Decoder Vtable */
+static int(*adec_flac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* FLAC Decoder Vtable */
&__mc_fill_packet_with_output_buffer};
-int(*adec_wma_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* WMA Decoder Vtable */
+static int(*adec_wma_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* WMA Decoder Vtable */
&__mc_fill_packet_with_output_buffer};
+static int(*aenc_opus_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* Opus Encoder Vtable */
+ &__mc_fill_aenc_packet_with_output_buffer};
+
+#define MEDIACODEC_ELEMENT_SET_STATE(x_element, x_state) \
+ do { \
+ LOGD("setting state [%s:%d] to [%s]\n", #x_state, x_state, GST_ELEMENT_NAME(x_element)); \
+ if (GST_STATE_CHANGE_FAILURE == gst_element_set_state(x_element, x_state)) { \
+ LOGE("failed to set state %s to %s\n", #x_state, GST_ELEMENT_NAME(x_element)); \
+ goto STATE_CHANGE_FAILED; \
+ } \
+ } while (0)
/*
* fill_inbuf virtual functions
{
gint ret = MC_ERROR_NONE;
uint64_t buf_size = 0;
- MMVideoBuffer *mm_vbuffer = NULL;
+ GstMemory *mem;
void *buf_data = NULL;
ret = media_packet_get_buffer_size(packet, &buf_size);
return MC_ERROR;
}
- mm_vbuffer = __mc_gst_make_tbm_buffer(core, mcbuffer->packet);
-
- if (mm_vbuffer != NULL) {
- gst_buffer_prepend_memory(mcbuffer->buffer,
- gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, mm_vbuffer, sizeof(*mm_vbuffer), 0,
- sizeof(*mm_vbuffer), mm_vbuffer, free));
- LOGD("mm_vbuffer appended, %d, %d", sizeof(*mm_vbuffer), gst_buffer_n_memory(mcbuffer->buffer));
+ mem = __mc_gst_make_tbm_buffer(core, mcbuffer);
+ if (mem == NULL) {
+ LOGW("Failed to make tizen memory");
+ return MC_ERROR;
}
- if (buf_data != NULL) {
- gst_buffer_prepend_memory(mcbuffer->buffer,
- gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0,
- buf_size, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb));
- LOGD("packet data apended, %d, %d", buf_size, gst_buffer_n_memory(mcbuffer->buffer));
- }
+ gst_buffer_append_memory(mcbuffer->buffer, mem);
+ LOGD("tizen memory appended");
+
return ret;
}
-int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer)
+static int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer)
{
gint ret = MC_ERROR_NONE;
void *buf_data = NULL;
return MC_ERROR;
}
- if (buf_data != NULL) {
- gst_buffer_append_memory(mcbuffer->buffer,
- gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0,
- buf_size, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb));
- LOGD("packet data apended");
- }
+ if (buf_data == NULL)
+ return MC_ERROR;
+
+ gst_buffer_append_memory(mcbuffer->buffer,
+ gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0,
+ buf_size, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb));
+ LOGD("packet data apended");
return ret;
}
-int __mc_fill_input_buffer_with_adec_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer)
+static int __mc_fill_input_buffer_with_adec_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer)
{
gint ret = MC_ERROR_NONE;
uint64_t buf_size = 0;
return ret;
}
-int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer)
+static int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer)
{
gint ret = MC_ERROR_NONE;
gint i;
uint32_t plane_num;
guint8 *planes[2];
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
+ mc_gst_port_def_t *port_def = &core->ports[in_port_index]->port_def;
- width = enc_info->width;
- height = enc_info->height;
+ width = port_def->info.video.width;
+ height = port_def->info.video.height;
ret = media_packet_get_number_of_video_planes(packet, &plane_num);
if (ret != MEDIA_PACKET_ERROR_NONE) {
}
}
} else {
- MMVideoBuffer *mm_video_buffer = NULL;
+ GstMemory *mem = NULL;
- mm_video_buffer = __mc_gst_make_tbm_buffer(core, packet);
-
- gst_buffer_prepend_memory(mcbuffer->buffer,
- gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, mm_video_buffer, sizeof(MMVideoBuffer), 0,
- sizeof(MMVideoBuffer), mm_video_buffer, free));
+ mem = __mc_gst_make_tbm_buffer(core, mcbuffer);
+ if (mem == NULL) {
+ LOGW("Failed to make tizen memory");
+ return MC_ERROR;
+ }
- LOGD("mm_video_buffer appended, %d, %d", sizeof(MMVideoBuffer), gst_buffer_n_memory(mcbuffer->buffer));
+ gst_buffer_append_memory(mcbuffer->buffer, mem);
+ LOGD("tizen memory appended");
}
-
- gst_buffer_prepend_memory(mcbuffer->buffer,
- gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, planes[0], mcbuffer->buf_size, 0,
- mcbuffer->buf_size, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb));
-
return ret;
}
* fill_outbuf virtual functions
*/
-int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
+static int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
{
return core->vtable[fill_outbuf](core, data, size, mcbuffer);
}
-int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
+static int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
{
int i;
int stride_width;
g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
+ mc_gst_port_def_t *port_def = &core->ports[out_port_index]->port_def;
if (!core->is_hw) {
- width = dec_info->width;
- height = dec_info->height;
+ width = port_def->info.video.width;
+ height = port_def->info.video.height;
stride_width = GST_ROUND_UP_4(width);
stride_height = height;
buf_size = stride_width * stride_height * 3 / 2;
return MC_ERROR;
}
- tsurf_info.width = dec_info->width;
- tsurf_info.height = dec_info->height;
+ tsurf_info.width = port_def->info.video.width;
+ tsurf_info.height = port_def->info.video.height;
tsurf_info.format = TBM_FORMAT_YVU420;
tsurf_info.bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_YVU420);
tsurf_info.num_planes = tbm_surface_internal_get_num_planes(TBM_FORMAT_YVU420);
tsurf = tbm_surface_internal_create_with_bos(&tsurf_info, bo, 1);
} else {
- int bo_num = 0;
- MMVideoBuffer *mm_vbuffer = NULL;
- mm_vbuffer = (MMVideoBuffer *)data;
-
- if (mm_vbuffer->type == MM_VIDEO_BUFFER_TYPE_TBM_BO) {
- tbm_surface_info_s tsurf_info;
- memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s));
-
- /* create tbm surface */
- for (i = 0; i < MM_VIDEO_BUFFER_PLANE_MAX; i++) {
- if (mm_vbuffer->handle.bo[i]) {
- bo_num++;
- tsurf_info.planes[i].stride = mm_vbuffer->stride_width[i];
- }
- }
-
- if (bo_num > 0) {
- tsurf_info.width = dec_info->width;
- tsurf_info.height = dec_info->height;
- tsurf_info.format = TBM_FORMAT_NV12; /* bo_format */
- tsurf_info.bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_NV12);
- tsurf_info.num_planes = tbm_surface_internal_get_num_planes(TBM_FORMAT_NV12);
- tsurf_info.size = 0;
-
- for (i = 0; i < tsurf_info.num_planes; i++) {
- tsurf_info.planes[i].stride = mm_vbuffer->stride_width[i];
- tsurf_info.planes[i].size = mm_vbuffer->stride_width[i] * mm_vbuffer->stride_height[i];
-
- if (i < bo_num)
- tsurf_info.planes[i].offset = 0;
- else
- tsurf_info.planes[i].offset = tsurf_info.planes[i-1].offset + tsurf_info.planes[i - 1].size;
-
- tsurf_info.size += tsurf_info.planes[i].size;
- LOGD("%d plane stride : %d, size : %d", i, tsurf_info.planes[i].stride, tsurf_info.planes[i].size);
- }
- tsurf = tbm_surface_internal_create_with_bos(&tsurf_info, (tbm_bo *)mm_vbuffer->handle.bo, bo_num);
- }
- }
+ tsurf = (tbm_surface_h)data;
}
if (tsurf) {
return MC_ERROR_NONE;
}
-int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
+static int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
{
gint ret = MC_ERROR_NONE;
gchar *ext_mem = NULL;
return MC_ERROR_NONE;
}
-int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
+static int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
{
gint ret = MC_ERROR_NONE;
bool codec_config = FALSE;
g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
- switch (core->out_mime) {
+ switch (core->ports[out_port_index]->port_def.coding_type) {
case MEDIA_FORMAT_H264_SP:
case MEDIA_FORMAT_H264_MP:
case MEDIA_FORMAT_H264_HP:
data_size = _mc_check_h264_bytestream((unsigned char *)data, size, 1, &codec_config, &sync_flag, &slice);
- if (data_size <= 0) {
+ if (data_size < 0) {
LOGE("No valid SPS/PPS ...");
return MC_INVALID_IN_BUF;
}
return ret;
}
-int __mc_fill_aenc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
+static int __mc_fill_aenc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
{
int ret = MC_ERROR_NONE;
gint mem_size = 0;
s = gst_caps_get_structure(peercaps, 0);
codec_data = gst_structure_get_value(s, "codec_data");
+ if (codec_data == NULL && gst_structure_has_field(s, "streamheader"))
+ codec_data = gst_structure_get_value(s, "streamheader");
+
core->codec_data = GST_BUFFER(g_value_dup_boxed(codec_data));
gst_caps_unref(peercaps);
}
__mc_gst_caps_set_buffer_array(core->caps, "streamheader", header1, header2, NULL);
gst_buffer_unref(header1);
gst_buffer_unref(header2);
+ } else if (core->codec_id == MEDIACODEC_OPUS) {
+ const GstTagList *tags;
+ GstTagList *empty_tags = NULL;
+ GstBuffer *header, *comments;
+ guint8 *decoding_channel_mapping = NULL;
+ mc_gst_port_def_t *port_def = &core->ports[in_port_index]->port_def;
+
+ header = gst_codec_utils_opus_create_header(port_def->info.audio.samplerate,
+ port_def->info.audio.channel,
+ 0, /* channel mapping family */
+ 1, /* stream count */
+ 0, /* coupled count */
+ decoding_channel_mapping,
+ 0, /* FIXME: look ahead configured value */
+ 0);
+ tags = gst_tag_setter_get_tag_list(GST_TAG_SETTER(core->codec));
+ if (!tags)
+ tags = empty_tags = gst_tag_list_new_empty();
+ comments = gst_tag_list_to_vorbiscomment_buffer(tags, (const guint8 *) "OpusTags",
+ 8, "Encoded with GStreamer opusenc");
+ core->caps = gst_codec_utils_opus_create_caps_from_header(header, comments);
+ if (empty_tags)
+ gst_tag_list_unref(empty_tags);
+ gst_buffer_unref(header);
+ gst_buffer_unref(comments);
} else {
LOGE("Not support case of Stream header Caps");
}
LOGE("media format create failed");
return MC_ERROR;
}
+ mc_gst_port_def_t *port_def = &core->ports[out_port_index]->port_def;
- if (encoder) {
- mc_encoder_info_t *info;
-
- info = (mc_encoder_info_t *)core->codec_info;
+ if (video) {
+ media_format_set_video_mime(core->output_fmt, out_mime);
+ media_format_set_video_width(core->output_fmt, port_def->info.video.width);
+ media_format_set_video_height(core->output_fmt, port_def->info.video.height);
- if (video) {
- media_format_set_video_mime(core->output_fmt, out_mime);
- media_format_set_video_width(core->output_fmt, info->width);
- media_format_set_video_height(core->output_fmt, info->height);
- media_format_set_video_avg_bps(core->output_fmt, info->bitrate);
- } else {
- int support_bit = 0;
- support_bit = _mc_get_support_bit_from_format(out_mime);
-
- media_format_set_audio_mime(core->output_fmt, out_mime);
- media_format_set_audio_channel(core->output_fmt, info->channel);
- media_format_set_audio_samplerate(core->output_fmt, info->samplerate);
- media_format_set_audio_bit(core->output_fmt, support_bit);
- media_format_set_audio_avg_bps(core->output_fmt, info->bitrate);
- }
+ if (encoder)
+ media_format_set_video_avg_bps(core->output_fmt, port_def->info.video.bitrate);
} else {
- mc_decoder_info_t *info;
+ media_format_set_audio_mime(core->output_fmt, out_mime);
+ media_format_set_audio_channel(core->output_fmt, port_def->info.audio.channel);
+ media_format_set_audio_samplerate(core->output_fmt, port_def->info.audio.samplerate);
+ media_format_set_audio_bit(core->output_fmt, port_def->info.audio.bit_depth);
- info = (mc_decoder_info_t *)core->codec_info;
-
- if (video) {
- media_format_set_video_mime(core->output_fmt, out_mime);
- media_format_set_video_width(core->output_fmt, info->width);
- media_format_set_video_height(core->output_fmt, info->height);
- } else {
- media_format_set_audio_mime(core->output_fmt, out_mime);
- media_format_set_audio_channel(core->output_fmt, info->channel);
- media_format_set_audio_samplerate(core->output_fmt, info->samplerate);
- media_format_set_audio_bit(core->output_fmt, info->bit);
- }
+ if (encoder)
+ media_format_set_audio_avg_bps(core->output_fmt, port_def->info.audio.bitrate);
}
+
return MC_ERROR_NONE;
}
/*
* mc_gst_core functions
*/
-mc_gst_core_t *mc_gst_core_new()
+static mc_gst_core_t *mc_gst_core_new()
{
mc_gst_core_t *core;
core = g_new0(mc_gst_core_t, 1);
/* 0 : input, 1 : output */
- core->ports[0] = NULL;
+ core->ports[0] = mc_gst_port_new(core);
+ core->ports[0]->index = 0;
core->ports[1] = mc_gst_port_new(core);
core->ports[1]->index = 1;
g_atomic_int_set(&core->available_queue->running, 1);
core->available_queue->thread = g_thread_new("feed thread", &feed_task, core);
+ core->allocator = gst_tizen_allocator_new();
core->bufmgr = NULL;
core->drm_fd = -1;
return core;
}
-void mc_gst_core_free(mc_gst_core_t *core)
+static void mc_gst_core_free(mc_gst_core_t *core)
{
MEDIACODEC_FENTER();
mc_async_queue_free(async_queue->input);
g_free(async_queue);
+ if (core->allocator) {
+ gst_object_unref(core->allocator);
+ core->allocator = NULL;
+ }
+
if (core->codec_data)
gst_buffer_unref(core->codec_data);
+ if (core->ports[0] != NULL) {
+ mc_gst_port_free(core->ports[0]);
+ core->ports[0] = NULL;
+ }
+
if (core->ports[1] != NULL) {
mc_gst_port_free(core->ports[1]);
core->ports[1] = NULL;
/*
* mc_gst_port functions
*/
-mc_gst_port_t *mc_gst_port_new(mc_gst_core_t *core)
+static mc_gst_port_t *mc_gst_port_new(mc_gst_core_t *core)
{
MEDIACODEC_FENTER();
port->num_buffers = -1;
port->buffer_size = 0;
port->is_allocated = 0;
- port->buffers = NULL;
g_mutex_init(&port->mutex);
port->queue = g_queue_new();
return port;
}
-void mc_gst_port_free(mc_gst_port_t *port)
+static void mc_gst_port_free(mc_gst_port_t *port)
{
MEDIACODEC_FENTER();
return;
}
-gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h fmt)
+gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h format)
{
- gboolean is_updated = FALSE;
+ gboolean is_format_change = FALSE;
- mc_decoder_info_t *codec_info = (mc_decoder_info_t *)core->codec_info;
+ mc_gst_port_def_t *input_port_def = &core->ports[in_port_index]->port_def;
if (core->video) {
gint width = 0;
gint height = 0;
gint bitrate = 0;
+ gint framerate = 0;
+ gchar *sformat = NULL;
+ media_format_mimetype_e mimetype = 0;
- media_format_get_video_info(fmt, NULL, &width, &height, &bitrate, NULL);
+ media_format_get_video_info(format, &mimetype, &width, &height, &bitrate, NULL);
+ media_format_get_video_frame_rate(format, &framerate);
- if ((codec_info->width != width) || (codec_info->height != height)) {
- LOGD("Resolution changed : %dx%d -> %dx%d", codec_info->width, codec_info->height, width, height);
- codec_info->width = width;
- codec_info->height = height;
- is_updated = TRUE;
+ is_format_change |= input_port_def->info.video.width != width;
+ is_format_change |= input_port_def->info.video.height != height;
+ is_format_change |= ((input_port_def->info.video.framerate != framerate) && (framerate != 0));
+ if (is_format_change) {
+ LOGD("Format changed : resolution %dx%d -> %dx%d, framerate %d -> %d",
+ input_port_def->info.video.width, input_port_def->info.video.height, width, height,
+ input_port_def->info.video.framerate, framerate);
+ input_port_def->info.video.width = width;
+ input_port_def->info.video.height = height;
}
if (core->encoder) {
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- if (bitrate != 0 && enc_info->bitrate != bitrate * 1000) {
- LOGD("Bitrate changed : %d -> %d", enc_info->bitrate, bitrate);
- enc_info->bitrate = bitrate * 1000;
- is_updated = TRUE;
+ sformat = __mc_get_gst_input_format(mimetype, core->is_hw);
+ is_format_change |= ((input_port_def->info.video.bitrate != bitrate * 1000) && (bitrate != 0));
+ is_format_change |= g_strcmp0(input_port_def->info.video.format, sformat);
+ if (is_format_change) {
+ LOGD("Bitrate changed : %d -> %d", input_port_def->info.video.bitrate, bitrate);
+ LOGD("Format changed : %s -> %s", input_port_def->info.video.format, sformat);
+ input_port_def->info.video.bitrate = bitrate * 1000;
+ input_port_def->info.video.format = g_strdup(sformat);
}
}
} else {
gint bit;
gint bitrate;
- media_format_get_audio_info(fmt, NULL, &channel, &samplerate, &bit, &bitrate);
+ media_format_get_audio_info(format, NULL, &channel, &samplerate, &bit, &bitrate);
- if ((codec_info->channel != channel) || (codec_info->samplerate != samplerate) || (codec_info->bit != bit)) {
- LOGD("Audio info. changed : %d -> %d, %d -> %d, %d -> %d", codec_info->channel, channel, codec_info->samplerate, samplerate, codec_info->bit, bit);
- codec_info->channel = channel;
- codec_info->samplerate = samplerate;
- codec_info->bit = bit;
- is_updated = TRUE;
+ is_format_change |= input_port_def->info.audio.channel != channel;
+ is_format_change |= input_port_def->info.audio.samplerate != samplerate;
+ is_format_change |= input_port_def->info.audio.bit_depth != bit;
+ if (is_format_change) {
+ LOGD("Audio info. changed : %d -> %d, %d -> %d, %d -> %d",
+ input_port_def->info.audio.channel, channel,
+ input_port_def->info.audio.samplerate, samplerate,
+ input_port_def->info.audio.bit_depth, bit);
+ input_port_def->info.audio.channel = channel;
+ input_port_def->info.audio.samplerate = samplerate;
+ input_port_def->info.audio.bit_depth = bit;
}
if (core->encoder) {
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- if (bitrate != 0 && enc_info->bitrate != bitrate * 1000) {
- LOGD("Bitrate changed : %d -> %d", enc_info->bitrate, bitrate);
- enc_info->bitrate = bitrate * 1000;
- is_updated = TRUE;
+ is_format_change |= ((input_port_def->info.audio.bitrate != bitrate * 1000) && (bitrate != 0));
+ if (is_format_change) {
+ LOGD("Bitrate changed : %d -> %d", input_port_def->info.audio.bitrate, bitrate);
+ input_port_def->info.audio.bitrate = bitrate * 1000;
}
}
}
- return is_updated;
+ return is_format_change;
}
-static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *mcbuffer, bool codec_config)
+static int _mc_set_codec_data(mc_gst_core_t *core, GstMCBuffer *mcbuffer, bool codec_config)
{
MEDIACODEC_FENTER();
int ret = MC_ERROR_NONE;
- if (core->video) {
- if (core->encoder) {
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- core->format = __mc_get_gst_input_format(mcbuffer->packet, core->is_hw);
- gst_caps_set_simple(core->caps,
- "format", G_TYPE_STRING, core->format,
- "width", G_TYPE_INT, enc_info->width,
- "height", G_TYPE_INT, enc_info->height,
- "framerate", GST_TYPE_FRACTION, enc_info->fps, 1,
- NULL);
-
- if (g_object_class_find_property(G_OBJECT_GET_CLASS(core->codec), "bitrate"))
- g_object_set(GST_OBJECT(core->codec), "bitrate", enc_info->bitrate, NULL);
- else
- g_object_set(GST_OBJECT(core->codec), "target-bitrate", enc_info->bitrate, NULL);
- LOGD("set bitrate = %d.", enc_info->bitrate);
- } else {
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- gst_caps_set_simple(core->caps,
- "width", G_TYPE_INT, dec_info->width,
- "height", G_TYPE_INT, dec_info->height,
- NULL);
-
- ret = __mc_set_caps_codecdata(core, mcbuffer, CODECDATA_NOT_USE);
+ switch (core->codec_id) {
+ case MEDIACODEC_AAC:
+ case MEDIACODEC_AAC_HE:
+ case MEDIACODEC_AAC_HE_PS:
+ if (codec_config) {
+ ret = __mc_set_caps_codecdata(core, mcbuffer, AAC_CODECDATA_SIZE);
if (ret != MC_ERROR_NONE)
LOGW("__mc_set_caps_codecdata failed");
}
- } else {
- if (core->encoder) {
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- gst_caps_set_simple(core->caps,
- "format", G_TYPE_STRING, _mc_bit_to_string(enc_info->bit),
- "rate", G_TYPE_INT, enc_info->samplerate,
- "channels", G_TYPE_INT, enc_info->channel,
- NULL);
- g_object_set(GST_OBJECT(core->codec), "bitrate", enc_info->bitrate, NULL);
- } else {
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- gst_caps_set_simple(core->caps,
- "rate", G_TYPE_INT, dec_info->samplerate,
- "channels", G_TYPE_INT, dec_info->channel,
- NULL);
-
- if (codec_config) {
- switch (core->codec_id) {
- case MEDIACODEC_AAC:
- case MEDIACODEC_AAC_HE:
- case MEDIACODEC_AAC_HE_PS:
- ret = __mc_set_caps_codecdata(core, mcbuffer, AAC_CODECDATA_SIZE);
- if (ret != MC_ERROR_NONE)
- LOGW("__mc_set_caps_codecdata failed");
- break;
- case MEDIACODEC_WMAV1:
- case MEDIACODEC_WMAV2:
- case MEDIACODEC_WMAPRO:
- case MEDIACODEC_WMALSL:
- ret = __mc_set_caps_codecdata(core, mcbuffer, WMA_CODECDATA_SIZE);
- if (ret != MC_ERROR_NONE)
- LOGW("__mc_set_caps_codecdata failed");
- break;
- case MEDIACODEC_VORBIS:
- case MEDIACODEC_FLAC:
- ret = __mc_set_caps_streamheader(core, mcbuffer, VORBIS_CODECDATA_SIZE);
- if (ret != MC_ERROR_NONE)
- LOGW("__mc_set_caps_streamheader failed");
- break;
- default:
- LOGD("doesn't need to set codecdata");
- break;
-
- }
- }
+ break;
+ case MEDIACODEC_WMAV1:
+ case MEDIACODEC_WMAV2:
+ case MEDIACODEC_WMAPRO:
+ case MEDIACODEC_WMALSL:
+ if (codec_config) {
+ ret = __mc_set_caps_codecdata(core, mcbuffer, WMA_CODECDATA_SIZE);
+ if (ret != MC_ERROR_NONE)
+ LOGW("__mc_set_caps_codecdata failed");
}
+ break;
+ case MEDIACODEC_VORBIS:
+ case MEDIACODEC_FLAC:
+ case MEDIACODEC_OPUS:
+ if (codec_config) {
+ ret = __mc_set_caps_streamheader(core, mcbuffer, VORBIS_CODECDATA_SIZE);
+ if (ret != MC_ERROR_NONE)
+ LOGW("__mc_set_caps_streamheader failed");
+ }
+ break;
+ case MEDIACODEC_H264:
+ case MEDIACODEC_MPEG4:
+ ret = __mc_set_caps_codecdata(core, mcbuffer, CODECDATA_NOT_USE);
+ if (ret != MC_ERROR_NONE)
+ LOGW("__mc_set_caps_codecdata failed");
+ break;
+ default:
+ LOGD("doesn't need to set codecdata");
+ break;
}
- g_object_set(core->appsrc, "caps", core->caps, NULL);
MEDIACODEC_FLEAVE();
return ret;
+
+
}
static gpointer feed_task(gpointer data)
bool codec_config = FALSE;
bool eos = FALSE;
bool initiative = TRUE;
- media_format_h fmt = NULL;
- media_packet_h in_buf = NULL;
+ bool is_format_change = FALSE;
+ media_format_h format = NULL;
+ media_packet_h input_buffer = NULL;
GstMCBuffer *mcbuffer = NULL;
MEDIACODEC_FENTER();
while (g_atomic_int_get(&core->available_queue->running)) {
LOGD("waiting for next input....");
- in_buf = _mc_get_input_buffer(core);
- if (!in_buf)
+ input_buffer = _mc_get_input_buffer(core);
+ if (!input_buffer)
goto LEAVE;
- media_packet_get_format(in_buf, &fmt);
- if (fmt) {
- if (_mc_update_packet_info(core, fmt))
- initiative = TRUE;
- media_format_unref(fmt);
+ media_packet_get_format(input_buffer, &format);
+ if (format) {
+ if (_mc_update_packet_info(core, format))
+ is_format_change = TRUE;
+ media_format_unref(format);
}
- if (media_packet_is_codec_config(in_buf, &codec_config) != MEDIA_PACKET_ERROR_NONE) {
+ if (media_packet_is_codec_config(input_buffer, &codec_config) != MEDIA_PACKET_ERROR_NONE) {
LOGE("media_packet_is_codec_config failed");
goto ERROR;
}
- if (media_packet_is_end_of_stream(in_buf, &eos) != MEDIA_PACKET_ERROR_NONE) {
+ if (media_packet_is_end_of_stream(input_buffer, &eos) != MEDIA_PACKET_ERROR_NONE) {
LOGE("media_packet_is_end_of_stream failed");
goto ERROR;
}
LOGD("end of stream");
gst_app_src_end_of_stream(GST_APP_SRC(core->appsrc));
_mc_wait_for_eos(core);
- initiative = true;
+ initiative = TRUE;
- _mc_gst_handle_input_buffer_used(core, in_buf);
+ _mc_gst_handle_input_buffer_used(core, input_buffer);
goto LEAVE;
}
- mcbuffer = _mc_gst_media_packet_to_gstbuffer(core, in_buf, codec_config);
+ mcbuffer = _mc_gst_media_packet_to_gstbuffer(core, input_buffer, codec_config);
if (!mcbuffer) {
LOGW("gstbuffer can't make");
goto ERROR;
}
- /* mcbuffer took the ownership of the in_buf, so set in_buf to NULL to aviod double unref */
- in_buf = NULL;
-
- if (codec_config)
- initiative = TRUE;
-
- if (initiative) {
- GstPad *pad;
-
- ret = _mc_gst_update_caps(core, mcbuffer, codec_config);
- if (ret != MC_ERROR_NONE) {
- LOGE("failed to update caps");
- /* unref mcbuff->buffer will invoke the finalize() of GstMcBuffer */
- gst_buffer_unref(mcbuffer->buffer);
- goto ERROR;
+ /* mcbuffer took the ownership of the input_buffer, so set input_buffer to NULL to aviod double unref */
+ input_buffer = NULL;
+
+ if (codec_config || initiative) {
+ GstPad *pad = NULL;
+ if (!core->encoder) {
+ ret = _mc_set_codec_data(core, mcbuffer, codec_config);
+ if (ret != MC_ERROR_NONE) {
+ LOGE("failed to set codec data");
+ gst_buffer_unref(mcbuffer->buffer);
+ goto ERROR;
+ }
}
-
pad = gst_element_get_static_pad(core->appsrc, "src");
gst_pad_push_event(pad, gst_event_new_stream_start("start"));
gst_object_unref(pad);
+ is_format_change = TRUE;
+ initiative = FALSE;
+ core->offset = GST_BUFFER_OFFSET_NONE;
+ }
+ if (is_format_change) {
+ GstCaps *caps;
+ caps = core->mc_caps_new(core, core->codec_id, in_port_index);
+ g_object_set(core->appsrc, "caps", caps, NULL);
+ gst_caps_unref(caps);
LOGD("caps updated");
+ is_format_change = FALSE;
}
+
/* inject buffer */
ret = _mc_gst_gstbuffer_to_appsrc(core, mcbuffer);
if (ret != GST_FLOW_OK) {
goto ERROR;
}
- initiative = false;
-
continue;
ERROR:
- if (in_buf)
- _mc_gst_handle_input_buffer_used(core, in_buf);
+ if (input_buffer)
+ _mc_gst_handle_input_buffer_used(core, input_buffer);
_mc_gst_set_flush_input(core);
continue;
LEAVE:
- /*LOGE("status : in_buf : %p, codec_config : %d, eos : %d, encoder : %d in feed_task", in_buf, codec_config, eos, core->encoder);*/
+ /*LOGE("status : input_buffer : %p, codec_config : %d, eos : %d, encoder : %d in feed_task", input_buffer, codec_config, eos, core->encoder);*/
continue;
}
- LOGI("status : in_buf : %p, codec_config : %d, eos : %d, video : %d, encoder : %d in feed_task",
- in_buf, codec_config, eos, core->video, core->encoder);
+ LOGI("status : input_buffer : %p, codec_config : %d, eos : %d, video : %d, encoder : %d in feed_task",
+ input_buffer, codec_config, eos, core->video, core->encoder);
LOGD("feed task finished %p v(%d)e(%d)", core, core->video, core->encoder);
MEDIACODEC_FLEAVE();
}
}
-static int _mc_link_vtable(mc_gst_core_t *core, mediacodec_codec_type_e id, gboolean encoder, gboolean is_hw)
+GstCaps *_mc_gst_aud_caps_new(mc_gst_core_t *core, mediacodec_codec_type_e codec_id, gint index)
{
- MEDIACODEC_FENTER();
+ GstCaps *caps = NULL;
+ mc_gst_port_def_t *port_def = &core->ports[index]->port_def;
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
+ caps = gst_caps_new_simple(core->mime,
+ "rate", G_TYPE_INT, port_def->info.audio.samplerate,
+ "channels", G_TYPE_INT, port_def->info.audio.channel, NULL);
- switch (id) {
+ switch (codec_id) {
case MEDIACODEC_AAC:
- /* if set to 'CODEC_CONFIG', then It is also available case of MEDIA_FORMAT_AAC_LC (RAW) */
- LOGD("aac lc (adts) vtable");
- if (encoder) {
- core->vtable = aenc_aac_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "layout", G_TYPE_STRING, "interleaved", NULL);
+ if (core->encoder) {
+ gst_caps_set_simple(caps,
+ "format", G_TYPE_STRING, _mc_bit_to_string(port_def->info.audio.bit_depth),
+ "layout", G_TYPE_STRING, "interleaved", NULL);
g_object_set(GST_OBJECT(core->codec), "compliance", -2, NULL);
} else {
+ gst_caps_set_simple(caps,
+ "framed", G_TYPE_BOOLEAN, TRUE,
+ "mpegversion", G_TYPE_INT, 4,
+ "stream-format", G_TYPE_STRING, "adts",
+ NULL);
LOGD("CAPS for codec_id (MEDIACODEC_AAC_LC - normal ADTS)");
-
- core->vtable = adec_aac_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "framed", G_TYPE_BOOLEAN, TRUE,
- "mpegversion", G_TYPE_INT, 4,
- "stream-format", G_TYPE_STRING, "adts",
- NULL);
}
break;
case MEDIACODEC_AAC_HE:
case MEDIACODEC_AAC_HE_PS:
- LOGD("aac he v12 vtable");
- if (encoder) {
+ if (core->encoder) {
LOGD("[MC_NOT_SUPPORTED] he-aac-v12 encoder is not supported yet!!!");
- return MC_NOT_SUPPORTED;
+ return NULL;
} else {
- LOGD("CAPS for codec_id (MEDIACODEC_AAC_HE and _PS - MP4/M4A case)");
- core->vtable = adec_aacv12_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "mpegversion", G_TYPE_INT, 4, /*TODO : need adding version /profile*/
- "framed", G_TYPE_BOOLEAN, TRUE,
- "stream-format", G_TYPE_STRING, "raw",
- NULL);
+ gst_caps_set_simple(caps,
+ "mpegversion", G_TYPE_INT, 4,
+ "framed", G_TYPE_BOOLEAN, TRUE,
+ "stream-format", G_TYPE_STRING, "raw",
+ NULL);
+ LOGD("CAPS for codec_id (MEDIACODEC_AAC_HE)");
}
break;
case MEDIACODEC_MP3:
- LOGD("mp3 vtable - Only support decoder");
- if (encoder) {
+ if (core->encoder) {
LOGD("[MC_NOT_SUPPORTED] mp3 encoder is not supported yet!!!");
- return MC_NOT_SUPPORTED;
+ return NULL;
} else {
- core->vtable = adec_mp3_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "framed", G_TYPE_BOOLEAN, TRUE,
- "mpegversion", G_TYPE_INT, 1, /* To-Do : plz check */
- "mpegaudioversion", G_TYPE_INT, 1, /* To-Do : plz check */
- "layer", G_TYPE_INT, 3, /* To-Do : plz check */
- NULL);
+ gst_caps_set_simple(caps,
+ "framed", G_TYPE_BOOLEAN, TRUE,
+ "mpegversion", G_TYPE_INT, 1, /* To-Do : plz check */
+ "mpegaudioversion", G_TYPE_INT, 1, /* To-Do : plz check */
+ "layer", G_TYPE_INT, 3, /* To-Do : plz check */
+ NULL);
+ LOGD("CAPS for codec_id (MEDIACODEC_MP3)");
}
break;
case MEDIACODEC_AMR_NB:
- LOGD("amrnb vtable");
- if (encoder) {
- core->vtable = aenc_amrnb_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "format", G_TYPE_STRING, "S16LE",
- "layout", G_TYPE_STRING, "interleaved",
- NULL);
-
+ if (core->encoder) {
+ gst_caps_set_simple(caps,
+ "format", G_TYPE_STRING, _mc_bit_to_string(port_def->info.audio.bit_depth),
+ "layout", G_TYPE_STRING, "interleaved",
+ NULL);
+ LOGD("CAPS for codec_id (MEDIACODEC_AMR_NB)");
} else {
- core->vtable = adec_amrnb_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "rate", G_TYPE_INT, 8000,
- NULL);
+ gst_caps_set_simple(caps,
+ "rate", G_TYPE_INT, 8000,
+ NULL);
}
break;
case MEDIACODEC_AMR_WB:
- LOGD("amrwb vtable - Only support decoder");
- if (encoder) {
+ if (core->encoder) {
LOGD("[MC_NOT_SUPPORTED] amr-wb encoder is not supported yet!!!");
- return MC_NOT_SUPPORTED;
+ return NULL;
} else {
- core->vtable = adec_amrwb_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "rate", G_TYPE_INT, 16000,
- NULL);
+ gst_caps_set_simple(caps,
+ "rate", G_TYPE_INT, 16000,
+ NULL);
}
break;
case MEDIACODEC_VORBIS:
- LOGD("vorbis vtable");
- if (encoder) {
+ if (core->encoder) {
LOGD("[MC_NOT_SUPPORTED] vorbis encoder is not supported yet!!!");
- return MC_NOT_SUPPORTED;
+ return NULL;
} else {
- core->vtable = adec_vorbis_vtable;
- core->caps = gst_caps_new_empty_simple("audio/x-vorbis");
}
break;
case MEDIACODEC_FLAC:
- LOGD("flac vtable");
- if (encoder) {
+ if (core->encoder) {
LOGD("[MC_NOT_SUPPORTED] flac encoder is not supported yet!!!");
- return MC_NOT_SUPPORTED;
+ return NULL;
} else {
- core->vtable = adec_flac_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "framed", G_TYPE_BOOLEAN, TRUE,
- /* FIXME - Insert More Info */
- NULL);
+ gst_caps_set_simple(caps,
+ "framed", G_TYPE_BOOLEAN, TRUE,
+ /* FIXME - Insert More Info */
+ NULL);
}
break;
case MEDIACODEC_WMAV1:
case MEDIACODEC_WMAV2:
case MEDIACODEC_WMAPRO:
case MEDIACODEC_WMALSL:
- LOGD("wma(V1 / V2 / LSL / PRO) vtable");
- if (encoder) {
+ if (core->encoder) {
LOGD("[MC_NOT_SUPPORTED] wma encoder is not supported yet!!!");
- return MC_NOT_SUPPORTED;
+ return NULL;
} else {
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- core->vtable = adec_wma_vtable;
-
/*
* Need to extract from Stream Type Specific ... or
* Need to get Demuxer's Caps from Stream Type Specific
LOGE("Not support WMA format");
}
- core->caps = gst_caps_new_simple(core->mime,
- "bitrate", G_TYPE_INT, bitrate,
- "depth", G_TYPE_INT, dec_info->bit,
- /* FIXME - Need More Info */
- "wmaversion", G_TYPE_INT, wma_version,
- "format_tag", G_TYPE_INT, format_tag,
- "block_align", G_TYPE_INT, block_align,
- NULL);
+ gst_caps_set_simple(caps,
+ "bitrate", G_TYPE_INT, bitrate,
+ "depth", G_TYPE_INT, port_def->info.audio.bit_depth,
+ /* FIXME - Need More Info */
+ "wmaversion", G_TYPE_INT, wma_version,
+ "format_tag", G_TYPE_INT, format_tag,
+ "block_align", G_TYPE_INT, block_align,
+ NULL);
+ }
+ break;
+ case MEDIACODEC_OPUS:
+ if (core->encoder) {
+ gst_caps_set_simple(caps,
+ "format", G_TYPE_STRING, _mc_bit_to_string(port_def->info.audio.bit_depth),
+ "layout", G_TYPE_STRING, "interleaved", NULL);
+ } else {
+ LOGD("[MC_NOT_SUPPORTED] opus decoder is not supported yet!!!");
+ return NULL;
+ }
+ break;
+ default:
+ break;
+ }
+ return caps;
+}
+
+GstCaps *_mc_gst_vid_caps_new(mc_gst_core_t *core, mediacodec_codec_type_e codec_id, gint index)
+{
+ GstCaps *caps = NULL;
+ mc_gst_port_def_t *port_def = &core->ports[index]->port_def;
+
+ caps = gst_caps_new_simple(core->mime,
+ "width", G_TYPE_INT, port_def->info.video.width,
+ "height", G_TYPE_INT, port_def->info.video.height,
+ "framerate", GST_TYPE_FRACTION, port_def->info.video.framerate, 1,
+ NULL);
+
+ switch (codec_id) {
+ case MEDIACODEC_H263:
+ if (core->encoder) {
+ gst_caps_set_simple(caps,
+ "format", G_TYPE_STRING, port_def->info.video.format,
+ NULL);
+ } else {
+ gst_caps_set_simple(caps,
+ "mpegversion", G_TYPE_INT, 4,
+ "framerate", GST_TYPE_FRACTION, 30, 1,
+ NULL);
+ }
+ break;
+ case MEDIACODEC_MPEG4:
+ if (core->encoder) {
+ gst_caps_set_simple(caps,
+ "format", G_TYPE_STRING, port_def->info.video.format,
+ NULL);
+ } else {
+ gst_caps_set_simple(caps,
+ "mpegversion", G_TYPE_INT, 4,
+ "systemstream", G_TYPE_BOOLEAN, false,
+ "parsed", G_TYPE_BOOLEAN, TRUE,
+ "framerate", GST_TYPE_FRACTION, 30, 1,
+ NULL);
+ }
+ break;
+ case MEDIACODEC_H264:
+ if (core->encoder) {
+ gst_caps_set_simple(caps,
+ "format", G_TYPE_STRING, port_def->info.video.format,
+ NULL);
+ g_object_set(GST_OBJECT(core->codec), "byte-stream", TRUE, NULL);
+ LOGE("format : %s", port_def->info.video.format);
+ } else {
+ gst_caps_set_simple(caps,
+ "parsed", G_TYPE_BOOLEAN, TRUE, /* FIXME different from sw */
+ "alignment", G_TYPE_STRING, "au",
+ "stream-format", G_TYPE_STRING, "byte-stream",
+ "framerate", GST_TYPE_FRACTION, 30, 1,
+ NULL);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return caps;
+}
+
+static int _mc_link_vtable(mc_gst_core_t *core, mediacodec_codec_type_e id, gboolean encoder, gboolean is_hw)
+{
+ MEDIACODEC_FENTER();
+
+ g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
+
+ switch (id) {
+ case MEDIACODEC_AAC:
+ if (encoder)
+ core->vtable = aenc_aac_vtable;
+ else
+ core->vtable = adec_aac_vtable;
+ break;
+ case MEDIACODEC_AAC_HE:
+ case MEDIACODEC_AAC_HE_PS:
+ if (encoder) {
+ LOGD("[MC_NOT_SUPPORTED] he-aac-v12 encoder is not supported yet!!!");
+ return MC_NOT_SUPPORTED;
+ } else {
+ core->vtable = adec_aacv12_vtable;
+ }
+ break;
+ case MEDIACODEC_MP3:
+ if (encoder) {
+ LOGD("[MC_NOT_SUPPORTED] mp3 encoder is not supported yet!!!");
+ return MC_NOT_SUPPORTED;
+ } else {
+ core->vtable = adec_mp3_vtable;
+ }
+ break;
+ case MEDIACODEC_AMR_NB:
+ LOGD("amrnb vtable");
+ if (encoder)
+ core->vtable = aenc_amrnb_vtable;
+ else
+ core->vtable = adec_amrnb_vtable;
+ break;
+ case MEDIACODEC_AMR_WB:
+ LOGD("amrwb vtable - Only support decoder");
+ if (encoder) {
+ LOGD("[MC_NOT_SUPPORTED] amr-wb encoder is not supported yet!!!");
+ return MC_NOT_SUPPORTED;
+ } else {
+ core->vtable = adec_amrwb_vtable;
+ }
+ break;
+ case MEDIACODEC_VORBIS:
+ LOGD("vorbis vtable");
+ if (encoder)
+ return MC_NOT_SUPPORTED;
+ else
+ core->vtable = adec_vorbis_vtable;
+ break;
+ case MEDIACODEC_FLAC:
+ LOGD("flac vtable");
+ if (encoder) {
+ LOGD("[MC_NOT_SUPPORTED] flac encoder is not supported yet!!!");
+ return MC_NOT_SUPPORTED;
+ } else {
+ core->vtable = adec_flac_vtable;
+ }
+ break;
+ case MEDIACODEC_OPUS:
+ LOGD("opus vtable");
+ if (encoder)
+ core->vtable = aenc_opus_vtable;
+ else
+ core->vtable = adec_vtable;
+ break;
+ case MEDIACODEC_WMAV1:
+ case MEDIACODEC_WMAV2:
+ case MEDIACODEC_WMAPRO:
+ case MEDIACODEC_WMALSL:
+ LOGD("wma(V1 / V2 / LSL / PRO) vtable");
+ if (encoder) {
+ LOGD("[MC_NOT_SUPPORTED] wma encoder is not supported yet!!!");
+ return MC_NOT_SUPPORTED;
+ } else {
+ core->vtable = adec_wma_vtable;
}
break;
case MEDIACODEC_H263:
LOGD("h263 vtable");
if (encoder) {
core->vtable = is_hw ? venc_h263_hw_vtable : venc_h263_sw_vtable;
- core->caps = gst_caps_new_empty_simple("video/x-raw");
} else {
- if (is_hw) {
+ if (is_hw)
core->vtable = vdec_h263_hw_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "mpegversion", G_TYPE_INT, 4,
- "framerate", GST_TYPE_FRACTION, 30, 1,
- NULL);
- } else {
+ else
core->vtable = vdec_h263_sw_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "variant", G_TYPE_STRING, "itu",
- "framerate", GST_TYPE_FRACTION, 30, 1,
- NULL);
- }
}
break;
case MEDIACODEC_MPEG4:
LOGD("mpeg4 vtable");
- if (encoder) {
+ if (encoder)
core->vtable = is_hw ? venc_mpeg4_hw_vtable : venc_mpeg4_sw_vtable;
- core->caps = gst_caps_new_empty_simple("video/x-raw");
- } else {
+ else
core->vtable = is_hw ? vdec_mpeg4_hw_vtable : vdec_mpeg4_sw_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "mpegversion", G_TYPE_INT, 4,
- "systemstream", G_TYPE_BOOLEAN, false,
- "parsed", G_TYPE_BOOLEAN, TRUE,
- "framerate", GST_TYPE_FRACTION, 30, 1,
- NULL);
- }
break;
case MEDIACODEC_H264:
LOGD("h264 vtable");
if (encoder) {
core->vtable = is_hw ? venc_h264_hw_vtable : venc_vtable;
- core->caps = gst_caps_new_empty_simple("video/x-raw");
- g_object_set(GST_OBJECT(core->codec), "byte-stream", TRUE, NULL);
} else {
- if (is_hw) {
+ if (is_hw)
core->vtable = vdec_h264_hw_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "parsed", G_TYPE_BOOLEAN, TRUE,
- "alignment", G_TYPE_STRING, "au",
- "stream-format", G_TYPE_STRING, "byte-stream",
- "framerate", GST_TYPE_FRACTION, 30, 1,
- NULL);
- } else {
+ else
core->vtable = vdec_h264_sw_vtable;
- core->caps = gst_caps_new_simple(core->mime,
- "alignment", G_TYPE_STRING, "au",
- "stream-format", G_TYPE_STRING, "byte-stream",
- "framerate", GST_TYPE_FRACTION, 30, 1,
- NULL);
- }
}
break;
default:
break;
}
- /* set caps */
- g_object_set(core->appsrc, "caps", core->caps, NULL);
MEDIACODEC_FLEAVE();
static gint _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *mcbuffer)
{
- gint ret = MC_ERROR_NONE;
-
- MEDIACODEC_FENTER();
-
- ret = gst_app_src_push_buffer(GST_APP_SRC(core->appsrc), mcbuffer->buffer);
- LOGD("pushed buffer to appsrc : %p, buffer of size %" G_GSIZE_FORMAT "",
- mcbuffer->buffer, gst_buffer_get_size(mcbuffer->buffer));
-
- MEDIACODEC_FLEAVE();
-
- return ret;
+ return gst_app_src_push_buffer(GST_APP_SRC(core->appsrc), mcbuffer->buffer);
}
media_packet_h _mc_get_input_buffer(mc_gst_core_t *core)
media_format_mimetype_e out_mime;
int num_supported_codec = 0;
int i = 0;
+ GstCaps *caps = NULL;
if (!mc_handle)
return MC_PARAM_ERROR;
new_core->eos = false;
new_core->encoder = encoder;
new_core->video = video;
- new_core->codec_info = encoder ? (void *)&mc_handle->info.encoder : (void *)&mc_handle->info.decoder;
- new_core->out_mime = codec_map[i].type.out_format;
+ memcpy(&new_core->ports[in_port_index]->port_def.info, &mc_handle->info, sizeof(mc_handle->info));
+ memcpy(&new_core->ports[out_port_index]->port_def.info, &mc_handle->info, sizeof(mc_handle->info));
+ new_core->ports[out_port_index]->port_def.coding_type = out_mime;
new_core->codec_id = id;
+ new_core->mc_caps_new = video ? &_mc_gst_vid_caps_new : &_mc_gst_aud_caps_new;
new_core->bufmgr = tbm_bufmgr_init(new_core->drm_fd);
if (new_core->bufmgr == NULL) {
}
}
- mc_handle->core = new_core;
-
/* create basic core elements */
- ret = _mc_gst_create_pipeline(mc_handle->core, factory_name);
+ ret = _mc_gst_create_pipeline(new_core, factory_name);
if (ret != MC_ERROR_NONE) {
LOGE("failed to create pipeline");
return ret;
}
/* link vtable */
- ret = _mc_link_vtable(mc_handle->core, id, encoder, hardware);
+ ret = _mc_link_vtable(new_core, id, encoder, hardware);
if (ret != MC_ERROR_NONE) {
LOGE("vtable link failed");
return ret;
}
+ /* set caps in capsfilter as default*/
+ caps = new_core->mc_caps_new(new_core, id, out_port_index);
+
+ new_core->caps = caps;
+ /* FIXME will parse input format from ini. format is needed when linking elements*/
+ if (new_core->video && new_core->encoder) {
+ gchar *format = NULL;
+
+ format = new_core->is_hw ? "SN12" : "I420";
+ gst_caps_set_simple(caps,
+ "format", G_TYPE_STRING, format,
+ NULL);
+ }
+ g_object_set(new_core->capsfilter, "caps", caps, NULL);
+ gst_caps_unref(caps);
+
+ mc_handle->core = new_core;
LOGD("initialized... %d", ret);
MEDIACODEC_FLEAVE();
return ret;
}
-mc_ret_e mc_gst_process_input(mc_handle_t *mc_handle, media_packet_h inbuf, uint64_t timeOutUs)
+mc_ret_e mc_gst_process_input(mc_handle_t *mc_handle, media_packet_h inbuf, uint64_t timeout_us)
{
MEDIACODEC_FENTER();
return ret;
}
-mc_ret_e mc_gst_get_output(mc_handle_t *mc_handle, media_packet_h *outbuf, uint64_t timeOutUs)
+mc_ret_e mc_gst_get_output(mc_handle_t *mc_handle, media_packet_h *outbuf, uint64_t timeout_us)
{
gint ret = MC_ERROR_NONE;
gint64 end_time = -1;
media_packet_h out_packet = NULL;
MEDIACODEC_FENTER();
- end_time = g_get_monotonic_time() + timeOutUs;
+ end_time = g_get_monotonic_time() + timeout_us;
if (!mc_handle)
return MC_PARAM_ERROR;
return FALSE;
}
-mc_ret_e _mc_gst_create_pipeline(mc_gst_core_t *core, gchar *factory_name)
+mc_ret_e _mc_gst_create_pipeline(mc_gst_core_t *core, const gchar *factory_name)
{
GstBus *bus = NULL;
LOGE("capsfilter can't create");
goto ERROR;
}
+
+ core->audioresample = gst_element_factory_make("audioresample", NULL);
+
+ if (!core->audioresample) {
+ LOGE("capsfilter can't create");
+ goto ERROR;
+ }
+ }
+
+ if (core->video && core->encoder) {
+ core->videoconvert = gst_element_factory_make("videoconvert", NULL);
+
+ if (!core->videoconvert) {
+ LOGE("videoconvert can't create");
+ goto ERROR;
+ }
+
+ core->videoscale = gst_element_factory_make("videoscale", NULL);
+ if (!core->videoscale) {
+ LOGE("videoscale can't create");
+ goto ERROR;
+ }
}
core->capsfilter = gst_element_factory_make("capsfilter", NULL);
/*__mc_link_elements(core);*/
if (!core->video && core->encoder) {
- gst_bin_add_many(GST_BIN(core->pipeline), core->appsrc, core->capsfilter, core->audioconvert, core->codec, core->fakesink, NULL);
+ gst_bin_add_many(GST_BIN(core->pipeline), core->appsrc, core->audioresample, core->audioconvert, core->capsfilter, core->codec, core->fakesink, NULL);
+
+ /* link elements */
+ if (!(gst_element_link_many(core->appsrc, core->audioresample, core->audioconvert, core->capsfilter, core->codec, core->fakesink, NULL))) {
+ LOGE("gst_element_link_many is failed");
+ goto ERROR;
+ }
+ } else if (core->video && core->encoder) {
+ gst_bin_add_many(GST_BIN(core->pipeline), core->appsrc, core->capsfilter, core->codec, core->fakesink, NULL);
/* link elements */
- if (!(gst_element_link_many(core->appsrc, core->capsfilter, core->audioconvert, core->codec, core->fakesink, NULL))) {
+ if (!(gst_element_link_many(core->appsrc, core->codec, core->fakesink, NULL))) {
LOGE("gst_element_link_many is failed");
goto ERROR;
}
if (core->capsfilter)
gst_object_unref(GST_OBJECT(core->capsfilter));
+ if (core->audioresample)
+ gst_object_unref(GST_OBJECT(core->audioresample));
+
+ if (core->videoscale)
+ gst_object_unref(GST_OBJECT(core->videoscale));
+
+ if (core->videoconvert)
+ gst_object_unref(GST_OBJECT(core->videoconvert));
+
if (core->audioconvert)
gst_object_unref(GST_OBJECT(core->audioconvert));
int __mc_output_buffer_finalize_cb(media_packet_h packet, int error_code, void *user_data)
{
- int i = 0;
- guint n;
- GstMemory *mem;
- GstMapInfo map = GST_MAP_INFO_INIT;
- MMVideoBuffer *mm_video_buf = NULL;
-
MEDIACODEC_FENTER();
GstMCBuffer *mcbuffer = (GstMCBuffer *)user_data;
- if (mcbuffer->buffer) {
- n = gst_buffer_n_memory(mcbuffer->buffer);
-
- if (n > 1) {
- mem = gst_buffer_peek_memory(mcbuffer->buffer, n-1);
- gst_memory_map(mem, &map, GST_MAP_READ);
- mm_video_buf = (MMVideoBuffer *)map.data;
-
- if (!mm_video_buf) {
- LOGW("gstbuffer map.data is null");
- } else {
- for (i = 0; i < MM_VIDEO_BUFFER_PLANE_MAX; i++) {
- if (mm_video_buf->handle.bo[i])
- tbm_bo_unref(mm_video_buf->handle.bo[i]);
- }
- }
- gst_memory_unmap(mem, &map);
- }
- gst_buffer_unref((GstBuffer *)mcbuffer->buffer);
- }
+ gst_buffer_unref((GstBuffer *)mcbuffer->buffer);
if (mcbuffer->ext_mem) {
g_free(mcbuffer->ext_mem);
return MEDIA_PACKET_FINALIZE;
}
-gchar *__mc_get_gst_input_format(media_packet_h packet, bool is_hw)
+gchar *__mc_get_gst_input_format(media_format_mimetype_e mimetype, bool is_hw)
{
gchar *format = NULL;
- media_format_h fmt = NULL;
- media_format_mimetype_e mimetype = 0;
-
- media_packet_get_format(packet, &fmt);
- media_format_get_video_info(fmt, &mimetype, NULL, NULL, NULL, NULL);
- media_format_unref(fmt);
- LOGD("input packet mimetype : %x", mimetype);
switch (mimetype) {
case MEDIA_FORMAT_I420:
* will not be invoked
*/
gst_buffer_unref(mcbuffer->buffer);
- free(mcbuffer);
+ g_free(mcbuffer);
return NULL;
}
media_packet_get_duration(packet, &dur);
GST_BUFFER_DURATION(mcbuffer->buffer) = dur;
+ GST_BUFFER_OFFSET(mcbuffer->buffer) = core->offset;
+
+ core->offset += buf_size;
+ GST_BUFFER_OFFSET_END(mcbuffer->buffer) = core->offset;
+
return mcbuffer;
}
GstMCBuffer *__mc_gst_make_media_packet(mc_gst_core_t *core, GstBuffer *buffer)
{
gint ret = MEDIA_PACKET_ERROR_NONE;
- guint n;
GstMemory *mem;
GstMapInfo map = GST_MAP_INFO_INIT;
GstMCBuffer *mcbuffer = NULL;
+ void *data = NULL;
+ gint size = 0;
+
mcbuffer = (GstMCBuffer *)g_malloc0(sizeof(*mcbuffer));
return NULL;
}
- n = gst_buffer_n_memory(buffer);
+ mem = gst_buffer_peek_memory(buffer, 0);
- mem = gst_buffer_peek_memory(buffer, n-1);
-
- gst_memory_map(mem, &map, GST_MAP_READ);
+ if (gst_is_tizen_memory(mem)) {
+ data = (void *)gst_tizen_memory_get_surface(mem);
+ size = tbm_surface_internal_get_size((tbm_surface_h)data);
+ } else {
+ gst_memory_map(mem, &map, GST_MAP_READ);
+ data = map.data;
+ size = map.size;
+ gst_memory_unmap(mem, &map);
+ }
mcbuffer->buffer = buffer;
mcbuffer->core = core;
- mcbuffer->buf_size = map.size;
+ mcbuffer->buf_size = size;
- LOGD("n : %d, map.data : %p, map.size : %d", n, map.data, map.size);
- ret = __mc_fill_output_buffer(core, map.data, map.size, mcbuffer);
+ ret = __mc_fill_output_buffer(core, data, mcbuffer->buf_size, mcbuffer);
if (ret != MC_ERROR_NONE) {
LOGW("failed to fill outbuf: %s (ox%08x)", _mc_error_to_string(ret), ret);
- gst_memory_unmap(mem, &map);
return NULL;
}
- gst_memory_unmap(mem, &map);
return mcbuffer;
}
media_packet_h packet = NULL;
MEDIACODEC_FENTER();
- if (media_packet_create_alloc(fmt, __mc_output_buffer_finalize_cb, mcbuffer, &packet)) {
- LOGE("media_packet_create_alloc failed\n");
+ if (media_packet_create(fmt, __mc_output_buffer_finalize_cb, mcbuffer, &packet)) {
+ LOGE("media_packet_create failed\n");
ret = MC_ERROR;
goto ERROR;
}
return reply;
}
-static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet_h packet)
+static GstMemory *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, GstMCBuffer *mcbuffer)
{
- gint i;
- gint num_bos;
- gint err;
int ret = MEDIA_PACKET_ERROR_NONE;
tbm_surface_h surface = NULL;
- tbm_surface_info_s surface_info;
- tbm_bo_handle handle_bo;
+ GstVideoInfo vinfo;
+ GstMemory *mem = NULL;
- if (!packet) {
+ if (!mcbuffer->packet) {
LOGE("output is null");
return NULL;
}
- MMVideoBuffer *mm_vbuffer = NULL;
- mm_vbuffer = (MMVideoBuffer *)malloc(sizeof(MMVideoBuffer));
- if (!mm_vbuffer) {
- LOGE("Failed to alloc MMVideoBuffer");
- return NULL;
- }
- memset(mm_vbuffer, 0x00, sizeof(MMVideoBuffer));
-
- ret = media_packet_get_tbm_surface(packet, &surface);
+ ret = media_packet_get_tbm_surface(mcbuffer->packet, &surface);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGE("Failed to get tbm surface");
- free(mm_vbuffer);
return NULL;
}
- num_bos = tbm_surface_internal_get_num_bos(surface);
- err = tbm_surface_get_info((tbm_surface_h)surface, &surface_info);
- if (err != TBM_SURFACE_ERROR_NONE) {
- LOGE("get tbm surface is failed");
- free(mm_vbuffer);
+ if (!gst_video_info_from_caps(&vinfo, core->caps)) {
+ LOGE("Failed to get video info");
return NULL;
}
- for (i = 0; i < num_bos; i++) {
- mm_vbuffer->handle.bo[i] = tbm_surface_internal_get_bo(surface, i);
- LOGD("mm_vbuffer->handle.bo[%d] : %p", i, mm_vbuffer->handle.bo[i]);
- tbm_bo_map(mm_vbuffer->handle.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ);
- tbm_bo_unmap(mm_vbuffer->handle.bo[i]);
- }
-
- mm_vbuffer->type = MM_VIDEO_BUFFER_TYPE_TBM_BO;
- mm_vbuffer->width[0] = surface_info.width;
- mm_vbuffer->height[0] = surface_info.height;
- mm_vbuffer->width[1] = surface_info.width;
- mm_vbuffer->height[1] = surface_info.height>>1;
- mm_vbuffer->size[0] = surface_info.planes[0].size;
- mm_vbuffer->size[1] = surface_info.planes[1].size;
- mm_vbuffer->stride_width[0] = surface_info.planes[0].stride;
- mm_vbuffer->stride_height[0] = surface_info.planes[0].size / surface_info.planes[0].stride;
- mm_vbuffer->stride_width[1] = surface_info.planes[1].stride;
- mm_vbuffer->stride_height[1] = surface_info.planes[1].size / surface_info.planes[1].stride;
+ mem = gst_tizen_allocator_alloc_surface(core->allocator,
+ &vinfo, surface, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb);
- if (mm_vbuffer->handle.bo[0]) {
- handle_bo = tbm_bo_get_handle(mm_vbuffer->handle.bo[0], TBM_DEVICE_CPU);
- mm_vbuffer->data[0] = handle_bo.ptr;
-
- handle_bo = tbm_bo_get_handle(mm_vbuffer->handle.bo[0], TBM_DEVICE_MM);
- mm_vbuffer->handle.dmabuf_fd[0] = handle_bo.u32;
- }
-
- if (mm_vbuffer->handle.bo[1]) {
- handle_bo = tbm_bo_get_handle(mm_vbuffer->handle.bo[1], TBM_DEVICE_CPU);
- mm_vbuffer->data[1] = handle_bo.ptr;
-
- handle_bo = tbm_bo_get_handle(mm_vbuffer->handle.bo[1], TBM_DEVICE_MM);
- mm_vbuffer->handle.dmabuf_fd[1] = handle_bo.u32;
- } else {
- mm_vbuffer->data[1] = mm_vbuffer->data[0] + mm_vbuffer->stride_width[0] * mm_vbuffer->stride_height[0];
- }
- mm_vbuffer->plane_num = 2;
-
- LOGD("size[0] : %d, size[1] : %d, bo[0] :%p, bo[1] :%p", mm_vbuffer->size[0], mm_vbuffer->size[1], mm_vbuffer->handle.bo[0], mm_vbuffer->handle.bo[1]);
-
- return mm_vbuffer;
+ return mem;
}
static void __mc_input_buffer_finalize_cb(GstMCBuffer *mcbuffer)
return;
LOGD("============>>>>> _finalize_cb : %p, %p", mcbuffer, mcbuffer->packet);
- mc_gst_core_t *core = (mc_gst_core_t *)mcbuffer->core;
- _mc_gst_handle_input_buffer_used(core, mcbuffer->packet);
+ _mc_gst_handle_input_buffer_used(mcbuffer->core, mcbuffer->packet);
g_free(mcbuffer);
- mcbuffer = NULL;
MEDIACODEC_FLEAVE();
-
- return;
}
static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t *core, media_packet_h packet, uint64_t size)
}
}
-int _mc_get_support_bit_from_format(media_format_mimetype_e format)
-{
- gint bit = 0;
-
- switch (format) {
- case MEDIA_FORMAT_PCM_S16LE:
- case MEDIA_FORMAT_PCM_S16BE:
- case MEDIA_FORMAT_PCM_U16LE:
- case MEDIA_FORMAT_PCM_U16BE:
- bit = 16;
- break;
- case MEDIA_FORMAT_PCM_S32LE:
- case MEDIA_FORMAT_PCM_S32BE:
- case MEDIA_FORMAT_PCM_U32LE:
- case MEDIA_FORMAT_PCM_U32BE:
- case MEDIA_FORMAT_PCM_F32LE:
- case MEDIA_FORMAT_PCM_F32BE:
- bit = 32;
- break;
- default:
- LOGE("NOT SUPPORTED!!!!");
- break;
- }
-
- return bit;
-}
-
int _mc_get_mime(mc_gst_core_t *core)
{
media_format_mimetype_e mime = MEDIA_FORMAT_MAX;
case MEDIACODEC_AMR_WB:
mime = MEDIA_FORMAT_AMR_WB;
break;
+ case MEDIACODEC_OPUS:
+ if (core->encoder)
+ mime = MEDIA_FORMAT_OPUS;
+ else
+ mime = MEDIA_FORMAT_PCM_S16LE;
+ break;
default:
- LOGE("NOT SUPPORTED!!!!");
+ LOGE("NOT SUPPORTED!!!! 0x%x ", core->codec_id);
break;
}
return mime;
mime_format = _mc_get_mime(core);
if (core->video) {
- if (core->encoder) {
- media_format_set_video_mime(fmt_handle, mime_format);
- media_format_set_video_width(fmt_handle, mc_handle->info.encoder.width);
- media_format_set_video_height(fmt_handle, mc_handle->info.encoder.height);
- media_format_set_video_avg_bps(fmt_handle, mc_handle->info.encoder.bitrate);
- } else {
- media_format_set_video_mime(fmt_handle, mime_format);
- media_format_set_video_width(fmt_handle, mc_handle->info.decoder.width);
- media_format_set_video_height(fmt_handle, mc_handle->info.decoder.height);
- }
+ media_format_set_video_mime(fmt_handle, mime_format);
+ media_format_set_video_width(fmt_handle, mc_handle->info.video.width);
+ media_format_set_video_height(fmt_handle, mc_handle->info.video.height);
+ if (core->encoder)
+ media_format_set_video_avg_bps(fmt_handle, mc_handle->info.video.bitrate);
} else {
- if (core->encoder) {
- media_format_set_audio_mime(fmt_handle, mime_format);
- media_format_set_audio_channel(fmt_handle, mc_handle->info.encoder.channel);
- media_format_set_audio_samplerate(fmt_handle, mc_handle->info.encoder.samplerate);
- media_format_set_audio_bit(fmt_handle, mc_handle->info.encoder.bit);
- } else {
media_format_set_audio_mime(fmt_handle, mime_format);
- media_format_set_audio_channel(fmt_handle, mc_handle->info.decoder.channel);
- media_format_set_audio_samplerate(fmt_handle, mc_handle->info.decoder.samplerate);
- media_format_set_audio_bit(fmt_handle, mc_handle->info.decoder.bit);
- }
+ media_format_set_audio_channel(fmt_handle, mc_handle->info.audio.channel);
+ media_format_set_audio_samplerate(fmt_handle, mc_handle->info.audio.samplerate);
+ media_format_set_audio_bit(fmt_handle, mc_handle->info.audio.bit_depth);
+ if (core->encoder)
+ media_format_set_audio_avg_bps(fmt_handle, mc_handle->info.audio.bitrate);
}
ret = media_packet_pool_set_media_format(pool, fmt_handle);