Plugged the DLL of the P2P connection and the transmission process - the latest improvement version
In the previous release of the DLL, use CString to save the data, but when CString is frequently deleted and added, the efficiency is too low, in the newly released DLL, remove all CString, in the original use of CString On the place, use a new class CStringex instead, and improve the process of receiving and transmitting, making the original reception, copy, replication process, completed by a receiving process, enhanced efficiency by 60%, and saving Resource. The transmission process of the data has also been made, which has been made significantly improved efficiency, especially for the transmission and reception of large data streams. The maximum difference in improvement is to eliminate the limit of the original data stream cannot exceed 18,000 bytes. The size of the data stream can be unlimited, and the transmission of binary streams, such as direct transmission of audio and video buffers, buffers of binary streaming Directly assign CSTRINGEX, or use CSTRINGEX to replace the original buffer, you can directly transfer data in the buffer. In the new DLL, in order to meet the future IP multicast, the M_SReceiver field (ie, the receiver ID) that is originally defined in the PBaseAct base class is canceled, and some changes are made in the sequence of objects, and the specific changes can be referred to in Example. The definition of the PCHATATATATATATATAtAtAttical class. CSTRINGEX will appear as the 5th class provided by the DLL. CSTRINGEX can implement most of CString, for convenience, only overloaded =, = operator, can directly assign or add an int, LPCTSTR type value. In addition, it is specifically optimized for the Delete (0, Ncount) method, enhances efficiency by 100%, making the time for the operation of the operation constant N, and the original CString delete (0, ncount) operation time is N * LEN, LEN is the length of CString. In addition, CSTRINGEX also supports an increase in binary flow buffering.
Through the release of the new version of the DLL, it should be seen that changes to the transfer and reception process, the change of the data stream itself, only for the DLL inside, and for developers using the DLL, do not need to change their own procedures The transmission and reception efficiency of the DLL change can be enjoyed directly.
In the next version of the DLL, I will join the audio transfer and playback to implement voice chat. In the next version, I will join the breakthrough to the firewall (currently limited to the firewall that supports the Socket5 protocol).
I hope that everyone can write their own experience after use, let more people understand and use the DLL to develop, and I hope that everyone can make your views and opinions on the development of the DLL.
Encapsulated the latest version of the P2P connection and the transfer process - support voice transmission
After a few days of hard work, voice transmission is finally integrated into the DLL, because I only have testing on 2 machines, how is the effect, I hope everyone can tell me in time after use. The capture and playback of sounds use DirectSound, which uses DirectSound Notify feature to read the write buffer when capturing and playback, making the sound to be more smoothly expressed. After the sound data is captured, save it in the CSTRINGEX object of an instruction, then transferred to the connector, and then writes the conveying process of the entire sound after receiving the instruction. In this release, I have not yet made very perfect, and there is no format check for each transmitted sound data, so the connection between the two sides must use the same format (ie sampling rate, 8/16, mono or stereo) ) To capture and play back, otherwise the sound may change. When you use the default value (ie 22.05kHz, 8-bit, mono) mode, the amount of data transmitted per second is about 22K, and this amount of data should be able to bear the 56K MODEM. Because I use a broadband, I can't test in a low-bandwidth network. I hope that friends who have tested can tell me the results. In addition, in this version, I made a small repayment, and did not transfer the sound in the entire dialog process, regardless of whether you are talking. I added a small filter program in the DLL. If there is no effect in the sound capture, it will not transfer data to the other party, and the sound instruction is transmitted to the other party only when valid data occurs. I only made a test on my own machine. I don't know how the effect. I hope everyone can use it, I can tell me the effect after use. How to start the sound transmission? Very simple, just call several static methods defined in the PDEfine class, you can complete the transfer process of the entire voice, you have an ip_phone. Please follow the following steps to start the sound transfer: 1 assigns the PDEfine :: CSMSGINFO structure. 2 Create a PFRIEND object and establish a chat connection at the other party. The specific procedures of these two steps are introduced in detail in the previous article, and this is no longer detailed, and the specific method can see the PPSer example program. 3 PDEfine :: splaySound (8); // Start the sound playback device, the argument is an integer between 0..15. The default is 8. // The meaning of the integer representation is the same as the order in the format list of the capture device. // The format of sound playback should be the same as the recorded format, otherwise it will result in a change. 4 hWnd hcombo = this-> getdlgitem (idc_combo1) -> m_hwnd; pdefine :: sgetsoundcaptureDevice (hCOMBO); // Create a sound capture device, passing a combination box control HWnd, DLL will populate the available sound capture device in a combination Inside the box. // If the HWND given is empty, the DLL does not fill it. Composite box controls should not be sorted.
5 PDEfine :: SinitsoundCaptureDevice (null); // If you give a HWND of a combo box control in step 4, the DLL will automatically set the initial choice to the 0th regulations. / / You can send the HWND of the combination box control to the // sinitsoundcaptureDevice () method to transfer the HWND of the combo box control as a parameter after waiting for the user to select the combo box. // If you hWND in the previous method, then when you call the sinitsoundcaptureDevice () method, // set the first parameter as NULL, then pass the second parameter, the second parameter indicates that you choose the first few Equipment, this value must // is a valid selection, the second parameter is 0.6 hWnd hlistbox = this-> getdlgitem (IDC_LIST1) -> getSoundCaptureavailableFormats (hlistbox); // Get the selection The available format list of capture devices, passing a list box control HWnd, and DLL will populate the available capture // format in the list box. If hwnd is empty, the DLL does not fill it. The list box control should not be sorted.
7 PDEfine :: SSETSOUNDCAPTUREACCEPTDFRIEND (cppserdlg :: sgetfriendfromid ("PPQ123456789"))); // With this method, you can choose which friend of the subsequent voice. // This method can change the recipient multiple times after starting the sound capture. // If you have not created a connection between you and this friend, the voice will not be transmitted, the program will not be wrong, I will add some messages in subsequent versions to notify the DLL to make a corresponding response.
8 PDEfine :: ScreateSoundCaptureBuffer; // How to use the usage of the above combination box. The second parameter is default, indicating that the default value is 8, // ie 22.05kHz, 8 bits, mono format.
9 PDEfine :: SRecordsound (); // Start the sound capture.
After the above 9 steps, you have created a channel of voice transmission, voice transmission, and text transmission use of the same connection, you can transfer other instructions while transmitting sounds. From the steps 4 to 9, do not repeat the call, unless you release the capture or playback device.
All methods related to sound capture and playback are static methods in the PDefine class, and other methods are as follows: static void sstopRecordsound (); // Temporarily stop the sound capture, the sound capture device is not released, you can use PDEfine :: SRecordSound () method continues to start the sound capture.
Static void SreleaseSoundCaptureDevice (); // Release the sound capture device. When you call this method, you don't need to stop the sound capture in advance, and the method is automatically called. // If you release the sound capture device, you can't continue the start of sound capture by calling the PDEfine :: SRecordsound () method; you must repeat steps 3 to 9 steps to restart the sound capture. // Note: At the end of the program, be sure to call the method to release the sound capture device, even if you do not start the sound capture device, call the method does not generate an error. Static void sStopplaySound (); // temporarily stops sound playback. You can continue playback by calling the PDEfine :: splaySound () method. During the period you stop your voice, the sound you receive will be saved in the memory. When you continue to play back, you will automatically play the sound in order to the original reception. // When this version, you can't create multiple sound playbacks. In subsequent versions, you will support multiple sound playbacks. Static void SreleaseSoundPlayDevice (); // Release the sound playback device. You can continue playback by calling the PDEfine :: splaySound () method. // Note: At the end of the program, be sure to call the method to release the sound playback device, even if you do not start the sound playback device, call the method does not generate an error.
Regarding the transmission method of the sound, it will be temporarily introduced here. In the next version, I will integrate the way to break through the firewall into the DLL, so that both sides in any location can achieve the interconnection of P2P. Due to the restrictions on development conditions, the test breaks through the method of firewall, which is a very troublesome thing to me. Because I only have a machine, I do this, I have to take a lot of bends, I don't know if a friend is willing to work together for testing.
I hope everyone can continue to pay attention to the subsequent version of the DLL.