kodi
VideoPlayerAudio.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "AudioSinkAE.h"
12 #include "DVDClock.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"
20 
21 #include <list>
22 #include <mutex>
23 #include <utility>
24 
25 
26 class CVideoPlayer;
27 class CDVDAudioCodec;
28 class CDVDAudioCodec;
29 
31 {
32 public:
33  CVideoPlayerAudio(CDVDClock* pClock, CDVDMessageQueue& parent, CProcessInfo &processInfo);
34  ~CVideoPlayerAudio() override;
35 
36  bool OpenStream(CDVDStreamInfo hints) override;
37  void CloseStream(bool bWaitForBuffers) override;
38 
39  void SetSpeed(int speed) override;
40  void Flush(bool sync) override;
41 
42  // waits until all available data has been rendered
43  bool AcceptsData() const override;
44  bool HasData() const override { return m_messageQueue.GetDataSize() > 0; }
45  int GetLevel() const override { return m_messageQueue.GetLevel(); }
46  bool IsInited() const override { return m_messageQueue.IsInited(); }
47  void SendMessage(std::shared_ptr<CDVDMsg> pMsg, int priority = 0) override
48  {
49  m_messageQueue.Put(pMsg, priority);
50  }
51  void FlushMessages() override { m_messageQueue.Flush(); }
52 
53  void SetDynamicRangeCompression(long drc) override { m_audioSink.SetDynamicRangeCompression(drc); }
54  float GetDynamicRangeAmplification() const override { return 0.0f; }
55 
56  std::string GetPlayerInfo() override;
57  int GetAudioChannels() override;
58 
59  double GetCurrentPts() override
60  {
61  std::unique_lock<CCriticalSection> lock(m_info_section);
62  return m_info.pts;
63  }
64 
65  bool IsStalled() const override { return m_stalled; }
66  bool IsPassthrough() const override;
67 
68 protected:
69 
70  void OnStartup() override;
71  void OnExit() override;
72  void Process() override;
73 
74  bool ProcessDecoderOutput(DVDAudioFrame &audioframe);
75  void UpdatePlayerInfo();
76  void OpenStream(CDVDStreamInfo& hints, std::unique_ptr<CDVDAudioCodec> codec);
79  bool SwitchCodecIfNeeded();
80  void SetSyncType(bool passthrough);
81 
82  CDVDMessageQueue m_messageQueue;
83  CDVDMessageQueue& m_messageParent;
84 
85  // holds stream information for current playing stream
86  CDVDStreamInfo m_streaminfo;
87 
88  double m_audioClock;
89 
90  CAudioSinkAE m_audioSink; // audio output device
91  CDVDClock* m_pClock; // dvd master clock
92  std::unique_ptr<CDVDAudioCodec> m_pAudioCodec; // audio codec
93  BitstreamStats m_audioStats;
94 
95  int m_speed;
96  bool m_stalled;
97  bool m_paused;
98  IDVDStreamPlayer::ESyncState m_syncState;
99  XbmcThreads::EndTime<> m_syncTimer;
100 
101  int m_synctype;
102  int m_prevsynctype;
103 
104  bool m_prevskipped;
105  double m_maxspeedadjust;
106 
107  struct SInfo
108  {
109  std::string info;
110  double pts = DVD_NOPTS_VALUE;
111  bool passthrough = false;
112  };
113 
114  mutable CCriticalSection m_info_section;
115  SInfo m_info;
116 
117  bool m_displayReset = false;
118  unsigned int m_disconAdjustTimeMs = 10; // maximum sync-off before adjusting
119  int m_disconAdjustCounter = 0;
120  XbmcThreads::EndTime<> m_disconTimer;
121  bool m_disconLearning = false;
122 };
123 
Definition: DVDStreamInfo.h:25
bool SwitchCodecIfNeeded()
Switch codec if needed.
Definition: VideoPlayerAudio.cpp:671
Definition: VideoPlayer.h:250
Definition: Thread.h:44
Definition: VideoPlayerAudio.h:30
Definition: DVDMessageQueue.h:48
Definition: SystemClock.h:31
Definition: AudioSinkAE.h:29
Definition: BitstreamStats.h:13
Definition: ProcessInfo.h:26
Definition: DVDAudioCodec.h:27
Definition: DVDClock.h:18
Definition: DVDAudioCodec.h:48
Definition: IVideoPlayer.h:102
Definition: VideoPlayerAudio.h:107