Modify the test suite operation used with mediacodec. 91/216791/7
authorGilbok Lee <gilbok.lee@samsung.com>
Fri, 1 Nov 2019 06:41:18 +0000 (15:41 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Thu, 7 Nov 2019 08:49:00 +0000 (17:49 +0900)
[Version] 0.1.21
[Issue Type] Fix test suite

Change-Id: I24866a0099016bdf08d236b6115febe8bb105b18

test/mediamuxer_test.c
test/mediamuxer_test_with_mediacodec.c

index d9dc8e3..825f024 100644 (file)
@@ -39,7 +39,6 @@
 #include <mediademuxer.h>
 #endif
 
-#define DUMP_OUTBUF 1
 /*-----------------------------------------------------------------------
 |    GLOBAL VARIABLE DEFINITIONS:                                       |
 -----------------------------------------------------------------------*/
@@ -81,12 +80,6 @@ media_format_h media_format_a = NULL;
 media_format_h media_format_t = NULL;
 media_format_h input_fmt = NULL;
 
-#if DUMP_OUTBUF
-int g_OutFileCtr;
-FILE *fp_in = NULL;
-bool validate_dump = false;
-#endif
-
 int use_video = 1;   /* 1 to test video with codec,   0 for audio */
 int use_encoder = 1;
 media_format_mimetype_e mimetype;
index 5641821..9a3941e 100644 (file)
@@ -42,6 +42,7 @@
 #define GST_SECOND (G_USEC_PER_SEC * G_GINT64_CONSTANT(1000))
 #endif
 
+#define DUMP_OUTBUF 0
 #define USE_INPUT_QUEUE 1
 #define MAX_INPUT_BUF_NUM 20
 #define CHECK_BIT(x, y) (((x) >> (y)) & 0x01)
@@ -81,7 +82,10 @@ static mediacodec_h g_media_codec[MAX_HANDLE] = {0};
 static int samplebyte = DEFAULT_SAMPLEBYTE;
 int enc_vide_pkt_available = 0;
 FILE *fp_src = NULL;
-
+#if DUMP_OUTBUF
+FILE *fp_in = NULL;
+bool validate_dump = false;
+#endif
 /* ----------------------------------------------------------------------
 |    HELPER  FUNCTION                                                   |
 ---------------------------------------------------------------------- */
@@ -195,15 +199,15 @@ void _add_adts_header_for_aacenc(unsigned char *buffer, int packetLen)
        /* 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[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;
 }
 
 /* To aid muxer-codec test */
-static void _mediacodec_fill_buffer_cb(media_packet_h pkt, void *user_data)
+static void _mediacodec_fill_buffer_cb(media_packet_h out_pkt, void *user_data)
 {
        g_print("**** Entered _mediacodec_fill_buffer_cb *****\n");
        int track_index_aud = 1;
@@ -212,30 +216,44 @@ static void _mediacodec_fill_buffer_cb(media_packet_h pkt, void *user_data)
        uint64_t pts, dts, duration, size;
        media_buffer_flags_e flags;
        void *codec_data;
+       bool is_eos = false;
+#if DUMP_OUTBUF
        void *pkt_data;
+#endif
        unsigned int codec_data_size;
+       media_packet_h pkt = NULL;
+       mediacodec_h codec_handle = (mediacodec_h)user_data;
+
+       if (!user_data)
+               return;
+
+       mediacodec_get_output(codec_handle, &pkt, 0);
+       if (!pkt) {
+               g_print("media codec output buffer is NULL\n");
+               return;
+       }
 
        g_print("A%d write sample call. packet add:%p\n", ++count, pkt);
 
        if (media_packet_get_buffer_size(pkt, &size)) {
                g_print("unable to get the buffer size actual =%"PRIu64"\n", size);
+               media_packet_destroy(pkt);
                return;
        }
-
+       /* for print log */
        media_packet_get_pts(pkt, &pts);
        media_packet_get_dts(pkt, &dts);
        media_packet_get_duration(pkt, &duration);
        /* offset */
        media_packet_get_flags(pkt, &flags);
-       media_packet_get_extra(pkt, (void**)&codec_data);
-       codec_data_size = strlen(codec_data) + 1;
+       media_packet_get_codec_data(pkt, (void **)&codec_data, &codec_data_size);
 
        g_print("***pkt attributes before writing *** Size=%"PRIu64", pts=%"PRIu64", dts=%"PRIu64", duration=%"PRIu64", flags=%d\n", size, pts, dts, duration, (int)flags);
-       g_print("Codec_data=%s\ncodec_data_size = %d\n", (char*)codec_data, codec_data_size);
+       g_print("Codec_data=%s\ncodec_data_size = %d\n", (char *)codec_data, codec_data_size);
 
 #if DUMP_OUTBUF
        if (count == 0) {
-               fp_in = fopen("/opt/usr/codec_dump_mxr.aac", "wb");
+               fp_in = fopen("/tmp/codec_dump_mxr.aac", "wb");
                if (fp_in != NULL)
                        validate_dump = true;
                else
@@ -243,24 +261,23 @@ static void _mediacodec_fill_buffer_cb(media_packet_h pkt, void *user_data)
        }
 #endif
 
-       /* EOS hack for mediacodec */
-       if (count == 1758) {  /* Last buffer for SampleAAC.aac. should be replaced with a valid eos. */
-               g_print("Last Buffer Reached\n");
 #if DUMP_OUTBUF
-               fclose(fp_in);
-#endif
-               _mediacodec_eos_cb(user_data);
-               goto Finalize;
-       }
-
        media_packet_get_buffer_data_ptr(pkt, &pkt_data);
-#if DUMP_OUTBUF
        if (validate_dump)
                fwrite(pkt_data, 1, size, fp_in);
 #endif
        mediamuxer_write_sample(myMuxer, track_index_aud, pkt);
 
-Finalize:
+       /* EOS hack for mediacodec */
+       media_packet_is_end_of_stream(pkt, &is_eos);
+       if (is_eos) {
+               g_print("Last Buffer Reached\n");
+#if DUMP_OUTBUF
+               fclose(fp_in);
+#endif
+       }
+
+       media_packet_destroy(pkt);
        return;
 }
 
@@ -293,12 +310,12 @@ static void _mediacodec_empty_buffer_cb(media_packet_h pkt, void *user_data)
 {
        if (pkt != NULL) {
 #if USE_INPUT_QUEUE
-       media_packet_unset_flags(pkt, MEDIA_PACKET_CODEC_CONFIG);
-       g_queue_push_tail(&input_available, pkt);
-       g_print("availablebuf = %p\n", pkt);
+               media_packet_unset_flags(pkt, MEDIA_PACKET_CODEC_CONFIG);
+               g_queue_push_tail(&input_available, pkt);
+               g_print("availablebuf = %p\n", pkt);
 #else
-       g_print("Used input buffer = %p\n", pkt);
-       media_packet_destroy(pkt);
+               g_print("Used input buffer = %p\n", pkt);
+               media_packet_destroy(pkt);
 #endif
        }
        return;
@@ -432,17 +449,16 @@ unsigned int __bytestream2yuv420(FILE *fd, unsigned char* yuv)
        if (feof(fd))
                return 0;
 
-       read_size = width*height*3/2;
+       read_size = width * height * 3 / 2;
 
        result = fread(buffer, 1, read_size, fd);
-       g_print("3\n");
 
        if (result != read_size)
                return -1;
 
-       memcpy(yuv, buffer, width*height*3/2);
+       memcpy(yuv, buffer, read_size);
 
-       return width*height*3/2;
+       return read_size;
 }
 
 /* To aid muxer-codec test */
@@ -456,14 +472,14 @@ unsigned int __extract_input_aacenc(FILE *fd, unsigned char* rawdata)
        if (feof(fd))
                return 0;
 
-       readsize =  ((samplebyte*channel)*(bit/8));
+       readsize = ((samplebyte * channel) * (bit / 8));
        result = fread(buffer, 1, readsize, fd);
        if (result != readsize)
-               return -1;
+               g_print("different size of read. result is %d\n", result);
 
-       memcpy(rawdata, buffer, readsize);
+       memcpy(rawdata, buffer, result);
 
-       return readsize;
+       return result;
 }
 
 /* To aid muxer-codec test */
