hedgewars/uVideoRec.pas
branch0.9.20
changeset 9901 e33178322a8f
parent 9545 f7a55d8e8f4d
child 9998 736015b847e3
equal deleted inserted replaced
9899:5b8bde62a8ef 9901:e33178322a8f
    51 uses uVariables, uUtils, GLunit, SDLh, SysUtils, uIO, uMisc, uTypes;
    51 uses uVariables, uUtils, GLunit, SDLh, SysUtils, uIO, uMisc, uTypes;
    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     if 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 then
       
   120         halt(-1);
   120 
   121 
   121     numPixels:= cScreenWidth*cScreenHeight;
   122     numPixels:= cScreenWidth*cScreenHeight;
   122     YCbCr_Planes[0]:= GetMem(numPixels);
   123     YCbCr_Planes[0]:= GetMem(numPixels);
   123     YCbCr_Planes[1]:= GetMem(numPixels div 4);
   124     YCbCr_Planes[1]:= GetMem(numPixels div 4);
   124     YCbCr_Planes[2]:= GetMem(numPixels div 4);
   125     YCbCr_Planes[2]:= GetMem(numPixels div 4);
   148     FreeMem(YCbCr_Planes[0], numPixels);
   149     FreeMem(YCbCr_Planes[0], numPixels);
   149     FreeMem(YCbCr_Planes[1], numPixels div 4);
   150     FreeMem(YCbCr_Planes[1], numPixels div 4);
   150     FreeMem(YCbCr_Planes[2], numPixels div 4);
   151     FreeMem(YCbCr_Planes[2], numPixels div 4);
   151     FreeMem(RGB_Buffer, 4*numPixels);
   152     FreeMem(RGB_Buffer, 4*numPixels);
   152     Close(cameraFile);
   153     Close(cameraFile);
   153     AVWrapper_Close();
   154     if AVWrapper_Close() < 0 then
       
   155         halt(-1);
   154     Erase(cameraFile);
   156     Erase(cameraFile);
   155     DeleteFile(soundFilePath);
   157     DeleteFile(soundFilePath);
   156     SendIPC(_S'v'); // inform frontend that we finished
   158     SendIPC(_S'v'); // inform frontend that we finished
   157 end;
   159 end;
   158 
   160 
   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);
   185             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));
   186             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));
   187             YCbCr_Planes[2][y*(cScreenWidth div 2) + x]:= Byte(128 + (( 7196*r - 6026*g - 1170*b) shr 16));
   186         end;
   188         end;
   187 
   189 
   188     AVWrapper_WriteFrame(YCbCr_Planes[0], YCbCr_Planes[1], YCbCr_Planes[2]);
   190     if AVWrapper_WriteFrame(YCbCr_Planes[0], YCbCr_Planes[1], YCbCr_Planes[2]) < 0 then
       
   191         halt(-1);
   189 
   192 
   190     // inform frontend that we have encoded new frame
   193     // inform frontend that we have encoded new frame
   191     s[0]:= #3;
   194     s[0]:= #3;
   192     s[1]:= 'p'; // p for progress
   195     s[1]:= 'p'; // p for progress
   193     SDLNet_Write16(progress*10000 div maxProgress, @s[2]);
   196     SDLNet_Write16(progress*10000 div maxProgress, @s[2]);