[UTC][mediacodec][NonACR] Code clean up 44/280944/3
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 7 Sep 2022 04:06:35 +0000 (13:06 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 7 Sep 2022 10:28:23 +0000 (10:28 +0000)
- Update error handling to prevent crash
- Remove build warnings

Change-Id: Ic234f1674cdf0ce63253f52294311ea656c2a9fe
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
src/utc/mediacodec/tct-mediacodec-core_mobile.h
src/utc/mediacodec/tct-mediacodec-core_tizeniot.h
src/utc/mediacodec/tct-mediacodec-core_wearable.h
src/utc/mediacodec/utc-media-mediacodec.c

index d7c1efc7f219dfe08865db1caf8560d7bd8b1492..167c73fc83b81efb5397cdbff6f0b756db73d9cb 100755 (executable)
@@ -13,8 +13,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 //
-#ifndef __TCT_MEDIACODEC-NATIVE_H__
-#define __TCT_MEDIACODEC-NATIVE_H__
+#ifndef __TCT_MEDIACODEC_NATIVE_H__
+#define __TCT_MEDIACODEC_NATIVE_H__
 
 #include "testcase.h"
 #include "tct_common.h"
@@ -133,4 +133,4 @@ testcase tc_array[] = {
        {NULL, NULL}
 };
 
-#endif // __TCT_MEDIACODEC-NATIVE_H__
+#endif // __TCT_MEDIACODEC_NATIVE_H__
index d7c1efc7f219dfe08865db1caf8560d7bd8b1492..167c73fc83b81efb5397cdbff6f0b756db73d9cb 100755 (executable)
@@ -13,8 +13,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 //
-#ifndef __TCT_MEDIACODEC-NATIVE_H__
-#define __TCT_MEDIACODEC-NATIVE_H__
+#ifndef __TCT_MEDIACODEC_NATIVE_H__
+#define __TCT_MEDIACODEC_NATIVE_H__
 
 #include "testcase.h"
 #include "tct_common.h"
@@ -133,4 +133,4 @@ testcase tc_array[] = {
        {NULL, NULL}
 };
 
-#endif // __TCT_MEDIACODEC-NATIVE_H__
+#endif // __TCT_MEDIACODEC_NATIVE_H__
index d7c1efc7f219dfe08865db1caf8560d7bd8b1492..167c73fc83b81efb5397cdbff6f0b756db73d9cb 100755 (executable)
@@ -13,8 +13,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 //
-#ifndef __TCT_MEDIACODEC-NATIVE_H__
-#define __TCT_MEDIACODEC-NATIVE_H__
+#ifndef __TCT_MEDIACODEC_NATIVE_H__
+#define __TCT_MEDIACODEC_NATIVE_H__
 
 #include "testcase.h"
 #include "tct_common.h"
@@ -133,4 +133,4 @@ testcase tc_array[] = {
        {NULL, NULL}
 };
 
-#endif // __TCT_MEDIACODEC-NATIVE_H__
+#endif // __TCT_MEDIACODEC_NATIVE_H__
index 4c1fefc1bd305c706624fcb51eb20a571a7c04eb..6d44271ddfdb104ebf21d21914616738298edcd5 100755 (executable)
@@ -96,16 +96,22 @@ static void feed_vdec_data(int frame_count);
 static void feed_vdec_data2(int frame_count);
 
 static unsigned int extract_nal(FILE *fd, unsigned char* nal);
+#ifdef USE_FEED_VENC_DATA
 static unsigned int extract_yuv420(FILE *fd, unsigned char* yuv);
-static unsigned int extract_pcm ( FILE *fd, unsigned char* pcm );
+#endif
+static unsigned int extract_pcm(FILE *fd, unsigned char* pcm);
 static unsigned int extract_aacdec(FILE *fd, unsigned char* aacdata);
 
+#ifdef USE_FEED_VENC_DATA
 unsigned int extract_yuv420(FILE *fd, unsigned char* yuv)
 {
        size_t result;
        int read_size;
        unsigned char buffer[1000000];
 
+       if (fd == NULL)
+               return -1;
+
        if (feof(fd))
                return 0;
 
@@ -122,13 +128,17 @@ unsigned int extract_yuv420(FILE *fd, unsigned char* yuv)
 
        return read_size;
 }
+#endif
 
-unsigned int extract_pcm ( FILE *fd, unsigned char* pcm )
+unsigned int extract_pcm(FILE *fd, unsigned char* pcm)
 {
        size_t result;
        int read_size;
        unsigned char buffer[1000000];
 
+       if (fd == NULL)
+               return -1;
+
        if (feof(fd))
                return 0;
 
@@ -151,6 +161,9 @@ unsigned int extract_aacdec(FILE *fd, unsigned char* aacdata)
        unsigned int hader_size = ADTS_HEADER_SIZE;
        unsigned char buffer[1000000];
 
+       if (fd == NULL)
+               return -1;
+
        if (feof(fd))
                return 0;
 
@@ -183,6 +196,9 @@ unsigned int extract_nal(FILE *fd, unsigned char* nal)
        int nal_unit_type = 0;
        int init;
 
+       if (fd == NULL)
+               return -1;
+
        zero_count = 0;
        if (feof(fd))
                return -1;
@@ -270,8 +286,8 @@ static void feed_vdec_data(int frame_count)
        static guint64 pts = 0L;
        void *buf_data_ptr = NULL;
 
-       if (media_packet_create_alloc(vdec_fmt, NULL, NULL, &video_pkt) != MEDIA_PACKET_ERROR_NONE) {
-               fprintf(stderr, "media_packet_create_alloc failed\n");
+       if (media_packet_new_alloc(vdec_fmt, NULL, NULL, &video_pkt) != MEDIA_PACKET_ERROR_NONE) {
+               fprintf(stderr, "media_packet_new_alloc failed\n");
                return;
        }
 
@@ -289,9 +305,9 @@ static void feed_vdec_data(int frame_count)
         */
        read = extract_nal(fp_vdec, buf_data_ptr);
        fprintf(stderr, "real length = %d\n", read);
-       if (read == 0) {
+       if (read <= 0) {
                fprintf(stderr, "input file read failed\n");
-               media_packet_destroy(video_pkt);
+               media_packet_unref(video_pkt);
                return;
        }
 
@@ -344,9 +360,9 @@ static void feed_vdec_data2(int frame_count)
         */
        read = extract_nal(fp_vdec, buf_data_ptr);
        fprintf(stderr, "real length = %d\n", read);
-       if (read == 0) {
+       if (read <= 0) {
                fprintf(stderr, "input file read failed\n");
-               media_packet_destroy(video_pkt);
+               media_packet_unref(video_pkt);
                return;
        }
 
@@ -375,15 +391,15 @@ static void feed_vdec_data2(int frame_count)
        return;
 }
 
+#ifdef USE_FEED_VENC_DATA
 static void feed_venc_data(int frame_count)
 {
        int read = 0;
-       static guint64 pts = 0L;
        void *buf_data_ptr = NULL;
        int ret;
 
-       if (media_packet_create_alloc(venc_fmt, NULL, NULL, &video_pkt) != MEDIA_PACKET_ERROR_NONE) {
-               fprintf(stderr, "media_packet_create_alloc failed\n");
+       if (media_packet_new_alloc(venc_fmt, NULL, NULL, &video_pkt) != MEDIA_PACKET_ERROR_NONE) {
+               fprintf(stderr, "media_packet_new_alloc failed\n");
                return;
        }
 
@@ -394,7 +410,7 @@ static void feed_venc_data(int frame_count)
 
        read = extract_yuv420(fp_venc, buf_data_ptr);
        fprintf(stderr, "real length = %d\n", read);
-       if (read == 0) {
+       if (read <= 0) {
                fprintf(stderr, "input file read failed\n");
                return;
        }
@@ -413,16 +429,16 @@ static void feed_venc_data(int frame_count)
        _feed_called = TRUE;
        return;
 }
+#endif
 
 static void feed_aenc_data(int frame_count)
 {
        int read = 0;
-       static guint64 pts = 0L;
        void *buf_data_ptr = NULL;
        int ret;
 
-       if (media_packet_create_alloc(aenc_fmt, NULL, NULL, &audio_pkt) != MEDIA_PACKET_ERROR_NONE) {
-               fprintf(stderr, "media_packet_create_alloc failed\n");
+       if (media_packet_new_alloc(aenc_fmt, NULL, NULL, &audio_pkt) != MEDIA_PACKET_ERROR_NONE) {
+               fprintf(stderr, "media_packet_new_alloc failed\n");
                return;
        }
 
@@ -436,7 +452,7 @@ static void feed_aenc_data(int frame_count)
         */
        read = extract_pcm(fp_aenc, buf_data_ptr);
        fprintf(stderr, "real length = %d\n", read);
-       if (read == 0) {
+       if (read <= 0) {
                fprintf(stderr, "input file read failed\n");
                return;
        }
@@ -453,6 +469,8 @@ static void feed_aenc_data(int frame_count)
 
        /* push media packet */
        ret = mediacodec_process_input ( g_media_codec, audio_pkt, 0);
+       if (ret != MEDIACODEC_ERROR_NONE)
+               fprintf(stderr, "mediacodec_process_input failed 0x%x\n", ret);
 
        _feed_called = TRUE;
        return;
@@ -461,12 +479,11 @@ static void feed_aenc_data(int frame_count)
 static void feed_adec_data(int frame_count)
 {
        int read = 0;
-       static guint64 pts = 0L;
        void *buf_data_ptr = NULL;
        int ret;
 
-       if (media_packet_create_alloc(adec_fmt, NULL, NULL, &audio_pkt) != MEDIA_PACKET_ERROR_NONE) {
-               fprintf(stderr, "media_packet_create_alloc failed\n");
+       if (media_packet_new_alloc(adec_fmt, NULL, NULL, &audio_pkt) != MEDIA_PACKET_ERROR_NONE) {
+               fprintf(stderr, "media_packet_new_alloc failed\n");
                return;
        }
 
@@ -477,7 +494,7 @@ static void feed_adec_data(int frame_count)
 
        read = extract_aacdec(fp_adec, buf_data_ptr);
        fprintf(stderr, "real length = %d\n", read);
-       if (read == 0) {
+       if (read <= 0) {
                fprintf(stderr, "input file read failed\n");
                return;
        }
@@ -489,6 +506,8 @@ static void feed_adec_data(int frame_count)
 
        /* push media packet */
        ret = mediacodec_process_input ( g_media_codec, audio_pkt, 0);
+       if (ret != MEDIACODEC_ERROR_NONE)
+               fprintf(stderr, "mediacodec_process_input failed 0x%x\n", ret);
 
        _feed_called = TRUE;
        return;
@@ -517,7 +536,7 @@ int _mediacodec_get_output(void)
        if (_is_positive) {
                ret = mediacodec_get_output(g_media_codec, &output_buf, 0);
                assert_eq(ret, MEDIACODEC_ERROR_NONE);
-               media_packet_destroy(output_buf);
+               media_packet_unref(output_buf);
        } else {
                ret = mediacodec_get_output(NULL, &output_buf, 0);
                assert_eq(ret, MEDIACODEC_ERROR_INVALID_PARAMETER);
@@ -526,23 +545,20 @@ int _mediacodec_get_output(void)
        return 0;
 }
 
-static bool _mediacodec_empty_buffer_cb(media_packet_h pkt, void *user_data)
+static void _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 {
+       if (!_use_pool) {
+               media_packet_unref(pkt);
+       else {
                ret = media_packet_pool_release_packet(pool, pkt);
-               if (ret != MEDIA_PACKET_ERROR_NONE) {
+               if (ret != MEDIA_PACKET_ERROR_NONE)
                        fprintf(stderr, "media_packet_pool_release_packet failed");
-                       return false;
-               }
        }
-       return true;
 }
 
-static bool _mediacodec_fill_buffer_cb(media_packet_h * pkt, void *user_data)
+static void _mediacodec_fill_buffer_cb(media_packet_h * pkt, void *user_data)
 {
        fprintf(stderr, "output available callback invoked\n");
        if (pkt != NULL) {
@@ -550,33 +566,28 @@ static bool _mediacodec_fill_buffer_cb(media_packet_h * pkt, void *user_data)
        }
 
        _fillbufferCB_called = true;
-       return true;
 }
 
-static bool _mediacodec_eos_cb(void *user_data)
+static void _mediacodec_eos_cb(void *user_data)
 {
        fprintf(stderr, "eos callback invoked!\n");
        _eosCB_called = true;
-       return true;
 }
 
-static bool fill_cb(media_packet_h * pkt, void *user_data)
+static void fill_cb(media_packet_h pkt, void *user_data)
 {
        g_print("fill_cb is called\n");
-       return true;
 }
 
-static bool error_cb(mediacodec_error_e error, void *user_data)
+static void error_cb(mediacodec_error_e error, void *user_data)
 {
        g_print("error_cb is called\n");
        _errorCB_called = true;
-       return true;
 }
 
-static bool eos_cb(void *user_data)
+static void eos_cb(void *user_data)
 {
        g_print("eos_cb is called\n");
-       return true;
 }
 
 static bool _mcdiacodec_supported_cb(mediacodec_codec_type_e type, void *user_data)
@@ -586,10 +597,9 @@ static bool _mcdiacodec_supported_cb(mediacodec_codec_type_e type, void *user_da
        return true;
 }
 
-static bool _mediacodec_buffer_status_cb(mediacodec_status_e status, void *user_data)
+static void _mediacodec_buffer_status_cb(mediacodec_status_e status, void *user_data)
 {
        g_print("_mediacodec_buffer_status_cb is called\n");
-       return true;
 }
 
 /**
@@ -601,7 +611,6 @@ static bool _mediacodec_buffer_status_cb(mediacodec_status_e status, void *user_
 void utc_media_mediacodec_startup(void)
 {
        int ret = 0;
-       int i;
 
        char pszValue[CONFIG_VALUE_LEN_MAX] = {0,};
        system_info_get_platform_bool("http://tizen.org/feature/multimedia.media_codec", &_mediacodec_supported);
@@ -645,26 +654,26 @@ void utc_media_mediacodec_startup(void)
                }
 
                snprintf(adec_path, size_of_path, "%s/res/%s", pszValue, adec_file);
-       }
-       else
-       {
-               PRINT_UTC_LOG("[Line : %d][%s] GetValueForTCTSetting returned error for 'DEVICE_SUITE_TARGET_30'\\n", __LINE__, API_NAMESPACE);
-       }
 
-       if ( (fp_vdec = fopen(vdec_path, "r")) == -1 ) {
-               fprintf(stderr, "File %s not exist\n", vdec_path);
-       }
+               fp_vdec = fopen(vdec_path, "r");
+               if (fp_vdec == NULL)
+                       fprintf(stderr, "File %s not exist\n", vdec_path);
 
-       if ( (fp_venc = fopen(venc_path, "r")) == -1 ) {
-               fprintf(stderr, "File %s not exist\n", venc_path);
-       }
+               fp_venc = fopen(venc_path, "r");
+               if (fp_venc == NULL)
+                       fprintf(stderr, "File %s not exist\n", venc_path);
 
-       if ( (fp_adec = fopen(adec_path, "r")) == -1 ) {
-               fprintf(stderr, "File %s not exist\n", adec_path);
-       }
+               fp_adec = fopen(adec_path, "r");
+               if (fp_adec == NULL)
+                       fprintf(stderr, "File %s not exist\n", adec_path);
 
-       if ( (fp_aenc = fopen(aenc_path, "r")) == -1 ) {
-               fprintf(stderr, "File %s not exist\n", aenc_path);
+               fp_aenc = fopen(aenc_path, "r");
+               if (fp_aenc == NULL)
+                       fprintf(stderr, "File %s not exist\n", aenc_path);
+       }
+       else
+       {
+               PRINT_UTC_LOG("[Line : %d][%s] GetValueForTCTSetting returned error for 'DEVICE_SUITE_TARGET_30'\\n", __LINE__, API_NAMESPACE);
        }
 
        ret = mediacodec_create(&g_media_codec);
@@ -729,7 +738,6 @@ void utc_media_mediacodec_startup(void)
  */
 void utc_media_mediacodec_cleanup(void)
 {
-       int i;
        int ret;
 
        if (aenc_fmt)
@@ -767,32 +775,44 @@ void utc_media_mediacodec_cleanup(void)
        }
 
        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;
        }
+
+       if (vdec_path) {
+               free(vdec_path);
+               vdec_path = NULL;
+       }
+
+       if (venc_path) {
+               free(venc_path);
+               venc_path = NULL;
+       }
+
+       if (aenc_path) {
+               free(aenc_path);
+               aenc_path = NULL;
+       }
+
+       if (adec_path) {
+               free(adec_path);
+               adec_path = NULL;
+       }
 }
 
 /**
@@ -1270,12 +1290,8 @@ int utc_media_mediacodec_process_input_p(void)
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
 
-       void *data = NULL;
-       unsigned int data_size = 0;
-       int i = 0;
-
        if (!_mediacodec_supported) {
-               ret = mediacodec_process_input(g_media_codec, NULL, NULL);
+               ret = mediacodec_process_input(g_media_codec, NULL, 0);
                assert_eq(ret, MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE);
                return 0;
        }
@@ -1332,12 +1348,8 @@ int utc_media_mediacodec_process_input_n(void)
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
 
-       void *data = NULL;
-       unsigned int data_size = 0;
-       int i = 0;
-
        if (!_mediacodec_supported) {
-               ret = mediacodec_process_input(NULL, NULL, NULL);
+               ret = mediacodec_process_input(NULL, NULL, 0);
                assert_eq(ret, MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE);
                return 0;
        }
@@ -1396,15 +1408,11 @@ int utc_media_mediacodec_get_output_p(void)
 {
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
-
-       void *data = NULL;
-       void *input_data = NULL;
-       unsigned int data_size = 0;
        int bit_depth[] = { 16, 32 };
        int i = 0;
 
        if (!_mediacodec_supported) {
-               ret = mediacodec_get_output(g_media_codec, NULL, NULL);
+               ret = mediacodec_get_output(g_media_codec, NULL, 0);
                assert_eq(ret, MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE);
                return 0;
        }
@@ -1460,15 +1468,11 @@ int utc_media_mediacodec_get_output_n(void)
 {
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
-
-       void *data = NULL;
-       void *input_data = NULL;
-       unsigned int data_size = 0;
        int bit_depth[] = { 16, 32 };
        int i = 0;
 
        if (!_mediacodec_supported) {
-               ret = mediacodec_get_output(NULL, NULL, NULL);
+               ret = mediacodec_get_output(NULL, NULL, 0);
                assert_eq(ret, MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE);
                return 0;
        }
@@ -1523,10 +1527,6 @@ int utc_media_mediacodec_flush_buffers_p(void)
 {
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
-
-       void *data = NULL;
-       void *input_data = NULL;
-       unsigned int data_size = 0;
        int bit_depth[] = { 16, 32 };
        int i = 0;
 
@@ -1627,10 +1627,6 @@ int utc_mediacodec_set_input_buffer_used_cb_p(void)
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
 
-       int i;
-       void *data = NULL;
-       unsigned int data_size = 0;
-
        if (!_mediacodec_supported) {
                ret = mediacodec_set_input_buffer_used_cb(g_media_codec,
                        (mediacodec_input_buffer_used_cb)_mediacodec_empty_buffer_cb,
@@ -2142,10 +2138,6 @@ int utc_mediacodec_get_packet_pool_p(void)
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
 
-       void *data = NULL;
-       unsigned int data_size = 0;
-       int i = 0;
-
        if (!_mediacodec_supported) {
                ret = mediacodec_get_packet_pool(g_media_codec, &pool);
                assert_eq(ret, MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE);
@@ -2207,9 +2199,6 @@ int utc_mediacodec_get_packet_pool_n(void)
        assert(!_is_broken);
        int ret = MEDIACODEC_ERROR_NONE;
 
-       void *data = NULL;
-       unsigned int data_size = 0;
-
        if (!_mediacodec_supported) {
                ret = mediacodec_get_packet_pool(NULL, &pool);
                assert_eq(ret, MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE);