Jump to content

IP Camera stream + record


FireFox
 Share

Recommended Posts

  • 2 months later...
  • 4 months later...

Thanks for the awesome script! I have modified it to give the option to toggle between multiple cameras and also display 2 at once! works great - except the second camera has approximately 7 second delay. Any ideas how I can fix that?

Thanks again for the great script!

 

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1 + 2)
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

TraySetToolTip(StringReplace(@ScriptName, ".exe", ""))

TraySetState(1)

Global $script_name = "Camera"
Global $script_version = $script_name & " v" & FileGetVersion(@ScriptName, "FileVersion")
Global $msg_normal = 262144, $msg_prompt = 262148, $msg_retry = 262150, $msg_error = 262160

Global $x_position, $y_position
Global $toggle_button, $always_on_top

Global Const $STM_SETIMAGE = 0x0172

Global $blGUIMinimized = False

Global $title_A, $camera_selection_A, $default_camera_A
Global $bRecvtmp_A = Binary(""), $bStream_A = $bRecvtmp_A
Global $iImgLen_A = 0, $iStreamLen_A = 0, $iWritten_A = 0, $iEOH_A = 0, $iContLenPos_A = 0, $pBuffer_A = 0
Global Const $iContLengthLen_A = StringLen("Content-Length: ")
Global $sStream_A = "", $sTrim2ContLen_A = ""
Global $hBMP_A = 0, $hHBITMAP2_A = 0, $GUI = 0, $pPic_A = 0, $hPic_A = 0
Global $iSocket_A, $iIPAddress_A, $iPort = 80

Global $title_B, $camera_combo_B, $set_default_button_B, $camera_selection_B, $default_camera_B
Global $bRecvtmp_B = Binary(""), $bStream_B = $bRecvtmp_B
Global $iImgLen_B = 0, $iStreamLen_B = 0, $iWritten_B = 0, $iEOH_B = 0, $iContLenPos_B = 0, $pBuffer_B = 0
Global Const $iContLengthLen_B = StringLen("Content-Length: ")
Global $sStream_B = "", $sTrim2ContLen_B = ""
Global $hBMP_B = 0, $hHBITMAP2_B = 0, $pPic_B = 0, $hPic_B = 0
Global $iSocket_B, $iIPAddress_B

$default_cameras = ReadSettings()

$array = StringSplit($default_cameras, "|")

$default_camera_A = $array[1]
$default_camera_B = $array[2]

If $always_on_top = "True" Then
$GUI = GUICreate($script_version, 320, 310, $x_position, $y_position, $GUI_SS_DEFAULT_GUI, $WS_EX_TOPMOST)
Else
$GUI = GUICreate($script_version, 320, 310, $x_position, $y_position, $GUI_SS_DEFAULT_GUI)
EndIf

$combo_selections = "Room 1|Room 2|Room 3|Room 4"

$camera_combo_A = GUICtrlCreateCombo("", 3, 3, 95, 15, $CBS_DROPDOWNLIST)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))
GUICtrlSetData(-1, $combo_selections, $default_camera_A)
GUICtrlSetOnEvent(-1, "SetCamera_A")

$set_default_button_A = GUICtrlCreateButton("Set As Default", 3, 25, 95, 15)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))
GUICtrlSetOnEvent(-1, "SetDefault_A")
GUICtrlSetFont(-1, 7)
GUICtrlSetTip(-1, "Set current camera as default")

$always_on_top_checkbox = GUICtrlCreateCheckbox("Always on Top", 242, 5, 77, 12)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKRIGHT, $GUI_DOCKTOP, $GUI_DOCKSIZE))
GUICtrlSetOnEvent(-1, "SetTopMost")
GUICtrlSetFont(-1, 7)
GUICtrlSetTip(-1, "Set this window to be on top of all other windows")

If $always_on_top = "True" Then
GUICtrlSetState(-1, $GUI_CHECKED)
EndIf

$title_A = GUICtrlCreateLabel("", 0, 50, 320, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))
GUICtrlSetBkColor(-1, 0x004E98)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 9, 600)

TCPStartup()

SetCamera_A()

$toggle_button = GUICtrlCreateButton(">>", 297, 30, 20, 15)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKRIGHT, $GUI_DOCKTOP, $GUI_DOCKSIZE))
GUICtrlSetOnEvent(-1, "Toggle_GUI")
GUICtrlSetTip(-1, "Add an additional camera")

