From: Sejun Park Date: Tue, 31 May 2016 07:30:19 +0000 (+0900) Subject: refactoring for adding backend pkg X-Git-Tag: submit/tizen/20160603.021103^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5daa1e23466e64ed32dfa49e749338f0957aef13;p=platform%2Fcore%2Fapi%2Fmediacodec.git refactoring for adding backend pkg Change-Id: Ie3166abb2b1d9b600f02d5179460fc3596f2c77d --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cba697..b80b61c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ FOREACH(flag ${${fw_name}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(CMAKE_C_FLAGS "-I./include -I./include/headers ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall") +SET(CMAKE_C_FLAGS "-I./include -I./include/headers ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") IF("${ARCH}" STREQUAL "arm") diff --git a/include/media_codec_port_gst.h b/include/media_codec_port_gst.h index eae6f9a..52793e2 100755 --- a/include/media_codec_port_gst.h +++ b/include/media_codec_port_gst.h @@ -58,150 +58,134 @@ typedef struct _mc_gst_core_t mc_gst_core_t; typedef struct _GstMCBuffer GstMCBuffer; typedef enum { - BUF_SHARE_METHOD_PADDR = 0, - BUF_SHARE_METHOD_FD, - BUF_SHARE_METHOD_TIZEN_BUFFER, - BUF_SHARE_METHOD_FLUSH_BUFFER + BUF_SHARE_METHOD_PADDR = 0, + BUF_SHARE_METHOD_FD, + BUF_SHARE_METHOD_TIZEN_BUFFER, + BUF_SHARE_METHOD_FLUSH_BUFFER } buf_share_method_t; #ifdef TIZEN_PROFILE_LITE struct ion_mmu_data { - int master_id; - int fd_buffer; - unsigned long iova_addr; - size_t iova_size; + int master_id; + int fd_buffer; + unsigned long iova_addr; + size_t iova_size; }; #endif struct _mc_gst_port_t { - mc_gst_core_t *core; - unsigned int num_buffers; - unsigned int buffer_size; - unsigned int index; - bool is_allocated; - media_packet_h *buffers; - //GSem - GQueue *queue; - GMutex mutex; - GCond buffer_cond; + mc_gst_core_t *core; + unsigned int num_buffers; + unsigned int buffer_size; + unsigned int index; + bool is_allocated; + media_packet_h *buffers; + GQueue *queue; + GMutex mutex; + GCond buffer_cond; }; struct _mc_gst_core_t { - int(**vtable)(); - const char *mime; - //int format; - gchar *format; - GstElement* pipeline; - GstElement* appsrc; - GstElement* capsfilter; - GstElement* parser; - GstElement* fakesink; - GstElement* codec; - MMVideoBuffer *psimgb; - tbm_bufmgr bufmgr; - int drm_fd; - - GMainContext *thread_default; - gulong signal_handoff; - gint bus_whatch_id; - gint probe_id; - - GMutex eos_mutex; - GMutex eos_wait_mutex; - GMutex prepare_lock; - GMutex drain_lock; - GCond eos_cond; - GCond eos_waiting_cond; - - GstState state; - bool output_allocated; - bool encoder; - bool video; - bool is_hw; - bool eos; - bool eos_waiting; - bool codec_config; - bool need_feed; - bool need_codec_data; - bool need_sync_flag; - bool unprepare_flag; - unsigned int prepare_count; - unsigned int num_live_buffers; - unsigned int etb_count; - unsigned int ftb_count; - - - mediacodec_codec_type_e codec_id; - media_format_mimetype_e out_mime; - media_format_h output_fmt; - mc_gst_port_t *ports[2]; - mc_bitstream_t bits; - - mc_aqueue_t *available_queue; - GQueue *output_queue; - - void *codec_info; - unsigned char codec_data[100]; - int codec_data_size; - - void* user_cb[_MEDIACODEC_EVENT_TYPE_NUM]; - void* user_data[_MEDIACODEC_EVENT_TYPE_NUM]; - + int(**vtable)(); + const char *mime; + gchar *format; + GstElement* pipeline; + GstElement* appsrc; + GstElement* capsfilter; + GstElement* parser; + GstElement* fakesink; + GstElement* codec; + tbm_bufmgr bufmgr; + int drm_fd; + + GMainContext *thread_default; + gulong signal_handoff; + gint bus_whatch_id; + gint probe_id; + + GMutex eos_mutex; + GMutex eos_wait_mutex; + GMutex prepare_lock; + GMutex drain_lock; + GCond eos_cond; + GCond eos_waiting_cond; + + bool output_allocated; + bool encoder; + bool video; + bool is_hw; + bool eos; + bool eos_waiting; + bool codec_config; + bool need_feed; + bool need_codec_data; + bool need_sync_flag; + bool unprepare_flag; + unsigned int prepare_count; + unsigned int num_live_buffers; + unsigned int etb_count; + unsigned int ftb_count; + + mediacodec_codec_type_e codec_id; + media_format_mimetype_e out_mime; + media_format_h output_fmt; + mc_gst_port_t *ports[2]; + mc_bitstream_t bits; + + mc_aqueue_t *available_queue; + GQueue *output_queue; + + void *codec_info; + + void* user_cb[_MEDIACODEC_EVENT_TYPE_NUM]; + void* user_data[_MEDIACODEC_EVENT_TYPE_NUM]; }; struct _GstMCBuffer { - GstBuffer *buffer; - int buf_size; - mc_gst_core_t* core; - media_packet_h pkt; - bool has_imgb; + GstBuffer *buffer; + int buf_size; + mc_gst_core_t* core; + media_packet_h pkt; + bool has_imgb; }; enum { fill_inbuf, fill_outbuf, create_caps }; -//int __mc_link_elements(mc_gst_core_t *core); int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff); int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt); int __mc_create_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config); -//int __mc_venc_link(mc_gst_core_t *core); -//int __mc_general_link(mc_gst_core_t *core); - -int __mc_fill_inbuf_with_mm_video_buffer(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff); -int __mc_fill_inbuf_with_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff); -int __mc_fill_inbuf_with_venc_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer); +int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff); +int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer); -int __mc_fill_packet_with_outbuf(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt); -int __mc_fill_venc_packet_with_outbuf(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt); -int __mc_fill_video_packet_with_mm_video_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt); -int __mc_fill_vdec_packet_with_outbuf(mc_gst_core_t *core, void *data, int size, media_packet_h *pkt); +int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt); +int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt); +int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *pkt); -int __mc_vdec_h264_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_venc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_vdec_sw_h264_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_vdec_hw_h264_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_venc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); int __mc_vdec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_vdec_h263_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_vdec_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_h264dec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_sprddec_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_hw_h264enc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_sprddec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_sprdenc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_sprdenc_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_aenc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_adec_aac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_aenc_aac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_adec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_adec_aacv12_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_adec_mp3_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_adec_amrnb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_adec_amrwb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_aenc_amrnb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_adec_vorbis_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_adec_flac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); -int __mc_adec_wma_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_vdec_sw_h263_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_vdec_hw_h263_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_vdec_h263_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_vdec_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_h264dec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_aenc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_adec_aac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_aenc_aac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_adec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_adec_aacv12_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_adec_mp3_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_adec_amrnb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_adec_amrwb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_aenc_amrnb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_adec_vorbis_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_adec_flac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); +int __mc_adec_wma_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config); void _mc_create_codec_map_from_ini(mc_handle_t *mc_handle, mc_codec_spec_t *spec_emul); void _mc_create_decoder_map_from_ini(mc_handle_t *mc_handle); diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index dbd4d24..0d12c63 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -68,6 +68,7 @@ static gint __gst_handle_resource_error(mc_gst_core_t *core, int code); 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 int __mc_fill_video_packet_with_mm_video_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt); /* will remove */ 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 @@ -88,99 +89,96 @@ static void _mc_wait_for_eos(mc_gst_core_t *core); static int _mediacodec_get_mime(mc_gst_core_t *core); /* 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 +int(*vdec_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer, &__mc_vdec_sw_h264_caps}; +int(*venc_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer, &__mc_venc_caps}; + + +int(*vdec_h264_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W H.264 Decoder Vtable */ + &__mc_fill_vdec_packet_with_output_buffer, + &__mc_vdec_sw_h264_caps}; + +int(*vdec_mpeg4_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W MPEG4 Decoder Vtable */ + &__mc_fill_vdec_packet_with_output_buffer, + &__mc_vdec_mpeg4_caps}; + +int(*vdec_h263_sw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* S/W MPEG4 Decoder Vtable */ + &__mc_fill_vdec_packet_with_output_buffer, + &__mc_vdec_sw_h263_caps}; + +int(*vdec_h264_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W H.264 Decoder Vtable */ + &__mc_fill_vdec_packet_with_output_buffer, + &__mc_vdec_hw_h264_caps}; + +int(*vdec_mpeg4_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W MPEG4 Decoder Vtable */ + &__mc_fill_vdec_packet_with_output_buffer, + &__mc_vdec_mpeg4_caps}; + +int(*vdec_h263_hw_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* H/W MPEG4 Decoder Vtable */ + &__mc_fill_vdec_packet_with_output_buffer, + &__mc_vdec_hw_h263_caps}; + +int(*venc_mpeg4_sw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* S/W MPEG4 Encoder Vtable */ + &__mc_fill_venc_packet_with_output_buffer, + &__mc_venc_caps}; + +int(*venc_h263_sw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* S/W MPEG4 Encoder Vtable */ + &__mc_fill_venc_packet_with_output_buffer, + &__mc_venc_caps}; + +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, + &__mc_venc_caps}; + +int(*venc_mpeg4_hw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* H/W MPEG4 Encoder Vtable */ + &__mc_fill_venc_packet_with_output_buffer, + &__mc_venc_caps}; + +int(*venc_h263_hw_vtable[])() = {&__mc_fill_input_buffer_with_venc_packet, /* H/W MPEG4 Encoder Vtable */ + &__mc_fill_venc_packet_with_output_buffer, + &__mc_venc_caps}; + +int(*aenc_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer, &__mc_aenc_caps}; +int(*adec_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer, &__mc_adec_caps}; + +int(*aenc_aac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AAC LC Encoder vtable */ + &__mc_fill_packet_with_output_buffer, + &__mc_aenc_aac_caps}; + +int(*adec_aac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AAC LC Decoder Vtable */ + &__mc_fill_packet_with_output_buffer, + &__mc_adec_aac_caps}; + +int(*adec_aacv12_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AAC HE Decoder Vtable */ + &__mc_fill_packet_with_output_buffer, + &__mc_adec_aacv12_caps}; + +int(*adec_mp3_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* MP3 Decoder Vtable */ + &__mc_fill_packet_with_output_buffer, + &__mc_adec_mp3_caps}; -/* 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}; +int(*adec_amrnb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-NB Decoder Vtable */ + &__mc_fill_packet_with_output_buffer, + &__mc_adec_amrnb_caps}; + +int(*adec_amrwb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-WB Decoder Vtable */ + &__mc_fill_packet_with_output_buffer, + &__mc_adec_amrwb_caps}; + +int(*aenc_amrnb_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AMR-NB Encoder Vtable */ + &__mc_fill_packet_with_output_buffer, + &__mc_aenc_amrnb_caps}; + +int(*adec_vorbis_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* VORBIS Decoder Vtable */ + &__mc_fill_packet_with_output_buffer, + &__mc_adec_vorbis_caps}; + +int(*adec_flac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* FLAC Decoder Vtable */ + &__mc_fill_packet_with_output_buffer, + &__mc_adec_flac_caps}; + +int(*adec_wma_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* WMA Decoder Vtable */ + &__mc_fill_packet_with_output_buffer, + &__mc_adec_wma_caps}; /* @@ -229,7 +227,7 @@ int __mc_fill_inbuf_with_mm_video_buffer(mc_gst_core_t *core, media_packet_h pkt return ret; } -int __mc_fill_inbuf_with_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer) +int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer) { int ret = MC_ERROR_NONE; void *buf_data = NULL; @@ -257,7 +255,7 @@ int __mc_fill_inbuf_with_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBu return ret; } -int __mc_fill_inbuf_with_venc_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer) +int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer) { int ret = MC_ERROR_NONE; void *uv_ptr = NULL; @@ -301,57 +299,67 @@ int __mc_fill_inbuf_with_venc_packet(mc_gst_core_t *core, media_packet_h pkt, Gs return MC_ERROR; } - if (width == stride_width) { - mc_buffer->buf_size += stride_width * stride_height; + if (!core->is_hw) { - 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); + if (width == stride_width) { + mc_buffer->buf_size += stride_width * stride_height; - 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); - 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; - - } - } else { - - 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; - } + buf_size = stride_width * stride_height; - stride = 0; + 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; - 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); + } + } else { - 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; + 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; } - 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; + stride = 0; + + 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(y_ptr + mc_buffer->buf_size, uv_ptr + stride, width>>1); + mc_buffer->buf_size += width>>1; + stride += stride_width; + } + + 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; + } } - } + } else { + MMVideoBuffer *mm_video_buffer = NULL; - 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); + mm_video_buffer = __mc_gst_make_tbm_buffer(core, pkt); + /* mm_video_buffer = core->mc_get_mm_video_buffer(pkt); */ + + gst_buffer_prepend_memory(mc_buffer->buffer, + gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, mm_video_buffer, sizeof(MMVideoBuffer), 0, + sizeof(MMVideoBuffer), mm_video_buffer, free)); + + LOGD("mm_video_buffer is appended, %d, %d", sizeof(MMVideoBuffer), gst_buffer_n_memory(mc_buffer->buffer)); } + gst_buffer_prepend_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)); + return ret; } @@ -365,7 +373,7 @@ int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, media_pac return core->vtable[fill_outbuf](core, data, size, out_pkt); } -int __mc_fill_vdec_packet_with_outbuf(mc_gst_core_t *core, void *data, int size, media_packet_h *pkt) +int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *pkt) { int i; int stride_width; @@ -380,57 +388,69 @@ int __mc_fill_vdec_packet_with_outbuf(mc_gst_core_t *core, void *data, int size, 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 (!core->is_hw) { - if (buf_size > size) - return MC_ERROR; + mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info; - memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s)); + 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; - bo[0] = tbm_bo_alloc(core->bufmgr, buf_size, TBM_BO_WC); - if (!bo[0]) { - LOGE("bo allocation failed"); - return MC_ERROR; - } + if (buf_size > size) + return MC_ERROR; - 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; + memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s)); - 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; + bo[0] = tbm_bo_alloc(core->bufmgr, buf_size, TBM_BO_WC); + if (!bo[0]) { + LOGE("bo allocation failed"); + return MC_ERROR; + } + + 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; + + 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; + } } - } - 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); + if (tsurf) { + media_packet_create_from_tbm_surface(core->output_fmt, tsurf, + (media_packet_finalize_cb)__mc_output_buffer_finalize_cb, core, pkt); + } + + } else { + __mc_fill_video_packet_with_mm_video_buffer(core, data, size, pkt); + /* tsurf = core->get_tbm_surface(data); */ + } +/* if (tsurf) { media_packet_create_from_tbm_surface(core->output_fmt, tsurf, (media_packet_finalize_cb)__mc_output_buffer_finalize_cb, core, pkt); } - +*/ return MC_ERROR_NONE; } @@ -508,7 +528,7 @@ int __mc_fill_video_packet_with_mm_video_buffer(mc_gst_core_t *core, void *data, return MC_ERROR_NONE; } -int __mc_fill_packet_with_outbuf(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt) +int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt) { void *pkt_data = NULL; int ret = MC_ERROR_NONE; @@ -527,7 +547,7 @@ int __mc_fill_packet_with_outbuf(mc_gst_core_t *core, void *data, int size, medi 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) +int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt) { void *pkt_data = NULL; bool codec_config = FALSE; @@ -589,96 +609,43 @@ int __mc_venc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gbool 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", + "format", G_TYPE_STRING, core->format, "width", G_TYPE_INT, enc_info->width, "height", G_TYPE_INT, enc_info->height, "framerate", GST_TYPE_FRACTION, enc_info->fps, 1, NULL); - 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, gboolean 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, NULL); + if (core->is_hw) + g_object_set(GST_OBJECT(core->codec), "target-bitrate", enc_info->bitrate, NULL); + else + g_object_set(GST_OBJECT(core->codec), "bitrate", enc_info->bitrate, 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, gboolean codec_config) +int __mc_vdec_sw_h263_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean 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, 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, gboolean 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, 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, gboolean 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); + "height", G_TYPE_INT, dec_info->height, + "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_sprddec_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config) +int __mc_vdec_hw_h263_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config) { g_return_val_if_fail(core != NULL, MC_PARAM_ERROR); @@ -699,53 +666,40 @@ int __mc_sprddec_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* bu return MC_ERROR_NONE; } -int __mc_sprddec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config) +int __mc_vdec_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean 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, + "systemstream", G_TYPE_BOOLEAN, false, + "parsed", G_TYPE_BOOLEAN, TRUE, "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, gboolean 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); + 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, gboolean codec_config) +int __mc_vdec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean 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); + "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_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config) +int __mc_vdec_sw_h264_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config) { g_return_val_if_fail(core != NULL, MC_PARAM_ERROR); @@ -759,15 +713,19 @@ int __mc_vdec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gbool return MC_ERROR_NONE; } -int __mc_vdec_h264_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config) +int __mc_vdec_hw_h264_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff,gboolean 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, + "parsed", G_TYPE_BOOLEAN, TRUE, "alignment", G_TYPE_STRING, "au", - "stream-format", G_TYPE_STRING, "byte-stream", NULL); + "stream-format", G_TYPE_STRING, "byte-stream", + "width", G_TYPE_INT, dec_info->width, + "framerate", GST_TYPE_FRACTION, 30, 1, + "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; @@ -820,6 +778,7 @@ int __mc_aenc_aac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, g "layout", G_TYPE_STRING, "interleaved", NULL); g_object_set(GST_OBJECT(core->codec), "compliance", -2, NULL); + g_object_set(GST_OBJECT(core->codec), "bitrate", enc_info->bitrate, NULL); LOGD("mime : %s, samplerate :%d, channel : %d", core->mime, enc_info->samplerate, enc_info->channel); @@ -1526,7 +1485,7 @@ gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h fmt) } if (core->encoder) { - mc_encoder_info_t *enc_info = (mc_decoder_info_t *)core->codec_info; + mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info; if (enc_info->bitrate != bitrate) { LOGD("Bitrate changed : %d -> %d",enc_info->bitrate, bitrate); @@ -1551,7 +1510,7 @@ gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h fmt) } if (core->encoder) { - mc_encoder_info_t *enc_info = (mc_decoder_info_t *)core->codec_info; + mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info; if (enc_info->bitrate != bitrate) { LOGD("Bitrate changed : %d -> %d",enc_info->bitrate, bitrate); @@ -3337,7 +3296,7 @@ const gchar * _mc_error_to_string(mc_ret_e err) int _mediacodec_get_mime(mc_gst_core_t *core) { - media_format_mimetype_e mime; + media_format_mimetype_e mime = MEDIA_FORMAT_MAX; switch (core->codec_id) { case MEDIACODEC_H264: @@ -3408,8 +3367,9 @@ mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pkt { int curr_size; int max_size, min_size; - media_format_mimetype_e mime_format; - media_format_h *fmt_handle = NULL; + 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) @@ -3417,7 +3377,7 @@ mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pkt core = (mc_gst_core_t *)mc_handle->core; - int ret = media_packet_pool_create(pkt_pool); + int ret = media_packet_pool_create(&pool); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGE("media_packet_pool_create failed"); @@ -3457,7 +3417,7 @@ mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pkt } } - ret = media_packet_pool_set_media_format(*pkt_pool, fmt_handle); + ret = media_packet_pool_set_media_format(pool, fmt_handle); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGE("media_packet_pool_set_media_format failed"); return MC_ERROR; @@ -3467,19 +3427,20 @@ mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pkt max_size = DEFAULT_POOL_SIZE; min_size = max_size; - ret = media_packet_pool_set_size(*pkt_pool, min_size, max_size); + ret = media_packet_pool_set_size(pool, min_size, max_size); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGE("media_packet_pool_set_size failed"); return MC_ERROR; } - media_packet_pool_get_size(*pkt_pool, &min_size, &max_size, &curr_size); + 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); - ret = media_packet_pool_allocate(*pkt_pool); + ret = media_packet_pool_allocate(pool); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGE("media_packet_pool_allocate failed"); return MC_OUT_OF_MEMORY; } + *pkt_pool = pool; return MC_ERROR_NONE; } diff --git a/test/media_codec_test.c b/test/media_codec_test.c index 852fa3b..46996e8 100755 --- a/test/media_codec_test.c +++ b/test/media_codec_test.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -54,7 +55,6 @@ #define AAC_CODECDATA_SIZE 16 -static int samplebyte = DEFAULT_SAMPLEBYTE; unsigned char buf_adts[ADTS_HEADER_SIZE]; enum { @@ -132,6 +132,8 @@ struct _App { bool is_video[MAX_HANDLE]; bool is_encoder[MAX_HANDLE]; bool hardware; + bool enable_dump; + int frame; type_e type; /* video */ mediacodec_h mc_handle[MAX_HANDLE]; @@ -162,14 +164,8 @@ struct _App { App s_app; -media_format_h aenc_fmt = NULL; -media_format_h adec_fmt = NULL; -media_format_h vdec_fmt = NULL; -media_format_h venc_fmt = NULL; - -#if DUMP_OUTBUF -FILE *fp_out = NULL; -#endif +media_format_h fmt = NULL; +media_packet_pool_h pkt_pool = NULL; /* Internal Functions */ static int _create_app(void *data); @@ -177,11 +173,11 @@ static int _terminate_app(void *data); static void displaymenu(void); static void display_sub_basic(); +static void _mediacodec_unprepare(App *app); /* For debugging */ static void mc_hex_dump(char *desc, void *addr, int len); -#if DUMP_OUTBUF static void decoder_output_dump(App *app, media_packet_h pkt); -#endif +static void output_dump(App *app, media_packet_h pkt); /* */ void (*extractor)(App *app, unsigned char** data, int *size, bool *have_frame); @@ -335,12 +331,10 @@ void h263_extractor(App * app, unsigned char **data, int *size, bool * have_fram unsigned char *pH263 = app->data + app->offset; *data = pH263; int max = app->length - app->offset; - *have_frame = TRUE; while (1) { if (len >= max) { read_size = (len - 1); - *have_frame = FALSE; goto DONE; } val = pH263[len++]; @@ -371,6 +365,7 @@ void h263_extractor(App * app, unsigned char **data, int *size, bool * have_fram DONE: *size = read_size; app->offset += read_size; + *have_frame = TRUE; } void mpeg4_extractor(App * app, unsigned char **data, int *size, bool * have_frame) @@ -385,7 +380,7 @@ void mpeg4_extractor(App * app, unsigned char **data, int *size, bool * have_fra while (1) { if (len >= max) { - *have_frame = FALSE; + result = (len - 1); goto DONE; } @@ -435,6 +430,7 @@ void mpeg4_extractor(App * app, unsigned char **data, int *size, bool * have_fra * - AMR-NB : mime type ("audio/AMR") / 8Khz / 1 ch / 16 bits * - AMR-WB : mime type ("audio/AMR-WB") / 16Khz / 1 ch / 16 bits **/ +int write_amr_header = 1; /* write magic number for AMR Header at one time */ static const char AMR_header[] = "#!AMR\n"; static const char AMRWB_header[] = "#!AMR-WB\n"; #define AMR_NB_MIME_HDR_SIZE 6 @@ -529,12 +525,12 @@ void aacenc_extractor(App *app, unsigned char **data, int *size, bool *have_fram int read_size; int offset = app->length - app->offset; - read_size = ((samplebyte*app->channel)*(app->bit/8)); - + read_size = ((DEFAULT_SAMPLEBYTE * app->channel)*(app->bit/8) * 2); *have_frame = TRUE; + *data = app->data + app->offset; - if (offset >= read_size) + if (read_size >= offset) *size = offset; else *size = read_size; @@ -553,8 +549,9 @@ void amrenc_extractor(App *app, unsigned char **data, int *size, bool *have_fram read_size = AMRWB_PCM_INPUT_SIZE; *have_frame = TRUE; + *data = app->data + app->offset; - if (offset >= read_size) + if (read_size >= offset) *size = offset; else *size = read_size; @@ -818,7 +815,7 @@ static void _mediacodec_empty_buffer_cb(media_packet_h pkt, void *user_data) return; } #endif -int _mediacodec_set_codec(int codecid, int flag, bool *hardware) +int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) { bool encoder; media_format_mimetype_e mime = 0; @@ -890,12 +887,24 @@ int _mediacodec_set_codec(int codecid, int flag, bool *hardware) case MEDIACODEC_WMALSL: break; case MEDIACODEC_AMR_NB: - extractor = amrdec_extractor; - mime = MEDIA_FORMAT_AMR_NB; + if (encoder) { + extractor = amrenc_extractor; + mime = MEDIA_FORMAT_PCM; + app->is_amr_nb = TRUE; + } else { + extractor = amrdec_extractor; + mime = MEDIA_FORMAT_AMR_NB; + } break; case MEDIACODEC_AMR_WB: - extractor = amrdec_extractor; - mime = MEDIA_FORMAT_AMR_WB; + if (encoder) { + extractor = amrenc_extractor; + mime = MEDIA_FORMAT_PCM; + app->is_amr_nb = FALSE; + } else { + extractor = amrdec_extractor; + mime = MEDIA_FORMAT_AMR_WB; + } break; default: LOGE("NOT SUPPORTED!!!!"); @@ -904,6 +913,80 @@ int _mediacodec_set_codec(int codecid, int flag, bool *hardware) return mime; } +static void _mediacodec_process_input(App *app) +{ + int i; + bool have_frame = FALSE; + int ret; + static guint64 pts = 0L; + void *buf_data_ptr = NULL; + media_packet_h pkt = NULL; + unsigned char *tmp; + int read; + int offset; + int stride_width, stride_height; + + for (i = 0; i < app->frame; i++) { + g_print("----------read data------------\n"); + + extractor(app, &tmp, &read, &have_frame); + + if (have_frame) { + if (media_packet_create_alloc(fmt, NULL, NULL, &pkt) != MEDIA_PACKET_ERROR_NONE) { + fprintf(stderr, "media_packet_create_alloc failed\n"); + return; + } + + if (media_packet_set_pts(pkt, (uint64_t)(pts)) != MEDIA_PACKET_ERROR_NONE) { + fprintf(stderr, "media_packet_set_pts failed\n"); + return; + } + + if (app->type != VIDEO_ENC) { + media_packet_get_buffer_data_ptr(pkt, &buf_data_ptr); + media_packet_set_buffer_size(pkt, (uint64_t)read); + + memcpy(buf_data_ptr, tmp, read); + g_print("tmp:%p, read:%d\n", tmp, read); + } else { + /* Y */ + media_packet_get_video_plane_data_ptr(pkt, 0, &buf_data_ptr); + media_packet_get_video_stride_width(pkt, 0, &stride_width); + media_packet_get_video_stride_height(pkt, 0, &stride_height); + + offset = stride_width*stride_height; + + memcpy(buf_data_ptr, tmp, offset); + + /* UV or U*/ + media_packet_get_video_plane_data_ptr(pkt, 1, &buf_data_ptr); + media_packet_get_video_stride_width(pkt, 1, &stride_width); + media_packet_get_video_stride_height(pkt, 1, &stride_height); + memcpy(buf_data_ptr, tmp + offset, stride_width*stride_height); + + if (app->hardware == FALSE) { + /* V */ + media_packet_get_video_plane_data_ptr(pkt, 2, &buf_data_ptr); + media_packet_get_video_stride_width(pkt, 2, &stride_width); + media_packet_get_video_stride_height(pkt, 2, &stride_height); + + offset += stride_width * stride_height; + + + memcpy(buf_data_ptr, tmp + offset, stride_width*stride_height); + } + } + mc_hex_dump("inbuf", tmp, 48); + + ret = mediacodec_process_input(app->mc_handle[0], pkt, -1); + if (ret != MEDIACODEC_ERROR_NONE) + return; + + pts += ES_DEFAULT_VIDEO_PTS_OFFSET; + } + } +} + static gboolean read_data(App *app) { guint len = 0; @@ -917,14 +1000,20 @@ static gboolean read_data(App *app) int offset; int stride_width, stride_height; + if (app->offset == 0) { + app->frame_count = 0; + app->start = clock(); + } + g_print("----------read data------------\n"); extractor(app, &tmp, &read, &have_frame); - if (app->offset >= app->length - 1) { + if (app->offset >= app->length - 4) { /* EOS */ g_print("EOS\n"); app->finish = clock(); - g_main_loop_quit(app->loop); + g_print("Average FPS = %3.3f\n", ((double)app->frame_count*1000000/(app->finish - app->start))); + g_print("---------------------------\n"); return FALSE; } g_print("length : %d, offset : %d\n", (int)app->length, (int)app->offset); @@ -935,11 +1024,18 @@ static gboolean read_data(App *app) g_print("%p, %d, have_frame :%d, read: %d\n", tmp, (int)read, have_frame, read); if (have_frame) { - if (media_packet_create_alloc(vdec_fmt, NULL, NULL, &pkt) != MEDIA_PACKET_ERROR_NONE) { +#ifdef USE_POOL + if (media_packet_pool_acquire_packet(pkt_pool, &pkt, -1) != MEDIA_PACKET_ERROR_NONE) { + fprintf(stderr, "media_packet_pool_aquire_packet failed\n"); + //return TRUE; + return FALSE; + } +#else + if (media_packet_create_alloc(fmt, NULL, NULL, &pkt) != MEDIA_PACKET_ERROR_NONE) { fprintf(stderr, "media_packet_create_alloc failed\n"); return FALSE; } - +#endif if (media_packet_set_pts(pkt, (uint64_t)(pts)) != MEDIA_PACKET_ERROR_NONE) { fprintf(stderr, "media_packet_set_pts failed\n"); return FALSE; @@ -1011,7 +1107,12 @@ static void stop_feed(App *app) static gboolean _mediacodec_inbuf_used_cb(media_packet_h pkt, void *user_data) { g_print("_mediacodec_inbuf_used_cb!!!\n"); +#ifdef USE_POOL + media_packet_pool_release_packet(pkt_pool, pkt); +#else media_packet_destroy(pkt); +#endif + return TRUE; } @@ -1031,19 +1132,12 @@ static bool _mediacodec_outbuf_available_cb(media_packet_h pkt, void *user_data) if (ret != MEDIACODEC_ERROR_NONE) g_print("get_output failed\n"); -#if DUMP_OUTBUF - void *data; - int buf_size; - int stride_width, stride_height; - - decoder_output_dump(app, out_pkt); - media_packet_get_buffer_data_ptr(out_pkt, &data); - media_packet_get_buffer_size(out_pkt, &buf_size); - g_print("output data : %p, size %d\n", data, (int)buf_size); - - fwrite(data, 1, buf_size, fp_out); - -#endif + if (app->enable_dump) { + if (app->type == VIDEO_DEC) + decoder_output_dump(app, out_pkt); + else + output_dump(app, out_pkt); + } app->frame_count++; @@ -1081,13 +1175,10 @@ static bool _mediacodec_eos_cb(void *user_data) return TRUE; } -static void _mediacodec_prepare(App *app) +static void _mediacodec_prepare(App *app, bool frame_all) { int ret; -#if DUMP_OUTBUF - fp_out = fopen("/tmp/codec_dump.out", "wb"); -#endif /* create instance */ ret = mediacodec_create(&app->mc_handle[0]); if (ret != MEDIACODEC_ERROR_NONE) { @@ -1102,39 +1193,38 @@ static void _mediacodec_prepare(App *app) return; } - - app->mime = _mediacodec_set_codec(app->codecid, app->flag, &app->hardware); + app->mime = _mediacodec_set_codec(app, app->codecid, app->flag, &app->hardware); /* set codec info */ - ret = media_format_create(&vdec_fmt); + ret = media_format_create(&fmt); switch (app->type) { case VIDEO_DEC: ret = mediacodec_set_vdec_info(app->mc_handle[0], app->width, app->height); - media_format_set_video_mime(vdec_fmt, app->mime); - media_format_set_video_width(vdec_fmt, app->width); - media_format_set_video_height(vdec_fmt, app->height); + media_format_set_video_mime(fmt, app->mime); + media_format_set_video_width(fmt, app->width); + media_format_set_video_height(fmt, app->height); break; case VIDEO_ENC: ret = mediacodec_set_venc_info(app->mc_handle[0], app->width, app->height, app->fps, app->target_bits); - media_format_set_video_mime(vdec_fmt, app->mime); - media_format_set_video_width(vdec_fmt, app->width); - media_format_set_video_height(vdec_fmt, app->height); - media_format_set_video_avg_bps(vdec_fmt, app->target_bits); + media_format_set_video_mime(fmt, app->mime); + media_format_set_video_width(fmt, app->width); + media_format_set_video_height(fmt, app->height); + media_format_set_video_avg_bps(fmt, app->target_bits); break; case AUDIO_DEC: ret = mediacodec_set_adec_info(app->mc_handle[0], app->samplerate, app->channel, app->bit); - media_format_set_audio_mime(vdec_fmt, app->mime); - media_format_set_audio_channel(vdec_fmt, app->channel); - media_format_set_audio_samplerate(vdec_fmt, app->samplerate); - media_format_set_audio_bit(vdec_fmt, app->bit); + media_format_set_audio_mime(fmt, app->mime); + media_format_set_audio_channel(fmt, app->channel); + media_format_set_audio_samplerate(fmt, app->samplerate); + media_format_set_audio_bit(fmt, app->bit); break; case AUDIO_ENC: ret = mediacodec_set_aenc_info(app->mc_handle[0], app->samplerate, app->channel, app->bit, app->bitrate); - media_format_set_audio_mime(vdec_fmt, app->mime); - media_format_set_audio_channel(vdec_fmt, app->channel); - media_format_set_audio_samplerate(vdec_fmt, app->samplerate); - media_format_set_audio_bit(vdec_fmt, app->bit); + media_format_set_audio_mime(fmt, app->mime); + media_format_set_audio_channel(fmt, app->channel); + media_format_set_audio_samplerate(fmt, app->samplerate); + media_format_set_audio_bit(fmt, app->bit); break; default: g_print("invaild type\n"); @@ -1149,7 +1239,8 @@ static void _mediacodec_prepare(App *app) /* set callback */ mediacodec_set_input_buffer_used_cb(app->mc_handle[0], (mediacodec_input_buffer_used_cb)_mediacodec_inbuf_used_cb, NULL); mediacodec_set_output_buffer_available_cb(app->mc_handle[0], (mediacodec_output_buffer_available_cb) _mediacodec_outbuf_available_cb, app); - mediacodec_set_buffer_status_cb(app->mc_handle[0], (mediacodec_buffer_status_cb) _mediacodec_buffer_status_cb, app); + if (frame_all) + mediacodec_set_buffer_status_cb(app->mc_handle[0], (mediacodec_buffer_status_cb) _mediacodec_buffer_status_cb, app); mediacodec_set_eos_cb(app->mc_handle[0], (mediacodec_eos_cb)_mediacodec_eos_cb, NULL); mediacodec_set_error_cb(app->mc_handle[0], (mediacodec_error_cb)_mediacodec_error_cb, NULL); @@ -1160,17 +1251,44 @@ static void _mediacodec_prepare(App *app) return; } - app->frame_count = 0; - app->start = clock(); - g_main_loop_run(app->loop); - - g_print("Average FPS = %3.3f\n", ((double)app->frame_count*1000000/(app->finish - app->start))); - g_print("---------------------------\n"); +/* get packet pool instance */ + ret = mediacodec_get_packet_pool(app->mc_handle[0], &pkt_pool); + if (ret != MEDIA_PACKET_ERROR_NONE) { + g_print("mediacodec_get_packet_pool failed\n"); + return; + } return; } +static void _mediacodec_unprepare(App *app) +{ + mediacodec_unprepare(app->mc_handle[0]); +} + +static void _mediacodec_destroy(App *app) +{ +#ifdef USE_POOL + if (media_packet_pool_deallocate(pkt_pool) != MEDIA_PACKET_ERROR_NONE) { + + fprintf(stderr, "media_packet_pool_deallocatet failed\n"); + g_print("PKT POOL deallocation failed \n"); + return; + } + g_print("PKT POOL deallocated! \n"); + + if (media_packet_pool_destroy(pkt_pool) != MEDIA_PACKET_ERROR_NONE) { + + fprintf(stderr, " media_packet_pool_destroy failed\n"); + g_print("PKT POOL destroy failed \n"); + return; + } + g_print("PKT POOL destroyed! \n"); +#endif + mediacodec_destroy(app->mc_handle[0]); +} + static void input_filepath(char *filename, App *app) { GError *error = NULL; @@ -1191,12 +1309,10 @@ static void input_filepath(char *filename, App *app) return; } -void quit_program() +void quit_program(App *app) { -#if DUMP_OUTBUF - if (fp_out) - fclose(fp_out); -#endif + media_format_unref(fmt); + g_main_loop_quit(app->loop); elm_exit(); } @@ -1216,12 +1332,14 @@ void _interpret_main_menu(char *cmd, App *app) else if (strncmp(cmd, "o", 1) == 0) g_menu_state = CURRENT_STATUS_GET_OUTPUT; else if (strncmp(cmd, "q", 1) == 0) - quit_program(); + quit_program(app); else g_print("unknown menu \n"); } else if (len == 2) { if (strncmp(cmd, "pr", 2) == 0) - _mediacodec_prepare(app); + _mediacodec_prepare(app, 0); + else if (strncmp(cmd, "pa", 2) == 0) + _mediacodec_prepare(app, 1); else if (strncmp(cmd, "sc", 2) == 0) g_menu_state = CURRENT_STATUS_SET_CODEC; else if (strncmp(cmd, "vd", 2) == 0) @@ -1234,7 +1352,19 @@ void _interpret_main_menu(char *cmd, App *app) g_menu_state = CURRENT_STATUS_SET_AENC_INFO; else if (strncmp(cmd, "pi", 2) == 0) g_menu_state = CURRENT_STATUS_PROCESS_INPUT; - else + else if (strncmp(cmd, "un", 2) == 0) + _mediacodec_unprepare(app); + else if (strncmp(cmd, "dt", 2) == 0) + _mediacodec_destroy(app); + else if (strncmp(cmd, "dp", 2) == 0) { + if(!app->enable_dump) { + app->enable_dump = TRUE; + g_print("dump enabled\n"); + } else { + app->enable_dump = FALSE; + g_print("dump disabled\n"); + } + } else display_sub_basic(); } else { g_print("unknown menu \n"); @@ -1448,6 +1578,8 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_PROCESS_INPUT: { + app->frame = atoi(cmd); + _mediacodec_process_input(app); reset_menu_state(); } break; @@ -1475,14 +1607,15 @@ static void display_sub_basic() g_print("ve. Set venc info \n"); g_print("ad. Set adec info \t"); g_print("ae. Set aenc info \n"); - g_print("pr. Prepare \t\t"); - g_print("pi. Process input \n"); + g_print("pr. Prepare \t"); + g_print("pa. Prepare and process all\t\t"); + g_print("pi. process input with num\n"); g_print("o. Get output \t\t"); g_print("rb. Reset output buffer \n"); - g_print("pa. Process all frames \n"); g_print("un. Unprepare \t\t"); g_print("dt. Destroy \t\t"); - g_print("q. quite test suite \t"); + g_print("q. quite test suite \n"); + g_print("dp. enable dump \n"); g_print("\n"); g_print("=========================================================================================\n"); } @@ -1512,10 +1645,13 @@ int main(int argc, char *argv[]) g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, app); + displaymenu(); app->loop = g_main_loop_new(NULL, TRUE); app->timer = g_timer_new(); + //app->frame_count = 0; + g_main_loop_run(app->loop); + - displaymenu(); ops.data = app; @@ -1558,7 +1694,6 @@ void mc_hex_dump(char *desc, void *addr, int len) printf(" %s\n", buff); } -#if DUMP_OUTBUF static void decoder_output_dump(App *app, media_packet_h pkt) { void *temp; @@ -1608,4 +1743,73 @@ static void decoder_output_dump(App *app, media_packet_h pkt) fclose(fp); } -#endif + +/** + * Add ADTS header at the beginning of each and every AAC packet. + * This is needed as MediaCodec encoder generates a packet of raw AAC data. + * Note the packetLen must count in the ADTS header itself. + **/ +void add_adts_header_for_aacenc(App *app, char *buffer, int packetLen) { + int profile = 2; //AAC LC (0x01) + int freqIdx = 3; //48KHz (0x03) + int chanCfg = 2; //CPE (0x02) + + if (app->samplerate == 96000) freqIdx = 0; + else if (app->samplerate == 88200) freqIdx = 1; + else if (app->samplerate == 64000) freqIdx = 2; + else if (app->samplerate == 48000) freqIdx = 3; + else if (app->samplerate == 44100) freqIdx = 4; + else if (app->samplerate == 32000) freqIdx = 5; + else if (app->samplerate == 24000) freqIdx = 6; + else if (app->samplerate == 22050) freqIdx = 7; + else if (app->samplerate == 16000) freqIdx = 8; + else if (app->samplerate == 12000) freqIdx = 9; + else if (app->samplerate == 11025) freqIdx = 10; + else if (app->samplerate == 8000) freqIdx = 11; + + if ((app->channel == 1) || (app->channel == 2)) + chanCfg = app->channel; + + // fill in ADTS data + buffer[0] = (char)0xFF; + buffer[1] = (char)0xF1; + buffer[2] = (char)(((profile-1)<<6) + (freqIdx<<2) +(chanCfg>>2)); + buffer[3] = (char)(((chanCfg&3)<<6) + (packetLen>>11)); + buffer[4] = (char)((packetLen&0x7FF) >> 3); + buffer[5] = (char)(((packetLen&7)<<5) + 0x1F); + buffer[6] = (char)0xFC; +} + +static void output_dump(App *app, media_packet_h pkt) +{ + void *temp; + uint64_t buf_size; + char filename[100] = {0}; + FILE *fp = NULL; + int ret = 0; + char adts[100] = {0, }; + + sprintf(filename, "/tmp/dec_output_dump_%d.out", app->type); + fp = fopen(filename, "ab"); + + media_packet_get_buffer_data_ptr(pkt, &temp); + media_packet_get_buffer_size(pkt, &buf_size); + g_print("output data : %p, size %d\n", temp, (int)buf_size); + + if (buf_size > 0 && app->codecid == MEDIACODEC_AAC_LC) { + add_adts_header_for_aacenc(app, adts, (buf_size + ADTS_HEADER_SIZE)); + fwrite(&adts, 1, ADTS_HEADER_SIZE, fp); + g_print("adts appended\n"); + } else if (buf_size > 0 && app->codecid == MEDIACODEC_AMR_NB && write_amr_header == 1) { + /* This is used only AMR encoder case for adding AMR masic header in only first frame */ + g_print("%s - AMR_header write in first frame\n",__func__); + fwrite(&AMR_header[0], 1, sizeof(AMR_header) - 1, fp); /* AMR-NB magic number */ + write_amr_header = 0; + } + + fwrite(temp, (int)buf_size, 1, fp); + + g_print("codec dec output dumped!!%d\n", ret); + fclose(fp); + +}