Exclusive secret voice and video chat room development top-notch production tutorials

Source: Internet
Author: User

With the continuous development of the Internet and the rise of various new technologies, I have gradually switched to the development of Internet-related operation products. In particular, the most popular audio/video interaction platform technology, today I will first list the most basic development process, suitable for developing video conferencing systems, voice and video chat rooms, distance education platforms, and instant messaging platforms (IM. I hope it will help my friends who like this. You are also welcomed to participate in the discussion, exchange and study.

First, let's take a look at how to get started.

 

I. Initialization

This part should be completed first, including setting the corresponding callback function, setting the SDK component path, and setting whether to generate a log file. The initialization code is usually as follows (C ++ ):

01. // enable (disable) The Logging Function

02. brac_activecalllog (true );

03.

04. // set the directory of the Core Component

05. charszcoresdkpath [max_path] = {0 };

06. getmodulefilename (null, szcoresdkpath, sizeof (szcoresdkpath ));

07. (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, how to handle related tasks (For details, refer to the Development Documentation)

11. dworddwfuncmode = brac_func_video_cbdata | brac_func_audio_autoplay | brac_func_chkdependmodule | dependency | 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 the path for saving the temporary video file

16. charszrecorddirectory [max_path] = {0 };

17.: getmodulefilename (null, szrecorddirectory, max_path );

18. (strrchr (szrecorddirectory, '\') [1] = 0;

19. strcat (szrecorddirectory, "record ");

20. brac_setsdkoption (brac_so_record_tmpdir, szrecorddirectory, strlen (szrecorddirectory ));

21.

22. // set the video file quality parameters

23. dworddwvideobitrate = 200*1000; // 200 kbps

24. brac_setsdkoption (brac_so_record_videobr, (pchar) & dwvideobitrate, sizeof (DWORD ));

25. dworddwaudiobitrate = 96*1000; // 96 kbps

26. brac_setsdkoption (brac_so_record_audiobr, (pchar) & dwaudiobitrate, sizeof (DWORD ));

27.

28. // set the path for saving the temporary snapshot File

29. charszsnapshotdirectory [max_path] = {0 };

30.: getmodulefilename (null, szsnapshotdirectory, max_path );

31. (strrchr (szsnapshotdirectory, '\') [1] = 0;

32. strcat (szsnapshotdirectory, "snapshot ");

33. brac_setsdkoption (brac_so_snapshot_tmpdir, szsnapshotdirectory, strlen (szsnapshotdirectory ));

34.

35. // set the temporary file path

36. charsztemppath [max_path] = {0 };

37.: getmodulefilename (null, sztemppath, max_path );

38. (strrchr (sztemppath, '\') [1] = 0;

39. strcat (sztemppath, "Temp ");

40. brac_setsdkoption (brac_so_coresdk_tmpdir, sztemppath, strlen (sztemppath ));

41.

42. // enable the automatic audio Parameter Function (disabled by default)

43. dwordbaudioautoparam = true;

44. brac_setsdkoption (brac_so_audio_autoparam, (pchar) & baudioautoparam, sizeof (DWORD ));

2. log on to the system

After the initialization is complete, you can connect to the server and verify the user identity. The call code is usually as follows (C ++ ):

1. // connect to the server

2. brac_connect ("2 11.155.25.90", 8906 );

3. // log on to the system

4. brac_login ("testuser", "", 0 );

Connecting to the server and logging on to the system is an asynchronous process, which will be returned immediately after the call, where:

A. if the connection to the Server succeeds or fails, asynchronous message: network connection message will be triggered.

B. If you log on to the system successfully or fail, an asynchronous message is triggered: log on to the system.

Therefore, the application needs to respond to these asynchronous messages (or process: Asynchronous Message notification callback function) to know whether the connection to the server and the system are successful.

After logging on to the system, if you need to implement the friend list in the instant messaging application (which is not implemented by anychat by default), you need to use the extended API interface of anychat to work with serversdk, after logging on to the system, the server returns a 32-bit user ID. If no password parameter is input during logon, the system considers the user as a visitor, and assign an independent user ID (such as-1 and-2). If a password parameter is input during logon, the login request will be sent to the "SDK filter plus" interface, or the interface corresponding to the "server SDK". You can develop your own server plug-in "SDK filter plus ", or call the API corresponding to the "server SDK" to process user authentication requests, manage user IDs, and interconnect with third-party systems, for more information, see the relevant documentation under the doc \ Server \ directory in the SDK package.

3. Enter the room

After logging on to the system in step 2, you can enter the room, because the interaction between voice and video can be completed only in the room. The call code is usually as follows (C ++ ):

1. // enter the room

2. brac_enterroom (1, "", 0 );

The room is dynamically managed by the server and uniquely identified by the 32-bit room ID number. When the room ID number specified by the client does not exist, the server will be automatically created. Entering the room is also an asynchronous process. Whether the room is successful or not will trigger an asynchronous message: when you enter the room, the server will send the online user list of the current room to the client, after the transmission is complete, asynchronous messages will be triggered: (this message is triggered only once). Audio and Video operations can be performed on users in the room only after the server's online user list is received. Online user messages in current room

When a user successfully enters the room and receives an online user message from the server, a new user enters the room or the old user leaves the room, an asynchronous message is triggered: the user enters (leaves) room message, so that you can know who is in or left the room.

1, Open your own audio and video

After entering the room, you can open your audio and video devices. The call code is as follows (C ++ ):

1. // open your own video device

2. brac_usercameracontrol (-1, true );

3. // open your own audio device

4. brac_userspeakcontrol (-1, true );

After you open your device, it does not immediately upload audio and video streams. Only when other users request their own audio and video data (you can request an audio stream or video stream separately) can they transmit it externally, enable your audio/video device. By default, the device is initialized Based on the server configuration information (such as the sampling resolution, video frame rate, and audio sampling frequency ), to adjust the sound and video quality in the client program,

2, Request other users' audio and video

If you want to display the audio and video of other users, you must request the audio and video streams of the other user after receiving the user list message in the room. Then, the other user can transmit the audio and video streams, the following code is usually used to request audio and video data from other users ):

1. // request the video stream of the other party

2. brac_usercameracontrol (dwuserid, true );

3. // request the audio stream of the other party

4. brac_userspeakcontrol (dwuserid, true );

Data transmission takes precedence over P2P. server-based forwarding is required only when P2P is not available. The P2P Nat and Data Stream Transmission policies are controlled by the server as long as there are requests, and the other party has opened its own audio and video device, then it will be able to receive the audio and video stream data of the other party.

3, Audio and video playback and display

After receiving audio data from other users:

A) if the "brac_func_audio_autoplay" flag is set during initialization, the SDK automatically plays the audio and mixes the audio;

B) if the "brac_func_audio_cbdata" flag is set during initialization, the SDK calls back the decoded audio data (in PCM format) to the upper-layer application through the callback function.

After receiving video data from other users:

A) if the "brac_func_video_autodisp" flag is set during initialization and the API is called :, the SDK will display the video to the specified position of the specified form (a video window is automatically added to the specified position); brac_setvideopos

B) if the "brac_func_video_cbdata" flag is set during initialization, the SDK calls back the decoded video data (RGB and YUV) to the upper layer through the callback function, it is drawn or rendered by upper-layer applications. This mode is suitable for applications in DirectX, HGE, and other non-window modes, or upper-layer applications that need to perform special processing on videos, such as overlapping text and logo.

4Text Interaction

After entering the room, you can call the API to send text messages to a specified user or all users in the room:

1. // send text messages

2. cstring strinput = "Hello World ";

3. brac_sendtextmessage (-1, false, strinput. getbuffer (0), strinput. getlength ());

After receiving the text message sent by others, other users will trigger the callback function: the text message callback function. by processing the callback message, the received text message is displayed on the interface, you can achieve text interaction.

5, Business logic processing

The basic logic built in the anychat SDK is that when your audio/video device is turned on, other users send streaming media data to the other Party upon request, without any business logic.

A) to implement a Video Conferencing System, the user needs to know who is the host after entering the room, and then open the video of the host;

B) to implement a video chat system, after entering the room, the user needs to know the number of male microphones in the current room, who are in male, and then open the video of the male users;

C )......

These business logic needs to be implemented in concert with the "SDK filter plus" or "anychat server SDK" on the server side. For specific implementation solutions, refer to the following in the SDK package: chapter 6th of anychat server SDK Development Guide under the doc \ Server \ directory.

4. release resources

The process of exiting the system is as follows (C ++ ):

1. // exit the room

2. brac_leaveroom (-1 );

3. // log out of the system (network connection will be disabled)

4. brac_logout ();

5. // release resources

6. brac_release ();

After leaving the room, you can enter a new room. After the system logs out, you can call the API to connect to the server again. However, after resources are released, they will no longer work.

Pay special attention to the time to release resources.


This article from the "ya gu chat room developers" blog, please be sure to keep this source http://ijizg123.blog.51cto.com/9657749/1583931

Exclusive secret voice and video chat room development top-notch production tutorials

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.