[1.0.27] Add ConnectionStats abstraction
[platform/core/api/mediatransporter.git] / include / MediaTransporterConnectionStats.h
1 /*
2 * Copyright (c) 2023 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_CONNECTION_STATS_H__
18 #define __TIZEN_MEDIA_TRANSPORTER_CONNECTION_STATS_H__
19
20 #include <variant>
21 #include <memory>
22 #include <map>
23 #include <glib-object.h>
24
25 #include "MediaTransporter.h"
26 #include "MediaTransporterCallback.h"
27 #include "MediaTransporterGst.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 namespace tizen_media_transporter {
34
35 using ConnectionStatPropMap = std::map<std::string, mtprConnectionStatsProp>;
36
37 class IForeachable
38 {
39 public:
40         virtual ~IForeachable() = default;
41
42         virtual void foreach() = 0;
43 };
44
45 class AbstractConnectionStats : public IForeachable
46 {
47 public:
48         AbstractConnectionStats(const GstElement* element, InvokablePtr callback, const ConnectionStatPropMap& prop)
49                 : _element(element),  _callback(std::move(callback)), _prop(prop) {}
50         virtual ~AbstractConnectionStats() = default;
51
52 protected:
53         const GstStructure* stats();
54
55         static gboolean _statsForeachCb(GQuark fieldId, const GValue* val, gpointer userData);
56         static std::optional<mtprConnectionStatsPropInfo> translateGvalue(const GValue* val,
57                                                                                                                                         const ConnectionStatPropMap& propList,
58                                                                                                                                         const std::string& fieldName);
59
60         const GstElement* _element { nullptr };
61         InvokablePtr _callback;
62         ConnectionStatPropMap _prop;
63 };
64
65 using ForeachablePtr = std::unique_ptr<IForeachable>;
66
67 struct ConnectionStatsFactory
68 {
69         static ForeachablePtr createReceiverSrtConnectionStats(const GstElement* element, InvokablePtr callback);
70         static ForeachablePtr createSenderSrtConnectionStats(const GstElement* element, InvokablePtr callback);
71 };
72
73 class ReceiverSrtConnectionStats : public AbstractConnectionStats
74 {
75 public:
76         ReceiverSrtConnectionStats(const GstElement* element, InvokablePtr callback);
77         virtual ~ReceiverSrtConnectionStats() = default;
78
79         void foreach() override;
80 };
81
82 class SenderSrtConnectionStats : public AbstractConnectionStats
83 {
84 public:
85         SenderSrtConnectionStats(const GstElement* element, InvokablePtr callback);
86         virtual ~SenderSrtConnectionStats() = default;
87
88         void foreach() override;
89 };
90
91 } // namespace
92
93 #ifdef __cplusplus
94 }
95 #endif /* __cplusplus */
96
97 #endif /* __TIZEN_MEDIA_TRANSPORTER_CONNECTION_STATS_H__ */