News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Security cameras and CreateThread API problem

Started by minor28, August 28, 2021, 06:22:52 PM

Previous topic - Next topic

minor28

I have four outdoor security Besder cameras. Three slightly older (1, 2 and 3) and one a little newer. They differ in how to log in. My problem is that when I run only one camera, each camera works as it should. When I run all four at the same time, it seems as if a "queuing system" is formed. Images pauses a while and then at a fast pace showing a couple of images. This despite the fact that I run each camera in four separate threads.

This is how I do it:

To avoid sharing same memory locations.
1. Each camera has been allocated space for storing the required data for managing the data stream (CAMERADATA struct Structures.inc).
2. Each camera has been allocated space for storing info about images (IMGINFO struct Structures.inc).

3. A static window is registred as videoclass and four videoclass windows are created.
3. Each camera is logged in one after the other (LoginProcess.asm) and each thread is created with DataStreamParser as thread processs.

I attach Structures.inc, Source.asm (main file), LoginProcess.asm and DataStreamParser.asm.

I understand that it can be difficult to get to grips with the problem. I myself have struggled with this for a long time. As I see it, it has to do with createthread. If anyone can look at this and possibly suggest how I could avoid the "queuing system" I would be grateful.

LiaoMi

Hi minor28,

which of your open source code is responsible for multi-threading? As far as I can tell, you have attached thread handlers, this is not enough for analyzing the source code of a multithreaded program. Based on your description, the error may be in the program's multithreading manager. In addition, it can be a GUI bug, there are many options here. Try to isolate the problem, for example, use two cameras, compare the results, create debug functions and functions for logging all processing steps with timers. It will be difficult to help here without the complete code.

P.S>You can replace the cameras with your server program, your program will, for example, send 4 different video streams, so you can test any situation.

stevenxie

minor28, very good!  :thumbsup:
In this program code you refer to the vasily.In inc.while,.if,.break and so on advanced simulation syntax macro, really admire you very much.You can provide the Header. in this postinc, WndProc.asm, BesderHash.asm, base64.asm, VideoWndProc.Is it a asm,LoginCamera4.asm,include LoginCamera123.asm?

fearless

Maybe its the receive event, perhaps you have to implement a buffering system to smooth out the processing of frames and add a timer system to fetch the next frame at the correct time to display to prevent the sudden fast display of lots of frames?

minor28

Thank you for your answers,

LiaoMi:
In succession, each camera is connected to the network and after the connection, a thread is created. Se LoginProcess.asm line 84 to 99. Thread process is DataStreamParser.

Not shure I know anything about a program's multithreading manager.

I doubt it's a gui bug.

One camera, two cameras OK. Three cameras problem to a lesser extent. Four cameras problem.

No server is involved.

fearless:
I have tried timers. The data stream is buffered, which means that a pause in the handling means that more frames are displayed in too fast a sequence.

hutch--

It sounds like its either a bandwidth problem or the input method is not fast enough for all of the data in parallel. How are you inputting the 4 channels ? If the four inputs are not conflicting with each other, any recent CPU should be able to handle the load with 4 threads.

LiaoMi

Hi minor28,

QuoteIn succession, each camera is connected to the network and after the connection, a thread is created. Se LoginProcess.asm line 84 to 99. Thread process is DataStreamParser.

Not shure I know anything about a program's multithreading manager.

"program's multithreading manager" - I mean the place where your input is displayed, this data should also be drawn independently of each other.

3. A static window is registred as videoclass and four videoclass windows are created. - where is this code?

Hi Hutch,

I think this is a home network  :azn:

minor28

Hutch--:
Remote: Camera -> WiFi -> Router up 15 Mbit/s -> 4G modem -> Router down 110 Mbit/s -> WiFi -> PC
Local: Camera -> WiFi -> Router -> WiFi -> PC
Separate ip addresses and ports

LiaoMi:
Each data stream package is handled by DataStreamParser process. This process calls Parser process to extract a frame. Remaining data are moved to the beginning of the buffer and next package is added to the buffer and so on. Parser process calls Decode process to decode the extracted frame and create a bitmap (CreateDIBitmap). Bitmap handle is stored in dedicated IMGINFO sturcture. Finally Decode process calls InvalidateRect API for the dedicated video window. All this within the camera thread.

Main window WM_CREATE calls CreateVideoWindows process

CreateVideoWindows proc
    local wc:WNDCLASSEX
    local i:dword

    mov wc.cbSize,sizeof WNDCLASSEX
    lea r8,wc
    lea rdx,szStatic
    mov rcx,0
    call GetClassInfoEx
    mov rax,wc.lpfnWndProc
    mov OldWinProc,rax
    mov rax,VideoWndProc
    mov wc.lpfnWndProc,rax
    mov rax,hInstance
    mov wc.hInstance,rax
    lea rax,szVideoclass
    mov wc.lpszClassName,rax

    lea rcx,wc
    call RegisterClassEx

    mov i,0
    .while i { NUM_CAMERAS
        invoke CreateWindowEx,WS_EX_LEFT,addr szVideoclass,0,WS_CHILD or SS_NOTIFY, \
                    0,0,0,0,hMainWnd,0,hInstance,0
        push rax
        mov ecx,i
        call GetImgInfoPointer
        pop r10
        mov qword ptr [rax].IMGINFO.VidWin,r10
        inc i
    .endw

    ret
CreateVideoWindows endp

LiaoMi

Hi minor28,

sorry, I still do not understand how the information output is processed  :rolleyes:, thanks for the explanations  :thup:, but for completeness it seems to me that something is missing. In any case, in order not to engage in fortune-telling, but to find a problem place, you will have to create a debug logger, and then you need to examine the execution log.

https://docs.microsoft.com/en-us/windows/win32/gdi/wm-paint
The system sends this message when there are no other messages in the application's message queue.

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-invalidaterect
The invalidated areas accumulate in the update region until the region is processed when the next WM_PAINT message occurs or until the region is validated by using the ValidateRect or ValidateRgn function.

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-updatewindow
The UpdateWindow function updates the client area of the specified window by sending a WM_PAINT message to the window if the window's update region is not empty. The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent.

Two examples below, the first with timers, the second using multithreading functions.


minor28

The information output, i.e. each image, is processed in VideWndProc and the image is created in MakeBitmap process and the bitmap is decoded from the data stream. Updatewindow API is not working, must be invalidate. How do I create a debug logger. Ordinary debugging with breakpoints is not possible. I use Visual Studio Community 2019 as ide.

Timer example:
WndProc trigger the timer to send the message in sequence to child windows seperate processes. My data stream is continuous.
Thread example:
Each child window have separat processes and each process start a thread.

These differ from my solution. I supeclassed the static window with a new window process, namely VideoWndProc. The same process for all four cameras. Starting the app shows the four gray windows with white text Camera 1 and so on.

A menu command starts to login to camera 1. When connected first thread is created. Then camera 2, 3 and 4 do the same procedure. All four threads uses the same process, namely DataStreamParser.

I am not sure I understand what you wanted to show with your examples.

six_L

Hi,minor28
QuoteRemote: Camera -> WiFi -> Router up 15 Mbit/s -> 4G modem -> Router down 110 Mbit/s -> WiFi -> PC
Local: Camera -> WiFi -> Router -> WiFi -> PC
Separate ip addresses and ports
the PC shares a wifi bandwidth between four cameras.

try to add a CISCO switch as following the network structure diagram.
Say you, Say me, Say the codes together for ever.

minor28

Hi,
Thanks for your suggestion. I probably do not think I buy a switch and three routers to test the local connection.