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_SHARED_MEMORY_BUFFER_H_
21 : #define FIREBOLT_RIALTO_SERVER_I_SHARED_MEMORY_BUFFER_H_
22 :
23 : #include <cstdint>
24 : #include <memory>
25 :
26 : #include "MediaCommon.h"
27 :
28 : namespace firebolt::rialto::server
29 : {
30 : class ISharedMemoryBuffer;
31 : class ISharedMemoryBufferFactory
32 : {
33 : public:
34 54 : ISharedMemoryBufferFactory() = default;
35 54 : virtual ~ISharedMemoryBufferFactory() = default;
36 :
37 : static std::unique_ptr<ISharedMemoryBufferFactory> createFactory();
38 : virtual std::shared_ptr<ISharedMemoryBuffer> createSharedMemoryBuffer(unsigned numOfPlaybacks,
39 : unsigned numOfWebAudioPlayers) const = 0;
40 : };
41 :
42 : class ISharedMemoryBuffer
43 : {
44 : public:
45 398 : ISharedMemoryBuffer() = default;
46 398 : virtual ~ISharedMemoryBuffer() = default;
47 :
48 : ISharedMemoryBuffer(const ISharedMemoryBuffer &) = delete;
49 : ISharedMemoryBuffer(ISharedMemoryBuffer &&) = delete;
50 : ISharedMemoryBuffer &operator=(const ISharedMemoryBuffer &) = delete;
51 : ISharedMemoryBuffer &operator=(ISharedMemoryBuffer &&) = delete;
52 :
53 : /**
54 : * @brief The type of media playback.
55 : */
56 : enum class MediaPlaybackType
57 : {
58 : GENERIC,
59 : WEB_AUDIO
60 : };
61 :
62 : /**
63 : * @brief Maps the partition for playback.
64 : *
65 : * @param[in] playbackType : The type of playback partition.
66 : * @param[in] id : The id for the partition of playbackType.
67 : *
68 : * @retval true on success.
69 : */
70 : virtual bool mapPartition(MediaPlaybackType playbackType, int id) = 0;
71 :
72 : /**
73 : * @brief Unmaps the partition for playback.
74 : *
75 : * @param[in] playbackType : The type of playback partition.
76 : * @param[in] id : The id for the partition of playbackType.
77 : *
78 : * @retval true on success.
79 : */
80 : virtual bool unmapPartition(MediaPlaybackType playbackType, int id) = 0;
81 :
82 : /**
83 : * @brief Clears the data in the specified partition.
84 : *
85 : * @param[in] playbackType : The type of playback partition.
86 : * @param[in] id : The id for the partition of playbackType.
87 : * @param[in] mediaSourceType : The type of media source partition.
88 : *
89 : * @retval true on success.
90 : */
91 : virtual bool clearData(MediaPlaybackType playbackType, int id, const MediaSourceType &mediaSourceType) const = 0;
92 :
93 : /**
94 : * @brief Gets the offset of the specified data partition.
95 : *
96 : * @param[in] playbackType : The type of playback partition.
97 : * @param[in] id : The id for the partition of playbackType.
98 : * @param[in] mediaSourceType : The type of media source partition.
99 : *
100 : * @retval true on success.
101 : */
102 : virtual std::uint32_t getDataOffset(MediaPlaybackType playbackType, int id,
103 : const MediaSourceType &mediaSourceType) const = 0;
104 :
105 : /**
106 : * @brief Gets the maximum length of the specified data partition.
107 : *
108 : * @param[in] playbackType : The type of playback partition.
109 : * @param[in] id : The id for the partition of playbackType.
110 : * @param[in] mediaSourceType : The type of media source partition.
111 : *
112 : * @retval true on success.
113 : */
114 : virtual std::uint32_t getMaxDataLen(MediaPlaybackType playbackType, int id,
115 : const MediaSourceType &mediaSourceType) const = 0;
116 :
117 : /**
118 : * @brief Gets the pointer to the start of the specified data partition.
119 : *
120 : * @param[in] playbackType : The type of playback partition.
121 : * @param[in] id : The id for the partition of playbackType.
122 : * @param[in] mediaSourceType : The type of media source partition.
123 : *
124 : * @retval true on success.
125 : */
126 : virtual std::uint8_t *getDataPtr(MediaPlaybackType playbackType, int id,
127 : const MediaSourceType &mediaSourceType) const = 0;
128 :
129 : /**
130 : * @brief Gets file descriptor of the shared memory.
131 : *
132 : * @retval > -1 on success.
133 : */
134 : virtual int getFd() const = 0;
135 :
136 : /**
137 : * @brief Gets the allocated size of the shared memory.
138 : *
139 : * @retval > 0 on success.
140 : */
141 : virtual std::uint32_t getSize() const = 0;
142 :
143 : /**
144 : * @brief Gets the pointer to the shared memory.
145 : *
146 : * @retval None null ptr value on success.
147 : */
148 : virtual std::uint8_t *getBuffer() const = 0;
149 : };
150 : } // namespace firebolt::rialto::server
151 :
152 : #endif // FIREBOLT_RIALTO_SERVER_I_SHARED_MEMORY_BUFFER_H_
|