$pPic_A = GUICtrlCreatePic("", 0, 70, 320, 240, $SS_BITMAP)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))
GUICtrlSetState($pPic_A, $GUI_DISABLE)
$hPic_A = GUICtrlGetHandle($pPic_A)

If $default_camera_B <> "NONE" Then
Toggle_GUI()
EndIf

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUISetState()

_GDIPlus_Startup()

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch

;1st camera
$bRecvtmp_A = TCPRecv($iSocket_A, 4096, 1) ;4kb
If @error Then ContinueLoop

If Not BinaryLen($bRecvtmp_A) Then ContinueLoop
$bStream_A &= $bRecvtmp_A

If $iImgLen_A = 0 Then
$sStream_A = BinaryToString($bStream_A)

$iContLenPos_A = StringInStr($sStream_A, "Content-Length: ", 2)
$iEOH_A = StringInStr($sStream_A, @CRLF & @CRLF, 2, 1, $iContLenPos_A)

If $iEOH_A = 0 Or $iContLenPos_A = 0 Then ContinueLoop

$sTrim2ContLen_A = StringTrimLeft($sStream_A, $iContLenPos_A + $iContLengthLen_A - 1)

$iImgLen_A = Number(StringLeft($sTrim2ContLen_A, StringInStr($sTrim2ContLen_A, @CR, 2) - 1))

$bStream_A = BinaryMid($bStream_A, $iEOH_A + 4)
EndIf

If $iImgLen_A = 0 Then ContinueLoop

$iStreamLen_A = BinaryLen($bStream_A)
If $iStreamLen_A < $iImgLen_A Then ContinueLoop

If Not $blGUIMinimized Then
$hBMP_A = Load_BMP_From_Mem($bStream_A)

$hHBITMAP2_A = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP_A)

_WinAPI_DeleteObject(_SendMessage($hPic_A, $STM_SETIMAGE, 0, $hHBITMAP2_A))

_GDIPlus_ImageDispose($hBMP_A)
_WinAPI_DeleteObject($hHBITMAP2_A)
EndIf

$iImgLen_A = 0

;2nd camera
$bRecvtmp_B = TCPRecv($iSocket_B, 4096, 1) ;4kb
If @error Then ContinueLoop

If Not BinaryLen($bRecvtmp_ B) Then ContinueLoop
$bStream_B &= $bRecvtmp_B

If $iImgLen_B = 0 Then
$sStream_B = BinaryToString($bStream_ B)

$iContLenPos_B = StringInStr($sStream_B, "Content-Length: ", 2)
$iEOH_B = StringInStr($sStream_B, @CRLF & @CRLF, 2, 1, $iContLenPos_ B)

If $iEOH_B = 0 Or $iContLenPos_B = 0 Then ContinueLoop

$sTrim2ContLen_B = StringTrimLeft($sStream_B, $iContLenPos_B + $iContLengthLen_B - 1)

$iImgLen_B = Number(StringLeft($sTrim2ContLen_B, StringInStr($sTrim2ContLen_B, @CR, 2) - 1))

$bStream_B = BinaryMid($bStream_B, $iEOH_B + 4)
EndIf

If $iImgLen_B = 0 Then ContinueLoop

$iStreamLen_B = BinaryLen($bStream_ B)
If $iStreamLen_B < $iImgLen_B Then ContinueLoop

If Not $blGUIMinimized Then
$hBMP_B = Load_BMP_From_Mem($bStream_ B)

$hHBITMAP2_B = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP_ B)

_WinAPI_DeleteObject(_SendMessage($hPic_B, $STM_SETIMAGE, 0, $hHBITMAP2_ B))

_GDIPlus_ImageDispose($hBMP_ B)
_WinAPI_DeleteObject($hHBITMAP2_ B)
EndIf

$iImgLen_B = 0
WEnd

Func Toggle_GUI()

$window_position = WinGetPos($GUI)

$window_x_position = $window_position[0]
$window_y_position = $window_position[1]
$window_width = $window_position[2]
$window_height = $window_position[3]

If $window_width = 326 Then
$camera_selection_A = GUICtrlRead($camera_combo_A)

If $camera_selection_A = "" Then
MsgBox($msg_error, $script_name, "Please select a primary view camera first.")
Return
EndIf

GUICtrlSetData($toggle_button, "<<")

WinMove($GUI, "", $window_x_position, $window_y_position, 646, $window_height)

