annotate Media/MediaPlayer.h @ 2516:56b6d74ce716

.
author Ritor1
date Thu, 02 Oct 2014 22:01:06 +0600
parents a77c34acdbc9
children a902abdfc7f2
rev   line source
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1 #pragma once
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
2 #include "OSWindow.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
3 #include "Engine/Graphics/Texture.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
4 #include "Engine/ErrorHandling.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
5
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
6 #pragma pack(push, 1)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
7
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
8 #pragma pack(pop)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
9
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
10 #pragma pack(push, 1)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
11 #pragma pack(pop)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
13
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
14
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
15 extern "C"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
16 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
17 #include "lib/libavcodec/avcodec.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
18 #include "lib/libavformat/avformat.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
19 #include "lib/libavutil/avutil.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
20 #include "lib/libavutil/imgutils.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
21 #include "lib/libswscale/swscale.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
22 #include "lib/libswresample/swresample.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
23 #include "lib/libavutil/opt.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
24 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
25 #pragma comment(lib, "avcodec.lib")
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
26 #pragma comment(lib, "avformat.lib")
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
27 #pragma comment(lib, "avutil.lib")
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
28 #pragma comment(lib, "swscale.lib")
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
29 #pragma comment(lib, "swresample.lib")
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
30
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
31 #include "lib/OpenAL/al.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
32 #include "lib/OpenAL/alc.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
33 #pragma comment(lib, "OpenAL32.lib")
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
34
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
35 #pragma pack(push, 1)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
36
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
37 struct MovieHeader
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
38 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
39 char pVideoName[40];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
40 unsigned int uFileOffset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
41 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
42 struct SoundHeader
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
43 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
44 char pSoundName[40];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
45 unsigned int uFileOffset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
46 unsigned int uCompressedSize;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
47 unsigned int uDecompressedSize;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
48 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
49
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
50 enum MovieType
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
51 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
52 MOVIE_Invalid = 0x0,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
53 MOVIE_3DOLogo = 0x1,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
54 MOVIE_NWCLogo = 0x2,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
55 MOVIE_JVC = 0x3,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
56 MOVIE_Emerald = 0x4,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
57 MOVIE_Intro = 0x5,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
58 MOVIE_Death = 0x6,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
59 MOVIE_Outro = 0x7,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
60 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
61
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
62 namespace Media
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
63 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
64 class ITrack
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
65 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
66 public:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
67 virtual ~ITrack() {}
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
68
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
69 virtual void Play(bool loop = false) = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
70 virtual void Release() = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
71 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
72
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
73 class IMovie
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
74 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
75 public:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
76 virtual ~IMovie() {}
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
77
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
78 virtual void Play() = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
79 virtual void GetNextFrame(double dt, void *target_surface) = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
80 virtual void Release() = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
81
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
82 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
83
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
84 class MPlayer
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
85 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
86 public:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
87 MPlayer();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
88 virtual ~MPlayer();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
89
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
90 //for video/////////////////////////////////////////////////
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
91 RGBTexture pVideoFrame;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
92 int field_44;//final video
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
93 unsigned int bFirstFrame;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
94 unsigned int bLoopPlaying;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
95 unsigned int bStopBeforeSchedule;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
96 OSWindow *window;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
97 int uMovieType;//0 - null, 1 - bik, 2 - smk
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
98 char pCurrentMovieName[64];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
99 char pVideoFrameTextureFilename[32];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
100 MovieHeader *pMightVideoHeaders;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
101 MovieHeader *pMagicVideoHeaders;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
102 HANDLE hMightVid;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
103 HANDLE hMagicVid;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
104 unsigned int uNumMightVideoHeaders;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
105 unsigned int uNumMagicVideoHeaders;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
106 bool bPlaying_Movie;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
107 bool loop_current_file;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
108 DWORD time_video_begin;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
109 int current_movie_width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
110 int current_movie_height;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
111 HANDLE hVidFile;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
112 int uSize;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
113 int uOffset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
114
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
115 void Initialize(OSWindow *window);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
116
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
117 void OpenFullscreenMovie(const char *pFilename, unsigned int bLoop);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
118 void OpenHouseMovie(const char *pMovieName, unsigned int a3_1);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
119
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
120 void LoadMovie(const char *);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
121 void SelectMovieType();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
122
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
123 inline void PlayFullscreenMovie(MovieType movie_type, bool bShowMouseAfterPlayback)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
124 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
125 extern unsigned int bNoVideo;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
126 if (bNoVideo) return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
127
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
128 switch (movie_type)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
129 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
130 case MOVIE_3DOLogo: FullscreenMovieLoop("3dologo", 0); break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
131 case MOVIE_NWCLogo: FullscreenMovieLoop("new world logo", 0); break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
132 case MOVIE_JVC: FullscreenMovieLoop("jvc", 0); break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
133 case MOVIE_Intro: FullscreenMovieLoop("Intro", 0); break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
134 case MOVIE_Emerald: FullscreenMovieLoop("Intro Post", 0); break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
135 case MOVIE_Death: FullscreenMovieLoop("losegame", 2); break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
136 case MOVIE_Outro: FullscreenMovieLoop("end_seq1", 20); break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
137
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
138 default:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
139 Error("Invalid movie requested: %u", movie_type);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
140 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
141 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
142 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
143 void FullscreenMovieLoop(const char *pMovieName, int a2);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
144 void HouseMovieLoop();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
145
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
146 void ShowMM7IntroVideo_and_LoadingScreen();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
147 void Unload();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
148 ///////////////////////////////////////////////
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
149
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
150 IMovie *LoadMovie(const wchar_t *name, int width, int height, int cache_ms);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
151 IMovie *LoadMovieFromLOD(HANDLE h, int readFunction(void*, uint8_t*, int), int64_t seekFunction(void*, int64_t, int), int width, int height);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
152
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
153 //for audio////////////////////////////////////
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
154 HANDLE hAudioSnd;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
155 unsigned int uNumSoundHeaders;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
156 struct SoundHeader *pSoundHeaders;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
157
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
158 void LoadAudioSnd();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
159 ///////////////////////////////////////////////
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
160
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
161
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
162 ITrack *LoadTrack(const wchar_t *name);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
163
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
164 protected:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
165 static int readFunction(void *, uint8_t *, int);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
166 static int64_t seekFunction(void *, int64_t, int);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
167 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
168 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
169 #pragma pack(pop)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
170 extern Media::MPlayer *pMediaPlayer;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
171 extern Media::IMovie *pMovie_Track;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
172 extern Media::ITrack *pAudio_Track;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
173 extern class Movie *movie;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
174
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
175 extern int mSourceID;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
176
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
177 extern void PlayMovie(const wchar_t * pFilename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
178 extern void PlayAudio(const wchar_t * pFilename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
179 extern void MovieRelease();