From e8c84f9a6d59598b1192c2a8cdf99c75941d03aa Mon Sep 17 00:00:00 2001 From: Laentir Valetov Date: Sun, 3 Mar 2019 17:57:34 +0400 Subject: [PATCH] Fixed - incorrect termination of the streams processing the receipt of the video stream from the cameras. Signed-off-by: Laentir Valetov --- .../cFFmpegIPCamSource.dproj | 57 +++++++++++++++++- .../cFFmpegIPCamSource/cFFmpegIPCamSource.res | Bin 59276 -> 59272 bytes .../LibDemo/cvFloodFill/cv_FloodFill.dproj | 2 +- .../vclCameraCapture/VCLCameraCapture.dproj | 57 +++++++++++++++++- .../vclCameraCapture/VCLCameraCapture.res | Bin 59024 -> 59020 bytes .../VCLIPCameraCapture.dproj | 57 +++++++++++++++++- .../vclIPCameraCapture/VCLIPCameraCapture.res | Bin 59024 -> 59020 bytes .../Delphi 10.3 Rio/dclCommonOpenCV260.dproj | 2 +- .../Delphi 10.3 Rio/dclFFMSource260.dproj | 2 +- .../Delphi 10.3 Rio/dclFMXOpenCV260.dproj | 2 +- .../Delphi 10.3 Rio/dclVCLOpenCV260.dproj | 2 +- source/component/ocv.comp.FFMSource.pas | 9 +-- source/component/ocv.comp.Source.pas | 37 +++++++++--- 13 files changed, 205 insertions(+), 22 deletions(-) diff --git a/samples/Components/cFFmpegIPCamSource/cFFmpegIPCamSource.dproj b/samples/Components/cFFmpegIPCamSource/cFFmpegIPCamSource.dproj index e145e26..acc9f41 100644 --- a/samples/Components/cFFmpegIPCamSource/cFFmpegIPCamSource.dproj +++ b/samples/Components/cFFmpegIPCamSource/cFFmpegIPCamSource.dproj @@ -1,7 +1,7 @@  {08BFF34B-6FF9-468C-9AB2-3F76BBC9E351} - 18.4 + 18.6 VCL cFFmpegIPCamSource.dpr True @@ -156,7 +156,6 @@ 1 - Contents\MacOS 0 @@ -166,6 +165,12 @@ 1 + + + res\xml + 1 + + library\lib\armeabi-v7a @@ -203,6 +208,12 @@ 1 + + + res\values-v21 + 1 + + res\drawable @@ -281,6 +292,11 @@ 1 .framework + + Contents\MacOS + 1 + .framework + 0 @@ -303,6 +319,11 @@ 1 .dylib + + Contents\MacOS + 1 + .dylib + 0 .dll;.bpl @@ -326,6 +347,11 @@ 1 .dylib + + Contents\MacOS + 1 + .dylib + 0 .bpl @@ -348,6 +374,10 @@ Contents\Resources\StartUp\ 0 + + Contents\Resources\StartUp\ + 0 + 0 @@ -484,23 +514,41 @@ 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + ..\ 1 + + ..\ + 1 + Contents 1 + + Contents + 1 + Contents\Resources 1 + + Contents\Resources + 1 + @@ -523,6 +571,10 @@ Contents\MacOS 1 + + Contents\MacOS + 1 + 0 @@ -562,6 +614,7 @@ + diff --git a/samples/Components/cFFmpegIPCamSource/cFFmpegIPCamSource.res b/samples/Components/cFFmpegIPCamSource/cFFmpegIPCamSource.res index 905d47b5398926c0c1d467bbc37d20e3854457fa..a70bfb26419db0a68f8a28a7e605b83ca5392b1b 100644 GIT binary patch delta 25 hcmeA<&)jjIc|*WM#_O8{AD(8~EcZl*d9u%Q2LPe33=RMQ delta 27 jcmeA;&)jpKc|*WM#+#c1AD(8~EcHZ>nUP_#`*TMCwY3Zj diff --git a/samples/LibDemo/cvFloodFill/cv_FloodFill.dproj b/samples/LibDemo/cvFloodFill/cv_FloodFill.dproj index 5088491..1715135 100644 --- a/samples/LibDemo/cvFloodFill/cv_FloodFill.dproj +++ b/samples/LibDemo/cvFloodFill/cv_FloodFill.dproj @@ -7,7 +7,7 @@ 3 Console None - 18.2 + 18.5 Win32 diff --git a/samples/VCLDemo/vclCameraCapture/VCLCameraCapture.dproj b/samples/VCLDemo/vclCameraCapture/VCLCameraCapture.dproj index 368121b..fdcf345 100644 --- a/samples/VCLDemo/vclCameraCapture/VCLCameraCapture.dproj +++ b/samples/VCLDemo/vclCameraCapture/VCLCameraCapture.dproj @@ -1,7 +1,7 @@  {B539F149-8AF0-4A5A-A74F-4A3205ED1D16} - 18.4 + 18.5 VCL VCLCameraCapture.dpr True @@ -215,7 +215,6 @@ 1 - Contents\MacOS 0 @@ -225,6 +224,12 @@ 1 + + + res\xml + 1 + + library\lib\armeabi-v7a @@ -262,6 +267,12 @@ 1 + + + res\values-v21 + 1 + + res\drawable @@ -340,6 +351,11 @@ 1 .framework + + Contents\MacOS + 1 + .framework + 0 @@ -362,6 +378,11 @@ 1 .dylib + + Contents\MacOS + 1 + .dylib + 0 .dll;.bpl @@ -385,6 +406,11 @@ 1 .dylib + + Contents\MacOS + 1 + .dylib + 0 .bpl @@ -407,6 +433,10 @@ Contents\Resources\StartUp\ 0 + + Contents\Resources\StartUp\ + 0 + 0 @@ -543,23 +573,41 @@ 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + ..\ 1 + + ..\ + 1 + Contents 1 + + Contents + 1 + Contents\Resources 1 + + Contents\Resources + 1 + @@ -582,6 +630,10 @@ Contents\MacOS 1 + + Contents\MacOS + 1 + 0 @@ -621,6 +673,7 @@ + diff --git a/samples/VCLDemo/vclCameraCapture/VCLCameraCapture.res b/samples/VCLDemo/vclCameraCapture/VCLCameraCapture.res index fd2aee25b3a117b705dfb96532f1c5a93cd8f1c8..a04757b0aea42bc749f5f8f90968580f9e279181 100644 GIT binary patch delta 25 hcmbPmmbvFF^M;TIjMq1ZJ~+*^S?RG3^W=bM4gjK)3?2Xg delta 27 jcmeA<%RJ#M^M;TIj5jxjJ~+*^S?;kOGb6)f?`MtxwzCWy diff --git a/samples/VCLDemo/vclIPCameraCapture/VCLIPCameraCapture.dproj b/samples/VCLDemo/vclIPCameraCapture/VCLIPCameraCapture.dproj index ab6ede9..23af21c 100644 --- a/samples/VCLDemo/vclIPCameraCapture/VCLIPCameraCapture.dproj +++ b/samples/VCLDemo/vclIPCameraCapture/VCLIPCameraCapture.dproj @@ -1,7 +1,7 @@  {E7756997-05DF-48F3-A962-1BDDF464DDC0} - 18.2 + 18.5 VCL VCLIPCameraCapture.dpr True @@ -215,7 +215,6 @@ 1 - Contents\MacOS 0 @@ -225,6 +224,12 @@ 1 + + + res\xml + 1 + + library\lib\armeabi-v7a @@ -262,6 +267,12 @@ 1 + + + res\values-v21 + 1 + + res\drawable @@ -340,6 +351,11 @@ 1 .framework + + Contents\MacOS + 1 + .framework + 0 @@ -362,6 +378,11 @@ 1 .dylib + + Contents\MacOS + 1 + .dylib + 0 .dll;.bpl @@ -385,6 +406,11 @@ 1 .dylib + + Contents\MacOS + 1 + .dylib + 0 .bpl @@ -407,6 +433,10 @@ Contents\Resources\StartUp\ 0 + + Contents\Resources\StartUp\ + 0 + 0 @@ -543,23 +573,41 @@ 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + ..\ 1 + + ..\ + 1 + Contents 1 + + Contents + 1 + Contents\Resources 1 + + Contents\Resources + 1 + @@ -582,6 +630,10 @@ Contents\MacOS 1 + + Contents\MacOS + 1 + 0 @@ -621,6 +673,7 @@ + diff --git a/samples/VCLDemo/vclIPCameraCapture/VCLIPCameraCapture.res b/samples/VCLDemo/vclIPCameraCapture/VCLIPCameraCapture.res index fd2aee25b3a117b705dfb96532f1c5a93cd8f1c8..a04757b0aea42bc749f5f8f90968580f9e279181 100644 GIT binary patch delta 25 hcmbPmmbvFF^M;TIjMq1ZJ~+*^S?RG3^W=bM4gjK)3?2Xg delta 27 jcmeA<%RJ#M^M;TIj5jxjJ~+*^S?;kOGb6)f?`MtxwzCWy diff --git a/source/component/Delphi 10.3 Rio/dclCommonOpenCV260.dproj b/source/component/Delphi 10.3 Rio/dclCommonOpenCV260.dproj index ae629d0..0c40777 100644 --- a/source/component/Delphi 10.3 Rio/dclCommonOpenCV260.dproj +++ b/source/component/Delphi 10.3 Rio/dclCommonOpenCV260.dproj @@ -7,7 +7,7 @@ 1 Package None - 18.5 + 18.6 Win32 diff --git a/source/component/Delphi 10.3 Rio/dclFFMSource260.dproj b/source/component/Delphi 10.3 Rio/dclFFMSource260.dproj index 3461a4e..3e17c6c 100644 --- a/source/component/Delphi 10.3 Rio/dclFFMSource260.dproj +++ b/source/component/Delphi 10.3 Rio/dclFFMSource260.dproj @@ -2,7 +2,7 @@ {3BC74F10-002A-41D7-B09F-6458FF2CE8F4} dclFFMSource260.dpk - 18.5 + 18.6 None True Debug diff --git a/source/component/Delphi 10.3 Rio/dclFMXOpenCV260.dproj b/source/component/Delphi 10.3 Rio/dclFMXOpenCV260.dproj index c227dbb..f5063f5 100644 --- a/source/component/Delphi 10.3 Rio/dclFMXOpenCV260.dproj +++ b/source/component/Delphi 10.3 Rio/dclFMXOpenCV260.dproj @@ -7,7 +7,7 @@ 1 Package None - 18.5 + 18.6 Win32 diff --git a/source/component/Delphi 10.3 Rio/dclVCLOpenCV260.dproj b/source/component/Delphi 10.3 Rio/dclVCLOpenCV260.dproj index 48a1722..aa2422a 100644 --- a/source/component/Delphi 10.3 Rio/dclVCLOpenCV260.dproj +++ b/source/component/Delphi 10.3 Rio/dclVCLOpenCV260.dproj @@ -7,7 +7,7 @@ 1 Package None - 18.5 + 18.6 Win32 diff --git a/source/component/ocv.comp.FFMSource.pas b/source/component/ocv.comp.FFMSource.pas index 4d2e5e0..76da246 100644 --- a/source/component/ocv.comp.FFMSource.pas +++ b/source/component/ocv.comp.FFMSource.pas @@ -129,7 +129,7 @@ begin FSourceThread := TocvFFMpegIPCamSourceThread.Create(Self); FSourceThread.OnNotifyData := OnNotifyData; FSourceThread.ThreadDelay := FThreadDelay; - FSourceThread.FreeOnTerminate := True; +// FSourceThread.FreeOnTerminate := True; end; end; @@ -368,8 +368,8 @@ begin Continue; end; - img_convert_context := sws_getCachedContext(nil, pCodecCtx^.Width, pCodecCtx^.Height, Integer(pCodecCtx^.pix_fmt), pCodecCtx^.Width, - pCodecCtx^.Height, Integer(AV_PIX_FMT_BGR24), SWS_BILINEAR, nil, nil, nil); + img_convert_context := sws_getCachedContext(nil, pCodecCtx^.Width, pCodecCtx^.Height, Integer(pCodecCtx^.pix_fmt), + pCodecCtx^.Width, pCodecCtx^.Height, Integer(AV_PIX_FMT_BGR24), SWS_BILINEAR, nil, nil, nil); if (img_convert_context = nil) then begin DoNotyfy(ffocvErrorGetStream); @@ -394,7 +394,8 @@ begin avcodec_decode_video2(pCodecCtx, frame, @frame_finished, @packet); if (frame_finished <> 0) then begin - sws_scale(img_convert_context, @frame^.data, @frame^.linesize, 0, pCodecCtx^.Height, @iplframe^.imageData, @linesize); + sws_scale(img_convert_context, @frame^.data, @frame^.linesize, 0, pCodecCtx^.Height, @iplframe^.imageData, + @linesize); if Assigned(OnNotifyData) then begin Image := TocvImage.CreateClone(iplframe); diff --git a/source/component/ocv.comp.Source.pas b/source/component/ocv.comp.Source.pas index 7a4eac8..bafd311 100644 --- a/source/component/ocv.comp.Source.pas +++ b/source/component/ocv.comp.Source.pas @@ -189,7 +189,8 @@ type FURI: string; FProtocol: TocvIPProtocol; protected - function GetIPCamTarget: AnsiString; + function GetIPCamTarget: AnsiString; overload; + function GetIPCamTarget(var URL: AnsiString): Boolean; overload; procedure SetEnabled(Value: Boolean); override; public constructor Create(AOwner: TComponent); override; @@ -268,8 +269,9 @@ Type end; Const - CameraResolution: array [TocvResolution] of TCameraResolution = ((cWidth: 160; cHeight: 120), (cWidth: 320; cHeight: 240), (cWidth: 424; - cHeight: 240), (cWidth: 640; cHeight: 360), (cWidth: 800; cHeight: 448), (cWidth: 960; cHeight: 544), (cWidth: 1280; cHeight: 720)); + CameraResolution: array [TocvResolution] of TCameraResolution = ((cWidth: 160; cHeight: 120), (cWidth: 320; + cHeight: 240), (cWidth: 424; cHeight: 240), (cWidth: 640; cHeight: 360), (cWidth: 800; cHeight: 448), (cWidth: 960; + cHeight: 544), (cWidth: 1280; cHeight: 720)); { TOpenCVCameraThread } @@ -455,7 +457,8 @@ begin FSourceThread.Terminate; if FSourceThread.Suspended then FSourceThread.Resume; - FSourceThread := Nil; + FSourceThread.WaitFor; + FreeAndNil(FSourceThread); end; end; @@ -583,7 +586,24 @@ begin end; end; +function TocvIPCamSource.GetIPCamTarget(var URL: AnsiString): Boolean; +begin + URL := IPProtocolString[FProtocol]; + if Length(Trim(UserName)) <> 0 then + URL := URL + AnsiString(Trim(UserName)) + ':' + AnsiString(Trim(Password)) + '@'; + URL := URL + AnsiString(IP) + ':' + AnsiString(IntToStr(Port)); + if Length(Trim(URI)) > 0 then + begin + if (URL[Length(URL)] <> '/') and (URI[1] <> '/') then + URL := URL + '/'; + URL := URL + AnsiString(URI); + end; + Result := Length(IP) > 0; +end; + procedure TocvIPCamSource.SetEnabled(Value: Boolean); +Var + IPCamURL: AnsiString; begin if FEnabled <> Value then begin @@ -599,11 +619,14 @@ begin end; if Value then begin + if GetIPCamTarget(IPCamURL) and (not(csLoading in ComponentState)) then + begin {$IFDEF DelphiOCVVersion_30} - FCapture := TVideoCapture.Create(GetIPCamTarget); + FCapture := TVideoCapture.Create(IPCamURL); {$ELSE} - FCapture := cvCreateFileCapture(PAnsiChar(GetIPCamTarget)); + FCapture := cvCreateFileCapture(PAnsiChar(IPCamURL)); {$ENDIF} + end; if Assigned(FCapture) then begin (FSourceThread as TocvCaptureThread).Capture := FCapture; @@ -625,7 +648,7 @@ begin FSourceThread := TocvCaptureThread.Create(True); FSourceThread.OnNotifyData := OnNotifyData; FSourceThread.FThreadDelay := FThreadDelay; - FSourceThread.FreeOnTerminate := True; + // FSourceThread.FreeOnTerminate := True; end; end;