Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2022 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #ifndef FIREBOLT_RIALTO_SERVER_I_GST_SRC_H_
21 : #define FIREBOLT_RIALTO_SERVER_I_GST_SRC_H_
22 :
23 : #include "IDecryptionService.h"
24 : #include <MediaCommon.h>
25 : #include <gst/app/gstappsrc.h>
26 : #include <gst/gst.h>
27 : #include <list>
28 : #include <memory>
29 : #include <stdint.h>
30 : #include <unordered_map>
31 :
32 : namespace firebolt::rialto::server
33 : {
34 : class IGstSrc;
35 :
36 : /**
37 : * @brief IGstSrc factory class, for the IGstSrc singleton object.
38 : */
39 : class IGstSrcFactory
40 : {
41 : public:
42 240 : IGstSrcFactory() = default;
43 240 : virtual ~IGstSrcFactory() = default;
44 :
45 : /**
46 : * @brief Gets the IGstSrcFactory instance.
47 : *
48 : * @retval the factory instance or null on error.
49 : */
50 : static std::shared_ptr<IGstSrcFactory> getFactory();
51 :
52 : /**
53 : * @brief Gets a IGstSrc singleton object.
54 : *
55 : * @retval the src instance or null on error.
56 : */
57 : virtual std::shared_ptr<IGstSrc> getGstSrc() = 0;
58 : };
59 :
60 : /**
61 : * @brief Structure used for stream info
62 : */
63 : struct StreamInfo
64 : {
65 689 : explicit StreamInfo(GstElement *appSrc_ = nullptr, bool hasDrm_ = true) : appSrc(appSrc_), hasDrm(hasDrm_) {}
66 24 : bool operator==(const StreamInfo &other) const
67 : {
68 16 : return appSrc == other.appSrc && hasDrm == other.hasDrm && isDataNeeded == other.isDataNeeded &&
69 40 : isNeedDataPending == other.isNeedDataPending && isDataPushed == other.isDataPushed;
70 : }
71 : GstElement *appSrc;
72 : bool hasDrm;
73 : bool isDataNeeded{false};
74 : bool isNeedDataPending{false};
75 : bool isDataPushed{false};
76 : std::list<GstBuffer *> buffers{};
77 : bool underflowOccured{false};
78 : };
79 : /**
80 : * @brief Definition of a stream info map.
81 : */
82 : using StreamInfoMap = std::unordered_map<MediaSourceType, StreamInfo>;
83 :
84 : class IGstSrc
85 : {
86 : public:
87 442 : IGstSrc() = default;
88 442 : virtual ~IGstSrc() = default;
89 :
90 : IGstSrc(const IGstSrc &) = delete;
91 : IGstSrc &operator=(const IGstSrc &) = delete;
92 : IGstSrc(IGstSrc &&) = delete;
93 : IGstSrc &operator=(IGstSrc &&) = delete;
94 :
95 : /**
96 : * @brief Initalise rialto src.
97 : */
98 : virtual void initSrc() = 0;
99 :
100 : /**
101 : * @brief Sets up the app source.
102 : *
103 : * @param[in] source : The source element.
104 : * @param[in] appsrc : The app source to attach.
105 : * @param[in] callbacks : Callbacks to be set on the app source.
106 : * @param[in] userData : Data to be passed to the callbacks.
107 : * @param[in] type : The media type of the source.
108 : */
109 : virtual void setupAndAddAppArc(IDecryptionService *decryptionService, GstElement *source, StreamInfo &streamInfo,
110 : GstAppSrcCallbacks *callbacks, gpointer userData,
111 : firebolt::rialto::MediaSourceType type) = 0;
112 :
113 : /**
114 : * @brief Notify rialto source that all app sources have been added.
115 : *
116 : * @param[in] element : The source element.
117 : */
118 : virtual void allAppSrcsAdded(GstElement *element) = 0;
119 : };
120 :
121 : }; // namespace firebolt::rialto::server
122 :
123 : #endif // FIREBOLT_RIALTO_SERVER_I_GST_SRC_H_
|