$camera_combo_B = GUICtrlCreateCombo("", 320, 3, 95, 15, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, $combo_selections, $default_camera_ B)
GUICtrlSetOnEvent(-1, "SetCamera_B")

$set_default_button_B = GUICtrlCreateButton("Set As Default", 320, 25, 95, 15)
GUICtrlSetOnEvent(-1, "SetDefault_B")
GUICtrlSetFont(-1, 7)
GUICtrlSetTip(-1, "Set current camera as default")

$title_B = GUICtrlCreateLabel("", 320, 50, 320, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0x004E98)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 9, 600)

$pPic_B = GUICtrlCreatePic("", 320, 70, 320, 240, $SS_BITMAP)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))
GUICtrlSetState($pPic_B, $GUI_DISABLE)
$hPic_B = GUICtrlGetHandle($pPic_ B)

SetCamera_B()
EndIf

If $window_width = 646 Then
GUICtrlSetData($toggle_button, ">>")

WinMove($GUI, "", $window_x_position, $window_y_position, 326, $window_height)

GUICtrlDelete($camera_combo_ B)
GUICtrlDelete($set_default_button_ B)
GUICtrlDelete($title_ B)
GUICtrlDelete($pPic_ B)

RegRead("HKLM\Software\Camera", "Default_B")

If Not @error Then
$prompt = MsgBox($msg_prompt, $script_name, "Remove 2nd camera default?")

If $prompt = 6 Then
RegDelete("HKLM\Software\Camera", "Default_B")

$default_camera_B = ""
EndIf
EndIf
EndIf

EndFunc ;==>Toggle_GUI

Func ReadSettings()

$ExtendedWidth = _WinAPI_GetSystemMetrics(78)
$ExtendedHeight = _WinAPI_GetSystemMetrics(79)

$always_on_top = RegRead("HKLM\Software\Camera", "TopMost")
$default_camera_A = RegRead("HKLM\Software\Camera", "Default_A")

If @error Then
$default_camera_A = RegRead("HKLM\Software\Camera", "Default")
If @error Then
$default_camera_A = "NONE"
Else
RegDelete("HKLM\Software\Camera", "Default")
RegWrite("HKLM\Software\Camera", "Default_A", "REG_SZ", $default_camera_A)
EndIf
EndIf

$default_camera_B = RegRead("HKLM\Software\Camera", "Default_B")

If @error Then
$default_camera_B = "NONE"
EndIf

$x_position = RegRead("HKLM\Software\Camera", "X_Position")

If $x_position = "" Then
$x_position = "0"
EndIf

If $x_position < 0 Then
$x_position = "0"
EndIf

If $x_position > $ExtendedWidth - 150 Then
$x_position = "0"
EndIf

$y_position = RegRead("HKLM\Software\Camera", "Y_Position")

If $y_position = "" Then
$y_position = "0"
EndIf

If $y_position > 800 Then
$y_position = "0"
EndIf

If @DesktopHeight = $ExtendedHeight Then
If $y_position < 0 Then
$y_position = "0"
EndIf
EndIf

If @DesktopHeight <> $ExtendedHeight Then
$y_topmost_coordinate = @DesktopHeight - $ExtendedHeight
If $y_position < $y_topmost_coordinate Then
$y_position = $y_topmost_coordinate
EndIf
EndIf

Return $default_camera_A & "|" & $default_camera_B

EndFunc ;==>ReadSettings

Func SetTopMost()

If BitAND(GUICtrlRead($always_on_top_checkbox), $GUI_CHECKED) Then
$topmost = True
WinSetOnTop($script_version, "", 1)
EndIf

If BitAND(GUICtrlRead($always_on_top_checkbox), $GUI_UNCHECKED) Then
$topmost = False
WinSetOnTop($script_version, "", 0)
EndIf

RegWrite("HKLM\Software\Camera", "TopMost", "REG_SZ", $topmost)

EndFunc ;==>SetTopMost

Func SetDefault_A()

$default_camera_A = GUICtrlRead($camera_combo_A)

If $default_camera_A = "" Then
MsgBox($msg_error, $script_name, "Please make a selection first.")
Return
EndIf

RegWrite("HKLM\Software\Camera", "Default_A", "REG_SZ", $default_camera_A)

MsgBox(262144, $script_version, $default_camera_A & " has been set as default.")

EndFunc ;==>SetDefault_A

Func SetDefault_B()

