Prepare the MediaPlayer to survive a media_server restart, by first
making it detect the quit/start of the media_server and media_addon_server. No action is currently taken in response to this, but the SoundOutput used by the Controller needs to be recreated I would think. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24573 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
* MainApp.cpp - Media Player for the Haiku Operating System
|
* MainApp.cpp - Media Player for the Haiku Operating System
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006 Marcus Overhagen <[email protected]>
|
* Copyright (C) 2006 Marcus Overhagen <[email protected]>
|
||||||
|
* Copyright (C) 2008 Stephan Aßmus <[email protected]>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
@@ -17,21 +18,32 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <Path.h>
|
#include "MainApp.h"
|
||||||
#include <Entry.h>
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
#include <unistd.h>
|
#include <Entry.h>
|
||||||
#include <stdio.h>
|
#include <MediaRoster.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <Roster.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "MainApp.h"
|
|
||||||
|
|
||||||
MainApp *gMainApp;
|
MainApp *gMainApp;
|
||||||
|
|
||||||
|
static const char* kMediaServerSig = "application/x-vnd.Be.media-server";
|
||||||
|
static const char* kMediaServerAddOnSig = "application/x-vnd.Be.addon-host";
|
||||||
|
|
||||||
|
|
||||||
MainApp::MainApp()
|
MainApp::MainApp()
|
||||||
: BApplication("application/x-vnd.Haiku-MediaPlayer"),
|
: BApplication("application/x-vnd.Haiku-MediaPlayer"),
|
||||||
fPlayerCount(0),
|
fPlayerCount(0),
|
||||||
fFirstWindow(NewWindow())
|
fFirstWindow(NewWindow()),
|
||||||
|
|
||||||
|
fMediaServerRunning(false),
|
||||||
|
fMediaAddOnServerRunning(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +62,21 @@ MainApp::NewWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MainApp::ReadyToRun()
|
||||||
|
{
|
||||||
|
// Now tell the application roster, that we're interested
|
||||||
|
// in getting notifications of apps being launched or quit.
|
||||||
|
// In this way we are going to detect a media_server restart.
|
||||||
|
be_roster->StartWatching(BMessenger(this, this),
|
||||||
|
B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
|
||||||
|
// we will keep track of the status of media_server
|
||||||
|
// and media_addon_server
|
||||||
|
fMediaServerRunning = be_roster->IsRunning(kMediaServerSig);
|
||||||
|
fMediaAddOnServerRunning = be_roster->IsRunning(kMediaServerAddOnSig);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MainApp::RefsReceived(BMessage *msg)
|
MainApp::RefsReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
@@ -106,17 +133,65 @@ MainApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MainApp::MessageReceived(BMessage *msg)
|
MainApp::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (message->what) {
|
||||||
case M_PLAYER_QUIT:
|
case M_PLAYER_QUIT:
|
||||||
fPlayerCount--;
|
fPlayerCount--;
|
||||||
if (fPlayerCount == 0)
|
if (fPlayerCount == 0)
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case B_SOME_APP_LAUNCHED:
|
||||||
|
case B_SOME_APP_QUIT:
|
||||||
|
{
|
||||||
|
const char* mimeSig;
|
||||||
|
if (message->FindString("be:signature", &mimeSig) < B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
bool isMediaServer = strcmp(mimeSig, kMediaServerSig) == 0;
|
||||||
|
bool isAddonServer = strcmp(mimeSig, kMediaServerAddOnSig) == 0;
|
||||||
|
if (!isMediaServer && !isAddonServer)
|
||||||
|
break;
|
||||||
|
|
||||||
|
bool running = (message->what == B_SOME_APP_LAUNCHED);
|
||||||
|
if (isMediaServer)
|
||||||
|
fMediaServerRunning = running;
|
||||||
|
if (isAddonServer)
|
||||||
|
fMediaAddOnServerRunning = running;
|
||||||
|
|
||||||
|
if (!fMediaServerRunning && !fMediaAddOnServerRunning) {
|
||||||
|
fprintf(stderr, "media server has quit.\n");
|
||||||
|
// trigger closing of media nodes
|
||||||
|
BMessage broadcast(M_MEDIA_SERVER_QUIT);
|
||||||
|
_BroadcastMessage(broadcast);
|
||||||
|
} else if (fMediaServerRunning && fMediaAddOnServerRunning) {
|
||||||
|
fprintf(stderr, "media server has launched.\n");
|
||||||
|
// HACK!
|
||||||
|
// quit our now invalid instance of the media roster
|
||||||
|
// so that before new nodes are created,
|
||||||
|
// we get a new roster (it is a normal looper)
|
||||||
|
// TODO: This functionality could become part of
|
||||||
|
// BMediaRoster. It could detect the start/quit of
|
||||||
|
// the servers like it is done here, and either quit
|
||||||
|
// itself, or re-establish the connection, and send some
|
||||||
|
// notification to the app... something along those lines.
|
||||||
|
BMediaRoster* roster = BMediaRoster::CurrentRoster();
|
||||||
|
if (roster) {
|
||||||
|
roster->Lock();
|
||||||
|
roster->Quit();
|
||||||
|
}
|
||||||
|
// give the servers some time to init...
|
||||||
|
snooze(3000000);
|
||||||
|
// trigger re-init of media nodes
|
||||||
|
BMessage broadcast(M_MEDIA_SERVER_STARTED);
|
||||||
|
_BroadcastMessage(broadcast);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BApplication::MessageReceived(msg);
|
BApplication::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,6 +204,19 @@ MainApp::AboutRequested()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MainApp::_BroadcastMessage(const BMessage& _message)
|
||||||
|
{
|
||||||
|
for (int32 i = 0; BWindow* window = WindowAt(i); i++) {
|
||||||
|
BMessage message(_message);
|
||||||
|
window->PostMessage(&message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
* MainApp.h - Media Player for the Haiku Operating System
|
* MainApp.h - Media Player for the Haiku Operating System
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006 Marcus Overhagen <[email protected]>
|
* Copyright (C) 2006 Marcus Overhagen <[email protected]>
|
||||||
|
* Copyright (C) 2008 Stephan Aßmus <[email protected]>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
@@ -24,7 +25,10 @@
|
|||||||
#include "MainWin.h"
|
#include "MainWin.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
M_PLAYER_QUIT = 'plqt',
|
M_PLAYER_QUIT = 'plqt',
|
||||||
|
|
||||||
|
M_MEDIA_SERVER_STARTED = 'msst',
|
||||||
|
M_MEDIA_SERVER_QUIT = 'msqt'
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainApp : public BApplication {
|
class MainApp : public BApplication {
|
||||||
@@ -35,14 +39,20 @@ public:
|
|||||||
BWindow* NewWindow();
|
BWindow* NewWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void ReadyToRun();
|
||||||
virtual void RefsReceived(BMessage* message);
|
virtual void RefsReceived(BMessage* message);
|
||||||
virtual void ArgvReceived(int32 argc, char** argv);
|
virtual void ArgvReceived(int32 argc, char** argv);
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual void AboutRequested();
|
virtual void AboutRequested();
|
||||||
|
|
||||||
|
void _BroadcastMessage(const BMessage& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 fPlayerCount;
|
int32 fPlayerCount;
|
||||||
BWindow* fFirstWindow;
|
BWindow* fFirstWindow;
|
||||||
|
|
||||||
|
bool fMediaServerRunning;
|
||||||
|
bool fMediaAddOnServerRunning;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MainApp* gMainApp;
|
extern MainApp* gMainApp;
|
||||||
|
|||||||
@@ -328,6 +328,14 @@ MainWin::MessageReceived(BMessage *msg)
|
|||||||
_RefsReceived(msg);
|
_RefsReceived(msg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case M_MEDIA_SERVER_STARTED:
|
||||||
|
// fController->...
|
||||||
|
break;
|
||||||
|
|
||||||
|
case M_MEDIA_SERVER_QUIT:
|
||||||
|
// fController->...
|
||||||
|
break;
|
||||||
|
|
||||||
// PlaylistObserver messages
|
// PlaylistObserver messages
|
||||||
case MSG_PLAYLIST_REF_ADDED: {
|
case MSG_PLAYLIST_REF_ADDED: {
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
|
|||||||
Reference in New Issue
Block a user