xbmc
AESinkAUDIOTRACK.h
1 /*
2  * Copyright (C) 2010-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/AESink.h"
12 #include "cores/AudioEngine/Utils/AEDeviceInfo.h"
13 #include "cores/AudioEngine/Utils/AEUtil.h"
14 #include "threads/CriticalSection.h"
15 #include "threads/SystemClock.h"
16 #include "threads/Thread.h"
17 
18 #include <deque>
19 #include <set>
20 
21 #include <androidjni/AudioTrack.h>
22 
23 class CAESinkAUDIOTRACK : public IAESink
24 {
25 public:
26  const char* GetName() override { return "AUDIOTRACK"; }
27 
29  ~CAESinkAUDIOTRACK() override;
30 
31  bool Initialize(AEAudioFormat& format, std::string& device) override;
32  void Deinitialize() override;
33  bool IsInitialized();
34 
35  void GetDelay(AEDelayStatus& status) override;
36  double GetLatency() override;
37  double GetCacheTotal() override;
38  unsigned int AddPackets(uint8_t** data, unsigned int frames, unsigned int offset) override;
39  void AddPause(unsigned int millis) override;
40  void Drain() override;
41  static void EnumerateDevicesEx(AEDeviceInfoList &list, bool force = false);
42  static void Register();
43  static IAESink* Create(std::string &device, AEAudioFormat &desiredFormat);
44 
45 protected:
46  static jni::CJNIAudioTrack *CreateAudioTrack(int stream, int sampleRate, int channelMask, int encoding, int bufferSize);
47  static bool IsSupported(int sampleRateInHz, int channelConfig, int audioFormat);
48  static bool VerifySinkConfiguration(int sampleRate,
49  int channelMask,
50  int encoding,
51  bool isRaw = false);
52  static void UpdateAvailablePCMCapabilities();
53  static void UpdateAvailablePassthroughCapabilities(bool isRaw = false);
54 
55  int AudioTrackWrite(char* audioData, int offsetInBytes, int sizeInBytes);
56  int AudioTrackWrite(char* audioData, int sizeInBytes, int64_t timestamp);
57 
58 private:
59  jni::CJNIAudioTrack *m_at_jni;
60  int m_jniAudioFormat;
61 
62  double m_duration_written;
63  unsigned int m_min_buffer_size;
64  uint64_t m_headPos;
65  uint64_t m_timestampPos = 0;
66  // Moving Average computes the weighted average delay over
67  // a fixed size of delay values - current size: 20 values
68  double GetMovingAverageDelay(double newestdelay);
69 
70  // We maintain our linear weighted average delay counter in here
71  // The n-th value (timely oldest value) is weighted with 1/n
72  // the newest value gets a weight of 1
73  std::deque<double> m_linearmovingaverage;
74 
75  static CAEDeviceInfo m_info;
76  static CAEDeviceInfo m_info_raw;
77  static CAEDeviceInfo m_info_iec;
78  static bool m_hasIEC;
79  static std::set<unsigned int> m_sink_sampleRates;
80  static bool m_sinkSupportsFloat;
81  static bool m_sinkSupportsMultiChannelFloat;
82  static bool m_passthrough_use_eac3;
83 
84  AEAudioFormat m_format;
85  int16_t *m_alignedS16;
86  unsigned int m_sink_frameSize;
87  unsigned int m_sink_sampleRate;
88  bool m_passthrough;
89  double m_audiotrackbuffer_sec;
90  int m_encoding;
91  double m_delay = 0.0;
92  double m_hw_delay = 0.0;
93  CJNIAudioTimestamp m_timestamp;
94  XbmcThreads::EndTime<> m_stampTimer;
95 
96  std::vector<float> m_floatbuf;
97  std::vector<int16_t> m_shortbuf;
98  std::vector<char> m_charbuf;
99 };
This classt provides the details of what the audio output hardware is capable of. ...
Definition: AEDeviceInfo.h:31
Definition: SystemClock.h:31
Definition: AESink.h:18
The audio format structure that fully defines a stream&#39;s audio information.
Definition: AEAudioFormat.h:19
void GetDelay(AEDelayStatus &status) override
Return a timestamped status structure with delay and sink info.
Definition: AESinkAUDIOTRACK.cpp:658
Definition: AEUtil.h:27
unsigned int AddPackets(uint8_t **data, unsigned int frames, unsigned int offset) override
Adds packets to be sent out, this routine MUST block or sleep.
Definition: AESinkAUDIOTRACK.cpp:809
void AddPause(unsigned int millis) override
instruct the sink to add a pause
Definition: AESinkAUDIOTRACK.cpp:937
Definition: AESinkAUDIOTRACK.h:23