1. Define cache_limit as follows:
Enum CacheLimit {
MaxSpeakers = 8, // indicates the maximum number of connected objects.
Max_pkts = 20 // indicates the maximum number of cache packages for each connection object
};
2. The definition of a video package is as follows:
Struct videopkt
{
Optional bytes uint32_t bytes _ from;
Required bytes uint32_t partition _ SID;
Optional bytes uint32_t partition _ seq;
Uint32_t _ time_stamp;
Required parameter STD: string & other payload;
Explain explain static int parsefrom (const char * data, size_t Len, videopkt ** out );
};
3. The definition of videouidmap is as follows:
Poco: hashmap <uint32_t, STD: Map <uint32_t, Poco: sharedptr <videopkt> videouidmap;
4. The video package cache is as follows:
Void onvideores (const char * pack, int length ){
Required parameter videopkt * Pkt = NULL;
Required parameter videopkt: parsefrom (pack, length, & Pkt );
Zookeeper // send the parsed video data back to the client for omitted implementation. Here we will focus on the implementation of cache.
Zookeeper // Delete Pkt; // update the cache instead of deleting the parsed Pkt.
Zookeeper // update Cache
Poco: hashmap <uint32_t, STD: Map <uint32_t, Poco: sharedptr <videopkt> >:: iterator itr = videouidmap. find (Pkt-> _ from );
When else if (itr = videouidmap. End () {// not found, it indicates it is a new connection object
Required bytes must exist if (videouidmap. Size () <max_speakers ){
When there are too many rows before STD: Map <uint32_t, Poco: sharedptr <videopkt> AMAP;
Too many rows have been inserted into videouidmap. insert (STD: MakePair (Pkt-> _ from, AMAP ));
Required parameter already exist before using itr = videouidmap. Find (Pkt-> _ from );
Please wait until then} else {
When there are too many other than return;
Too many threads}
Billing details}
Required bytes if (itr-> second. Size () = max_pkts ){
Please wait until now itr-> second. Erase (itr-> second. Begin ());
Billing details}
Zookeeper poco: sharedptr P (Pkt );
Using repeated itr-> second. insert (STD: MakePair (Pkt-> _ seq, p ));
}
5. Implementation of retransmission requests:
Bool onresendvideoreq (uint32_t uid, uint32_t SEQ ){
Zookeeper poco: hashmap <uint32T, STD: Map <uint32T, Poco: sharedptr <videopkt >>:: iterator ITT = videouidmap. Find (UID );
When else if (ITT! = Videouidmap. End ()){
Required parameter STD: Map <uint32_t, Poco: sharedptr <videopkt >:: iterator ita = ITT-> second. Find (SEQ );
When else if (ITA! = ITT-> second. End () {// indicates that the lost video package is found in the local cache.
Invalid listener // checks whether the listening ID is invalid. If it is invalid, false is returned. Skipped here.
Zookeeper // send back the video data packets found in the cache to the client.
Optional values return true;
Billing details}
Repeated repeated return resendvideo (UID, SEQ); // The video is not found in the cache and the request is sent to the video front end again.
}
Reprinted please indicate the source: zhujian blog, http://blog.csdn.net/linyanwen99/article/details/8485475