$default_camera_B = GUICtrlRead($camera_combo_ B)

If $default_camera_B = "" Then
MsgBox($msg_error, $script_name, "Please make a selection first.")
Return
EndIf

RegWrite("HKLM\Software\Camera", "Default_B", "REG_SZ", $default_camera_ B)

MsgBox(262144, $script_version, $default_camera_B & " has been set as default.")

EndFunc ;==>SetDefault_B

Func SetPosition()

$position_array = WinGetPos($script_version, "")

$x_position = $position_array[0]
$y_position = $position_array[1]

RegWrite("HKLM\Software\Camera", "X_Position", "REG_SZ", $x_position)
RegWrite("HKLM\Software\Camera", "Y_Position", "REG_SZ", $y_position)

EndFunc ;==>SetPosition

Func SetCamera_A()

$camera_selection_A = GUICtrlRead($camera_combo_A)

If $camera_selection_A = "" Then
MsgBox($msg_normal, $script_name, "Please select a camera from the dropdown and Set As Default.")
Return
EndIf

Select
Case $camera_selection_A = "Room 1"
$iIPAddress_A = "192.168.1.20"
Case $camera_selection_A = "Room 2"
$iIPAddress_A = "192.168.1.30"
Case $camera_selection_A = "Room 3"
$iIPAddress_A = "192.168.1.40"
Case $camera_selection_A = "Room 4"
$iIPAddress_A = "192.168.1.50"
EndSelect

$iSocket_A = TCPConnect($iIPAddress_A, $iPort)
If @error Then
MsgBox($msg_error, $script_name, "Could not connect to " & $camera_selection_A)
Return
EndIf

$shtauth = "cm9vdDpjYXBpdGFs" ;base64 - root:capital

TCPSend($iSocket_A, _
"GET /-wvhttp-01-/GetOneShot?image_size=320x240&frame_count=0 HTTP/1.1" & @CRLF & _
"Host: " & $iIPAddress_A & ":" & $iPort & @CRLF & _
"Connection: keep-alive" & @CRLF & _
"Authorization: Basic " & $shtauth & @CRLF & @CRLF)

GUICtrlSetData($title_A, $camera_selection_A)

EndFunc ;==>SetCamera_A

Func SetCamera_B()

$camera_selection_B = GUICtrlRead($camera_combo_ B)

If $camera_selection_B = "" Then
Return
EndIf

Select
Case $camera_selection_B = "Room 1"
$iIPAddress_B = "192.168.1.20"
Case $camera_selection_B = "Room 2"
$iIPAddress_B = "192.168.1.30"
Case $camera_selection_B = "Room 3"
$iIPAddress_B = "192.168.1.40"
Case $camera_selection_B = "Room 4"
$iIPAddress_B = "192.168.1.50"
EndSelect

$iSocket_B = TCPConnect($iIPAddress_B, $iPort)
If @error Then
MsgBox($msg_error, $script_name, "Could not connect to " & $camera_selection_ B)
Return
EndIf

$shtauth = "cm9vdDpjYXBpdGFs" ;base64 - root:capital

TCPSend($iSocket_B, _
"GET /-wvhttp-01-/GetOneShot?image_size=320x240&frame_count=0 HTTP/1.1" & @CRLF & _
"Host: " & $iIPAddress_B & ":" & $iPort & @CRLF & _
"Connection: keep-alive" & @CRLF & _
"Authorization: Basic " & $shtauth & @CRLF & @CRLF)

GUICtrlSetData($title_B, $camera_selection_ B)

EndFunc ;==>SetCamera_B

Func Debug($variable1 = "", $variable2 = "", $variable3 = "")

If IsArray($variable1) Then
_ArrayDisplay($variable1)
Else
If $variable2 <> "" Then
$variable1 &= @CRLF & $variable2
EndIf

If $variable3 <> "" Then
$variable1 &= @CRLF & $variable3
EndIf

ClipPut($variable1)
MsgBox($msg_normal, "Debug", $variable1)
EndIf

EndFunc ;==>Debug

Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam)
Local Const $SC_MINIMIZE = 0xF020, $SC_RESTORE = 0xF120

Switch BitAND($wParam, 0xFFF0)
Case $SC_MINIMIZE, $SC_RESTORE
$blGUIMinimized = Not $blGUIMinimized
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc ;==>WM_SYSCOMMAND

