kodi
AudioSinkAE.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 "cores/AudioEngine/Interfaces/AE.h"
12 #include "cores/AudioEngine/Interfaces/AEStream.h"
13 #include "cores/AudioEngine/Utils/AEChannelInfo.h"
14 #include "threads/CriticalSection.h"
15 
16 #include <atomic>
17 #include <mutex>
18 
19 #include "PlatformDefs.h"
20 
21 extern "C" {
22 #include <libavcodec/avcodec.h>
23 }
24 
25 typedef struct stDVDAudioFrame DVDAudioFrame;
26 
27 class CDVDClock;
28 
30 {
31 public:
32  explicit CAudioSinkAE(CDVDClock *clock);
33  ~CAudioSinkAE() override;
34 
35  void SetVolume(float fVolume);
36  void SetDynamicRangeCompression(long drc);
37  void Pause();
38  void Resume();
39  bool Create(const DVDAudioFrame &audioframe, AVCodecID codec, bool needresampler);
40  bool IsValidFormat(const DVDAudioFrame &audioframe);
41  void Destroy(bool finish);
42  unsigned int AddPackets(const DVDAudioFrame &audioframe);
43  double GetPlayingPts();
44  double GetCacheTime();
45  double GetCacheTotal(); // returns total time a stream can buffer
46  double GetMaxDelay(); // returns total time of audio in AE for the stream
47  double GetDelay(); // returns the time it takes to play a packet if we add one at this time
48  double GetSyncError();
49  void SetSyncErrorCorrection(double correction);
50 
54  double GetResampleRatio();
55 
56  void SetResampleMode(int mode);
57  void Flush();
58  void Drain();
59  void AbortAddPackets();
60 
61  double GetClock() override;
62  double GetClockSpeed() override;
63 
64  CAEStreamInfo::DataType GetPassthroughStreamType(AVCodecID codecId, int samplerate, int profile);
65 
66 protected:
67  IAE::StreamPtr m_pAudioStream;
68  double m_playingPts;
69  double m_timeOfPts;
70  double m_syncError;
71  unsigned int m_syncErrorTime;
72  double m_resampleRatio = 0.0; // invalid
73  CCriticalSection m_critSection;
74 
75  AEDataFormat m_dataFormat;
76  unsigned int m_sampleRate;
77  int m_iBitsPerSample;
78  bool m_bPassthrough;
79  CAEChannelInfo m_channelLayout;
80  CAEStreamInfo::DataType m_dataType;
81  bool m_bPaused;
82 
83  std::atomic_bool m_bAbort;
84  CDVDClock *m_pClock;
85 };
Callback interface for VideoPlayer clock needed by AE for sync.
Definition: AEStream.h:23
Definition: AudioSinkAE.h:29
Definition: DVDAudioCodec.h:27
double GetResampleRatio()
Returns the resample ratio, or 0.0 if unknown/invalid.
Definition: AudioSinkAE.cpp:305
Definition: DVDClock.h:18
Definition: AEChannelInfo.h:19