bf9e32e15db6eaf17b6b774589bd3e55134256c4
[platform/core/api/mediatransporter.git] / include / MediaTransporterSenderSrt.h
1 /**
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __TIZEN_MEDIA_TRANSPORTER_SENDER_SRT_H__
18 #define __TIZEN_MEDIA_TRANSPORTER_SENDER_SRT_H__
19
20 #ifdef __cplusplus
21
22 #include <string>
23 #include <thread>
24
25 #include "MediaTransporter.h"
26 #include "MediaTransporterSender.h"
27 #include "MediaTransporterGst.h"
28 #include "MediaTransporterParam.h"
29
30 namespace tizen_media_transporter {
31
32 class MediaTransporterSenderSrt : public MediaTransporterSender
33 {
34 public:
35         MediaTransporterSenderSrt();
36         ~MediaTransporterSenderSrt();
37
38         void buildPipeline() override;
39         void startPipeline() override;
40         void stopPipeline() override;
41
42         void setConnection(std::string name, std::string value) override;
43         std::string getConnection(std::string name) override;
44
45         void setSenderAddress(std::string address) override;
46         std::string getSenderAddress() override { return _senderAddress; }
47
48         mtprConnectionType type() override { return MTPR_CONNECTION_TYPE_SRT_SENDER; }
49
50         void foreachConnectionStats(InvokablePtr callback) override;
51
52 private:
53         void startStatsMonitoring();
54         void stopStatsMonitoring();
55         static gpointer _statsMonitorThread(gpointer userData);
56         static gpointer _updateStats(gpointer userData);
57         static gboolean _statsForeachCb(GQuark fieldId, const GValue* val, gpointer userData);
58
59         struct stats {
60                 gint64 packetsSent { 0 };
61                 gint packetsSentLost { 0 };
62                 gdouble bandwidthMbps { 0. };
63                 gdouble sendRateMbps { 0. };
64                 gdouble rttMs { 0. };
65         };
66         stats _stats;
67         GThread* _statsMonitor { nullptr };
68
69         param::srt::connectionParam _connectionParam;
70         std::string _senderAddress;
71         bool _threadExit { false };
72         GstElement* _srtSink { nullptr };
73 };
74
75 } // namespace
76
77 #endif // __cplusplus
78 #endif // __TIZEN_MEDIA_TRANSPORTER_SENDER_SRT_H__