Func Load_BMP_From_Mem($mem_image)
;author: UEZ
;Additional Code: thanks to progandy for the MemGlobalAlloc and tVARIANT lines
If Not IsBinary($mem_image) Then Return SetError(1, 0, 0)

Local Const $memBitmap = Binary($mem_image)
Local Const $len = BinaryLen($memBitmap)
Local Const $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE)
Local Const $pData = _MemGlobalLock($hData)
Local $tMem = DllStructCreate("byte[" & $len & "]", $pData)

DllStructSetData($tMem, 1, $memBitmap)
_MemGlobalUnlock($hData)

Local $hStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0)
$hStream = $hStream[3]

Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0)
$hBitmap = $hBitmap[2]
Local Const $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _
"dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT))
$tMem = 0
Return $hBitmap
EndFunc ;==>Load_BMP_From_Mem

Func _Exit()
TCPCloseSocket($iSocket_A)
TCPCloseSocket($iSocket_ B)
TCPShutdown()
SetPosition()
Exit
EndFunc ;==>_Exit
Edited by gcue
Link to comment
Share on other sites

I will take a look at it when I will have the time to test it in real conditions.

I might have told you (this means maybe nothing in english...) I created a script to display up to 4 cameras, however I was too lazy to finish it BUT I have to, so someday I will post it.

Edited by FireFox
Link to comment
Share on other sites

i think it might have to do with these lines in the while loop....

$bRecvtmp_A = TCPRecv($iSocket_A, 4096, 1) ;4kb
If @error Then ContinueLoop

$bRecvtmp_B = TCPRecv($iSocket_B, 4096, 1) ;4kb
If @error Then ContinueLoop

The original code does an exitloop instead of continueloop but exitloop exits the script gracefully. continueloop crashes it.

This seems to be the issue not sure yet tho

Link to comment
Share on other sites

It's wrong indeed.

 

If nothing is received on the socket A, all the script of for the camera B will be paused.

;Instead of
...
If Not BinaryLen($bRecvtmp_A) Then ContinueLoop
$bStream_A &= $bRecvtmp_A
...
 
;do
...
If BinaryLen($bRecvtmp_A) > 0 Then
    $bStream_A &= $bRecvtmp_A
    ;process camera A
    ...
EndIf
 
;socket B + process camera B
Br, FireFox. Edited by FireFox
Link to comment
Share on other sites

cool - i wrapped the IF statement around the entire processing of camera_A (in the while loop)

does this look like it will fix the crashes?

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch

;1st camera
$bRecvtmp_A = TCPRecv($iSocket_A, 4096, 1) ;4kb
If @error Then ContinueLoop

If BinaryLen($bRecvtmp_A) > 0 Then
$bStream_A &= $bRecvtmp_A

If $iImgLen_A = 0 Then
$sStream_A = BinaryToString($bStream_A)

$iContLenPos_A = StringInStr($sStream_A, "Content-Length: ", 2)
$iEOH_A = StringInStr($sStream_A, @CRLF & @CRLF, 2, 1, $iContLenPos_A)

If $iEOH_A = 0 Or $iContLenPos_A = 0 Then ContinueLoop

$sTrim2ContLen_A = StringTrimLeft($sStream_A, $iContLenPos_A + $iContLengthLen_A - 1)

$iImgLen_A = Number(StringLeft($sTrim2ContLen_A, StringInStr($sTrim2ContLen_A, @CR, 2) - 1))

$bStream_A = BinaryMid($bStream_A, $iEOH_A + 4)
EndIf

If $iImgLen_A = 0 Then ContinueLoop

$iStreamLen_A = BinaryLen($bStream_A)
If $iStreamLen_A < $iImgLen_A Then ContinueLoop

If Not $blGUIMinimized Then
$hBMP_A = Load_BMP_From_Mem($bStream_A)

$hHBITMAP2_A = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP_A)

_WinAPI_DeleteObject(_SendMessage($hPic_A, $STM_SETIMAGE, 0, $hHBITMAP2_A))

_GDIPlus_ImageDispose($hBMP_A)
_WinAPI_DeleteObject($hHBITMAP2_A)
EndIf

$iImgLen_A = 0
EndIf

;2nd camera
$bRecvtmp_B = TCPRecv($iSocket_B, 4096, 1) ;4kb
If @error Then ContinueLoop

If Not BinaryLen($bRecvtmp_ B) Then ContinueLoop
$bStream_B &= $bRecvtmp_B

If $iImgLen_B = 0 Then
$sStream_B = BinaryToString($bStream_ B)

