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 "NeedMediaData.h"
21 : #include "IActiveRequests.h"
22 : #include "IMediaPipelineClient.h"
23 : #include "ISharedMemoryBuffer.h"
24 : #include "RialtoServerLogging.h"
25 : #include "ShmUtils.h"
26 : #include "TypeConverters.h"
27 :
28 : namespace firebolt::rialto::server
29 : {
30 11 : NeedMediaData::NeedMediaData(std::weak_ptr<IMediaPipelineClient> client, IActiveRequests &activeRequests,
31 : const ISharedMemoryBuffer &shmBuffer, int sessionId, MediaSourceType mediaSourceType,
32 11 : std::int32_t sourceId, PlaybackState currentPlaybackState)
33 11 : : m_client{client}, m_activeRequests{activeRequests}, m_mediaSourceType{mediaSourceType}, m_frameCount{kMaxFrames},
34 11 : m_sourceId{sourceId}
35 : {
36 11 : if (PlaybackState::PLAYING != currentPlaybackState)
37 : {
38 7 : RIALTO_SERVER_LOG_DEBUG("Pipeline in prerolling state. Sending smaller frame count for %s",
39 : common::convertMediaSourceType(m_mediaSourceType));
40 7 : m_frameCount = kPrerollNumFrames;
41 : }
42 11 : if (MediaSourceType::AUDIO != mediaSourceType && MediaSourceType::VIDEO != mediaSourceType &&
43 1 : MediaSourceType::SUBTITLE != mediaSourceType)
44 : {
45 1 : RIALTO_SERVER_LOG_ERROR("Unable to initialize NeedMediaData - unknown mediaSourceType: %s",
46 : common::convertMediaSourceType(m_mediaSourceType));
47 1 : m_isValid = false;
48 1 : return;
49 : }
50 : try
51 : {
52 10 : m_maxMediaBytes =
53 10 : shmBuffer.getMaxDataLen(ISharedMemoryBuffer::MediaPlaybackType::GENERIC, sessionId, mediaSourceType) -
54 10 : getMaxMetadataBytes();
55 : auto metadataOffset =
56 10 : shmBuffer.getDataOffset(ISharedMemoryBuffer::MediaPlaybackType::GENERIC, sessionId, mediaSourceType);
57 10 : auto mediadataOffset = metadataOffset + getMaxMetadataBytes();
58 10 : m_shmInfo = std::make_shared<MediaPlayerShmInfo>(
59 10 : MediaPlayerShmInfo{getMaxMetadataBytes(), metadataOffset, mediadataOffset, m_maxMediaBytes});
60 10 : m_isValid = true;
61 : }
62 0 : catch (const std::exception &e)
63 : {
64 0 : RIALTO_SERVER_LOG_ERROR("Unable to construct NeedMediaData message for %s - %s",
65 : common::convertMediaSourceType(m_mediaSourceType), e.what());
66 0 : m_isValid = false;
67 : }
68 : }
69 :
70 11 : bool NeedMediaData::send() const
71 : {
72 11 : auto client = m_client.lock();
73 11 : if (client && m_isValid)
74 : {
75 20 : client->notifyNeedMediaData(m_sourceId, m_frameCount,
76 10 : m_activeRequests.insert(m_mediaSourceType, m_maxMediaBytes), m_shmInfo);
77 10 : return true;
78 : }
79 1 : return false;
80 11 : }
81 : } // namespace firebolt::rialto::server
|