1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 21:32:42 +00:00
OpenMW/apps/openmw/mwsound/ffmpeg_decoder.hpp
AnyOldName3 28131fd62b Fixes for a whole bunch of warnings
These warnings were always enabled, but we didn't see them due to https://gitlab.com/OpenMW/openmw/-/issues/7882.
I do not fully understand the cause of 7822 as I can't repro it in a minimal CMake project.

Some of these fixes are thought through.
Some are sensible best guesses.
Some are kind of a stab in the dark as I don't know whether there was a
possible bug the warning was telling me about that I've done nothing to
help by introducing a static_cast.

Nearly all of these warnings were about some kind of narrowing
conversion, so I'm not sure why they weren't firing with GCC and Clang,
which have -Wall -Wextra -pedantic set, which should imply -Wnarrowing,
and they can't have been affected by 7882.

There were also some warnings being triggered from Boost code.
The vast majority of library headers that do questionable things weren't
firing warnings off, but for some reason, /external:I wasn't putting
these Boost headers into external mode.

We need these warnings dealt with one way or another so we can switch
the default Windows CI from MSBuild (which doesn't do ccache) to Ninja
(which does).
I have the necessary magic for that on a branch, but the branch won't
build because of these warnings.
2024-03-14 23:39:33 +00:00

90 lines
2.2 KiB
C++

#ifndef GAME_SOUND_FFMPEG_DECODER_H
#define GAME_SOUND_FFMPEG_DECODER_H
#include <cstdint>
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4244)
#endif
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/channel_layout.h>
// From version 54.56 binkaudio encoding format changed from S16 to FLTP. See:
// https://gitorious.org/ffmpeg/ffmpeg/commit/7bfd1766d1c18f07b0a2dd042418a874d49ea60d
// https://ffmpeg.zeranoe.com/forum/viewtopic.php?f=15&t=872
#include <libswresample/swresample.h>
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#include <components/files/istreamptr.hpp>
#include <string>
#include "sound_decoder.hpp"
namespace MWSound
{
class FFmpeg_Decoder final : public Sound_Decoder
{
AVFormatContext* mFormatCtx;
AVCodecContext* mCodecCtx;
AVStream** mStream;
AVPacket mPacket;
AVFrame* mFrame;
std::size_t mFrameSize;
std::size_t mFramePos;
double mNextPts;
SwrContext* mSwr;
enum AVSampleFormat mOutputSampleFormat;
int64_t mOutputChannelLayout;
uint8_t* mDataBuf;
uint8_t** mFrameData;
int mDataBufLen;
bool getNextPacket();
Files::IStreamPtr mDataStream;
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);
bool getAVAudioData();
size_t readAVAudioData(void* data, size_t length);
void open(const std::string& fname) override;
void close() override;
std::string getName() override;
void getInfo(int* samplerate, ChannelConfig* chans, SampleType* type) override;
size_t read(char* buffer, size_t bytes) override;
void readAll(std::vector<char>& output) override;
size_t getSampleOffset() override;
FFmpeg_Decoder& operator=(const FFmpeg_Decoder& rhs);
FFmpeg_Decoder(const FFmpeg_Decoder& rhs);
public:
explicit FFmpeg_Decoder(const VFS::Manager* vfs);
virtual ~FFmpeg_Decoder();
friend class SoundManager;
};
}
#endif