2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "AudioSinkAE.h"
13 #include "DVDMessageQueue.h"
14 #include "DVDStreamInfo.h"
15 #include "IVideoPlayer.h"
16 #include "cores/VideoPlayer/Interface/TimingConstants.h"
17 #include "threads/SystemClock.h"
18 #include "threads/Thread.h"
19 #include "utils/BitstreamStats.h"
30 class CVideoPlayerAudio
: public CThread
, public IDVDStreamPlayerAudio
33 CVideoPlayerAudio(CDVDClock
* pClock
,
34 CDVDMessageQueue
& parent
,
35 CProcessInfo
& processInfo
,
36 double messageQueueTimeSize
);
37 ~CVideoPlayerAudio() override
;
39 bool OpenStream(CDVDStreamInfo hints
) override
;
40 void CloseStream(bool bWaitForBuffers
) override
;
42 void SetSpeed(int speed
) override
;
43 void Flush(bool sync
) override
;
45 // waits until all available data has been rendered
46 bool AcceptsData() const override
;
47 bool HasData() const override
{ return m_messageQueue
.GetDataSize() > 0; }
48 int GetLevel() const override
{ return m_messageQueue
.GetLevel(); }
49 bool IsInited() const override
{ return m_messageQueue
.IsInited(); }
50 void SendMessage(std::shared_ptr
<CDVDMsg
> pMsg
, int priority
= 0) override
52 m_messageQueue
.Put(pMsg
, priority
);
54 void FlushMessages() override
{ m_messageQueue
.Flush(); }
56 void SetDynamicRangeCompression(long drc
) override
{ m_audioSink
.SetDynamicRangeCompression(drc
); }
57 float GetDynamicRangeAmplification() const override
{ return 0.0f
; }
59 std::string
GetPlayerInfo() override
;
60 int GetAudioChannels() override
;
62 double GetCurrentPts() override
64 std::unique_lock
<CCriticalSection
> lock(m_info_section
);
68 bool IsStalled() const override
{ return m_stalled
; }
69 bool IsPassthrough() const override
;
73 void OnStartup() override
;
74 void OnExit() override
;
75 void Process() override
;
77 bool ProcessDecoderOutput(DVDAudioFrame
&audioframe
);
78 void UpdatePlayerInfo();
79 void OpenStream(CDVDStreamInfo
& hints
, std::unique_ptr
<CDVDAudioCodec
> codec
);
80 //! Switch codec if needed. Called when the sample rate gotten from the
81 //! codec changes, in which case we may want to switch passthrough on/off.
82 bool SwitchCodecIfNeeded();
83 void SetSyncType(bool passthrough
);
85 CDVDMessageQueue m_messageQueue
;
86 CDVDMessageQueue
& m_messageParent
;
88 // holds stream information for current playing stream
89 CDVDStreamInfo m_streaminfo
;
93 CAudioSinkAE m_audioSink
; // audio output device
94 CDVDClock
* m_pClock
; // dvd master clock
95 std::unique_ptr
<CDVDAudioCodec
> m_pAudioCodec
; // audio codec
96 BitstreamStats m_audioStats
;
101 IDVDStreamPlayer::ESyncState m_syncState
;
102 XbmcThreads::EndTime
<> m_syncTimer
;
108 double m_maxspeedadjust
;
113 double pts
= DVD_NOPTS_VALUE
;
114 bool passthrough
= false;
117 mutable CCriticalSection m_info_section
;
120 bool m_displayReset
= false;
121 unsigned int m_disconAdjustTimeMs
= 50; // maximum sync-off before adjusting
122 int m_disconAdjustCounter
= 0;