Introduction of antecedents
This story may be a little difficult to tell, and it involves a lot of things. I hope I can tell the story as clearly as possible.
Let’s start with the order bucket:
Token buckets are a common flow control technique. The token bucket itself does not have a discard and priority policy. Principle:
1. Tokens are put into the bucket at a certain rate. 2. Each token allows the source to send a certain number of bits. 3. When sending a packet, the flow regulator removes the number of tokens equal to the packet size from the bucket. 4. If there are not enough tokens to send the packet, the packet will wait until there are enough tokens (in the case of the plastic) or the packet is discarded, and may also be marked with a lower DSCP (in the case of the policy maker). 5. Buckets have a specific capacity, and if the bucket is full, newly added tokens are discarded. Thus, at any one time, the maximum amount of burst data the source sends to the network is proportional to the size of the bucket. The token bucket allows bursts, but does not exceed the limit.Copy the code
It might be more intuitive to draw a picture:Ah,, I don’t seem to know how to draw fancy pictures, but I’ll just have to.
After the token bucket, let’s talk about my application scenario. Again, draw a picture:
The general process is as shown in the figure above, but the specific process is more complicated.
Application Scenarios:
When the Server -phone rotates, the client screen occasionally freezes.
The case detection
Guess the possible causes:
- The client decoding module is abnormal. Procedure
- The Server coding module is abnormal. Procedure
- Description The server did not receive a request from the client
Number of tokens | VideoSource frame | A frame used for encoding | Send out frame |
---|---|---|---|
request | input | drawing | output |
The logic goes like this:
Received the token: request++ | | received Input (and request is greater than 0) : request --, drawing++ | | listen to the encoder output: drawing++Copy the code
In theory,
request = drawing = output
Input is discarded without request
It is a time-consuming process from the VideoEncoder receiving the image frame to the encoding completion, and the output of H.264 data suitable for transmission over the network.
When the screen rotates, because ***VideoEncoder*** will be destroyed and then created again.Copy the code
When you rotate the screen
Client does not receive data. Client does not receive data. No token request is generated. No token Request is generated Server does not receive request --> No more drawingCopy the code
So the solution is to reset the Encoder and recalculate the request:
reqeust = request + drawing;
drawing = 0;
Copy the code
The case summary
Be careful with each asynchronous process.