[UTC/ITC][capi-media-codec][Fix incorrect bit depth setting]
authorSejun Park <sejun79.park@samsung.com>
Thu, 29 Mar 2018 07:38:12 +0000 (16:38 +0900)
committerSejun Park <sejun79.park@samsung.com>
Mon, 2 Apr 2018 06:39:23 +0000 (15:39 +0900)
Change-Id: Ic59b681d01e5345e6be3699a3cddcd240b3f1a5c

src/itc/mediacodec/ITs-mediacodec.c
src/utc/mediacodec/utc-media-mediacodec.c

index 0a11209..376ae85 100755 (executable)
@@ -283,7 +283,7 @@ void ITs_media_codec_startup(void)
        nRet = media_format_create(&hFormat);
        if (nRet != MEDIA_FORMAT_ERROR_NONE)
        {
-               FPRINTF("[Line : %d][%s] media_format_create API failed \\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
+               FPRINTF("[Line : %d][%s] media_format_create API failed = %s \\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
                g_bIsMediaCodecValidHandle = false;
                return;
        }
@@ -296,37 +296,37 @@ void ITs_media_codec_startup(void)
        nRet = media_format_set_audio_mime(hFormat, MEDIA_FORMAT_PCM);
        if (nRet != MEDIA_FORMAT_ERROR_NONE)
        {
-               FPRINTF("[Line : %d][%s] media_format_set_audio_mime API failed \\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
+               FPRINTF("[Line : %d][%s] media_format_set_audio_mime API failed = %s\\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
                return;
        }
        nRet = media_format_set_audio_samplerate(hFormat, 48000);
        if (nRet != MEDIA_FORMAT_ERROR_NONE)
        {
-               FPRINTF("[Line : %d][%s] media_format_set_audio_samplerate API failed \\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
+               FPRINTF("[Line : %d][%s] media_format_set_audio_samplerate API failed = %s\\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
                return;
        }
        nRet = media_format_set_audio_channel(hFormat, 2);
        if (nRet != MEDIA_FORMAT_ERROR_NONE)
        {
-               FPRINTF("[Line : %d][%s] media_format_set_audio_channel API failed \\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
+               FPRINTF("[Line : %d][%s] media_format_set_audio_channel API failed = %s \\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
                return;
        }
        nRet = media_format_set_audio_bit(hFormat, 16);
        if (nRet != MEDIA_FORMAT_ERROR_NONE)
        {
-               FPRINTF("[Line : %d][%s] media_format_set_audio_bit API failed \\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
+               FPRINTF("[Line : %d][%s] media_format_set_audio_bit API failed = %s\\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
                return;
        }
        nRet = media_format_set_audio_avg_bps(hFormat,128000);
        if (nRet != MEDIA_FORMAT_ERROR_NONE)
        {
-               FPRINTF("[Line : %d][%s] media_format_set_audio_avg_bps API failed \\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
+               FPRINTF("[Line : %d][%s] media_format_set_audio_avg_bps API failed = %s\\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
                return;
        }
        nRet = media_packet_create_alloc(hFormat, NULL, NULL, &hInputBuff);
        if (nRet != MEDIA_FORMAT_ERROR_NONE)
        {
-               FPRINTF("[Line : %d][%s] media_format_set_audio_alloc API failed \\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
+               FPRINTF("[Line : %d][%s] media_format_set_audio_alloc API failed = %s\\n", __LINE__, API_NAMESPACE, MediaCodecGetError(nRet));
                return;
        }
 }
@@ -427,6 +427,8 @@ int ITc_mediacodec_prepare_unprepare_p(void)
        int flags;
        bool bEncoder = true; // checking encoder type
        int nType = 0;
+       int i = 0;
+       int bit_depth[] = { 16, 32 };
 
        int nRet = mediacodec_get_supported_type(g_mediacodec, codec, bEncoder, &nType);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_get_supported_type", MediaCodecGetError(nRet));
@@ -443,7 +445,11 @@ int ITc_mediacodec_prepare_unprepare_p(void)
        nRet = mediacodec_set_codec(g_mediacodec, codec, flags);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_codec", MediaCodecGetError(nRet));
 
-       nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, bit_depth[i], 128000);
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_aenc_info", MediaCodecGetError(nRet));
 
        //Target API
@@ -540,6 +546,8 @@ int ITc_mediacodec_set_adec_info_p(void)
        int flags;
        bool bEncoder = false; // checking encoder type
        int nType = 0;
+       int i = 0;
+       int bit_depth[] = { 16, 32 };
 
        int nRet = mediacodec_get_supported_type(g_mediacodec, codec, bEncoder, &nType);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_get_supported_type", MediaCodecGetError(nRet));
@@ -557,7 +565,11 @@ int ITc_mediacodec_set_adec_info_p(void)
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_codec", MediaCodecGetError(nRet));
 
        //Target API
-       nRet = mediacodec_set_adec_info(g_mediacodec, 48000, 2, 16);
+       for (i = 0; i < 2; i++) {
+               nRet = mediacodec_set_adec_info(g_mediacodec, 48000, 2, bit_depth[i]);
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_adec_info", MediaCodecGetError(nRet));
 
        return 0;
@@ -588,6 +600,8 @@ int ITc_mediacodec_set_aenc_info_p(void)
        int flags;
        bool bEncoder = true; // checking encoder type
        int nType = 0;
+       int i = 0;
+       int bit_depth[] = { 16, 32 };
 
        int nRet = mediacodec_get_supported_type(g_mediacodec, codec, bEncoder, &nType);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_get_supported_type", MediaCodecGetError(nRet));
@@ -605,7 +619,11 @@ int ITc_mediacodec_set_aenc_info_p(void)
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_codec", MediaCodecGetError(nRet));
 
        //Target API
-       nRet = mediacodec_set_aenc_info(g_mediacodec, 100, 64, 32, 0);
+       for (i = 0; i < 2; i++) {
+               nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, bit_depth[i], 128000);
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_aenc_info", MediaCodecGetError(nRet));
 
        return 0;
@@ -726,6 +744,8 @@ int ITc_mediacodec_process_input_p(void)
        int flags;
        bool bEncoder = true; // checking encoder type
        int nType = 0;
+       int i = 0;
+       int bit_depth[] = { 16, 32 };
 
        int nRet = mediacodec_get_supported_type(g_mediacodec, codec, bEncoder, &nType);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_get_supported_type", MediaCodecGetError(nRet));
@@ -742,7 +762,11 @@ int ITc_mediacodec_process_input_p(void)
        nRet = mediacodec_set_codec(g_mediacodec, codec, flags);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_codec", MediaCodecGetError(nRet));
 
-       nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, bit_depth[i], 128000);
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_aenc_info", MediaCodecGetError(nRet));
 
        nRet = mediacodec_prepare(g_mediacodec);
@@ -788,6 +812,7 @@ int ITc_mediacodec_get_output_p(void)
        int flags;
        bool bEncoder = true; // checking encoder type
        int nType = 0, i = 0;
+       int bit_depth[] = { 16, 32 };
 
        int nRet = mediacodec_get_supported_type(g_mediacodec, codec, bEncoder, &nType);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_get_supported_type", MediaCodecGetError(nRet));
@@ -804,7 +829,11 @@ int ITc_mediacodec_get_output_p(void)
        nRet = mediacodec_set_codec(g_mediacodec, codec, flags);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_codec", MediaCodecGetError(nRet));
 
-       nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, bit_depth[i], 128000);
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_aenc_info", MediaCodecGetError(nRet));
 
        nRet = mediacodec_set_output_buffer_available_cb(g_mediacodec, mediacodec_get_output_cb_p, NULL);
@@ -933,6 +962,7 @@ int ITc_mediacodec_set_unset_input_buffer_used_cb_p(void)
        int flags;
        bool bEncoder = true; // checking encoder type
        int nType = 0, i = 0;
+       int bit_depth[] = { 16, 32 };
 
        int nRet = mediacodec_get_supported_type(g_mediacodec, codec, bEncoder, &nType);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_get_supported_type", MediaCodecGetError(nRet));
@@ -949,7 +979,11 @@ int ITc_mediacodec_set_unset_input_buffer_used_cb_p(void)
        nRet = mediacodec_set_codec(g_mediacodec, codec, flags);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_codec", MediaCodecGetError(nRet));
 
-       nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, bit_depth[i], 128000);
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_aenc_info", MediaCodecGetError(nRet));
 
        //Target API
@@ -1020,6 +1054,7 @@ int ITc_mediacodec_set_unset_output_buffer_available_cb_p(void)
        int flags;
        bool bEncoder = true; // checking encoder type
        int nType = 0, i = 0;
+       int bit_depth[] = { 16, 32 };
 
        int nRet = mediacodec_get_supported_type(g_mediacodec, codec, bEncoder, &nType);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_get_supported_type", MediaCodecGetError(nRet));
@@ -1036,7 +1071,11 @@ int ITc_mediacodec_set_unset_output_buffer_available_cb_p(void)
        nRet = mediacodec_set_codec(g_mediacodec, codec, flags);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_codec", MediaCodecGetError(nRet));
 
-       nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, bit_depth[i], 128000);
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_aenc_info", MediaCodecGetError(nRet));
 
        //Target API
@@ -1104,6 +1143,8 @@ int ITc_mediacodec_flush_buffers_p(void)
        int flags;
        bool bEncoder = true; // checking encoder type
        int nType = 0;
+       int bit_depth[] = { 16, 32 };
+       int i;
 
        int nRet = mediacodec_get_supported_type(g_mediacodec, codec, bEncoder, &nType);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_get_supported_type", MediaCodecGetError(nRet));
@@ -1120,7 +1161,11 @@ int ITc_mediacodec_flush_buffers_p(void)
        nRet = mediacodec_set_codec(g_mediacodec, codec, flags);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_codec", MediaCodecGetError(nRet));
 
-       nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, bit_depth[i], 128000);
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_aenc_info", MediaCodecGetError(nRet));
 
        //Target API
@@ -1235,6 +1280,7 @@ int ITc_mediacodec_set_unset_buffer_status_cb_p(void)
        int flags;
        bool bEncoder = true; // checking encoder type
        int nType = 0, i = 0;
+       int bit_depth[] = { 16, 32 };
 
        int nRet = mediacodec_get_supported_type(g_mediacodec, codec, bEncoder, &nType);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_get_supported_type", MediaCodecGetError(nRet));
@@ -1251,7 +1297,11 @@ int ITc_mediacodec_set_unset_buffer_status_cb_p(void)
        nRet = mediacodec_set_codec(g_mediacodec, codec, flags);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_codec", MediaCodecGetError(nRet));
 
-       nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, bit_depth[i], 128000);
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_aenc_info", MediaCodecGetError(nRet));
 
        //Target API
@@ -1320,10 +1370,8 @@ int ITc_mediacodec_get_packet_pool_p(void)
        bool bEncoder = true; // checking encoder type
        int nType = 0;
        media_packet_pool_h hpacket_pool;
-       int nsamplerate =48000;
-       int nchannel =2;
-       int nbit =16;
-       int nbitrate = 128000;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        int nRet = mediacodec_get_supported_type(g_mediacodec, codec, bEncoder, &nType);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_get_supported_type", MediaCodecGetError(nRet));
@@ -1340,7 +1388,11 @@ int ITc_mediacodec_get_packet_pool_p(void)
        nRet = mediacodec_set_codec(g_mediacodec, codec, flags);
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_codec", MediaCodecGetError(nRet));
 
-       nRet = mediacodec_set_aenc_info(g_mediacodec, nsamplerate, nchannel, nbit, nbitrate);
+       for (i = 0; i < 2; i++) {
+               nRet = mediacodec_set_aenc_info(g_mediacodec, 48000, 2, bit_depth[i], 128000);
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_set_aenc_info", MediaCodecGetError(nRet));
 
        nRet = mediacodec_prepare(g_mediacodec);
@@ -1388,6 +1440,8 @@ int ITc_mediacodec_configure_from_media_format_audio_video_decoder_p(void)
        int nRet =  0;
        media_format_h audioDecoderformat = NULL;
        media_format_h videoDecoderformat = NULL;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        nRet = media_format_create(&audioDecoderformat);
        PRINT_RESULT(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_create", MediaCodecGetError(nRet));
@@ -1399,12 +1453,16 @@ int ITc_mediacodec_configure_from_media_format_audio_video_decoder_p(void)
        PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_set_audio_mime", MediaCodecGetError(nRet), media_format_unref(audioDecoderformat));
        nRet = media_format_set_audio_channel(audioDecoderformat, 2);
        PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_set_audio_channel", MediaCodecGetError(nRet), media_format_unref(audioDecoderformat));
-       nRet = media_format_set_audio_bit(audioDecoderformat, 16);
-       PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_set_audio_bit", MediaCodecGetError(nRet), media_format_unref(audioDecoderformat));
        nRet = media_format_set_audio_samplerate(audioDecoderformat, 48000);
        PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_set_audio_samplerate", MediaCodecGetError(nRet), media_format_unref(audioDecoderformat));
 
-       nRet = mediacodec_configure_from_media_format(g_mediacodec, audioDecoderformat, (MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_SW));
+       for (i = 0; i < 2; i++) {
+               nRet = media_format_set_audio_bit(audioDecoderformat, bit_depth[i]);
+               PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_set_audio_bit", MediaCodecGetError(nRet), media_format_unref(audioDecoderformat));
+               nRet = mediacodec_configure_from_media_format(g_mediacodec, audioDecoderformat, (MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_SW));
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT_CLEANUP(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_configure_from_media_format", MediaCodecGetError(nRet), media_format_unref(audioDecoderformat));
 
        nRet = media_format_unref(audioDecoderformat);
@@ -1454,6 +1512,8 @@ int ITc_mediacodec_configure_from_media_format_audio_video_encoder_p(void)
        int nRet =  0;
        media_format_h audioEncoderformat = NULL;
        media_format_h videoEncoderformat = NULL;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        nRet = media_format_create(&audioEncoderformat);
        PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_create", MediaCodecGetError(nRet), media_format_unref(audioEncoderformat));
@@ -1466,12 +1526,16 @@ int ITc_mediacodec_configure_from_media_format_audio_video_encoder_p(void)
        PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_set_audio_samplerate", MediaCodecGetError(nRet), media_format_unref(audioEncoderformat));
        nRet = media_format_set_audio_channel(audioEncoderformat, 2);
        PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_set_audio_channel", MediaCodecGetError(nRet), media_format_unref(audioEncoderformat));
-       nRet = media_format_set_audio_bit(audioEncoderformat, 16);
-       PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_set_audio_bit", MediaCodecGetError(nRet), media_format_unref(audioEncoderformat));
        nRet = media_format_set_audio_avg_bps(audioEncoderformat,128000);
        PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_set_audio_avg_bps", MediaCodecGetError(nRet), media_format_unref(audioEncoderformat));
 
-       nRet = mediacodec_configure_from_media_format(g_mediacodec, audioEncoderformat, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
+       for (i = 0; i < 2; i++) {
+               nRet = media_format_set_audio_bit(audioEncoderformat, bit_depth[i]);
+               PRINT_RESULT_CLEANUP(MEDIA_FORMAT_ERROR_NONE, nRet, "media_format_set_audio_bit", MediaCodecGetError(nRet), media_format_unref(audioEncoderformat));
+               nRet = mediacodec_configure_from_media_format(g_mediacodec, audioEncoderformat, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
+               if (nRet == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        PRINT_RESULT_CLEANUP(MEDIACODEC_ERROR_NONE, nRet, "mediacodec_configure_from_media_format", MediaCodecGetError(nRet), media_format_unref(audioEncoderformat));
 
        nRet = media_format_unref(audioEncoderformat);
index 9747725..21609f6 100755 (executable)
@@ -162,6 +162,8 @@ unsigned int extract_aacdec(FILE *fd, unsigned char* aacdata)
        if ((buffer[0] == 0xff) && ((buffer[1] & 0xf6) == 0xf0)) {
                readsize = ((buffer[3] & 0x03) << 11) | (buffer[4] << 3) | ((buffer[5] & 0xe0) >> 5);
                result = fread(buffer + hader_size, 1,(readsize - hader_size), fd);
+               if (result != (readsize - hader_size))
+                       return 0;
                memcpy(aacdata, buffer, readsize);
        } else {
                readsize = 0;
@@ -526,11 +528,17 @@ int _mediacodec_get_output(void)
 
 static bool _mediacodec_empty_buffer_cb(media_packet_h pkt, void *user_data)
 {
+       int ret = 0;
        _emptybufferCB_called = true;
        if (!_use_pool)
                media_packet_destroy(pkt);
-       else
-               media_packet_pool_release_packet(pool, pkt);
+       else {
+               ret = media_packet_pool_release_packet(pool, pkt);
+               if (ret != MEDIA_PACKET_ERROR_NONE) {
+                       fprintf(stderr, "media_packet_pool_release_packet failed");
+                       return false;
+               }
+       }
        return true;
 }
 
@@ -604,18 +612,38 @@ void utc_media_mediacodec_startup(void)
                int size_of_path = 0;
                size_of_path = strlen(pszValue) + strlen(vdec_file) + 6;
                vdec_path = (char*)malloc(size_of_path);
+
+               if (!vdec_path) {
+                       _is_broken = true;
+                       return;
+               }
                snprintf(vdec_path, size_of_path, "%s/res/%s", pszValue, vdec_file);
 
                size_of_path = strlen(pszValue) + strlen(venc_file) + 6;
                venc_path = (char*)malloc(size_of_path);
+
+               if (!venc_path) {
+                       _is_broken = true;
+                       return;
+               }
                snprintf(venc_path, size_of_path, "%s/res/%s", pszValue, venc_file);
 
                size_of_path = strlen(pszValue) + strlen(aenc_file) + 6;
                aenc_path = (char*)malloc(size_of_path);
+
+               if (!aenc_path) {
+                       _is_broken = true;
+                       return;
+               }
                snprintf(aenc_path, size_of_path, "%s/res/%s", pszValue, aenc_file);
 
                size_of_path = strlen(pszValue) + strlen(adec_file) + 6;
                adec_path = (char*)malloc(size_of_path);
+               if (!adec_path) {
+                       _is_broken = true;
+                       return;
+               }
+
                snprintf(adec_path, size_of_path, "%s/res/%s", pszValue, adec_file);
        }
        else
@@ -702,6 +730,7 @@ void utc_media_mediacodec_startup(void)
 void utc_media_mediacodec_cleanup(void)
 {
        int i;
+       int ret;
 
        if (aenc_fmt)
                media_format_unref(aenc_fmt);
@@ -722,27 +751,45 @@ void utc_media_mediacodec_cleanup(void)
        }
 
        if (_use_pool) {
-               media_packet_pool_deallocate(pool);
-               media_packet_pool_destroy(pool);
+               ret = media_packet_pool_deallocate(pool);
+               if (ret != MEDIA_PACKET_ERROR_NONE) {
+                       _is_broken = true;
+                       fprintf(stderr, "media_packet_pool_deallocate failed");
+                       return;
+               }
+               ret = media_packet_pool_destroy(pool);
+               if (ret != MEDIA_PACKET_ERROR_NONE) {
+                       _is_broken = true;
+                       fprintf(stderr, "media_packet_pool_deallocate failed");
+                       return;
+               }
                _use_pool = FALSE;
        }
 
        if (fp_vdec) {
+               if (vdec_path)
+                       free(vdec_path);
                fclose(fp_vdec);
                fp_vdec = NULL;
        }
 
        if (fp_venc) {
+               if (venc_path)
+                       free(venc_path);
                fclose(fp_venc);
                fp_venc = NULL;
        }
 
        if (fp_aenc) {
+               if (aenc_path)
+                       free(aenc_path);
                fclose(fp_aenc);
                fp_aenc = NULL;
        }
 
        if (fp_adec) {
+               if (adec_path)
+                       free(adec_path);
                fclose(fp_adec);
                fp_adec = NULL;
        }
@@ -870,7 +917,7 @@ int utc_media_mediacodec_set_venc_info_p(void)
        int ret = MEDIACODEC_ERROR_NONE;
 
        if (!_mediacodec_supported) {
-               ret = mediacodec_set_venc_info(g_media_codec, 640, 480, 30, 1000000);
+               ret = mediacodec_set_venc_info(g_media_codec, 352, 288, 30, 10000);
                assert_eq(ret, MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE);
                return 0;
        }
@@ -878,7 +925,7 @@ int utc_media_mediacodec_set_venc_info_p(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_H263, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_venc_info(g_media_codec, 640, 480, 30, 1000000);
+       ret = mediacodec_set_venc_info(g_media_codec, 352, 288, 30, 10000);
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        return 0;
@@ -968,6 +1015,8 @@ int utc_media_mediacodec_set_aenc_info_p(void)
 {
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        if (!_mediacodec_supported) {
                ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, 16, 128000);
@@ -978,7 +1027,11 @@ int utc_media_mediacodec_set_aenc_info_p(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_AAC, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, bit_depth[i], 128000);
+               if (ret == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        return 0;
@@ -1018,6 +1071,8 @@ int utc_media_mediacodec_set_adec_info_p(void)
 {
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        if (!_mediacodec_supported) {
                ret = mediacodec_set_adec_info(g_media_codec, 48000, 2, 16);
@@ -1028,7 +1083,11 @@ int utc_media_mediacodec_set_adec_info_p(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_AAC, (MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_adec_info(g_media_codec, 48000, 2, 16);
+       for (i = 0; i < 2; i++) {
+               ret = mediacodec_set_adec_info(g_media_codec, 48000, 2, bit_depth[i]);
+               if (ret == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        return 0;
@@ -1068,6 +1127,8 @@ int utc_media_mediacodec_prepare_p(void)
 {
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        if (!_mediacodec_supported) {
                ret = mediacodec_prepare(g_media_codec);
@@ -1078,7 +1139,11 @@ int utc_media_mediacodec_prepare_p(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_AAC, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, bit_depth[i], 128000);
+               if (ret == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        ret = mediacodec_prepare(g_media_codec);
@@ -1096,6 +1161,8 @@ int utc_media_mediacodec_prepare_n(void)
 {
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        if (!_mediacodec_supported) {
                ret = mediacodec_prepare(NULL);
@@ -1106,7 +1173,11 @@ int utc_media_mediacodec_prepare_n(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_AAC, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, bit_depth[i], 128000);
+               if (ret == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        ret = mediacodec_prepare(NULL);
@@ -1124,6 +1195,8 @@ int utc_media_mediacodec_unprepare_p(void)
 {
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        if (!_mediacodec_supported) {
                ret = mediacodec_unprepare(g_media_codec);
@@ -1134,7 +1207,11 @@ int utc_media_mediacodec_unprepare_p(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_AAC, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, bit_depth[i], 128000);
+               if (ret == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        ret = mediacodec_prepare(g_media_codec);
@@ -1155,6 +1232,8 @@ int utc_media_mediacodec_unprepare_n(void)
 {
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        if (!_mediacodec_supported) {
                ret = mediacodec_unprepare(NULL);
@@ -1165,7 +1244,11 @@ int utc_media_mediacodec_unprepare_n(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_AAC, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, bit_depth[i], 128000);
+               if (ret == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        ret = mediacodec_prepare(g_media_codec);
@@ -1317,7 +1400,8 @@ int utc_media_mediacodec_get_output_p(void)
        void *data = NULL;
        void *input_data = NULL;
        unsigned int data_size = 0;
-       int i;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        if (!_mediacodec_supported) {
                ret = mediacodec_get_output(g_media_codec, NULL, NULL);
@@ -1328,7 +1412,11 @@ int utc_media_mediacodec_get_output_p(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_AAC, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, 16, 128);
+       for (i = 0; i < 2; i++) {
+               ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, bit_depth[i], 128000);
+               if (ret == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        mediacodec_set_input_buffer_used_cb(g_media_codec,
@@ -1376,7 +1464,8 @@ int utc_media_mediacodec_get_output_n(void)
        void *data = NULL;
        void *input_data = NULL;
        unsigned int data_size = 0;
-       int i;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        if (!_mediacodec_supported) {
                ret = mediacodec_get_output(NULL, NULL, NULL);
@@ -1387,7 +1476,11 @@ int utc_media_mediacodec_get_output_n(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_AAC, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, 16, 128);
+       for (i = 0; i < 2; i++) {
+               ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, bit_depth[i], 128000);
+               if (ret == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        mediacodec_set_input_buffer_used_cb(g_media_codec,
@@ -1434,7 +1527,8 @@ int utc_media_mediacodec_flush_buffers_p(void)
        void *data = NULL;
        void *input_data = NULL;
        unsigned int data_size = 0;
-       int i;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        if (!_mediacodec_supported) {
                ret = mediacodec_flush_buffers(g_media_codec);
@@ -1445,7 +1539,11 @@ int utc_media_mediacodec_flush_buffers_p(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_AAC, (MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_adec_info(g_media_codec, 48000, 2, 16);
+       for (i = 0; i < 2; i++) {
+               ret = mediacodec_set_adec_info(g_media_codec, 48000, 2, bit_depth[i]);
+               if (ret == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        mediacodec_set_input_buffer_used_cb(g_media_codec,
@@ -1491,6 +1589,8 @@ int utc_media_mediacodec_flush_buffers_n(void)
 {
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
+       int bit_depth[] = { 16, 32 };
+       int i = 0;
 
        if (!_mediacodec_supported) {
                ret = mediacodec_flush_buffers(NULL);
@@ -1501,7 +1601,11 @@ int utc_media_mediacodec_flush_buffers_n(void)
        ret = mediacodec_set_codec(g_media_codec, MEDIACODEC_AAC, (MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_SW));
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
-       ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, 16, 128000);
+       for (i = 0; i < 2; i++) {
+               ret = mediacodec_set_aenc_info(g_media_codec, 48000, 2, bit_depth[i], 128000);
+               if (ret == MEDIACODEC_ERROR_NONE)
+                       break;
+       }
        assert_eq(ret, MEDIACODEC_ERROR_NONE);
 
        ret = mediacodec_prepare(g_media_codec);