Merge pull request #4878 from FernetMenta/xfade
[vuplus_xbmc] / xbmc / cores / AudioEngine / Engines / ActiveAE / ActiveAEBuffer.h
1 #pragma once
2 /*
3  *      Copyright (C) 2010-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "DllAvUtil.h"
23 #include "DllSwResample.h"
24 #include "cores/AudioEngine/Utils/AEAudioFormat.h"
25 #include "cores/AudioEngine/Interfaces/AE.h"
26 #include <deque>
27
28 namespace ActiveAE
29 {
30
31 struct SampleConfig
32 {
33   AVSampleFormat fmt;
34   uint64_t channel_layout;
35   int channels;
36   int sample_rate;
37   int bits_per_sample;
38 };
39
40 /**
41  * the variables here follow ffmpeg naming
42  */
43 class CSoundPacket
44 {
45 public:
46   CSoundPacket(SampleConfig conf, int samples);
47   ~CSoundPacket();
48   uint8_t **data;                        // array with pointers to planes of data
49   SampleConfig config;
50   AEDataFormat internal_format;          // used when carrying pass through
51   int bytes_per_sample;                  // bytes per sample and per channel
52   int linesize;                          // see ffmpeg, required for planar formats
53   int planes;                            // 1 for non planar formats, #channels for planar
54   int nb_samples;                        // number of frames used
55   int max_nb_samples;                    // max number of frames this packet can hold
56 };
57
58 class CActiveAEBufferPool;
59
60 class CSampleBuffer
61 {
62 public:
63   CSampleBuffer();
64   ~CSampleBuffer();
65   CSampleBuffer *Acquire();
66   void Return();
67   CSoundPacket *pkt;
68   CActiveAEBufferPool *pool;
69   unsigned int timestamp;
70   int refCount;
71 };
72
73 class CActiveAEBufferPool
74 {
75 public:
76   CActiveAEBufferPool(AEAudioFormat format);
77   virtual ~CActiveAEBufferPool();
78   virtual bool Create(unsigned int totaltime);
79   CSampleBuffer *GetFreeBuffer();
80   void ReturnBuffer(CSampleBuffer *buffer);
81   AEAudioFormat m_format;
82   std::deque<CSampleBuffer*> m_allSamples;
83   std::deque<CSampleBuffer*> m_freeSamples;
84 };
85
86 class CActiveAEResample;
87
88 class CActiveAEBufferPoolResample : public CActiveAEBufferPool
89 {
90 public:
91   CActiveAEBufferPoolResample(AEAudioFormat inputFormat, AEAudioFormat outputFormat, AEQuality quality);
92   virtual ~CActiveAEBufferPoolResample();
93   virtual bool Create(unsigned int totaltime, bool remap, bool upmix, bool normalize = true);
94   void ChangeResampler();
95   bool ResampleBuffers(unsigned int timestamp = 0);
96   float GetDelay();
97   void Flush();
98   AEAudioFormat m_inputFormat;
99   std::deque<CSampleBuffer*> m_inputSamples;
100   std::deque<CSampleBuffer*> m_outputSamples;
101   CSampleBuffer *m_procSample;
102   CActiveAEResample *m_resampler;
103   uint8_t *m_planes[16];
104   bool m_fillPackets;
105   bool m_drain;
106   bool m_empty;
107   bool m_changeResampler;
108   double m_resampleRatio;
109   AEQuality m_resampleQuality;
110   bool m_stereoUpmix;
111   bool m_normalize;
112 };
113
114 }