$iContLenPos_B = StringInStr($sStream_B, "Content-Length: ", 2)
$iEOH_B = StringInStr($sStream_B, @CRLF & @CRLF, 2, 1, $iContLenPos_ B)

If $iEOH_B = 0 Or $iContLenPos_B = 0 Then ContinueLoop

$sTrim2ContLen_B = StringTrimLeft($sStream_B, $iContLenPos_B + $iContLengthLen_B - 1)

$iImgLen_B = Number(StringLeft($sTrim2ContLen_B, StringInStr($sTrim2ContLen_B, @CR, 2) - 1))

$bStream_B = BinaryMid($bStream_B, $iEOH_B + 4)
EndIf

If $iImgLen_B = 0 Then ContinueLoop

$iStreamLen_B = BinaryLen($bStream_ B)
If $iStreamLen_B < $iImgLen_B Then ContinueLoop

If Not $blGUIMinimized Then
$hBMP_B = Load_BMP_From_Mem($bStream_ B)

$hHBITMAP2_B = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP_ B)

_WinAPI_DeleteObject(_SendMessage($hPic_B, $STM_SETIMAGE, 0, $hHBITMAP2_ B))

_GDIPlus_ImageDispose($hBMP_ B)
_WinAPI_DeleteObject($hHBITMAP2_ B)
EndIf

$iImgLen_B = 0
WEnd
Link to comment
Share on other sites

wasnt sure if you meant i should also make the same change to camera_B

testing it now to see if it crashes...

sorry to be a bother with this - i have a bunch of users using this and its crashing for all of them - *sigh*

thanks soooo much for your help!!!

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch

;1st camera
$bRecvtmp_A = TCPRecv($iSocket_A, 4096, 1) ;4kb
If @error Then ContinueLoop

If BinaryLen($bRecvtmp_A) > 0 Then
$bStream_A &= $bRecvtmp_A

If $iImgLen_A = 0 Then
$sStream_A = BinaryToString($bStream_A)

$iContLenPos_A = StringInStr($sStream_A, "Content-Length: ", 2)
$iEOH_A = StringInStr($sStream_A, @CRLF & @CRLF, 2, 1, $iContLenPos_A)

If $iEOH_A = 0 Or $iContLenPos_A = 0 Then ContinueLoop

$sTrim2ContLen_A = StringTrimLeft($sStream_A, $iContLenPos_A + $iContLengthLen_A - 1)

$iImgLen_A = Number(StringLeft($sTrim2ContLen_A, StringInStr($sTrim2ContLen_A, @CR, 2) - 1))

$bStream_A = BinaryMid($bStream_A, $iEOH_A + 4)
EndIf

If $iImgLen_A = 0 Then ContinueLoop

$iStreamLen_A = BinaryLen($bStream_A)
If $iStreamLen_A < $iImgLen_A Then ContinueLoop

If Not $blGUIMinimized Then
$hBMP_A = Load_BMP_From_Mem($bStream_A)

$hHBITMAP2_A = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP_A)

_WinAPI_DeleteObject(_SendMessage($hPic_A, $STM_SETIMAGE, 0, $hHBITMAP2_A))

_GDIPlus_ImageDispose($hBMP_A)
_WinAPI_DeleteObject($hHBITMAP2_A)
EndIf

$iImgLen_A = 0
EndIf

;2nd camera
$bRecvtmp_B = TCPRecv($iSocket_B, 4096, 1) ;4kb
If @error Then ContinueLoop

If BinaryLen($bRecvtmp_ B) > 0 Then
$bStream_B &= $bRecvtmp_B

If $iImgLen_B = 0 Then
$sStream_B = BinaryToString($bStream_ B)

$iContLenPos_B = StringInStr($sStream_B, "Content-Length: ", 2)
$iEOH_B = StringInStr($sStream_B, @CRLF & @CRLF, 2, 1, $iContLenPos_ B)

If $iEOH_B = 0 Or $iContLenPos_B = 0 Then ContinueLoop

$sTrim2ContLen_B = StringTrimLeft($sStream_B, $iContLenPos_B + $iContLengthLen_B - 1)

$iImgLen_B = Number(StringLeft($sTrim2ContLen_B, StringInStr($sTrim2ContLen_B, @CR, 2) - 1))

$bStream_B = BinaryMid($bStream_B, $iEOH_B + 4)
EndIf

