Haikang Network Camera multi-camera data transmission and stream Decoding

Source: Internet
Author: User

Preface:

I don't want to give more comments on haikang's technical support. I don't want to reply to emails when I cannot get through the phone. The inspiration for finding a solution is mostly from haikang's Forum and demo provided by the official website.Program.

However, after the problem is solved, it is important not to give up on your own.

Statement: the solution here is to combine the effect of the demo on the official website with the Haicang ForumCodeIt is also annoying to find what you need in the vast Code. It is good to save only a little time for others ~

Get the camera data stream idea:

Two callback functions (this is not available in the SDK) are used to complete the process in net_dvr_setrealdatacallback (m_lrealhandle,G_realdatacallback_v30, (DWORD) m_camerano) set the callback function to parse data packets. When a frame of image data packets arrive completely, playm4_setdeccallback (lport,DecfunctionHere, decfunction is the decoded callback function. In this function, yv12 data is converted into the format you need and then transmitted in a queue or any other form.

 

PS: 1. The so-called callback function is a function called with a function pointer. In most cases, the callback function is called by the system or other functions.

2. The callback function parameters here are all SDK-defined (in the net_dvr_setrealdatacallback function declaration)

3. Here, the callback function is like an interface left to us when the SDK function is processing the stream, which is passed through parameters, you only need to pass the data through a certain situation to process the data in other parts of the program ~

G_realdatacallback_v30

The function body is as follows. A small loss of modification is made based on the Demo code (the key modification has been bold). This callback function is decoded when data packets arrive, we can see that there are headers and so on. I only added one of them to identify which camera is like when there are multiple cameras:

DWORD dwwinindex = puser ;//Obtain the camera index from the callback function parameter puser.

G_camoperate [dwwinindex]. m_port = lport ;//G_camoperate is a class that encapsulates camera initialization and read functions. The decoded callback function (decfunction) is a global function (is this called ?), All cameras use this function for decoding. Therefore, it is very important to identify different camera data in the decoding callback function, and the port number is transmitted to the decoding function by parameters in each decoding, so here the value is assigned to the class attribute to distinguish the data of different cameras ~

Void callback g_realdatacallback_v30 (long lrealhandle, DWORD dwdatatype, byte * pbuffer, DWORD dwbufsize, DWORD puser) // data stream callback {bool iret = false; DWORD dwwinindex = puser; // get player port to protect the process safelport = g_camoperate [dwwinindex]. m_port; Switch (dwdatatype) {Case net_dvr_syshead: // coming the stream header, open stream // soft decodeif (lport =-1) {If (! Playm4_getport (& lport) {return ;}g_camoperate [dwwinindex]. m_port = lport; If (dwbufsize> 0) {// set as stream mode, real-time stream under previewif (! Playm4_setstreamopenmode (lport, streame_realtime) {trace ("set streammode error! "); Return;} // start playerif (! Playm4_openstream (lport, pbuffer, dwbufsize, 1024*1024) {trace ("playm4_openstream Err"); return;} If (! Playm4_setdeccallback (lport, decfunction) {trace ("playm4_setdeccallback Err"); return;} If (! Playm4_setdisplaybuf (lport, 6) {trace ("playm4_setdisplaybuf Err"); Return ;}// start play, set play too WIF (! Playm4_play (lport, null) {trace ("playm4_play Err"); break;} // set frame buffer number} break; Case net_dvr_streamdata: // start soft decodeif (dwbufsize> 0 & lport! =-1) {If (decsignal) {decsignal = false;} If (! Playm4_inputdata (lport, pbuffer, dwbufsize) {trace ("playm4_inputdata Err") ;}} break; // case net_dvr_realplaynetclose: Case exception_preview: break; default: break;} return ;}

Decfunction:

Here, decfunction completes the function of transferring decoded data. In the parameter, nport identifies the camera port, pbuf indicates the stream data, and the rest is the stream attributes ~
Drawself indicates whether to obtain RGB data or grayscale data. Yv12toyuv completes converting yv12 into yvu data. It's not much to say about coding ~
G_camoperate [pwndindex]. insertframe (pimg); // a method of the class to insert the decoded data into the queue, corresponding to the getframe method, in this way, you can call g_camoperate as needed ~

 void callback decfunction (long nport, char * pbuf, long nsize, frame_info * pframeinfo, long nreserved1, long nreserved2) // decoding callback {// obtain the decoded image data // bool Bret = false; # If drawselfiplimage * pimgycrcb = cvcreateimage (cvsize (pframeinfo-> nwidth, pframeinfo-> nheight), 8, 3); // obtain the Y component yv12toyuv (pimgycrcb-> imagedata, pbuf, pframeinfo-> nwidth, pframeinfo-> nheight, pimgycrcb-> widthstep); // obtain all RGB image iplimage * pimg = cvcreateimage (cvsize (pframeinfo-> nwidth, pframeinfo-> nheight), 8, 3); cvcvtcolor (pimgycrcb, pimg, cv_ycrcb2rgb); # elseiplimage * pimg = cvcreateimage (cvsize (pframeinfo-> nwidth, pframeinfo-> nheight), 8, 1); memcpy (pimg-> imagedata, pbuf, pframeinfo-> nwidth * pframeinfo-> nheight); # endifint pwndindex = 0; // find the corresponding camera and port for (INT I = 0; I 
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.