1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/**********************************************************************
Audacity: A Digital Audio Editor
AVCodecContextWrapper.h
Dmitry Vedenko
**********************************************************************/
#pragma once
#include <memory>
#include <vector>
#include <cstdint>
#include "FFmpegTypes.h"
#include "SampleFormat.h"
struct FFmpegFunctions;
typedef struct AVCodecContext AVCodecContext;
class AVCodecWrapper;
class AVDictionaryWrapper;
class AVFrameWrapper;
class AVPacketWrapper;
class AVChannelLayoutWrapper;
class FFMPEG_SUPPORT_API AVCodecContextWrapper
{
public:
AVCodecContextWrapper(const AVCodecContextWrapper&) = delete;
AVCodecContextWrapper& operator=(AVCodecContextWrapper&) = delete;
AVCodecContextWrapper(AVCodecContextWrapper&&) = delete;
AVCodecContextWrapper& operator=(AVCodecContextWrapper&&) = delete;
AVCodecContextWrapper(const FFmpegFunctions& ffmpeg, std::unique_ptr<AVCodecWrapper> codec) noexcept;
AVCodecContextWrapper(const FFmpegFunctions& ffmpeg, AVCodecContext* wrapped) noexcept;
AVCodecContext* GetWrappedValue() noexcept;
const AVCodecContext* GetWrappedValue() const noexcept;
virtual ~AVCodecContextWrapper();
std::vector<uint8_t> DecodeAudioPacket(const AVPacketWrapper* packet);
virtual sampleFormat GetPreferredAudacitySampleFormat() const noexcept = 0;
virtual std::vector<int16_t> DecodeAudioPacketInt16(const AVPacketWrapper* packet) = 0;
virtual std::vector<float> DecodeAudioPacketFloat(const AVPacketWrapper* packet) = 0;
virtual int GetBitRate() const noexcept = 0;
virtual void SetBitRate(int value) noexcept = 0;
virtual const AVChannelLayoutWrapper* GetChannelLayout() const noexcept = 0;
virtual void SetChannelLayout(const AVChannelLayoutWrapper* value) noexcept = 0;
virtual int GetChannels() const noexcept = 0;
virtual const AVCodecWrapper* GetCodec() const noexcept = 0;
virtual AVCodecIDFwd GetCodecId() const noexcept = 0;
void SetCodecTagFourCC(const char* fourCC) noexcept;
virtual void SetCodecTag(unsigned int tag) noexcept = 0;
virtual unsigned int GetCodecTag() const noexcept = 0;
virtual AVMediaTypeFwd GetCodecType() const noexcept = 0;
virtual int GetCompressionLevel() const noexcept = 0;
virtual void SetCompressionLevel(int value) noexcept = 0;
virtual int GetCutoff() const noexcept = 0;
virtual void SetCutoff(int value) noexcept = 0;
virtual int GetFlags() const noexcept = 0;
virtual void SetFlags(int value) noexcept = 0;
virtual int GetFlags2() const noexcept = 0;
virtual void SetFlags2(int value) noexcept = 0;
virtual int GetFrameNumber() const noexcept = 0;
virtual int GetFrameSize() const noexcept = 0;
virtual void SetFrameSize(int value) noexcept = 0;
virtual int GetGlobalQuality() const noexcept = 0;
virtual void SetGlobalQuality(int value) noexcept = 0;
virtual int GetProfile() const noexcept = 0;
virtual void SetProfile(int value) noexcept = 0;
virtual AVSampleFormatFwd GetSampleFmt() const noexcept = 0;
virtual void SetSampleFmt(AVSampleFormatFwd value) noexcept = 0;
virtual int GetSampleRate() const noexcept = 0;
virtual void SetSampleRate(int value) noexcept = 0;
virtual int GetStrictStdCompliance() const noexcept = 0;
virtual void SetStrictStdCompliance(int value) noexcept = 0;
virtual struct AudacityAVRational GetTimeBase() const noexcept = 0;
virtual void SetTimeBase(struct AudacityAVRational value) noexcept = 0;
/*!
@param options A dictionary filled with AVCodecContext and
codec-private options. On return this object will be filled with
options that were not found.
@return zero if success, negative if error
*/
virtual int Open(
const AVCodecWrapper *codec, AVDictionaryWrapper *options = nullptr) = 0;
private:
void ConsumeFrame(std::vector<uint8_t>& data, AVFrameWrapper& frame);
protected:
const FFmpegFunctions& mFFmpeg;
AVCodecContext* mAVCodecContext { nullptr };
// May be created on demand to satisfy GetCodec():
mutable std::unique_ptr<AVCodecWrapper> mAVCodec;
bool mIsOwned { false };
};
|