The continuous development of the Internet, the rise of a variety of new technologies, today I first listed the most basic development process, suitable for the development of video conferencing system, voice video chat system, distance education platform and instant communication platform ( IM ) and so on. Hope to be helpful to those who like this. At the same time welcome the major experts to participate in the discussion, mutual exchange, learning.
First of all, let's see how to start working.
Download:http://www.anychat.com.cn/download.html Download the development package for your own platform.
First, initialize
This section is the first to complete, including setting the corresponding callback function, setting the SDK component path, setting whether to produce a log file, and so on, usually initialized with the following code (c + +):
01.// turn on (off) logging feature
02.brac_activecalllog (TRUE);
03.
04.// set the directory where the core components reside
05.CHAR szcoresdkpath[max_path]={0};
06.GetModuleFileName (null,szcoresdkpath,sizeof (Szcoresdkpath));
(STRRCHR (szcoresdkpath, ' \ \ ')) [1]=0;
08.brac_setsdkoption (Brac_so_coresdk_path,szcoresdkpath,strlen (Szcoresdkpath));
09.
10.// according to the second parameter of BRAC_INITSDK: Dwfuncmode, tell how to handle the related task (see Development documentation for details)
11.dworddwfuncmode=brac_func_video_cbdata | Brac_func_audio_autoplay | brac_func_chkdependmodule| Brac_func_audio_volumecalc | Brac_func_net_supportupnp | brac_func_firewall_open|
12.brac_func_audio_autovolume| Brac_func_config_localini;
13.BRAC_INITSDK (This->getsafehwnd ()/*null*/,dwfuncmode);
14.
15.// Set Recording temp file save path
16.CHAR szrecorddirectory[max_path]={0};
17.::getmodulefilename (Null,szrecorddirectory,max_path);
(STRRCHR (szrecorddirectory, ' \ \ ')) [1]=0;
19.strcat (Szrecorddirectory, "Record");
20.brac_setsdkoption (Brac_so_record_tmpdir,szrecorddirectory,strlen (szrecorddirectory));
21st.
22.// set video file quality parameters
23.DWORD dwvideobitrate=200 * 1000; 200kbps
24.brac_setsdkoption (BRAC_SO_RECORD_VIDEOBR, (PCHAR) &dwvideobitrate,sizeof (DWORD));
25.DWORD dwaudiobitrate=96 * 1000; 96kbps
26.brac_setsdkoption (BRAC_SO_RECORD_AUDIOBR, (PCHAR) &dwaudiobitrate,sizeof (DWORD));
27.
28.// set Snapshot Temporary file save path
29.CHAR szsnapshotdirectory[max_path]={0};
30.::getmodulefilename (Null,szsnapshotdirectory,max_path);
(STRRCHR (szsnapshotdirectory, ' \ \ ')) [1]=0;
32.strcat (Szsnapshotdirectory, "SnapShot");
33.brac_setsdkoption (Brac_so_snapshot_tmpdir,szsnapshotdirectory,strlen (szsnapshotdirectory));
34.
35.// set temporary file path
36.CHAR sztemppath[max_path]={0};
37.::getmodulefilename (Null,sztemppath,max_path);
(STRRCHR (sztemppath, ' \ \ ')) [1]=0;
39.strcat (Sztemppath, "Temp");
40.brac_setsdkoption (Brac_so_coresdk_tmpdir,sztemppath,strlen (Sztemppath));
41.
42.// enable the audio auto-parameter feature (default off)
43.DWORD baudioautoparam=true;
44.brac_setsdkoption (Brac_so_audio_autoparam, (PCHAR) &baudioautoparam,sizeof (DWORD));
Second, login system
when the first step is complete, you can connect to the server and authenticate the user. The usual calling code is as follows (C + +):
1.// connecting to a server
2.brac_connect ("211.155.25.90", 8906);
3.// Login System
4.brac_login ("TestUser", "", 0);
Connecting the server to the login system is an asynchronous process that is returned immediately after the call, where:
a , the connection server succeeds, or fails, the asynchronous message will be triggered: network connection message
b , the login system succeeds, or fails, it will trigger an asynchronous message: Log on to the system message
so the application needs to respond to these asynchronous messages (or handle the asynchronous message notification callback function ) to know if the server is connected and the system is logged on successfully.
Once the login system is successful, if you need to implement the Friends list in the IM app (Anychat is not implemented by default), you need to use Anychat's extended API interface with the server SDK to implement, after the login system succeeds, The server returns a 32-bit user ID, and if there is no incoming password parameter at login, the system will consider a visitor login and assign a separate user ID (such as-1,-2, etc.), and if the password parameter is passed in at login, the login request will be given to the SDK Filter Plus interface, or " Server SDK "interface, users can develop their own server plug-in" SDK Filter Plus ", or call the" Server SDK "corresponding to the API to handle user authentication requests, complete the management of the user ID, to achieve interoperability with the third-party system, For more information, refer to the documentation in the SDK package: Doc\server\ directory.
Third, enter the room
after the second step of logging in to the system is successful, you can enter the room, because only in the room, you can complete the voice and video interaction. The usual calling code is as follows (C + +):
1.// Enter the room
2.brac_enterroom (1, "", 0);
The room is dynamically managed by the server and is uniquely marked by the room ID number of the three-bit, and the server will be created automatically when the room ID number specified by the client does not exist. Entering the room is also an asynchronous process, and whether the success will trigger an asynchronous message: You enter the room message , enter the room after the successful, the server will be the current room online user list to the client, after the transfer is complete, will trigger the asynchronous message: Current room online user message (This message is only triggered once), only after receiving the list of online users of the server, the user in the room to perform audio and video related operations.
When you enter the room successfully and receive the server's online user message, a new user enters the room or the old user leaves the room, triggering an asynchronous message: user enters (leaves) room message , so that they know who entered, or left the room.
1 , turn on your own audio and video
after entering the room successfully, you can open your own audio and video device, usually the calling code is as follows (C + +):
1.// turn on your own video device
2.brac_usercameracontrol ( -1,true);
3.// turn on your own audio device
4.brac_userspeakcontrol ( -1,true);
After you open your device, the audio and video stream is not immediately uploaded, only when other users request their own audio and video data (which can be requested separately, or video streaming), to open their own audio and video devices, by default, by the server's configuration information to initialize the device (such as sample resolution, video frame rate, Audio sampling frequency, etc.), such as the need to adjust the sound, video quality in the client program,
2 , requesting audio and video from other users
If you need to display other user's audio and video, you must request the other person's audio and video stream after receiving the room user list message, then the other party will transmit the audio and video stream, usually request the other user's audio and video data call code as follows (c + +):
1.// request each other's video stream
2.brac_usercameracontrol (dwuserid,true);
3.// request an audio stream from each other
4.brac_userspeakcontrol (dwuserid,true);
data transmission priority to peer , only when the peer is not available, only by the server forwarding, peer-to the NAT hole process, and the data flow transmission strategy is controlled by the server, as long as there is a request, and the other side has opened its own audio and video equipment, you can receive the other's audio and video streaming data.
3 , audio and video playback and display
When you receive audio data from another user:
a if the "Brac_func_audio_autoplay" flag is set during initialization , the SDK will automatically play and mix automatically;
b if the "Brac_func_audio_cbdata" flag is set at initialization time , the SDK will call back the decoded audio data (PCM format) to the upper application via a callback function.
when you receive video data from another user :
a if the "BRAC_FUNC_VIDEO_AUTODISP" flag is set at initialization and the API is called: brac_setvideopos, The inside of the SDK will display the video to the specified position in the specified form (Automatically overlay a video window at the specified location);
b if the "Brac_func_video_cbdata" flag is set at initialization time , the SDK will call back the decoded video data (RGB, YUV) through the callback function to the upper application, drawn by the upper application itself, or rendered, This mode is suitable for applications that do not have windowed modes such as DirectX, Hge, or where the upper-level application requires special processing of the video, such as overlapping text, logos, etc.
4 , text interaction
Once you have successfully entered the room, you can call the API interface to send text messages to the specified user or to all users in the room:
1.// Send text message
2.CStringstrInput = "HelloWorld";
3.brac_sendtextmessage ( -1,false,strinput.getbuffer (0), strinput.getlength ());
when other users receive their own text messages, they trigger the callback function: the text message callback function , which can realize the interaction of text by processing the callback message and then displaying the received text message on the interface.
5 , business logic processing
anychat SDK The basic logic is that when your own audio and video device is turned on, other users request it, they will transfer the streaming media to each other without any business logic.
a if you want to implement a video conferencing system, then the user enters the room, you need to know who is the host, and then open the video of the host;
b if you want to implement a video chat system, then users enter the room, you need to know the current room has several male, who on the public wheat, and then open the corresponding to the user's video, such as the public;
C ) ...
These business logic needs to be implemented in conjunction with the server-side "Sdkfilter Plus" or "anychat server SDK", which can be referenced in the SDK package: The Doc\server\ directory under the The 6th chapter of the Anychat Server SDK Development Guide.
Iv. release of resources
with the previous connection to the server, login system, enter the room corresponding to the process of exiting the system is: leave the room, log off the system, release resources, usually the calling code is as follows (C + +):
1.// leave the room
2.brac_leaveroom (-1);
3.// Log off the system (network connection will be turned off)
4.brac_logout ();
5.// Freeing Resources
6.brac_release ();
after leaving the room, you can enter a new room, after the system logoff, you can again call the Connection Server API interface, but after releasing the resources, will no longer work.
Special attention needs to be paid to the opportunity to release resources.
after that, we will know why, if you like this project, please continue to follow www.anychat.cn
Video development of internet video websites