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 : #include "DataReaderFactory.h"
21 : #include "DataReaderV1.h"
22 : #include "DataReaderV2.h"
23 : #include "ShmCommon.h"
24 : #include "ShmUtils.h"
25 :
26 : namespace
27 : {
28 3 : uint32_t readLEUint32(const uint8_t *buffer)
29 : {
30 3 : uint32_t value = buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0];
31 3 : return value;
32 : }
33 : } // namespace
34 :
35 : namespace firebolt::rialto::server
36 : {
37 3 : std::shared_ptr<IDataReader> DataReaderFactory::createDataReader(const MediaSourceType &mediaSourceType,
38 : std::uint8_t *buffer, std::uint32_t dataOffset,
39 : std::uint32_t numFrames) const
40 : {
41 : // Version is always first 4 bytes of data
42 3 : std::uint8_t *metadata = buffer + dataOffset;
43 3 : std::uint32_t version = readLEUint32(metadata);
44 3 : if (1 == version)
45 : {
46 1 : std::uint32_t metadataOffsetWithoutVersion = dataOffset + common::VERSION_SIZE_BYTES;
47 1 : return std::make_shared<DataReaderV1>(mediaSourceType, buffer, metadataOffsetWithoutVersion, numFrames);
48 : }
49 2 : if (2 == version)
50 : {
51 1 : std::uint32_t v2DataOffset = dataOffset + getMaxMetadataBytes();
52 1 : return std::make_shared<DataReaderV2>(mediaSourceType, buffer, v2DataOffset, numFrames);
53 : }
54 1 : return nullptr;
55 : }
56 : } // namespace firebolt::rialto::server
|