4 * Copyright (C) 2005-2013 Team XBMC
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This Program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with XBMC; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
25 #include "cores/IPlayer.h"
26 #include "threads/Thread.h"
27 #include "AudioDecoder.h"
28 #include "threads/SharedSection.h"
29 #include "utils/Job.h"
31 #include "cores/IAudioCallback.h"
32 #include "cores/AudioEngine/Utils/AEChannelInfo.h"
37 class PAPlayer : public IPlayer, public CThread, public IJobCallback
39 friend class CQueueNextFileJob;
41 PAPlayer(IPlayerCallback& callback);
44 virtual void RegisterAudioCallback(IAudioCallback* pCallback);
45 virtual void UnRegisterAudioCallback();
46 virtual bool OpenFile(const CFileItem& file, const CPlayerOptions &options);
47 virtual bool QueueNextFile(const CFileItem &file);
48 virtual void OnNothingToQueueNotify();
49 virtual bool CloseFile();
50 virtual bool IsPlaying() const;
52 virtual bool IsPaused() const;
53 virtual bool HasVideo() const { return false; }
54 virtual bool HasAudio() const { return true; }
55 virtual bool CanSeek();
56 virtual void Seek(bool bPlus = true, bool bLargeStep = false);
57 virtual void SeekPercentage(float fPercent = 0.0f);
58 virtual float GetPercentage();
59 virtual void SetVolume(float volume);
60 virtual void SetDynamicRangeCompression(long drc);
61 virtual void GetAudioInfo( CStdString& strAudioInfo) {}
62 virtual void GetVideoInfo( CStdString& strVideoInfo) {}
63 virtual void GetGeneralInfo( CStdString& strVideoInfo) {}
64 virtual void ToFFRW(int iSpeed = 0);
65 virtual int GetCacheLevel() const;
66 virtual int64_t GetTotalTime();
67 virtual void GetAudioStreamInfo(int index, SPlayerAudioStreamInfo &info);
68 virtual int GetBitsPerSample();
69 virtual int GetSampleRate();
70 virtual int64_t GetTime();
71 virtual void SeekTime(int64_t iTime = 0);
72 virtual bool SkipNext();
74 static bool HandlesType(const CStdString &type);
76 virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job);
92 virtual void OnStartup() {}
93 virtual void Process();
94 virtual void OnExit();
98 CAudioDecoder m_decoder; /* the stream decoder */
99 int64_t m_startOffset; /* the stream start offset */
100 int64_t m_endOffset; /* the stream end offset */
101 CAEChannelInfo m_channelInfo; /* channel layout information */
102 unsigned int m_sampleRate; /* sample rate of the stream */
103 unsigned int m_encodedSampleRate; /* the encoded sample rate of raw streams */
104 enum AEDataFormat m_dataFormat; /* data format of the samples */
105 unsigned int m_bytesPerSample; /* number of bytes per audio sample */
106 unsigned int m_bytesPerFrame; /* number of bytes per audio frame */
108 bool m_started; /* if playback of this stream has been started */
109 bool m_finishing; /* if this stream is finishing */
110 int m_framesSent; /* number of frames sent to the stream */
111 int m_prepareNextAtFrame; /* when to prepare the next stream */
112 bool m_prepareTriggered; /* if the next stream has been prepared */
113 int m_playNextAtFrame; /* when to start playing the next stream */
114 bool m_playNextTriggered; /* if this stream has started the next one */
115 bool m_fadeOutTriggered; /* if the stream has been told to fade out */
116 int m_seekNextAtFrame; /* the FF/RR sample to seek at */
117 int m_seekFrame; /* the exact position to seek too, -1 for none */
119 IAEStream* m_stream; /* the playback stream */
120 float m_volume; /* the initial volume level to set the stream to on creation */
122 bool m_isSlaved; /* true if the stream has been slaved to another */
125 typedef std::list<StreamInfo*> StreamList;
127 bool m_signalSpeedChange; /* true if OnPlaybackSpeedChange needs to be called */
128 int m_playbackSpeed; /* the playback speed (1 = normal) */
131 bool m_isFinished; /* if there are no more songs in the queue */
132 unsigned int m_defaultCrossfadeMS; /* how long the default crossfade is in ms */
133 unsigned int m_upcomingCrossfadeMS; /* how long the upcoming crossfade is in ms */
134 CEvent m_startEvent; /* event for playback start */
135 StreamInfo* m_currentStream; /* the current playing stream */
136 IAudioCallback* m_audioCallback; /* the viz audio callback */
138 CFileItem* m_FileItem; /* our queued file or current file if no file is queued */
140 CSharedSection m_streamsLock; /* lock for the stream list */
141 StreamList m_streams; /* playing streams */
142 StreamList m_finishing; /* finishing streams */
146 bool QueueNextFileEx(const CFileItem &file, bool fadeIn = true, bool job = false);
147 void SoftStart(bool wait = false);
148 void SoftStop(bool wait = false, bool close = true);
149 void CloseAllStreams(bool fade = true);
150 void ProcessStreams(double &delay, double &buffer);
151 bool PrepareStream(StreamInfo *si);
152 bool ProcessStream(StreamInfo *si, double &delay, double &buffer);
153 bool QueueData(StreamInfo *si);
154 int64_t GetTotalTime64();
155 void UpdateCrossfadeTime(const CFileItem& file);
156 void UpdateStreamInfoPlayNextAtFrame(StreamInfo *si, unsigned int crossFadingTime);
157 void UpdateGUIData(StreamInfo *si);
158 int64_t GetTimeInternal();