Skip to content

Commit

Permalink
Добавление временных меток к видео для дебага
Browse files Browse the repository at this point in the history
  • Loading branch information
konvikkor committed Jan 4, 2019
1 parent 06c6bd0 commit 5f95452
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 40 deletions.
2 changes: 2 additions & 0 deletions uMediaConstant.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ interface
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,

OpenGl,

Vcl.ExtCtrls,Math,System.SyncObjs,System.Generics.Collections,

Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FFTypes, FFUtils, System.DateUtils,
Expand Down
153 changes: 118 additions & 35 deletions uMediaDisplay.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ TMediaDisplay = class (TCustomPanel)
CS:TCriticalSection;
FAutoInitSDL: Boolean;
RenderBMP:TBitmap;
FASCIICharList: GLuint;
GlobalTime,PackTime:Cardinal;
protected
procedure Paint; override;
procedure CreateWnd; override;
Expand Down Expand Up @@ -67,7 +69,8 @@ TMediaDisplay = class (TCustomPanel)
function DrawBitmapTex(texId: GLuint; x, y, w, h: Integer): TMediaDisplay; overload;
function DrawBitmapTex(bmp: TBitmap; x, y, w, h: Integer): TMediaDisplay; overload;
Procedure BeginRender;
Procedure SetBitmap(BMP:TBitmap);
Procedure SetBitmap(BMP:TBitmap;GlobalTime,PackTime:Cardinal);
function TextOut(const text: WideString; x, y: Integer; red, green, blue, alpha: Single): TMediaDisplay;
Procedure EndRender;
published
Property AutoInitSDL:Boolean Read FAutoInitSDL Write FAutoInitSDL default true;
Expand Down Expand Up @@ -110,7 +113,6 @@ implementation
procedure TMediaDisplay.BeginRender;
begin
CS.Enter;
glClear (GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT or GL_COLOR_BUFFER_BIT); //Î÷èñòêà áóôåðà öâåòà è ãëóáèíû
end;

function TMediaDisplay.BuildTexture(bmp: TBitmap;
Expand All @@ -123,9 +125,19 @@ function TMediaDisplay.BuildTexture(bmp: TBitmap;
glPixelStorei(GL_PACK_ALIGNMENT, 1);
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texId); // Bind To The Texture ID
(* TEST ADD > *)
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
(* TEST ADD < *)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Min Filter
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Mag Filter
glTexImage2D(GL_TEXTURE_2D, 0, 3, bmpInfo.bmWidth, bmpInfo.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, bmpInfo.bmBits);
if bmpInfo.bmBitsPixel = 32 then
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, bmpInfo.bmWidth, bmpInfo.bmHeight, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, bmpInfo.bmBits)
else
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGR_EXT, bmpInfo.bmWidth, bmpInfo.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, bmpInfo.bmBits);
(* TEST > *)
//glGenerateMipmap(GL_TEXTURE_2D);
(* TEST < *)
Result := Self;
end;

