kodi
ActiveAEBuffer.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/Utils/AEAudioFormat.h"
12 #include "cores/AudioEngine/Interfaces/AE.h"
13 #include <cmath>
14 #include <deque>
15 #include <memory>
16 
17 extern "C" {
18 #include <libavutil/avutil.h>
19 #include <libswresample/swresample.h>
20 }
21 
22 namespace ActiveAE
23 {
24 
29 {
30 public:
31  CSoundPacket(const SampleConfig& conf, int samples);
32  ~CSoundPacket();
33  uint8_t **data; // array with pointers to planes of data
35  int bytes_per_sample; // bytes per sample and per channel
36  int linesize; // see ffmpeg, required for planar formats
37  int planes; // 1 for non planar formats, #channels for planar
38  int nb_samples; // number of frames used
39  int max_nb_samples; // max number of frames this packet can hold
40  int pause_burst_ms;
41 };
42 
44 
46 {
47 public:
48  CSampleBuffer() = default;
49  ~CSampleBuffer() = default;
50  CSampleBuffer *Acquire();
51  void Return();
52  std::unique_ptr<CSoundPacket> pkt;
53  CActiveAEBufferPool *pool = nullptr;
54  int64_t timestamp;
55  int pkt_start_offset = 0;
56  int refCount = 0;
57  double centerMixLevel;
58 };
59 
61 {
62 public:
63  explicit CActiveAEBufferPool(const AEAudioFormat& format);
64  virtual ~CActiveAEBufferPool();
65  virtual bool Create(unsigned int totaltime);
66  CSampleBuffer *GetFreeBuffer();
67  void ReturnBuffer(CSampleBuffer *buffer);
68  AEAudioFormat m_format;
69  std::deque<CSampleBuffer*> m_allSamples;
70  std::deque<CSampleBuffer*> m_freeSamples;
71 };
72 
73 class IAEResample;
74 
76 {
77 public:
78  CActiveAEBufferPoolResample(const AEAudioFormat& inputFormat, const AEAudioFormat& outputFormat, AEQuality quality);
79  ~CActiveAEBufferPoolResample() override;
80  using CActiveAEBufferPool::Create;
81  bool Create(unsigned int totaltime, bool remap, bool upmix, bool normalize = true);
82  bool ResampleBuffers(int64_t timestamp = 0);
83  void ConfigureResampler(bool normalizelevels, bool stereoupmix, AEQuality quality);
84  float GetDelay();
85  void Flush();
86  void SetDrain(bool drain);
87  void SetRR(double rr);
88  double GetRR() const;
89  void FillBuffer();
90  bool DoesNormalize() const;
91  void ForceResampler(bool force);
92  AEAudioFormat m_inputFormat;
93  std::deque<CSampleBuffer*> m_inputSamples;
94  std::deque<CSampleBuffer*> m_outputSamples;
95 
96 protected:
97  void ChangeResampler();
98 
99  uint8_t *m_planes[16];
100  bool m_empty = true;
101  bool m_drain = false;
102  int64_t m_lastSamplePts = 0;
103  bool m_remap = false;
104  CSampleBuffer *m_procSample = nullptr;
105  std::unique_ptr<IAEResample> m_resampler;
106  double m_resampleRatio = 1.0;
107  double m_centerMixLevel = M_SQRT1_2;
108  bool m_fillPackets = false;
109  bool m_normalize = true;
110  bool m_changeResampler = false;
111  bool m_forceResampler = false;
112  AEQuality m_resampleQuality;
113  bool m_stereoUpmix = false;
114 };
115 
116 class CActiveAEFilter;
117 
119 {
120 public:
121  explicit CActiveAEBufferPoolAtempo(const AEAudioFormat& format);
122  ~CActiveAEBufferPoolAtempo() override;
123  bool Create(unsigned int totaltime) override;
124  bool ProcessBuffers();
125  float GetDelay();
126  void Flush();
127  void SetTempo(float tempo);
128  float GetTempo() const;
129  void FillBuffer();
130  void SetDrain(bool drain);
131  std::deque<CSampleBuffer*> m_inputSamples;
132  std::deque<CSampleBuffer*> m_outputSamples;
133 
134 protected:
135  void ChangeFilter();
136  std::unique_ptr<CActiveAEFilter> m_pTempoFilter;
137  uint8_t *m_planes[16];
138  CSampleBuffer *m_procSample;
139  bool m_empty;
140  bool m_drain;
141  bool m_changeFilter;
142  float m_tempo;
143  int64_t m_lastSamplePts;
144  bool m_fillPackets;
145 };
146 
147 }
Definition: deflate.c:123
Definition: ActiveAEFilter.h:21
the variables here follow ffmpeg naming
Definition: ActiveAEBuffer.h:28
Definition: ActiveAEBuffer.h:75
Definition: Application.h:67
Definition: AE.h:68
The audio format structure that fully defines a stream&#39;s audio information.
Definition: AEAudioFormat.h:19
Definition: ActiveAEBuffer.h:60
Definition: ActiveAEBuffer.h:118
Definition: ActiveAEBuffer.h:45
Definition: AEResample.h:16