[1.0.28] Fix more cppcheck defects 59/297259/5 accepted/tizen/8.0/unified/20231005.092747 accepted/tizen/unified/20230821.162315 tizen_8.0_m2_release
authorSeungbae Shin <seungbae.shin@samsung.com>
Wed, 16 Aug 2023 04:24:35 +0000 (13:24 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 17 Aug 2023 12:07:22 +0000 (21:07 +0900)
- style: C-style pointer casting [cstyleCast]
- style: Parameter 'item' can be declared as reference to const [constParameterReference]
- performance: Function parameter 'mime' should be passed by const reference. [passedByValue]
- performance: Variable '_dirPath' is assigned in constructor body.
               Consider performing initialization in initialization list. [useInitializationList]
- style: The scope of the variable 'ipAddr' can be reduced. [variableScope]
- style: The scope of the variable 'portNum' can be reduced. [variableScope]
- style: inconclusive: Technically the member function 'EsStreamReader::getMediaFormat' can be const. [functionConst]

In addition, a little minor refactoring of MediaTransporterSenderRtsp::startRtspServer()

Change-Id: Ie4d2bfa4275b57947a768c60381bd2dc74985a5d

include/MediaTransporterSenderRtsp.h
packaging/capi-media-transporter.spec
src/MediaTransporterConnectionStats.cpp
src/MediaTransporterGst.cpp
src/MediaTransporterParseIni.cpp
src/MediaTransporterReceiver.cpp
src/MediaTransporterSenderRtsp.cpp
src/MediaTransporterSenderSrt.cpp
unittest/ut_es_reader.hpp

index 7e7eed3..1d44071 100644 (file)
@@ -20,6 +20,7 @@
 #ifdef __cplusplus
 
 #include <string>
+#include <tuple>
 #include <gst/rtsp-server/rtsp-server.h>
 #include <gst/rtsp-server/rtsp-media-factory-mtpr.h>
 
@@ -59,6 +60,8 @@ private:
        void postMsgOnIdle(GstMessage* message);
        void removeIdleEventSource();
 
+       std::tuple<std::string, std::string, std::string> parseAddress() const;
+
        struct idleData {
                void* handle;
                mtpr_error_e error;
index 0d5a0bc..d3a0adf 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-transporter
 Summary:    A Media Transporter library in Tizen Native API
-Version:    1.0.27
+Version:    1.0.28
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 46964ca..dfaf884 100644 (file)
@@ -219,7 +219,7 @@ void SenderSrtConnectionStats::foreach()
 
                LOG_DEBUG("SENDER >>> num of callers : %d", callers->n_values);
                for (int i = 0; i < (int)callers->n_values; i++) {
-                       const GstStructure* callerStats = (GstStructure *)g_value_get_boxed(&callers->values[i]);
+                       const GstStructure* callerStats = static_cast<GstStructure *>(g_value_get_boxed(&callers->values[i]));
 
                        LOG_DEBUG("SENDER >>> caller idx : %d", i);
                        ret = gst_structure_foreach(callerStats, _statsForeachCb, &userdata);
index 2d66acc..082bace 100644 (file)
@@ -219,13 +219,13 @@ static void __parse_type_and_set_value(GType type, GstElement* element, gchar**
        case G_TYPE_INT:
        case G_TYPE_INT64:
        case G_TYPE_ENUM: {
-               gint64 value = g_ascii_strtoll((const gchar*)key_value_pair[1], NULL, 10);
+               gint64 value = g_ascii_strtoll(static_cast<const gchar*>(key_value_pair[1]), NULL, 10);
                g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
                break;
        }
        case G_TYPE_UINT:
        case G_TYPE_UINT64: {
-               guint64 value = g_ascii_strtoll((const gchar*)key_value_pair[1], NULL, 10);
+               guint64 value = g_ascii_strtoll(static_cast<const gchar*>(key_value_pair[1]), NULL, 10);
                g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
                break;
        }
@@ -235,7 +235,7 @@ static void __parse_type_and_set_value(GType type, GstElement* element, gchar**
                  "1", "yes", "on", "true", "TRUE", NULL
                };
 
-               if (g_strv_contains (true_names, (const gchar*)key_value_pair[1]))
+               if (g_strv_contains (true_names, static_cast<const gchar*>(key_value_pair[1])))
                  value = TRUE;
 
                g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
@@ -243,13 +243,13 @@ static void __parse_type_and_set_value(GType type, GstElement* element, gchar**
        }
        case G_TYPE_FLOAT:
        case G_TYPE_DOUBLE: {
-               gdouble value = g_ascii_strtod((const gchar*)key_value_pair[1], NULL);
+               gdouble value = g_ascii_strtod(static_cast<const gchar*>(key_value_pair[1]), NULL);
                g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
                break;
        }
        default:
                LOG_DEBUG("not supported type(0x%x) exactly, but try it with int64 type", (unsigned int)type); /* e.g.) custom enum type falls through here */
-               gint64 value = g_ascii_strtoll((const gchar*)key_value_pair[1], NULL, 10);
+               gint64 value = g_ascii_strtoll(static_cast<const gchar*>(key_value_pair[1]), NULL, 10);
                g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
                break;
        }
index 4c43e24..3181fd4 100644 (file)
@@ -34,7 +34,7 @@ static void dumpItem(const char* prefix_str, int item)
        LOG_INFO("- %-19s = %d", prefix_str, item);
 }
 
-static void dumpItem(const char* prefix_str, std::string& item)
+static void dumpItem(const char* prefix_str, const std::string& item)
 {
        LOG_INFO("- %-19s = %s", prefix_str, item.c_str());
 }
index 041c1a7..cc768d2 100644 (file)
@@ -69,7 +69,7 @@ void MediaTransporterReceiver::unsetAudioPacketCallback()
        _audioCallback._callback = nullptr;
 }
 
-static media_format_mimetype_e _getMediaFormatMimeType(std::string mime)
+static media_format_mimetype_e _getMediaFormatMimeType(const std::string& mime)
 {
        if (mime.find(gst::MEDIA_TYPE_AUDIO_AAC) != std::string::npos)
                return MEDIA_FORMAT_AAC;
@@ -237,7 +237,7 @@ media_packet_h MediaTransporterReceiver::_makeMediaPacket(GstBuffer* buffer, Gst
 
        /* FIXME: We put the gstbuffer to extra field of media packet. It does not guarantee the validity of the gstbuffer
         * after destroying this media packet. Currently, the gstbuffer must be used before destroying the packet. */
-       ret |= media_packet_set_extra(packet, (void*)buffer);
+       ret |= media_packet_set_extra(packet, static_cast<void*>(buffer));
        if (ret != MEDIA_PACKET_ERROR_NONE) {
                LOG_ERROR("failed to media_packet_set_*()");
                goto ERROR;
index 67f5c31..5d7dff8 100644 (file)
@@ -30,8 +30,8 @@ using namespace tizen_media_transporter;
 static GstRTSPFilterResult
 __clientFilter(GstRTSPServer* server, GstRTSPClient* client, gpointer userData)
 {
-  /* Simple filter that shuts down all clients. */
-  return GST_RTSP_FILTER_REMOVE;
+       /* Simple filter that shuts down all clients. */
+       return GST_RTSP_FILTER_REMOVE;
 }
 
 MediaTransporterSenderRtsp::MediaTransporterSenderRtsp()
@@ -110,56 +110,56 @@ void MediaTransporterSenderRtsp::setSenderAddress(std::string address)
        _senderAddress = address; // rtsp server addr
 }
 
+std::tuple<std::string, std::string, std::string> MediaTransporterSenderRtsp::parseAddress() const
+{
+       /* address format "rtsp://{ip address}:{port number}/{mount_point}" */
+       std::string address = util::removeProtocolPrefix(_senderAddress, "rtsp");
+
+       if ((address.find(ADDR_PORT_DELIM) == std::string::npos) &&
+               (address.find(ADDR_PATH_DELIM) == std::string::npos)) {
+               SECURE_LOG_ERROR("invalid address %s", address.c_str());
+               throw MediaTransporterException(MTPR_ERROR_INVALID_OPERATION, "invalid sender address");
+       }
+
+       auto portPos = address.find(ADDR_PORT_DELIM);
+       std::string ipAddr = address.substr(0, portPos++);
+       auto mountPos = address.find(ADDR_PATH_DELIM);
+
+       return {
+               ipAddr, address.substr(portPos, mountPos - portPos), address.substr(mountPos)
+       };
+}
+
 void MediaTransporterSenderRtsp::startRtspServer()
 {
-       GstRTSPMountPoints* mounts = NULL;
-       GstRTSPMediaFactoryMTPR* factoryMtpr = NULL;
-       GstRTSPServer* server = NULL;
-       std::string rtspPrefix("rtsp://");
-       std::string address;
-       std::string ipAddr;
-       std::string portNum;
+       GstRTSPServer* server = gst_rtsp_server_new();
+       if (!server) {
+               LOG_ERROR("Failed to create rtsp server");
+               throw MediaTransporterException(MTPR_ERROR_INVALID_OPERATION, "failed to create rtsp server");
+       }
+
        std::string mountPoint;
 
        try {
-               server = gst_rtsp_server_new();
-               if (!server) {
-                       LOG_ERROR("Failed to create rtsp server");
-                       throw MediaTransporterException(MTPR_ERROR_INVALID_OPERATION, "failed to create rtsp server");
-               }
-
-               /* address format "rtsp://{ip address}:{port number}/{mount_point}" */
-               address = util::removeProtocolPrefix(_senderAddress, "rtsp");
-
-               if ((address.find(ADDR_PORT_DELIM) == std::string::npos) &&
-                               (address.find(ADDR_PATH_DELIM) == std::string::npos)) {
-                       SECURE_LOG_ERROR("invalid address %s", address.c_str());
-                       throw MediaTransporterException(MTPR_ERROR_INVALID_OPERATION, "invalid sender address");
-               }
+               std::string ipAddr, portNum;
 
-               auto portPos = address.find(ADDR_PORT_DELIM);
-               ipAddr = address.substr(0, portPos);
-               auto mountPos = address.find(ADDR_PATH_DELIM);
-               portPos++;
-               portNum = address.substr(portPos, mountPos - portPos);
-               mountPoint = address.substr(mountPos);
+               std::tie(ipAddr, portNum, mountPoint) = parseAddress();
 
                gst_rtsp_server_set_address(GST_RTSP_SERVER(server), ipAddr.c_str());
                gst_rtsp_server_set_service(GST_RTSP_SERVER(server), portNum.c_str());
-
                g_signal_connect(server, "client-connected", G_CALLBACK(_clientConnectedCb), NULL);
 
-               mounts = gst_rtsp_server_get_mount_points(server);
-               factoryMtpr = gst_rtsp_media_factory_mtpr_new();
-               gst_object_ref(_gst.pipeline);
-               gst_rtsp_media_factory_mtpr_set_custom_element(factoryMtpr, GST_ELEMENT(_gst.pipeline));
+               GstRTSPMountPoints* mounts = gst_rtsp_server_get_mount_points(server);
+
+               GstRTSPMediaFactoryMTPR* factoryMtpr = gst_rtsp_media_factory_mtpr_new();
+               gst_rtsp_media_factory_mtpr_set_custom_element(factoryMtpr, GST_ELEMENT(gst_object_ref(_gst.pipeline)));
                gst::_generateDot(_gst.pipeline, "rtsp-sender");
+               g_signal_connect(GST_RTSP_MEDIA_FACTORY(factoryMtpr), "media-constructed", G_CALLBACK(_mediaConstructedCb), this);
+               g_signal_connect(GST_RTSP_MEDIA_FACTORY(factoryMtpr), "media-configure", G_CALLBACK(_mediaConfigureCb), this);
 
                gst_rtsp_mount_points_add_factory(mounts, mountPoint.c_str(), GST_RTSP_MEDIA_FACTORY(factoryMtpr));
-               g_object_unref(mounts);
 
-               g_signal_connect(GST_RTSP_MEDIA_FACTORY(factoryMtpr), "media-constructed", G_CALLBACK(_mediaConstructedCb), this);
-               g_signal_connect(GST_RTSP_MEDIA_FACTORY(factoryMtpr), "media-configure", G_CALLBACK(_mediaConfigureCb), this);
+               g_object_unref(mounts);
 
                if ((_sourceId = gst_rtsp_server_attach(server, NULL)) == 0) {
                        LOG_ERROR("failed to attach server to default context");
@@ -170,14 +170,15 @@ void MediaTransporterSenderRtsp::startRtspServer()
 
                _rtspServer = static_cast<void*>(server);
                _rtspMountPoint = mountPoint;
+
        } catch (const MediaTransporterException& e) {
                LOG_ERROR("%s", e.what());
-               if (server) {
-                       mounts = gst_rtsp_server_get_mount_points(server);
-                       gst_rtsp_mount_points_remove_factory(mounts, mountPoint.c_str());
-                       g_object_unref(mounts);
-                       gst_object_unref(server);
-               }
+
+               GstRTSPMountPoints* mounts = gst_rtsp_server_get_mount_points(server);
+               gst_rtsp_mount_points_remove_factory(mounts, mountPoint.c_str());
+               g_object_unref(mounts);
+
+               gst_object_unref(server);
                throw;
        }
 }
@@ -334,7 +335,7 @@ void MediaTransporterSenderRtsp::postMsgOnIdle(GstMessage* message)
        RET_IF(!message, "message is NULL");
 
        idleData* data = g_new0(idleData, 1);
-       data->handle = (void *)this;
+       data->handle = static_cast<void *>(this);
        data->error = MTPR_ERROR_INVALID_OPERATION; /* FIXME: error code could be different depends on the message */
 
        std::lock_guard<std::mutex> mutex(_idleEventMutex);
index 80c815c..d51c4ea 100644 (file)
@@ -31,28 +31,28 @@ constexpr unsigned int STATS_UPDATE_INTERVAL = 1000;
 
 static void __callerAddedCb(GstElement* element, gint socket, GSocketAddress* address, gpointer userData)
 {
-       g_autofree gchar* ip_addr = g_inet_address_to_string(g_inet_socket_address_get_address((GInetSocketAddress*)address));
+       g_autofree gchar* ip_addr = g_inet_address_to_string(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(address)));
 
        LOG_INFO("socket %d, address %s", socket, ip_addr);
 }
 
 static void __callerRemovedCb(GstElement* element, gint socket, GSocketAddress* address, gpointer userData)
 {
-       g_autofree gchar* ip_addr = g_inet_address_to_string(g_inet_socket_address_get_address((GInetSocketAddress*)address));
+       g_autofree gchar* ip_addr = g_inet_address_to_string(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(address)));
 
        LOG_INFO("socket %d, address %s", socket, ip_addr);
 }
 
 static void __callerRejectedCb(GstElement* element, GSocketAddress* peerAddress, const gchar* stream_id, gpointer userData)
 {
-       g_autofree gchar* ip_addr = g_inet_address_to_string(g_inet_socket_address_get_address((GInetSocketAddress*)peerAddress));
+       g_autofree gchar* ip_addr = g_inet_address_to_string(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(peerAddress)));
 
        LOG_INFO("stream_id %s, peer_address %s", stream_id, ip_addr);
 }
 
 static void __callerConnectingCb(GstElement* element, GSocketAddress* peerAddress, const gchar* stream_id, gpointer userData)
 {
-       g_autofree gchar* ip_addr = g_inet_address_to_string(g_inet_socket_address_get_address((GInetSocketAddress*)peerAddress));
+       g_autofree gchar* ip_addr = g_inet_address_to_string(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(peerAddress)));
 
        LOG_INFO("stream_id %s, peer_address %s", stream_id, ip_addr);
 }