Expand Down Expand Up @@ -244,20 +256,20 @@ function TMediaDisplay.DrawBitmapTex(bmp: TBitmap; x, y, w,
tex: GLuint;
begin
glColor3f(1.0, 1.0, 1.0);
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
//glDisable(GL_BLEND);
//glEnable(GL_TEXTURE_2D);
BuildTexture(bmp, tex);

glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3i(x, y, 0);
glTexCoord2f(1.0, 0.0); glVertex3f(x + w, y, 0);
glTexCoord2f(1.0, 1.0); glVertex3f(x + w, y + h, 0);
glTexCoord2f(0.0, 1.0); glVertex3f(x, y + h, 0);
glTexCoord2f(0.0, 0.0); glVertex3i(x, y, 0);
glTexCoord2f(1.0, 0.0); glVertex3f(x + w, y, 0);
glTexCoord2f(1.0, 1.0); glVertex3f(x + w, y + h, 0);
glTexCoord2f(0.0, 1.0); glVertex3f(x, y + h, 0);
glEnd;

glDeleteTextures(1, @tex);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
//glDisable(GL_TEXTURE_2D);
//glEnable(GL_BLEND);
//SetBlendState(FBlend);
//glColor4fv(@FPenColor); // Restore color
Result := Self;
Expand All @@ -279,14 +291,13 @@ function TMediaDisplay.DrawBitmapTex(texId: GLuint; x, y, w,
glEnd;

glDisable(GL_TEXTURE_2D);
//glEnable(GL_BLEND);
glEnable(GL_BLEND);
//glColor4fv(@FPenColor); // Restore color
Result := Self;
end;

procedure TMediaDisplay.EndRender;
begin
SwapBuffers(wglGetCurrentDC);
CS.Leave;
end;

Expand Down Expand Up @@ -352,41 +363,79 @@ procedure TMediaDisplay.InitSDL;

procedure TMediaDisplay.OnTimer(Sender: TObject);
var x,y:Integer;
begin
//glClear(GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT or GL_COLOR_BUFFER_BIT);
if not Assigned(RenderBMP) then exit;
if RenderBMP.Empty then exit;
BeginRender;
//glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
//glLoadIdentity;
Text:AnsiString;
Texture:Cardinal;
bmpInfo: BITMAP;
begin x:=0; y:=0; Texture:=0;
//glColor3f(1.0,0.0,0.0);
glClear (GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT or GL_COLOR_BUFFER_BIT); //Î÷èñòêà áóôåðà öâåòà è ãëóáèíû

glMatrixMode(GL_MODELVIEW);
x:=-RenderBMP.Width div 2;
y:=-RenderBMP.Height div 2;
DrawBitmap(RenderBMP,x,y);
//SwapBuffers(HDC);
EndRender;
glLoadIdentity;
TextOut('Media Display ['+FormatDateTime('hh.mm.ss.zzz',Time)+']',-ClientWidth div 2 + 5,ClientHeight div 2 - 15,-128,11,0,0);
TextOut('['+FormatDateTime('hh.mm.ss.zzz',IncMilliSecond(MinDateTime,GlobalTime))+'] Global',-ClientWidth div 2 + 5,ClientHeight div 2 - 30,1,0,1,0);
TextOut('['+FormatDateTime('hh.mm.ss.zzz',IncMilliSecond(MinDateTime,PackTime))+'] Packed',-ClientWidth div 2 + 5,ClientHeight div 2 - 45,1,1,0,0);
if Assigned(RenderBMP) then begin
BeginRender;
try
if not RenderBMP.Empty then begin
(* Draw IMG > *)
x:=-RenderBMP.Width div 2;
y:=-RenderBMP.Height div 2;
DrawBitmap(RenderBMP,x,y);
{x:=RenderBMP.Width;
y:=RenderBMP.Height;
glColor3f(0.7,0.7,0.7);
glEnable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_2D);
glGenTextures(1,@Texture);
glBindTexture(GL_TEXTURE_2D,Texture);
GetObject(RenderBMP.Handle, SizeOf(bmpInfo), @bmpInfo);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0,GL_RGBA, GL_UNSIGNED_BYTE, bmpInfo.bmBits);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(-x/2, -y/2, 0);
glTexCoord2f(1, 0);
glVertex3f(x/2, -y/2, 0);
glTexCoord2f(1, 1);
glVertex3f(x/2, y/2, 0);
glTexCoord2f(0, 1);
glVertex3f(-x/2, y/2, 0);
glEnd;}
//DrawBitmapTex(RenderBMP,-x div 2,-y div 2,x,y);
//gluLookAt(0,0,-10,0,0,0,0,0,0);
(* Draw IMG < *)
(*BuildTexture(RenderBMP,Texture);
DrawBitmapTex(Texture,-x div 2,-y div 2,x,y);
DeleteTexture(Texture);*)
end;
finally
EndRender;
end;
end;
//SwapBuffers(wglGetCurrentDC);
//glFlush;
//Application.ProcessMessages;
SwapBuffers(HDC);
end;

