From 69dd0f486e53d400c726bf18b94d23026ccfeb87 Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Fri, 9 Jun 2017 12:38:10 +0900 Subject: [PATCH] removed unused code Change-Id: Ieca797efb30634bcfd742caba63434074a70406d --- include/media_codec.h | 0 include/media_codec_bitstream.h | 0 include/media_codec_ini.h | 0 include/media_codec_internal.h | 0 include/media_codec_port.h | 0 include/media_codec_port_gst.h | 0 include/media_codec_private.h | 0 include/media_codec_queue.h | 0 include/media_codec_spec_emul.h | 0 include/media_codec_util.h | 10 +- src/media_codec.c | 0 src/media_codec_bitstream.c | 0 src/media_codec_ini.c | 0 src/media_codec_internal.c | 0 src/media_codec_port.c | 0 src/media_codec_port_gst.c | 0 src/media_codec_queue.c | 0 src/media_codec_util.c | 0 test/media_codec_test.c | 403 ++++++++++++++++------------------------ 19 files changed, 166 insertions(+), 247 deletions(-) mode change 100755 => 100644 include/media_codec.h mode change 100755 => 100644 include/media_codec_bitstream.h mode change 100755 => 100644 include/media_codec_ini.h mode change 100755 => 100644 include/media_codec_internal.h mode change 100755 => 100644 include/media_codec_port.h mode change 100755 => 100644 include/media_codec_port_gst.h mode change 100755 => 100644 include/media_codec_private.h mode change 100755 => 100644 include/media_codec_queue.h mode change 100755 => 100644 include/media_codec_spec_emul.h mode change 100755 => 100644 include/media_codec_util.h mode change 100755 => 100644 src/media_codec.c mode change 100755 => 100644 src/media_codec_bitstream.c mode change 100755 => 100644 src/media_codec_ini.c mode change 100755 => 100644 src/media_codec_internal.c mode change 100755 => 100644 src/media_codec_port.c mode change 100755 => 100644 src/media_codec_port_gst.c mode change 100755 => 100644 src/media_codec_queue.c mode change 100755 => 100644 src/media_codec_util.c mode change 100755 => 100644 test/media_codec_test.c diff --git a/include/media_codec.h b/include/media_codec.h old mode 100755 new mode 100644 diff --git a/include/media_codec_bitstream.h b/include/media_codec_bitstream.h old mode 100755 new mode 100644 diff --git a/include/media_codec_ini.h b/include/media_codec_ini.h old mode 100755 new mode 100644 diff --git a/include/media_codec_internal.h b/include/media_codec_internal.h old mode 100755 new mode 100644 diff --git a/include/media_codec_port.h b/include/media_codec_port.h old mode 100755 new mode 100644 diff --git a/include/media_codec_port_gst.h b/include/media_codec_port_gst.h old mode 100755 new mode 100644 diff --git a/include/media_codec_private.h b/include/media_codec_private.h old mode 100755 new mode 100644 diff --git a/include/media_codec_queue.h b/include/media_codec_queue.h old mode 100755 new mode 100644 diff --git a/include/media_codec_spec_emul.h b/include/media_codec_spec_emul.h old mode 100755 new mode 100644 diff --git a/include/media_codec_util.h b/include/media_codec_util.h old mode 100755 new mode 100644 index 988a54a..5dde410 --- a/include/media_codec_util.h +++ b/include/media_codec_util.h @@ -55,10 +55,12 @@ void mc_sem_up(mc_sem_t *sem); void mc_hex_dump(char *desc, void *addr, int len); -#define MC_FREEIF(x) \ - if (x) \ - g_free(x); \ - x = NULL; +#define MC_FREEIF(x) \ + do { \ + if (x) \ + g_free(x); \ + x = NULL; \ + } while(0) #ifdef __cplusplus } diff --git a/src/media_codec.c b/src/media_codec.c old mode 100755 new mode 100644 diff --git a/src/media_codec_bitstream.c b/src/media_codec_bitstream.c old mode 100755 new mode 100644 diff --git a/src/media_codec_ini.c b/src/media_codec_ini.c old mode 100755 new mode 100644 diff --git a/src/media_codec_internal.c b/src/media_codec_internal.c old mode 100755 new mode 100644 diff --git a/src/media_codec_port.c b/src/media_codec_port.c old mode 100755 new mode 100644 diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c old mode 100755 new mode 100644 diff --git a/src/media_codec_queue.c b/src/media_codec_queue.c old mode 100755 new mode 100644 diff --git a/src/media_codec_util.c b/src/media_codec_util.c old mode 100755 new mode 100644 diff --git a/test/media_codec_test.c b/test/media_codec_test.c old mode 100755 new mode 100644 index 67f0f68..9c35563 --- a/test/media_codec_test.c +++ b/test/media_codec_test.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,7 @@ #include #include #include +#include #include #include @@ -58,7 +60,7 @@ #define AAC_CODECDATA_SIZE 16 #define USE_POOL 1 -unsigned char buf_adts[ADTS_HEADER_SIZE]; +guint8 buf_adts[ADTS_HEADER_SIZE]; enum { MC_EXIST_SPS = 1 << 0, @@ -125,18 +127,18 @@ struct _App { gint obj; GTimer *timer; - long start; - long finish; - long process_time; - int frame_count; - - int codecid; - int flag; - bool is_video; - bool is_encoder; - bool hardware; - bool enable_dump; - int frame; + glong start; + glong finish; + glong process_time; + gint frame_count; + + gint codecid; + gint flag; + gboolean is_video; + gboolean is_encoder; + gboolean hardware; + gboolean enable_dump; + gint frame; type_e type; camera_h camera_handle; /* video */ @@ -152,7 +154,7 @@ struct _App { guint channel; guint bit; guint bitrate; - bool is_amr_nb; + gboolean is_amr_nb; /* Render */ @@ -172,24 +174,24 @@ media_format_h fmt = NULL; media_packet_pool_h pkt_pool = NULL; /* Internal Functions */ -static int _create_app(void *data); -static int _terminate_app(void *data); +static gint _create_app(void *data); +static gint _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); +static void mc_hex_dump(char *desc, void *addr, gint len); static void decoder_output_dump(App *app, media_packet_h pkt); static void output_dump(App *app, media_packet_h pkt); /* */ const char* codec_type_to_string(mediacodec_codec_type_e media_codec_id); -void (*extractor)(App *app, unsigned char** data, int *size, bool *have_frame); +void (*extractor)(App *app, guint8** data, gint *size, gboolean *have_frame, gboolean *codec_data); -int g_menu_state = CURRENT_STATUS_MAINMENU; +gint g_menu_state = CURRENT_STATUS_MAINMENU; -static int _create_app(void *data) +static gint _create_app(void *data) { g_print("My app is going alive!\n"); App *app = (App*)data; @@ -198,7 +200,7 @@ static int _create_app(void *data) return 0; } -static int _terminate_app(void *data) +static gint _terminate_app(void *data) { g_print("My app is going gone!\n"); App *app = (App*)data; @@ -231,18 +233,18 @@ static const guint mp3types_freqs[3][3] = { {44100, 48000, 32000}, {11025, 12000, 8000} }; -void h264_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void h264_extractor(App *app, guint8 **data, gint *size, gboolean *have_frame, gboolean *codec_data) { - unsigned char val, zero_count; - unsigned char *pNal = app->data + app->offset; - int max = app->length - app->offset; - int index = 0; - int nal_unit_type = 0; - bool init; - bool slice; - bool idr; - static int state; - int read; + guint8 val, zero_count; + guint8 *pNal = app->data + app->offset; + gint max = app->length - app->offset; + gint index = 0; + gint nal_unit_type = 0; + gboolean init; + gboolean slice; + gboolean idr; + static gint state; + gint read; zero_count = 0; @@ -328,12 +330,12 @@ DONE: app->offset += read; } -void h263_extractor(App * app, unsigned char **data, int *size, bool * have_frame) +void h263_extractor(App * app, guint8 **data, gint *size, gboolean * have_frame, gboolean *codec_data) { int len = 0; int read_size = 1, state = 1, bStart = 0; - unsigned char val; - unsigned char *pH263 = app->data + app->offset; + guint8 val; + guint8 *pH263 = app->data + app->offset; *data = pH263; int max = app->length - app->offset; @@ -373,13 +375,13 @@ void h263_extractor(App * app, unsigned char **data, int *size, bool * have_fram *have_frame = TRUE; } -void mpeg4_extractor(App * app, unsigned char **data, int *size, bool * have_frame) +void mpeg4_extractor(App * app, guint8 **data, gint *size, gboolean * have_frame, gboolean *codec_data) { int len = 0; int result = 0; int state = 1, bType = 0; - unsigned char val; - unsigned char *pMpeg4 = app->data + app->offset; + guint8 val; + guint8 *pMpeg4 = app->data + app->offset; *data = pMpeg4; int max = app->length - app->offset; @@ -435,20 +437,20 @@ 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"; +gint write_amr_header = 1; /* write magic number for AMR Header at one time */ +static const gchar AMR_header[] = "#!AMR\n"; +static const gchar AMRWB_header[] = "#!AMR-WB\n"; #define AMR_NB_MIME_HDR_SIZE 6 #define AMR_WB_MIME_HDR_SIZE 9 -static const int block_size_nb[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; -static const int block_size_wb[16] = { 17, 23, 32, 36, 40, 46, 50, 58, 60, 5, -1, -1, -1, -1, 0, 0 }; +static const gint block_size_nb[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; +static const gint block_size_wb[16] = { 17, 23, 32, 36, 40, 46, 50, 58, 60, 5, -1, -1, -1, -1, 0, 0 }; -int *blocksize_tbl; -void amrdec_extractor(App * app, unsigned char **data, int *size, bool * have_frame) +gint *blocksize_tbl; +void amrdec_extractor(App * app, guint8 **data, gint *size, gboolean * have_frame, gboolean *codec_data) { - int readsize = 0, mode_temp; - unsigned int fsize, mode; - unsigned char *pAmr = app->data + app->offset; + gint readsize = 0, mode_temp; + gint fsize, mode; + guint8 *pAmr = app->data + app->offset; /* change the below one to frame count */ if (app->offset == 0) { if (!memcmp(pAmr, AMR_header, AMR_NB_MIME_HDR_SIZE)) { @@ -484,10 +486,10 @@ void amrdec_extractor(App * app, unsigned char **data, int *size, bool * have_fr *have_frame = TRUE; } -void nv12_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void nv12_extractor(App *app, guint8 **data, gint *size, gboolean *have_frame, gboolean *codec_data) { - int yuv_size; - int offset = app->length - app->offset; + gint yuv_size; + gint offset = app->length - app->offset; yuv_size = app->width * app->height * 3 / 2; @@ -497,16 +499,18 @@ void nv12_extractor(App *app, unsigned char **data, int *size, bool *have_frame) *have_frame = TRUE; *data = app->data + app->offset; - if (offset >= yuv_size) + if (yuv_size >= offset) *size = offset; else *size = yuv_size; + + app->offset += *size; } -void yuv_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void yuv_extractor(App *app, guint8 **data, int *size, gboolean *have_frame, gboolean *codec_data) { - int yuv_size; - int offset = app->length - app->offset; + gint yuv_size; + gint offset = app->length - app->offset; yuv_size = app->width * app->height * 3 / 2; @@ -522,13 +526,12 @@ void yuv_extractor(App *app, unsigned char **data, int *size, bool *have_frame) *size = yuv_size; app->offset += *size; - } -void aacenc_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void aacenc_extractor(App *app, guint8 **data, int *size, gboolean *have_frame, gboolean *codec_data) { - int read_size; - int offset = app->length - app->offset; + gint read_size; + gint offset = app->length - app->offset; read_size = ((DEFAULT_SAMPLEBYTE * app->channel)*(app->bit/8) * 2); @@ -543,10 +546,10 @@ void aacenc_extractor(App *app, unsigned char **data, int *size, bool *have_fram app->offset += *size; } -void amrenc_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void amrenc_extractor(App *app, guint8 **data, int *size, gboolean *have_frame, gboolean *codec_data) { - int read_size; - int offset = app->length - app->offset; + gint read_size; + gint offset = app->length - app->offset; if (app->is_amr_nb) read_size = AMRNB_PCM_INPUT_SIZE; @@ -569,11 +572,11 @@ void amrenc_extractor(App *app, unsigned char **data, int *size, bool *have_fram * (case of (LC profile) ADTS format) * codec_data : Don't need **/ -void aacdec_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void aacdec_extractor(App *app, guint8 **data, int *size, gboolean *have_frame, gboolean *codec_data) { int read_size; int offset = app->length - app->offset; - unsigned char *pData = app->data + app->offset; + guint8 *pData = app->data + app->offset; if ((pData != NULL) && (pData[0] == 0xff) && ((pData[1] & 0xf6) == 0xf0)) { read_size = ((pData[3] & 0x03) << 11) | (pData[4] << 3) | ((pData[5] & 0xe0) >> 5); @@ -591,17 +594,16 @@ void aacdec_extractor(App *app, unsigned char **data, int *size, bool *have_fram *size = read_size; app->offset += *size; - } -void mp3dec_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void mp3dec_extractor(App *app, guint8 **data, int *size, gboolean *have_frame, gboolean *codec_data) { - int read_size; + gint read_size; guint header; guint padding, bitrate, lsf = 0, layer = 0, mpg25 = 0; guint hdr_bitrate = 0, sf = 0; - int offset = app->length - app->offset; - unsigned char *pData = app->data + app->offset; + gint offset = app->length - app->offset; + guint8 *pData = app->data + app->offset; header = GST_READ_UINT32_BE(pData); @@ -693,117 +695,11 @@ void mp3dec_extractor(App *app, unsigned char **data, int *size, bool *have_fram app->offset += *size; } -#if 1 -void extract_input_aacdec_m4a_test(App * app, unsigned char **data, int *size, bool * have_frame) -{ - int readsize = 0, read_size = 0; - unsigned int header_size = ADTS_HEADER_SIZE; - unsigned char buffer[100000]; - unsigned char codecdata[AAC_CODECDATA_SIZE] = { 0, }; - int offset = app->length - app->offset; - unsigned char *pData = app->data + app->offset; - /* - * It is not support full parsing MP4 container box. - * So It MUST start as RAW valid frame sequence. - * Testsuit that are not guaranteed to be available on functionality of all General DEMUXER/PARSER. - */ - - /* change the below one later */ - if (app->offset == 0) { - /* - * CAUTION : Codec data is needed only once in first time - * Codec data is made(or extracted) by MP4 demuxer in 'esds' box. - * So I use this data (byte) as hard coding for temporary our testing. - */ -#if 1 - /* - * The codec_data data is according to AudioSpecificConfig, - * ISO/IEC 14496-3, 1.6.2.1 - * - * below example is test for using "test.aac" or "TestSample-AAC-LC.m4a" - * case : M4A - LC profile - * codec_data=(buffer)119056e5000000000000000000000000 - * savs aac decoder get codec_data. size: 16 (Tag size : 5 byte) - * - codec data: profile : 2 - * - codec data: samplrate: 48000 - * - codec data: channels : 2 - */ - /* 2 bytes are mandatory */ - codecdata[0] = 0x11; /* ex) (5bit) 2 (LC) / (4bit) 3 (48khz)*/ - codecdata[1] = 0x90; /* ex) (4bit) 2 (2ch) */ - /* othter bytes are (optional) epconfig information */ - codecdata[2] = 0x56; - codecdata[3] = 0xE5; - codecdata[4] = 0x00; -#else - /* - * below example is test for using "TestSample-EAAC+.m4a" - * - * case : M4A - HE-AAC v1 and v2 profile - * codec_data=(buffer)138856e5a54880000000000000000000 - * savs aac decoder get codec_data. size: 16 (Tag size : 7 byte) - * - codec data: profile : 2 - * - codec data: samplrate: 22050 - * - codec data: channels : 1 - */ - /* 2 bytes are mandatory */ - codecdata[0] = 0x13; /* ex) (5bit) 2 (LC) / (4bit) 9 (22khz) */ - codecdata[1] = 0x88; /* ex) (4bit) 1 (1ch) */ - /* othter bytes are (optional) epconfig information */ - codecdata[2] = 0x56; - codecdata[3] = 0xE5; - codecdata[4] = 0xA5; - codecdata[5] = 0x48; - codecdata[6] = 0x80; -#endif - - memcpy(buffer, codecdata, AAC_CODECDATA_SIZE); - if ((pData != NULL) && (pData[0] == 0xff) && ((pData[1] & 0xf6) == 0xf0)) { - read_size = ((pData[3] & 0x03) << 11) | (pData[4] << 3) | ((pData[5] & 0xe0) >> 5); - } else { - read_size = 0; - g_print("[FAIL] Not found aac frame sync.....\n"); - } - readsize = read_size - header_size; - memcpy(buffer + AAC_CODECDATA_SIZE, pData + 7, readsize); - read_size = readsize + AAC_CODECDATA_SIZE; /* return combination of (codec_data + raw_data) */ - app->offset += header_size + readsize; - goto DONE; - } - - if ((pData != NULL) && (pData[0] == 0xff) && ((pData[1] & 0xf6) == 0xf0)) { - read_size = ((pData[3] & 0x03) << 11) | (pData[4] << 3) | ((pData[5] & 0xe0) >> 5); - readsize = read_size - header_size; - memcpy(buffer, pData + 7, readsize); /* Make only RAW data, so exclude header 7 bytes */ - read_size = readsize; - app->offset += header_size + readsize; - - if (app->offset > app->length) { - read_size = 0; - *have_frame = FALSE; - g_print("[FAIL] offset error \n"); - return; - } - - } else { - read_size = 0; - g_print("[FAIL] Not found aac frame sync. \n"); - } - DONE: - *data = buffer; - *have_frame = TRUE; - if (read_size >= offset) - *size = offset; - else - *size = read_size; -} -#endif - /** * Extract Input data for AAC encoder **/ /* - void aacenc_extractor(App *app, unsigned char **data, int *size, bool *have_frame) + void aacenc_extractor(App *app, guint8 **data, int *size, gboolean *have_frame) { int read_size; int offset = app->length - app->offset; @@ -824,19 +720,9 @@ void extract_input_aacdec_m4a_test(App * app, unsigned char **data, int *size, b app->offset += *size; } */ -#if 0 -static void _mediacodec_empty_buffer_cb(media_packet_h pkt, void *user_data) -{ - if (pkt != NULL) { - g_print("Used input buffer = %p\n", pkt); - media_packet_destroy(pkt); - } - return; -} -#endif -int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) +int _configure(App *app, int codecid, int flag, gboolean *hardware) { - bool encoder; + gboolean encoder; media_format_mimetype_e mime = 0; encoder = GET_IS_ENCODER(flag) ? 1 : 0; *hardware = GET_IS_HW(flag) ? 1 : 0; @@ -883,9 +769,6 @@ int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) if (encoder) { extractor = aacenc_extractor; mime = MEDIA_FORMAT_PCM_F32LE; /* FIXME need to check according to verdor */ - } else { - extractor = extract_input_aacdec_m4a_test; - mime = MEDIA_FORMAT_AAC_HE; } break; case MEDIACODEC_AAC_HE_PS: @@ -935,22 +818,23 @@ int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) static void _mediacodec_process_input(App *app) { - int i; - bool have_frame = FALSE; - int ret; + gint i; + gboolean have_frame = FALSE; + gint ret; static guint64 pts = 0L; void *buf_data_ptr = NULL; media_packet_h pkt = NULL; - unsigned char *tmp; - int read; - int size; - int offset; - int stride_width; + guint8 *tmp; + gint read; + gint size; + gint offset; + gint stride_width; + gboolean codec_config = FALSE; for (i = 0; i < app->frame; i++) { g_print("----------read data------------\n"); - extractor(app, &tmp, &read, &have_frame); + extractor(app, &tmp, &read, &have_frame, &codec_config); if (have_frame) { #ifdef USE_POOL @@ -973,7 +857,6 @@ static void _mediacodec_process_input(App *app) 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 { @@ -1037,17 +920,18 @@ static void _mediacodec_process_input(App *app) static gboolean read_data(App *app) { guint len = 0; - bool have_frame = FALSE; - int ret; + gboolean have_frame = FALSE; + gboolean codec_config = FALSE; + gint ret; static guint64 pts = 0L; void *buf_data_ptr = NULL; media_packet_h pkt = NULL; - unsigned char *tmp; - int i; - int read; - int size; - int offset; - int stride_width; + guint8 *tmp; + gint i; + gint read; + gint size; + gint offset; + gint stride_width; if (app->offset == 0) { app->frame_count = 0; @@ -1055,7 +939,7 @@ static gboolean read_data(App *app) } g_print("----------read data------------\n"); - extractor(app, &tmp, &read, &have_frame); + extractor(app, &tmp, &read, &have_frame, &codec_config); if (app->offset >= app->length - 4) { /* EOS */ @@ -1185,7 +1069,7 @@ static gboolean _mediacodec_inbuf_used_cb(media_packet_h pkt, void *user_data) return TRUE; } -static bool _mediacodec_outbuf_available_cb(media_packet_h pkt, void *user_data) +static gboolean _mediacodec_outbuf_available_cb(media_packet_h pkt, void *user_data) { media_packet_h out_pkt = NULL; int ret; @@ -1220,7 +1104,7 @@ static bool _mediacodec_outbuf_available_cb(media_packet_h pkt, void *user_data) return TRUE; } -static bool _mediacodec_buffer_status_cb(mediacodec_status_e status, void *user_data) +static gboolean _mediacodec_buffer_status_cb(mediacodec_status_e status, void *user_data) { g_print("_mediacodec_buffer_status_cb %d\n", status); @@ -1234,12 +1118,12 @@ static bool _mediacodec_buffer_status_cb(mediacodec_status_e status, void *user_ return TRUE; } -static bool _mediacodec_error_cb(mediacodec_error_e error, void *user_data) +static gboolean _mediacodec_error_cb(mediacodec_error_e error, void *user_data) { return TRUE; } -static bool _mediacodec_eos_cb(void *user_data) +static gboolean _mediacodec_eos_cb(void *user_data) { return TRUE; } @@ -1250,7 +1134,7 @@ gboolean _foreach_cb(mediacodec_codec_type_e codec_type, void *user_data) return TRUE; } -static void _mediacodec_prepare(App *app, bool frame_all) +static void _mediacodec_prepare(App *app, gboolean frame_all) { int ret; @@ -1271,7 +1155,8 @@ static void _mediacodec_prepare(App *app, bool frame_all) return; } - app->mime = _mediacodec_set_codec(app, app->codecid, app->flag, &app->hardware); + /* get mime and link to each codec parser */ + app->mime = _configure(app, app->codecid, app->flag, &app->hardware); /* set codec info */ ret = media_format_create(&fmt); @@ -1332,7 +1217,7 @@ static void _mediacodec_prepare(App *app, bool frame_all) } -/* get packet pool instance */ + /* 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"); @@ -1493,7 +1378,7 @@ void quit_program(App *app) { media_format_unref(fmt); g_main_loop_quit(app->loop); - elm_exit(); + exit(0); } @@ -1505,7 +1390,7 @@ void reset_menu_state() void _interpret_main_menu(char *cmd, App *app) { - int len = strlen(cmd); + gint len = strlen(cmd); if (len == 1) { if (strncmp(cmd, "a", 1) == 0) g_menu_state = CURRENT_STATUS_FILENAME; @@ -1619,8 +1504,11 @@ gboolean timeout_menu_display(void* data) } -static void interpret(char *cmd, App *app) +static void interpret(char *cmd) { + App *app = &s_app; + gint tmp = 0; + switch (g_menu_state) { case CURRENT_STATUS_MAINMENU: _interpret_main_menu(cmd, app); @@ -1631,9 +1519,8 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_SET_CODEC: { - int tmp; - static int cnt = 0; - char **ptr = NULL; + static gint cnt = 0; + gchar **ptr = NULL; switch (cnt) { case 0: tmp = atoi(cmd); @@ -1662,7 +1549,7 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_SET_VDEC_INFO: { - static int cnt = 0; + static gint cnt = 0; switch (cnt) { case 0: app->width = atoi(cmd); @@ -1682,7 +1569,7 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_SET_VENC_INFO: { - static int cnt = 0; + static gint cnt = 0; switch (cnt) { case 0: app->width = atoi(cmd); @@ -1710,7 +1597,7 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_SET_ADEC_INFO: { - static int cnt = 0; + static gint cnt = 0; switch (cnt) { case 0: app->samplerate = atoi(cmd); @@ -1737,20 +1624,48 @@ static void interpret(char *cmd, App *app) static int cnt = 0; switch (cnt) { case 0: - app->samplerate = atoi(cmd); + tmp = atoi(cmd); + + if (tmp <= 0 || tmp > 96000) { + g_print("Invalid value\n"); + reset_menu_state(); + break; + } + app->samplerate = tmp; cnt++; break; case 1: - app->channel = atoi(cmd); + tmp = atoi(cmd); + + if (tmp <= 0 || tmp > 6) { + g_print("Invalid value\n"); + reset_menu_state(); + break; + } + app->channel = tmp; cnt++; break; case 2: - app->bit = atoi(cmd); + tmp = atoi(cmd); + + if (tmp <= 0 || tmp > 32) { + g_print("Invalid value\n"); + reset_menu_state(); + break; + } + app->bit = tmp; cnt++; break; case 3: - app->bitrate = atoi(cmd); + tmp = atoi(cmd); + + if (tmp <= 0 || tmp > INT_MAX) { + g_print("Invalid value\n"); + reset_menu_state(); + break; + } app->type = AUDIO_ENC; + app->bitrate = tmp; reset_menu_state(); cnt = 0; @@ -1762,10 +1677,16 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_PROCESS_INPUT: { - app->frame = atoi(cmd); + tmp = atoi(cmd); + + if (tmp <= 0 || tmp > INT_MAX) { + g_print("Invalid value\n"); + reset_menu_state(); + break; + } + app->frame = tmp; - if (app->frame > 0 && app->frame < 10) - _mediacodec_process_input(app); + _mediacodec_process_input(app); reset_menu_state(); } break; @@ -1814,33 +1735,29 @@ gboolean input(GIOChannel *channel, GIOCondition cond, gpointer data) gchar buf[MAX_STRING_LEN]; gsize read; GError *error = NULL; - App *context = (App*)data; g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error); buf[read] = '\0'; g_strstrip(buf); - interpret(buf, context); + interpret(buf); return TRUE; } int main(int argc, char *argv[]) { - App *app = &s_app; - GIOChannel *stdin_channel; stdin_channel = g_io_channel_unix_new(0); g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL); - g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, app); + g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL); + App *app = &s_app; displaymenu(); app->loop = g_main_loop_new(NULL, TRUE); app->timer = g_timer_new(); g_main_loop_run(app->loop); - - ops.data = app; return appcore_efl_main(PACKAGE, &argc, &argv, &ops); @@ -1848,11 +1765,11 @@ int main(int argc, char *argv[]) -void mc_hex_dump(char *desc, void *addr, int len) +void mc_hex_dump(char *desc, void *addr, gint len) { int i; - unsigned char buff[17]; - unsigned char *pc = (unsigned char *)addr; + guint8 buff[17]; + guint8 *pc = (guint8 *)addr; if (desc != NULL) g_print("%s:\n", desc); -- 2.7.4