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