Linuxc/C ++ programming BASICS (30) video package cache implementation

Source: Internet
Author: User
1. Define cache_limit as follows:

Enum CacheLimit {
  Max
Speakers = 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: Make
Pair (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

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.