implemented seeking and position update

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17378 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen 2006-05-08 21:47:19 +00:00
parent 3b55bd0c3c
commit 0f0bbc9751
5 changed files with 94 additions and 4 deletions

View File

@ -25,6 +25,7 @@
#include <MediaTrack.h> #include <MediaTrack.h>
#include "Controller.h" #include "Controller.h"
#include "ControllerView.h"
#include "VideoView.h" #include "VideoView.h"
#include "SoundOutput.h" #include "SoundOutput.h"
@ -45,6 +46,7 @@ HandleError(const char *text, status_t err)
Controller::Controller() Controller::Controller()
: fVideoView(NULL) : fVideoView(NULL)
, fControllerView(NULL)
, fName() , fName()
, fPaused(false) , fPaused(false)
, fStopped(true) , fStopped(true)
@ -61,6 +63,9 @@ Controller::Controller()
, fStopAudioPlayback(false) , fStopAudioPlayback(false)
, fStopVideoPlayback(false) , fStopVideoPlayback(false)
, fSoundOutput(NULL) , 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 status_t
Controller::SetTo(const entry_ref &ref) Controller::SetTo(const entry_ref &ref)
{ {
@ -221,7 +233,7 @@ Controller::Duration()
{ {
bigtime_t a = fAudioTrack ? fAudioTrack->Duration() : 0; bigtime_t a = fAudioTrack ? fAudioTrack->Duration() : 0;
bigtime_t v = fVideoTrack ? fVideoTrack->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); return max_c(a, v);
} }
@ -255,11 +267,36 @@ Controller::VolumeDown()
void void
Controller::SetVolume(float value) Controller::SetVolume(float value)
{ {
printf("Controller::SetVolume %.4f\n", value);
if (fSoundOutput) // hack... if (fSoundOutput) // hack...
fSoundOutput->SetVolume(value); 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 bool
Controller::IsOverlayActive() Controller::IsOverlayActive()
{ {
@ -365,14 +402,28 @@ Controller::AudioPlayThread()
SoundOutput out(fName.String(), fmt.u.raw_audio); 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; int frame_size = (fmt.u.raw_audio.format & 0xf) * fmt.u.raw_audio.channel_count;
uint8 buffer[fmt.u.raw_audio.buffer_size]; uint8 buffer[fmt.u.raw_audio.buffer_size];
int64 frames; int64 frames;
media_header mh; media_header mh;
fSoundOutput = &out; fSoundOutput = &out;
while (!fStopAudioPlayback && B_OK == fAudioTrack->ReadFrames(buffer, &frames, &mh)) { while (!fStopAudioPlayback) {
if (B_OK == fAudioTrack->ReadFrames(buffer, &frames, &mh)) {
out.Play(buffer, frames * frame_size); 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; fSoundOutput = NULL;
} }

View File

@ -29,6 +29,7 @@ class BMediaFile;
class BMediaTrack; class BMediaTrack;
class SoundOutput; class SoundOutput;
class VideoView; class VideoView;
class ControllerView;
class Controller class Controller
{ {
@ -55,6 +56,7 @@ public:
bool IsPaused(); bool IsPaused();
void SetVideoView(VideoView *view); void SetVideoView(VideoView *view);
void SetControllerView(ControllerView *view);
bool IsOverlayActive(); bool IsOverlayActive();
@ -67,6 +69,11 @@ public:
void SetVolume(float value); void SetVolume(float value);
void SetPosition(float value);
void UpdateVolume(float value);
void UpdatePosition(float value);
private: private:
static int32 audio_play_thread(void *self); static int32 audio_play_thread(void *self);
static int32 video_play_thread(void *self); static int32 video_play_thread(void *self);
@ -81,6 +88,7 @@ private:
private: private:
VideoView * fVideoView; VideoView * fVideoView;
ControllerView * fControllerView;
BString fName; BString fName;
bool fPaused; bool fPaused;
bool fStopped; bool fStopped;
@ -99,6 +107,9 @@ private:
volatile bool fStopAudioPlayback; volatile bool fStopAudioPlayback;
volatile bool fStopVideoPlayback; volatile bool fStopVideoPlayback;
SoundOutput * fSoundOutput; SoundOutput * fSoundOutput;
volatile bool fSeekAudio;
volatile bool fSeekVideo;
volatile bigtime_t fSeekPosition;
}; };

View File

@ -152,5 +152,6 @@ ControllerView::PositionChanged(float value)
{ {
printf("ControllerView::PositionChanged(%.2f)\n", value); printf("ControllerView::PositionChanged(%.2f)\n", value);
// 0.0 ... 1.0 // 0.0 ... 1.0
fController->SetPosition(value);
} }

View File

@ -140,6 +140,7 @@ MainWin::MainWin()
// fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight); // fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight);
fController->SetVideoView(fVideoView); fController->SetVideoView(fVideoView);
fController->SetControllerView(fControls);
fVideoView->IsOverlaySupported(); fVideoView->IsOverlaySupported();
printf("fMenuBarHeight %d\n", fMenuBarHeight); printf("fMenuBarHeight %d\n", fMenuBarHeight);

View File

@ -48,7 +48,7 @@ enum {
#define kVolumeDbExpNegative 1.9 // for dB values < 0 #define kVolumeDbExpNegative 1.9 // for dB values < 0
#define kVolumeFactor 1000 #define kVolumeFactor 1000
#define kPositionFactor 65535 #define kPositionFactor 3000
// constructor // constructor
TransportControlGroup::TransportControlGroup(BRect frame) TransportControlGroup::TransportControlGroup(BRect frame)
@ -320,6 +320,9 @@ TransportControlGroup::_GainToDb(float gain)
void void
TransportControlGroup::SetEnabled(uint32 buttons) TransportControlGroup::SetEnabled(uint32 buttons)
{ {
// if (B_OK != LockLooperWithTimeout(50000))
if (!LockLooper())
return;
fSeekSlider->SetEnabled(buttons & SEEK_ENABLED); fSeekSlider->SetEnabled(buttons & SEEK_ENABLED);
fVolumeSlider->SetEnabled(buttons & VOLUME_ENABLED); fVolumeSlider->SetEnabled(buttons & VOLUME_ENABLED);
@ -332,6 +335,7 @@ TransportControlGroup::SetEnabled(uint32 buttons)
fPlayPause->SetEnabled(buttons & PLAYBACK_ENABLED); fPlayPause->SetEnabled(buttons & PLAYBACK_ENABLED);
fStop->SetEnabled(buttons & PLAYBACK_ENABLED); fStop->SetEnabled(buttons & PLAYBACK_ENABLED);
UnlockLooper();
} }
// #pragma mark - // #pragma mark -
@ -340,6 +344,9 @@ TransportControlGroup::SetEnabled(uint32 buttons)
void void
TransportControlGroup::SetPlaybackState(uint32 state) TransportControlGroup::SetPlaybackState(uint32 state)
{ {
// if (B_OK != LockLooperWithTimeout(50000))
if (!LockLooper())
return;
switch (state) { switch (state) {
case PLAYBACK_STATE_PLAYING: case PLAYBACK_STATE_PLAYING:
fPlayPause->SetPlaying(); fPlayPause->SetPlaying();
@ -351,14 +358,19 @@ TransportControlGroup::SetPlaybackState(uint32 state)
fPlayPause->SetStopped(); fPlayPause->SetStopped();
break; break;
} }
UnlockLooper();
} }
// SetSkippable // SetSkippable
void void
TransportControlGroup::SetSkippable(bool backward, bool forward) TransportControlGroup::SetSkippable(bool backward, bool forward)
{ {
// if (B_OK != LockLooperWithTimeout(50000))
if (!LockLooper())
return;
fSkipBack->SetEnabled(backward); fSkipBack->SetEnabled(backward);
fSkipForward->SetEnabled(forward); fSkipForward->SetEnabled(forward);
UnlockLooper();
} }
// #pragma mark - // #pragma mark -
@ -367,29 +379,43 @@ TransportControlGroup::SetSkippable(bool backward, bool forward)
void void
TransportControlGroup::SetAudioEnabled(bool enabled) TransportControlGroup::SetAudioEnabled(bool enabled)
{ {
// if (B_OK != LockLooperWithTimeout(50000))
if (!LockLooper())
return;
fMute->SetEnabled(enabled); fMute->SetEnabled(enabled);
fVolumeSlider->SetEnabled(enabled); fVolumeSlider->SetEnabled(enabled);
UnlockLooper();
} }
// SetMuted // SetMuted
void void
TransportControlGroup::SetMuted(bool mute) TransportControlGroup::SetMuted(bool mute)
{ {
// if (B_OK != LockLooperWithTimeout(50000))
if (!LockLooper())
return;
fVolumeSlider->SetMuted(mute); fVolumeSlider->SetMuted(mute);
UnlockLooper();
} }
void void
TransportControlGroup::SetVolume(float value) TransportControlGroup::SetVolume(float value)
{ {
if (B_OK != LockLooperWithTimeout(50000))
return;
fVolumeSlider->SetValue(_DbToGain(_ExponentialToLinear(_GainToDb(value))) * kVolumeFactor); fVolumeSlider->SetValue(_DbToGain(_ExponentialToLinear(_GainToDb(value))) * kVolumeFactor);
UnlockLooper();
} }
void void
TransportControlGroup::SetPosition(float value) TransportControlGroup::SetPosition(float value)
{ {
if (B_OK != LockLooperWithTimeout(50000))
return;
fSeekSlider->SetPosition(value); fSeekSlider->SetPosition(value);
UnlockLooper();
} }