#include <Elementary.h>
#include <appcore-efl.h>
#include <gst/gst.h>
+#include <limits.h>
#include <tbm_surface.h>
#include <dlog.h>
#include <camera.h>
#include <media_codec.h>
#include <media_packet.h>
+#include <media_packet_internal.h>
#include <media_packet_pool.h>
#include <media_codec_internal.h>
#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,
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 */
guint channel;
guint bit;
guint bitrate;
- bool is_amr_nb;
+ gboolean is_amr_nb;
/* Render */
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;
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;
{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;
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;
*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;
* - 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)) {
*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;
*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;
*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);
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;
* (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);
*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);
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;
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;
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:
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
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 {
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;
}
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 */
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;
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);
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;
}
return TRUE;
}
-static void _mediacodec_prepare(App *app, bool frame_all)
+static void _mediacodec_prepare(App *app, gboolean frame_all)
{
int ret;
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);
}
-/* 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");
{
media_format_unref(fmt);
g_main_loop_quit(app->loop);
- elm_exit();
+ exit(0);
}
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;
}
-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);
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);
break;
case CURRENT_STATUS_SET_VDEC_INFO:
{
- static int cnt = 0;
+ static gint cnt = 0;
switch (cnt) {
case 0:
app->width = atoi(cmd);
break;
case CURRENT_STATUS_SET_VENC_INFO:
{
- static int cnt = 0;
+ static gint cnt = 0;
switch (cnt) {
case 0:
app->width = atoi(cmd);
break;
case CURRENT_STATUS_SET_ADEC_INFO:
{
- static int cnt = 0;
+ static gint cnt = 0;
switch (cnt) {
case 0:
app->samplerate = atoi(cmd);
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;
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;
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);
-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);