Mercurial > mm7
diff VideoPlayer.h @ 2137:d24ee391fd1f
libavcodec playing movies and houses, loops not working yet
author | zipi |
---|---|
date | Wed, 01 Jan 2014 13:43:09 +0000 |
parents | 992d2e6f907d |
children | ca548138d6aa |
line wrap: on
line diff
--- a/VideoPlayer.h Tue Dec 31 23:03:01 2013 +0600 +++ b/VideoPlayer.h Wed Jan 01 13:43:09 2014 +0000 @@ -5,6 +5,7 @@ + #pragma pack(push, 1) @@ -318,7 +319,7 @@ return false; } }; -typedef OpenALSoundProviderGeneric<16> OpenALSoundProvider; +typedef OpenALSoundProviderGeneric<64> OpenALSoundProvider; @@ -513,6 +514,9 @@ } }; +int readFunction(void* opaque, uint8_t* buf, int buf_size); + +int64_t seekFunction(void* opaque, int64_t offset, int whence); template<int NUM_PRECACHED_FRAMES> class MovieCached @@ -543,7 +547,37 @@ { this->width = width; this->height = height; + +/* for (uint i = 0; i < pVideoPlayer->uNumMagicVideoHeaders; ++i) + if (!_stricmp(video_filename, pVideoPlayer->pMagicVideoHeaders[i].pVideoName)) + { + SetFilePointer(pVideoPlayer->hMagicVid, pVideoPlayer->pMagicVideoHeaders[i].uFileOffset, 0, FILE_BEGIN); + break; + } +*/ packet = nullptr; + int ioBufferSize = 32768; + void *src; + + unsigned char * ioBuffer = (unsigned char *)av_malloc(ioBufferSize + FF_INPUT_BUFFER_PADDING_SIZE); // can get av_free()ed by libav + if (pVideoPlayer->uVidFile) + { + src = (void*)pVideoPlayer->hMagicVid; + } + else + { + src = (void*)pVideoPlayer->hMightVid; + } + avioContext = avio_alloc_context(ioBuffer, ioBufferSize, 0, src, &readFunction, NULL, &seekFunction); + //offset = SetFilePointer(pVideoPlayer->hMagicVid,0,0,FILE_CURRENT); + LARGE_INTEGER li, li2; + PLARGE_INTEGER pli = &li2; + li.QuadPart = 0; + SetFilePointerEx(pVideoPlayer->hMagicVid, li, pli, FILE_CURRENT); + offset = pli->QuadPart; + + format_ctx = avformat_alloc_context(); + format_ctx->pb = avioContext; if (avformat_open_input(&format_ctx, video_filename, nullptr, nullptr) >= 0) { if (avformat_find_stream_info(format_ctx, nullptr) >= 0) @@ -623,6 +657,26 @@ return -1; } + void Rewind() + { + //auto i=avio_seek(avioContext, pVideoPlayer->uOffset, 0); + //auto i = av_seek_frame(format_ctx, -1, 0, AVSEEK_FLAG_BYTE); + //i = av_seek_frame(format_ctx, audio_stream_idx, 0, AVSEEK_FLAG_BYTE); + + int64_t timestamp = 9; + int ret, i; + if (format_ctx->start_time != AV_NOPTS_VALUE) + timestamp += format_ctx->start_time; + ret = av_seek_frame(format_ctx, -1, format_ctx->start_time, AVSEEK_FLAG_BYTE); + if (ret < 0) { +// av_log(ctx, AV_LOG_ERROR, "Unable to loop: %s\n", av_err2str(ret)); + //loop_count = 1; /* do not try again */ + return;// ret; + } + + + stopped = false; + } MultimediaFrame::Ptr GetNextFrame() { @@ -668,6 +722,8 @@ AVStream *audio_stream; AVCodec *audio_stream_dec; AVCodecContext *audio_stream_dec_ctx; + AVIOContext * avioContext; + int64_t offset; }; typedef MovieCached<10> Movie; @@ -715,6 +771,10 @@ return nullptr; } + inline void Rewind() + { + current_movie->Rewind(); + } inline char *DoFrame() { @@ -729,6 +789,7 @@ if (frame->Type() == AVMEDIA_TYPE_AUDIO) { + //continue; uint8_t *data; if (frame->Decode() >= 0) { @@ -819,7 +880,7 @@ unsigned int uNumMightVideoHeaders; unsigned int uNumMagicVideoHeaders; int uBinkDirectDrawSurfaceType; - int field_54; + int bBufferLoaded; unsigned int bPlayingMovie; unsigned int bFirstFrame; unsigned int bUsingSmackerMMX; @@ -835,10 +896,15 @@ _BINKBUF *pBinkBuffer; char field_88[20]; unsigned int uMovieFormat; - int dword_0000A0; + int uMovieFormatSwapped; char pCurrentMovieName[64]; char pVideoFrameTextureFilename[32]; int field_104; + MultimediaPlayer *mPlayer; + Movie *mMovie; + int uVidFile; + int uSize; + int uOffset; }; #pragma pack(pop) @@ -847,3 +913,4 @@ extern VideoPlayer *pVideoPlayer; +extern LRESULT __stdcall wWinProc(HWND hwnd, unsigned int msg, WPARAM wparam, LPARAM lparam); \ No newline at end of file