1 (* |
1 (* |
2 * Hedgewars, a free turn based strategy game |
2 * Hedgewars, a free turn based strategy game |
3 * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
3 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4 * |
4 * |
5 * This program is free software; you can redistribute it and/or modify |
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 |
6 * it under the terms of the GNU General Public License as published by |
7 * the Free Software Foundation; version 2 of the License |
7 * the Free Software Foundation; version 2 of the License |
8 * |
8 * |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. |
12 * GNU General Public License for more details. |
13 * |
13 * |
14 * You should have received a copy of the GNU General Public License |
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 |
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 |
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 *) |
17 *) |
18 |
18 |
19 |
19 |
20 {$INCLUDE "options.inc"} |
20 {$INCLUDE "options.inc"} |
21 |
21 |
46 |
46 |
47 procedure initModule; |
47 procedure initModule; |
48 procedure freeModule; |
48 procedure freeModule; |
49 |
49 |
50 implementation |
50 implementation |
51 uses uVariables, uUtils, GLunit, SDLh, SysUtils, uIO, uMisc, uTypes; |
51 uses uVariables, uUtils, GLunit, SDLh, SysUtils, uIO, uMisc, uTypes, uDebug; |
52 |
52 |
53 type TAddFileLogRaw = procedure (s: pchar); cdecl; |
53 type TAddFileLogRaw = procedure (s: pchar); cdecl; |
54 const AvwrapperLibName = 'libavwrapper'; |
54 const AvwrapperLibName = 'libavwrapper'; |
55 |
55 |
56 procedure AVWrapper_Init( |
56 function AVWrapper_Init( |
57 AddLog: TAddFileLogRaw; |
57 AddLog: TAddFileLogRaw; |
58 filename, desc, soundFile, format, vcodec, acodec: PChar; |
58 filename, desc, soundFile, format, vcodec, acodec: PChar; |
59 width, height, framerateNum, framerateDen, vquality: LongInt); cdecl; external AvwrapperLibName; |
59 width, height, framerateNum, framerateDen, vquality: LongInt): LongInt; cdecl; external AvwrapperLibName; |
60 procedure AVWrapper_Close; cdecl; external AvwrapperLibName; |
60 function AVWrapper_Close: LongInt; cdecl; external AvwrapperLibName; |
61 procedure AVWrapper_WriteFrame( pY, pCb, pCr: PByte ); cdecl; external AvwrapperLibName; |
61 function AVWrapper_WriteFrame( pY, pCb, pCr: PByte ): LongInt; cdecl; external AvwrapperLibName; |
62 |
62 |
63 type TFrame = record |
63 type TFrame = record |
64 realTicks: LongWord; |
64 realTicks: LongWord; |
65 gameTicks: LongWord; |
65 gameTicks: LongWord; |
66 CamX, CamY: LongInt; |
66 CamX, CamY: LongInt; |
107 desc:= desc + 'prefix[' + RecPrefix + ']prefix'; |
107 desc:= desc + 'prefix[' + RecPrefix + ']prefix'; |
108 |
108 |
109 filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix; |
109 filename:= UserPathPrefix + '/VideoTemp/' + RecPrefix; |
110 soundFilePath:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw'; |
110 soundFilePath:= UserPathPrefix + '/VideoTemp/' + RecPrefix + '.sw'; |
111 |
111 |
112 AVWrapper_Init(@AddFileLogRaw |
112 TryDo(AVWrapper_Init(@AddFileLogRaw |
113 , PChar(ansistring(filename)) |
113 , PChar(ansistring(filename)) |
114 , PChar(ansistring(desc)) |
114 , PChar(ansistring(desc)) |
115 , PChar(ansistring(soundFilePath)) |
115 , PChar(ansistring(soundFilePath)) |
116 , PChar(ansistring(cAVFormat)) |
116 , PChar(ansistring(cAVFormat)) |
117 , PChar(ansistring(cVideoCodec)) |
117 , PChar(ansistring(cVideoCodec)) |
118 , PChar(ansistring(cAudioCodec)) |
118 , PChar(ansistring(cAudioCodec)) |
119 , cScreenWidth, cScreenHeight, cVideoFramerateNum, cVideoFramerateDen, cVideoQuality); |
119 , cScreenWidth, cScreenHeight, cVideoFramerateNum, cVideoFramerateDen, cVideoQuality) >= 0, |
|
120 'AVWrapper_Init failed', |
|
121 true); |
120 |
122 |
121 numPixels:= cScreenWidth*cScreenHeight; |
123 numPixels:= cScreenWidth*cScreenHeight; |
122 YCbCr_Planes[0]:= GetMem(numPixels); |
124 YCbCr_Planes[0]:= GetMem(numPixels); |
123 YCbCr_Planes[1]:= GetMem(numPixels div 4); |
125 YCbCr_Planes[1]:= GetMem(numPixels div 4); |
124 YCbCr_Planes[2]:= GetMem(numPixels div 4); |
126 YCbCr_Planes[2]:= GetMem(numPixels div 4); |
148 FreeMem(YCbCr_Planes[0], numPixels); |
150 FreeMem(YCbCr_Planes[0], numPixels); |
149 FreeMem(YCbCr_Planes[1], numPixels div 4); |
151 FreeMem(YCbCr_Planes[1], numPixels div 4); |
150 FreeMem(YCbCr_Planes[2], numPixels div 4); |
152 FreeMem(YCbCr_Planes[2], numPixels div 4); |
151 FreeMem(RGB_Buffer, 4*numPixels); |
153 FreeMem(RGB_Buffer, 4*numPixels); |
152 Close(cameraFile); |
154 Close(cameraFile); |
153 AVWrapper_Close(); |
155 if AVWrapper_Close() < 0 then |
|
156 halt(-1); |
154 Erase(cameraFile); |
157 Erase(cameraFile); |
155 DeleteFile(soundFilePath); |
158 DeleteFile(soundFilePath); |
156 SendIPC(_S'v'); // inform frontend that we finished |
159 SendIPC(_S'v'); // inform frontend that we finished |
157 end; |
160 end; |
158 |
161 |
183 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); |
186 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); |
184 YCbCr_Planes[1][y*(cScreenWidth div 2) + x]:= Byte(128 + ((-2428*r - 4768*g + 7196*b) shr 16)); |
187 YCbCr_Planes[1][y*(cScreenWidth div 2) + x]:= Byte(128 + ((-2428*r - 4768*g + 7196*b) shr 16)); |
185 YCbCr_Planes[2][y*(cScreenWidth div 2) + x]:= Byte(128 + (( 7196*r - 6026*g - 1170*b) shr 16)); |
188 YCbCr_Planes[2][y*(cScreenWidth div 2) + x]:= Byte(128 + (( 7196*r - 6026*g - 1170*b) shr 16)); |
186 end; |
189 end; |
187 |
190 |
188 AVWrapper_WriteFrame(YCbCr_Planes[0], YCbCr_Planes[1], YCbCr_Planes[2]); |
191 if AVWrapper_WriteFrame(YCbCr_Planes[0], YCbCr_Planes[1], YCbCr_Planes[2]) < 0 then |
|
192 halt(-1); |
189 |
193 |
190 // inform frontend that we have encoded new frame |
194 // inform frontend that we have encoded new frame |
191 s[0]:= #3; |
195 s[0]:= #3; |
192 s[1]:= 'p'; // p for progress |
196 s[1]:= 'p'; // p for progress |
193 SDLNet_Write16(progress*10000 div maxProgress, @s[2]); |
197 SDLNet_Write16(progress*10000 div maxProgress, @s[2]); |
233 k: LongInt; |
237 k: LongInt; |
234 begin |
238 begin |
235 thumbpath:= '/VideoTemp/' + RecPrefix; |
239 thumbpath:= '/VideoTemp/' + RecPrefix; |
236 AddFileLog('Saving thumbnail ' + thumbpath); |
240 AddFileLog('Saving thumbnail ' + thumbpath); |
237 k:= max(max(cScreenWidth, cScreenHeight) div 400, 1); // here 400 is minimum size of thumbnail |
241 k:= max(max(cScreenWidth, cScreenHeight) div 400, 1); // here 400 is minimum size of thumbnail |
238 MakeScreenshot(thumbpath, k); |
242 MakeScreenshot(thumbpath, k, 0); |
239 thumbnailSaved:= true; |
243 thumbnailSaved:= true; |
240 end; |
244 end; |
241 |
245 |
242 // copy file (free pascal doesn't have copy file function) |
246 // copy file (free pascal doesn't have copy file function) |
243 procedure CopyFile(src, dest: shortstring); |
247 procedure CopyFile(src, dest: shortstring); |