19 const FFmpegFunctions& ffmpeg, std::unique_ptr<AVCodecWrapper> codec) noexcept
21 , mAVCodec(std::move(codec))
25 mFFmpeg.avcodec_alloc_context3(mAVCodec->GetWrappedValue());
31 , mAVCodecContext(wrapped)
71 std::vector<uint8_t> data;
75 std::unique_ptr<AVPacketWrapper> packetCopy =
84 bool flushing = packet
85 ? (packetCopy->GetSize() == 0 && packetCopy->GetData() ==
nullptr)
87 if (!flushing && packetCopy->GetData() ==
nullptr)
98 packetCopy->GetWrappedValue());
100 if (bytesDecoded < 0)
113 packetCopy->OffsetPacket(bytesDecoded);
119 packetCopy->OffsetPacket(bytesDecoded);
121 while ( flushing ? bytesDecoded > 0 : packetCopy->GetSize() > 0 );
159 const auto frameSize = channels * sampleSize * samplesCount;
161 auto oldSize = data.size();
162 data.resize(oldSize + frameSize);
163 auto pData = &data[oldSize];
165 if (frame.
GetData(1) !=
nullptr)
168 for (
int channel = 0; channel < channels; channel++)
170 for (
int sample = 0; sample < samplesCount; sample++)
172 const uint8_t* channelData =
176 pData + sampleSize * (channels * sample + channel);
178 std::copy(channelData, channelData + sampleSize, output);
184 uint8_t* frameData = frame.
GetData(0);
185 std::copy(frameData, frameData + frameSize, pData);
191unsigned int MakeTag(
char a,
char b,
char c,
char d)
noexcept
194 (
static_cast<unsigned>(a) << 0) | (
static_cast<unsigned>(b) << 8) |
195 (
static_cast<unsigned>(c) << 16) | (
static_cast<unsigned>(d) << 24);
201 if (fourCC ==
nullptr || std::strlen(fourCC) != 4)
204 SetCodecTag(
MakeTag(fourCC[0], fourCC[1], fourCC[2], fourCC[3]));
#define AUDACITY_AVERROR(e)
#define AUDACITY_AVERROR_EOF
AVCodecContext * mAVCodecContext
virtual ~AVCodecContextWrapper()
AVCodecContext * GetWrappedValue() noexcept
const FFmpegFunctions & mFFmpeg
AVCodecContextWrapper(const AVCodecContextWrapper &)=delete
virtual int GetChannels() const noexcept=0
std::vector< uint8_t > DecodeAudioPacket(const AVPacketWrapper *packet)
void SetCodecTagFourCC(const char *fourCC) noexcept
void ConsumeFrame(std::vector< uint8_t > &data, AVFrameWrapper &frame)
virtual AVSampleFormatFwd GetFormat() const noexcept=0
virtual int GetSamplesCount() const noexcept=0
virtual uint8_t * GetData(int index) const noexcept=0
virtual uint8_t * GetExtendedData(int index) const noexcept=0
AVPacket * GetWrappedValue() noexcept
virtual std::unique_ptr< AVPacketWrapper > Clone() const noexcept=0
unsigned int MakeTag(char a, char b, char c, char d) noexcept
void copy(const T *src, T *dst, int32_t n)
int(* avcodec_close)(AVCodecContext *avctx)
int(* avcodec_receive_frame)(AVCodecContext *avctx, AVFrame *frame)
int(* avcodec_send_packet)(AVCodecContext *avctx, const AVPacket *avpkt)
int(* avcodec_is_open)(AVCodecContext *avctx)
int(* avcodec_decode_audio4)(AVCodecContext *avctx, AVFrame *frame, int *got_output, const AVPacket *avpkt)
void(* avcodec_free_context)(AVCodecContext **avctx)
int(* av_get_bytes_per_sample)(AVSampleFormatFwd sample_fmt)
std::unique_ptr< AVFrameWrapper > CreateAVFrameWrapper() const
std::unique_ptr< AVPacketWrapper > CreateAVPacketWrapper() const