@@ -484,9 +500,9 @@ int __mediacodec_process_input(void)
 
        if (fp_src == NULL) {
                if (bMultipleFiles) {
-                       if (g_uri[g_len-1] != '/')
+                       if (g_uri[g_len - 1] != '/')
                                g_uri[g_len++] = '/';
-                       snprintf(g_uri+g_len, MAX_STRING_LEN - g_len, "%05d", frame_count);
+                       snprintf(g_uri + g_len, MAX_STRING_LEN - g_len, "%05d", frame_count);
                }
                fp_src = fopen(g_uri, "r");
                if (fp_src == NULL) {
@@ -514,7 +530,7 @@ int __mediacodec_process_input(void)
                                if (bMultipleFiles) {
                                        buf_size = __extract_input_per_frame(fp_src, data);
                                        fclose(fp_src);
-                                       snprintf(g_uri+g_len, MAX_STRING_LEN-g_len, "%05d", frame_count+1);
+                                       snprintf(g_uri + g_len, MAX_STRING_LEN - g_len, "%05d", frame_count + 1);
                                        fp_src = fopen(g_uri, "r");
                                        if (fp_src == NULL) {
                                                media_packet_set_flags(in_buf, MEDIA_PACKET_END_OF_STREAM);
@@ -536,14 +552,14 @@ int __mediacodec_process_input(void)
                                buf_size = __extract_input_aacenc(fp_src, data);
                                g_print("audio buf_size=%d\n", buf_size);
                                /* pts is not needed for muxer, if adts header is present */
-                               /* media_packet_set_pts (in_buf, pts); */
                                g_print("----pts calculation: input pts = %"PRIu64", buf_size=%d samplerate=%d, samplebyte=%d\n", pts, buf_size, samplerate, samplebyte);
+                               media_packet_set_pts(in_buf, pts);
                                if (samplerate != 0)
                                        pts += ((GST_SECOND / samplerate) * samplebyte);
                        }
                }
 
-               if (buf_size >= 0) {
+               if (buf_size > 0) {
                        if (use_video && buf_size == 4) {
                                media_packet_set_flags(in_buf, MEDIA_PACKET_END_OF_STREAM);
                                media_packet_set_buffer_size(in_buf, 4);
@@ -556,6 +572,12 @@ int __mediacodec_process_input(void)
                        g_print("%s - input_buf size = %4d  (0x%x) at %4d frame, %p\n", __func__, buf_size, buf_size, frame_count, in_buf);
 
                        ret = mediacodec_process_input(g_media_codec[0], in_buf, 0);
+               } else if (buf_size == 0) {
+                       media_packet_set_flags(in_buf, MEDIA_PACKET_END_OF_STREAM);
+                       media_packet_set_buffer_size(in_buf, 0);
+                       mediacodec_process_input(g_media_codec[0], in_buf, 0);
+                       g_print("\n\nEOS packet is sent\n");
+                       return MEDIACODEC_ERROR_INVALID_INBUFFER;
                } else {
                        g_print("%s - [WARN] Check to input buf_size = %4d  at %4d frame, %p\n", __func__, buf_size, frame_count, in_buf);
                        return MEDIACODEC_ERROR_INVALID_INBUFFER;