fixed coverity issues 19/155019/3 accepted/tizen/unified/20171013.193212 submit/tizen/20171013.040928
authorSejun Park <sejun79.park@samsung.com>
Thu, 12 Oct 2017 01:54:49 +0000 (10:54 +0900)
committerSejun Park <sejun79.park@samsung.com>
Thu, 12 Oct 2017 02:36:07 +0000 (11:36 +0900)
Change-Id: Id8fbe562674bf38057cee10d50870516b4be7b05

include/media_codec_bitstream.h
include/media_codec_port.h
include/media_codec_private.h
src/media_codec_bitstream.c
src/media_codec_port.c
src/media_codec_port_gst.c
test/media_codec_test.c

index 2898146..416c9b3 100644 (file)
@@ -18,7 +18,7 @@
 #define __TIZEN_MEDIA_CODEC_BITSTREAM_H__
 
 #include <tizen.h>
-#include <media_codec_port.h>
+#include <media_codec_private.h>
 
 typedef struct _mc_bitstream_t mc_bitstream_t;
 
index f704059..f1c3fca 100644 (file)
@@ -288,8 +288,8 @@ void _mc_create_codec_map_from_ini_static(mc_ini_t *ini, mc_codec_spec_t *spec_e
 void _mc_create_decoder_map_from_ini(mc_handle_t *mc_handle);
 void _mc_create_encoder_map_from_ini(mc_handle_t *mc_handle);
 
-const int simple_to_codec_type_enumeration(codec_type_e codec_id);
-const int codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id);
+const codec_type_e simple_to_codec_type_enumeration(codec_type_e codec_id);
+const codec_type_e codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id);
 
 #ifdef __cplusplus
 }
index dc5d663..6f50a49 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <tizen.h>
 #include <stdint.h>
+#include <glib.h>
 
 #include <media_codec.h>
 
