annotate MediaPlayer.cpp @ 2461:ff7f4995aa25

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