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_SHARED_MEMORY_BUFFER_H_
21 : #define FIREBOLT_RIALTO_SERVER_SHARED_MEMORY_BUFFER_H_
22 :
23 : #include "ISharedMemoryBuffer.h"
24 : #include <cstdint>
25 : #include <memory>
26 : #include <vector>
27 :
28 : namespace firebolt::rialto::server
29 : {
30 : class SharedMemoryBufferFactory : public ISharedMemoryBufferFactory
31 : {
32 : public:
33 50 : ~SharedMemoryBufferFactory() override = default;
34 : std::shared_ptr<ISharedMemoryBuffer> createSharedMemoryBuffer(unsigned numOfPlaybacks,
35 : unsigned numOfWebAudioPlayers) const override;
36 : };
37 :
38 : class SharedMemoryBuffer : public ISharedMemoryBuffer
39 : {
40 : public:
41 : explicit SharedMemoryBuffer(unsigned numOfPlaybacks, unsigned numOfWebAudioPlayers);
42 : ~SharedMemoryBuffer() override;
43 : SharedMemoryBuffer(const SharedMemoryBuffer &) = delete;
44 : SharedMemoryBuffer(SharedMemoryBuffer &&) = delete;
45 : SharedMemoryBuffer &operator=(const SharedMemoryBuffer &) = delete;
46 : SharedMemoryBuffer &operator=(SharedMemoryBuffer &&) = delete;
47 :
48 : bool mapPartition(MediaPlaybackType playbackType, int id) override;
49 : bool unmapPartition(MediaPlaybackType playbackType, int id) override;
50 :
51 : bool clearData(MediaPlaybackType playbackType, int id, const MediaSourceType &mediaSourceType) const override;
52 :
53 : std::uint32_t getDataOffset(MediaPlaybackType playbackType, int id,
54 : const MediaSourceType &mediaSourceType) const override;
55 : std::uint32_t getMaxDataLen(MediaPlaybackType playbackType, int id,
56 : const MediaSourceType &mediaSourceType) const override;
57 : std::uint8_t *getDataPtr(MediaPlaybackType playbackType, int id,
58 : const MediaSourceType &mediaSourceType) const override;
59 :
60 : int getFd() const override;
61 : std::uint32_t getSize() const override;
62 : std::uint8_t *getBuffer() const override;
63 :
64 : struct Partition
65 : {
66 : int id;
67 : std::uint32_t dataBufferAudioLen;
68 : std::uint32_t dataBufferVideoLen;
69 : std::uint32_t dataBufferSubtitleLen;
70 : };
71 :
72 : private:
73 : size_t calculateBufferSize() const;
74 : bool getDataPtrForPartition(MediaPlaybackType playbackType, int id, std::uint8_t **ptr) const;
75 : const std::vector<Partition> *getPlaybackTypePartition(MediaPlaybackType playbackType) const;
76 : std::vector<Partition> *getPlaybackTypePartition(MediaPlaybackType playbackType);
77 :
78 : private:
79 : std::vector<Partition> m_genericPartitions;
80 : std::vector<Partition> m_webAudioPartitions;
81 : std::uint32_t m_dataBufferLen;
82 : int m_dataBufferFd;
83 : std::uint8_t *m_dataBuffer;
84 : };
85 : } // namespace firebolt::rialto::server
86 :
87 : #endif // FIREBOLT_RIALTO_SERVER_SHARED_MEMORY_BUFFER_H_
|