[WASAPI] set stream audio category
[xbmc.git] / xbmc / cores / AudioEngine / Sinks / AESinkAUDIOTRACK.h
blobdb476bb8d47bbf9d710b14f3ddb8abf71073b322
1 /*
2 * Copyright (C) 2010-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.
7 */
9 #pragma once
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"
18 #include <deque>
19 #include <set>
21 #include <androidjni/AudioTrack.h>
23 class CAESinkAUDIOTRACK : public IAESink
25 public:
26 const char* GetName() override { return "AUDIOTRACK"; }
28 CAESinkAUDIOTRACK();
29 ~CAESinkAUDIOTRACK() override;
31 bool Initialize(AEAudioFormat& format, std::string& device) override;
32 void Deinitialize() override;
33 bool IsInitialized();
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 std::unique_ptr<IAESink> Create(std::string& device, AEAudioFormat& desiredFormat);
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);
55 int AudioTrackWrite(char* audioData, int offsetInBytes, int sizeInBytes);
56 int AudioTrackWrite(char* audioData, int sizeInBytes, int64_t timestamp);
58 private:
59 jni::CJNIAudioTrack *m_at_jni;
60 int m_jniAudioFormat;
62 double m_duration_written;
63 unsigned int m_min_buffer_size;
64 uint64_t m_headPos;
65 uint64_t m_headPosOld;
66 uint32_t m_stuckCounter;
67 uint64_t m_timestampPos = 0;
68 // Moving Average computes the weighted average delay over
69 // a fixed size of delay values - current size: 20 values
70 double GetMovingAverageDelay(double newestdelay);
72 // We maintain our linear weighted average delay counter in here
73 // The n-th value (timely oldest value) is weighted with 1/n
74 // the newest value gets a weight of 1
75 std::deque<double> m_linearmovingaverage;
77 static CAEDeviceInfo m_info;
78 static CAEDeviceInfo m_info_raw;
79 static CAEDeviceInfo m_info_iec;
80 static bool m_hasIEC;
81 static std::set<unsigned int> m_sink_sampleRates;
82 static bool m_sinkSupportsFloat;
83 static bool m_sinkSupportsMultiChannelFloat;
84 static bool m_passthrough_use_eac3;
86 AEAudioFormat m_format;
87 int16_t *m_alignedS16;
88 unsigned int m_sink_frameSize;
89 unsigned int m_sink_sampleRate;
90 bool m_passthrough;
91 double m_audiotrackbuffer_sec;
92 double m_audiotrackbuffer_sec_orig;
93 int m_encoding;
94 double m_pause_ms = 0.0;
95 double m_delay = 0.0;
96 double m_hw_delay = 0.0;
97 CJNIAudioTimestamp m_timestamp;
98 XbmcThreads::EndTime<> m_stampTimer;
99 bool m_superviseAudioDelay = false;
101 std::vector<float> m_floatbuf;
102 std::vector<int16_t> m_shortbuf;
103 std::vector<char> m_charbuf;