annotate Media/MediaPlayer.cpp @ 2575:a76d408c5132 tip

DrawTranslucent -> DrawTextureGrayShade Removed old texture drawing stuff
author a.parshin
date Wed, 09 Mar 2016 01:39:52 +0200
parents 0c67be4ec900
children
rev   line source
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1 #define _CRTDBG_MAP_ALLOC
2567
d569340b05ff Few constants changed into enum values
a.parshin
parents: 2541
diff changeset
2 #define _CRT_SECURE_NO_WARNINGS
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
3 #include <stdlib.h>
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
4 #include <crtdbg.h>
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
5 #include <vector>
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
6 #include <deque>
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
7
2541
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2540
diff changeset
8 #include "Engine/Engine.h"
2572
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
9 #include "Engine/AssetsManager.h"
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
10
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
11 #include "IO/Mouse.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
12 #include "GUI/GUIWindow.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
13 #include "Media/Audio/OpenALSoundProvider.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
14 #include "MediaPlayer.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
15 #include "Media/Video/Bink_Smacker.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
16 #include "Media/Audio/AudioPlayer.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
17 #include "Engine/Timer.h"
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
18 #include "Engine/Graphics/Render.h"
2508
491f0babd563 use_music_folder
Ritor1
parents: 2504
diff changeset
19 #include "Engine/MMT.h"
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
20
2541
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2540
diff changeset
21 #include "Game/MainMenu.h"
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2540
diff changeset
22
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
23
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
24 #pragma comment(lib, "Version.lib")
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
25
2541
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2540
diff changeset
26
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
27 using namespace Media;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
28
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
29 Media::MPlayer *pMediaPlayer = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
30 Media::IMovie *pMovie_Track;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
31 Media::ITrack *pAudio_Track;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
32 Movie *movie;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
33
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
34 int mSourceID;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
35
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
36 void PlayMovie(const wchar_t * pFilename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
37 void PlayAudio(const wchar_t * pFilename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
38 void LoadMovie(const char *);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
39
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
40 class MemoryStream
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
41 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
42 public:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
43 inline MemoryStream(void *data, size_t data_size)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
44 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
45 this->data_size = data_size;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
46 this->data = data;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
47 this->current_pos = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
48 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
49 inline MemoryStream()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
50 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
51 this->data_size = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
52 this->data = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
53 this->current_pos = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
54 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
55
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
56 inline ~MemoryStream()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
57 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
58 //Log::Warning(L"Destructor: data delete %u", data);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
59 if (data)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
60 delete [] data;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
61 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
62
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
63 inline size_t Write(void *buffer, size_t num_bytes)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
64 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
65 if (!data)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
66 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
67 data_size = 32 + num_bytes;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
68 data = new char[data_size];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
69 //Log::Warning(L"new data %u", data);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
70 current_pos = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
71 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
72 else if (current_pos + num_bytes >= data_size)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
73 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
74 int new_data_size = data_size + num_bytes + data_size / 8 + 4;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
75 auto new_data = new char[new_data_size];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
76 //Log::Warning(L"new new_data %u", new_data);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
77
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
78 memcpy(new_data, data, data_size);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
79 //Log::Warning(L"data delete %u", data);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
80 delete [] data;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
81
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
82 data_size = new_data_size;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
83 data = new_data;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
84 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
85 memcpy((char *)data + current_pos, buffer, num_bytes);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
86 current_pos += num_bytes;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
87 return num_bytes;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
88 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
89
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
90 inline size_t Read(void *buffer, size_t num_bytes)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
91 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
92 size_t read_size = min(num_bytes, data_size - current_pos);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
93 if (read_size)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
94 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
95 memcpy(buffer, (char *)data + current_pos, read_size);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
96 current_pos += read_size;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
97 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
98 return read_size;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
99 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
100
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
101 inline void Reset()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
102 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
103 current_pos = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
104 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
105 inline void SeekToEnd()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
106 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
107 current_pos = data_size;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
108 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
109
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
110 inline size_t Unwind(size_t bytes)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
111 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
112 if (bytes > current_pos)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
113 current_pos = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
114 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
115 current_pos -= bytes;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
116 return current_pos;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
117 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
118
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
119 inline size_t Rewind(size_t bytes)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
120 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
121 if (current_pos + bytes >= data_size)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
122 current_pos = data_size;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
123 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
124 current_pos += bytes;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
125 return current_pos;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
126 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
127
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
128 inline size_t Size() const {return data_size;}
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
129 inline size_t Current() const {return current_pos;}
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
130 inline void *Ptr() const {return data;}
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
131
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
132 private:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
133 void *data;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
134 size_t data_size;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
135 size_t current_pos;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
136 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
137
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
138 OpenALSoundProvider *provider = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
139
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
140 static int av_num_bytes_per_sample(AVSampleFormat sample_fmt)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
141 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
142 switch (sample_fmt)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
143 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
144 case AV_SAMPLE_FMT_U8:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
145 case AV_SAMPLE_FMT_U8P:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
146 return 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
147
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
148 case AV_SAMPLE_FMT_S16:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
149 case AV_SAMPLE_FMT_S16P:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
150 return 2;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
151
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
152 case AV_SAMPLE_FMT_S32:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
153 case AV_SAMPLE_FMT_S32P:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
154 case AV_SAMPLE_FMT_FLT:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
155 case AV_SAMPLE_FMT_FLTP:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
156 return 4;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
157
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
158 case AV_SAMPLE_FMT_DBL:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
159 case AV_SAMPLE_FMT_DBLP:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
160 return 8;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
161
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
162 default:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
163 case AV_SAMPLE_FMT_NONE:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
164 Error("Invalid av sample format: %u", sample_fmt);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
165 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
166 return 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
167 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
168
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
169 struct AVStreamWrapper
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
170 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
171 inline AVStreamWrapper()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
172 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
173 this->type = AVMEDIA_TYPE_UNKNOWN;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
174 this->stream_idx = -1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
175 this->stream = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
176 this->dec = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
177 this->dec_ctx = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
178 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
179
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
180 inline void Release()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
181 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
182 type = AVMEDIA_TYPE_UNKNOWN;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
183 stream_idx = -1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
184 stream = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
185 dec = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
186 if (dec_ctx)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
187 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
188 // Close the codec
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
189 avcodec_close(dec_ctx);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
190 Log::Warning(L"close decoder context file\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
191 dec_ctx = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
192 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
193 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
194
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
195 AVMediaType type;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
196 int stream_idx;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
197 AVStream *stream;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
198 AVCodec *dec;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
199 AVCodecContext *dec_ctx;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
200 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
201
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
202 struct AVAudioStream: public AVStreamWrapper
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
203 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
204 inline AVAudioStream():AVStreamWrapper()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
205 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
206 this->bytes_per_sample = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
207 this->bytes_per_second = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
208 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
209
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
210 int bytes_per_sample;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
211 int bytes_per_second;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
212 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
213
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
214 struct AVVideoStream: public AVStreamWrapper
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
215 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
216 inline AVVideoStream(): AVStreamWrapper()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
217 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
218 this->frames_per_second = 0.0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
219 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
220
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
221 double frames_per_second;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
222 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
223
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
224 static bool av_open_stream(AVFormatContext *format_ctx, AVMediaType type, AVStreamWrapper *out_stream)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
225 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
226 int stream_idx = av_find_best_stream(format_ctx, type, -1, -1, nullptr, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
227 if (stream_idx >= 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
228 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
229 auto stream = format_ctx->streams[stream_idx];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
230 auto dec_ctx = stream->codec;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
231
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
232 // Find the decoder for the video stream
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
233 auto dec = avcodec_find_decoder(dec_ctx->codec_id);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
234 if (dec)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
235 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
236 // Open codec
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
237 if (avcodec_open2(dec_ctx, dec, nullptr) >= 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
238 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
239 out_stream->type = type;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
240 out_stream->stream_idx = stream_idx;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
241 out_stream->stream = stream;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
242 out_stream->dec = dec;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
243 out_stream->dec_ctx = dec_ctx;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
244 return true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
245 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
246 fprintf(stderr, "ffmpeg: Could not open codec\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
247 return false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
248 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
249 fprintf(stderr, "ffmpeg: Unable to open codec\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
250 return false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
251 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
252 fprintf(stderr, "ffmpeg: Didn't find a stream\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
253 return false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
254 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
255
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
256 static bool av_open_audio_stream(AVFormatContext *format_ctx, AVAudioStream *out_stream)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
257 {
2504
6b8c2f8c7fad for audio in House video
Ritor1
parents: 2502
diff changeset
258 if (av_open_stream(format_ctx, AVMEDIA_TYPE_AUDIO, out_stream))
6b8c2f8c7fad for audio in House video
Ritor1
parents: 2502
diff changeset
259 //return Error("Audio stream not found"), false;
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
260
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
261 // we support only 2-channel audio for now
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
262 //if (out_stream->dec_ctx->channels != 2)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
263 //{
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
264 // out_stream->Release();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
265 // return Error("Unsupported number of channels: %u", out_stream->dec_ctx->channels), false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
266 //}
2504
6b8c2f8c7fad for audio in House video
Ritor1
parents: 2502
diff changeset
267 {
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
268 out_stream->bytes_per_sample = av_num_bytes_per_sample(out_stream->dec_ctx->sample_fmt);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
269 out_stream->bytes_per_second = out_stream->dec_ctx->channels * out_stream->dec_ctx->sample_rate * out_stream->bytes_per_sample;
2504
6b8c2f8c7fad for audio in House video
Ritor1
parents: 2502
diff changeset
270 }
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
271 return true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
272 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
273
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
274 static bool av_open_video_stream(AVFormatContext *format_ctx, AVVideoStream *out_stream)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
275 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
276 if (!av_open_stream(format_ctx, AVMEDIA_TYPE_VIDEO, out_stream))
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2519
diff changeset
277 {
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2519
diff changeset
278 Error("Video stream not found");
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2519
diff changeset
279 false;
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2519
diff changeset
280 }
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
281
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
282 out_stream->frames_per_second = (double)out_stream->dec_ctx->time_base.den / (double)out_stream->dec_ctx->time_base.num;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
283 return true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
284 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
285
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
286 void InterleaveAudioData(MemoryStream *stream, AVSampleFormat src_format, int num_channels, int num_samples, uint8_t **channels)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
287 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
288 unsigned int bytes_per_sample;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
289 switch (src_format)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
290 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
291 case AV_SAMPLE_FMT_U8:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
292 case AV_SAMPLE_FMT_U8P:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
293 __debugbreak();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
294
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
295 case AV_SAMPLE_FMT_S16:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
296 bytes_per_sample = sizeof(__int16);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
297 stream->Write(channels[0], num_channels * num_samples * bytes_per_sample);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
298 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
299
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
300 case AV_SAMPLE_FMT_S16P:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
301 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
302 bytes_per_sample = sizeof(__int16);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
303 for (int i = 0; i < num_samples; ++i)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
304 for (int j = 0; j < num_channels; ++j)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
305 stream->Write(channels[j] + i * bytes_per_sample, bytes_per_sample);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
306 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
307 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
308
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
309 case AV_SAMPLE_FMT_FLT:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
310 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
311 SwrContext *converter = swr_alloc();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
312 av_opt_set_int(converter, "in_channel_layout", av_get_default_channel_layout(2), 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
313 //av_opt_set_int(converter, "in_sample_rate", sample_ra, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
314 av_opt_set_sample_fmt(converter, "in_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
315
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
316 av_opt_set_int(converter, "out_channel_layout", av_get_default_channel_layout(2), 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
317 //av_opt_set_int(converter, "out_sample_rate", dst_sample_rate, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
318 av_opt_set_sample_fmt(converter, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
319
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
320 if (swr_init(converter) < 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
321 {
2540
a.parshin
parents: 2524
diff changeset
322 Log::Warning(L"swr_init: failed");
a.parshin
parents: 2524
diff changeset
323 //__debugbreak();
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
324 swr_free(&converter);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
325 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
326 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
327
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
328 uint8_t **dst_channels;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
329 int dst_linesize[8];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
330 //int dst_nb_channels = av_get_channel_layout_nb_channels(dst_channel_layout);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
331 if (av_samples_alloc_array_and_samples(&dst_channels, dst_linesize, 2, num_channels * num_samples, AV_SAMPLE_FMT_S16, 0) < 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
332 {
2540
a.parshin
parents: 2524
diff changeset
333 Log::Warning(L"av_samples_alloc_array_and_samples: failed");
a.parshin
parents: 2524
diff changeset
334 //__debugbreak();
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
335 swr_free(&converter);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
336 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
337 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
338
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
339 if (swr_convert(converter, dst_channels, num_channels * num_samples, (const uint8_t **)channels, num_channels * num_samples) >= 0) //Invalid partial memory access, Uninitialized memory access
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
340
2540
a.parshin
parents: 2524
diff changeset
341 stream->Write(dst_channels[0], num_channels * num_samples * sizeof(__int16));
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
342 else
2540
a.parshin
parents: 2524
diff changeset
343 //__debugbreak();
a.parshin
parents: 2524
diff changeset
344 Log::Warning(L"swr_convert: failed");
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
345
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
346 av_free(dst_channels[0]);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
347 swr_free(&converter);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
348 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
349 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
350
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
351 default:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
352 __debugbreak();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
353 //if (Resample(next_frame->avframe, next_frame->avframe->channel_layout, next_frame->avframe->sample_rate,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
354 // av_get_default_channel_layout(2), next_frame->avframe->sample_rate, AV_SAMPLE_FMT_S16P, resampled_data))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
355 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
356 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
357
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
358 const uint16_t ff_wma_critical_freqs[25] = {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
359 100, 200, 300, 400, 510, 630, 770, 920,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
360 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
361 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
362 24500,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
363 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
364 extern const uint16_t ff_wma_critical_freqs[25];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
365 static float quant_table[96];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
366
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
367 bool DecodeAudioFrame(AVCodecContext *dec_ctx, AVPacket *avpacket, AVFrame *avframe, MemoryStream *out_audio_data, int *out_num_audio_samples)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
368 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
369 volatile int decoded = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
370 do
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
371 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
372 if (avcodec_decode_audio4(dec_ctx, avframe, (int *)&decoded, avpacket) < 0) //Uninitialized portail memory access
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
373 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
374 log("Cannot decode audio frame\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
375 return false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
376 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
377
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
378 if (!decoded)
2508
491f0babd563 use_music_folder
Ritor1
parents: 2504
diff changeset
379 {
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
380 log("Cannot decode audio frame in one piece\n");
2508
491f0babd563 use_music_folder
Ritor1
parents: 2504
diff changeset
381 break;
491f0babd563 use_music_folder
Ritor1
parents: 2504
diff changeset
382 }
491f0babd563 use_music_folder
Ritor1
parents: 2504
diff changeset
383
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
384 } while (!decoded);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
385
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
386 switch (dec_ctx->codec_id)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
387 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
388 case AV_CODEC_ID_BINKAUDIO_DCT:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
389 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
390 __debugbreak();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
391 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
392 case AV_CODEC_ID_BINKAUDIO_RDFT:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
393 {//pts samples dpts
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
394 // 0 960
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
395 //17280 960 17280 18x960
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
396 //18240 960 960 1x960
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
397 //20160 960 1920 2x960
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
398 //21120 960 960 1x960
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
399 //23040 960 1920 2x960
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
400 /*static int bink_next_pts = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
401
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
402 // there's a gap in the sound - fill empty samples in
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
403 if (bink_next_pts < avpacket->pts)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
404 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
405 short silence[1024];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
406 memset(silence, 0, sizeof(silence));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
407
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
408 int samples_to_fill = /*dec_ctx->channels * (avpacket->pts - bink_next_pts);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
409 while (samples_to_fill > 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
410 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
411 int samples_to_fill_this_step = samples_to_fill >= 1024 ? 1024 : samples_to_fill;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
412 out_audio_data->Write(silence, samples_to_fill_this_step * sizeof(short));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
413
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
414 samples_to_fill -= samples_to_fill_this_step;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
415 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
416 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
417
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
418 bink_next_pts = avpacket->pts + /*dec_ctx->channels * avframe->nb_samples; */
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
419
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
420 AVFrame frame;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
421 int first;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
422 int version_b;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
423 int frame_len;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
424 int overlap_len;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
425 int block_size;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
426 int num_bands;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
427 unsigned int *bands;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
428 float root;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
429 int sample_rate = dec_ctx->sample_rate;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
430 int sample_rate_half;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
431 int i;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
432 int frame_len_bits;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
433 int channels;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
434
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
435 //compresses audio in chunks of varying sizes depending on sample rate:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
436 // if sample rate < 22050, frame size is 2048 samples
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
437 // if sample rate < 44100, frame size is 4096 samples
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
438 // else, frame size is 8192 samples
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
439
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
440
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
441 /* determine frame length */
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
442 if (dec_ctx->sample_rate < 22050)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
443 frame_len_bits = 9;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
444 else if (dec_ctx->sample_rate < 44100)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
445 frame_len_bits = 10;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
446 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
447 frame_len_bits = 11;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
448
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
449 if (dec_ctx->channels < 1 || dec_ctx->channels > 2)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
450 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
451 av_log(dec_ctx, AV_LOG_ERROR, "invalid number of channels: %d\n", dec_ctx->channels);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
452 return AVERROR_INVALIDDATA;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
453 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
454
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
455 version_b = dec_ctx->extradata_size >= 4 && dec_ctx->extradata[3] == 'b';
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
456 if (version_b)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
457 __debugbreak();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
458
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
459 if (dec_ctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
460 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
461 // audio is already interleaved for the RDFT format variant
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
462 dec_ctx->sample_fmt = AV_SAMPLE_FMT_FLT;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
463 sample_rate *= dec_ctx->channels;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
464 channels = 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
465 if (!version_b)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
466 frame_len_bits += av_log2(dec_ctx->channels);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
467 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
468 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
469 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
470 channels = dec_ctx->channels;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
471 dec_ctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
472 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
473
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
474 frame_len = 1 << frame_len_bits; //2048
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
475
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
476 //a frame is windowed with the previous frame; the size of the window is frame size / 16
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
477 overlap_len = frame_len / 16; //128
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
478 block_size = (frame_len - overlap_len) * channels; //1920
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
479
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
480 //compute half the sample rate as (sample rate + 1) / 2;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
481 //initialize an array of band frequencies corresponding to an array of 25 critical frequencies (same as WMA, apparently),
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
482 // any for which the critical frequencies are less than half the sample rate
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
483
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
484 sample_rate_half = (sample_rate + 1) / 2; //22050
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
485 if (dec_ctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
486 root = 2.0 / (sqrt(float(frame_len)) * 32768.0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
487 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
488 root = frame_len / (sqrt(float(frame_len)) * 32768.0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
489 for (i = 0; i < 96; i++)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
490 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
491 /* constant is result of 0.066399999/log10(M_E) */
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
492 quant_table[i] = expf(i * 0.15289164787221953823f) * root;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
493 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
494
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
495 /* calculate number of bands */
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
496 //bands calculation:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
497 //bands[0] = 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
498 //foreach (i in 1..# of bands-1):
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
499 //bands[i] = crit_freq[i-1] * (frame length / 2) / (sample rate / 2);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
500 //bands[# of bands] = frame length / 2
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
501 for (num_bands = 1; num_bands < 25; num_bands++)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
502 if (sample_rate_half <= ff_wma_critical_freqs[num_bands - 1])
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
503 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
504
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
505 bands = (unsigned int *)(av_malloc((num_bands + 1) * sizeof(*bands)));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
506 if (!bands)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
507 return AVERROR(ENOMEM);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
508
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
509 /* populate bands data */
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
510 bands[0] = 2;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
511 for (i = 1; i < num_bands; i++)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
512 bands[i] = (ff_wma_critical_freqs[i - 1] * frame_len / sample_rate_half) & ~1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
513 bands[num_bands] = frame_len;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
514
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
515 first = 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
516
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
517 //ff_rdft_init(&trans.rdft, frame_len_bits, DFT_C2R);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
518
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
519 avcodec_get_frame_defaults(&frame);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
520 dec_ctx->coded_frame = &frame;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
521 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
522 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
523 /*
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
524 case AV_CODEC_ID_SMACKAUDIO:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
525 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
526 static int smack_debug_next_audio_time = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
527 if (smack_debug_next_audio_time != packet->pts)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
528 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
529 Error("There's a gap in the sound before frame %u\n", num_audio_frames);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
530 __debugbreak(); // there's a gap in the sound
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
531 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
532
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
533 int num_actual_data_channels = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
534 switch (dec_ctx->sample_fmt)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
535 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
536 case AV_SAMPLE_FMT_U8:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
537 case AV_SAMPLE_FMT_S16:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
538 case AV_SAMPLE_FMT_S32:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
539 case AV_SAMPLE_FMT_FLT:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
540 case AV_SAMPLE_FMT_DBL:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
541 num_actual_data_channels = 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
542 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
543
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
544 case AV_SAMPLE_FMT_U8P:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
545 case AV_SAMPLE_FMT_S16P:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
546 case AV_SAMPLE_FMT_S32P:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
547 case AV_SAMPLE_FMT_FLTP:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
548 case AV_SAMPLE_FMT_DBLP:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
549 num_actual_data_channels = dec_ctx->channels;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
550 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
551
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
552 default:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
553 case AV_SAMPLE_FMT_NONE:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
554 case AV_SAMPLE_FMT_NB:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
555 __debugbreak();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
556 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
557
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
558 smack_debug_next_audio_time += dec_ctx->channels * frame->nb_samples * bytes_per_sample;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
559 Assert(frame->avframe->linesize[0] == audio.dec_ctx->channels * frame->avframe->nb_samples * audio.bytes_per_sample / num_actual_data_channels,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
560 "Smack audio size mismatch in frame %u in %s\n", audio_num_read_frames, movie_filename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
561
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
562 frame->play_time = (double)frame->avpacket->pts / (double)audio.bytes_per_second;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
563 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
564 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
565
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
566 case AV_CODEC_ID_MP3:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
567 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
568 static int mp3_samples_decoded_so_far = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
569 static int mp3_prev_samples_count = frame->avframe->nb_samples; // mp3 seems to always feed same amount of samples
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
570 frame->play_time = (double)mp3_samples_decoded_so_far / (double)audio.dec_ctx->sample_rate;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
571
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
572 mp3_samples_decoded_so_far += frame->avframe->nb_samples;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
573 Assert(mp3_prev_samples_count == frame->avframe->nb_samples,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
574 "MP3 audio have variable sample count in frame %u in %s\n", audio_num_read_frames, movie_filename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
575 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
576 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
577
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
578 default:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
579 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
580 __debugbreak();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
581 double samples_per_second = (double)audio.dec_ctx->time_base.den / (double)audio.dec_ctx->time_base.num;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
582 double play_length = frame->avframe->nb_samples / samples_per_second;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
583 frame->play_time = (double)frame->avpacket->pts / samples_per_second;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
584 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
585 break;*/
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
586 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
587
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
588 if (!avframe->channel_layout)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
589 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
590 log("Audio channel layout not specified, rolling back to default\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
591 avframe->channel_layout = av_get_default_channel_layout(dec_ctx->channels);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
592 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
593
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
594 *out_num_audio_samples = dec_ctx->channels * avframe->nb_samples;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
595 InterleaveAudioData(out_audio_data, dec_ctx->sample_fmt,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
596 dec_ctx->channels, avframe->nb_samples, avframe->data);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
597 return true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
598 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
599
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
600 bool LoadAudioTrack(AVFormatContext *format_ctx, AVCodecContext *dec_ctx, int audio_stream_idx, MemoryStream *out_audio_stream, int *out_num_audio_frames, int *out_num_audio_samples)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
601 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
602 out_audio_stream->Reset();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
603
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
604 AVFrame *frame = avcodec_alloc_frame();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
605
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
606 AVPacket *packet = new AVPacket;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
607 av_init_packet(packet);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
608
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
609 int num_audio_frames = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
610 int num_audio_samples = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
611
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
612 while (av_read_frame(format_ctx, packet) >= 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
613 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
614 // Is this a packet from the audio stream?
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
615 if (packet->stream_index != audio_stream_idx)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
616 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
617 //log("Suspicious stream id %u in %s", packet->stream_index, filenamea);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
618 continue;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
619 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
620
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
621 // Decode audio frame
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
622 int num_samples_decoded;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
623 DecodeAudioFrame(dec_ctx, packet, frame, out_audio_stream, &num_samples_decoded);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
624
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
625 num_audio_samples += num_samples_decoded;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
626 num_audio_frames++;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
627 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
628 *out_num_audio_frames = num_audio_frames;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
629 *out_num_audio_samples = num_audio_samples;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
630
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
631 avcodec_free_frame(&frame);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
632 delete frame;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
633 av_free_packet(packet);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
634 delete packet;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
635
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
636 return true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
637 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
638
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
639 class Track: public Media::ITrack
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
640 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
641 public:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
642 inline Track()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
643 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
644 this->format_ctx = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
645 this->audio_num_samples = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
646 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
647
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
648 void Release()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
649 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
650 ReleaseAvcodec();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
651 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
652
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
653 void ReleaseAvcodec()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
654 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
655 audio.Release();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
656 if (format_ctx)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
657 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
658 av_close_input_file(format_ctx);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
659 Log::Warning(L"close audio format context file\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
660 format_ctx = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
661 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
662 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
663
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
664 bool LoadAudio(const wchar_t *filename)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
665 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
666 char filenamea[1024];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
667 sprintf(filenamea, "%S", filename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
668 // Open audio file
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
669 if (avformat_open_input(&format_ctx, filenamea, nullptr, nullptr) >= 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
670 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
671 // Retrieve stream information
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
672 if (avformat_find_stream_info(format_ctx, nullptr) >= 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
673 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
674 // Dump information about file onto standard error
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
675 av_dump_format(format_ctx, 0, filenamea, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
676
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
677 if (!av_open_audio_stream(format_ctx, &audio))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
678 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
679 Error("Cannot open strack: %s", filenamea);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
680 return Release(), false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
681 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
682
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
683 MemoryStream audio_plain_data;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
684 int num_audio_frames;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
685 int num_audio_samples;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
686
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
687 if (LoadAudioTrack(format_ctx, audio.dec_ctx, audio.stream_idx, &audio_plain_data, &num_audio_frames, &num_audio_samples))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
688 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
689 /*#ifdef _DEBUG
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
690 char debug_filename[1024];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
691 sprintf(debug_filename, "%s.wav", filenamea);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
692 FILE *wav = fopen(debug_filename, "w+b");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
693
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
694 extern void write_wav_header(FILE *wav, int channel_count = 2, int sample_rate = 22050, int bytes_per_sample = 2);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
695 write_wav_header(wav, audio.dec_ctx->channels, audio.dec_ctx->sample_rate, audio.bytes_per_sample);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
696
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
697 fwrite(audio_plain_data.Ptr(), audio_plain_data.Current(), 1, wav);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
698
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
699 extern void fix_wav_header(FILE *wav, int wav_bytes_in_stream);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
700 fix_wav_header(wav, audio_plain_data.Current());
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
701 #endif*/
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
702
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
703 device_buffer = provider->CreateTrack16(audio.dec_ctx->channels, audio.dec_ctx->sample_rate, 2, num_audio_samples, audio_plain_data.Ptr());
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
704
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
705 Release();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
706 return true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
707 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
708 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
709 Release();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
710 fprintf(stderr, "ffmpeg: Unable to find stream info\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
711 return false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
712 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
713 fprintf(stderr, "ffmpeg: Unable to open input file\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
714 return false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
715 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
716
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
717 virtual void Play(bool loop)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
718 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
719 provider->PlayTrack16(device_buffer, loop);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
720 mSourceID = device_buffer->source_id;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
721 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
722
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
723 protected:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
724 AVFormatContext *format_ctx;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
725 AVAudioStream audio;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
726 int audio_num_samples;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
727
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
728 bool stopped;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
729
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
730 OpenALSoundProvider::TrackBuffer *device_buffer;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
731 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
732
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
733 class Movie: public Media::IMovie
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
734 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
735 public:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
736 inline Movie()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
737 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
738 this->movie_filename[0] = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
739 this->width = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
740 this->height = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
741 this->format_ctx = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
742 this->end_of_file = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
743 this->playback_time = 0.0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
744
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
745 this->num_audio_frames = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
746 this->num_audio_samples = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
747
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
748 this->last_resampled_frame_num = -1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
749 memset(last_resampled_frame_data, 0, sizeof(last_resampled_frame_data));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
750 memset(last_resampled_frame_linesize, 0, sizeof(last_resampled_frame_linesize));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
751
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
752 audio_data_in_device = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
753 decoding_packet = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
754 ioBuffer = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
755 format_ctx = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
756 avioContext = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
757 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
758
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
759 virtual ~Movie() {}
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
760
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
761 virtual void Release()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
762 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
763 ReleaseAVCodec();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
764
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
765 if (audio_data_in_device)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
766 provider->DeleteStreamingTrack(&audio_data_in_device);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
767 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
768
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
769 inline void ReleaseAVCodec()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
770 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
771 audio.Release();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
772 video.Release();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
773
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
774 if (format_ctx)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
775 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
776 // Close the video file
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
777 av_close_input_file(format_ctx);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
778 Log::Warning(L"close video format context file\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
779 format_ctx = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
780 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
781 if(avioContext)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
782 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
783 av_free(avioContext);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
784 avioContext = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
785 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
786 if (ioBuffer)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
787 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
788 //av_free(ioBuffer);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
789 ioBuffer = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
790 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
791 av_free_packet(decoding_packet);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
792 delete decoding_packet;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
793 avcodec_free_frame(&decoding_frame);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
794 delete decoding_frame;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
795 if (last_resampled_frame_data[0])
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
796 av_freep(&last_resampled_frame_data[0]);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
797
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
798 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
799
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
800 bool Load(const wchar_t *filename, int dst_width, int dst_height, int cache_ms) //Çàãðóçêà
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
801 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
802 char filenamea[1024];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
803 sprintf(filenamea, "%S", filename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
804 sprintf(movie_filename, "%S", filename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
805
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
806 width = dst_width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
807 height = dst_height;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
808 // Open video file
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
809 if (avformat_open_input(&format_ctx, filenamea, nullptr, nullptr) >= 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
810 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
811 // Retrieve stream information
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
812 if (avformat_find_stream_info(format_ctx, nullptr) >= 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
813 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
814 // Dump information about file onto standard error
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
815 av_dump_format(format_ctx, 0, filenamea, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
816
2504
6b8c2f8c7fad for audio in House video
Ritor1
parents: 2502
diff changeset
817 /*if (!av_open_audio_stream(format_ctx, &audio))
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
818 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
819 Error("Cannot open audio stream: %s", filenamea);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
820 return Release(), false;
2504
6b8c2f8c7fad for audio in House video
Ritor1
parents: 2502
diff changeset
821 }*/
6b8c2f8c7fad for audio in House video
Ritor1
parents: 2502
diff changeset
822 av_open_audio_stream(format_ctx, &audio);
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
823
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
824 if (!av_open_video_stream(format_ctx, &video))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
825 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
826 Error("Cannot open video stream: %s", filenamea);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
827 return Release(), false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
828 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
829
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
830 //Ritor1: include
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
831 if (_stricmp("binkvideo", video.dec->name) )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
832 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
833 pMediaPlayer->current_movie_width = video.dec_ctx->width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
834 pMediaPlayer->current_movie_height = video.dec_ctx->height;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
835 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
836 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
837 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
838 pMediaPlayer->current_movie_width = width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
839 pMediaPlayer->current_movie_height = height;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
840 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
841 //
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
842 decoding_packet = new AVPacket;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
843 av_init_packet(decoding_packet);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
844
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
845 // Allocate video frame
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
846 decoding_frame = avcodec_alloc_frame();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
847
2504
6b8c2f8c7fad for audio in House video
Ritor1
parents: 2502
diff changeset
848 if (audio.stream_idx >= 0)
6b8c2f8c7fad for audio in House video
Ritor1
parents: 2502
diff changeset
849 audio_data_in_device = provider->CreateStreamingTrack16(audio.dec_ctx->channels, audio.dec_ctx->sample_rate, 2);
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
850 return true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
851 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
852 fprintf(stderr, "ffmpeg: Unable to find stream info\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
853 return Release(), false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
854 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
855 fprintf(stderr, "ffmpeg: Unable to open input file\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
856 return Release(), false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
857 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
858
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
859 bool LoadFromLOD(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
860 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
861 if (!ioBuffer)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
862 ioBuffer = (unsigned char *)av_malloc(0x4000 + FF_INPUT_BUFFER_PADDING_SIZE); // can get av_free()ed by libav
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
863 if (!avioContext)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
864 avioContext = avio_alloc_context(ioBuffer, 0x4000, 0, h, readFunction, NULL, seekFunction);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
865 if (!format_ctx)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
866 format_ctx = avformat_alloc_context();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
867 format_ctx->pb = avioContext;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
868 return Load(L"dummyFilename", width, height, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
869 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
870
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
871 virtual void GetNextFrame(double dt, void *dst_surface)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
872 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
873 playback_time += dt;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
874
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
875 AVPacket *avpacket = decoding_packet;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
876 AVFrame *avframe = decoding_frame;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
877
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
878 avcodec_get_frame_defaults(avframe);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
879
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
880 int desired_frame_number = floor(playback_time * video.dec_ctx->time_base.den / video.dec_ctx->time_base.num + 0.5);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
881 if (last_resampled_frame_num == desired_frame_number)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
882 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
883 memcpy(dst_surface, last_resampled_frame_data[0], pMediaPlayer->current_movie_height * last_resampled_frame_linesize[0]);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
884 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
885 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
886
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
887 volatile int frameFinished = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
888
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
889 // keep reading packets until we hit the end or find a video packet
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
890 do
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
891 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
892 if (pMediaPlayer->loop_current_file)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
893 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
894 //Now seek back to the beginning of the stream
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
895 if (video.dec_ctx->frame_number >= video.stream->duration - 1 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
896 pMediaPlayer->bPlaying_Movie = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
897 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
898 if (av_read_frame(format_ctx, avpacket) < 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
899 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
900 // probably movie is finished
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
901 pMediaPlayer->bPlaying_Movie = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
902 av_free_packet(avpacket);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
903 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
904 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
905 // Is this a packet from the video stream?
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
906 // audio packet - queue into playing
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
907 if (avpacket->stream_index == audio.stream_idx)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
908 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
909 MemoryStream audio_data;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
910 if (DecodeAudioFrame(audio.dec_ctx, avpacket, avframe, &audio_data, &num_audio_samples))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
911 provider->Stream16(audio_data_in_device, num_audio_samples, audio_data.Ptr());
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
912 //continue;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
913 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
914
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
915 // Decode video frame
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
916 // video packet - decode & maybe show
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
917 else if (avpacket->stream_index == video.stream_idx)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
918 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
919 do
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
920 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
921 if (avcodec_decode_video2(video.dec_ctx, avframe, (int *)&frameFinished, avpacket) < 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
922 __debugbreak();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
923 } while (!frameFinished);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
924 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
925 else __debugbreak(); // unknown stream
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
926 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
927 while (avpacket->stream_index != video.stream_idx ||
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
928 avpacket->pts != desired_frame_number);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
929
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
930 if (frameFinished)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
931 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
932 if (last_resampled_frame_data[0])
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
933 av_freep(&last_resampled_frame_data[0]);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
934
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
935 AVPixelFormat rescaled_format = AV_PIX_FMT_RGB32;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
936 uint8_t *rescaled_data[4] = {nullptr, nullptr, nullptr, nullptr};
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
937 int rescaled_linesize[4] = {0, 0, 0, 0};
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
938
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
939 if (av_image_alloc(rescaled_data, rescaled_linesize, pMediaPlayer->current_movie_width, pMediaPlayer->current_movie_height, rescaled_format, 1) >= 0)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
940 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
941 SwsContext *converter = sws_getContext(avframe->width, avframe->height, (AVPixelFormat)avframe->format,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
942 pMediaPlayer->current_movie_width, pMediaPlayer->current_movie_height, rescaled_format,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
943 SWS_BICUBIC, nullptr, nullptr, nullptr);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
944 sws_scale(converter, avframe->data, avframe->linesize, 0, avframe->height, rescaled_data, rescaled_linesize);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
945 sws_freeContext(converter);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
946
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
947 memcpy(dst_surface, rescaled_data[0], pMediaPlayer->current_movie_height * rescaled_linesize[0]);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
948
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
949 last_resampled_frame_num = desired_frame_number;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
950 memcpy(last_resampled_frame_data, rescaled_data, sizeof(rescaled_data));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
951 memcpy(last_resampled_frame_linesize, rescaled_linesize, sizeof(rescaled_linesize));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
952 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
953 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
954 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
955 memset(dst_surface, 0, width * pMediaPlayer->current_movie_height * 4);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
956
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
957 // Free the packet that was allocated by av_read_frame
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
958 av_free_packet(avpacket);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
959 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
960
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
961 virtual void Play()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
962 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
963 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
964
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
965 protected:
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
966 char movie_filename[256];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
967 int width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
968 int height;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
969 bool stopped;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
970 AVFormatContext *format_ctx;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
971 double playback_time;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
972 bool end_of_file;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
973
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
974 AVPacket *decoding_packet;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
975 AVFrame *decoding_frame;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
976
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
977 AVAudioStream audio;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
978 int num_audio_frames;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
979 int num_audio_samples;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
980 unsigned char *ioBuffer;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
981 AVIOContext *avioContext;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
982 OpenALSoundProvider::StreamingTrackBuffer *audio_data_in_device;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
983
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
984 AVVideoStream video;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
985 int last_resampled_frame_num;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
986 uint8_t *last_resampled_frame_data[4];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
987 int last_resampled_frame_linesize[4];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
988 };
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
989
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
990 ITrack *MPlayer::LoadTrack(const wchar_t *filename)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
991 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
992 auto audio_track = new Track;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
993 Log::Warning(L"allocation dynamic memory for audio_track\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
994 if (!audio_track->LoadAudio(filename))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
995 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
996 delete audio_track;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
997 Log::Warning(L"delete dynamic memory for audio_track\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
998 audio_track = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
999 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1000 return audio_track;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1001 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1002
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1003 IMovie *MPlayer::LoadMovie(const wchar_t *filename, int width, int height, int cache_ms) //Çàãðóçèòü âèäåî
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1004 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1005 movie = new Movie;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1006 Log::Warning(L"allocation dynamic memory for movie\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1007 if (!movie->Load(filename, width, height, cache_ms))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1008 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1009 delete movie;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1010 Log::Warning(L"delete dynamic memory for movie\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1011 movie = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1012 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1013 return movie;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1014 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1015
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1016
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1017 //for video/////////////////////////////////////////////////////////////////
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1018
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1019 //----- (004BE9D8) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1020 void MPlayer::Initialize(OSWindow *target_window)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1021 {
2519
b36b858a5175 * error loading video when -novideo specified
a.parshin
parents: 2510
diff changeset
1022 window = target_window;
b36b858a5175 * error loading video when -novideo specified
a.parshin
parents: 2510
diff changeset
1023
2572
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1024 hVidFile = INVALID_HANDLE_VALUE;
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1025
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1026 uNumMightVideoHeaders = 0;
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1027 pMightVideoHeaders = nullptr;
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1028
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1029 uNumMagicVideoHeaders = 0;
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1030 pMagicVideoHeaders = nullptr;
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1031
2519
b36b858a5175 * error loading video when -novideo specified
a.parshin
parents: 2510
diff changeset
1032 if (bNoVideo)
b36b858a5175 * error loading video when -novideo specified
a.parshin
parents: 2510
diff changeset
1033 return;
b36b858a5175 * error loading video when -novideo specified
a.parshin
parents: 2510
diff changeset
1034
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1035 DWORD NumberOfBytesRead; // [sp+10h] [bp-4h]@9
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1036
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1037
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1038 unsigned int uBinkVersionMajor = -1,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1039 uBinkVersionMinor = -1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1040 //GetDllVersion(L"BINKW32.DLL", &uBinkVersionMajor, &uBinkVersionMinor);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1041 //uBinkVersion = (unsigned __int64)uBinkVersionMajor << 32 | uBinkVersionMinor;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1042
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1043 strcpy(pTmpBuf.data(), "anims\\might7.vid");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1044 hMightVid = CreateFileW(L"anims\\might7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1045 if ( hMightVid == INVALID_HANDLE_VALUE )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1046 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1047 sprintf(pTmpBuf2.data(), "Can't open file - anims\\%s.smk", pTmpBuf.data());
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1048 MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1049 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1050 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1051 strcpy(pTmpBuf.data(), "anims\\magic7.vid");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1052 hMagicVid = CreateFileW(L"anims\\magic7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1053 if ( hMagicVid == INVALID_HANDLE_VALUE )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1054 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1055 if ( !bCanLoadFromCD )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1056 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1057 sprintf(pTmpBuf2.data(), "Can't open file - anims\\%s.smk", pTmpBuf.data());
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1058 MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1059 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1060 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1061 sprintf(pTmpBuf2.data(), "%c:\\%s", (unsigned __int8)cMM7GameCDDriveLetter, pTmpBuf.data());
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1062 hMagicVid = CreateFileA(pTmpBuf2.data(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1063 if ( hMagicVid == (HANDLE)INVALID_HANDLE_VALUE )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1064 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1065 sprintf(pTmpBuf2.data(), "Can't open file - %s", pTmpBuf.data());
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1066 MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1067 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1068 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1069 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1070 ReadFile(hMightVid, &uNumMightVideoHeaders, 4, &NumberOfBytesRead, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1071 ReadFile(hMagicVid, &uNumMagicVideoHeaders, 4, &NumberOfBytesRead, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1072 pMightVideoHeaders = (MovieHeader *)malloc(sizeof(MovieHeader) * uNumMightVideoHeaders + 2);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1073 pMagicVideoHeaders = (MovieHeader *)malloc(sizeof(MovieHeader) * uNumMagicVideoHeaders + 2);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1074 ReadFile(hMightVid, pMightVideoHeaders, 44 * uNumMightVideoHeaders, &NumberOfBytesRead, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1075 ReadFile(hMagicVid, pMagicVideoHeaders, 44 * uNumMagicVideoHeaders, &NumberOfBytesRead, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1076 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1077
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1078 //----- (004BF411) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1079 void MPlayer::OpenFullscreenMovie(const char *pFilename, unsigned int bLoop/*, int ScreenSizeFlag*/)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1080 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1081 if (!this->bPlaying_Movie)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1082 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1083 pEventTimer->Pause();
2510
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1084 if ( use_music_folder )
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1085 alSourcePause(mSourceID);
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1086 else if (pAudioPlayer->hAILRedbook)
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1087 AIL_redbook_pause(pAudioPlayer->hAILRedbook);
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1088
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1089 bStopBeforeSchedule = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1090 bFirstFrame = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1091 this->bLoopPlaying = bLoop;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1092 LoadMovie(pFilename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1093 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1094 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1095 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1096
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1097 //----- (004BF28F) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1098 void MPlayer::OpenHouseMovie(const char *pMovieName, unsigned int a3_1)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1099 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1100 if (!this->bPlaying_Movie)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1101 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1102 //Prepare();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1103 pEventTimer->Pause();
2510
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1104 if ( use_music_folder )
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1105 alSourcePause(mSourceID);
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1106 else if (pAudioPlayer->hAILRedbook)
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1107 AIL_redbook_pause(pAudioPlayer->hAILRedbook);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1108
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1109 bStopBeforeSchedule = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1110 bFirstFrame = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1111
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1112 this->bLoopPlaying = a3_1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1113 /*if ( LOBYTE(this->field_104) == 1 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1114 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1115 MessageBoxA(nullptr, "Unsupported Bink playback!", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Video.cpp:925", 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1116 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1117 }*/
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1118
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1119 LoadMovie(pMovieName);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1120 time_video_begin = GetTickCount();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1121 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1122 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1123
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1124 //----- (004BE70E) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1125 void MPlayer::FullscreenMovieLoop(const char *pMovieName, int a2/*, int ScreenSizeFlag, int a4*/)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1126 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1127 int v4; // ebp@1
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1128 MSG Msg; // [sp+Ch] [bp-1Ch]@12
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1129
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1130 v4 = a2;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1131 if ( dword_6BE364_game_settings_1 & (GAME_SETTINGS_NO_HOUSE_ANIM | GAME_SETTINGS_NO_INTRO) ||
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1132 bNoVideo)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1133 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1134
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1135 if ( a2 == 2 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1136 v4 = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1137 ShowCursor(0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1138 OpenFullscreenMovie(pMovieName, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1139 bPlaying_Movie = 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1140 field_44 = v4;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1141 pRenderer->ClearTarget(0);
2541
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2540
diff changeset
1142 current_screen_type = SCREEN_VIDEO;
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1143
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1144 auto hwnd = pMediaPlayer->window->GetApiHandle();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1145
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1146 RECT rc_client;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1147 GetClientRect(hwnd, &rc_client);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1148 int client_width = rc_client.right - rc_client.left,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1149 client_height = rc_client.bottom - rc_client.top;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1150
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1151 HDC dc = GetDC(hwnd);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1152 HDC back_dc = CreateCompatibleDC(dc);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1153 HBITMAP back_bmp = CreateCompatibleBitmap(dc, client_width, client_height);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1154 auto frame_buffer = new char[client_width * client_height * 4];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1155 SelectObject(back_dc, back_bmp);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1156
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1157 DWORD t = GetTickCount();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1158
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1159 bPlaying_Movie = true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1160
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1161 while (true)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1162 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1163 if (pMediaPlayer->bStopBeforeSchedule)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1164 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1165 while (PeekMessageA(&Msg, hwnd, 0, 0, PM_REMOVE))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1166 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1167 if (Msg.message == WM_QUIT)
2541
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2540
diff changeset
1168 Engine_DeinitializeAndTerminate(0);
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1169 if (Msg.message == WM_PAINT)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1170 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1171 TranslateMessage(&Msg);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1172 DispatchMessageA(&Msg);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1173 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1174
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1175 double dt = (GetTickCount() - t) / 1000.0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1176 t = GetTickCount();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1177
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1178 pMovie_Track->GetNextFrame(dt, frame_buffer);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1179
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1180 if (!bPlaying_Movie)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1181 break;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1182
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1183 if (frame_buffer)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1184 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1185 // draw to hwnd
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1186 BITMAPINFO bmi;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1187 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1188 bmi.bmiHeader.biWidth = client_width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1189 bmi.bmiHeader.biHeight = -client_height;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1190 bmi.bmiHeader.biPlanes = 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1191 bmi.bmiHeader.biBitCount = 32;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1192 bmi.bmiHeader.biCompression = BI_RGB;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1193 bmi.bmiHeader.biSizeImage = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1194 bmi.bmiHeader.biXPelsPerMeter = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1195 bmi.bmiHeader.biYPelsPerMeter = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1196 bmi.bmiHeader.biClrUsed = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1197 bmi.bmiHeader.biClrImportant = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1198 GetDIBits(back_dc, back_bmp, 0, client_height, 0, &bmi, DIB_RGB_COLORS);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1199 SetDIBits(back_dc, back_bmp, 0, client_height, frame_buffer, &bmi, DIB_RGB_COLORS);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1200 BitBlt(dc, 0, 0, client_width, client_height, back_dc, 0, 0, SRCCOPY);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1201 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1202
2541
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2540
diff changeset
1203 MainMenu_EventLoop();
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1204
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1205 if (pMediaPlayer->bStopBeforeSchedule == 1)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1206 Sleep(1000);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1207 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1208 delete [] frame_buffer;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1209 DeleteObject(back_bmp);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1210 DeleteObject(back_dc);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1211 ReleaseDC(hwnd, dc);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1212
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1213 pMediaPlayer->Unload();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1214
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1215 //if (a4 == 1)
2541
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2540
diff changeset
1216 current_screen_type = SCREEN_GAME;
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1217
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1218 pMediaPlayer->bPlaying_Movie = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1219
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1220 ShowCursor(1);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1221
2541
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2540
diff changeset
1222 /*if ( current_screen_type == SCREEN_VIDEO )
a902abdfc7f2 1. Renamed class Game to class Engine.
a.parshin
parents: 2540
diff changeset
1223 current_screen_type = SCREEN_GAME;*/
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1224 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1225
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1226 void MPlayer::HouseMovieLoop()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1227 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1228 if (pMovie_Track && !bNoVideo)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1229 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1230 pRenderer->BeginScene();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1231 pMouse->DrawCursorToTarget();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1232
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1233 Log::Warning(L"smacker");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1234 loop_current_file = true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1235 pRenderer->BeginScene();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1236 if (!bPlaying_Movie)//reload
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1237 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1238 unsigned int width = game_viewport_width;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1239 unsigned int height = game_viewport_height;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1240 MovieRelease();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1241
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1242 SetFilePointer(hVidFile, uOffset, nullptr, FILE_BEGIN);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1243 pMovie_Track = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1244 Log::Warning(L"reload pMovie_Track");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1245 pMovie_Track = pMediaPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, width, height);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1246 bPlaying_Movie = true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1247 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1248 //else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1249 //{
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1250 double dt = (GetTickCount() - time_video_begin) / 1000.0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1251 //dt = 1.0/15.0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1252 time_video_begin = GetTickCount();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1253
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1254 //log("dt=%.5f\n", dt);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1255
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1256 auto image = new char[current_movie_width * current_movie_height * 4];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1257
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1258 pMovie_Track->GetNextFrame(dt, image);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1259
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1260 int image_array[460 * 344];//game_viewport_width * game_viewport_height
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1261 if (image)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1262 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1263 memcpy(image_array, image, sizeof (image_array));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1264 for (unsigned int y = 8; y < 8 + game_viewport_height; ++y)//êîîðäèíàòû ìåñòîïîëîæåíèÿ âèäåîðîëèêà
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1265 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1266 for (unsigned int x = 8; x < 8 + game_viewport_width; ++x)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1267 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1268 auto p = (unsigned __int32 *)pRenderer->pTargetSurface + x + y * pRenderer->uTargetSurfacePitch;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1269 *p = image_array[((x - 8) + ((y - 8)*game_viewport_width))];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1270 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1271 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1272 delete[] image;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1273 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1274 //}
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1275 pRenderer->EndScene();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1276 pMouse->ReadCursorWithItem();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1277 pRenderer->EndScene();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1278 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1279 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1280
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1281 //----- (004BF73A) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1282 void MPlayer::SelectMovieType()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1283 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1284 char Source[32]; // [sp+Ch] [bp-40h]@1
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1285
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1286 strcpy(Source, this->pCurrentMovieName);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1287 pMediaPlayer->Unload();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1288 if ( this->uMovieType == 1 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1289 OpenHouseMovie(Source, LOBYTE(this->bLoopPlaying));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1290 else if ( this->uMovieType == 2 )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1291 OpenFullscreenMovie(Source, LOBYTE(this->bLoopPlaying));
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1292 else
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1293 __debugbreak();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1294 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1295
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1296 void MPlayer::LoadMovie(const char *pFilename)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1297 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1298 char pVideoNameBik[120]; // [sp+Ch] [bp-28h]@2
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1299 char pVideoNameSmk[120]; // [sp+Ch] [bp-28h]@2
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1300
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1301 sprintf(pVideoNameBik, "%s.bik", pFilename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1302 sprintf(pVideoNameSmk, "%s.smk", pFilename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1303 for (uint i = 0; i < uNumMightVideoHeaders; ++i)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1304 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1305 if (!_stricmp(pVideoNameSmk, pMightVideoHeaders[i].pVideoName))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1306 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1307 hVidFile = hMightVid;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1308 uOffset = pMightVideoHeaders[i].uFileOffset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1309 uSize = pMightVideoHeaders[i + 1].uFileOffset - uOffset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1310 this->uMovieType = 2;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1311 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1312 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1313 for (uint i = 0; i < uNumMagicVideoHeaders; ++i)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1314 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1315 if (!_stricmp(pVideoNameBik, pMagicVideoHeaders[i].pVideoName))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1316 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1317 hVidFile = hMagicVid;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1318 uOffset = pMagicVideoHeaders[i].uFileOffset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1319 uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1320 this->uMovieType = 1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1321 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1322 if (!_stricmp(pVideoNameSmk, pMagicVideoHeaders[i].pVideoName))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1323 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1324 hVidFile = hMagicVid;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1325 uOffset = pMagicVideoHeaders[i].uFileOffset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1326 uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1327 this->uMovieType = 2;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1328 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1329 }
2572
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1330 if (hVidFile == INVALID_HANDLE_VALUE)
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1331 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1332 pMediaPlayer->Unload();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1333 MessageBoxA(0, "MediaPlayer error", "MediaPlayer Error", 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1334 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1335 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1336
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1337 SetFilePointer(hVidFile, uOffset, 0, FILE_BEGIN);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1338 strcpy(this->pCurrentMovieName, pFilename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1339
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1340 auto hwnd = pMediaPlayer->window->GetApiHandle();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1341 RECT rc_client;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1342 GetClientRect(hwnd, &rc_client);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1343 int client_width = rc_client.right - rc_client.left,
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1344 client_height = rc_client.bottom - rc_client.top;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1345
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1346 pMovie_Track = pMediaPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, client_width, client_height);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1347 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1348
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1349 //----- (004BF794) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1350 void MPlayer::ShowMM7IntroVideo_and_LoadingScreen()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1351 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1352 pMediaPlayer->bStopBeforeSchedule = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1353 // pMediaPlayer->pResetflag = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1354 bGameoverLoop = true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1355 if (!bNoVideo)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1356 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1357 pRenderer->PresentBlackScreen();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1358 if ( !pMediaPlayer->bStopBeforeSchedule )
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1359 PlayFullscreenMovie(MOVIE_Intro, true);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1360 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1361
2572
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1362 Image *tex = assets->GetImage_PCXFromIconsLOD(L"mm6title.pcx");
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1363
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1364 pRenderer->BeginScene();
2572
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1365 pRenderer->DrawTextureNew(0, 0, tex);
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1366
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1367 //LoadFonts_and_DrawCopyrightWindow();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1368 DrawMM7CopyrightWindow();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1369
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1370 pRenderer->EndScene();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1371 pRenderer->Present();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1372
2572
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1373 tex->Release();
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1374 tex = nullptr;
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1375
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1376 #ifndef _DEBUG
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1377 Sleep(1500); // let the copyright window stay for a while
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1378 #endif
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1379
2572
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1380 if (!bNoSound)
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1381 pAudioPlayer->PlayMusicTrack(MUSIC_MainMenu);
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1382
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1383 bGameoverLoop = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1384 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1385
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1386 //----- (004BEBD7) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1387 void MPlayer::Unload()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1388 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1389 bPlaying_Movie = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1390 uMovieType = 0;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1391 memset(pCurrentMovieName, 0, 0x40);
2510
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1392 if ( !bGameoverLoop && pMediaPlayer->current_movie_width == 460)
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1393 {
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1394 if ( use_music_folder )
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1395 alSourcePlay(mSourceID);
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1396 else if ( pAudioPlayer->hAILRedbook )
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1397 AIL_redbook_resume(pAudioPlayer->hAILRedbook);
ae2b7048b3eb alSourcePause
Ritor1
parents: 2508
diff changeset
1398 }
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1399 pEventTimer->Resume();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1400
2572
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1401 if (pMovie_Track)
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1402 {
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1403 pMovie_Track->Release();
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1404 delete pMovie_Track;
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1405 }
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1406 pMovie_Track = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1407 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1408
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1409 int MPlayer::readFunction(void* opaque, uint8_t* buf, int buf_size)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1410 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1411 HANDLE stream = (HANDLE)opaque;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1412 //int numBytes = stream->read((char*)buf, buf_size);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1413 int numBytes;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1414 ReadFile(stream, (char *)buf, buf_size, (LPDWORD)&numBytes, NULL);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1415 return numBytes;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1416 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1417
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1418 int64_t MPlayer::seekFunction(void* opaque, int64_t offset, int whence)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1419 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1420 if (whence == AVSEEK_SIZE)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1421 return pMediaPlayer->uSize;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1422 HANDLE h = (HANDLE)opaque;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1423 LARGE_INTEGER li;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1424 li.QuadPart = offset;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1425
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1426 if (!SetFilePointerEx(h, li, (PLARGE_INTEGER)&li, FILE_BEGIN))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1427 return -1;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1428 return li.QuadPart;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1429 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1430
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1431 //for video//////////////////////////////////////////////////////////////////
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1432
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1433
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1434
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1435 IMovie *MPlayer::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
1436 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1437 movie = new Movie;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1438 Log::Warning(L"allocation dynamic memory for movie\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1439 if (movie)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1440 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1441 if (movie->LoadFromLOD(h, readFunction, seekFunction, width, height))
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1442 return movie;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1443 delete movie;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1444 Log::Warning(L"delete dynamic memory for movie\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1445 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1446 return nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1447 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1448
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1449 void MovieRelease()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1450 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1451 movie->Release();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1452 delete movie;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1453 Log::Warning(L"delete dynamic memory for movie\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1454 movie = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1455 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1456
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1457
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1458 //for audio///////////////////////////////////////////////////////
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1459 //----- (004AB818) --------------------------------------------------------
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1460 void MPlayer::LoadAudioSnd()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1461 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1462 DWORD NumberOfBytesRead; // [sp+Ch] [bp-4h]@3
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1463
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1464 hAudioSnd = CreateFileA("Sounds\\Audio.snd", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080u, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1465 if (hAudioSnd == INVALID_HANDLE_VALUE)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1466 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1467 Log::Warning(L"Can't open file: %s", L"Sounds\\Audio.snd");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1468 return;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1469 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1470
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1471 ReadFile(hAudioSnd, &uNumSoundHeaders, 4, &NumberOfBytesRead, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1472 pSoundHeaders = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1473 pSoundHeaders = (SoundHeader *)malloc(52 * uNumSoundHeaders + 2);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1474 ReadFile(hAudioSnd, pSoundHeaders, 52 * uNumSoundHeaders, &NumberOfBytesRead, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1475 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1476 //for audio///////////////////////////////////////////////////////
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1477
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1478 void av_logger(void *, int, const char *format, va_list args)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1479 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1480 va_list va;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1481 va_start(va, format);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1482 char msg[256];
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1483 vsprintf(msg, format, va);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1484 va_end(va);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1485
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1486 log("av: %s", msg);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1487 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1488
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1489 MPlayer::MPlayer()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1490 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1491 bPlaying_Movie = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1492
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1493 static int libavcodec_initialized = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1494
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1495 if (!libavcodec_initialized)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1496 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1497 av_log_set_callback(av_logger);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1498 avcodec_register_all();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1499
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1500 // Register all available file formats and codecs
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1501 av_register_all();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1503 libavcodec_initialized = true;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1504 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1505
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1506 bStopBeforeSchedule = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1507 pMovie_Track = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1508
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1509 if (!provider)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1510 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1511 provider = new OpenALSoundProvider;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1512 Log::Warning(L"allocation dynamic memory for provider\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1513 provider->Initialize();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1514 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1515 LoadAudioSnd();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1516 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1517
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1518 MPlayer::~MPlayer()
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1519 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1520 delete provider;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1521 Log::Warning(L"delete dynamic memory for provider\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1522
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1523 bStopBeforeSchedule = false;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1524 // pResetflag = 0;
2572
d87bfbd3bb3b Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents: 2567
diff changeset
1525 // pVideoFrame.Release();
2502
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1526 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1527
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1528 void PlayAudio(const wchar_t * pFilename)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1529 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1530 pAudio_Track = pMediaPlayer->LoadTrack(pFilename);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1531 pAudio_Track->Play();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1532 delete pAudio_Track;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1533 Log::Warning(L"delete dynamic memory for pAudio_Track\n");
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1534 pAudio_Track = nullptr;
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1535 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1536
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1537 void PlayMovie(const wchar_t * pFilename)
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1538 {
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1539 Media::IMovie *Movie_track = pMediaPlayer->LoadMovie(pFilename, 640, 480, 0);
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1540 Movie_track->Play();
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1541 }
a77c34acdbc9 Media folder
Ritor1
parents:
diff changeset
1542