* Added the implementation behind the "Use overlays if available" and "Scale

videos smoothly in non-overlay mode" options.
* Disabled the other controls in the SettingsWindow which are not yet
  implemented.
* Enable and disable Revert button according to settings state.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27157 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-08-22 16:43:35 +00:00
parent 757f253a2d
commit 613ecaf5f9
10 changed files with 150 additions and 33 deletions
+12 -5
View File
@@ -101,6 +101,7 @@ Controller::Controller()
, fDuration(0)
, fVideoFrameRate(25.0)
, fSeekFrame(-1)
, fLastSeekEventTime(LONGLONG_MIN)
, fAutoplay(true)
, fPauseAtEndOfStream(false)
@@ -269,6 +270,8 @@ Controller::SetTo(const entry_ref &ref)
fVideoView->DisableOverlay();
// get video properties (if there is video at all)
bool useOverlays = fVideoView ? fVideoView->UseOverlays() : true;
int width;
int height;
GetSize(&width, &height);
@@ -288,10 +291,11 @@ Controller::SetTo(const entry_ref &ref)
if (InitCheck() != B_OK) {
Init(BRect(0, 0, width - 1, height - 1), fVideoFrameRate,
preferredVideoFormat, LOOPING_ALL, false, 1.0, enabledNodes);
preferredVideoFormat, LOOPING_ALL, false, 1.0, enabledNodes,
useOverlays);
} else {
FormatChanged(BRect(0, 0, width - 1, height - 1), fVideoFrameRate,
preferredVideoFormat, enabledNodes);
preferredVideoFormat, enabledNodes, useOverlays);
}
_NotifyFileChanged();
@@ -578,9 +582,10 @@ Controller::SetPosition(float value)
fSeekFrame = (int32)(Duration() * value);
int32 currentFrame = CurrentFrame();
if (fSeekFrame != currentFrame)
if (fSeekFrame != currentFrame) {
SetCurrentFrame(fSeekFrame);
else
fLastSeekEventTime = system_time();
} else
fSeekFrame = -1;
// TODO: What was this used for in the old framework?
@@ -916,8 +921,10 @@ Controller::NotifyCurrentFrameChanged(int32 frame) const
{
// check if we are still waiting to reach the seekframe,
// don't pass the event on to the listeners in that case
if (fSeekFrame >= 0 && frame != fSeekFrame)
if ((system_time() - fLastSeekEventTime) < 1000000
&& fSeekFrame >= 0 && frame != fSeekFrame) {
return;
}
fSeekFrame = -1;
float position = 0.0;
+1
View File
@@ -175,6 +175,7 @@ private:
bigtime_t fDuration;
float fVideoFrameRate;
mutable int32 fSeekFrame;
bigtime_t fLastSeekEventTime;
bool fAutoplay;
volatile bool fPauseAtEndOfStream;
+58 -6
View File
@@ -8,10 +8,13 @@
#include <Bitmap.h>
#include "Settings.h"
VideoView::VideoView(BRect frame, const char* name, uint32 resizeMask)
: BView(frame, name, resizeMask, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fOverlayMode(false)
fOverlayMode(false),
fGlobalSettingsListener(this)
{
SetViewColor(B_TRANSPARENT_COLOR);
// might be reset to overlay key color if overlays are used
@@ -22,11 +25,15 @@ VideoView::VideoView(BRect frame, const char* name, uint32 resizeMask)
fOverlayRestrictions.max_width_scale = 8.0;
fOverlayRestrictions.min_height_scale = 0.25;
fOverlayRestrictions.max_height_scale = 8.0;
Settings::Default()->AddListener(&fGlobalSettingsListener);
_AdoptGlobalSettings();
}
VideoView::~VideoView()
{
Settings::Default()->RemoveListener(&fGlobalSettingsListener);
}
@@ -36,11 +43,10 @@ VideoView::Draw(BRect updateRect)
bool fillBlack = true;
if (LockBitmap()) {
BRect r(Bounds());
if (const BBitmap* bitmap = GetBitmap()) {
fillBlack = false;
if (!fOverlayMode)
DrawBitmap(bitmap, bitmap->Bounds(), r);
_DrawBitmap(bitmap);
}
UnlockBitmap();
}
@@ -50,6 +56,21 @@ VideoView::Draw(BRect updateRect)
}
void
VideoView::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_OBJECT_CHANGED:
// TODO: find out which object, if we ever watch more than
// the global settings instance...
_AdoptGlobalSettings();
break;
default:
BView::MessageReceived(message);
}
}
void
VideoView::SetBitmap(const BBitmap* bitmap)
{
@@ -60,8 +81,7 @@ VideoView::SetBitmap(const BBitmap* bitmap)
// -> Window).
if (bitmap && LockLooperWithTimeout(10000) == B_OK) {
if (LockBitmap()) {
// if (fOverlayMode || bitmap->Flags() & B_BITMAP_WILL_OVERLAY) {
if (fOverlayMode || bitmap->ColorSpace() == B_YCbCr422) {
if (fOverlayMode || (bitmap->Flags() & B_BITMAP_WILL_OVERLAY)) {
if (!fOverlayMode) {
// init overlay
rgb_color key;
@@ -104,7 +124,7 @@ VideoView::SetBitmap(const BBitmap* bitmap)
SetViewColor(B_TRANSPARENT_COLOR);
}
if (!fOverlayMode)
DrawBitmap(bitmap, bitmap->Bounds(), Bounds());
_DrawBitmap(bitmap);
UnlockBitmap();
}
@@ -140,6 +160,13 @@ VideoView::OverlayScreenshotCleanup()
}
bool
VideoView::UseOverlays() const
{
return fUseOverlays;
}
bool
VideoView::IsOverlayActive()
{
@@ -167,3 +194,28 @@ VideoView::DisableOverlay()
fOverlayMode = false;
}
// #pragma mark -
void
VideoView::_DrawBitmap(const BBitmap* bitmap)
{
#ifdef __HAIKU__
uint32 options = fUseBilinearScaling ? B_FILTER_BITMAP_BILINEAR : 0;
DrawBitmap(bitmap, bitmap->Bounds(), Bounds(), options);
#else
DrawBitmap(bitmap, bitmap->Bounds(), Bounds());
#endif
}
void
VideoView::_AdoptGlobalSettings()
{
mpSettings settings = Settings::CurrentSettings();
fUseOverlays = settings.useOverlays;
fUseBilinearScaling = settings.scaleBilinear;
}
+10
View File
@@ -8,6 +8,7 @@
#include <View.h>
#include "ListenerAdapter.h"
#include "VideoTarget.h"
@@ -19,6 +20,7 @@ public:
// BView interface
virtual void Draw(BRect updateRect);
virtual void MessageReceived(BMessage* message);
// VideoTarget interface
virtual void SetBitmap(const BBitmap* bitmap);
@@ -30,13 +32,21 @@ public:
void OverlayScreenshotPrepare();
void OverlayScreenshotCleanup();
bool UseOverlays() const;
bool IsOverlayActive();
void DisableOverlay();
private:
void _DrawBitmap(const BBitmap* bitmap);
void _AdoptGlobalSettings();
bool fOverlayMode;
overlay_restrictions fOverlayRestrictions;
rgb_color fOverlayKeyColor;
ListenerAdapter fGlobalSettingsListener;
bool fUseOverlays;
bool fUseBilinearScaling;
};
#endif // VIDEO_VIEW_H
@@ -67,7 +67,7 @@ NodeManager::~NodeManager()
status_t
NodeManager::Init(BRect videoBounds, float videoFrameRate,
color_space preferredVideoFormat, int32 loopingMode,
bool loopingEnabled, float speed, uint32 enabledNodes)
bool loopingEnabled, float speed, uint32 enabledNodes, bool useOverlays)
{
// init base class
PlaybackManager::Init(videoFrameRate, loopingMode, loopingEnabled, speed);
@@ -83,7 +83,7 @@ NodeManager::Init(BRect videoBounds, float videoFrameRate,
fAudioSupplier = CreateAudioSupplier();
return FormatChanged(videoBounds, videoFrameRate, preferredVideoFormat,
enabledNodes, true);
enabledNodes, useOverlays, true);
}
// InitCheck
@@ -118,7 +118,8 @@ NodeManager::CleanupNodes()
// FormatChanged
status_t
NodeManager::FormatChanged(BRect videoBounds, float videoFrameRate,
color_space preferredVideoFormat, uint32 enabledNodes, bool force)
color_space preferredVideoFormat, uint32 enabledNodes, bool useOverlays,
bool force)
{
TRACE("NodeManager::FormatChanged()\n");
@@ -142,7 +143,8 @@ NodeManager::FormatChanged(BRect videoBounds, float videoFrameRate,
SetVideoBounds(videoBounds);
status_t ret = _SetUpNodes(preferredVideoFormat, enabledNodes);
status_t ret = _SetUpNodes(preferredVideoFormat, enabledNodes,
useOverlays);
if (ret == B_OK)
_StartNodes();
else
@@ -250,7 +252,8 @@ NodeManager::SetPeakListener(BHandler* handler)
// _SetUpNodes
status_t
NodeManager::_SetUpNodes(color_space preferredVideoFormat, uint32 enabledNodes)
NodeManager::_SetUpNodes(color_space preferredVideoFormat, uint32 enabledNodes,
bool useOverlays)
{
TRACE("NodeManager::_SetUpNodes()\n");
@@ -275,7 +278,7 @@ NodeManager::_SetUpNodes(color_space preferredVideoFormat, uint32 enabledNodes)
// setup the video nodes
if (enabledNodes != AUDIO_ONLY) {
fStatus = _SetUpVideoNodes(preferredVideoFormat);
fStatus = _SetUpVideoNodes(preferredVideoFormat, useOverlays);
if (fStatus != B_OK) {
print_error("Error setting up video nodes", fStatus);
fMediaRoster->Unlock();
@@ -307,7 +310,8 @@ fNoAudio = true;
// _SetUpVideoNodes
status_t
NodeManager::_SetUpVideoNodes(color_space preferredVideoFormat)
NodeManager::_SetUpVideoNodes(color_space preferredVideoFormat,
bool useOverlays)
{
// create the video producer node
fVideoProducer = new VideoProducer(NULL, "MediaPlayer Video Out", 0,
@@ -381,7 +385,7 @@ NodeManager::_SetUpVideoNodes(color_space preferredVideoFormat)
format.u.raw_video = videoFormat;
// connect video producer to consumer (hopefully using overlays)
fVideoConsumer->SetTryOverlay(true);
fVideoConsumer->SetTryOverlay(useOverlays);
fStatus = fMediaRoster->Connect(videoOutput.source, videoInput.destination,
&format, &videoOutput, &videoInput);
@@ -40,10 +40,11 @@ class NodeManager : public PlaybackManager {
status_t Init(BRect videoBounds, float videoFrameRate,
color_space preferredVideoFormat,
int32 loopingMode = LOOPING_ALL,
bool loopingEnabled = true,
float speed = 1.0,
uint32 enabledNodes = AUDIO_AND_VIDEO);
int32 loopingMode,
bool loopingEnabled,
float speed,
uint32 enabledNodes,
bool useOverlays);
status_t InitCheck();
// only call this if the
// media_server has died!
@@ -52,7 +53,8 @@ class NodeManager : public PlaybackManager {
status_t FormatChanged(BRect videoBounds,
float videoFrameRate,
color_space preferredVideoFormat,
uint32 enabledNodes = AUDIO_AND_VIDEO,
uint32 enabledNodes,
bool useOverlays,
bool force = false);
virtual void SetPlayMode(int32 mode,
bool continuePlaying = true);
@@ -74,9 +76,10 @@ class NodeManager : public PlaybackManager {
private:
status_t _SetUpNodes(color_space preferredVideoFormat,
uint32 enabledNodes);
uint32 enabledNodes, bool useOverlays);
status_t _SetUpVideoNodes(
color_space preferredVideoFormat);
color_space preferredVideoFormat,
bool useOverlays);
status_t _SetUpAudioNodes();
status_t _TearDownNodes(bool disconnect = true);
status_t _StartNodes();
+17 -1
View File
@@ -11,6 +11,20 @@
#include <Autolock.h>
bool
mpSettings::operator!=(const mpSettings& other) const
{
return autostart != other.autostart
|| closeWhenDonePlayingMovie != other.closeWhenDonePlayingMovie
|| closeWhenDonePlayingSound != other.closeWhenDonePlayingSound
|| loopMovie != other.loopMovie
|| loopSound != other.loopSound
|| useOverlays != other.useOverlays
|| scaleBilinear != other.scaleBilinear
|| backgroundMovieVolumeMode != other.backgroundMovieVolumeMode;
}
Settings::Settings(const char* filename)
: BLocker("settings lock"),
fSettingsMessage(B_USER_CONFIG_DIRECTORY, filename)
@@ -36,7 +50,7 @@ Settings::LoadSettings(mpSettings& settings) const
settings.backgroundMovieVolumeMode
= fSettingsMessage.GetValue("bgMovieVolumeMode",
(uint32)mpSettings::BG_MOVIES_MUTED);
(uint32)mpSettings::BG_MOVIES_FULL_VOLUME);
}
@@ -63,6 +77,8 @@ Settings::SaveSettings(const mpSettings& settings)
// this will make sure the settings are saved even when the player
// crashes.
fSettingsMessage.Save();
Notify();
}
+5 -1
View File
@@ -11,6 +11,7 @@
#include <Locker.h>
#include "Notifier.h"
#include "SettingsMessage.h"
struct mpSettings {
@@ -27,11 +28,13 @@ struct mpSettings {
BG_MOVIES_MUTED = 2
};
uint32 backgroundMovieVolumeMode;
bool operator!=(const mpSettings& other) const;
};
#define SETTINGS_FILENAME "MediaPlayerSettings"
class Settings : public BLocker {
class Settings : public BLocker, public Notifier {
public:
Settings(
const char* filename = SETTINGS_FILENAME);
@@ -44,6 +47,7 @@ public:
private:
SettingsMessage fSettingsMessage;
BList fListeners;
static Settings sGlobalInstance;
};
@@ -110,7 +110,7 @@ SettingsWindow::SettingsWindow(BRect frame)
fMutedVolumeBGMoviesRB = new BRadioButton("rdbtnfullvolume",
"Muted", new BMessage(M_START_MUTE_VOLUME));
BButton* revertButton = new BButton("revert", "Revert",
fRevertB = new BButton("revert", "Revert",
new BMessage(M_SETTINGS_REVERT));
BButton* cancelButton = new BButton("cancel", "Cancel",
@@ -167,7 +167,7 @@ SettingsWindow::SettingsWindow(BRect frame)
.SetInsets(5, 5, 15, 5)
)
.Add(BGroupLayoutBuilder(buttonLayout)
.Add(revertButton)
.Add(fRevertB)
.AddGlue()
.Add(cancelButton)
.Add(okButton)
@@ -175,9 +175,8 @@ SettingsWindow::SettingsWindow(BRect frame)
)
);
#else
frame = Bounds();
BView* view = new BView(frame,"SettingsView",B_FOLLOW_ALL_SIDES,B_WILL_DRAW);
view->SetViewColor(216, 216, 216);
@@ -251,8 +250,16 @@ SettingsWindow::SettingsWindow(BRect frame)
#endif
// disable currently unsupported features
fAutostartCB->SetEnabled(false);
fCloseWindowMoviesCB->SetEnabled(false);
fCloseWindowSoundsCB->SetEnabled(false);
fLoopMoviesCB->SetEnabled(false);
fLoopSoundsCB->SetEnabled(false);
fFullVolumeBGMoviesRB->SetEnabled(false);
fHalfVolumeBGMoviesRB->SetEnabled(false);
fMutedVolumeBGMoviesRB->SetEnabled(false);
}
@@ -339,6 +346,8 @@ SettingsWindow::AdoptSettings()
== mpSettings::BG_MOVIES_HALF_VLUME);
fMutedVolumeBGMoviesRB->SetValue(fSettings.backgroundMovieVolumeMode
== mpSettings::BG_MOVIES_MUTED);
fRevertB->SetEnabled(IsRevertable());
}
@@ -368,6 +377,8 @@ SettingsWindow::ApplySettings()
}
Settings::Default()->SaveSettings(fSettings);
fRevertB->SetEnabled(IsRevertable());
}
@@ -379,3 +390,10 @@ SettingsWindow::Revert()
Settings::Default()->SaveSettings(fSettings);
}
bool
SettingsWindow::IsRevertable() const
{
return fSettings != fLastSettings;
}
@@ -27,7 +27,7 @@ public:
void AdoptSettings();
void ApplySettings();
void Revert();
bool IsRevertable();
bool IsRevertable() const;
private:
mpSettings fSettings;
@@ -45,6 +45,8 @@ private:
BRadioButton* fFullVolumeBGMoviesRB;
BRadioButton* fHalfVolumeBGMoviesRB;
BRadioButton* fMutedVolumeBGMoviesRB;
BButton* fRevertB;
};
#endif