ck a dull boy All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull

boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a 
dull boy. All work and no play makes Jack a


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21497 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen 2007-06-23 23:17:57 +00:00
parent 16c1a4e653
commit be5f5c2d14

View File

@ -30,6 +30,7 @@
#include <MediaFile.h> #include <MediaFile.h>
#include <MediaTrack.h> #include <MediaTrack.h>
#include <Path.h> #include <Path.h>
#include <Window.h> // for debugging only
#include "ControllerView.h" #include "ControllerView.h"
#include "PlaybackState.h" #include "PlaybackState.h"
@ -220,6 +221,8 @@ Controller::SetTo(const entry_ref &ref)
fStopped = fAutoplay ? false : true; fStopped = fAutoplay ? false : true;
fPauseAtEndOfStream = false; fPauseAtEndOfStream = false;
fSeekToStartAfterPause = false; fSeekToStartAfterPause = false;
fTimeSourceSysTime = system_time();
fTimeSourcePerfTime = 0;
fDuration = 0; fDuration = 0;
_UpdatePosition(0); _UpdatePosition(0);
@ -804,14 +807,6 @@ printf("audio play start\n");
if (!fDataLock.Lock()) if (!fDataLock.Lock())
return; return;
// TODO: fix performance time update (in case no audio)
if (fTimeSourceLock.Lock()) {
fTimeSourceSysTime = system_time() + audioLatency - bufferDuration;
fTimeSourceLock.Unlock();
}
// printf("timesource: sys: %Ld perf: %Ld\n", fTimeSourceSysTime,
// fTimeSourcePerfTime);
if (buffer->sizeUsed == 0) { if (buffer->sizeUsed == 0) {
bool pause = fPauseAtEndOfStream && buffer->endOfStream; bool pause = fPauseAtEndOfStream && buffer->endOfStream;
fDataLock.Unlock(); fDataLock.Unlock();
@ -841,12 +836,22 @@ printf("audio format changed, new buffer duration %Ld\n", bufferDuration);
} }
} }
// TODO: fix performance time update (in case no audio)
if (fTimeSourceLock.Lock()) {
audioLatency = fSoundOutput->Latency();
fTimeSourceSysTime = system_time() + audioLatency - bufferDuration;
fTimeSourcePerfTime = buffer->startTime;
fTimeSourceLock.Unlock();
}
// printf("timesource: sys: %Ld perf: %Ld\n", fTimeSourceSysTime,
// fTimeSourcePerfTime);
if (fSoundOutput) { if (fSoundOutput) {
fSoundOutput->Play(buffer->buffer, buffer->sizeUsed); fSoundOutput->Play(buffer->buffer, buffer->sizeUsed);
audioLatency = fSoundOutput->Latency();
_UpdatePosition(buffer->startTime); _UpdatePosition(buffer->startTime);
} }
fDataLock.Unlock(); fDataLock.Unlock();
release_sem(fAudioDecodeSem); release_sem(fAudioDecodeSem);
@ -985,29 +990,47 @@ printf("video decode start\n");
goto wait; goto wait;
} }
#if 0
bigtime_t waituntil; bigtime_t waituntil;
bigtime_t waitdelta; bigtime_t waitdelta;
char test[100]; bigtime_t now;
{ if (fTimeSourceLock.Lock()) {
BAutolock lock(fTimeSourceLock); now = system_time();
waituntil = fTimeSourceSysTime - fTimeSourcePerfTime + buffer->startTime - 1000;
waituntil = fTimeSourceSysTime - fTimeSourcePerfTime + buffer->startTime; waitdelta = waituntil - now;
waitdelta = waituntil - system_time(); fTimeSourceLock.Unlock();
sprintf(test, "sys %.6f perf %.6f, vid %.6f, waituntil %.6f, waitdelta %.6f", } else {
fTimeSourceSysTime / 1000000.0f, // puhh...
fTimeSourcePerfTime / 1000000.0f,
buffer->startTime / 1000000.0f,
waituntil / 1000000.0f,
waitdelta / 1000000.0f);
} }
#if 0
char test[100];
sprintf(test, "sys %.6f perf %.6f, vid %.6f, now %.6f, waituntil %.6f, waitdelta %.6f",
fTimeSourceSysTime / 1E6, fTimeSourcePerfTime / 1E6,
buffer->startTime / 1E6, now / 1E6,
waituntil / 1E6, waitdelta / 1E6);
if (fVideoView->LockLooperWithTimeout(5000) == B_OK) { if (fVideoView->LockLooperWithTimeout(5000) == B_OK) {
fVideoView->Window()->SetTitle(test); fVideoView->Window()->SetTitle(test);
fVideoView->UnlockLooper(); fVideoView->UnlockLooper();
} }
#else #endif
bigtime_t waituntil;
waituntil = fTimeSourceSysTime - fTimeSourcePerfTime + buffer->startTime; if (fAudioSupplierLock.Lock()) {
if (!fAudioSupplier) {
fTimeSourceSysTime = system_time();
fTimeSourcePerfTime = buffer->startTime;
}
fAudioSupplierLock.Unlock();
} else {
// puhh...
}
#if 1
if (waitdelta < -150000) {
printf("video: frame %.6f too late, dropped\n", waitdelta / -1E6);
release_sem(fVideoDecodeSem);
continue;
}
#endif #endif
status = acquire_sem_etc(fVideoWaitSem, 1, B_ABSOLUTE_TIMEOUT, waituntil); status = acquire_sem_etc(fVideoWaitSem, 1, B_ABSOLUTE_TIMEOUT, waituntil);
@ -1039,8 +1062,9 @@ printf("video decode start\n");
fPauseAtEndOfStream = false; fPauseAtEndOfStream = false;
fSeekToStartAfterPause = true; fSeekToStartAfterPause = true;
Pause(); Pause();
} else }
snooze(25000); //else
// snooze(25000);
continue; continue;
} }
} else } else
@ -1051,7 +1075,7 @@ printf("video decode start\n");
// snooze(60000); // snooze(60000);
release_sem(fVideoDecodeSem); release_sem(fVideoDecodeSem);
} }
// status_t status = acquire_sem_etc(fVideoWaitSem, 1, B_ABSOLUTE_TIMEOUT, buffer->startTime); // status_t status = acquire_sem_etc(fVideoWaitSem, 1, B_ABSOLUTE_TIMEOUT, buffer->startTime);
// if (status != B_TIMED_OUT) // if (status != B_TIMED_OUT)
// return; // return;
@ -1151,8 +1175,8 @@ Controller::_UpdatePosition(bigtime_t position, bool isVideoPosition, bool force
if (isVideoPosition && fAudioSupplier) if (isVideoPosition && fAudioSupplier)
return; return;
BAutolock _(fTimeSourceLock); // BAutolock _(fTimeSourceLock);
fTimeSourcePerfTime = position; // fTimeSourcePerfTime = position;
fPosition = position; fPosition = position;
float scale = fDuration > 0 ? (float)fPosition / fDuration : 0.0; float scale = fDuration > 0 ? (float)fPosition / fDuration : 0.0;