index 373da79..da6d3b7 100644 (file)
@@ -162,7 +162,7 @@ unsigned int __mc_bytestream_to_nal(unsigned char *data, int size)
 
 int __mc_decode_sps(mc_bitstream_t *pstream, int *width, int *height)
 {
-       int ret = MC_ERROR_NONE;
+       int ret = 0;
        unsigned int tmp = 0;
 
        int profile_idc = 0;
@@ -177,7 +177,7 @@ int __mc_decode_sps(mc_bitstream_t *pstream, int *width, int *height)
        profile_idc = tmp;
 
        if (profile_idc > 51)
-               ret = MC_INVALID_IN_BUF;
+               ret = -1;
 
        /*TODO parse width, height, etc...*/
 
@@ -220,7 +220,7 @@ int _mc_check_h264_bytestream(unsigned char *nal, int byte_length, bool port, bo
                        switch (syntax & 0x1F) {
                        case NAL_SEQUENCE_PARAMETER_SET:
                                LOGD("nal_unit_type : SPS");
-                               if ((ret = __mc_decode_sps(&pstream, NULL, NULL)) != MC_ERROR_NONE)
+                               if ((ret = __mc_decode_sps(&pstream, NULL, NULL)) != -1)
                                        return ret;
                                state |= MC_EXIST_SPS;
                                codec_length += nal_length;
@@ -264,7 +264,7 @@ int _mc_check_h264_bytestream(unsigned char *nal, int byte_length, bool port, bo
 
        /* input port */
        if (!port && !CHECK_VALID_PACKET(state, MC_VALID_FIRST_SLICE))
-               return MC_INVALID_IN_BUF;
+               return -1;
 
        /* output port */
        if (port) {
@@ -289,9 +289,9 @@ int _mc_check_valid_h263_frame(unsigned char *p, int size)
        } while (count == 1 && p < end);
 
        if (count != 1)
-               return MC_INVALID_IN_BUF; /* frame boundary violated */
+               return -1; /* frame boundary violated */
 
-       return MC_ERROR_NONE;
+       return 0;
 }
 
 bool _mc_is_voss(unsigned char *buf, int size, int *codec_size)
@@ -352,8 +352,6 @@ bool _mc_is_vop(unsigned char *p, int size, int pos)
 int _mc_check_mpeg4_out_bytestream(unsigned char *buf, int buf_length, bool* need_codec_data, bool *need_sync_flag)
 {
        int codec_data_size = 0;
-       g_return_val_if_fail(need_codec_data != NULL, MC_PARAM_ERROR);
-       g_return_val_if_fail(need_sync_flag != NULL, MC_PARAM_ERROR);
 
        *need_codec_data = FALSE;
        *need_sync_flag = FALSE;
@@ -368,8 +366,6 @@ int _mc_check_mpeg4_out_bytestream(unsigned char *buf, int buf_length, bool* nee
 
 bool _mc_check_h263_out_bytestream(unsigned char *p, int buf_length, bool* need_sync_flag)
 {
-       g_return_val_if_fail(need_sync_flag != NULL, MC_PARAM_ERROR);
-
        *need_sync_flag = FALSE;
 
        /* PSC not present */
@@ -402,7 +398,7 @@ int _mc_get_h264_codecdata_size(guint8 *data, int size)
                data_size = _mc_check_h264_bytestream(data, size, 0, NULL, NULL, NULL);
                if (data_size <= 0) {
                        LOGE("No valid SPS/PPS ...");
-                       return MC_INVALID_IN_BUF;
+                       return -1;
                }
                return data_size;
        } else {
@@ -417,12 +413,12 @@ int _mc_get_h264_codecdata_size(guint8 *data, int size)
                /* parse the avcC data */
                if (size < 7) { /* when numSPS==0 and numPPS==0, length is 7 bytes */
                        LOGE("If contains codec_data, size should over 7 bytes ...");
-                       return MC_INVALID_IN_BUF;
+                       return -1;
                }
                /* parse the version, this must be 1 */
                if (data[0] != 1) {
                        LOGE("If contains codec_data, first byte must be 1 ...");
-                       return MC_INVALID_IN_BUF;
+                       return -1;
                }
 
                num_sps = data[5] & 0x1f;
@@ -451,7 +447,7 @@ int _mc_get_h264_codecdata_size(guint8 *data, int size)
                        return offset;
                }
 
-               return MC_INVALID_IN_BUF;
+               return -1;
        }
 
 }
index 238c492..3584dd5 100644 (file)
@@ -79,7 +79,7 @@ int mc_create(MMHandleType *mediacodec)
        return ret;
 
 ERROR:
-
+       g_free(new_mediacodec);
        return MC_INVALID_ARG;
 }
 
@@ -798,18 +798,18 @@ int _mediacodec_foreach_supported_codec(mediacodec_supported_codec_cb callback,
 {
        int ret = MEDIACODEC_NONE;
        int i;
-       int index = 0;
+       int index;
 
        gboolean codec[CODEC_NR_ITEMS] = {0,};
 
        for (i = 0; i < mc_ini.num_supported_codecs; i++) {
-               index = codec_type_to_simple_enumeration(spec_emul[i].codec_id);
+               index = (int)codec_type_to_simple_enumeration(spec_emul[i].codec_id);
                codec[index] = TRUE;
        }
 
        for (i = 0; i < CODEC_NR_ITEMS; i++) {
                if (codec[i]) {
-                       index = simple_to_codec_type_enumeration(i);
+                       index = (int)simple_to_codec_type_enumeration(i);
                        if (!callback(index, user_data))
                                goto CALLBACK_ERROR;
                }
@@ -988,7 +988,7 @@ void _mc_create_codec_map_from_ini_static(mc_ini_t *ini, mc_codec_spec_t *spec_e
        return;
 }
 
-const int codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id)
+const codec_type_e codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id)
 {
        guint media_codec_id_u = (guint)media_codec_id;
 
@@ -1052,7 +1052,7 @@ const int codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_i
        }
 }
 
-const int simple_to_codec_type_enumeration(codec_type_e codec_id)
+const codec_type_e simple_to_codec_type_enumeration(codec_type_e codec_id)
 {
        guint codec_id_u = (guint)codec_id;
 
index 50a24b6..5bf33cf 100644 (file)
@@ -14,7 +14,6 @@
  * limitations under the License.
  *
  */
-#include <glib.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -516,6 +515,7 @@ int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int siz
        ret = media_packet_create_from_external_memory(core->output_fmt, ext_mem, mem_size, __mc_output_buffer_finalize_cb, mcbuffer, &packet);
        if (ret != MEDIA_PACKET_ERROR_NONE) {
                LOGW("media_packet_create_alloc failed");
+               g_free(ext_mem);
                return MC_ERROR;
        }
        mcbuffer->packet = packet;
@@ -536,6 +536,7 @@ int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, in
        bool slice = FALSE;
        gint mem_size = 0;
        gchar *ext_mem = NULL;
+       gint data_size = 0;
        void *packet_data = NULL;
        media_packet_h packet = NULL;
 
@@ -545,7 +546,12 @@ int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, in
        case MEDIA_FORMAT_H264_SP:
        case MEDIA_FORMAT_H264_MP:
        case MEDIA_FORMAT_H264_HP:
-               ret = _mc_check_h264_bytestream((unsigned char *)data, size, 1, &codec_config, &sync_flag, &slice);
+               data_size = _mc_check_h264_bytestream((unsigned char *)data, size, 1, &codec_config, &sync_flag, &slice);
+
+               if (data_size <= 0) {
+                       LOGE("No valid SPS/PPS ...");
+                       return MC_INVALID_IN_BUF;
+               }
                break;
        case MEDIA_FORMAT_MPEG4_SP:
        case MEDIA_FORMAT_MPEG4_ASP:
@@ -567,6 +573,7 @@ int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, in
        ret = media_packet_create_from_external_memory(core->output_fmt, ext_mem, mem_size, __mc_output_buffer_finalize_cb, mcbuffer, &packet);
        if (ret != MEDIA_PACKET_ERROR_NONE) {
                LOGW("media_packet_create_alloc failed");
+               g_free(ext_mem);
                return MC_ERROR;
        }
        mcbuffer->packet = packet;
@@ -607,6 +614,7 @@ int __mc_fill_aenc_packet_with_output_buffer(mc_gst_core_t *core, void *data, in
        ret = media_packet_create_from_external_memory(core->output_fmt, ext_mem, mem_size, __mc_output_buffer_finalize_cb, mcbuffer, &packet);
        if (ret != MEDIA_PACKET_ERROR_NONE) {
                LOGW("media_packet_create_alloc failed");
+               g_free(ext_mem);
                return MC_ERROR;
        }
        mcbuffer->packet = packet;
@@ -641,7 +649,12 @@ int __mc_fill_aenc_packet_with_output_buffer(mc_gst_core_t *core, void *data, in
                gst_buffer_map(core->codec_data, &map, GST_MAP_READ);
                ptr = map.data;
                len = map.size;
-               media_packet_set_codec_data(packet, ptr, len);
+               ret = media_packet_set_codec_data(packet, ptr, len);
+               if (ret != MEDIA_PACKET_ERROR_NONE) {
+                       LOGW("media_packet_set_codec_data failed");
+                       gst_buffer_unmap(core->codec_data, &map);
+                       return MC_ERROR;
+               }
                gst_buffer_unmap(core->codec_data, &map);
        }
 
index a542c46..5b592f5 100644 (file)
@@ -832,8 +832,6 @@ void _mediacodec_process_input(App *app)
        media_packet_h pkt = NULL;
        guint8 *tmp;
        gint read;
-       gint size;
-       gint offset;
        gint stride_width;
        gboolean codec_config = FALSE;
 
@@ -869,7 +867,6 @@ void _mediacodec_process_input(App *app)
                                /* Y */
                                media_packet_get_video_plane_data_ptr(pkt, 0, (void **)&buf_data_ptr);
                                media_packet_get_video_stride_width(pkt, 0, &stride_width);
-                               offset = app->width*app->height;
 
                                for (j = 0; j < app->height; j++) {
                                        memcpy(buf_data_ptr, tmp, app->width);
@@ -880,7 +877,6 @@ void _mediacodec_process_input(App *app)
                                if (app->hardware == TRUE) {
                                        media_packet_get_video_plane_data_ptr(pkt, 1, (void **)&buf_data_ptr);
                                        media_packet_get_video_stride_width(pkt, 1, &stride_width);
-                                       size = app->width * app->height / 2;
 
                                        for (j = 0; j < app->height / 2; j++) {
                                                memcpy(buf_data_ptr, tmp, app->width);
@@ -891,7 +887,6 @@ void _mediacodec_process_input(App *app)
                                        /* U */
                                        media_packet_get_video_plane_data_ptr(pkt, 1, (void **)&buf_data_ptr);
                                        media_packet_get_video_stride_width(pkt, 1, &stride_width);
-                                       size = (app->width>>1) * (app->height>>1);
 
                                        for (j = 0; j < app->height/2; j++) {
                                                memcpy(buf_data_ptr, tmp, app->width/2);
@@ -902,7 +897,6 @@ void _mediacodec_process_input(App *app)
                                        /* V */
                                        media_packet_get_video_plane_data_ptr(pkt, 2, (void **)&buf_data_ptr);
                                        media_packet_get_video_stride_width(pkt, 2, &stride_width);
-                                       offset += size;
 
                                        for (j = 0; j < app->height/2; j++) {
                                                memcpy(buf_data_ptr, tmp, app->width/2);
@@ -935,8 +929,6 @@ gboolean read_data(App *app)
        guint8 *tmp;
        gint i;
        gint read;
-       gint size;
-       gint offset;
        gint stride_width;
 
        if (app->offset == 0) {
@@ -990,7 +982,6 @@ gboolean read_data(App *app)
                        /* Y */
                        media_packet_get_video_plane_data_ptr(pkt, 0, (void **)&buf_data_ptr);
                        media_packet_get_video_stride_width(pkt, 0, &stride_width);
-                       offset = app->width*app->height;
 
                        for (i = 0; i < app->height; i++) {
                                memcpy(buf_data_ptr, tmp, app->width);
@@ -1001,7 +992,6 @@ gboolean read_data(App *app)
                        if (app->hardware == TRUE) {
                                media_packet_get_video_plane_data_ptr(pkt, 1, (void **)&buf_data_ptr);
                                media_packet_get_video_stride_width(pkt, 1, &stride_width);
-                               size = app->width * app->height>>1;
 
                                for (i = 0; i < app->height>>1; i++) {
                                        memcpy(buf_data_ptr, tmp, app->width);
@@ -1013,7 +1003,6 @@ gboolean read_data(App *app)
                                /* U */
                                media_packet_get_video_plane_data_ptr(pkt, 1, (void **)&buf_data_ptr);
                                media_packet_get_video_stride_width(pkt, 1, &stride_width);
-                               size = (app->width>>1) * (app->height>>1);
 
                                for (i = 0; i < app->height/2; i++) {
                                        memcpy(buf_data_ptr, tmp, app->width>>1);
@@ -1024,7 +1013,6 @@ gboolean read_data(App *app)
                                /* V */
                                media_packet_get_video_plane_data_ptr(pkt, 2, (void **)&buf_data_ptr);
                                media_packet_get_video_stride_width(pkt, 2, &stride_width);
-                               offset += size;
 
                                for (i = 0; i < app->height/2; i++) {
                                        memcpy(buf_data_ptr, tmp, app->width>>1);
@@ -2359,7 +2347,7 @@ void decoder_output_dump(App *app, media_packet_h pkt)
        guint8 *temp;
        int i = 0;
        int stride_width, stride_height;
-       gchar filename[100] = {0};
+       gchar filename[256] = {0, };
        FILE *fp = NULL;
        int ret = 0;
 
@@ -2445,7 +2433,7 @@ void output_dump(App *app, media_packet_h pkt)
 {
        void *temp;
        uint64_t buf_size;
-       gchar filename[100] = {0};
+       gchar filename[256] = {0, };
        FILE *fp = NULL;
        int ret = 0;
        char adts[100] = {0, };
@@ -2537,7 +2525,6 @@ const char* codec_type_to_string(mediacodec_codec_type_e media_codec_id)
        default:
                return "NONE";
        }
-       return "NONE";
 }
 
 int main(int argc, char *argv[])