author | Stepan777 <stepik-777@mail.ru> |
Mon, 09 Jul 2012 16:42:13 +0400 | |
changeset 7373 | d5ec4e4eb2d5 |
parent 7369 | 46921fbe76d3 |
child 7376 | 48b79b3ca592 |
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 |
||
7286 | 19 |
|
7180 | 20 |
{$INCLUDE "options.inc"} |
21 |
||
22 |
unit uVideoRec; |
|
23 |
||
7286 | 24 |
{$IFNDEF USE_VIDEO_RECORDING} |
25 |
interface |
|
26 |
implementation |
|
27 |
end. |
|
28 |
{$ELSE} |
|
29 |
||
7180 | 30 |
{$IFDEF UNIX} |
31 |
{$LINKLIB avwrapper} |
|
32 |
{$LINKLIB avutil} |
|
33 |
{$LINKLIB avcodec} |
|
34 |
{$LINKLIB avformat} |
|
35 |
{$ENDIF} |
|
36 |
||
37 |
interface |
|
38 |
||
39 |
var flagPrerecording: boolean = false; |
|
40 |
||
41 |
function BeginVideoRecording: Boolean; |
|
42 |
function LoadNextCameraPosition: LongInt; |
|
43 |
procedure EncodeFrame; |
|
44 |
procedure StopVideoRecording; |
|
45 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
46 |
procedure BeginPreRecording; |
7180 | 47 |
procedure StopPreRecording; |
48 |
procedure SaveCameraPosition; |
|
49 |
||
50 |
procedure freeModule; |
|
51 |
||
52 |
implementation |
|
53 |
||
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
54 |
uses uVariables, uUtils, GLunit, SDLh, SysUtils, uIO, uMisc, uTypes; |
7180 | 55 |
|
56 |
{$IFDEF WIN32} |
|
57 |
const AVWrapperLibName = 'libavwrapper.dll'; |
|
58 |
{$ENDIF} |
|
59 |
||
60 |
type TAddFileLogRaw = procedure (s: pchar); cdecl; |
|
61 |
||
62 |
{$IFDEF WIN32} |
|
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 AVWrapperLibName; |
7180 | 67 |
procedure AVWrapper_Close; cdecl; external AVWrapperLibName; |
68 |
procedure AVWrapper_WriteFrame( pY, pCb, pCr: PByte ); cdecl; external AVWrapperLibName; |
|
69 |
{$ELSE} |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
70 |
procedure AVWrapper_Init( |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
71 |
AddLog: TAddFileLogRaw; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
72 |
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
|
73 |
width, height, framerateNum, framerateDen, vquality, aquality: LongInt); cdecl; external; |
7180 | 74 |
procedure AVWrapper_Close; cdecl; external; |
75 |
procedure AVWrapper_WriteFrame( pY, pCb, pCr: PByte ); cdecl; external; |
|
76 |
{$ENDIF} |
|
77 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
78 |
type TFrame = record |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
79 |
ticks: LongWord; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
80 |
CamX, CamY: LongInt; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
81 |
zoom: single; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
82 |
end; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
83 |
|
7180 | 84 |
var YCbCr_Planes: array[0..2] of PByte; |
85 |
RGB_Buffer: PByte; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
86 |
cameraFile: File of TFrame; |
7180 | 87 |
audioFile: File; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
88 |
numPixels: LongWord; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
89 |
startTime, numFrames: LongWord; |
7180 | 90 |
cameraFilePath, soundFilePath: shortstring; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
91 |
thumbnailSaved : Boolean; |
7180 | 92 |
|
93 |
function BeginVideoRecording: Boolean; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
94 |
var filename, desc: shortstring; |
7180 | 95 |
begin |
96 |
AddFileLog('BeginVideoRecording'); |
|
97 |
||
98 |
numPixels:= cScreenWidth*cScreenHeight; |
|
99 |
||
100 |
{$IOCHECKS OFF} |
|
101 |
// open file with prerecorded camera positions |
|
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
102 |
cameraFilePath:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.txtin'; |
7180 | 103 |
Assign(cameraFile, cameraFilePath); |
104 |
Reset(cameraFile); |
|
105 |
if IOResult <> 0 then |
|
106 |
begin |
|
107 |
AddFileLog('Error: Could not read from ' + cameraFilePath); |
|
108 |
exit(false); |
|
109 |
end; |
|
110 |
{$IOCHECKS ON} |
|
111 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
112 |
desc:= ''; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
113 |
if UserNick <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
114 |
desc+= 'Player: ' + UserNick + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
115 |
if recordFileName <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
116 |
desc+= 'Record: ' + recordFileName + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
117 |
if cMapName <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
118 |
desc+= 'Map: ' + cMapName + #10; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
119 |
if Theme <> '' then |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
120 |
desc+= 'Theme: ' + Theme + #10; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
121 |
desc+= 'prefix[' + RecPrefix + ']prefix'; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
122 |
desc+= #0; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
123 |
|
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
124 |
filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + #0; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
125 |
soundFilePath:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw' + #0; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
126 |
cAVFormat+= #0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
127 |
cAudioCodec+= #0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
128 |
cVideoCodec+= #0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
129 |
cVideoPreset+= #0; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
130 |
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
|
131 |
cScreenWidth, cScreenHeight, cVideoFramerateNum, cVideoFramerateDen, cAudioQuality, cVideoQuality); |
7180 | 132 |
|
133 |
YCbCr_Planes[0]:= GetMem(numPixels); |
|
134 |
YCbCr_Planes[1]:= GetMem(numPixels div 4); |
|
135 |
YCbCr_Planes[2]:= GetMem(numPixels div 4); |
|
136 |
||
137 |
if (YCbCr_Planes[0] = nil) or (YCbCr_Planes[1] = nil) or (YCbCr_Planes[2] = nil) then |
|
138 |
begin |
|
139 |
AddFileLog('Error: Could not allocate memory for video recording (YCbCr buffer).'); |
|
140 |
exit(false); |
|
141 |
end; |
|
142 |
||
143 |
RGB_Buffer:= GetMem(4*numPixels); |
|
144 |
if RGB_Buffer = nil then |
|
145 |
begin |
|
146 |
AddFileLog('Error: Could not allocate memory for video recording (RGB buffer).'); |
|
147 |
exit(false); |
|
148 |
end; |
|
149 |
||
150 |
BeginVideoRecording:= true; |
|
151 |
end; |
|
152 |
||
153 |
procedure StopVideoRecording; |
|
154 |
begin |
|
155 |
AddFileLog('StopVideoRecording'); |
|
156 |
FreeMem(YCbCr_Planes[0], numPixels); |
|
157 |
FreeMem(YCbCr_Planes[1], numPixels div 4); |
|
158 |
FreeMem(YCbCr_Planes[2], numPixels div 4); |
|
159 |
FreeMem(RGB_Buffer, 4*numPixels); |
|
160 |
Close(cameraFile); |
|
161 |
AVWrapper_Close(); |
|
162 |
DeleteFile(cameraFilePath); |
|
163 |
DeleteFile(soundFilePath); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
164 |
SendIPC(_S'v'); |
7180 | 165 |
end; |
166 |
||
167 |
function pixel(x, y, color: LongInt): LongInt; |
|
168 |
begin |
|
169 |
pixel:= RGB_Buffer[(cScreenHeight-y-1)*cScreenWidth*4 + x*4 + color]; |
|
170 |
end; |
|
171 |
||
172 |
procedure EncodeFrame; |
|
173 |
var x, y, r, g, b: LongInt; |
|
174 |
begin |
|
175 |
// read pixels from OpenGL |
|
176 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_RGBA, GL_UNSIGNED_BYTE, RGB_Buffer); |
|
177 |
||
178 |
// convert to YCbCr 4:2:0 format |
|
179 |
// Y |
|
180 |
for y := 0 to cScreenHeight-1 do |
|
181 |
for x := 0 to cScreenWidth-1 do |
|
182 |
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)); |
|
183 |
||
184 |
// Cb and Cr |
|
185 |
for y := 0 to cScreenHeight div 2 - 1 do |
|
186 |
for x := 0 to cScreenWidth div 2 - 1 do |
|
187 |
begin |
|
188 |
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); |
|
189 |
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); |
|
190 |
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); |
|
191 |
YCbCr_Planes[1][y*(cScreenWidth div 2) + x]:= Byte(128 + ((-2428*r - 4768*g + 7196*b) shr 16)); |
|
192 |
YCbCr_Planes[2][y*(cScreenWidth div 2) + x]:= Byte(128 + (( 7196*r - 6026*g - 1170*b) shr 16)); |
|
193 |
end; |
|
194 |
||
195 |
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
|
196 |
|
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
197 |
// 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
|
198 |
SendIPC(_S'p'); |
7180 | 199 |
end; |
200 |
||
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
201 |
// returns new game ticks |
7180 | 202 |
function LoadNextCameraPosition: LongInt; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
203 |
var frame: TFrame; |
7180 | 204 |
begin |
205 |
{$IOCHECKS OFF} |
|
206 |
if eof(cameraFile) then |
|
207 |
exit(-1); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
208 |
BlockRead(cameraFile, frame, 1); |
7180 | 209 |
{$IOCHECKS ON} |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
210 |
WorldDx:= frame.CamX; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
211 |
WorldDy:= frame.CamY + cScreenHeight div 2; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
212 |
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
|
213 |
ZoomValue:= zoom; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
214 |
LoadNextCameraPosition:= frame.ticks; |
7180 | 215 |
end; |
216 |
||
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
217 |
// 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
|
218 |
// This procedure may be called from different thread. |
7180 | 219 |
procedure RecordPostMix(udata: pointer; stream: PByte; len: LongInt); cdecl; |
220 |
begin |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
221 |
udata:= udata; // avoid warning |
7180 | 222 |
{$IOCHECKS OFF} |
223 |
BlockWrite(audioFile, stream^, len); |
|
224 |
{$IOCHECKS ON} |
|
225 |
end; |
|
226 |
||
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
227 |
procedure SaveThumbnail; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
228 |
var thumbpath: shortstring; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
229 |
k: LongInt; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
230 |
begin |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
231 |
thumbpath:= '/VideoTemp/' + RecPrefix; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
232 |
AddFileLog('Saving thumbnail ' + thumbpath); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
233 |
if cScreenWidth > cScreenHeight then |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
234 |
k:= cScreenWidth div 400 // here 400 is minimum size of thumbnail |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
235 |
else |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
236 |
k:= cScreenHeight div 400; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
237 |
if k = 0 then |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
238 |
k:= 1; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
239 |
MakeScreenshot(thumbpath, k); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
240 |
thumbnailSaved:= true; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
241 |
end; |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
242 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
243 |
procedure BeginPreRecording; |
7180 | 244 |
var format: word; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
245 |
filename: shortstring; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
246 |
frequency, channels: LongInt; |
7180 | 247 |
begin |
248 |
AddFileLog('BeginPreRecording'); |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
249 |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
250 |
numFrames:= 0; |
7369
46921fbe76d3
Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents:
7363
diff
changeset
|
251 |
thumbnailSaved:= false; |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
252 |
RecPrefix:= FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
253 |
|
7180 | 254 |
Mix_QuerySpec(@frequency, @format, @channels); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
255 |
AddFileLog('sound: frequency = ' + IntToStr(frequency) + ', format = ' + IntToStr(format) + ', channels = ' + IntToStr(channels)); |
7180 | 256 |
if format <> $8010 then |
257 |
begin |
|
258 |
// TODO: support any audio format |
|
259 |
AddFileLog('Error: Unexpected audio format ' + IntToStr(format)); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
260 |
exit; |
7180 | 261 |
end; |
262 |
||
263 |
{$IOCHECKS OFF} |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
264 |
// create sound file |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
265 |
filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw'; |
7180 | 266 |
Assign(audioFile, filename); |
267 |
Rewrite(audioFile, 1); |
|
268 |
if IOResult <> 0 then |
|
269 |
begin |
|
270 |
AddFileLog('Error: Could not write to ' + filename); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
271 |
exit; |
7180 | 272 |
end; |
273 |
||
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
274 |
// create file with camera positions |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
275 |
filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.txtout'; |
7180 | 276 |
Assign(cameraFile, filename); |
277 |
Rewrite(cameraFile); |
|
278 |
if IOResult <> 0 then |
|
279 |
begin |
|
280 |
AddFileLog('Error: Could not write to ' + filename); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
281 |
exit; |
7180 | 282 |
end; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
283 |
|
7369
46921fbe76d3
Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents:
7363
diff
changeset
|
284 |
// save audio parameters in sound file |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
285 |
BlockWrite(audioFile, frequency, 4); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
286 |
BlockWrite(audioFile, channels, 4); |
7180 | 287 |
{$IOCHECKS ON} |
288 |
||
289 |
// register callback for actual audio recording |
|
290 |
Mix_SetPostMix(@RecordPostMix, nil); |
|
291 |
||
7369
46921fbe76d3
Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents:
7363
diff
changeset
|
292 |
startTime:= SDL_GetTicks(); |
7180 | 293 |
flagPrerecording:= true; |
294 |
end; |
|
295 |
||
296 |
procedure StopPreRecording; |
|
297 |
begin |
|
298 |
AddFileLog('StopPreRecording'); |
|
299 |
flagPrerecording:= false; |
|
300 |
||
301 |
// call SDL_LockAudio because RecordPostMix may be executing right now |
|
302 |
SDL_LockAudio(); |
|
303 |
Close(audioFile); |
|
304 |
Close(cameraFile); |
|
305 |
Mix_SetPostMix(nil, nil); |
|
306 |
SDL_UnlockAudio(); |
|
7369
46921fbe76d3
Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents:
7363
diff
changeset
|
307 |
|
46921fbe76d3
Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents:
7363
diff
changeset
|
308 |
if not thumbnailSaved then |
46921fbe76d3
Move SDL_GetTicks() to another place, maybe this will fix sound desync.
Stepan777 <stepik-777@mail.ru>
parents:
7363
diff
changeset
|
309 |
SaveThumbnail(); |
7180 | 310 |
end; |
311 |
||
312 |
procedure SaveCameraPosition; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
313 |
var curTime: LongInt; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
314 |
frame: TFrame; |
7180 | 315 |
begin |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
316 |
if (not thumbnailSaved) and (ScreenFade = sfNone) then |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
317 |
SaveThumbnail(); |
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7286
diff
changeset
|
318 |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
319 |
curTime:= SDL_GetTicks(); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
320 |
while Int64(curTime - startTime)*cVideoFramerateNum > Int64(numFrames)*cVideoFramerateDen*1000 do |
7180 | 321 |
begin |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
322 |
frame.ticks:= GameTicks; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
323 |
frame.CamX:= WorldDx; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
324 |
frame.CamY:= WorldDy - cScreenHeight div 2; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
325 |
frame.zoom:= zoom/cScreenWidth; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
326 |
BlockWrite(cameraFile, frame, 1); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
327 |
inc(numFrames); |
7180 | 328 |
end; |
329 |
end; |
|
330 |
||
331 |
procedure freeModule; |
|
332 |
begin |
|
333 |
if flagPrerecording then |
|
334 |
StopPreRecording(); |
|
335 |
end; |
|
336 |
||
337 |
end. |
|
7286 | 338 |
|
339 |
{$ENDIF} // USE_VIDEO_RECORDING |