C # Video Monitoring series (4): client-audio receiving and screenshots

Source: Internet
Author: User

 

Preface

Since there are not many codes and instructions for Receiving audio, Let's GO! !

 

Note:

This series of articles is limited to learning and communication and focus on the process. Due to the involvement of companies, source code download is not provided. Sorry !! But please rest assured that I will post the core, implementation, and other codes that can be pasted out, and strive to answer every question in the message as much as possible. Thank you for your attention and welcome to the discussion.

 

Series

1. C # Video Monitoring series (1): Preparation

2. C # Video Monitoring series (2): client-encapsulation API

3. C # Video Monitoring series (3): client-connection Server

4. C # Video Monitoring series (4): client-audio receiving and capturing

 

Body

I. I wrote three articles to provide a sketch of the interface, so that everyone has a number in mind.

Ii. Audio reception

The code for Receiving audio is relatively simple, and the server side is enabled by default. You only need to connect the picker to the card with a white line labeled AID 1/2/3/4.

VC ++ Code:

If (nn1> = 0)
{
MP4_ClientAudioStart (nn1 );
MP4_ClientAudioVolume (0xfff0 );
}

C # Code:

If (cs> = 0)
{
PcHikClient. MP4_ClientAudioStart (cs );
PcHikClient. MP4_ClientAudioVolume (0 xffff );
}

Note the volume value range set by MP4_ClientAudioVolume: (0-0xffff ).

3. image capture,

VC ++ Code:

MP4_ClientSetCapPicCallBack (nn1, CapPicFun );

Void CALLBACK CapPicFun (long nPort ,\
Char * pBuf, long nSize ,\
Long nWidth, long nHeight ,\
Long nStamp, long nType, long nReceaved)
{
If (! (G_bCapPic) & (nPort = ipos )))
Return;
CString csFile;
Switch (nType)
{
Case T_UYVY:
CsFile = "c :\\ uyvy.bmp ";
Break;
Case T_YV12:
CsFile = "c :\\ yv12.bmp ";
Break;
Case T_RGB32:
CsFile = "c: \ rgb.bmp ";
Break;
Default:
Return;
}
MP4_ClientSavePicFile (pBuf, nSize, nWidth, nHeight, nType, csFile. GetBuffer (csFile. GetLength ()));
G_bCapPic = FALSE;

}

We can see that the callback is implemented. Note that when writing the corresponding callback function, we need to convert the callback instance into a member variable.

C # Code:

Private const int T_UYVY = 1;
Private const int T_YV12 = 3;
Private const int T_RGB32 = 7;

Private CapPicFun cpf;

Private void button3_Click (object sender, EventArgs e)
{
PcHikClient. MP4_ClientSetCapPicCallBack (cs, cpf );
}

// Public void CapPicFun1 (int StockHandle, [financialas (UnmanagedType. LPArray, SizeConst = 152064)] byte [] pBuf, int nSize, int nWidth, int nHeight, int nStamp, int nType, int nReceaved)
Public void CapPicFun1 (int StockHandle, IntPtr pBuf, int nSize, int nWidth, int nHeight, int nStamp, int nType, int nReceaved)
{
String csFile = string. Empty;

Switch (nType)
{
Case T_UYVY:
CsFile = @ "c: \ uyvy.bmp ";
Break;
Case T_YV12:
CsFile = @ "c: \ yv12.bmp ";
Break;
Case T_RGB32:
CsFile = @ "c: \ rgb32.bmp ";
Break;
}

PcHikClient. MP4_ClientSavePicFile (pBuf, nSize, nWidth, nHeight, nType, csFile );
// Stop execution callback
PcHikClient. MP4_ClientSetCapPicCallBack (cs, null );
}

Code Description:

1. The button3 clicking event corresponds to the clicking event on the interface.

2. From the API documentation, we can see the description of MP4_ClientSetCapPicCallBack:"Be sure to return the result as soon as possible. If you want to stop the callback, you can set the callback function pointer CapPicFun to NULL. Once the callback function is setValid until the program exits .".

3. Run the client to connect to the server and display the video screen on the basis of the above before calling this function. Otherwise, the function will neither report errors nor take pictures.

4. Delegate private CapPicFun cpf; instantiation I performed in formateload: cpf = new CapPicFun (CapPicFun1 );

5. In other words, configure your C-root directory according to your photo. yv12.bmp :)

 

End

The function was also implemented when I wrote this article. I used the original API to discover and save the function, but the image was black and then modified the parameter type. Of course, I have also updated the API of the previous article. I hope that this series of articles will be completed smoothly and I have to boast that hikcom's card is indeed doing well !!

 

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.