Jump to content

Recommended Posts

Posted (edited)

Under Chrome:

-Open a new tab

-Press F12

-Click on the Network tab

-Navigate to your Camera URL stream

-Click on the first result from the network tab

-Click on the Headers sub tab

You will have the header params sent (Request Headers), so you can compare the Authorization param of Chrome and yours.

Br, FireFox.

Edited by FireFox
Posted (edited)

wow didnt know chrome could do that.

neato!

Thanks!!!

 

i am also trying to incorporate a refresh function to your camera example script. but have not yet been successful.  set a hotkey for refresh for now

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <Memory.au3>
 
#region Global Vars
Global Const $sProgramTitle = "IP Camera stream"
 
;HERE YOU GO:
Global Const $iIPAddress = "192.168.0.1", $iPort = 80
 
Global Const $STM_SETIMAGE = 0x0172
 
Global $blGUIMinimized = False
 
Global $bRecvtmp = Binary(""), $bStream = $bRecvtmp
Global $iImgLen = 0, $iStreamLen = 0, $iWritten = 0, $iEOH = 0, $iContLenPos = 0, $pBuffer = 0
Global Const $iContLengthLen = StringLen("Content-Length: ")
Global $sStream = "", $sTrim2ContLen = "", $iSocket = ""
 
Global $hBMP = 0, $hHBITMAP2 = 0
#endregion Global Vars
 
TCPStartup()
 
 
$iSocket = TCPConnect($iIPAddress, $iPort)
If @error Then
MsgBox(16, $sProgramTitle, "Could not connect !")
Exit -1
EndIf
 
TCPSend($iSocket, _
"GET /-wvhttp-01-/video.cgi?v=jpg:320x240::10000 HTTP/1.1" & @CRLF & _
"Host: " & $iIPAddress & ":" & $iPort & @CRLF & _
"Connection: keep-alive" & @CRLF & @CRLF)
 
#region GUI
Global $hGUI = 0, $pPic = 0, $hPic = 0
 
$hGUI = GUICreate($sProgramTitle, 320, 240)
 
$pPic = GUICtrlCreatePic("", 0, 0, 320, 240, $SS_BITMAP)
GUICtrlSetState($pPic, $GUI_DISABLE)
$hPic = GUICtrlGetHandle($pPic)
 
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
 
HotKeySet("{F5}", "Refresh")
 
GUISetState(@SW_SHOW, $hGUI)
#endregion GUI
 
_GDIPlus_Startup()
 
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
 
$bRecvtmp = TCPRecv($iSocket, 4096, 1) ;4kb
If @error Then Wait()
 
If Not BinaryLen($bRecvtmp) Then ContinueLoop
$bStream &= $bRecvtmp
 
If $iImgLen = 0 Then
$sStream = BinaryToString($bStream)
 
$iContLenPos = StringInStr($sStream, "Content-Length: ", 2)
$iEOH = StringInStr($sStream, @CRLF & @CRLF, 2, 1, $iContLenPos)
 
If $iEOH = 0 Or $iContLenPos = 0 Then ContinueLoop
 
$sTrim2ContLen = StringTrimLeft($sStream, $iContLenPos + $iContLengthLen - 1)
 
$iImgLen = Number(StringLeft($sTrim2ContLen, StringInStr($sTrim2ContLen, @CR, 2) - 1))
 
$bStream = BinaryMid($bStream, $iEOH + 4)
EndIf
 
If $iImgLen = 0 Then ContinueLoop
 
$iStreamLen = BinaryLen($bStream)
If $iStreamLen < $iImgLen Then ContinueLoop
 
If Not $blGUIMinimized Then
$hBMP = Load_BMP_From_Mem($bStream)
 
$hHBITMAP2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP)
 
_WinAPI_DeleteObject(_SendMessage($hPic, $STM_SETIMAGE, 0, $hHBITMAP2))
 
_GDIPlus_ImageDispose($hBMP)
_WinAPI_DeleteObject($hHBITMAP2)
EndIf
 
$iImgLen = 0
WEnd
 
_GDIPlus_Shutdown()
 
TCPCloseSocket($iSocket)
TCPShutdown()
 
Func Wait()
while 1
sleep(10)
wend
EndFunc
 
Func Refresh()
 
TCPCloseSocket($iSocket)
TCPShutdown()
 
TCPStartup()
 
$iSocket = TCPConnect($iIPAddress, $iPort)
If @error Then
MsgBox(16, $sProgramTitle, "Could not connect !")
Exit -1
EndIf
 
$shtauth = "cm9vdDpjYXBpdGFs" ;base64 - root:capital
 
;~  "Connection: keep-alive" & @CRLF & @CRLF)
 
TCPSend($iSocket, _
"GET /-wvhttp-01-/video.cgi?v=jpg:320x240::10000 HTTP/1.1" & @CRLF & _
"Host: " & $iIPAddress & ":" & $iPort & @CRLF & _
"Connection: keep-alive" & @CRLF & @CRLF)
;~  "Connection: keep-alive" & @CRLF & _
;~  "Authorization: Basic " & $shtauth & @CRLF & @CRLF)
 
EndFunc
 
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
Edited by gcue
Posted (edited)

plus im going to use the script to toggle the viewing of 6 different cameras - so i figured the way to refresh one would be similar to changing to another camera... 

is there in easy way?

 

=)

Edited by gcue
Posted

Yeah, you will have to code it anyway.

Put the camera links in an array an associate a button to an array index, if you follow me you will know how to do the rest.

Br, FireFox.

Posted (edited)

actually im doing a combobox but maybe its possible with combox as well.

what if i wanted to display 2 cameras at once?

thanks for your help =)

Edited by gcue
Posted (edited)

There's no advice for it. Do it like you think it's the best for you.

To display two cameras at once you will need to duplicate the majority of the code (use two TCP sockets).

My only advice would to use an array, eventually with two dimensions to store all the informations of your two (or more) cameras.

Br, FireFox.

Edited by FireFox

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
×
×
  • Create New...