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 "tasks/generic/SetPosition.h"
21 : #include "GenericPlayerContext.h"
22 : #include "IGstGenericPlayerClient.h"
23 : #include "IGstGenericPlayerPrivate.h"
24 : #include "IGstWrapper.h"
25 : #include "RialtoServerLogging.h"
26 : #include "tasks/generic/NeedData.h"
27 :
28 : namespace firebolt::rialto::server::tasks::generic
29 : {
30 6 : SetPosition::SetPosition(GenericPlayerContext &context, IGstGenericPlayerPrivate &player, IGstGenericPlayerClient *client,
31 6 : std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> gstWrapper, std::int64_t position)
32 6 : : m_context{context}, m_player{player}, m_gstPlayerClient{client}, m_gstWrapper{gstWrapper}, m_position{position}
33 : {
34 6 : RIALTO_SERVER_LOG_DEBUG("Constructing SetPosition");
35 : }
36 :
37 7 : SetPosition::~SetPosition()
38 : {
39 6 : RIALTO_SERVER_LOG_DEBUG("SetPosition finished");
40 7 : }
41 :
42 5 : void SetPosition::execute() const
43 : {
44 5 : RIALTO_SERVER_LOG_DEBUG("Executing SetPosition");
45 5 : if (!m_gstPlayerClient)
46 : {
47 1 : RIALTO_SERVER_LOG_ERROR("Seek failed - GstPlayerClient is NULL");
48 1 : return;
49 : }
50 4 : m_gstPlayerClient->notifyPlaybackState(PlaybackState::SEEKING);
51 :
52 : // Stop sending new NeedMediaData requests
53 12 : for (auto &elem : m_context.streamInfo)
54 : {
55 8 : StreamInfo &streamInfo = elem.second;
56 8 : streamInfo.isDataNeeded = false;
57 8 : streamInfo.isNeedDataPending = false;
58 :
59 : // Clear buffered samples for player session
60 16 : for (auto &buffer : streamInfo.buffers)
61 : {
62 8 : m_gstWrapper->gstBufferUnref(buffer);
63 : }
64 :
65 8 : streamInfo.buffers.clear();
66 : }
67 :
68 : // Clear local cache of any active data requests for player session
69 4 : m_gstPlayerClient->clearActiveRequestsCache();
70 4 : m_context.lastAudioSampleTimestamps = m_position;
71 :
72 4 : if (!m_context.pipeline)
73 : {
74 1 : RIALTO_SERVER_LOG_ERROR("Seek failed - pipeline is null");
75 1 : m_gstPlayerClient->notifyPlaybackState(PlaybackState::FAILURE);
76 1 : return;
77 : }
78 6 : if (!m_gstWrapper->gstElementSeek(m_context.pipeline, m_context.playbackRate, GST_FORMAT_TIME,
79 3 : static_cast<GstSeekFlags>(GST_SEEK_FLAG_FLUSH), GST_SEEK_TYPE_SET, m_position,
80 : GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
81 : {
82 1 : RIALTO_SERVER_LOG_ERROR("Seek failed - gstreamer error");
83 1 : m_gstPlayerClient->notifyPlaybackState(PlaybackState::FAILURE);
84 1 : return;
85 : }
86 :
87 : // Reset Eos info
88 2 : m_context.endOfStreamInfo.clear();
89 2 : m_context.eosNotified = false;
90 :
91 2 : m_gstPlayerClient->notifyPlaybackState(PlaybackState::SEEK_DONE);
92 :
93 : // // Trigger NeedMediaData for all attached sources
94 6 : for (const auto &streamInfo : m_context.streamInfo)
95 : {
96 4 : if (streamInfo.second.appSrc)
97 : {
98 4 : NeedData task{m_context, m_player, m_gstPlayerClient, GST_APP_SRC(streamInfo.second.appSrc)};
99 4 : task.execute();
100 : }
101 : }
102 : }
103 : } // namespace firebolt::rialto::server::tasks::generic
|