Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SegmentManager::adapt(unsigned int* n, int speed, int stream_type, DASH_Context* dash_context)
- {
- unsigned int i = 0;
- unsigned int reservoir = 12;
- unsigned int cushion = 24;
- unsigned int upper_reservoir = 12;
- unsigned int up_limit;
- unsigned int down_limit;
- if(stream_type == STREAM_TYPE_VIDEO)
- {
- m_numberOfVideoSegmentsCurrRep++;
- if(m_numberOfVideoSegmentsCurrRep < MINIMUM_REQUIRED_NUMBER_OF_SEGMENTS)
- {
- return;
- }
- }
- if(stream_type == STREAM_TYPE_AUDIO)
- {
- m_numberOfAudioSegmentsCurrRep++;
- if(m_numberOfAudioSegmentsCurrRep < MINIMUM_REQUIRED_NUMBER_OF_SEGMENTS)
- {
- return;
- }
- }
- if(stream_type == STREAM_TYPE_SUBTITLE)
- {
- m_numberOfSubtitleSegmentsCurrRep++;
- if(m_numberOfSubtitleSegmentsCurrRep < MINIMUM_REQUIRED_NUMBER_OF_SEGMENTS)
- {
- return;
- }
- }
- if(*n >= (dash_context->bandsVideo.size()- 1))
- {
- up_limit = dash_context->bandsVideo.size()- 1;
- }
- else
- {
- up_limit = *n + 1;
- }
- if(*n == 0)
- {
- down_limit = 0;
- }
- else
- {
- down_limit = *n-1;
- }
- int map_buffer_to_rate = ((dash_context->videoBufferFullness - reservoir) * ((double)(dash_context->bandsVideo.size() - 1)/cushion));
- if(dash_context->videoBufferFullness <= reservoir)
- {
- *n = 0;
- }
- else if(dash_context->videoBufferFullness >= (reservoir + cushion))
- {
- *n = dash_context->bandsVideo.size()-1;
- }
- else if(map_buffer_to_rate >= up_limit)
- {
- *n = map_buffer_to_rate - 1;
- }
- else if(map_buffer_to_rate <= down_limit)
- {
- *n = map_buffer_to_rate + 1;
- }
- else
- {
- DBG_VERBOSE("quality same as previous\n");
- }
- DBG_VERBOSE("BUFFER = %lf\n", dash_context->videoBufferFullness);
- DBG_VERBOSE("SPEED = %d\n", speed * 8);
- DBG_VERBOSE("QUALITY = %d\n", *n);
- if(dash_context->videoBufferFullness >= (reservoir + cushion))
- {
- usleep(1000 * 1000 * (dash_context->videoBufferFullness - (reservoir + cushion)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement