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_ACTIVE_REQUESTS_H_
21 : #define FIREBOLT_RIALTO_SERVER_ACTIVE_REQUESTS_H_
22 :
23 : #include "IActiveRequests.h"
24 : #include <map>
25 : #include <memory>
26 : #include <mutex>
27 : #include <vector>
28 :
29 : namespace firebolt::rialto::server
30 : {
31 : class ActiveRequests : public IActiveRequests
32 : {
33 : public:
34 : class ActiveRequestsData
35 : {
36 : public:
37 22 : ActiveRequestsData(MediaSourceType type, std::uint32_t maxMediaBytes, std::uint32_t maxFrames)
38 22 : : m_type(type), m_bytesWritten(0), m_maxMediaBytes(maxMediaBytes), m_maxFrames(maxFrames)
39 : {
40 : }
41 : ~ActiveRequestsData();
42 22 : ActiveRequestsData(ActiveRequestsData &&) = default;
43 : ActiveRequestsData &operator=(ActiveRequestsData &&) = default;
44 :
45 : ActiveRequestsData(const ActiveRequestsData &) = delete;
46 : ActiveRequestsData &operator=(const ActiveRequestsData &) = delete;
47 :
48 : AddSegmentStatus addSegment(const std::unique_ptr<IMediaPipeline::MediaSegment> &segment);
49 :
50 27 : MediaSourceType getType() const { return m_type; }
51 2 : std::uint32_t getMaxFrames() const { return m_maxFrames; }
52 1 : const IMediaPipeline::MediaSegmentVector &getSegments() const { return m_segments; }
53 :
54 : private:
55 : MediaSourceType m_type;
56 : std::uint32_t m_bytesWritten;
57 : std::uint32_t m_maxMediaBytes;
58 : std::uint32_t m_maxFrames;
59 : IMediaPipeline::MediaSegmentVector m_segments;
60 : std::vector<std::vector<uint8_t>> m_segmentBuffers;
61 : };
62 :
63 : ActiveRequests();
64 16 : ~ActiveRequests() override = default;
65 : ActiveRequests(const ActiveRequests &) = delete;
66 : ActiveRequests(ActiveRequests &&) = delete;
67 : ActiveRequests &operator=(const ActiveRequests &) = delete;
68 : ActiveRequests &operator=(ActiveRequests &&) = delete;
69 :
70 : std::uint32_t insert(const MediaSourceType &mediaSourceType, std::uint32_t maxMediaBytes,
71 : std::uint32_t maxFrames) override;
72 : MediaSourceType getType(std::uint32_t requestId) const override;
73 : std::uint32_t getMaxFrames(std::uint32_t requestId) const override;
74 : void erase(std::uint32_t requestId) override;
75 : void erase(const MediaSourceType &mediaSourceType) override;
76 : void clear() override;
77 : AddSegmentStatus addSegment(std::uint32_t requestId,
78 : const std::unique_ptr<IMediaPipeline::MediaSegment> &segment) override;
79 : const IMediaPipeline::MediaSegmentVector &getSegments(std::uint32_t requestId) const override;
80 :
81 : private:
82 : mutable std::mutex m_mutex;
83 : std::uint32_t m_currentId;
84 : std::map<std::uint32_t, ActiveRequestsData> m_requestMap;
85 : // only used in server-only mode
86 : std::map<std::uint32_t, std::unique_ptr<IMediaPipeline::IMediaPipeline::MediaSegment>> m_addedSegments;
87 : };
88 :
89 : } // namespace firebolt::rialto::server
90 :
91 : #endif // FIREBOLT_RIALTO_SERVER_ACTIVE_REQUESTS_H_
|