If $iImgLen_B = 0 Then ContinueLoop

$iStreamLen_B = BinaryLen($bStream_ B)
If $iStreamLen_B < $iImgLen_B Then ContinueLoop

If Not $blGUIMinimized Then
$hBMP_B = Load_BMP_From_Mem($bStream_ B)

$hHBITMAP2_B = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP_ B)

_WinAPI_DeleteObject(_SendMessage($hPic_B, $STM_SETIMAGE, 0, $hHBITMAP2_ B))

_GDIPlus_ImageDispose($hBMP_ B)
_WinAPI_DeleteObject($hHBITMAP2_ B)
EndIf

$iImgLen_B = 0
EndIf
WEnd
Link to comment
Share on other sites

I haven't tested it, but try this loop:

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
 
    ;1st camera
    $bRecvtmp_A = TCPRecv($iSocket_A, 4096, 1) ;4kb
 
    If @error = 0 And BinaryLen($bRecvtmp_A) > 0 Then
        $bStream_A &= $bRecvtmp_A
 
        If $iImgLen_A = 0 Then
            $sStream_A = BinaryToString($bStream_A)
 
            $iContLenPos_A = StringInStr($sStream_A, "Content-Length: ", 2)
            $iEOH_A = StringInStr($sStream_A, @CRLF & @CRLF, 2, 1, $iContLenPos_A)
 
            If $iEOH_A > 0 And $iContLenPos_A > 0 Then
                $sTrim2ContLen_A = StringTrimLeft($sStream_A, $iContLenPos_A + $iContLengthLen_A - 1)
 
                $iImgLen_A = Number(StringLeft($sTrim2ContLen_A, StringInStr($sTrim2ContLen_A, @CR, 2) - 1))
 
                $bStream_A = BinaryMid($bStream_A, $iEOH_A + 4)
            EndIf
        EndIf
 
        If $iImgLen_A > 0 Then
            $iStreamLen_A = BinaryLen($bStream_A)
            If $iStreamLen_A >= $iImgLen_A Then
                If Not $blGUIMinimized Then
                    $hBMP_A = Load_BMP_From_Mem($bStream_A)
 
                    $hHBITMAP2_A = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP_A)
 
                    _WinAPI_DeleteObject(_SendMessage($hPic_A, $STM_SETIMAGE, 0, $hHBITMAP2_A))
 
                    _GDIPlus_ImageDispose($hBMP_A)
                    _WinAPI_DeleteObject($hHBITMAP2_A)
                EndIf
 
                $iImgLen_A = 0
            EndIf
        EndIf
    EndIf
 
    ;2nd camera
    $bRecvtmp_B = TCPRecv($iSocket_B, 4096, 1) ;4kb
 
    If @error = 0 And BinaryLen($bRecvtmp_B) > 0 Then
        $bStream_B &= $bRecvtmp_B
 
        If $iImgLen_B = 0 Then
            $sStream_B = BinaryToString($bStream_B)
 
            $iContLenPos_B = StringInStr($sStream_B, "Content-Length: ", 2)
            $iEOH_B = StringInStr($sStream_B, @CRLF & @CRLF, 2, 1, $iContLenPos_B)
 
            If $iEOH_B > 0 And $iContLenPos_B > 0 Then
                $sTrim2ContLen_B = StringTrimLeft($sStream_B, $iContLenPos_B + $iContLengthLen_B - 1)
 
                $iImgLen_B = Number(StringLeft($sTrim2ContLen_B, StringInStr($sTrim2ContLen_B, @CR, 2) - 1))
 
                $bStream_B = BinaryMid($bStream_B, $iEOH_B + 4)
            EndIf
        EndIf
 
        If $iImgLen_B > 0 Then
            $iStreamLen_B = BinaryLen($bStream_B)
            If $iStreamLen_B >= $iImgLen_B Then
                If Not $blGUIMinimized Then
                    $hBMP_B = Load_BMP_From_Mem($bStream_B)
 
                    $hHBITMAP2_B = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP_B)
 
                    _WinAPI_DeleteObject(_SendMessage($hPic_B, $STM_SETIMAGE, 0, $hHBITMAP2_B))
 
                    _GDIPlus_ImageDispose($hBMP_B)
                    _WinAPI_DeleteObject($hHBITMAP2_B)
                EndIf
 
                $iImgLen_B = 0
            EndIf
        EndIf
    EndIf
WEnd
Br, FireFox.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...