2012-03-17 06:59:21 +00:00
|
|
|
#ifndef GAME_SOUND_FFMPEG_DECODER_H
|
|
|
|
#define GAME_SOUND_FFMPEG_DECODER_H
|
|
|
|
|
2022-01-22 21:44:02 +00:00
|
|
|
#include <cstdint>
|
2021-05-02 08:59:22 +00:00
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4244)
|
|
|
|
#endif
|
|
|
|
|
2012-03-17 06:59:21 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2012-12-01 19:53:28 +00:00
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavformat/avformat.h>
|
2018-10-20 07:09:52 +00:00
|
|
|
#include <libavutil/channel_layout.h>
|
2014-09-11 11:15:18 +00:00
|
|
|
|
|
|
|
// From version 54.56 binkaudio encoding format changed from S16 to FLTP. See:
|
|
|
|
// https://gitorious.org/ffmpeg/ffmpeg/commit/7bfd1766d1c18f07b0a2dd042418a874d49ea60d
|
2018-03-08 20:23:24 +00:00
|
|
|
// https://ffmpeg.zeranoe.com/forum/viewtopic.php?f=15&t=872
|
2014-09-11 11:15:18 +00:00
|
|
|
#include <libswresample/swresample.h>
|
2012-03-17 06:59:21 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 08:59:22 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2022-07-16 16:19:56 +00:00
|
|
|
#include <components/files/istreamptr.hpp>
|
2015-04-13 20:48:37 +00:00
|
|
|
|
2013-05-26 08:36:17 +00:00
|
|
|
#include <string>
|
|
|
|
|
2012-03-17 06:59:21 +00:00
|
|
|
#include "sound_decoder.hpp"
|
|
|
|
|
|
|
|
namespace MWSound
|
|
|
|
{
|
2017-12-08 15:00:04 +00:00
|
|
|
class FFmpeg_Decoder final : public Sound_Decoder
|
2012-03-17 06:59:21 +00:00
|
|
|
{
|
2012-03-20 23:45:01 +00:00
|
|
|
AVFormatContext* mFormatCtx;
|
2018-10-20 07:09:52 +00:00
|
|
|
AVCodecContext* mCodecCtx;
|
2012-12-16 07:46:32 +00:00
|
|
|
AVStream** mStream;
|
|
|
|
|
|
|
|
AVPacket mPacket;
|
|
|
|
AVFrame* mFrame;
|
|
|
|
|
|
|
|
int mFrameSize;
|
|
|
|
int mFramePos;
|
2012-03-20 23:45:01 +00:00
|
|
|
|
2012-12-16 09:56:52 +00:00
|
|
|
double mNextPts;
|
2012-03-20 23:45:01 +00:00
|
|
|
|
2014-09-11 11:15:18 +00:00
|
|
|
SwrContext* mSwr;
|
|
|
|
enum AVSampleFormat mOutputSampleFormat;
|
2014-10-25 15:17:57 +00:00
|
|
|
int64_t mOutputChannelLayout;
|
2014-09-11 11:15:18 +00:00
|
|
|
uint8_t* mDataBuf;
|
|
|
|
uint8_t** mFrameData;
|
|
|
|
int mDataBufLen;
|
|
|
|
|
2012-12-16 06:13:19 +00:00
|
|
|
bool getNextPacket();
|
2012-03-20 23:45:01 +00:00
|
|
|
|
2015-04-13 20:48:37 +00:00
|
|
|
Files::IStreamPtr mDataStream;
|
|
|
|
|
2012-03-20 23:45:01 +00:00
|
|
|
static int readPacket(void* user_data, uint8_t* buf, int buf_size);
|
|
|
|
static int writePacket(void* user_data, uint8_t* buf, int buf_size);
|
|
|
|
static int64_t seek(void* user_data, int64_t offset, int whence);
|
|
|
|
|
2012-12-16 07:46:32 +00:00
|
|
|
bool getAVAudioData();
|
|
|
|
size_t readAVAudioData(void* data, size_t length);
|
|
|
|
|
2017-12-09 19:00:56 +00:00
|
|
|
void open(const std::string& fname) override;
|
2017-12-08 15:00:04 +00:00
|
|
|
void close() override;
|
2012-03-17 06:59:21 +00:00
|
|
|
|
2017-12-08 15:00:04 +00:00
|
|
|
std::string getName() override;
|
2017-12-09 19:00:56 +00:00
|
|
|
void getInfo(int* samplerate, ChannelConfig* chans, SampleType* type) override;
|
2012-03-19 15:48:25 +00:00
|
|
|
|
2017-12-08 15:00:04 +00:00
|
|
|
size_t read(char* buffer, size_t bytes) override;
|
|
|
|
void readAll(std::vector<char>& output) override;
|
|
|
|
size_t getSampleOffset() override;
|
2014-03-16 22:38:51 +00:00
|
|
|
|
2012-03-24 10:49:03 +00:00
|
|
|
FFmpeg_Decoder& operator=(const FFmpeg_Decoder& rhs);
|
|
|
|
FFmpeg_Decoder(const FFmpeg_Decoder& rhs);
|
|
|
|
|
2012-03-20 21:13:58 +00:00
|
|
|
public:
|
2021-01-08 21:18:37 +00:00
|
|
|
explicit FFmpeg_Decoder(const VFS::Manager* vfs);
|
|
|
|
|
2012-03-17 06:59:21 +00:00
|
|
|
virtual ~FFmpeg_Decoder();
|
|
|
|
|
|
|
|
friend class SoundManager;
|
|
|
|
};
|
2012-10-17 16:03:02 +00:00
|
|
|
}
|
2012-03-17 06:59:21 +00:00
|
|
|
|
|
|
|
#endif
|