[1.0.27] Add ConnectionStats abstraction
[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
58         struct stats {
59                 gint64 packetsSent { 0 };
60                 gint packetsSentLost { 0 };
61                 gdouble bandwidthMbps { 0. };
62                 gdouble sendRateMbps { 0. };
63                 gdouble rttMs { 0. };
64         };
65         stats _stats;
66         GThread* _statsMonitor { nullptr };
67
68         param::srt::connectionParam _connectionParam;
69         std::string _senderAddress;
70         bool _threadExit { false };
71         GstElement* _srtSink { nullptr };
72 };
73
74 } // namespace
75
76 #endif // __cplusplus
77 #endif // __TIZEN_MEDIA_TRANSPORTER_SENDER_SRT_H__