#ifdef __cplusplus
#include <string>
+#include <tuple>
#include <gst/rtsp-server/rtsp-server.h>
#include <gst/rtsp-server/rtsp-media-factory-mtpr.h>
void postMsgOnIdle(GstMessage* message);
void removeIdleEventSource();
+ std::tuple<std::string, std::string, std::string> parseAddress() const;
+
struct idleData {
void* handle;
mtpr_error_e error;
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
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);
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;
}
"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);
}
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;
}
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());
}
_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;
/* 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;
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()
_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");
_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;
}
}
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);
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);
}
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);
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;
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;
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)
}
zero_count = 0;
- init = 1;
+ int init = 1;
while (1) {
if (_stream.eof())