diff --git a/src/apps/mediaplayer/Controller.cpp b/src/apps/mediaplayer/Controller.cpp index e5f39263ab..5757492c32 100644 --- a/src/apps/mediaplayer/Controller.cpp +++ b/src/apps/mediaplayer/Controller.cpp @@ -25,6 +25,7 @@ #include #include "Controller.h" +#include "ControllerView.h" #include "VideoView.h" #include "SoundOutput.h" @@ -45,6 +46,7 @@ HandleError(const char *text, status_t err) Controller::Controller() : fVideoView(NULL) + , fControllerView(NULL) , fName() , fPaused(false) , fStopped(true) @@ -61,6 +63,9 @@ Controller::Controller() , fStopAudioPlayback(false) , fStopVideoPlayback(false) , fSoundOutput(NULL) + , fSeekAudio(false) + , fSeekVideo(false) + , fSeekPosition(0) { } @@ -87,6 +92,13 @@ Controller::SetVideoView(VideoView *view) } +void +Controller::SetControllerView(ControllerView *view) +{ + fControllerView = view; +} + + status_t Controller::SetTo(const entry_ref &ref) { @@ -221,7 +233,7 @@ Controller::Duration() { bigtime_t a = fAudioTrack ? fAudioTrack->Duration() : 0; bigtime_t v = fVideoTrack ? fVideoTrack->Duration() : 0; - printf("Controller::Duration: audio %.6f, video %.6f", a / 1000000.0, v / 1000000.0); +// printf("Controller::Duration: audio %.6f, video %.6f\n", a / 1000000.0, v / 1000000.0); return max_c(a, v); } @@ -255,11 +267,36 @@ Controller::VolumeDown() void Controller::SetVolume(float value) { + printf("Controller::SetVolume %.4f\n", value); if (fSoundOutput) // hack... fSoundOutput->SetVolume(value); } +void +Controller::SetPosition(float value) +{ + printf("Controller::SetPosition %.4f\n", value); + fSeekPosition = bigtime_t(value * Duration()); + fSeekAudio = true; + fSeekVideo = true; +} + + +void +Controller::UpdateVolume(float value) +{ + fControllerView->SetVolume(value); +} + + +void +Controller::UpdatePosition(float value) +{ + fControllerView->SetPosition(value); +} + + bool Controller::IsOverlayActive() { @@ -365,14 +402,28 @@ Controller::AudioPlayThread() SoundOutput out(fName.String(), fmt.u.raw_audio); + out.SetVolume(1.0); + UpdateVolume(1.0); + + int frame_size = (fmt.u.raw_audio.format & 0xf) * fmt.u.raw_audio.channel_count; uint8 buffer[fmt.u.raw_audio.buffer_size]; int64 frames; media_header mh; fSoundOutput = &out; - while (!fStopAudioPlayback && B_OK == fAudioTrack->ReadFrames(buffer, &frames, &mh)) { - out.Play(buffer, frames * frame_size); + while (!fStopAudioPlayback) { + if (B_OK == fAudioTrack->ReadFrames(buffer, &frames, &mh)) { + out.Play(buffer, frames * frame_size); + UpdatePosition(mh.start_time / (float)Duration()); + } else { + snooze(50000); + } + if (fSeekAudio) { + bigtime_t pos = fSeekPosition; + fAudioTrack->SeekToTime(&pos); + fSeekAudio = false; + } } fSoundOutput = NULL; } diff --git a/src/apps/mediaplayer/Controller.h b/src/apps/mediaplayer/Controller.h index ac069edb5e..ff6714d225 100644 --- a/src/apps/mediaplayer/Controller.h +++ b/src/apps/mediaplayer/Controller.h @@ -29,6 +29,7 @@ class BMediaFile; class BMediaTrack; class SoundOutput; class VideoView; +class ControllerView; class Controller { @@ -55,6 +56,7 @@ public: bool IsPaused(); void SetVideoView(VideoView *view); + void SetControllerView(ControllerView *view); bool IsOverlayActive(); @@ -66,6 +68,11 @@ public: void VolumeDown(); void SetVolume(float value); + + void SetPosition(float value); + + void UpdateVolume(float value); + void UpdatePosition(float value); private: static int32 audio_play_thread(void *self); @@ -81,6 +88,7 @@ private: private: VideoView * fVideoView; + ControllerView * fControllerView; BString fName; bool fPaused; bool fStopped; @@ -99,6 +107,9 @@ private: volatile bool fStopAudioPlayback; volatile bool fStopVideoPlayback; SoundOutput * fSoundOutput; + volatile bool fSeekAudio; + volatile bool fSeekVideo; + volatile bigtime_t fSeekPosition; }; diff --git a/src/apps/mediaplayer/ControllerView.cpp b/src/apps/mediaplayer/ControllerView.cpp index 303864b4b9..5098cdfa29 100644 --- a/src/apps/mediaplayer/ControllerView.cpp +++ b/src/apps/mediaplayer/ControllerView.cpp @@ -152,5 +152,6 @@ ControllerView::PositionChanged(float value) { printf("ControllerView::PositionChanged(%.2f)\n", value); // 0.0 ... 1.0 + fController->SetPosition(value); } diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index 8b37e2add7..c1ae350ca2 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -140,6 +140,7 @@ MainWin::MainWin() // fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight); fController->SetVideoView(fVideoView); + fController->SetControllerView(fControls); fVideoView->IsOverlaySupported(); printf("fMenuBarHeight %d\n", fMenuBarHeight); diff --git a/src/apps/mediaplayer/TransportControlGroup.cpp b/src/apps/mediaplayer/TransportControlGroup.cpp index 9db616e66d..62845bf098 100644 --- a/src/apps/mediaplayer/TransportControlGroup.cpp +++ b/src/apps/mediaplayer/TransportControlGroup.cpp @@ -48,7 +48,7 @@ enum { #define kVolumeDbExpNegative 1.9 // for dB values < 0 #define kVolumeFactor 1000 -#define kPositionFactor 65535 +#define kPositionFactor 3000 // constructor TransportControlGroup::TransportControlGroup(BRect frame) @@ -320,6 +320,9 @@ TransportControlGroup::_GainToDb(float gain) void TransportControlGroup::SetEnabled(uint32 buttons) { +// if (B_OK != LockLooperWithTimeout(50000)) + if (!LockLooper()) + return; fSeekSlider->SetEnabled(buttons & SEEK_ENABLED); fVolumeSlider->SetEnabled(buttons & VOLUME_ENABLED); @@ -332,6 +335,7 @@ TransportControlGroup::SetEnabled(uint32 buttons) fPlayPause->SetEnabled(buttons & PLAYBACK_ENABLED); fStop->SetEnabled(buttons & PLAYBACK_ENABLED); + UnlockLooper(); } // #pragma mark - @@ -340,6 +344,9 @@ TransportControlGroup::SetEnabled(uint32 buttons) void TransportControlGroup::SetPlaybackState(uint32 state) { +// if (B_OK != LockLooperWithTimeout(50000)) + if (!LockLooper()) + return; switch (state) { case PLAYBACK_STATE_PLAYING: fPlayPause->SetPlaying(); @@ -351,14 +358,19 @@ TransportControlGroup::SetPlaybackState(uint32 state) fPlayPause->SetStopped(); break; } + UnlockLooper(); } // SetSkippable void TransportControlGroup::SetSkippable(bool backward, bool forward) { +// if (B_OK != LockLooperWithTimeout(50000)) + if (!LockLooper()) + return; fSkipBack->SetEnabled(backward); fSkipForward->SetEnabled(forward); + UnlockLooper(); } // #pragma mark - @@ -367,29 +379,43 @@ TransportControlGroup::SetSkippable(bool backward, bool forward) void TransportControlGroup::SetAudioEnabled(bool enabled) { +// if (B_OK != LockLooperWithTimeout(50000)) + if (!LockLooper()) + return; fMute->SetEnabled(enabled); fVolumeSlider->SetEnabled(enabled); + UnlockLooper(); } // SetMuted void TransportControlGroup::SetMuted(bool mute) { +// if (B_OK != LockLooperWithTimeout(50000)) + if (!LockLooper()) + return; fVolumeSlider->SetMuted(mute); + UnlockLooper(); } void TransportControlGroup::SetVolume(float value) { + if (B_OK != LockLooperWithTimeout(50000)) + return; fVolumeSlider->SetValue(_DbToGain(_ExponentialToLinear(_GainToDb(value))) * kVolumeFactor); + UnlockLooper(); } void TransportControlGroup::SetPosition(float value) { + if (B_OK != LockLooperWithTimeout(50000)) + return; fSeekSlider->SetPosition(value); + UnlockLooper(); }