World of Might and Magic
0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
|
См. документацию.
35 #pragma comment(lib, "avcodec.lib")
36 #pragma comment(lib, "avformat.lib")
37 #pragma comment(lib, "avutil.lib")
38 #pragma comment(lib, "swscale.lib")
39 #pragma comment(lib, "swresample.lib")
85 fprintf(stderr,
"ffmpeg: Unable to find audio stream\n");
113 std::queue<PMemBuffer, std::deque<PMemBuffer>>
queue;
143 if (!
queue.empty()) {
152 if (
res == AVERROR(EAGAIN) ||
res == AVERROR_EOF) {
161 uint8_t *dst_channels[8] = { 0 };
162 dst_channels[0] = (
uint8_t*)tmp_buf->GetData();
166 if (got_samples > 0) {
206 AV_PIX_FMT_RGB32, SWS_BICUBIC,
nullptr,
nullptr,
nullptr);
215 if (!
queue.empty()) {
224 if (
res == AVERROR(EAGAIN) ||
res == AVERROR_EOF) {
231 int linesizes[4] = { 0, 0, 0, 0 };
235 uint8_t *
data[4] = {
nullptr,
nullptr,
nullptr,
nullptr };
240 data, linesizes) < 0) {
316 bool Load(
const char *filename) {
326 fprintf(stderr,
"ffmpeg: Unable to find stream info\n");
337 Error(
"Cannot open video stream: %s", filename);
369 return Load(
"dummyFilename");
377 auto current_time = std::chrono::system_clock::now();
378 std::chrono::duration<double, std::ratio<1>> diff = current_time -
start_time;
379 std::chrono::milliseconds diff_ms = std::chrono::duration_cast<std::chrono::milliseconds>(diff);
381 start_time = std::chrono::system_clock::now();
393 AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY);
402 desired_frame_number = 0;
437 avpacket->
pts != desired_frame_number);
448 virtual bool Play(
bool loop =
false) {
449 start_time = std::chrono::system_clock::now();
465 return _this->
read(opaque,
buf, buf_size);
476 buf_size = fread(
buf, 1, buf_size,
hFile);
482 if (whence == AVSEEK_SIZE) {
518 std::chrono::time_point<std::chrono::system_clock>
start_time;
532 #pragma pack(push, 1)
543 typedef std::map<std::string, Node>
Nodes;
549 if (
file !=
nullptr) {
556 static_assert(
sizeof(
MovieHeader) == 44,
"Wrong type size");
558 if (
engine->config->NoVideo()) {
562 file = fopen(file_path.c_str(),
"rb");
563 if (
file ==
nullptr) {
564 logger->
Warning(L
"Can't open video file: %S", file_path.c_str());
567 fseek(
file, 0, SEEK_END);
568 size_t file_size = ftell(
file);
569 fseek(
file, 0, SEEK_SET);
572 fread(&uNumVideoHeaders, 1, 4,
file);
574 std::vector<MovieHeader> headers;
575 headers.resize(uNumVideoHeaders);
580 std::sort(headers.begin(), headers.end(),
582 return a.uFileOffset < b.uFileOffset;
585 for (
size_t i = 0; i < headers.size(); i++) {
589 node.
offset = headers[i].uFileOffset;
590 if (i < headers.size() - 1) {
591 node.
size = headers[i + 1].uFileOffset - headers[i].uFileOffset;
593 node.
size = file_size - headers[i].uFileOffset;
608 if (it !=
nodes.end()) {
610 offset = it->second.offset;
611 size = it->second.size;
643 if (file ==
nullptr) {
647 std::shared_ptr<Movie> pMovie = std::make_shared<Movie>();
649 pMovie_Track = std::dynamic_pointer_cast<IMovie>(pMovie);
681 memcpy(pix,
buffer->GetData(), num_pixels_bytes);
684 render->Update_Texture(tex);
685 render->DrawImage(tex, rect);
692 if (file !=
nullptr) {
693 std::shared_ptr<Movie> pMovie = std::make_shared<Movie>();
695 pMovie_Track = std::dynamic_pointer_cast<IMovie>(pMovie);
706 if (
engine->config->NoVideo()) {
713 if (file ==
nullptr) {
717 std::shared_ptr<Movie> pMovie = std::make_shared<Movie>();
718 if (!pMovie->LoadFromLOD(file,
size,
offset)) {
721 pMovie_Track = std::dynamic_pointer_cast<IMovie>(pMovie);
733 rect.
z = rect.
x + 640;
734 rect.
w = rect.
y + 480;
742 window->PeekMessageLoop();
758 memcpy(pix,
buffer->GetData(), num_pixels_bytes);
761 render->Update_Texture(tex);
762 render->DrawImage(tex, rect);
796 pVideoNameBik.begin(), ::tolower);
799 pVideoNameSmk.begin(), ::tolower);
801 FILE *file =
nullptr;
847 static int libavcodec_initialized =
false;
849 if (!libavcodec_initialized) {
856 libavcodec_initialized =
true;
890 virtual void Close();
902 std::queue<PMemBuffer, std::deque<PMemBuffer>>
queue;
917 fprintf(stderr,
"ffmpeg: Unable to find stream info\n");
926 fprintf(stderr,
"ffmpeg: Unable to find audio stream\n");
956 fprintf(stderr,
"ffmpeg: Failed to create converter\n");
1003 if (!
queue.empty()) {
1017 if (
res == AVERROR(EAGAIN) ||
res == AVERROR_EOF) {
1025 uint8_t *dst_channels[8] = {0};
1026 dst_channels[0] = (
uint8_t *)tmp_buf->GetData();
1030 if (got_samples > 0) {
1034 queue.push(tmp_buf);
1054 virtual bool Open();
1072 fprintf(stderr,
"ffmpeg: Unable to open input file\n");
1142 fprintf(stderr,
"ffmpeg: Unable to open input buffer\n");
1170 std::shared_ptr<AudioFileDataSource>
source =
1171 std::make_shared<AudioFileDataSource>(file_name);
1172 return std::dynamic_pointer_cast<IAudioDataSource, AudioFileDataSource>(
1177 std::shared_ptr<AudioBufferDataSource>
source =
1178 std::make_shared<AudioBufferDataSource>(
buffer);
1179 return std::dynamic_pointer_cast<IAudioDataSource, AudioBufferDataSource>(
int avcodec_close(AVCodecContext *avctx)
std::string sInHouseMovie
virtual unsigned int GetWidth() const
virtual PMemBuffer GetNextBuffer()
void PlayFullscreenMovie(const std::string &pMovieName)
bool LoadFromLOD(FILE *f, size_t size, size_t offset)
void OS_ShowCursor(bool show)
void av_frame_free(AVFrame **frame)
void * av_malloc(size_t size) av_malloc_attrib av_alloc_size(1)
GLsizei GLsizei GLchar * source
PMemBuffer decode_frame(AVPacket *avpacket)
EGLSurface EGLint EGLint EGLint EGLint height
attribute_deprecated void avcodec_register_all(void)
static int s_read(void *opaque, uint8_t *buf, int buf_size)
virtual ~AudioFileDataSource()
int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
std::shared_ptr< Engine > engine
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
unsigned int game_viewport_width
void av_packet_free(AVPacket **pkt)
unsigned int IMAGE_FORMAT_BytesPerPixel(IMAGE_FORMAT format)
void avformat_close_input(AVFormatContext **s)
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
virtual ~AudioBaseDataSource()
std::map< std::string, Node > Nodes
virtual unsigned int GetHeight() const
virtual size_t GetChannelCount()
unsigned int game_viewport_height
AVFrame * av_frame_alloc(void)
bool find(const std::string &video_name, FILE *&file_, size_t &offset, size_t &size)
virtual bool Play(bool loop=false)
enum CURRENT_SCREEN current_screen_type
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
int swr_init(struct SwrContext *s)
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, char *line, int line_size, int *print_prefix)
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
attribute_deprecated void av_register_all(void)
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
void Initialize(const std::string &file_path)
AudioFileDataSource(const std::string &file_name)
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
void OpenHouseMovie(const std::string &pMovieName, bool bLoop)
EGLContext EGLenum EGLClientBuffer buffer
static double av_q2d(AVRational a)
FILE * LoadMovie(const std::string &video_name, size_t &size, size_t &offset)
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
PMemBuffer AllocMemBuffer(size_t size)
std::chrono::time_point< std::chrono::system_clock > start_time
GLenum GLuint GLenum GLsizei const GLchar * buf
struct SwrContext * swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx)
StreamingTrackBuffer * CreateStreamingTrack16(int num_channels, int sample_rate, int bytes_per_sample)
virtual bool open(AVFormatContext *format_ctx)
int last_resampled_frame_num
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
void DeleteStreamingTrack(StreamingTrackBuffer **buffer)
EGLSurface EGLint EGLint EGLint width
void Warning(const wchar_t *pFormat,...)
AVFormatContext * pFormatContext
virtual bool open(AVFormatContext *format_ctx, AVMediaType type_)
virtual bool open(AVFormatContext *format_ctx)=0
bool Load(const char *filename)
EGLSurface EGLNativeWindowType * window
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
uint8_t * avio_ctx_buffer
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
AVFormatContext * avformat_alloc_context(void)
struct SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
struct SwrContext SwrContext
AVFormatContext * format_ctx
void swr_free(struct SwrContext **s)
int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in, int in_count)
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
int linesize[AV_NUM_DATA_POINTERS]
AVPacket * av_packet_alloc(void)
enum AVSampleFormat sample_fmt
sample format
virtual size_t GetSampleRate()
virtual bool IsPlaing() const
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
virtual ~AVStreamWrapper()
void Stream16(StreamingTrackBuffer *buffer, int num_samples, const void *samples, bool wait=false)
int avformat_open_input(AVFormatContext **ps, const char *url, ff_const59 AVInputFormat *fmt, AVDictionary **options)
GLuint GLenum GLenum transform
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
int ReadPacket(uint8_t *buf, int buf_size)
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
@ AV_SAMPLE_FMT_S16
signed 16 bits
GLboolean GLboolean GLboolean b
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
std::queue< PMemBuffer, std::deque< PMemBuffer > > queue
int64_t seek(void *opaque, int64_t offset, int whence)
int read(void *opaque, uint8_t *buf, int buf_size)
EGLImageKHR EGLint * name
AVIOContext * avioContext
std::string MakeDataPath(const char *file_rel_path)
void avcodec_flush_buffers(AVCodecContext *avctx)
virtual ~AudioBufferDataSource()
virtual bool open(AVFormatContext *format_ctx)
void log(const char *format,...)
AudioBufferDataSource(PMemBuffer buffer)
uint8_t * data[AV_NUM_DATA_POINTERS]
const void * GetPixels(IMAGE_FORMAT format)
size_t avio_ctx_buffer_size
GLboolean GLboolean GLboolean GLboolean a
AudioPlayer * pAudioPlayer
std::queue< PMemBuffer, std::deque< PMemBuffer > > queue
GLsizei const GLchar *const * string
static int64_t s_seek(void *opaque, int64_t offset, int whence)
enum AVPixelFormat pix_fmt
OpenALSoundProvider::StreamingTrackBuffer * audio_data_in_device
virtual PMemBuffer GetFrame()
bool IsMoviePlaying() const
PMemBuffer decode_frame(AVPacket *avpacket)
std::shared_ptr< IMemBuffer > PMemBuffer
int channels
number of audio channels
unsigned __int32 uint32_t
AVCodecContext * pCodecContext
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
int sample_rate
samples per second
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, AVCodec **decoder_ret, int flags)
std::shared_ptr< IRender > render