xbmc
AEEncoderFFmpeg.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/AEEncoder.h"
12 
13 extern "C" {
14 #include <libswresample/swresample.h>
15 }
16 
17 /* ffmpeg re-defines this, so undef it to squash the warning */
18 #undef restrict
19 
21 {
22 public:
24  ~CAEEncoderFFmpeg() override;
25 
26  bool IsCompatible(const AEAudioFormat& format) override;
27  bool Initialize(AEAudioFormat &format, bool allow_planar_input = false) override;
28  void Reset() override;
29 
30  unsigned int GetBitRate() override;
31  AVCodecID GetCodecID() override;
32  unsigned int GetFrames() override;
33 
34  int Encode(uint8_t *in, int in_size, uint8_t *out, int out_size) override;
35  int GetData(uint8_t **data) override;
36  double GetDelay(unsigned int bufferSize) override;
37 private:
38  unsigned int BuildChannelLayout(const int64_t ffmap, CAEChannelInfo& layout);
39 
40  std::string m_CodecName;
41  AVCodecID m_CodecID;
42  unsigned int m_BitRate = 0;
43  AEAudioFormat m_CurrentFormat;
44  AVCodecContext *m_CodecCtx;
45  SwrContext *m_SwrCtx;
46  CAEChannelInfo m_Layout;
47  uint8_t m_Buffer[8 + AV_INPUT_BUFFER_MIN_SIZE];
48  int m_BufferSize = 0;
49  int m_OutputSize = 0;
50  double m_OutputRatio = 0.0;
51  double m_SampleRateMul = 0.0;
52  unsigned int m_NeededFrames = 0;
53  bool m_NeedConversion = false;
54 };
55 
unsigned int GetBitRate() override
Returns the bitrate of the encoder.
Definition: AEEncoderFFmpeg.cpp:247
IAEEncoder interface for on the fly audio compression.
Definition: AEEncoder.h:20
double GetDelay(unsigned int bufferSize) override
Get the delay in seconds.
Definition: AEEncoderFFmpeg.cpp:351
bool Initialize(AEAudioFormat &format, bool allow_planar_input=false) override
Called to setup the encoder to accept data in the specified format.
Definition: AEEncoderFFmpeg.cpp:90
void Reset() override
Reset the encoder for new data.
Definition: AEEncoderFFmpeg.cpp:242
unsigned int GetFrames() override
Return the number of frames needed to encode.
Definition: AEEncoderFFmpeg.cpp:257
The audio format structure that fully defines a stream&#39;s audio information.
Definition: AEAudioFormat.h:19
int GetData(uint8_t **data) override
Get the encoded data.
Definition: AEEncoderFFmpeg.cpp:342
int Encode(uint8_t *in, int in_size, uint8_t *out, int out_size) override
Encodes the supplied samples into a provided buffer.
Definition: AEEncoderFFmpeg.cpp:262
Definition: AEEncoderFFmpeg.h:20
Definition: AEChannelInfo.h:19
AVCodecID GetCodecID() override
Returns the AVCodecID of the encoder.
Definition: AEEncoderFFmpeg.cpp:252
bool IsCompatible(const AEAudioFormat &format) override
Return true if the supplied format is compatible with the current open encoder.
Definition: AEEncoderFFmpeg.cpp:44