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/CheckAudioUnderflow.h"
21 : #include "GenericPlayerContext.h"
22 : #include "IGstGenericPlayerClient.h"
23 : #include "IGstWrapper.h"
24 : #include "RialtoServerLogging.h"
25 : #include "tasks/generic/Underflow.h"
26 : #include <gst/gst.h>
27 :
28 : #include <cinttypes>
29 :
30 : namespace firebolt::rialto::server::tasks::generic
31 : {
32 4 : CheckAudioUnderflow::CheckAudioUnderflow(GenericPlayerContext &context, IGstGenericPlayerPrivate &player,
33 : IGstGenericPlayerClient *client,
34 4 : std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> gstWrapper)
35 4 : : m_context{context}, m_player(player), m_gstPlayerClient{client}, m_gstWrapper{gstWrapper}
36 : {
37 : }
38 :
39 3 : void CheckAudioUnderflow::execute() const
40 : {
41 : // TODO(LLDEV-31012) Check if the audio stream is in underflow state.
42 3 : if (m_context.streamInfo.find(firebolt::rialto::MediaSourceType::AUDIO) != m_context.streamInfo.end())
43 : {
44 3 : gint64 position = m_player.getPosition(m_context.pipeline);
45 3 : if (position == -1)
46 : {
47 1 : RIALTO_SERVER_LOG_WARN("Getting the position failed");
48 1 : return;
49 : }
50 :
51 2 : constexpr int64_t kAudioUnderflowMarginNs = 350 * 1000000;
52 5 : if ((position > m_context.lastAudioSampleTimestamps + kAudioUnderflowMarginNs) &&
53 3 : m_gstWrapper->gstElementGetState(m_context.pipeline) == GST_STATE_PLAYING &&
54 1 : m_gstWrapper->gstElementGetPendingState(m_context.pipeline) != GST_STATE_PAUSED)
55 : {
56 1 : RIALTO_SERVER_LOG_WARN("Audio stream underflow! Position %" PRIu64 ", lastAudioSampleTimestamps: %" PRIu64,
57 : position, m_context.lastAudioSampleTimestamps);
58 1 : bool underflowEnabled = m_context.isPlaying && !m_context.audioSourceRemoved;
59 1 : Underflow task(m_context, m_player, m_gstPlayerClient, underflowEnabled, MediaSourceType::AUDIO);
60 1 : task.execute();
61 : }
62 : }
63 : }
64 :
65 : } // namespace firebolt::rialto::server::tasks::generic
|