author | Stepan777 <stepik-777@mail.ru> |
Sun, 24 Jun 2012 20:57:02 +0400 | |
changeset 7280 | fd707afbc3a2 |
parent 7235 | baa69bd025d9 |
child 7286 | 068adc6948e3 |
permissions | -rw-r--r-- |
7180 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
19 |
{$INCLUDE "options.inc"} |
|
20 |
||
21 |
unit uVideoRec; |
|
22 |
||
23 |
{$IFDEF UNIX} |
|
24 |
{$LINKLIB avwrapper} |
|
25 |
{$LINKLIB avutil} |
|
26 |
{$LINKLIB avcodec} |
|
27 |
{$LINKLIB avformat} |
|
28 |
{$ENDIF} |
|
29 |
||
30 |
interface |
|
31 |
||
32 |
var flagPrerecording: boolean = false; |
|
33 |
||
34 |
function BeginVideoRecording: Boolean; |
|
35 |
function LoadNextCameraPosition: LongInt; |
|
36 |
procedure EncodeFrame; |
|
37 |
procedure StopVideoRecording; |
|
38 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
39 |
procedure BeginPreRecording; |
7180 | 40 |
procedure StopPreRecording; |
41 |
procedure SaveCameraPosition; |
|
42 |
||
43 |
procedure freeModule; |
|
44 |
||
45 |
implementation |
|
46 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
47 |
uses uVariables, uUtils, GLunit, SDLh, SysUtils, uIO; |
7180 | 48 |
|
49 |
{$IFDEF WIN32} |
|
50 |
const AVWrapperLibName = 'libavwrapper.dll'; |
|
51 |
{$ENDIF} |
|
52 |
||
53 |
type TAddFileLogRaw = procedure (s: pchar); cdecl; |
|
54 |
||
55 |
{$IFDEF WIN32} |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
56 |
procedure AVWrapper_Init( |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
57 |
AddLog: TAddFileLogRaw; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
58 |
filename, desc, soundFile, format, vcodec, acodec, preset: PChar; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
59 |
width, height, framerateNum, framerateDen, vquality, aquality: LongInt); cdecl; external AVWrapperLibName; |
7180 | 60 |
procedure AVWrapper_Close; cdecl; external AVWrapperLibName; |
61 |
procedure AVWrapper_WriteFrame( pY, pCb, pCr: PByte ); cdecl; external AVWrapperLibName; |
|
62 |
{$ELSE} |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
63 |
procedure AVWrapper_Init( |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
64 |
AddLog: TAddFileLogRaw; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
65 |
filename, desc, soundFile, format, vcodec, acodec, preset: PChar; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
66 |
width, height, framerateNum, framerateDen, vquality, aquality: LongInt); cdecl; external; |
7180 | 67 |
procedure AVWrapper_Close; cdecl; external; |
68 |
procedure AVWrapper_WriteFrame( pY, pCb, pCr: PByte ); cdecl; external; |
|
69 |
{$ENDIF} |
|
70 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
71 |
type TFrame = record |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
72 |
ticks: LongWord; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
73 |
CamX, CamY: LongInt; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
74 |
zoom: single; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
75 |
end; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
76 |
|
7180 | 77 |
var YCbCr_Planes: array[0..2] of PByte; |
78 |
RGB_Buffer: PByte; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
79 |
cameraFile: File of TFrame; |
7180 | 80 |
audioFile: File; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
81 |
numPixels: LongWord; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
82 |
startTime, numFrames: LongWord; |
7180 | 83 |
cameraFilePath, soundFilePath: shortstring; |
84 |
||
85 |
function BeginVideoRecording: Boolean; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
86 |
var filename, desc: shortstring; |
7180 | 87 |
begin |
88 |
AddFileLog('BeginVideoRecording'); |
|
89 |
||
90 |
numPixels:= cScreenWidth*cScreenHeight; |
|
91 |
||
92 |
{$IOCHECKS OFF} |
|
93 |
// open file with prerecorded camera positions |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
94 |
cameraFilePath:= UserPathPrefix + '/VideoTemp/' + cRecPrefix + '.txtin'; |
7180 | 95 |
Assign(cameraFile, cameraFilePath); |
96 |
Reset(cameraFile); |
|
97 |
if IOResult <> 0 then |
|
98 |
begin |
|
99 |
AddFileLog('Error: Could not read from ' + cameraFilePath); |
|
100 |
exit(false); |
|
101 |
end; |
|
102 |
{$IOCHECKS ON} |
|
103 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
104 |
desc:= ''; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
105 |
if UserNick <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
106 |
desc+= 'Player: ' + UserNick + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
107 |
if recordFileName <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
108 |
desc+= 'Record: ' + recordFileName + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
109 |
if cMapName <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
110 |
desc+= 'Map: ' + cMapName + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
111 |
if Theme <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
112 |
desc+= 'Theme: ' + Theme + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
113 |
desc+= #0; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
114 |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
115 |
filename:= UserPathPrefix + '/VideoTemp/' + cRecPrefix + #0; |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
116 |
soundFilePath:= UserPathPrefix + '/VideoTemp/' + cRecPrefix + '.sw' + #0; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
117 |
cAVFormat+= #0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
118 |
cAudioCodec+= #0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
119 |
cVideoCodec+= #0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
120 |
cVideoPreset+= #0; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
121 |
AVWrapper_Init(@AddFileLogRaw, @filename[1], @desc[1], @soundFilePath[1], @cAVFormat[1], @cVideoCodec[1], @cAudioCodec[1], @cVideoPreset[1], |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
122 |
cScreenWidth, cScreenHeight, cVideoFramerateNum, cVideoFramerateDen, cAudioQuality, cVideoQuality); |
7180 | 123 |
|
124 |
YCbCr_Planes[0]:= GetMem(numPixels); |
|
125 |
YCbCr_Planes[1]:= GetMem(numPixels div 4); |
|
126 |
YCbCr_Planes[2]:= GetMem(numPixels div 4); |
|
127 |
||
128 |
if (YCbCr_Planes[0] = nil) or (YCbCr_Planes[1] = nil) or (YCbCr_Planes[2] = nil) then |
|
129 |
begin |
|
130 |
AddFileLog('Error: Could not allocate memory for video recording (YCbCr buffer).'); |
|
131 |
exit(false); |
|
132 |
end; |
|
133 |
||
134 |
RGB_Buffer:= GetMem(4*numPixels); |
|
135 |
if RGB_Buffer = nil then |
|
136 |
begin |
|
137 |
AddFileLog('Error: Could not allocate memory for video recording (RGB buffer).'); |
|
138 |
exit(false); |
|
139 |
end; |
|
140 |
||
141 |
BeginVideoRecording:= true; |
|
142 |
end; |
|
143 |
||
144 |
procedure StopVideoRecording; |
|
145 |
begin |
|
146 |
AddFileLog('StopVideoRecording'); |
|
147 |
FreeMem(YCbCr_Planes[0], numPixels); |
|
148 |
FreeMem(YCbCr_Planes[1], numPixels div 4); |
|
149 |
FreeMem(YCbCr_Planes[2], numPixels div 4); |
|
150 |
FreeMem(RGB_Buffer, 4*numPixels); |
|
151 |
Close(cameraFile); |
|
152 |
AVWrapper_Close(); |
|
153 |
DeleteFile(cameraFilePath); |
|
154 |
DeleteFile(soundFilePath); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
155 |
SendIPC(_S'v'); |
7180 | 156 |
end; |
157 |
||
158 |
function pixel(x, y, color: LongInt): LongInt; |
|
159 |
begin |
|
160 |
pixel:= RGB_Buffer[(cScreenHeight-y-1)*cScreenWidth*4 + x*4 + color]; |
|
161 |
end; |
|
162 |
||
163 |
procedure EncodeFrame; |
|
164 |
var x, y, r, g, b: LongInt; |
|
165 |
begin |
|
166 |
// read pixels from OpenGL |
|
167 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_RGBA, GL_UNSIGNED_BYTE, RGB_Buffer); |
|
168 |
||
169 |
// convert to YCbCr 4:2:0 format |
|
170 |
// Y |
|
171 |
for y := 0 to cScreenHeight-1 do |
|
172 |
for x := 0 to cScreenWidth-1 do |
|
173 |
YCbCr_Planes[0][y*cScreenWidth + x]:= Byte(16 + ((16828*pixel(x,y,0) + 33038*pixel(x,y,1) + 6416*pixel(x,y,2)) shr 16)); |
|
174 |
||
175 |
// Cb and Cr |
|
176 |
for y := 0 to cScreenHeight div 2 - 1 do |
|
177 |
for x := 0 to cScreenWidth div 2 - 1 do |
|
178 |
begin |
|
179 |
r:= pixel(2*x,2*y,0) + pixel(2*x+1,2*y,0) + pixel(2*x,2*y+1,0) + pixel(2*x+1,2*y+1,0); |
|
180 |
g:= pixel(2*x,2*y,1) + pixel(2*x+1,2*y,1) + pixel(2*x,2*y+1,1) + pixel(2*x+1,2*y+1,1); |
|
181 |
b:= pixel(2*x,2*y,2) + pixel(2*x+1,2*y,2) + pixel(2*x,2*y+1,2) + pixel(2*x+1,2*y+1,2); |
|
182 |
YCbCr_Planes[1][y*(cScreenWidth div 2) + x]:= Byte(128 + ((-2428*r - 4768*g + 7196*b) shr 16)); |
|
183 |
YCbCr_Planes[2][y*(cScreenWidth div 2) + x]:= Byte(128 + (( 7196*r - 6026*g - 1170*b) shr 16)); |
|
184 |
end; |
|
185 |
||
186 |
AVWrapper_WriteFrame(YCbCr_Planes[0], YCbCr_Planes[1], YCbCr_Planes[2]); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
187 |
|
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
188 |
// inform frontend that we have encoded new frame (p for progress) |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
189 |
SendIPC(_S'p'); |
7180 | 190 |
end; |
191 |
||
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
192 |
// returns new game ticks |
7180 | 193 |
function LoadNextCameraPosition: LongInt; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
194 |
var frame: TFrame; |
7180 | 195 |
begin |
196 |
{$IOCHECKS OFF} |
|
197 |
if eof(cameraFile) then |
|
198 |
exit(-1); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
199 |
BlockRead(cameraFile, frame, 1); |
7180 | 200 |
{$IOCHECKS ON} |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
201 |
WorldDx:= frame.CamX; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
202 |
WorldDy:= frame.CamY + cScreenHeight div 2; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
203 |
zoom:= frame.zoom*cScreenWidth; |
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
204 |
ZoomValue:= zoom; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
205 |
LoadNextCameraPosition:= frame.ticks; |
7180 | 206 |
end; |
207 |
||
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
208 |
// Callback which records sound. |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
209 |
// This procedure may be called from different thread. |
7180 | 210 |
procedure RecordPostMix(udata: pointer; stream: PByte; len: LongInt); cdecl; |
211 |
begin |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
212 |
udata:= udata; // avoid warning |
7180 | 213 |
{$IOCHECKS OFF} |
214 |
BlockWrite(audioFile, stream^, len); |
|
215 |
{$IOCHECKS ON} |
|
216 |
end; |
|
217 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
218 |
procedure BeginPreRecording; |
7180 | 219 |
var format: word; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
220 |
filePrefix, filename: shortstring; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
221 |
frequency, channels: LongInt; |
7180 | 222 |
begin |
223 |
AddFileLog('BeginPreRecording'); |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
224 |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
225 |
numFrames:= 0; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
226 |
startTime:= SDL_GetTicks(); |
7180 | 227 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
228 |
filePrefix:= FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
229 |
|
7180 | 230 |
Mix_QuerySpec(@frequency, @format, @channels); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
231 |
AddFileLog('sound: frequency = ' + IntToStr(frequency) + ', format = ' + IntToStr(format) + ', channels = ' + IntToStr(channels)); |
7180 | 232 |
if format <> $8010 then |
233 |
begin |
|
234 |
// TODO: support any audio format |
|
235 |
AddFileLog('Error: Unexpected audio format ' + IntToStr(format)); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
236 |
exit; |
7180 | 237 |
end; |
238 |
||
239 |
{$IOCHECKS OFF} |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
240 |
// create sound file |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
241 |
filename:= UserPathPrefix + '/VideoTemp/' + filePrefix + '.sw'; |
7180 | 242 |
Assign(audioFile, filename); |
243 |
Rewrite(audioFile, 1); |
|
244 |
if IOResult <> 0 then |
|
245 |
begin |
|
246 |
AddFileLog('Error: Could not write to ' + filename); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
247 |
exit; |
7180 | 248 |
end; |
249 |
||
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
250 |
// create file with camera positions |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
251 |
filename:= UserPathPrefix + '/VideoTemp/' + filePrefix + '.txtout'; |
7180 | 252 |
Assign(cameraFile, filename); |
253 |
Rewrite(cameraFile); |
|
254 |
if IOResult <> 0 then |
|
255 |
begin |
|
256 |
AddFileLog('Error: Could not write to ' + filename); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
257 |
exit; |
7180 | 258 |
end; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
259 |
|
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
260 |
BlockWrite(audioFile, frequency, 4); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
261 |
BlockWrite(audioFile, channels, 4); |
7180 | 262 |
{$IOCHECKS ON} |
263 |
||
264 |
// register callback for actual audio recording |
|
265 |
Mix_SetPostMix(@RecordPostMix, nil); |
|
266 |
||
267 |
flagPrerecording:= true; |
|
268 |
end; |
|
269 |
||
270 |
procedure StopPreRecording; |
|
271 |
begin |
|
272 |
AddFileLog('StopPreRecording'); |
|
273 |
flagPrerecording:= false; |
|
274 |
||
275 |
// call SDL_LockAudio because RecordPostMix may be executing right now |
|
276 |
SDL_LockAudio(); |
|
277 |
Close(audioFile); |
|
278 |
Close(cameraFile); |
|
279 |
Mix_SetPostMix(nil, nil); |
|
280 |
SDL_UnlockAudio(); |
|
281 |
end; |
|
282 |
||
283 |
procedure SaveCameraPosition; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
284 |
var curTime: LongInt; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
285 |
frame: TFrame; |
7180 | 286 |
begin |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
287 |
curTime:= SDL_GetTicks(); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
288 |
while Int64(curTime - startTime)*cVideoFramerateNum > Int64(numFrames)*cVideoFramerateDen*1000 do |
7180 | 289 |
begin |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
290 |
frame.ticks:= GameTicks; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
291 |
frame.CamX:= WorldDx; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
292 |
frame.CamY:= WorldDy - cScreenHeight div 2; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
293 |
frame.zoom:= zoom/cScreenWidth; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
294 |
BlockWrite(cameraFile, frame, 1); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
295 |
inc(numFrames); |
7180 | 296 |
end; |
297 |
end; |
|
298 |
||
299 |
procedure freeModule; |
|
300 |
begin |
|
301 |
if flagPrerecording then |
|
302 |
StopPreRecording(); |
|
303 |
end; |
|
304 |
||
305 |
end. |