mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-29 03:26:38 +00:00 
			
		
		
		
	Always try to resync if the clock difference is large
This commit is contained in:
		
							parent
							
								
									f97eaec7ab
								
							
						
					
					
						commit
						582efcdb9b
					
				
					 1 changed files with 24 additions and 38 deletions
				
			
		|  | @ -11,7 +11,6 @@ | ||||||
| #define MAX_AUDIOQ_SIZE (5 * 16 * 1024) | #define MAX_AUDIOQ_SIZE (5 * 16 * 1024) | ||||||
| #define MAX_VIDEOQ_SIZE (5 * 256 * 1024) | #define MAX_VIDEOQ_SIZE (5 * 256 * 1024) | ||||||
| #define AV_SYNC_THRESHOLD 0.01 | #define AV_SYNC_THRESHOLD 0.01 | ||||||
| #define AV_NOSYNC_THRESHOLD 10.0 |  | ||||||
| #define SAMPLE_CORRECTION_PERCENT_MAX 10 | #define SAMPLE_CORRECTION_PERCENT_MAX 10 | ||||||
| #define AUDIO_DIFF_AVG_NB 20 | #define AUDIO_DIFF_AVG_NB 20 | ||||||
| 
 | 
 | ||||||
|  | @ -161,36 +160,26 @@ class MovieAudioDecoder : public MWSound::Sound_Decoder | ||||||
|         if(is->av_sync_type == AV_SYNC_AUDIO_MASTER) |         if(is->av_sync_type == AV_SYNC_AUDIO_MASTER) | ||||||
|             return samples_size; |             return samples_size; | ||||||
| 
 | 
 | ||||||
|         double ref_clock = get_master_clock(is); |         // accumulate the clock difference
 | ||||||
|         double diff = get_audio_clock(is) - ref_clock; |         double diff = get_audio_clock(is) - get_master_clock(is); | ||||||
|         if(diff < AV_NOSYNC_THRESHOLD) |         is->audio_diff_cum = diff + is->audio_diff_avg_coef * | ||||||
|         { |                                     is->audio_diff_cum; | ||||||
|             // accumulate the diffs
 |         if(is->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) | ||||||
|             is->audio_diff_cum = diff + is->audio_diff_avg_coef * |             is->audio_diff_avg_count++; | ||||||
|                                         is->audio_diff_cum; |  | ||||||
|             if(is->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) |  | ||||||
|                 is->audio_diff_avg_count++; |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 double avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef); |  | ||||||
|                 if(fabs(avg_diff) >= is->audio_diff_threshold) |  | ||||||
|                 { |  | ||||||
|                     int n = av_get_bytes_per_sample(is->audio_st->codec->sample_fmt) * |  | ||||||
|                             is->audio_st->codec->channels; |  | ||||||
|                     int wanted_size = samples_size + ((int)(diff * is->audio_st->codec->sample_rate) * n); |  | ||||||
| 
 |  | ||||||
|                     wanted_size = std::max(0, wanted_size); |  | ||||||
|                     wanted_size = std::min(wanted_size, samples_size*2); |  | ||||||
| 
 |  | ||||||
|                     samples_size = wanted_size; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         else |         else | ||||||
|         { |         { | ||||||
|             /* difference is TOO big; reset diff stuff */ |             double avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef); | ||||||
|             is->audio_diff_avg_count = 0; |             if(fabs(avg_diff) >= is->audio_diff_threshold) | ||||||
|             is->audio_diff_cum = 0; |             { | ||||||
|  |                 int n = av_get_bytes_per_sample(is->audio_st->codec->sample_fmt) * | ||||||
|  |                         is->audio_st->codec->channels; | ||||||
|  |                 int wanted_size = samples_size + ((int)(diff * is->audio_st->codec->sample_rate) * n); | ||||||
|  | 
 | ||||||
|  |                 wanted_size = std::max(0, wanted_size); | ||||||
|  |                 wanted_size = std::min(wanted_size, samples_size*2); | ||||||
|  | 
 | ||||||
|  |                 samples_size = wanted_size; | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return samples_size; |         return samples_size; | ||||||
|  | @ -499,15 +488,12 @@ void VideoState::video_refresh_timer() | ||||||
|         diff = vp->pts - ref_clock; |         diff = vp->pts - ref_clock; | ||||||
| 
 | 
 | ||||||
|         /* Skip or repeat the frame. Take delay into account
 |         /* Skip or repeat the frame. Take delay into account
 | ||||||
|             FFPlay still doesn't "know if this is the best guess." */ |          * FFPlay still doesn't "know if this is the best guess." */ | ||||||
|         sync_threshold = (delay > AV_SYNC_THRESHOLD) ? delay : AV_SYNC_THRESHOLD; |         sync_threshold = std::max(delay, AV_SYNC_THRESHOLD); | ||||||
|         if(fabs(diff) < AV_NOSYNC_THRESHOLD) |         if(diff <= -sync_threshold) | ||||||
|         { |             delay = 0; | ||||||
|             if(diff <= -sync_threshold) |         else if(diff >= sync_threshold) | ||||||
|                 delay = 0; |             delay = 2 * delay; | ||||||
|             else if(diff >= sync_threshold) |  | ||||||
|                 delay = 2 * delay; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|     this->frame_timer += delay; |     this->frame_timer += delay; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue