* limitations under the License.
*
*/
-#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlog.h>
#include <media_codec_queue.h>
#include <media_codec_port_gst.h>
+#include <media_packet_internal.h>
#include <media_codec_util.h>
#include <gst/gst.h>
#include <gst/gstelement.h>
#include <gst/app/gstappsrc.h>
+#include <gst/pbutils/pbutils.h>
+#include <gst/tag/tag.h>
-#ifdef TIZEN_PROFILE_LITE
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <linux/ion.h>
-#endif
-
-#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
/*
* 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 void _mc_gst_update_caps(mc_gst_core_t *core, media_packet_h pkt, GstCaps **caps, GstMCBuffer* buff, bool codec_config);
-static GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t *core, GstCaps **caps, media_packet_h pkt, bool codec_config);
-static int _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *buff);
-static gchar *__mc_get_gst_input_format(media_packet_h packet, bool is_hw);
-static media_packet_h __mc_gst_make_media_packet(mc_gst_core_t *core, unsigned char *data, int size);
+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_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 pkt);
-static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t* core, media_packet_h pkt, uint64_t size);
-static void gst_mediacodec_buffer_finalize(GstMCBuffer *buffer);
-static int __mc_set_caps_streamheader(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer*buff, guint streamheader_size);
-static int __mc_set_caps_codecdata(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer*buff, guint codecdata_size);
+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 int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint codecdata_size);
+static void __mc_push_output_to_queue(mc_gst_core_t *core, GstMCBuffer *mcbuffer);
+static int __mc_gst_create_eos_packet(media_format_h fmt, GstMCBuffer *mcbuffer);
+static void _mc_gst_handle_input_buffer_used(mc_gst_core_t *core, media_packet_h packet);
static gint __gst_handle_stream_error(mc_gst_core_t *core, GError *error, GstMessage *message);
static gint __gst_transform_gsterror(mc_gst_core_t *core, GstMessage *message, GError *error);
static gint __gst_handle_library_error(mc_gst_core_t *core, int code);
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_link_vtable(mc_gst_core_t *core, mediacodec_codec_type_e id, gboolean is_encoder, gboolean is_hw);
-#ifdef TIZEN_PROFILE_LITE
-static int __tbm_get_physical_addr_bo(tbm_bo_handle tbm_bo_handle_fd_t, int *phy_addr, int *phy_size);
-#endif
static int _mc_gst_flush_buffers(mc_gst_core_t *core);
static void _mc_gst_set_flush_input(mc_gst_core_t *core);
static void _mc_gst_set_flush_output(mc_gst_core_t *core);
+#ifdef TIZEN_EXYNOS_SPECIFIC
static int __tile_4x2_read(int x_size, int y_size, int x_pos, int y_pos);
static void __csc_tiled_to_linear_crop(unsigned char *yuv420_dest,
unsigned char *nv12t_src, int yuv420_width, int yuv420_height,
int left, int top, int right, int buttom);
+#endif
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_inbuf_with_packet, &__mc_fill_vdec_packet_with_outbuf, &__mc_vdec_caps};
-int(*venc_vtable[])() = {&__mc_fill_inbuf_with_packet, &__mc_fill_venc_packet_with_outbuf, &__mc_venc_caps};
-
-
-int(*vdec_h264_sw_vtable[])() = {&__mc_fill_inbuf_with_packet, /* FFMPEG H.264 Decoder Vtable */
- &__mc_fill_vdec_packet_with_outbuf,
- &__mc_vdec_caps};
-int(*vdec_mpeg4_sw_vtable[])() = {&__mc_fill_inbuf_with_packet, /* FFMPEG MPEG4 Decoder Vtable */
- &__mc_fill_vdec_packet_with_outbuf,
- &__mc_vdec_mpeg4_caps};
-int(*venc_mpeg4_sw_vtable[])() = {&__mc_fill_inbuf_with_venc_packet, /* SPRD MPEG4 Encoder Vtable */
- &__mc_fill_venc_packet_with_outbuf,
- &__mc_venc_caps};
-int(*vdec_h263_sw_vtable[])() = {&__mc_fill_inbuf_with_packet, /* FFMPEG MPEG4 Decoder Vtable */
- &__mc_fill_vdec_packet_with_outbuf,
- &__mc_vdec_h263_caps};
-int(*venc_h263_sw_vtable[])() = {&__mc_fill_inbuf_with_venc_packet, /* SPRD MPEG4 Encoder Vtable */
- &__mc_fill_venc_packet_with_outbuf,
- &__mc_venc_caps};
-#ifdef TIZEN_PROFILE_LITE
-int(*vdec_h264_hw_vtable[])() = {&__mc_fill_inbuf_with_packet, /* SPRD H.264 Decoder Vtable */
- &__mc_fill_video_packet_with_mm_video_buffer,
- &__mc_sprddec_caps};
-int(*venc_h264_hw_vtable[])() = {&__mc_fill_inbuf_with_mm_video_buffer, /* SPRD H.264 Encoder Vtable */
- &__mc_fill_venc_packet_with_outbuf,
- &__mc_sprdenc_caps};
-int(*vdec_mpeg4_hw_vtable[])() = {&__mc_fill_inbuf_with_packet, /* SPRD MPEG4 Decoder Vtable */
- &__mc_fill_video_packet_with_mm_video_buffer,
- &__mc_sprddec_mpeg4_caps};
-int(*venc_mpeg4_hw_vtable[])() = {&__mc_fill_inbuf_with_mm_video_buffer, /* SPRD MPEG4 Encoder Vtable */
- &__mc_fill_venc_packet_with_outbuf,
- &__mc_sprdenc_mpeg4_caps};
-int(*vdec_h263_hw_vtable[])() = {&__mc_fill_inbuf_with_packet, /* SPRD MPEG4 Decoder Vtable */
- &__mc_fill_video_packet_with_mm_video_buffer,
- &__mc_sprddec_mpeg4_caps};
-int(*venc_h263_hw_vtable[])() = {&__mc_fill_inbuf_with_mm_video_buffer, /* SPRD MPEG4 Encoder Vtable */
- &__mc_fill_venc_packet_with_outbuf,
- &__mc_sprdenc_mpeg4_caps};
-#else
-int(*vdec_h264_hw_vtable[])() = {&__mc_fill_inbuf_with_packet, /* EXYNOS H.264 Decoder Vtable */
- &__mc_fill_video_packet_with_mm_video_buffer,
- &__mc_h264dec_caps};
-int(*venc_h264_hw_vtable[])() = {&__mc_fill_inbuf_with_mm_video_buffer, /* EXYNOS H.264 Encoder Vtable */
- &__mc_fill_venc_packet_with_outbuf,
- &__mc_hw_h264enc_caps};
-int(*vdec_mpeg4_hw_vtable[])() = {&__mc_fill_inbuf_with_packet, /* EXYNOS MPEG4 Decoder Vtable */
- &__mc_fill_video_packet_with_mm_video_buffer,
- &__mc_sprddec_mpeg4_caps};
-int(*venc_mpeg4_hw_vtable[])() = {&__mc_fill_inbuf_with_mm_video_buffer, /* EXYNOS MPEG4 Encoder Vtable */
- &__mc_fill_venc_packet_with_outbuf,
- &__mc_sprdenc_mpeg4_caps};
-int(*vdec_h263_hw_vtable[])() = {&__mc_fill_inbuf_with_packet, /* EXYNOS MPEG4 Decoder Vtable */
- &__mc_fill_video_packet_with_mm_video_buffer,
- &__mc_sprddec_mpeg4_caps};
-int(*venc_h263_hw_vtable[])() = {&__mc_fill_inbuf_with_mm_video_buffer, /* EXYNOS MPEG4 Encoder Vtable */
- &__mc_fill_venc_packet_with_outbuf,
- &__mc_sprdenc_mpeg4_caps};
-#endif
+__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};
+
+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};
+
+static int(*vdec_mpeg4_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W MPEG4 Decoder Vtable */
+ &__mc_fill_vdec_packet_with_output_buffer};
+
+static int(*vdec_h263_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W MPEG4 Decoder Vtable */
+ &__mc_fill_vdec_packet_with_output_buffer};
+
+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};
+
+static int(*vdec_mpeg4_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W MPEG4 Decoder Vtable */
+ &__mc_fill_vdec_packet_with_output_buffer};
+
+static int(*vdec_h263_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W MPEG4 Decoder Vtable */
+ &__mc_fill_vdec_packet_with_output_buffer};
+
+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};
+
+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};
+
+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};
+
+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};
+
+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};
+
+__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};
+
+static int(*aenc_aac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AAC LC Encoder vtable */
+ &__mc_fill_aenc_packet_with_output_buffer};
+
+static int(*adec_aac_vtable[])() = {&__mc_fill_input_buffer_with_adec_packet, /* AAC LC Decoder Vtable */
+ &__mc_fill_packet_with_output_buffer};
+
+static int(*adec_aacv12_vtable[])() = {&__mc_fill_input_buffer_with_adec_packet, /* AAC HE Decoder Vtable */
+ &__mc_fill_packet_with_output_buffer};
-/* audio vtable */
-int(*aenc_vtable[])() = {&__mc_fill_inbuf_with_packet, &__mc_fill_packet_with_outbuf, &__mc_aenc_caps};
-int(*adec_vtable[])() = {&__mc_fill_inbuf_with_packet, &__mc_fill_packet_with_outbuf, &__mc_adec_caps};
-
-int(*aenc_aac_vtable[])() = {&__mc_fill_inbuf_with_packet, /* AAC LC Encoder vtable */
- &__mc_fill_packet_with_outbuf,
- &__mc_aenc_aac_caps};
-int(*adec_aac_vtable[])() = {&__mc_fill_inbuf_with_packet, /* AAC LC Decoder Vtable */
- &__mc_fill_packet_with_outbuf,
- &__mc_adec_aac_caps};
-int(*adec_aacv12_vtable[])() = {&__mc_fill_inbuf_with_packet, /* AAC HE Decoder Vtable */
- &__mc_fill_packet_with_outbuf,
- &__mc_adec_aacv12_caps};
-int(*adec_mp3_vtable[])() = {&__mc_fill_inbuf_with_packet, /* MP3 Decoder Vtable */
- &__mc_fill_packet_with_outbuf,
- &__mc_adec_mp3_caps};
-int(*adec_amrnb_vtable[])() = {&__mc_fill_inbuf_with_packet, /* AMR-NB Decoder Vtable */
- &__mc_fill_packet_with_outbuf,
- &__mc_adec_amrnb_caps};
-int(*adec_amrwb_vtable[])() = {&__mc_fill_inbuf_with_packet, /* AMR-WB Decoder Vtable */
- &__mc_fill_packet_with_outbuf,
- &__mc_adec_amrwb_caps};
-int(*aenc_amrnb_vtable[])() = {&__mc_fill_inbuf_with_packet, /* AMR-NB Encoder Vtable */
- &__mc_fill_packet_with_outbuf,
- &__mc_aenc_amrnb_caps};
-int(*adec_vorbis_vtable[])() = {&__mc_fill_inbuf_with_packet, /* VORBIS Decoder Vtable */
- &__mc_fill_packet_with_outbuf,
- &__mc_adec_vorbis_caps};
-int(*adec_flac_vtable[])() = {&__mc_fill_inbuf_with_packet, /* FLAC Decoder Vtable */
- &__mc_fill_packet_with_outbuf,
- &__mc_adec_flac_caps};
-int(*adec_wma_vtable[])() = {&__mc_fill_inbuf_with_packet, /* WMA Decoder Vtable */
- &__mc_fill_packet_with_outbuf,
- &__mc_adec_wma_caps};
+static int(*adec_mp3_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* MP3 Decoder Vtable */
+ &__mc_fill_packet_with_output_buffer};
+static int(*adec_amrnb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-NB Decoder Vtable */
+ &__mc_fill_packet_with_output_buffer};
+
+static int(*adec_amrwb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-WB Decoder Vtable */
+ &__mc_fill_packet_with_output_buffer};
+
+static int(*aenc_amrnb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-NB Encoder Vtable */
+ &__mc_fill_packet_with_output_buffer};
+
+static int(*adec_vorbis_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* VORBIS Decoder Vtable */
+ &__mc_fill_packet_with_output_buffer};
+
+static int(*adec_flac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* FLAC Decoder Vtable */
+ &__mc_fill_packet_with_output_buffer};
+
+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
*/
-int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff)
+int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer)
{
- return core->vtable[fill_inbuf](core, pkt, buff);
+ return core->vtable[fill_inbuf](core, packet, mcbuffer);
}
-int __mc_fill_inbuf_with_mm_video_buffer(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer)
+int __mc_fill_inbuf_with_mm_video_buffer(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer)
{
- int ret = MC_ERROR_NONE;
-
- MMVideoBuffer *mm_vbuffer = NULL;
- void *buf_data = NULL;
+ gint ret = MC_ERROR_NONE;
uint64_t buf_size = 0;
+ GstMemory *mem;
+ void *buf_data = NULL;
- ret = media_packet_get_buffer_size(pkt, &buf_size);
+ ret = media_packet_get_buffer_size(packet, &buf_size);
if (ret != MEDIA_PACKET_ERROR_NONE) {
- LOGW("buffer size get fail");
+ LOGW("buffer size get failed");
return MC_ERROR;
}
- ret = media_packet_get_buffer_data_ptr(pkt, &buf_data);
+ ret = media_packet_get_buffer_data_ptr(packet, &buf_data);
if (ret != MEDIA_PACKET_ERROR_NONE) {
- LOGW("buffer size get fail");
+ LOGW("buffer data get failed");
+ return MC_ERROR;
+ }
+
+ mem = __mc_gst_make_tbm_buffer(core, mcbuffer);
+ if (mem == NULL) {
+ LOGW("Failed to make tizen memory");
return MC_ERROR;
}
- mm_vbuffer = __mc_gst_make_tbm_buffer(core, mc_buffer->pkt);
+ gst_buffer_append_memory(mcbuffer->buffer, mem);
+ LOGD("tizen memory appended");
+
+ return ret;
+}
- if (mm_vbuffer != NULL) {
- gst_buffer_prepend_memory(mc_buffer->buffer,
- gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, mm_vbuffer, sizeof(*mm_vbuffer), 0,
- sizeof(*mm_vbuffer), mm_vbuffer, free));
- LOGD("scmn_mm_vbuffer is appended, %d, %d", sizeof(*mm_vbuffer), gst_buffer_n_memory(mc_buffer->buffer));
+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;
+ uint64_t buf_size = 0;
+
+ ret = media_packet_get_buffer_size(packet, &buf_size);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ LOGW("buffer size get failed");
+ return MC_ERROR;
}
- if (buf_data != NULL) {
- gst_buffer_prepend_memory(mc_buffer->buffer,
- gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0,
- buf_size, mc_buffer, (GDestroyNotify)gst_mediacodec_buffer_finalize));
- LOGD("packet data apended, %d, %d", buf_size, gst_buffer_n_memory(mc_buffer->buffer));
+ ret = media_packet_get_buffer_data_ptr(packet, &buf_data);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ LOGW("buffer data get failed");
+ return MC_ERROR;
}
+
+ 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_inbuf_with_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer)
+static int __mc_fill_input_buffer_with_adec_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer)
{
- int ret = MC_ERROR_NONE;
- void *buf_data = NULL;
+ gint ret = MC_ERROR_NONE;
uint64_t buf_size = 0;
+ unsigned int codec_size = 0;
+ bool codec_config = FALSE;
+ void *buf_data = NULL;
+ void *codec_data = NULL;
- ret = media_packet_get_buffer_size(pkt, &buf_size);
+ ret = media_packet_get_buffer_size(packet, &buf_size);
if (ret != MEDIA_PACKET_ERROR_NONE) {
- LOGW("buffer size get fail");
+ LOGW("buffer size get failed");
return MC_ERROR;
}
- ret = media_packet_get_buffer_data_ptr(pkt, &buf_data);
+ ret = media_packet_get_buffer_data_ptr(packet, &buf_data);
if (ret != MEDIA_PACKET_ERROR_NONE) {
- LOGW("buffer size get fail");
+ LOGW("buffer data get failed");
+ return MC_ERROR;
+ }
+
+ if (media_packet_is_codec_config(packet, &codec_config) != MEDIA_PACKET_ERROR_NONE) {
+ LOGE("media_packet_is_codec_config failed");
return MC_ERROR;
}
if (buf_data != NULL) {
- gst_buffer_append_memory(mc_buffer->buffer,
- gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0,
- buf_size, mc_buffer, (GDestroyNotify)gst_mediacodec_buffer_finalize));
- LOGD("packet data apended");
+ media_packet_get_codec_data(packet, &codec_data, &codec_size);
+
+ if (!codec_data && codec_config) {
+ gst_buffer_append_memory(mcbuffer->buffer,
+ gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0,
+ buf_size, NULL, NULL));
+ LOGD("csd packet data apended");
+ } else {
+ 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_inbuf_with_venc_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer)
+static int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer)
{
- int ret = MC_ERROR_NONE;
- void *uv_ptr = NULL;
- void *y_ptr = NULL;
- int buf_size = 0;
- int stride_width;
- int stride_height;
- int width;
- int height;
+ gint ret = MC_ERROR_NONE;
+ gint i;
+ gint j;
+ gint stride = 0;
+ gint buf_size = 0;
+ gint stride_width;
+ gint stride_height;
+ gint width;
+ gint height;
uint32_t plane_num;
- int i;
- int j;
- int stride = 0;
+ 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(pkt, &plane_num);
+ ret = media_packet_get_number_of_video_planes(packet, &plane_num);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGW("media_packet_get_number_of_video_planes failed");
return MC_ERROR;
}
- ret = media_packet_get_video_plane_data_ptr(pkt, 0, &y_ptr);
+ ret = media_packet_get_video_plane_data_ptr(packet, 0, (void **)&planes[0]);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGW("media_packet_get_video_plane_data_ptr failed");
return MC_ERROR;
}
- ret = media_packet_get_video_stride_width(pkt, 0, &stride_width);
+ ret = media_packet_get_video_stride_width(packet, 0, &stride_width);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGW("media_packet_get_video_stride_width failed");
return MC_ERROR;
}
- ret = media_packet_get_video_stride_height(pkt, 0, &stride_height);
+ ret = media_packet_get_video_stride_height(packet, 0, &stride_height);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGW("media_packet_get_video_stride_width failed");
return MC_ERROR;
}
- if (width == stride_width) {
- mc_buffer->buf_size += stride_width * stride_height;
+ if (!core->is_hw) {
+ if (width == stride_width) {
+ mcbuffer->buf_size += stride_width * stride_height;
- for (i = 1; i < plane_num; i++) {
- media_packet_get_video_plane_data_ptr(pkt, i, &uv_ptr);
- media_packet_get_video_stride_width(pkt, i, &stride_width);
- media_packet_get_video_stride_height(pkt, i, &stride_height);
+ for (i = 1; i < plane_num; i++) {
+ media_packet_get_video_plane_data_ptr(packet, i, (void **)&planes[1]);
+ media_packet_get_video_stride_width(packet, i, &stride_width);
+ media_packet_get_video_stride_height(packet, i, &stride_height);
- buf_size = stride_width * stride_height;
+ buf_size = stride_width * stride_height;
- memcpy(y_ptr + mc_buffer->buf_size, uv_ptr, buf_size);
- LOGD("width is same with stride");
- LOGD("plane : %d, buf_size : %d, total : %d", i, buf_size, mc_buffer->buf_size);
- mc_buffer->buf_size += buf_size;
+ memcpy(planes[0] + mcbuffer->buf_size, planes[1], buf_size);
+ mcbuffer->buf_size += buf_size;
+ LOGD("plane : %d, buf_size : %d, total : %d", i, buf_size, mcbuffer->buf_size);
+ }
+ } else {
- }
- } else {
+ for (j = 0; j < height; j++) {
+ memcpy(planes[0] + mcbuffer->buf_size, planes[0] + stride, width);
+ mcbuffer->buf_size += width;
+ stride += stride_width;
+ }
- for (j = 0; j < height; j++) {
- memcpy(y_ptr + mc_buffer->buf_size, y_ptr + stride, width);
- mc_buffer->buf_size += width;
- stride += stride_width;
- }
+ stride = 0;
- stride = 0;
+ for (i = 1; i < plane_num; i++) {
+ media_packet_get_video_plane_data_ptr(packet, i, (void **)&planes[1]);
+ media_packet_get_video_stride_width(packet, i, &stride_width);
+ media_packet_get_video_stride_height(packet, i, &stride_height);
- for (i = 1; i < plane_num; i++) {
- media_packet_get_video_plane_data_ptr(pkt, i, &uv_ptr);
- media_packet_get_video_stride_width(pkt, i, &stride_width);
- media_packet_get_video_stride_height(pkt, i, &stride_height);
+ for (j = 0; j < height>>1; j++) {
+ memcpy(planes[0] + mcbuffer->buf_size, planes[1] + stride, width>>1);
+ mcbuffer->buf_size += width>>1;
+ stride += stride_width;
+ }
- for (j = 0; j < height>>1; j++) {
- memcpy(y_ptr + mc_buffer->buf_size, uv_ptr + stride, width>>1);
- mc_buffer->buf_size += width>>1;
- stride += stride_width;
+ memcpy(planes[0] + mcbuffer->buf_size, planes[1], buf_size);
+ LOGD("plane : %d, buf_size : %d, total : %d", i, buf_size, mcbuffer->buf_size);
+ mcbuffer->buf_size += buf_size;
}
+ }
+ } else {
+ GstMemory *mem = NULL;
- memcpy(y_ptr + mc_buffer->buf_size, uv_ptr, buf_size);
- LOGD("plane : %d, buf_size : %d, total : %d", i, buf_size, mc_buffer->buf_size);
- mc_buffer->buf_size += buf_size;
+ mem = __mc_gst_make_tbm_buffer(core, mcbuffer);
+ if (mem == NULL) {
+ LOGW("Failed to make tizen memory");
+ return MC_ERROR;
}
- }
- if (y_ptr != NULL) {
- gst_buffer_append_memory(mc_buffer->buffer,
- gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, y_ptr, mc_buffer->buf_size, 0,
- mc_buffer->buf_size, mc_buffer, (GDestroyNotify)gst_mediacodec_buffer_finalize));
- LOGD("%d plane data apended : width : %d, height : %d, size : %d",
- i, stride_width, stride_height, mc_buffer->buf_size);
+ gst_buffer_append_memory(mcbuffer->buffer, mem);
+ LOGD("tizen memory appended");
}
-
return ret;
}
* fill_outbuf virtual functions
*/
-int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt)
+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, out_pkt);
+ return core->vtable[fill_outbuf](core, data, size, mcbuffer);
}
-int __mc_fill_vdec_packet_with_outbuf(mc_gst_core_t *core, void *data, int size, media_packet_h *pkt)
+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;
int stride_height;
uint32_t width;
uint32_t height;
- uint32_t plane_num;
uint32_t buf_size;
- uint32_t plane_size;
- int ret = MC_ERROR_NONE;
- void *pkt_data = NULL;
- tbm_surface_h tsurf = NULL;
tbm_surface_info_s tsurf_info;
tbm_bo bo[MM_VIDEO_BUFFER_PLANE_MAX];
tbm_bo_handle thandle;
+ tbm_surface_h tsurf = NULL;
+ media_packet_h packet = NULL;
g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- width = dec_info->width;
- height = dec_info->height;
- stride_width = ALIGN(width, 4);
- stride_height = ALIGN(height, 4);
- buf_size = stride_width * stride_height * 3 / 2;
-
- if (buf_size > size)
- return MC_ERROR;
+ mc_gst_port_def_t *port_def = &core->ports[out_port_index]->port_def;
- memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s));
+ if (!core->is_hw) {
+ 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;
- bo[0] = tbm_bo_alloc(core->bufmgr, buf_size, TBM_BO_WC);
- if (!bo[0]) {
- LOGE("bo allocation failed");
- return MC_ERROR;
- }
+ memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s));
- tsurf_info.width = dec_info->width;
- tsurf_info.height = dec_info->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_info.size = 0;
+ bo[0] = tbm_bo_alloc(core->bufmgr, buf_size, TBM_BO_WC);
+ if (!bo[0]) {
+ LOGE("bo allocation failed");
+ return MC_ERROR;
+ }
- for (i = 0; i < tsurf_info.num_planes; i++) {
- if (i == 0) {
- tsurf_info.planes[i].stride = stride_width;
- tsurf_info.planes[i].size = stride_width * stride_height;
- tsurf_info.planes[i].offset = 0;
- tsurf_info.size = tsurf_info.planes[i].size;
- } else {
- tsurf_info.planes[i].stride = stride_width>>1;
- tsurf_info.planes[i].size = (stride_width>>1) * (stride_height>>1);
- 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;
+ 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_info.size = 0;
+
+ for (i = 0; i < tsurf_info.num_planes; i++) {
+ if (i == 0) {
+ tsurf_info.planes[i].stride = stride_width;
+ tsurf_info.planes[i].size = stride_width * stride_height;
+ tsurf_info.planes[i].offset = 0;
+ tsurf_info.size = tsurf_info.planes[i].size;
+ } else {
+ tsurf_info.planes[i].stride = GST_ROUND_UP_4(GST_ROUND_UP_2(width) / 2);
+ tsurf_info.planes[i].size = GST_ROUND_UP_4(GST_ROUND_UP_2(width) / 2) * (height / 2);
+ 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;
+ }
}
- }
- thandle = tbm_bo_map(bo[0], TBM_DEVICE_CPU, TBM_OPTION_WRITE);
- memcpy(thandle.ptr, data, tsurf_info.size);
- tbm_bo_unmap(bo[0]);
+ thandle = tbm_bo_map(bo[0], TBM_DEVICE_CPU, TBM_OPTION_WRITE);
+ memcpy(thandle.ptr, data, tsurf_info.size);
+ tbm_bo_unmap(bo[0]);
- tsurf = tbm_surface_internal_create_with_bos(&tsurf_info, bo, 1);
+ tsurf = tbm_surface_internal_create_with_bos(&tsurf_info, bo, 1);
+ } else {
+ tsurf = (tbm_surface_h)data;
+ }
if (tsurf) {
media_packet_create_from_tbm_surface(core->output_fmt, tsurf,
- (media_packet_finalize_cb)__mc_output_buffer_finalize_cb, core, pkt);
+ (media_packet_finalize_cb)__mc_output_buffer_finalize_cb, mcbuffer, &packet);
+ mcbuffer->packet = packet;
}
return MC_ERROR_NONE;
}
-int __mc_fill_video_packet_with_mm_video_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt)
+static int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
{
- void *pkt_data = NULL;
- MMVideoBuffer *mm_vbuffer = NULL;
- int i;
- int bo_num = 0;
+ gint ret = MC_ERROR_NONE;
+ gchar *ext_mem = NULL;
+ gint mem_size = 0;
+ void *packet_data = NULL;
+ media_packet_h packet = NULL;
g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
- mc_decoder_info_t *codec_info = (mc_decoder_info_t *)core->codec_info;
- mm_vbuffer = (MMVideoBuffer *)data;
-
- LOGD("buf_share_method %d", mm_vbuffer->type);
-
- LOGD("a[0] : %p, a[1] : %p, p[0] : %p, p[1] : %p",
- mm_vbuffer->data[0], mm_vbuffer->data[1], mm_vbuffer->handle.paddr[0], mm_vbuffer->handle.paddr[1]);
- LOGD("s[0]:%d, e[0]:%d, w[0]:%d, h[0]:%d",
- mm_vbuffer->stride_width[0], mm_vbuffer->stride_height[0], mm_vbuffer->width[0], mm_vbuffer->height[0]);
-
- if (mm_vbuffer->type == MM_VIDEO_BUFFER_TYPE_PHYSICAL_ADDRESS) {
- media_packet_set_buffer_size(*out_pkt, mm_vbuffer->width[0]*mm_vbuffer->height[0]*3/2);
- media_packet_get_buffer_data_ptr(*out_pkt, &pkt_data);
-
- __csc_tiled_to_linear_crop(pkt_data, mm_vbuffer->data[0],
- mm_vbuffer->stride_width[0], mm_vbuffer->stride_height[0], 0, 0, 0, 0);
- __csc_tiled_to_linear_crop(pkt_data+mm_vbuffer->stride_width[0]*mm_vbuffer->stride_height[0],
- mm_vbuffer->data[1], mm_vbuffer->stride_width[0], mm_vbuffer->stride_height[0]/2, 0, 0, 0, 0);
- } else if (mm_vbuffer->type == MM_VIDEO_BUFFER_TYPE_DMABUF_FD) {
- LOGD("FD type");
- } else if (mm_vbuffer->type == MM_VIDEO_BUFFER_TYPE_TBM_BO) {
- tbm_surface_h tsurf = NULL;
- 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 = codec_info->width;
- tsurf_info.height = codec_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);
- }
-
- if (tsurf) {
- media_packet_create_from_tbm_surface(core->output_fmt, tsurf,
- (media_packet_finalize_cb)__mc_output_buffer_finalize_cb, core, out_pkt);
- }
- }
+ if (core->encoder && core->codec_id == MEDIACODEC_AAC)
+ media_format_set_audio_aac_type(core->output_fmt, FALSE);
- return MC_ERROR_NONE;
-}
+ mem_size = GST_ROUND_UP_4(size);
+ ext_mem = g_malloc0(mem_size);
-int __mc_fill_packet_with_outbuf(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt)
-{
- void *pkt_data = NULL;
- int ret = MC_ERROR_NONE;
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- ret = media_packet_create_alloc(core->output_fmt, __mc_output_buffer_finalize_cb, core, out_pkt);
+ ret = media_packet_create_from_external_memory(core->output_fmt, ext_mem, mem_size, __mc_output_buffer_finalize_cb, mcbuffer, &packet);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGW("media_packet_create_alloc failed");
+ g_free(ext_mem);
return MC_ERROR;
}
+ mcbuffer->packet = packet;
+ mcbuffer->ext_mem = ext_mem;
- media_packet_set_buffer_size(*out_pkt, size);
- media_packet_get_buffer_data_ptr(*out_pkt, &pkt_data);
- memcpy(pkt_data, data, size);
+ media_packet_set_buffer_size(packet, size);
+ media_packet_get_buffer_data_ptr(packet, &packet_data);
+ memcpy(packet_data, data, size);
return MC_ERROR_NONE;
}
-int __mc_fill_venc_packet_with_outbuf(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt)
+static int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, GstMCBuffer *mcbuffer)
{
- void *pkt_data = NULL;
+ gint ret = MC_ERROR_NONE;
bool codec_config = FALSE;
bool sync_flag = FALSE;
bool slice = FALSE;
- int codec_data_size = 0;
- int ret = MC_ERROR_NONE;
+ gint mem_size = 0;
+ gchar *ext_mem = NULL;
+ gint data_size = 0;
+ void *packet_data = NULL;
+ media_packet_h packet = NULL;
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:
- ret = _mc_check_h264_bytestream((unsigned char *)data, size, 1, &codec_config, &sync_flag, &slice);
+ data_size = _mc_check_h264_bytestream((unsigned char *)data, size, 1, &codec_config, &sync_flag, &slice);
+
+ if (data_size < 0) {
+ LOGE("No valid SPS/PPS ...");
+ return MC_INVALID_IN_BUF;
+ }
break;
case MEDIA_FORMAT_MPEG4_SP:
case MEDIA_FORMAT_MPEG4_ASP:
- codec_data_size = _mc_check_mpeg4_out_bytestream((unsigned char *)data, size, &codec_config, &sync_flag);
+ _mc_check_mpeg4_out_bytestream((unsigned char *)data, size, &codec_config, &sync_flag);
break;
case MEDIA_FORMAT_H263:
case MEDIA_FORMAT_H263P:
}
LOGD("codec_config : %d, sync_flag : %d, slice : %d", codec_config, sync_flag, slice);
- ret = media_packet_create_alloc(core->output_fmt, __mc_output_buffer_finalize_cb, core, out_pkt);
+ mem_size = GST_ROUND_UP_4(size);
+ ext_mem = g_malloc0(mem_size);
+
+ ret = media_packet_create_from_external_memory(core->output_fmt, ext_mem, mem_size, __mc_output_buffer_finalize_cb, mcbuffer, &packet);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGW("media_packet_create_alloc failed");
+ g_free(ext_mem);
return MC_ERROR;
}
+ mcbuffer->packet = packet;
+ mcbuffer->ext_mem = ext_mem;
- media_packet_set_buffer_size(*out_pkt, size);
- media_packet_get_buffer_data_ptr(*out_pkt, &pkt_data);
- memcpy(pkt_data, data, size);
+ media_packet_set_buffer_size(packet, size);
+ media_packet_get_buffer_data_ptr(packet, &packet_data);
+ memcpy(packet_data, data, size);
core->need_sync_flag = sync_flag ? 1 : 0;
core->need_codec_data = codec_config ? 1 : 0;
return ret;
}
-/*
- * create_caps virtual functions
- */
-
-int __mc_create_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- return core->vtable[create_caps](core, caps, buff, codec_config);
-}
-
-int __mc_venc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple("video/x-raw",
- "format", G_TYPE_STRING, "I420",
- "width", G_TYPE_INT, enc_info->width,
- "height", G_TYPE_INT, enc_info->height,
- "framerate", GST_TYPE_FRACTION, enc_info->fps, 1,
- NULL);
-
- LOGD("%d, %d, %d", enc_info->width, enc_info->height, enc_info->fps);
-
- return MC_ERROR_NONE;
-}
-
-int __mc_hw_h264enc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple("video/x-raw",
- "format", G_TYPE_STRING, "SN12",
- "width", G_TYPE_INT, enc_info->width,
- "height", G_TYPE_INT, enc_info->height,
- "framerate", GST_TYPE_FRACTION, enc_info->fps, 1,
- NULL);
- g_object_set(GST_OBJECT(core->codec), "target-bitrate", enc_info->bitrate*1000, NULL);
-
- LOGD("%d, %d, %d", enc_info->width, enc_info->height, enc_info->fps);
-
- return MC_ERROR_NONE;
-}
-
-int __mc_sprdenc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple(core->mime,
- "format", G_TYPE_STRING, "SN12",
- "width", G_TYPE_INT, enc_info->width,
- "height", G_TYPE_INT, enc_info->height,
- "framerate", GST_TYPE_FRACTION, enc_info->fps, 1, NULL);
-
- g_object_set(GST_OBJECT(core->codec), "byte-stream", TRUE, NULL);
- g_object_set(GST_OBJECT(core->codec), "bitrate", enc_info->bitrate*1000, NULL);
-
- LOGD("%s, %d, %d, %d", core->format, enc_info->width, enc_info->height, enc_info->fps);
-
-
- return MC_ERROR_NONE;
-}
-
-int __mc_sprdenc_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer *buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple("video/x-raw",
- "format", G_TYPE_STRING, "SN12",
- "width", G_TYPE_INT, enc_info->width,
- "height", G_TYPE_INT, enc_info->height,
- "framerate", GST_TYPE_FRACTION, enc_info->fps, 1, NULL);
-
- g_object_set(GST_OBJECT(core->codec), "bitrate", enc_info->bitrate*1000, NULL);
-
- LOGD("%s, %d, %d, %d", core->format, enc_info->width, enc_info->height, enc_info->fps);
-
-
- return MC_ERROR_NONE;
-}
-
-int __mc_h264dec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- LOGD("%d, %d, ", dec_info->width, dec_info->height);
- *caps = gst_caps_new_simple(core->mime,
- "parsed", G_TYPE_BOOLEAN, TRUE,
- "alignment", G_TYPE_STRING, "au",
- "stream-format", G_TYPE_STRING, "byte-stream",
- "width", G_TYPE_INT, dec_info->width,
- "height", G_TYPE_INT, dec_info->height, NULL);
-
- LOGD("mime : %s, widht :%d, height : %d", core->mime, dec_info->width, dec_info->height);
- return MC_ERROR_NONE;
-}
-
-int __mc_sprddec_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- LOGD("%d, %d, ", dec_info->width, dec_info->height);
-
- *caps = gst_caps_new_simple(core->mime,
- "mpegversion", G_TYPE_INT, 4,
- "width", G_TYPE_INT, dec_info->width,
- "height", G_TYPE_INT, dec_info->height,
- "framerate", GST_TYPE_FRACTION, 30, 1,
- NULL);
-
- LOGD("mime : %s, widht :%d, height : %d", core->mime, dec_info->width, dec_info->height);
-
- return MC_ERROR_NONE;
-}
-
-int __mc_sprddec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- LOGD("%d, %d, ", dec_info->width, dec_info->height);
- *caps = gst_caps_new_simple(core->mime,
- "width", G_TYPE_INT, dec_info->width,
- "height", G_TYPE_INT, dec_info->height,
- "framerate", GST_TYPE_FRACTION, 30, 1,
- "alignment", G_TYPE_STRING, "au",
- "stream-format", G_TYPE_STRING, "byte-stream", NULL);
-
- LOGD("mime : %s, widht :%d, height : %d", core->mime, dec_info->width, dec_info->height);
-
- return MC_ERROR_NONE;
-}
-
-int __mc_vdec_h263_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple(core->mime,
- "variant", G_TYPE_STRING, "itu", NULL);
-
- LOGD("mime : %s, widht :%d, height : %d", core->mime, dec_info->width, dec_info->height);
- return MC_ERROR_NONE;
-}
-
-int __mc_vdec_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple(core->mime,
- "mpegversion", G_TYPE_INT, 4,
- "systemstream", G_TYPE_BOOLEAN, false, NULL);
-
- LOGD("mime : %s, widht :%d, height : %d", core->mime, dec_info->width, dec_info->height);
- return MC_ERROR_NONE;
-}
-
-int __mc_vdec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple(core->mime,
- "alignment", G_TYPE_STRING, "au",
- "stream-format", G_TYPE_STRING, "byte-stream", NULL);
-
- LOGD("mime : %s, widht :%d, height : %d", core->mime, dec_info->width, dec_info->height);
- return MC_ERROR_NONE;
-}
-
-int __mc_vdec_h264_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple(core->mime,
- "alignment", G_TYPE_STRING, "au",
- "stream-format", G_TYPE_STRING, "byte-stream", NULL);
-
- LOGD("mime : %s, widht :%d, height : %d", core->mime, dec_info->width, dec_info->height);
- return MC_ERROR_NONE;
-}
-
-int __mc_aenc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple(core->mime,
- "rate", G_TYPE_INT, enc_info->samplerate,
- "channels", G_TYPE_INT, enc_info->channel,
- "format", G_TYPE_STRING, "F32LE",
- "layout", G_TYPE_STRING, "interleaved", NULL);
-
- /*
- +----GstAudioEncoder
- +----avenc_aac
-
- Element Properties:
-compliance : Adherence of the encoder to the specifications
-flags: readable, writable
-Enum "GstFFMpegCompliance" Default: 0, "normal"
-(2): verystrict - Strictly conform to older spec
-(1): strict - Strictly conform to current spec
-(0): normal - Normal behavior
-(-1): unofficial - Allow unofficial extensions
-(-2): experimental - Allow nonstandardized experimental things
-*/
- g_object_set(GST_OBJECT(core->codec), "compliance", -2, NULL);
-
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, enc_info->samplerate, enc_info->channel);
-
- return MC_ERROR_NONE;
-}
-
-int __mc_aenc_aac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple(core->mime,
- "rate", G_TYPE_INT, enc_info->samplerate,
- "channels", G_TYPE_INT, enc_info->channel,
- "format", G_TYPE_STRING, "F32LE",
- "layout", G_TYPE_STRING, "interleaved", NULL);
-
- g_object_set(GST_OBJECT(core->codec), "compliance", -2, NULL);
-
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, enc_info->samplerate, enc_info->channel);
-
- return MC_ERROR_NONE;
-}
-
-int __mc_aenc_amrnb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple(core->mime,
- "rate", G_TYPE_INT, enc_info->samplerate,
- "channels", G_TYPE_INT, enc_info->channel,
- "format", G_TYPE_STRING, "S16LE",
- "layout", G_TYPE_STRING, "interleaved",
- NULL);
-
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, enc_info->samplerate, enc_info->channel);
-
- return MC_ERROR_NONE;
-}
-
-int __mc_adec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- int ret = MC_ERROR_NONE;
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- LOGD("CAPS for codec_id (MEDIACODEC_AAC_LC - normal ADTS)");
- *caps = gst_caps_new_simple(core->mime,
- "framed", G_TYPE_BOOLEAN, TRUE,
- "mpegversion", G_TYPE_INT, 4,
- "stream-format", G_TYPE_STRING, "adts",
- "rate", G_TYPE_INT, dec_info->samplerate,
- "channels", G_TYPE_INT, dec_info->channel,
- NULL);
-
- if (codec_config && (!core->encoder)) {
- guint codecdata_size = 16; /*AAC_CODECDATA_SIZE = 16 (in testsuit)*/
- ret = __mc_set_caps_codecdata(core, caps, buff, codecdata_size);
- if (ret != MC_ERROR_NONE) {
- LOGW("__mc_set_caps_codecdata failed");
- return ret;
- }
- }
-
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, dec_info->samplerate, dec_info->channel);
-
- return ret;
-}
-
-int __mc_adec_aac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
-{
- int ret = MC_ERROR_NONE;
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- LOGD("CAPS for codec_id (MEDIACODEC_AAC_LC - normal ADTS)");
- *caps = gst_caps_new_simple(core->mime,
- "framed", G_TYPE_BOOLEAN, TRUE,
- "mpegversion", G_TYPE_INT, 4,
- "stream-format", G_TYPE_STRING, "adts",
- "rate", G_TYPE_INT, dec_info->samplerate,
- "channels", G_TYPE_INT, dec_info->channel,
- NULL);
-
- if (codec_config && (!core->encoder)) {
- guint codecdata_size = 16; /*AAC_CODECDATA_SIZE = 16 (in testsuit)*/
- ret = __mc_set_caps_codecdata(core, caps, buff, codecdata_size);
- if (ret != MC_ERROR_NONE) {
- LOGW("__mc_set_caps_codecdata failed");
- return ret;
- }
- }
-
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, dec_info->samplerate, dec_info->channel);
-
- return ret;
-}
-
-int __mc_adec_aacv12_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer *buff, bool codec_config)
+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;
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- LOGD("CAPS for codec_id (MEDIACODEC_AAC_HE and _PS - MP4/M4A case)");
- *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",
- "channels", G_TYPE_INT, dec_info->channel,
- "rate", G_TYPE_INT, dec_info->samplerate,
- NULL);
-
- if (codec_config && (!core->encoder)) {
- guint codecdata_size = 16; /*AAC_CODECDATA_SIZE = 16 (in testsuit)*/
- ret = __mc_set_caps_codecdata(core, caps, buff, codecdata_size);
- if (ret != MC_ERROR_NONE) {
- LOGW("__mc_set_caps_codecdata failed");
- return ret;
- }
- }
-
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, dec_info->samplerate, dec_info->channel);
-
- return ret;
-}
-
-int __mc_adec_mp3_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer *buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- *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 */
- "rate", G_TYPE_INT, dec_info->samplerate,
- "channels", G_TYPE_INT, dec_info->channel,
- NULL);
-
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, dec_info->samplerate, dec_info->channel);
-
- return MC_ERROR_NONE;
-}
-
-int __mc_adec_amrnb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer *buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple(core->mime,
- "rate", G_TYPE_INT, 8000,
- "channels", G_TYPE_INT, dec_info->channel, /* FIXME - by 1 */
- NULL);
-
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, dec_info->samplerate, dec_info->channel);
-
- return MC_ERROR_NONE;
-}
-
-int __mc_adec_amrwb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer *buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- *caps = gst_caps_new_simple(core->mime,
- "rate", G_TYPE_INT, 16000,
- "channels", G_TYPE_INT, dec_info->channel, /* FIXME - by 1 */
- NULL);
-
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, dec_info->samplerate, dec_info->channel);
-
- return MC_ERROR_NONE;
-}
+ gint mem_size = 0;
+ GstPad *pad;
+ GstCaps *peercaps;
+ GstMapInfo map;
+ guint8 *ptr;
+ gsize len;
+ gchar *ext_mem = NULL;
+ const GValue *codec_data = NULL;
+ void *packet_data = NULL;
+ media_packet_h packet = NULL;
-int __mc_adec_vorbis_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer *buff, bool codec_config)
-{
g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
- int ret = MC_ERROR_NONE;
+ if (core->encoder && core->codec_id == MEDIACODEC_AAC)
+ media_format_set_audio_aac_type(core->output_fmt, FALSE);
- *caps = gst_caps_new_simple(core->mime,
- "channels", G_TYPE_INT, dec_info->channel,
- "rate", G_TYPE_INT, dec_info->samplerate,
- /* FIXME - Insert 'Stream Header' */
- NULL);
+ mem_size = GST_ROUND_UP_4(size);
+ ext_mem = g_malloc0(mem_size);
- LOGD(" ----- VORBIS Need Additional Caps -----------");
- /*
- * Need to extract from each Stream header ... or
- * Need to get Demuxer's Caps from each Stream heade
- */
- if (codec_config && (!core->encoder)) {
- guint streamheader_size = 4096; /* VORBIS_CODECDATA_SIZE = 4096 */
- ret = __mc_set_caps_streamheader(core, caps, buff, streamheader_size);
- if (ret != MC_ERROR_NONE) {
- LOGW("__mc_set_caps_streamheader failed");
- return ret;
- }
+ ret = media_packet_create_from_external_memory(core->output_fmt, ext_mem, mem_size, __mc_output_buffer_finalize_cb, mcbuffer, &packet);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ LOGW("media_packet_create_alloc failed");
+ g_free(ext_mem);
+ return MC_ERROR;
}
+ mcbuffer->packet = packet;
+ mcbuffer->ext_mem = ext_mem;
+
+ media_packet_set_buffer_size(packet, size);
+ media_packet_get_buffer_data_ptr(packet, &packet_data);
+ memcpy(packet_data, data, size);
+
+ if (!core->codec_data) {
+ pad = gst_element_get_static_pad(core->fakesink, "sink");
+ peercaps = gst_pad_get_current_caps(pad);
+ if (peercaps) {
+ GstStructure *s;
+ if (gst_caps_is_empty(peercaps)) {
+ gst_caps_unref(peercaps);
+ gst_object_unref(pad);
+ LOGW("Empty caps");
+ return ret;
+ }
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, dec_info->samplerate, dec_info->channel);
-
- return ret;
-}
-
-int __mc_adec_flac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer *buff, bool codec_config)
-{
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
- int ret = MC_ERROR_NONE;
-
- *caps = gst_caps_new_simple(core->mime,
- "channels", G_TYPE_INT, dec_info->channel,
- "rate", G_TYPE_INT, dec_info->samplerate,
- "framed", G_TYPE_BOOLEAN, TRUE,
- /* FIXME - Insert More Info */
- NULL);
+ 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");
- LOGD(" ----- FLAC Need Additional Caps -----------");
- /*
- * Need to extract from each Stream header ... or
- * Need to get Demuxer's Caps from each Stream heade
- */
- if (codec_config && (!core->encoder)) {
- guint streamheader_size = 4096; /* FLAC_CODECDATA_SIZE = 4096 */
- ret = __mc_set_caps_streamheader(core, caps, buff, streamheader_size);
- if (ret != MC_ERROR_NONE) {
- LOGW("__mc_set_caps_streamheader failed");
- return ret;
+ core->codec_data = GST_BUFFER(g_value_dup_boxed(codec_data));
+ gst_caps_unref(peercaps);
}
- }
-
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, dec_info->samplerate, dec_info->channel);
-
- return ret;
-}
-
-int __mc_adec_wma_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer *buff, bool codec_config)
-{
- int ret = MC_ERROR_NONE;
- g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
-
- mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info;
-
- /*
- * Need to extract from Stream Type Specific ... or
- * Need to get Demuxer's Caps from Stream Type Specific
- */
- guint16 format_tag = 0;
- gint wma_version = 0;
- gint block_align = 1024; /*FIXME : Need checking */
- gint bitrate = 128000; /*FIXME : Need checking */
-
- LOGD(" ----- WMA Need Additional Caps -----------");
- if (core->codec_id == MEDIACODEC_WMAV1) {
- format_tag = 352; /* 0x160 */
- wma_version = 1;
- } else if (core->codec_id == MEDIACODEC_WMAV2) {
- format_tag = 353; /* 0x161 */
- wma_version = 2;
- } else if (core->codec_id == MEDIACODEC_WMAPRO) {
- format_tag = 354; /* 0x162 */
- wma_version = 3;
- } else if (core->codec_id == MEDIACODEC_WMALSL) {
- format_tag = 355; /* 0x163 */
- wma_version = 3;
- } else {
- LOGE("Not support WMA format");
- }
-
- *caps = gst_caps_new_simple(core->mime,
- "rate", G_TYPE_INT, dec_info->samplerate,
- "channels", G_TYPE_INT, dec_info->channel,
- "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);
-
- if (codec_config && (!core->encoder)) {
- guint codecdata_size = 64; /* WMA_CODECDATA_SIZE = 64 */
- ret = __mc_set_caps_codecdata(core, caps, buff, codecdata_size);
- if (ret != MC_ERROR_NONE) {
- LOGW("__mc_set_caps_codecdata failed");
- return ret;
+ gst_object_unref(pad);
+ LOGD("codec data set");
+ }
+
+ if (core->codec_data) {
+ gst_buffer_map(core->codec_data, &map, GST_MAP_READ);
+ ptr = map.data;
+ len = map.size;
+ ret = media_packet_set_codec_data(packet, ptr, len);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ LOGW("media_packet_set_codec_data failed");
+ gst_buffer_unmap(core->codec_data, &map);
+ return MC_ERROR;
}
+ gst_buffer_unmap(core->codec_data, &map);
}
- LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, dec_info->samplerate, dec_info->channel);
-
return ret;
}
return caps;
}
-int __mc_set_caps_streamheader(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer*buff, guint streamheader_size)
+int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint streamheader_size)
{
- int ret = MEDIA_PACKET_ERROR_NONE;
- void *buf_data = NULL;
+ gint ret = MEDIA_PACKET_ERROR_NONE;
uint64_t buf_size = 0;
GstBuffer *header1, *header2, *header3;
guint hsize1, hsize2, hsize3;
GstBuffer *tmp_header;
- guint8 *tmp_buf = NULL;
GstMapInfo map;
+ guint8 *buf_data = NULL;
+ guint8 *tmp_buf = NULL;
- ret = media_packet_get_buffer_size(buff->pkt, &buf_size);
+ ret = media_packet_get_buffer_size(mcbuffer->packet, &buf_size);
if (ret != MEDIA_PACKET_ERROR_NONE) {
- LOGW("buffer size get fail");
+ LOGW("buffer size get failed");
return ret;
}
- ret = media_packet_get_buffer_data_ptr(buff->pkt, &buf_data);
+ ret = media_packet_get_buffer_data_ptr(mcbuffer->packet, (void **)&buf_data);
if (ret != MEDIA_PACKET_ERROR_NONE) {
- LOGW("buffer size get fail");
+ LOGW("buffer data get failed");
return ret;
}
LOGD("[vorbis] streamheader hsize1 (%d) + hsize2 (%d) + hsize3 (%d) = Total (%d)",
hsize1, hsize2, hsize3, (hsize1 + hsize2 + hsize3));
- __mc_gst_caps_set_buffer_array(*caps, "streamheader", header1, header2, header3, NULL);
+ __mc_gst_caps_set_buffer_array(core->caps, "streamheader", header1, header2, header3, NULL);
gst_buffer_unref(header1);
gst_buffer_unref(header2);
gst_buffer_unmap(header2, &map);
LOGD("[flac] streamheader hsize1 (%d) + hsize2 (%d) = Total (%d)", hsize1, hsize2, (hsize1 + hsize2));
- __mc_gst_caps_set_buffer_array(*caps, "streamheader", header1, header2, NULL);
+ __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");
}
/* Update gstbuffer's data ptr and size for using previous streamheader.*/
- LOGD("BEFORE : buff->buffer of size %" G_GSIZE_FORMAT "", gst_buffer_get_size(buff->buffer));
- gst_buffer_remove_memory_range(buff->buffer, streamheader_size, -1);
- gst_buffer_set_size(buff->buffer, buf_size - streamheader_size);
- LOGD("AFTER : buff->buffer of size %" G_GSIZE_FORMAT "", gst_buffer_get_size(buff->buffer));
+ LOGD("BEFORE : mcbuffer->buffer of size %" G_GSIZE_FORMAT "", gst_buffer_get_size(mcbuffer->buffer));
+ gst_buffer_remove_memory_range(mcbuffer->buffer, streamheader_size, -1);
+ gst_buffer_set_size(mcbuffer->buffer, buf_size - streamheader_size);
+ LOGD("AFTER : mcbuffer->buffer of size %" G_GSIZE_FORMAT "", gst_buffer_get_size(mcbuffer->buffer));
return ret;
}
-
-
-int __mc_set_caps_codecdata(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer *buff, guint codecdata_size)
+int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint fixed_size)
{
- int ret = MEDIA_PACKET_ERROR_NONE;
- void *buf_data = NULL;
- uint64_t buf_size = 0;
+ gint ret = MC_ERROR_NONE;
+ uint32_t codec_data_size = 0;
+ GstMapInfo map;
GstBuffer *codecdata_buffer;
-
- ret = media_packet_get_buffer_size(buff->pkt, &buf_size);
- if (ret != MEDIA_PACKET_ERROR_NONE) {
- LOGW("buffer size get fail");
- return ret;
- }
-
- ret = media_packet_get_buffer_data_ptr(buff->pkt, &buf_data);
- if (ret != MEDIA_PACKET_ERROR_NONE) {
- LOGW("buffer size get fail");
- return ret;
+ guint8 *data = NULL;
+ void *codec_data = NULL;
+
+ media_packet_get_codec_data(mcbuffer->packet, &codec_data, &codec_data_size);
+
+ if (codec_data != NULL) { /* get the codec data from media_packet_get_codec_data() */
+ data = g_malloc0(codec_data_size);
+ memcpy(data, codec_data, codec_data_size);
+ codecdata_buffer = gst_buffer_new_wrapped(data, codec_data_size);
+ gst_caps_set_simple(core->caps, "codec_data", GST_TYPE_BUFFER, codecdata_buffer, NULL);
+ LOGD("set codec data : %" G_GSIZE_FORMAT "", gst_buffer_get_size(codecdata_buffer));
+ gst_buffer_unref(codecdata_buffer);
+ } else { /* get the codec data from media_packet_get_buffer_data_ptr() */
+ uint64_t buffer_size = 0;
+ void *buff_data = NULL;
+
+ media_packet_get_buffer_size(mcbuffer->packet, &buffer_size);
+ media_packet_get_buffer_data_ptr(mcbuffer->packet, &buff_data);
+
+ /* For audio, it's necessary to change the offset value of buffer after extracting csd */
+ /* it's not necessary to set csd to caps in case of annex-b */
+ if (buffer_size > fixed_size) {
+ data = g_malloc0(fixed_size);
+ gst_buffer_map(mcbuffer->buffer, &map, GST_MAP_READ);
+ memcpy(data, map.data, fixed_size);
+ codecdata_buffer = gst_buffer_new_wrapped(data, fixed_size);
+ gst_caps_set_simple(core->caps, "codec_data", GST_TYPE_BUFFER, codecdata_buffer, NULL);
+ gst_buffer_unref(codecdata_buffer);
+
+ gst_buffer_replace_memory(mcbuffer->buffer, 0,
+ gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, map.data + fixed_size , buffer_size - fixed_size, 0,
+ buffer_size - fixed_size, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb));
+
+ LOGD("after : set codec data from packet: %" G_GSIZE_FORMAT "", gst_buffer_get_size(mcbuffer->buffer));
+ gst_buffer_unmap(mcbuffer->buffer, &map);
+ }
}
-
- LOGD("Set caps for codec_data in mime : %s and codec_id (0x%x)", core->mime, core->codec_id);
-
- /* Add the codec_data attribute to caps, if we have it */
- codecdata_buffer = gst_buffer_new();
- gst_buffer_copy_into(codecdata_buffer, buff->buffer, GST_BUFFER_COPY_MEMORY, 0, codecdata_size);
- gst_buffer_ref(codecdata_buffer);
- LOGD("setting codec_data from (packet) buf_data used codecdata_size (%d)", codecdata_size);
-
- gst_caps_set_simple(*caps, "codec_data", GST_TYPE_BUFFER, codecdata_buffer, NULL);
- gst_buffer_unref(codecdata_buffer);
-
- /* Update gstbuffer's data ptr and size for using previous codec_data..*/
- LOGD("BEFORE : buff->buffer of size %" G_GSIZE_FORMAT "", gst_buffer_get_size(buff->buffer));
-
- gst_buffer_replace_memory(buff->buffer, 0,
- gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data + codecdata_size , buf_size - codecdata_size, 0,
- buf_size - codecdata_size, buff, (GDestroyNotify)gst_mediacodec_buffer_finalize));
-
- LOGD("AFTER : buff->buffer of size %" G_GSIZE_FORMAT "", gst_buffer_get_size(buff->buffer));
-
return ret;
}
-
int _mc_output_media_packet_new(mc_gst_core_t *core, bool video, bool encoder, media_format_mimetype_e out_mime)
{
if (media_format_create(&core->output_fmt) != MEDIA_FORMAT_ERROR_NONE) {
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 {
- 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);
- 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;
-
- info = (mc_decoder_info_t *)core->codec_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);
- 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_mutex_init(&core->eos_mutex);
g_cond_init(&core->eos_cond);
+ g_cond_init(&core->buffer_cond);
+ g_cond_init(&core->out_buffer_cond);
g_mutex_init(&core->prepare_lock);
g_mutex_init(&core->drain_lock);
+ core->need_drain = false;
core->need_feed = false;
core->eos = false;
core->need_codec_data = false;
core->need_sync_flag = false;
core->unprepare_flag = false;
core->prepare_count = 0;
- core->queued_count = 0;
- core->dequeued_count = 0;
+ core->etb_count = 0;
+ core->codec_data = NULL;
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();
g_mutex_clear(&core->prepare_lock);
g_mutex_clear(&core->drain_lock);
g_cond_clear(&core->eos_cond);
+ g_cond_clear(&core->buffer_cond);
+ g_cond_clear(&core->out_buffer_cond);
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;
}
- LOGD("gst_core(%p) is destroyed", core);
+ LOGD("gst_core(%p) destroyed", core);
g_free(core);
MEDIACODEC_FLEAVE();
/*
* 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);
- g_cond_init(&port->buffer_cond);
port->queue = g_queue_new();
- LOGD("gst_port(%p) is created", port);
+ LOGD("gst_port(%p) created", port);
MEDIACODEC_FLEAVE();
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();
g_mutex_clear(&port->mutex);
- g_cond_clear(&port->buffer_cond);
g_queue_free(port->queue);
- LOGD("gst_port(%p) is freed", port);
+ LOGD("gst_port(%p) freed", port);
g_free(port);
MEDIACODEC_FLEAVE();
return;
}
-static void _mc_gst_update_caps(mc_gst_core_t *core, media_packet_h pkt, GstCaps **caps, GstMCBuffer* buff, bool codec_config)
+gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h format)
{
- /*TODO remove is_hw param*/
- core->format = __mc_get_gst_input_format(pkt, core->is_hw);
+ gboolean is_format_change = FALSE;
+
+ mc_gst_port_def_t *input_port_def = &core->ports[in_port_index]->port_def;
- GstPad *pad = NULL;
- GstCaps *template_caps;
+ if (core->video) {
+ gint width = 0;
+ gint height = 0;
+ gint bitrate = 0;
+ gint framerate = 0;
+ gchar *sformat = NULL;
+ media_format_mimetype_e mimetype = 0;
- pad = gst_element_get_static_pad(core->codec, "src");
- template_caps = gst_pad_get_pad_template_caps(pad);
+ media_format_get_video_info(format, &mimetype, &width, &height, &bitrate, NULL);
+ media_format_get_video_frame_rate(format, &framerate);
+
+ 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;
+ }
- __mc_create_caps(core, caps, buff, codec_config);
- g_object_set(core->appsrc, "caps", *caps, NULL);
+ if (core->encoder) {
+ 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 channel;
+ gint samplerate;
+ gint bit;
+ gint bitrate;
+
+ media_format_get_audio_info(format, NULL, &channel, &samplerate, &bit, &bitrate);
+
+ 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 (gst_caps_is_subset(*caps, template_caps))
- LOGD("new caps is subset of template caps");
+ if (core->encoder) {
+ 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;
+ }
+ }
+ }
- gst_object_unref(pad);
+ return is_format_change;
}
-static gpointer feed_task(gpointer data)
+static int _mc_set_codec_data(mc_gst_core_t *core, GstMCBuffer *mcbuffer, bool codec_config)
{
- mc_gst_core_t *core = (mc_gst_core_t *)data;
+ MEDIACODEC_FENTER();
+
+ g_return_val_if_fail(core != NULL, MC_PARAM_ERROR);
+ g_return_val_if_fail(mcbuffer != NULL, MC_PARAM_ERROR);
+
int ret = MC_ERROR_NONE;
+
+ 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");
+ }
+ 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;
+ }
+
+ MEDIACODEC_FLEAVE();
+ return ret;
+
+
+}
+
+static gpointer feed_task(gpointer data)
+{
+ gint ret = MC_ERROR_NONE;
bool codec_config = FALSE;
bool eos = FALSE;
- media_packet_h in_buf = NULL;
- GstMCBuffer *buff = NULL;
- GstCaps *new_caps = NULL;
- bool initiative = true;
+ bool initiative = TRUE;
+ bool is_format_change = FALSE;
+ media_format_h format = NULL;
+ media_packet_h input_buffer = NULL;
+ GstMCBuffer *mcbuffer = NULL;
MEDIACODEC_FENTER();
+ mc_gst_core_t *core = (mc_gst_core_t *)data;
+
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;
- if (media_packet_is_codec_config(in_buf, &codec_config) != MEDIA_PACKET_ERROR_NONE) {
+ 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(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;
}
+ /*
+ * receive an eos packet. For decoder + encoder case, encoder always get tbm surface plane first from input data,
+ * but eos packet only has flag not valid data, so we don't put it to downstream.
+ */
+ if (eos) {
+ LOGD("end of stream");
+ gst_app_src_end_of_stream(GST_APP_SRC(core->appsrc));
+ _mc_wait_for_eos(core);
+ initiative = TRUE;
+
+ _mc_gst_handle_input_buffer_used(core, input_buffer);
+ goto LEAVE;
+ }
- buff = _mc_gst_media_packet_to_gstbuffer(core, &new_caps, in_buf, codec_config);
- if (!buff) {
+ mcbuffer = _mc_gst_media_packet_to_gstbuffer(core, input_buffer, codec_config);
+ if (!mcbuffer) {
LOGW("gstbuffer can't make");
goto ERROR;
}
-
- if (codec_config)
- initiative = true;
-
- if (initiative) {
- GstPad *pad;
-
- _mc_gst_update_caps(core, in_buf, &new_caps, buff, codec_config);
-
+ /* 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("sejun"));
+ 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, buff);
+ ret = _mc_gst_gstbuffer_to_appsrc(core, mcbuffer);
if (ret != GST_FLOW_OK) {
LOGE("Failed to push gst buffer");
goto ERROR;
}
- initiative = false;
-
- if (eos) {
- LOGD("end of stream");
- gst_app_src_end_of_stream(GST_APP_SRC(core->appsrc));
- _mc_wait_for_eos(core);
- initiative = true;
- }
-
-
continue;
ERROR:
+ if (input_buffer)
+ _mc_gst_handle_input_buffer_used(core, input_buffer);
+
_mc_gst_set_flush_input(core);
if (core->user_cb[_MEDIACODEC_EVENT_TYPE_ERROR]) {
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;
}
- if (new_caps)
- gst_caps_unref(new_caps);
-
- 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();
}
}
+GstCaps *_mc_gst_aud_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,
+ "rate", G_TYPE_INT, port_def->info.audio.samplerate,
+ "channels", G_TYPE_INT, port_def->info.audio.channel, NULL);
+
+ switch (codec_id) {
+ case MEDIACODEC_AAC:
+ 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)");
+ }
+ break;
+ case MEDIACODEC_AAC_HE:
+ case MEDIACODEC_AAC_HE_PS:
+ if (core->encoder) {
+ LOGD("[MC_NOT_SUPPORTED] he-aac-v12 encoder is not supported yet!!!");
+ return NULL;
+ } else {
+ 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:
+ if (core->encoder) {
+ LOGD("[MC_NOT_SUPPORTED] mp3 encoder is not supported yet!!!");
+ return NULL;
+ } else {
+ 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:
+ 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 {
+ gst_caps_set_simple(caps,
+ "rate", G_TYPE_INT, 8000,
+ NULL);
+ }
+ break;
+ case MEDIACODEC_AMR_WB:
+ if (core->encoder) {
+ LOGD("[MC_NOT_SUPPORTED] amr-wb encoder is not supported yet!!!");
+ return NULL;
+ } else {
+ gst_caps_set_simple(caps,
+ "rate", G_TYPE_INT, 16000,
+ NULL);
+ }
+ break;
+ case MEDIACODEC_VORBIS:
+ if (core->encoder) {
+ LOGD("[MC_NOT_SUPPORTED] vorbis encoder is not supported yet!!!");
+ return NULL;
+ } else {
+ }
+ break;
+ case MEDIACODEC_FLAC:
+ if (core->encoder) {
+ LOGD("[MC_NOT_SUPPORTED] flac encoder is not supported yet!!!");
+ return NULL;
+ } else {
+ 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:
+ if (core->encoder) {
+ LOGD("[MC_NOT_SUPPORTED] wma encoder is not supported yet!!!");
+ return NULL;
+ } else {
+ /*
+ * Need to extract from Stream Type Specific ... or
+ * Need to get Demuxer's Caps from Stream Type Specific
+ */
+ guint16 format_tag = 0;
+ gint wma_version = 0;
+ gint block_align = 1024; /*FIXME : Need checking */
+ gint bitrate = 128000; /*FIXME : Need checking */
+
+ LOGD(" ----- WMA Need Additional Caps -----------");
+ if (core->codec_id == MEDIACODEC_WMAV1) {
+ format_tag = 352; /* 0x160 */
+ wma_version = 1;
+ } else if (core->codec_id == MEDIACODEC_WMAV2) {
+ format_tag = 353; /* 0x161 */
+ wma_version = 2;
+ } else if (core->codec_id == MEDIACODEC_WMAPRO) {
+ format_tag = 354; /* 0x162 */
+ wma_version = 3;
+ } else if (core->codec_id == MEDIACODEC_WMALSL) {
+ format_tag = 355; /* 0x163 */
+ wma_version = 3;
+ } else {
+ LOGE("Not support WMA format");
+ }
+
+ 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();
switch (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");
- core->vtable = encoder ? aenc_aac_vtable : adec_aac_vtable;
+ if (encoder)
+ core->vtable = aenc_aac_vtable;
+ else
+ core->vtable = adec_aac_vtable;
break;
case MEDIACODEC_AAC_HE:
case MEDIACODEC_AAC_HE_PS:
- LOGD("aac he v12 vtable");
- core->vtable = encoder ? aenc_aac_vtable : adec_aacv12_vtable;
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:
- LOGD("mp3 vtable - Only support decoder");
- core->vtable = encoder ? aenc_vtable : adec_mp3_vtable;
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");
- core->vtable = encoder ? aenc_amrnb_vtable : adec_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");
- core->vtable = encoder ? aenc_vtable : adec_amrwb_vtable;
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");
- core->vtable = encoder ? aenc_vtable : adec_vorbis_vtable;
- if (encoder) {
- LOGD("[MC_NOT_SUPPORTED] vorbis encoder is not supported yet!!!");
+ if (encoder)
return MC_NOT_SUPPORTED;
- }
+ else
+ core->vtable = adec_vorbis_vtable;
break;
case MEDIACODEC_FLAC:
LOGD("flac vtable");
- core->vtable = encoder ? aenc_vtable : adec_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");
- core->vtable = encoder ? aenc_vtable : adec_wma_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");
- core->vtable = encoder ? (is_hw ? venc_h263_hw_vtable : venc_h263_sw_vtable) : is_hw ? vdec_h263_hw_vtable : vdec_h263_sw_vtable;
+ if (encoder) {
+ core->vtable = is_hw ? venc_h263_hw_vtable : venc_h263_sw_vtable;
+ } else {
+ if (is_hw)
+ core->vtable = vdec_h263_hw_vtable;
+ else
+ core->vtable = vdec_h263_sw_vtable;
+ }
break;
case MEDIACODEC_MPEG4:
LOGD("mpeg4 vtable");
- core->vtable = encoder ? (is_hw ? venc_mpeg4_hw_vtable : venc_mpeg4_sw_vtable) : is_hw ? vdec_mpeg4_hw_vtable : vdec_mpeg4_sw_vtable;
-
+ if (encoder)
+ core->vtable = is_hw ? venc_mpeg4_hw_vtable : venc_mpeg4_sw_vtable;
+ else
+ core->vtable = is_hw ? vdec_mpeg4_hw_vtable : vdec_mpeg4_sw_vtable;
break;
case MEDIACODEC_H264:
LOGD("h264 vtable");
- core->vtable = encoder ? (is_hw ? venc_h264_hw_vtable : venc_vtable) : is_hw ? vdec_h264_hw_vtable : vdec_h264_sw_vtable;
+ if (encoder) {
+ core->vtable = is_hw ? venc_h264_hw_vtable : venc_vtable;
+ } else {
+ if (is_hw)
+ core->vtable = vdec_h264_hw_vtable;
+ else
+ core->vtable = vdec_h264_sw_vtable;
+ }
break;
default:
break;
}
+ MEDIACODEC_FLEAVE();
+
return MC_ERROR_NONE;
}
-static int _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *buff)
+static gint _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *mcbuffer)
{
- MEDIACODEC_FENTER();
-
- int ret = MC_ERROR_NONE;
-
- LOGD("pushed buffer to appsrc : %p, buffer of size %" G_GSIZE_FORMAT "",
- buff->buffer, gst_buffer_get_size(buff->buffer));
-
- ret = gst_app_src_push_buffer(GST_APP_SRC(core->appsrc), buff->buffer);
-
- 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) {
LOGD("factory name : %s, output_fmt : %x", factory_name, out_mime);
/* create media_packet for output fmt */
- if ((ret = _mc_output_media_packet_new(new_core, video, encoder, out_mime)) != MC_ERROR_NONE) {
+ ret = _mc_output_media_packet_new(new_core, video, encoder, out_mime);
+ if (ret != MC_ERROR_NONE) {
LOGE("Failed to create output pakcet");
return ret;
}
- /* link vtable */
- if ((ret = _mc_link_vtable(new_core, id, encoder, hardware)) != MC_ERROR_NONE) {
- LOGE("vtable link failed");
- return ret;
- }
-
for (i = 0; i < _MEDIACODEC_EVENT_TYPE_INTERNAL_FILLBUFFER ; i++) {
LOGD("copy cb function [%d]", i);
if (mc_handle->user_cb[i]) {
}
}
- 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(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;
}
}
}
+ 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();
int ret = MC_ERROR_NONE;
mc_gst_core_t *core = NULL;
- GTimeVal nowtv;
if (!mc_handle)
return MC_PARAM_ERROR;
core = (mc_gst_core_t *)mc_handle->core;
- g_get_current_time(&nowtv);
- g_time_val_add(&nowtv, 500 * 1000); /* usec */
- /*
- if (!g_cond_timed_wait(&nowtv)) {
- }
- */
+ g_mutex_lock(&core->drain_lock);
+
+ while (g_atomic_int_get(&core->etb_count) == MAXINUM_QNUM) {
+ LOGD("Waiting until packets are drained..");
+ core->need_drain = true;
+ g_cond_wait(&core->buffer_cond, &core->drain_lock);
+ }
+ g_mutex_unlock(&core->drain_lock);
if (core->prepare_count == 0)
- return MEDIACODEC_ERROR_INVALID_STATE;
+ return MC_INVALID_STATUS;
g_mutex_lock(&core->drain_lock);
}
g_mutex_unlock(&core->drain_lock);
- LOGI("@v(%d)e(%d)process_input(%d): %p", core->video, core->encoder, core->queued_count, inbuf);
- core->queued_count++;
+ g_atomic_int_inc(&core->etb_count);
+ LOGI("@v(%d)e(%d)process_input(%d): %p", core->video, core->encoder, core->etb_count, inbuf);
MEDIACODEC_FLEAVE();
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)
{
- MEDIACODEC_FENTER();
-
- int ret = MC_ERROR_NONE;
+ gint ret = MC_ERROR_NONE;
+ gint64 end_time = -1;
+ gboolean signalled;
mc_gst_core_t *core = NULL;
- media_packet_h out_pkt = NULL;
+ media_packet_h out_packet = NULL;
+
+ MEDIACODEC_FENTER();
+ end_time = g_get_monotonic_time() + timeout_us;
if (!mc_handle)
return MC_PARAM_ERROR;
core = (mc_gst_core_t *)mc_handle->core;
- LOGI("@%p v(%d)e(%d) get_output", core, core->video, core->encoder);
g_mutex_lock(&core->ports[1]->mutex);
- if (!g_queue_is_empty(core->ports[1]->queue)) {
- out_pkt = g_queue_pop_head(core->ports[1]->queue);
- LOGD("pop from output_queue : %p", out_pkt);
- } else {
+ if (!g_queue_is_empty(core->ports[1]->queue))
+ signalled = TRUE;
+ else {
+ LOGD("no buffer, wait for signal");
+ signalled = g_cond_wait_until(&core->out_buffer_cond, &core->ports[1]->mutex, end_time);
+ }
+
+ if (signalled)
+ out_packet = g_queue_pop_head(core->ports[1]->queue);
+ else {
+ LOGW("Failed to get buffer");
ret = MC_OUTPUT_BUFFER_EMPTY;
- LOGD("output_queue is empty");
}
- *outbuf = out_pkt;
+
+ *outbuf = out_packet;
+ LOGI("@%p v(%d)e(%d) got buffer :%p", core, core->video, core->encoder, out_packet);
g_mutex_unlock(&core->ports[1]->mutex);
mc_ret_e mc_gst_flush_buffers(mc_handle_t *mc_handle)
{
- MEDIACODEC_FENTER();
-
- int ret = MC_ERROR_NONE;
+ gint ret = MC_ERROR_NONE;
mc_gst_core_t *core = NULL;
+ MEDIACODEC_FENTER();
+
if (!mc_handle)
return MC_PARAM_ERROR;
{
MEDIACODEC_FENTER();
+ gint i = 0;
+ gint arg_count = 0;
static gboolean initialized = FALSE;
static const int max_argc = 50;
gint *argc = NULL;
gchar **argv = NULL;
gchar **argv2 = NULL;
GError *err = NULL;
- int i = 0;
- int arg_count = 0;
if (initialized) {
LOGD("gstreamer already initialized.\n");
return TRUE;
ERROR:
-
/* release */
for (i = 0; i < arg_count; i++) {
LOGD("free[%d] : %s\n", i, argv2[i]);
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;
goto ERROR;
}
+ if (!core->video && core->encoder) {
+ core->audioconvert = gst_element_factory_make("audioconvert", NULL);
+
+ if (!core->audioconvert) {
+ 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);
if (!core->capsfilter) {
g_object_set(core->fakesink, "enable-last-sample", FALSE, NULL);
/*__mc_link_elements(core);*/
- gst_bin_add_many(GST_BIN(core->pipeline), core->appsrc, core->capsfilter, core->codec, core->fakesink, NULL);
+ if (!core->video && core->encoder) {
+ 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->capsfilter, core->codec, core->fakesink, NULL))) {
- LOGE("gst_element_link_many is failed");
- goto ERROR;
+ /* 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->codec, core->fakesink, NULL))) {
+ LOGE("gst_element_link_many is failed");
+ goto ERROR;
+ }
+ } else {
+ 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->codec, core->fakesink, NULL))) {
+ LOGE("gst_element_link_many is failed");
+ goto ERROR;
+ }
}
/* connect signals, bus watcher */
bus = gst_pipeline_get_bus(GST_PIPELINE(core->pipeline));
- core->bus_whatch_id = gst_bus_add_watch(bus, __mc_gst_bus_callback, core);
+ core->bus_watch_id = gst_bus_add_watch(bus, __mc_gst_bus_callback, core);
core->thread_default = g_main_context_get_thread_default();
/* set sync handler to get tag synchronously */
/* set state PLAYING */
MEDIACODEC_ELEMENT_SET_STATE(GST_ELEMENT_CAST(core->pipeline), GST_STATE_PLAYING);
+
}
core->prepare_count++;
g_mutex_unlock(&core->prepare_lock);
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));
+
if (core->fakesink)
gst_object_unref(GST_OBJECT(core->fakesink));
}
}
- if (core->bus_whatch_id) {
+ if (core->bus_watch_id) {
GSource *source = NULL;
- source = g_main_context_find_source_by_id(core->thread_default, core->bus_whatch_id);
+ source = g_main_context_find_source_by_id(core->thread_default, core->bus_watch_id);
g_source_destroy(source);
- LOGD("bus_whatch_id destroy");
+ LOGD("bus_watch_id destroy");
}
MEDIACODEC_ELEMENT_SET_STATE(core->pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(core->pipeline));
+ if (core->caps) {
+ gst_caps_unref(core->caps);
+ core->caps = NULL;
+ }
}
}
return MC_ERROR;
}
-void __mc_gst_buffer_add(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer data)
+void __mc_push_output_to_queue(mc_gst_core_t *core, GstMCBuffer *mcbuffer)
{
- guint n;
- GstMemory *mem;
- GstMapInfo map = GST_MAP_INFO_INIT;
- media_packet_h out_pkt = NULL;
+ g_mutex_lock(&core->ports[1]->mutex);
- MEDIACODEC_FENTER();
+ /* push it to output buffer queue */
+ g_queue_push_tail(core->ports[1]->queue, mcbuffer->packet);
+ g_cond_broadcast(&core->out_buffer_cond);
- mc_gst_core_t *core = (mc_gst_core_t *)data;
+ if (mcbuffer->buffer) {
+ LOGD("dq : v(%d)e(%d) TIMESTAMP = %"GST_TIME_FORMAT " DURATION = %"GST_TIME_FORMAT, core->video, core->encoder,
+ GST_TIME_ARGS(GST_BUFFER_TIMESTAMP(mcbuffer->buffer)), GST_TIME_ARGS(GST_BUFFER_DURATION(mcbuffer->buffer)));
+ } else {
+ LOGD("dq : v(%d)e(%d)", core->video, core->encoder);
+ }
- gst_buffer_ref(buffer);
+ g_mutex_unlock(&core->ports[1]->mutex);
+
+ if (core->user_cb[_MEDIACODEC_EVENT_TYPE_FILLBUFFER]) {
+ ((mc_fill_buffer_cb) core->user_cb[_MEDIACODEC_EVENT_TYPE_FILLBUFFER])
+ (mcbuffer->packet, core->user_data[_MEDIACODEC_EVENT_TYPE_FILLBUFFER]);
+ }
+}
- n = gst_buffer_n_memory(buffer);
+void __mc_gst_buffer_add(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer data)
+{
+ GstMCBuffer *mcbuffer = NULL;
- mem = gst_buffer_peek_memory(buffer, n-1);
+ MEDIACODEC_FENTER();
- gst_memory_map(mem, &map, GST_MAP_READ);
- LOGD("n : %d, map.data : %p, map.size : %d", n, map.data, map.size);
+ mc_gst_core_t *core = (mc_gst_core_t *)data;
- out_pkt = __mc_gst_make_media_packet(core, map.data, map.size);
+ gst_buffer_ref(buffer);
- LOGI("@%p(%d) out_pkt : %p", core, core->encoder, out_pkt);
- gst_memory_unmap(mem, &map);
+ mcbuffer = __mc_gst_make_media_packet(core, buffer);
+ LOGI("@%p(%d) out_packet : %p", core, core->encoder, mcbuffer->packet);
- if (out_pkt) {
- media_packet_set_extra(out_pkt, buffer);
- media_packet_set_pts(out_pkt, GST_BUFFER_TIMESTAMP(buffer));
+ if (mcbuffer->packet) {
+ media_packet_set_pts(mcbuffer->packet, GST_BUFFER_TIMESTAMP(buffer));
+ media_packet_set_dts(mcbuffer->packet, GST_BUFFER_DTS(buffer));
+ media_packet_set_duration(mcbuffer->packet, GST_BUFFER_DURATION(buffer));
if (core->need_codec_data) {
- media_packet_set_flags(out_pkt, MEDIA_PACKET_CODEC_CONFIG);
+ media_packet_set_flags(mcbuffer->packet, MEDIA_PACKET_CODEC_CONFIG);
core->need_codec_data = false;
}
if (core->need_sync_flag) {
- media_packet_set_flags(out_pkt, MEDIA_PACKET_SYNC_FRAME);
+ media_packet_set_flags(mcbuffer->packet, MEDIA_PACKET_SYNC_FRAME);
core->need_sync_flag = false;
}
- g_mutex_lock(&core->ports[1]->mutex);
- /* push it to output buffer queue */
- g_queue_push_tail(core->ports[1]->queue, out_pkt);
-
- core->dequeued_count++;
- LOGD("dequeued : %d", core->dequeued_count);
- LOGD("GST_BUFFER_TIMESTAMP = %"GST_TIME_FORMAT, GST_TIME_ARGS(GST_BUFFER_TIMESTAMP(buffer)));
-
- g_mutex_unlock(&core->ports[1]->mutex);
-
- if (core->user_cb[_MEDIACODEC_EVENT_TYPE_FILLBUFFER]) {
- ((mc_fill_buffer_cb) core->user_cb[_MEDIACODEC_EVENT_TYPE_FILLBUFFER])
- (out_pkt, core->user_data[_MEDIACODEC_EVENT_TYPE_FILLBUFFER]);
- }
+ __mc_push_output_to_queue(core, mcbuffer);
+ } else {
+ gst_buffer_unref(buffer);
+ LOGE("Failed to dequeue output packet");
}
MEDIACODEC_FLEAVE();
int __mc_output_buffer_finalize_cb(media_packet_h packet, int error_code, void *user_data)
{
- void *buffer = NULL;
- int i = 0;
- guint n;
- GstMemory *mem;
- GstMapInfo map = GST_MAP_INFO_INIT;
- MMVideoBuffer *mm_video_buf = NULL;
- mc_gst_core_t *core = NULL;
+ MEDIACODEC_FENTER();
- core = (mc_gst_core_t*)user_data;
+ GstMCBuffer *mcbuffer = (GstMCBuffer *)user_data;
- LOGD("packet finalized: %p", packet);
- media_packet_get_extra(packet, &buffer);
+ gst_buffer_unref((GstBuffer *)mcbuffer->buffer);
- n = gst_buffer_n_memory(buffer);
+ if (mcbuffer->ext_mem) {
+ g_free(mcbuffer->ext_mem);
+ LOGD("freed external memory");
+ mcbuffer->ext_mem = NULL;
+ }
- if (n > 1) {
- mem = gst_buffer_peek_memory(buffer, n-1);
- gst_memory_map(mem, &map, GST_MAP_READ);
- mm_video_buf = (MMVideoBuffer *)map.data;
+ LOGD("output port filled buffer : %p", packet);
+ g_free(mcbuffer);
- 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 *)buffer);
+ MEDIACODEC_FLEAVE();
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:
return format;
}
-GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t* core, GstCaps **caps, media_packet_h pkt, bool codec_config)
+GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t *core, media_packet_h packet, bool codec_config)
{
- int ret = MEDIA_PACKET_ERROR_NONE;
- GstMCBuffer *mc_buffer = NULL;
- void *buf_data = NULL;
+ gint ret = MEDIA_PACKET_ERROR_NONE;
uint64_t buf_size = 0;
uint64_t pts = 0;
+ uint64_t dts = 0;
uint64_t dur = 0;
+ void *buf_data = NULL;
+ GstMCBuffer *mcbuffer = NULL;
- ret = media_packet_get_buffer_size(pkt, &buf_size);
+ ret = media_packet_get_buffer_size(packet, &buf_size);
if (ret != MEDIA_PACKET_ERROR_NONE) {
LOGW("buffer size get fail");
return NULL;
}
- ret = media_packet_get_buffer_data_ptr(pkt, &buf_data);
+ ret = media_packet_get_buffer_data_ptr(packet, &buf_data);
if (ret != MEDIA_PACKET_ERROR_NONE) {
- LOGW("buffer size get fail");
+ LOGW("buffer data get fail");
return NULL;
}
- mc_buffer = gst_mediacodec_buffer_new(core, pkt, buf_size);
- if (mc_buffer == NULL) {
+ mcbuffer = gst_mediacodec_buffer_new(core, packet, buf_size);
+ if (mcbuffer == NULL) {
LOGW("failed to create inbuf");
return NULL;
}
- LOGD("pkt : %p, buf_size : %d", pkt, (int)buf_size);
+ LOGD("packet :v(%d)e(%d) %p, buf_size : %d", core->video, core->encoder, packet, (int)buf_size);
- ret = __mc_fill_input_buffer(core, pkt, mc_buffer);
+ ret = __mc_fill_input_buffer(core, packet, mcbuffer);
if (ret != MC_ERROR_NONE) {
LOGW("failed to fill inbuf: %s (ox%08x)", _mc_error_to_string(ret), ret);
+ /*
+ * if __mc_fill_input_buffer() failed, no memory appended to mcbuffer->buffer, so gst_mediacodec_buffer_finalize()
+ * will not be invoked
+ */
+ gst_buffer_unref(mcbuffer->buffer);
+ g_free(mcbuffer);
return NULL;
}
+ /* dts */
+ media_packet_get_pts(packet, &dts);
+ GST_BUFFER_DTS(mcbuffer->buffer) = dts;
+
/* pts */
- media_packet_get_pts(pkt, &pts);
- GST_BUFFER_PTS(mc_buffer->buffer) = pts;
+ media_packet_get_pts(packet, &pts);
+ GST_BUFFER_PTS(mcbuffer->buffer) = pts;
/* duration */
- media_packet_get_duration(pkt, &dur);
- GST_BUFFER_DURATION(mc_buffer->buffer) = dur;
+ media_packet_get_duration(packet, &dur);
+ GST_BUFFER_DURATION(mcbuffer->buffer) = dur;
+
+ GST_BUFFER_OFFSET(mcbuffer->buffer) = core->offset;
- return mc_buffer;
+ core->offset += buf_size;
+ GST_BUFFER_OFFSET_END(mcbuffer->buffer) = core->offset;
+
+ return mcbuffer;
}
-media_packet_h __mc_gst_make_media_packet(mc_gst_core_t *core, unsigned char *data, int size)
+GstMCBuffer *__mc_gst_make_media_packet(mc_gst_core_t *core, GstBuffer *buffer)
{
- int ret = MEDIA_PACKET_ERROR_NONE;
- media_packet_h pkt = NULL;
+ gint ret = MEDIA_PACKET_ERROR_NONE;
+ GstMemory *mem;
+ GstMapInfo map = GST_MAP_INFO_INIT;
+ GstMCBuffer *mcbuffer = NULL;
+ void *data = NULL;
+ gint size = 0;
+
+
+ mcbuffer = (GstMCBuffer *)g_malloc0(sizeof(*mcbuffer));
- ret = __mc_fill_output_buffer(core, data, size, &pkt);
+ if (mcbuffer == NULL) {
+ LOGE("malloc fail");
+ return NULL;
+ }
+
+ mem = gst_buffer_peek_memory(buffer, 0);
+
+ 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 = size;
+
+ 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);
return NULL;
}
+ return mcbuffer;
+}
+
+int __mc_gst_create_eos_packet(media_format_h fmt, GstMCBuffer *mcbuffer)
+{
+ gint ret = MC_ERROR_NONE;
+ media_packet_h packet = NULL;
+
+ MEDIACODEC_FENTER();
+ if (media_packet_create(fmt, __mc_output_buffer_finalize_cb, mcbuffer, &packet)) {
+ LOGE("media_packet_create failed\n");
+ ret = MC_ERROR;
+ goto ERROR;
+ }
+
+ if (media_packet_set_flags(packet, MEDIA_PACKET_END_OF_STREAM)) {
+ LOGE("unable to set EOS flag\n");
+ ret = MC_ERROR;
+ goto ERROR;
+ }
+
+ mcbuffer->buffer = NULL;
+ mcbuffer->ext_mem = NULL;
+ mcbuffer->buf_size = 0;
+ mcbuffer->packet = packet;
+ MEDIACODEC_FLEAVE();
+
+ return ret;
+ERROR:
+ if (packet)
+ media_packet_destroy(packet);
+ MEDIACODEC_FLEAVE();
+ return ret;
+}
+
+void _mc_gst_handle_input_buffer_used(mc_gst_core_t *core, media_packet_h packet)
+{
+ if (core) {
+ g_atomic_int_dec_and_test(&core->etb_count);
+ LOGD("@v(%d)e(%d) input port used(%d)----- ", core->video, core->encoder, core->etb_count);
+ }
+
+ if (core && core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) {
+ ((mc_empty_buffer_cb)core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER])
+ (packet, core->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]);
+
+ g_mutex_lock(&core->drain_lock);
- return pkt;
+ if (core->need_drain) {
+ LOGD("@v(%d)e(%d) input port used----- single process_input.....", core->video, core->encoder);
+ core->need_drain = false;
+ g_cond_signal(&core->buffer_cond);
+ }
+ g_mutex_unlock(&core->drain_lock);
+ }
}
gboolean __mc_gst_bus_callback(GstBus *bus, GstMessage *msg, gpointer data)
{
- int ret = MC_ERROR_NONE;
+ gint ret = MC_ERROR_NONE;
+ GstMCBuffer *mcbuffer = NULL;
+
mc_gst_core_t *core = (mc_gst_core_t *)data;
- LOGD("@%p v(%d)e(%d)", core, core->video, core->encoder);
+ LOGI("@%p v(%d)e(%d)bus message : %s", core, core->video, core->encoder, gst_message_type_get_name(GST_MESSAGE_TYPE(msg)));
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
_mc_send_eos_signal(core);
+ mcbuffer = (GstMCBuffer *)g_malloc0(sizeof(GstMCBuffer));
+ if (__mc_gst_create_eos_packet(core->output_fmt, mcbuffer) == MC_ERROR_NONE) {
+ __mc_push_output_to_queue(core, mcbuffer);
+ LOGD("send eos packet.");
+ } else {
+ LOGE("failed to create eos packet.");
+ g_free(mcbuffer);
+ }
+
if (core->user_cb[_MEDIACODEC_EVENT_TYPE_EOS]) {
LOGD("eos callback invoked");
((mc_eos_cb) core->user_cb[_MEDIACODEC_EVENT_TYPE_EOS])(core->user_data[_MEDIACODEC_EVENT_TYPE_EOS]);
else
LOGW("Unexpected error has occured");
+ g_mutex_lock(&core->drain_lock);
+
+ if (core->need_drain) {
+ LOGD("@v(%d)e(%d) input port used----- single process_input.....", core->video, core->encoder);
+ core->need_drain = false;
+ g_cond_signal(&core->buffer_cond);
+ }
+
+ g_mutex_unlock(&core->drain_lock);
+
if (core->user_cb[_MEDIACODEC_EVENT_TYPE_ERROR]) {
((mc_error_cb) core->user_cb[_MEDIACODEC_EVENT_TYPE_ERROR])
(ret, core->user_data[_MEDIACODEC_EVENT_TYPE_ERROR]);
static gboolean __mc_gst_check_useful_message(mc_gst_core_t *core, GstMessage *msg)
{
- gboolean retval = false;
+ gboolean retval = FALSE;
if (!core->pipeline) {
LOGE("mediacodec pipeline handle is null");
- return true;
+ return TRUE;
}
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
case GST_MESSAGE_ERROR:
case GST_MESSAGE_WARNING:
- retval = true;
+ retval = TRUE;
break;
default:
- retval = false;
+ retval = FALSE;
break;
}
mc_gst_core_t *core = (mc_gst_core_t *)data;
GstBusSyncReply reply = GST_BUS_DROP;
- LOGD("__mc_gst_bus_sync_callback is called");
+ LOGD("__mc_gst_bus_sync_callback is called : %s", gst_message_type_get_name(GST_MESSAGE_TYPE(msg)));
if (!core->pipeline) {
LOGE("mediacodec pipeline handle is null");
return reply;
}
-static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t* core, media_packet_h pkt)
+static GstMemory *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, GstMCBuffer *mcbuffer)
{
- int i;
- int num_bos;
+ int ret = MEDIA_PACKET_ERROR_NONE;
tbm_surface_h surface = NULL;
- tbm_surface_info_s surface_info;
- mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info;
+ GstVideoInfo vinfo;
+ GstMemory *mem = NULL;
- if (!pkt) {
+ 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");
+ ret = media_packet_get_tbm_surface(mcbuffer->packet, &surface);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ LOGE("Failed to get tbm surface");
return NULL;
}
- memset(mm_vbuffer, 0x00, sizeof(MMVideoBuffer));
- media_packet_get_tbm_surface(pkt, &surface);
- num_bos = tbm_surface_internal_get_num_bos(surface);
- int 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);
- LOGE("mm_vbuffer->handle.bo[%d] : %p", i, mm_vbuffer->handle.bo[i]);
- }
-
- tbm_bo_handle handle = tbm_bo_get_handle(mm_vbuffer->handle.bo[0], TBM_DEVICE_CPU);
-#ifdef TIZEN_PROFILE_LITE
- int phy_addr = 0;
- int phy_size = 0;
- tbm_bo_handle handle_fd = tbm_bo_get_handle(mm_vbuffer->handle.bo[0], TBM_DEVICE_MM);
-
- if (__tbm_get_physical_addr_bo(handle_fd, &phy_addr, &phy_size) == 0) {
- mm_vbuffer->handle.paddr[0] = (void *)phy_addr;
- LOGD("mm_vbuffer->paddr : %p", mm_vbuffer->handle.paddr[0]);
- }
-#endif
-
- 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->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;
- 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]);
+ mem = gst_tizen_allocator_alloc_surface(core->allocator,
+ &vinfo, surface, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb);
- return mm_vbuffer;
+ return mem;
}
-static void gst_mediacodec_buffer_finalize(GstMCBuffer *mc_buffer)
+static void __mc_input_buffer_finalize_cb(GstMCBuffer *mcbuffer)
{
- if (!mc_buffer)
+ MEDIACODEC_FENTER();
+
+ if (!mcbuffer)
return;
- mc_gst_core_t *core = (mc_gst_core_t *)mc_buffer->core;
+ LOGD("============>>>>> _finalize_cb : %p, %p", mcbuffer, mcbuffer->packet);
- if (core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) {
- ((mc_empty_buffer_cb) core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER])
- (mc_buffer->pkt, core->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]);
- }
+ _mc_gst_handle_input_buffer_used(mcbuffer->core, mcbuffer->packet);
- LOGD("%p(%p) buffer finalized...", mc_buffer, mc_buffer->pkt);
- free(mc_buffer);
- mc_buffer = NULL;
+ g_free(mcbuffer);
- return;
+ MEDIACODEC_FLEAVE();
}
-static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t* core, media_packet_h pkt, uint64_t size)
+static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t *core, media_packet_h packet, uint64_t size)
{
- GstMCBuffer *mc_buffer = NULL;
+ GstMCBuffer *mcbuffer = NULL;
- mc_buffer = (GstMCBuffer *)malloc(sizeof(*mc_buffer));
+ mcbuffer = (GstMCBuffer *)g_malloc0(sizeof(GstMCBuffer));
- if (mc_buffer == NULL) {
+ if (mcbuffer == NULL) {
LOGE("malloc fail");
return NULL;
}
- mc_buffer->buffer = gst_buffer_new();
- mc_buffer->buf_size = 0;
+ mcbuffer->buffer = gst_buffer_new();
+ mcbuffer->buf_size = 0;
- LOGD("creating buffer : %p, %p", mc_buffer, mc_buffer->buffer);
- mc_buffer->core = core;
- mc_buffer->pkt = pkt;
+ LOGD("creating buffer : %p, %p", mcbuffer, mcbuffer->buffer);
+ mcbuffer->core = core;
+ mcbuffer->packet = packet;
- return mc_buffer;
+ return mcbuffer;
}
static gint __gst_handle_core_error(mc_gst_core_t *core, int code)
return trans_err;
}
-static gint __gst_handle_stream_error(mc_gst_core_t *core, GError* error, GstMessage * message)
+static gint __gst_handle_stream_error(mc_gst_core_t *core, GError *error, GstMessage *message)
{
gint trans_err = MEDIACODEC_ERROR_NONE;
return trans_err;
}
-static gint __gst_transform_gsterror(mc_gst_core_t *core, GstMessage * message, GError* error)
+static gint __gst_transform_gsterror(mc_gst_core_t *core, GstMessage *message, GError *error)
{
gchar *src_element_name = NULL;
GstElement *src_element = NULL;
switch (error->code) {
case GST_STREAM_ERROR_DECODE:
+ case GST_STREAM_ERROR_FAILED:
return MEDIACODEC_ERROR_INVALID_STREAM;
break;
return MEDIACODEC_ERROR_NOT_SUPPORTED_FORMAT;
break;
- case GST_STREAM_ERROR_FAILED:
- return MEDIACODEC_ERROR_NOT_SUPPORTED_FORMAT;
- break;
-
default:
+ return MEDIACODEC_ERROR_INTERNAL;
break;
}
- return MEDIACODEC_ERROR_INVALID_STREAM;
-
INTERNAL_ERROR:
return MEDIACODEC_ERROR_INTERNAL;
}
-static int _mc_gst_flush_buffers(mc_gst_core_t *core)
+static gint _mc_gst_flush_buffers(mc_gst_core_t *core)
{
gboolean ret = FALSE;
GstEvent *event = NULL;
_mc_gst_set_flush_input(core);
+ LOGW("Trying send flush_start .... ");
+ event = gst_event_new_flush_start();
+ ret = gst_element_send_event(core->appsrc, event);
+ if (ret != TRUE) {
+ LOGE("failed to send Flush_Start event");
+ return MC_ERROR;
+ }
+
+ LOGW("Trying send flush_stop .... ");
+ event = gst_event_new_flush_stop(TRUE);
+ ret = gst_element_send_event(core->appsrc, event);
+ if (ret != TRUE) {
+ LOGE("failed to send Flush_Stop event");
+ return MC_ERROR;
+ }
+
+ LOGW("Trying send seek .... ");
event = gst_event_new_seek(1.0, GST_FORMAT_BYTES, GST_SEEK_FLAG_FLUSH,
GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, -1);
static void _mc_gst_set_flush_input(mc_gst_core_t *core)
{
- media_packet_h pkt = NULL;
+ media_packet_h packet = NULL;
- LOGI("_mc_gst_set_flush_input is called");
+ MEDIACODEC_FENTER();
+ LOGI("_mc_gst_set_flush_input called : input_queue_len = %d, etb_count = %d", core->available_queue->input->length, core->etb_count);
while (!mc_async_queue_is_empty(core->available_queue->input)) {
- pkt = mc_async_queue_pop_forced(core->available_queue->input);
+ packet = mc_async_queue_pop_forced(core->available_queue->input);
+ LOGD("%p poped(%d)", packet, core->etb_count);
- if (core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) {
- ((mc_empty_buffer_cb) core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER])
- (pkt, core->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]);
- }
+ _mc_gst_handle_input_buffer_used(core, packet);
}
mc_async_queue_flush(core->available_queue->input);
- core->queued_count = 0;
+ LOGI("_mc_gst_set_flush_input ended : input_queue_len = %d, etb_count = %d", core->available_queue->input->length, core->etb_count);
+ MEDIACODEC_FLEAVE();
}
static void _mc_gst_set_flush_output(mc_gst_core_t *core)
{
- media_packet_h pkt = NULL;
+ media_packet_h packet = NULL;
MEDIACODEC_FENTER();
g_mutex_lock(&core->ports[1]->mutex);
- while (!g_queue_is_empty(core->ports[1]->queue)) {
- pkt = g_queue_pop_head(core->ports[1]->queue);
- LOGD("outpkt in output_queue : %p", pkt);
- if (pkt) {
- media_packet_destroy(pkt);
- LOGD("outpkt destroyed");
- pkt = NULL;
+ while (!g_queue_is_empty(core->ports[1]->queue)) {
+ packet = g_queue_pop_head(core->ports[1]->queue);
+ LOGD("%p poped", packet);
+ if (packet) {
+ media_packet_destroy(packet);
+ LOGD("outpacket destroyed");
+ packet = NULL;
}
}
- core->dequeued_count = 0;
g_mutex_unlock(&core->ports[1]->mutex);
MEDIACODEC_FLEAVE();
}
-#ifdef TIZEN_PROFILE_LITE
-int __tbm_get_physical_addr_bo(tbm_bo_handle tbm_bo_handle_fd_t, int *phy_addr, int *phy_size)
-{
- int tbm_bo_handle_fd;
-
- int ret = 0;
-
- tbm_bo_handle_fd = tbm_bo_handle_fd_t.u32;
-
- int open_flags = O_RDWR;
- int ion_fd = -1;
-
- struct ion_mmu_data mmu_data;
- struct ion_custom_data custom_data;
-
- mmu_data.fd_buffer = tbm_bo_handle_fd;
- custom_data.cmd = 4;
- custom_data.arg = (unsigned long)&mmu_data;
-
- ion_fd = open("/dev/ion", open_flags);
- if (ion_fd < 0)
- LOGE("[tbm_get_physical_addr_bo] ion_fd open device failed");
-
- if (ioctl(ion_fd, ION_IOC_CUSTOM, &custom_data) < 0) {
- LOGE("[tbm_get_physical_addr_bo] ION_IOC_CUSTOM failed");
- ret = -1;
- }
-
- if (!ret) {
- *phy_addr = mmu_data.iova_addr;
- *phy_size = mmu_data.iova_size;
- } else {
- *phy_addr = 0;
- *phy_size = 0;
- LOGW("[tbm_get_physical_addr_bo] getting physical address is failed. phy_addr = 0");
- }
-
- if (ion_fd != -1) {
- close(ion_fd);
- ion_fd = -1;
- }
-
- return 0;
-}
-#endif
-
+#if TIZEN_EXYNOS_SPECIFIC
/*
* Get tiled address of position(x,y)
*
* @return
* address of tiled data
*/
-static int __tile_4x2_read(int x_size, int y_size, int x_pos, int y_pos)
+static gint __tile_4x2_read(gint x_size, gint y_size, gint x_pos, gint y_pos)
{
- int pixel_x_m1, pixel_y_m1;
- int roundup_x;
- int linear_addr0, linear_addr1, bank_addr ;
- int x_addr;
- int trans_addr;
+ gint pixel_x_m1, pixel_y_m1;
+ gint roundup_x;
+ gint linear_addr0, linear_addr1, bank_addr ;
+ gint x_addr;
+ gint trans_addr;
pixel_x_m1 = x_size - 1;
pixel_y_m1 = y_size - 1;
* @param buttom
* Crop size of buttom
*/
-static void __csc_tiled_to_linear_crop(unsigned char *yuv420_dest, unsigned char *nv12t_src,
- int yuv420_width, int yuv420_height,
- int left, int top, int right, int buttom)
+static void __csc_tiled_to_linear_crop(gchar *yuv420_dest, gchar *nv12t_src,
+ gint yuv420_width, gint yuv420_height,
+ gint left, int top, gint right, gint buttom)
{
- int i, j;
- int tiled_offset = 0, tiled_offset1 = 0;
- int linear_offset = 0;
- int temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0;
+ gint i, j;
+ gint tiled_offset = 0, tiled_offset1 = 0;
+ gint linear_offset = 0;
+ gint temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0;
temp3 = yuv420_width-right;
temp1 = temp3-left;
}
}
}
+#endif
void _mc_send_eos_signal(mc_gst_core_t *core)
{
}
}
+const gchar * _mc_bit_to_string(int bit)
+{
+ switch (bit) {
+ case 16:
+ return "S16LE";
+ case 32:
+ return "F32LE";
+ default:
+ return "NULL";
+
+ }
+}
+
+int _mc_get_mime(mc_gst_core_t *core)
+{
+ media_format_mimetype_e mime = MEDIA_FORMAT_MAX;
+
+ switch (core->codec_id) {
+ case MEDIACODEC_H264:
+ if (core->encoder)
+ mime = (core->is_hw) ? MEDIA_FORMAT_NV12 : MEDIA_FORMAT_I420;
+ else
+ mime = MEDIA_FORMAT_H264_SP;
+ break;
+ case MEDIACODEC_MPEG4:
+ if (core->encoder)
+ mime = (core->is_hw) ? MEDIA_FORMAT_NV12 : MEDIA_FORMAT_I420;
+ else
+ mime = MEDIA_FORMAT_MPEG4_SP;
+
+ break;
+ case MEDIACODEC_H263:
+ if (core->encoder)
+ mime = (core->is_hw) ? MEDIA_FORMAT_NV12 : MEDIA_FORMAT_I420;
+ else
+ mime = MEDIA_FORMAT_H263P;
+
+ break;
+ case MEDIACODEC_AAC:
+ if (core->encoder)
+ mime = MEDIA_FORMAT_PCM_F32LE; /*FIXME need to change PCM supported by chipset */
+ else
+ mime = MEDIA_FORMAT_AAC;
+
+ break;
+ case MEDIACODEC_AAC_HE:
+ if (core->encoder)
+ mime = MEDIA_FORMAT_PCM_F32LE; /* FIXME need to change PCM supported by chipset */
+ else
+ mime = MEDIA_FORMAT_AAC_HE;
+
+ break;
+ case MEDIACODEC_AAC_HE_PS:
+ break;
+ case MEDIACODEC_MP3:
+ mime = MEDIA_FORMAT_MP3;
+ break;
+ case MEDIACODEC_VORBIS:
+ break;
+ case MEDIACODEC_FLAC:
+ break;
+ case MEDIACODEC_WMAV1:
+ break;
+ case MEDIACODEC_WMAV2:
+ break;
+ case MEDIACODEC_WMAPRO:
+ break;
+ case MEDIACODEC_WMALSL:
+ break;
+ case MEDIACODEC_AMR_NB:
+ mime = MEDIA_FORMAT_AMR_NB;
+ break;
+ 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!!!! 0x%x ", core->codec_id);
+ break;
+ }
+ return mime;
+}
+
+mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *packet_pool)
+{
+ gint ret = MC_ERROR_NONE;
+ gint curr_size;
+ gint max_size, min_size;
+ media_format_mimetype_e mime_format = MEDIA_FORMAT_MAX;
+ media_format_h fmt_handle = NULL;
+ media_packet_pool_h pool = NULL;
+ mc_gst_core_t *core = NULL;
+
+ if (!mc_handle)
+ return MC_PARAM_ERROR;
+
+ core = (mc_gst_core_t *)mc_handle->core;
+
+ ret = media_packet_pool_create(&pool);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ LOGE("media_packet_pool_create failed");
+ return MC_ERROR;
+ }
+
+ if (media_format_create(&fmt_handle) != MEDIA_FORMAT_ERROR_NONE) {
+ LOGE("media format create failed");
+ media_packet_pool_destroy(pool);
+ return MC_ERROR;
+ }
+
+ mime_format = _mc_get_mime(core);
+
+ if (core->video) {
+ 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 {
+ media_format_set_audio_mime(fmt_handle, mime_format);
+ 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);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ media_packet_pool_destroy(pool);
+ LOGE("media_packet_pool_set_media_format failed");
+ return MC_ERROR;
+ }
+
+ /* will use default size temporarily */
+ max_size = core->encoder ? DEFAULT_ENC_POOL_SIZE : DEFAULT_DEC_POOL_SIZE;
+
+ min_size = max_size;
+ ret = media_packet_pool_set_size(pool, min_size, max_size);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ media_packet_pool_destroy(pool);
+ LOGE("media_packet_pool_set_size failed");
+ return MC_ERROR;
+ }
+
+ ret = media_packet_pool_allocate(pool);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ media_packet_pool_destroy(pool);
+ LOGE("media_packet_pool_allocate failed");
+ return MC_OUT_OF_MEMORY;
+ }
+ media_packet_pool_get_size(pool, &min_size, &max_size, &curr_size);
+ LOGD("curr_size is %d min_size is %d and max_size is %d \n", curr_size, min_size, max_size);
+
+ *packet_pool = pool;
+ return MC_ERROR_NONE;
+}