comparison mplayer.c @ 22488:b6aa3eedf49b

Move the sh_audio->delay field to mpctx->delay. The value is related to overall a/v sync and is not used by audio demuxers or decoders.
author uau
date Sun, 11 Mar 2007 06:16:14 +0000
parents 2c1ecca1886c
children b6b1bd155b58
comparison
equal deleted inserted replaced
22487:1c5ea79749ea 22488:b6aa3eedf49b
1152 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer), 1152 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
1153 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer)); 1153 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
1154 else 1154 else
1155 saddf(line, &pos, width, "??%% ??%% ??,?%% "); 1155 saddf(line, &pos, width, "??%% ??%% ??,?%% ");
1156 } else if (mpctx->sh_audio) { 1156 } else if (mpctx->sh_audio) {
1157 if (mpctx->sh_audio->delay > 0.5) 1157 if (mpctx->delay > 0.5)
1158 saddf(line, &pos, width, "%4.1f%% ", 1158 saddf(line, &pos, width, "%4.1f%% ",
1159 100.0*audio_time_usage/(double)mpctx->sh_audio->delay); 1159 100.0*audio_time_usage/(double)mpctx->delay);
1160 else 1160 else
1161 saddf(line, &pos, width, "??,?%% "); 1161 saddf(line, &pos, width, "??,?%% ");
1162 } 1162 }
1163 1163
1164 // VO stats 1164 // VO stats
1697 * trying to measure. This keeps the two from competing, but still 1697 * trying to measure. This keeps the two from competing, but still
1698 * allows the code to correct for PTS drift *only*. (Using a delay 1698 * allows the code to correct for PTS drift *only*. (Using a delay
1699 * value here, even a "corrected" one, would be incompatible with 1699 * value here, even a "corrected" one, would be incompatible with
1700 * autosync mode.) 1700 * autosync mode.)
1701 */ 1701 */
1702 a_pts = written_audio_pts(mpctx->sh_audio, mpctx->d_audio) - mpctx->sh_audio->delay; 1702 a_pts = written_audio_pts(mpctx->sh_audio, mpctx->d_audio) - mpctx->delay;
1703 else 1703 else
1704 a_pts = playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, mpctx->audio_out); 1704 a_pts = playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, mpctx->audio_out);
1705 1705
1706 v_pts = mpctx->sh_video->pts; 1706 v_pts = mpctx->sh_video->pts;
1707 1707
1727 if (default_max_pts_correction >= 0) 1727 if (default_max_pts_correction >= 0)
1728 max_pts_correction = default_max_pts_correction; 1728 max_pts_correction = default_max_pts_correction;
1729 else 1729 else
1730 max_pts_correction = mpctx->sh_video->frametime*0.10; // +-10% of time 1730 max_pts_correction = mpctx->sh_video->frametime*0.10; // +-10% of time
1731 if (!between_frames) { 1731 if (!between_frames) {
1732 mpctx->sh_audio->delay+=x; 1732 mpctx->delay+=x;
1733 c_total+=x; 1733 c_total+=x;
1734 } 1734 }
1735 if(!quiet) 1735 if(!quiet)
1736 print_status(a_pts - audio_delay, AV_delay, c_total); 1736 print_status(a_pts - audio_delay, AV_delay, c_total);
1737 } 1737 }
1758 1758
1759 while (1) { 1759 while (1) {
1760 // all the current uses of ao_data.pts seem to be in aos that handle 1760 // all the current uses of ao_data.pts seem to be in aos that handle
1761 // sync completely wrong; there should be no need to use ao_data.pts 1761 // sync completely wrong; there should be no need to use ao_data.pts
1762 // in get_space() 1762 // in get_space()
1763 ao_data.pts = ((mpctx->sh_video?mpctx->sh_video->timer:0)+sh_audio->delay)*90000.0; 1763 ao_data.pts = ((mpctx->sh_video?mpctx->sh_video->timer:0)+mpctx->delay)*90000.0;
1764 bytes_to_write = mpctx->audio_out->get_space(); 1764 bytes_to_write = mpctx->audio_out->get_space();
1765 if (mpctx->sh_video || bytes_to_write >= ao_data.outburst) 1765 if (mpctx->sh_video || bytes_to_write >= ao_data.outburst)
1766 break; 1766 break;
1767 1767
1768 // handle audio-only case: 1768 // handle audio-only case:
1810 current_module="play_audio"; 1810 current_module="play_audio";
1811 1811
1812 // Is this pts value actually useful for the aos that access it? 1812 // Is this pts value actually useful for the aos that access it?
1813 // They're obviously badly broken in the way they handle av sync; 1813 // They're obviously badly broken in the way they handle av sync;
1814 // would not having access to this make them more broken? 1814 // would not having access to this make them more broken?
1815 ao_data.pts = ((mpctx->sh_video?mpctx->sh_video->timer:0)+sh_audio->delay)*90000.0; 1815 ao_data.pts = ((mpctx->sh_video?mpctx->sh_video->timer:0)+mpctx->delay)*90000.0;
1816 playsize = mpctx->audio_out->play(sh_audio->a_out_buffer, playsize, playflags); 1816 playsize = mpctx->audio_out->play(sh_audio->a_out_buffer, playsize, playflags);
1817 1817
1818 if (playsize > 0) { 1818 if (playsize > 0) {
1819 sh_audio->a_out_buffer_len -= playsize; 1819 sh_audio->a_out_buffer_len -= playsize;
1820 memmove(sh_audio->a_out_buffer, &sh_audio->a_out_buffer[playsize], 1820 memmove(sh_audio->a_out_buffer, &sh_audio->a_out_buffer[playsize],
1821 sh_audio->a_out_buffer_len); 1821 sh_audio->a_out_buffer_len);
1822 sh_audio->delay += playback_speed*playsize/(double)ao_data.bps; 1822 mpctx->delay += playback_speed*playsize/(double)ao_data.bps;
1823 } 1823 }
1824 else if (audio_eof && mpctx->audio_out->get_delay() < .04) { 1824 else if (audio_eof && mpctx->audio_out->get_delay() < .04) {
1825 // Sanity check to avoid hanging in case current ao doesn't output 1825 // Sanity check to avoid hanging in case current ao doesn't output
1826 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK 1826 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
1827 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Audio output truncated at end.\n"); 1827 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Audio output truncated at end.\n");
1850 * closer to the delay value gets to that which "-nosound" 1850 * closer to the delay value gets to that which "-nosound"
1851 * would have used, and the longer it will take for A/V 1851 * would have used, and the longer it will take for A/V
1852 * sync to settle at the right value (but it eventually will.) 1852 * sync to settle at the right value (but it eventually will.)
1853 * This settling time is very short for values below 100. 1853 * This settling time is very short for values below 100.
1854 */ 1854 */
1855 float predicted = mpctx->sh_audio->delay / playback_speed + *time_frame; 1855 float predicted = mpctx->delay / playback_speed + *time_frame;
1856 float difference = delay - predicted; 1856 float difference = delay - predicted;
1857 delay = predicted + difference / (float)autosync; 1857 delay = predicted + difference / (float)autosync;
1858 } 1858 }
1859 1859
1860 *time_frame = delay - mpctx->sh_audio->delay / playback_speed; 1860 *time_frame = delay - mpctx->delay / playback_speed;
1861 1861
1862 // delay = amount of audio buffered in soundcard/driver 1862 // delay = amount of audio buffered in soundcard/driver
1863 if (delay > 0.25) delay=0.25; else 1863 if (delay > 0.25) delay=0.25; else
1864 if (delay < 0.10) delay=0.10; 1864 if (delay < 0.10) delay=0.10;
1865 if (*time_frame > delay*0.6) { 1865 if (*time_frame > delay*0.6) {
2012 return -1; 2012 return -1;
2013 if (in_size > max_framesize) 2013 if (in_size > max_framesize)
2014 max_framesize = in_size; // stats 2014 max_framesize = in_size; // stats
2015 sh_video->timer += frame_time; 2015 sh_video->timer += frame_time;
2016 if (mpctx->sh_audio) 2016 if (mpctx->sh_audio)
2017 mpctx->sh_audio->delay -= frame_time; 2017 mpctx->delay -= frame_time;
2018 // video_read_frame can change fps (e.g. for ASF video) 2018 // video_read_frame can change fps (e.g. for ASF video)
2019 vo_fps = sh_video->fps; 2019 vo_fps = sh_video->fps;
2020 // check for frame-drop: 2020 // check for frame-drop:
2021 current_module = "check_framedrop"; 2021 current_module = "check_framedrop";
2022 if (mpctx->sh_audio && !mpctx->d_audio->eof) { 2022 if (mpctx->sh_audio && !mpctx->d_audio->eof) {
2023 static int dropped_frames; 2023 static int dropped_frames;
2024 float delay = playback_speed*mpctx->audio_out->get_delay(); 2024 float delay = playback_speed*mpctx->audio_out->get_delay();
2025 float d = delay-mpctx->sh_audio->delay; 2025 float d = delay-mpctx->delay;
2026 // we should avoid dropping too many frames in sequence unless we 2026 // we should avoid dropping too many frames in sequence unless we
2027 // are too late. and we allow 100ms A-V delay here: 2027 // are too late. and we allow 100ms A-V delay here:
2028 if (d < -dropped_frames*frame_time-0.100 && 2028 if (d < -dropped_frames*frame_time-0.100 &&
2029 mpctx->osd_function != OSD_PAUSE) { 2029 mpctx->osd_function != OSD_PAUSE) {
2030 drop_frame = frame_dropping; 2030 drop_frame = frame_dropping;
2060 } 2060 }
2061 frame_time = sh_video->pts - sh_video->last_pts; 2061 frame_time = sh_video->pts - sh_video->last_pts;
2062 sh_video->last_pts = sh_video->pts; 2062 sh_video->last_pts = sh_video->pts;
2063 sh_video->timer += frame_time; 2063 sh_video->timer += frame_time;
2064 if(mpctx->sh_audio) 2064 if(mpctx->sh_audio)
2065 mpctx->sh_audio->delay -= frame_time; 2065 mpctx->delay -= frame_time;
2066 *blit_frame = 1; 2066 *blit_frame = 1;
2067 } 2067 }
2068 return frame_time; 2068 return frame_time;
2069 } 2069 }
2070 2070
2240 if (vo_config_count) 2240 if (vo_config_count)
2241 mpctx->video_out->control(VOCTRL_RESET, NULL); 2241 mpctx->video_out->control(VOCTRL_RESET, NULL);
2242 mpctx->sh_video->num_buffered_pts = 0; 2242 mpctx->sh_video->num_buffered_pts = 0;
2243 mpctx->sh_video->last_pts = MP_NOPTS_VALUE; 2243 mpctx->sh_video->last_pts = MP_NOPTS_VALUE;
2244 mpctx->num_buffered_frames = 0; 2244 mpctx->num_buffered_frames = 0;
2245 mpctx->delay = 0;
2245 // Not all demuxers set d_video->pts during seek, so this value 2246 // Not all demuxers set d_video->pts during seek, so this value
2246 // (which is used by at least vobsub and edl code below) may 2247 // (which is used by at least vobsub and edl code below) may
2247 // be completely wrong (probably 0). 2248 // be completely wrong (probably 0).
2248 mpctx->sh_video->pts = mpctx->d_video->pts; 2249 mpctx->sh_video->pts = mpctx->d_video->pts;
2249 update_subtitles(mpctx->sh_video, mpctx->d_sub, 1); 2250 update_subtitles(mpctx->sh_video, mpctx->d_sub, 1);
3274 audio_delay += mpctx->sh_video->stream_delay; 3275 audio_delay += mpctx->sh_video->stream_delay;
3275 } 3276 }
3276 if(mpctx->sh_audio){ 3277 if(mpctx->sh_audio){
3277 if (! ignore_start) 3278 if (! ignore_start)
3278 audio_delay -= mpctx->sh_audio->stream_delay; 3279 audio_delay -= mpctx->sh_audio->stream_delay;
3279 mpctx->sh_audio->delay=-audio_delay; 3280 mpctx->delay=-audio_delay;
3280 } 3281 }
3281 3282
3282 if(!mpctx->sh_audio){ 3283 if(!mpctx->sh_audio){
3283 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound); 3284 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
3284 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",mpctx->d_audio->packs); 3285 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",mpctx->d_audio->packs);
3559 off_t len = ( mpctx->demuxer->movi_end - mpctx->demuxer->movi_start ); 3560 off_t len = ( mpctx->demuxer->movi_end - mpctx->demuxer->movi_start );
3560 off_t pos = ( mpctx->demuxer->file_format == DEMUXER_TYPE_AUDIO?mpctx->stream->pos:mpctx->demuxer->filepos ); 3561 off_t pos = ( mpctx->demuxer->file_format == DEMUXER_TYPE_AUDIO?mpctx->stream->pos:mpctx->demuxer->filepos );
3561 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - mpctx->demuxer->movi_start ) * 100.0f / len ); 3562 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - mpctx->demuxer->movi_start ) * 100.0f / len );
3562 } 3563 }
3563 if ( mpctx->sh_video ) guiIntfStruct.TimeSec=mpctx->sh_video->pts; 3564 if ( mpctx->sh_video ) guiIntfStruct.TimeSec=mpctx->sh_video->pts;
3564 else if ( mpctx->sh_audio ) guiIntfStruct.TimeSec=mpctx->sh_audio->delay; 3565 else if ( mpctx->sh_audio ) guiIntfStruct.TimeSec=mpctx->delay;
3565 guiIntfStruct.LengthInSec=demuxer_get_time_length(mpctx->demuxer); 3566 guiIntfStruct.LengthInSec=demuxer_get_time_length(mpctx->demuxer);
3566 guiGetEvent( guiReDraw,NULL ); 3567 guiGetEvent( guiReDraw,NULL );
3567 guiGetEvent( guiSetVolume,NULL ); 3568 guiGetEvent( guiSetVolume,NULL );
3568 if(guiIntfStruct.Playing==0) break; // STOP 3569 if(guiIntfStruct.Playing==0) break; // STOP
3569 if(guiIntfStruct.Playing==2) mpctx->osd_function=OSD_PAUSE; 3570 if(guiIntfStruct.Playing==2) mpctx->osd_function=OSD_PAUSE;