procedure TMediaDisplay.Paint;
var Rect: TRect;
Text:string;
begin
glClearColor (0.5, 0.5, 0.75, 1.0); //Öâåò ôîíà
//glClearColor (0.5, 0.5, 0.75, 1.0); //Öâåò ôîíà
glClearColor (0, 0, 0, 1.0); //Öâåò ôîíà
glClear (GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT or GL_COLOR_BUFFER_BIT); //Î÷èñòêà áóôåðà öâåòà è ãëóáèíû
glLoadIdentity;
glViewport(0,0,ClientWidth,ClientHeight); // ðàçìåðû ýêðàíà ÷òî áóäåì ïîêàçûâàòü
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
(*glOrtho(-ClientWidth div 2,
ClientWidth div 2,
-ClientHeight div 2,
ClientHeight div 2,-800,800); //öåíòðîâêà â íîëü ïî öåíòðó ýêðàíà*)
gluOrtho2D(-ClientWidth div 2,
ClientWidth div 2,
-ClientHeight div 2,
ClientHeight div 2); //öåíòðîâêà â íîëü ïî öåíòðó ýêðàíà*)
glOrtho(-ClientWidth div 2,ClientWidth div 2,-ClientHeight div 2,ClientHeight div 2,-800,800); //öåíòðîâêà â íîëü ïî öåíòðó ýêðàíà*)
//gluOrtho2D(-ClientWidth div 2,ClientWidth div 2,-ClientHeight div 2,ClientHeight div 2); //öåíòðîâêà â íîëü ïî öåíòðó ýêðàíà*)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
//glTranslatef(0.0,0.0,-10.0);
Expand Down Expand Up @@ -515,11 +564,13 @@ procedure TMediaDisplay.Render(w, h: SInt32; Data: array of PByte;
end;
end;

procedure TMediaDisplay.SetBitmap(BMP: TBitmap);
procedure TMediaDisplay.SetBitmap(BMP: TBitmap;GlobalTime,PackTime:Cardinal);
var Stream:TMemoryStream;
begin
if not Assigned(RenderBMP) then Exit;
CS.Enter;
Self.GlobalTime:=GlobalTime;
Self.PackTime:=PackTime;
Stream:=TMemoryStream.Create;
try
BMP.SaveToStream(Stream);
Expand Down Expand Up @@ -568,4 +619,36 @@ procedure TMediaDisplay.setupPixelFormat(DC: HDC);
exit;
end;

function TMediaDisplay.TextOut(const text: WideString; x,
y: Integer; red, green, blue, alpha: Single): TMediaDisplay;
var
i: Integer;
GLList: GLuint;
Font:TFont;
begin
Font:=TFont.Create;
try
Font.Style:=[fsBold];
Font.Size:=10;
Font.Color:=clGreen;
SelectObject(HDC, Font.Handle);
GLList := glGenLists(MaxChar);
wglUseFontBitmaps(HDC, 0, MaxChar, GLList);

glPushMatrix;
glLoadIdentity;
glColor4f(red, green, blue, alpha);
glRasterPos2i(x, y);
for i := 1 to Length(text) do
glCallList(GLList + Ord(text[i]));
glPopMatrix;

glDeleteLists(GLList, MaxChar);
//glColor4fv(@FPenColor);
Result := Self;
finally
FreeAndNil(Font);
end;
end;

end.
2 changes: 1 addition & 1 deletion uTestMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ procedure TForm1.EST1Click(Sender: TObject);
BMP:=TBitmap.Create;
try
BMP.LoadFromFile(OpenDialog2.FileName);
MediaDisplay.SetBitmap(BMP);
MediaDisplay.SetBitmap(BMP,0,0);
finally
FreeAndNil(BMP);
end;
Expand Down
12 changes: 8 additions & 4 deletions uVideoThread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ procedure TVideoThread.Execute;
if FAVPacked = nil then exit;
if FAVPacked.pts <> AV_NOPTS_VALUE then
tmp:=Round((FAVPacked.pts * (FVideoStrem.time_base.num / FVideoStrem.time_base.den)) * 1000)
else tmp:=0;
else begin
if FAVPacked.dts <> AV_NOPTS_VALUE then
tmp:=Round((FAVPacked.dts * (FVideoStrem.time_base.num / FVideoStrem.time_base.den)) * 1000)
else tmp:=0;
end;
Result:= GT >= tmp
end;

Expand Down Expand Up @@ -229,8 +233,8 @@ procedure TVideoThread.Execute;
Continue;
end;
//Render := avcodec_decode_video2(FVideoStrem^.codec, FAVFrame, FGotFrame, FAVPacked) > 0;
{if not isTimeFail then Render := FOnDecodeFrame(self,FAVPacked,FAVFrame,FGotFrame) > 0
else Render:=False;}
(*if not isTimeFail then Render := FOnDecodeFrame(self,FAVPacked,FAVFrame,FGotFrame) > 0
else Render:=False;*)
Render := FOnDecodeFrame(self,FAVPacked,FAVFrame,FGotFrame) > 0;
(*IF Assigned(CS) then CS.Enter;
try
Expand Down Expand Up @@ -562,7 +566,7 @@ function TVideoThread.SaveFrameAsJPEG(w,h:SInt32;Data:Array of PByte;linesize: A
//glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
//wglMakeCurrent(FMediaDisplay.HDC, FMediaDisplay.RC);
//glClear(GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT or GL_COLOR_BUFFER_BIT);//GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
FMediaDisplay.SetBitmap(bmp);
FMediaDisplay.SetBitmap(bmp,GT,Round((FAVPacked.dts * (FVideoStrem.time_base.num / FVideoStrem.time_base.den)) * 1000));
//SwapBuffers(Self.FMediaDisplay.HDC);
(* OpenGL < *)
(*img:=TGPBitmap.Create(TStreamAdapter.Create(BMPFile));
Expand Down

0 comments on commit 5f95452

Please sign in to comment.