Home > Software engineering >  MFC high-speed receive a large number of video streaming data network interruption
MFC high-speed receive a large number of video streaming data network interruption

Time:10-12

My project implement the following two main functions:
1. The image data was obtained from the gigabit network camera (800 M/s) speed (camera through the Internet, even the computer directly without a router),
2. Image real-time display (every 50 ms refresh a frame),

I am so:
A thread to obtain images saved to the buffer, use the UDP protocol recvfrom collecting data (if there is a packet loss, ignoring the current frame, continue to accept a frame),
Another thread interval 50 ms take a frame data in the buffer and drawing (drawing tried GDI drawing, OpenGL drawing),

Simple, when you pick up the data and not drawing is normal, can realize the frame data will be collected all save to AVI files, BMP file,
However, drawing again in collecting data at the same time, over a period of time the network connection is disconnected , then the network recovery, but already can't accept figure,

Excuse me, may be where reasons, from what aspects to consider to solve this problem?

CodePudding user response:

The camera on the other side of the OS found a large number of packet loss, and then reset the network card??

CodePudding user response:

reference 1st floor shenyi0106 response:
is the camera on the other side of the OS found a large number of packet loss, and then reset the network card??


Should not this problem, the operation mode of the camera is at present: received contract orders, then contract continuously, until the cessation of received orders, this side of camera does not detect packet loss,

CodePudding user response:

refer to the second floor u011355780 response:
Quote: refer to 1st floor shenyi0106 response:

The camera on the other side of the OS found a large number of packet loss, and then reset the network card??


Should not the problem, the operation mode of the camera is at present: received contract orders, then contract continuously, until the cessation of received orders, camera side does not detect packet loss,

The camera's OS

CodePudding user response:

Will the drawing takes up too much resources, led to the suspension of network communication,

CodePudding user response:

Will not because the receiver is not a contract order, how long does lead to the sender and interrupt? If so, will not because drawing takes up too much resources lead to "no" to send?

CodePudding user response:

Characterized by interrupt, may be the reason is not in the network communication
1. Pay attention to the system resources, see if there is leakage of memory and handle
Data read speed slower than produce speed, buffer has been up?
2. If the number of charge can be complete saved to a file, the display is can use the
Another process to deal with,

CodePudding user response:

One way to check whether resource leaks:
In the process of the task manager to see inside the column selection: memory, virtual memory size, handle number, number of threads, the USER object, GDI objects
Make your program (process) don't quit, cycle through main process many times, the more the better, like 1000000 times or even an infinite loop, record the above numerical, it through at least one hour, as long as possible, such as a month, to record more than the value, if the above two groups of numerical differential is bigger or increasing over time, will certainly have a corresponding resources resource leaks!

Search "GDI leak detection"

CodePudding user response:

Sometimes not to "call a function name + each parameter value, after entering the function of each parameter values, intermediate variable values, exit the function return value of preparation, return to the function to call after the function value of the parameter name + + return value" this information to write logs to a file is where no matter how to also can not find the problem, including capture all kinds of abnormal, writing log to the screen and single step or set a breakpoint or core file is generated,... These methods are not! Write logs to a file reference below:
//loop to a function sends a length of 200 bytes (this is the fixed) buffer, 
//a function need to incoming buffer, the circulation of 240 bytes (fixed) new buffer for processing,
//when dealing with each new printing takes two bytes of the buffer
# ifdef _MSC_VER
# pragma warning (4996) disable:
# endif
# include & lt; stdio.h>
# include & lt; stdlib.h>
# include & lt; string.h>
# ifdef _MSC_VER
# include & lt; Windows. H>
# include & lt; Process. H>
# include & lt; IO. H>
# define MYVOID void
# define vsnprintf _vsnprintf
# the else
# include & lt; unistd.h>
# include & lt; Sys/time. H>
# include & lt; Pthread. H>
# define CRITICAL_SECTION pthread_mutex_t
# define MYVOID void *
# endif
//the Log {
# define MAXLOGSIZE 20000000
# define MAXLINSIZE 16000
# include & lt; Time. H>
# include & lt; Sys/timeb. H>
# include & lt; Stdarg. H>
Char logfilename1 []="MyLog1. Log";
Char logfilename2 []="MyLog2. Log";
The static char logstr [MAXLINSIZE + 1];
Char datestr [16].
Char timestr [16].
Char MSS [4].
CRITICAL_SECTION cs_log;
The FILE * flog;
# ifdef _MSC_VER
The Lock (CRITICAL_SECTION void * l) {
The EnterCriticalSection (l);
}
Void Unlock (CRITICAL_SECTION * l) {
LeaveCriticalSection (l);
}
Void sleep_ms (int) ms {
Sleep (ms).
}
# the else
The Lock (CRITICAL_SECTION void * l) {
Pthread_mutex_lock (l);
}
Void Unlock (CRITICAL_SECTION * l) {
Pthread_mutex_unlock (l);
}
Void sleep_ms (int) ms {
Usleep (ms * 1000);
}
# endif
Void LogV (const char * pszFmt, va_list argp) {
* struct tm now;
Struct timeb TB;

If (NULL==pszFmt | | 0==pszFmt [0]) return;
Vsnprintf (logstr, MAXLINSIZE pszFmt, argp);
Ftime (& amp; TB);
Now=localtime (& amp; TB. Time);
Sprintf (datestr, "% d % % 4 d - 02-02 d", now - & gt; Tm_year + 1900, now - & gt; Tm_mon + 1, now - & gt; Tm_mday);
Sprintf (timestr, "02 02 02 % d: % d: % d", now - & gt; Tm_hour, now - & gt; Tm_min, now - & gt; Tm_sec);
Sprintf (MSS, "% 3 d", TB. Millitm);
Printf (" % s % s. % s % s ", datestr, timestr, MSS, logstr);
Flog=fopen (logfilename1, "a");
If (NULL! Flog)={
Fprintf (flog, "% s % s. % s % s", datestr, timestr, MSS, logstr);
If (ftell (flog) & gt; MAXLOGSIZE) {
The fclose (flog);
If (rename (logfilename1 logfilename2)) {
Remove (logfilename2);
Rename (logfilename1 logfilename2);
}
} else {
The fclose (flog);
}
}
}
Void the Log (const char * pszFmt,... ) {
Va_list argp;

The Lock (& amp; Cs_log);
Va_start (argp, pszFmt);
LogV (pszFmt argp);
Va_end (argp);
Unlock (& amp; Cs_log);
}
//the Log}
# define ASIZE 200
# define BSIZE 240
# define CSIZE 2
Char Abuf [ASIZE];
Char Cbuf [CSIZE];
CRITICAL_SECTION cs_HEX;
CRITICAL_SECTION cs_BBB;
Struct FIFO_BUFFER {
Int the head;
Int tail;
Int size;
Char data [BSIZE];
} BBB;
Int No_Loop=0;
Void HexDump) (int cn, char * buf, int len) {
Int I, j, k; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related