@@ -101,10 +101,10 @@ gpointer MediaTransporterSenderSrt::_updateStats(gpointer userData)
        if (gst_structure_has_field(structure, "callers")) {
          GValueArray *array;
 
-         array = (GValueArray *)g_value_get_boxed(gst_structure_get_value(structure, "callers"));
+         array = static_cast<GValueArray *>(g_value_get_boxed(gst_structure_get_value(structure, "callers")));
 
          LOG_DEBUG("SENDER >>> size of callers array : %d", array->n_values);
-         structure = (GstStructure *)g_value_get_boxed(&array->values[array->n_values - 1]);
+         structure = static_cast<GstStructure *>(g_value_get_boxed(&array->values[array->n_values - 1]));
        }
 
        gst_structure_get_int64(structure, "packets-sent", &srt->_stats.packetsSent);
index 6ca2f44..ca9f96b 100644 (file)
@@ -60,9 +60,9 @@ static const std::string tc_root_dir = "/home/owner/";
 
 class EsStreamReader {
 public:
-       explicit EsStreamReader(const std::string& dirpath,
-                                                       contentsType type) {
-               _dirPath = tc_root_dir + dirpath;
+       EsStreamReader(const std::string& dirpath,
+                                       contentsType type)
+               : _dirPath(tc_root_dir + dirpath) {
                _ESDataFile = _dirPath + "MTPR.es";
                _ESInfoFile = _dirPath + "MTPR.info";
                _type = type;
@@ -135,7 +135,7 @@ public:
                return false;
        }
 
-       media_format_h getMediaFormat() { return _mediaFormat; }
+       media_format_h getMediaFormat() const { return _mediaFormat; }
 
        bool ReadNextPacket(media_packet_h* outPacket) {
                static uint64_t pts = 0L;
@@ -214,16 +214,15 @@ private:
                int nal_length = 0;
                int read_size = 1;
                char buffer[1000000];
-               unsigned char val, zero_count, i;
-               int init = 0;
+               unsigned char i;
                int type = 0;
 
                do {
-                       zero_count = 0;
+                       unsigned char zero_count = 0;
 
                        _stream.read(buffer, read_size);
 
-                       val = buffer[0];
+                       unsigned char val = buffer[0];
                        nal[nal_length++] = val;
                        while (1) {
                                if ((zero_count == 2 || zero_count == 3) && val == 1)
@@ -236,7 +235,7 @@ private:
                        }
 
                        zero_count = 0;
-                       init = 1;
+                       int init = 1;
 
                        while (1) {
                                if (_stream.eof())