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 "AudioDecoder.h"
12 #include "cores/AudioEngine/Interfaces/AE.h"
13 #include "cores/AudioEngine/Interfaces/IAudioCallback.h"
14 #include "cores/IPlayer.h"
15 #include "threads/CriticalSection.h"
16 #include "threads/Thread.h"
17 #include "utils/Job.h"
27 class PAPlayer
: public IPlayer
, public CThread
, public IJobCallback
29 friend class CQueueNextFileJob
;
31 explicit PAPlayer(IPlayerCallback
& callback
);
34 bool OpenFile(const CFileItem
& file
, const CPlayerOptions
&options
) override
;
35 bool QueueNextFile(const CFileItem
&file
) override
;
36 void OnNothingToQueueNotify() override
;
37 bool CloseFile(bool reopen
= false) override
;
38 bool IsPlaying() const override
;
39 void Pause() override
;
40 bool HasVideo() const override
{ return false; }
41 bool HasAudio() const override
{ return true; }
42 bool CanSeek() const override
;
43 void Seek(bool bPlus
= true, bool bLargeStep
= false, bool bChapterOverride
= false) override
;
44 void SeekPercentage(float fPercent
= 0.0f
) override
;
45 void SetVolume(float volume
) override
;
46 void SetDynamicRangeCompression(long drc
) override
;
47 void SetSpeed(float speed
= 0) override
;
48 int GetCacheLevel() const override
;
49 void SetTotalTime(int64_t time
) override
;
50 void GetAudioStreamInfo(int index
, AudioStreamInfo
& info
) const override
;
51 void SetTime(int64_t time
) override
;
52 void SeekTime(int64_t iTime
= 0) override
;
53 void GetAudioCapabilities(std::vector
<int>& audioCaps
) const override
{}
55 int GetAudioStreamCount() const override
{ return 1; }
56 int GetAudioStream() override
{ return 0; }
58 // implementation of IJobCallback
59 void OnJobComplete(unsigned int jobID
, bool success
, CJob
*job
) override
;
75 // implementation of CThread
76 void OnStartup() override
{}
77 void Process() override
;
78 void OnExit() override
;
79 float GetPercentage();
84 std::unique_ptr
<CFileItem
> m_fileItem
;
85 std::unique_ptr
<CFileItem
> m_nextFileItem
;
86 CAudioDecoder m_decoder
; /* the stream decoder */
87 int64_t m_startOffset
; /* the stream start offset */
88 int64_t m_endOffset
; /* the stream end offset */
89 int64_t m_decoderTotal
= 0;
90 AEAudioFormat m_audioFormat
;
91 unsigned int m_bytesPerSample
; /* number of bytes per audio sample */
92 unsigned int m_bytesPerFrame
; /* number of bytes per audio frame */
94 bool m_started
; /* if playback of this stream has been started */
95 bool m_finishing
; /* if this stream is finishing */
96 int m_framesSent
; /* number of frames sent to the stream */
97 int m_prepareNextAtFrame
; /* when to prepare the next stream */
98 bool m_prepareTriggered
; /* if the next stream has been prepared */
99 int m_playNextAtFrame
; /* when to start playing the next stream */
100 bool m_playNextTriggered
; /* if this stream has started the next one */
101 bool m_fadeOutTriggered
; /* if the stream has been told to fade out */
102 int m_seekNextAtFrame
; /* the FF/RR sample to seek at */
103 int m_seekFrame
; /* the exact position to seek too, -1 for none */
105 IAE::StreamPtr m_stream
; /* the playback stream */
106 float m_volume
; /* the initial volume level to set the stream to on creation */
108 bool m_isSlaved
; /* true if the stream has been slaved to another */
109 bool m_waitOnDrain
; /* wait for stream being drained in AE */
112 typedef std::list
<StreamInfo
*> StreamList
;
114 bool m_signalSpeedChange
= false; /* true if OnPlaybackSpeedChange needs to be called */
115 bool m_signalStarted
= true;
116 std::atomic_int m_playbackSpeed
; /* the playback speed (1 = normal) */
117 bool m_isPlaying
= false;
118 bool m_isPaused
= false;
119 bool m_isFinished
= false; /* if there are no more songs in the queue */
121 unsigned int m_defaultCrossfadeMS
= 0; /* how long the default crossfade is in ms */
122 unsigned int m_upcomingCrossfadeMS
= 0; /* how long the upcoming crossfade is in ms */
123 CEvent m_startEvent
; /* event for playback start */
124 StreamInfo
* m_currentStream
= nullptr;
125 IAudioCallback
* m_audioCallback
; /* the viz audio callback */
127 CCriticalSection m_streamsLock
; /* lock for the stream list */
128 StreamList m_streams
; /* playing streams */
129 StreamList m_finishing
; /* finishing streams */
130 int m_jobCounter
= 0;
132 int64_t m_newForcedPlayerTime
= -1;
133 int64_t m_newForcedTotalTime
= -1;
134 std::unique_ptr
<CProcessInfo
> m_processInfo
;
136 bool QueueNextFileEx(const CFileItem
&file
, bool fadeIn
);
137 void SoftStart(bool wait
= false);
138 void SoftStop(bool wait
= false, bool close
= true);
139 void CloseAllStreams(bool fade
= true);
140 void ProcessStreams(double &freeBufferTime
);
141 bool PrepareStream(StreamInfo
*si
);
142 bool ProcessStream(StreamInfo
*si
, double &freeBufferTime
);
143 bool QueueData(StreamInfo
*si
);
144 int64_t GetTotalTime64();
145 void UpdateCrossfadeTime(const CFileItem
& file
);
146 void UpdateStreamInfoPlayNextAtFrame(StreamInfo
*si
, unsigned int crossFadingTime
);
147 void UpdateGUIData(StreamInfo
*si
);
148 int64_t GetTimeInternal();
149 bool SetTimeInternal(int64_t time
);
150 bool SetTotalTimeInternal(int64_t time
);
151 void CloseFileCB(StreamInfo
&si
);
152 void AdvancePlaylistOnError(CFileItem
&fileItem
);