hrev50183 adds 6 changesets to branch 'master'
old head: 6501f7fb632dd22683c393d152946f83bd8e03ea
new head: a0b3904a33dc5566e404a87fee827c06e7f92e6b
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=a0b3904a33dc+%5E6501f7fb632d
----------------------------------------------------------------------------
1199f321eaf0: media_server: Initial move to BServer
77c6944c0246: NodeManager: Use boolean expression
866084f7a922: MediaPrefs: No need to start media services anymore
* This will cause troubles as the launch_daemon is
doing this job for us.
53c3fa513774: Introduce functionality for syncing with the media services
* The global synchro semaphore is provided with the purpose of
being used to avoid threads lock up when the media_server is in
an undefined state. There's still room for improvements.
* BMediaRoster::SyncToServices lock up on a semaphore until
the multi_audio correctly connected to the mixer.
c131229f0800: media_server: Add notifications
a0b3904a33dc: launch_media_server: Remove notifications handled elsewhere
[ Dario Casalinuovo <b.vitruvio@xxxxxxxxx> ]
----------------------------------------------------------------------------
12 files changed, 96 insertions(+), 22 deletions(-)
headers/os/media/MediaRoster.h | 6 ++++-
headers/private/media/MediaMisc.h | 13 +++++++++++
headers/private/media/ServerInterface.h | 4 ++++
src/kits/media/MediaDefs.cpp | 3 ---
src/kits/media/MediaRoster.cpp | 24 +++++++++++++++++++
src/preferences/media/MediaWindow.cpp | 1 -
src/servers/media/AppManager.cpp | 15 +++++++++++-
src/servers/media/AppManager.h | 5 +++-
src/servers/media/DefaultManager.cpp | 7 +++++-
src/servers/media/Jamfile | 2 +-
src/servers/media/NodeManager.cpp | 2 +-
src/servers/media/media_server.cpp | 36 +++++++++++++++++++----------
############################################################################
Commit: 1199f321eaf064d8be34512e4cb6b6cf136ede99
URL: http://cgit.haiku-os.org/haiku/commit/?id=1199f321eaf0
Author: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date: Fri Apr 1 14:46:13 2016 UTC
media_server: Initial move to BServer
----------------------------------------------------------------------------
diff --git a/src/servers/media/Jamfile b/src/servers/media/Jamfile
index c5edb71..aa638ee 100644
--- a/src/servers/media/Jamfile
+++ b/src/servers/media/Jamfile
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src servers media ;
SetSubDirSupportedPlatformsBeOSCompatible ;
-UsePrivateHeaders media shared storage ;
+UsePrivateHeaders media shared storage app ;
UsePrivateSystemHeaders ;
AddResources media_server : media_server.rdef ;
diff --git a/src/servers/media/media_server.cpp
b/src/servers/media/media_server.cpp
index f4d7dd6..9ed51d5 100644
--- a/src/servers/media/media_server.cpp
+++ b/src/servers/media/media_server.cpp
@@ -37,7 +37,7 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c)
2002, 2003 "
#include <string.h>
#include <Alert.h>
-#include <Application.h>
+#include <Server.h>
#include <Autolock.h>
#include <Directory.h>
#include <Roster.h>
@@ -69,10 +69,10 @@ NotificationManager* gNotificationManager;
#define REPLY_TIMEOUT ((bigtime_t)500000)
-class ServerApp : BApplication {
+class ServerApp : public BServer {
public:
- ServerApp();
- ~ServerApp();
+
ServerApp(status_t& error);
+ virtual ~ServerApp();
protected:
virtual void ArgvReceived(int32 argc, char**
argv);
@@ -89,7 +89,7 @@ private:
private:
port_id _ControlPort() const {
return fControlPort; }
- static int32 _ControlThread(void* arg);
+ static int32 _ControlThread(void* arg);
BLocker fLocker;
port_id fControlPort;
@@ -97,9 +97,9 @@ private:
};
-ServerApp::ServerApp()
+ServerApp::ServerApp(status_t& error)
:
- BApplication(B_MEDIA_SERVER_SIGNATURE),
+ BServer(B_MEDIA_SERVER_SIGNATURE, true, &error),
fLocker("media server locker")
{
gNotificationManager = new NotificationManager;
@@ -971,8 +971,11 @@ ServerApp::MessageReceived(BMessage* msg)
int
main()
{
- new ServerApp;
- be_app->Run();
- delete be_app;
- return 0;
+ status_t status;
+ ServerApp app(status);
+
+ if (status == B_OK)
+ app.Run();
+
+ return status == B_OK ? EXIT_SUCCESS : EXIT_FAILURE;
}
############################################################################
Commit: 77c6944c024624728ece129b30d005f93f88b6bd
URL: http://cgit.haiku-os.org/haiku/commit/?id=77c6944c0246
Author: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date: Sat Apr 2 17:22:35 2016 UTC
NodeManager: Use boolean expression
----------------------------------------------------------------------------
diff --git a/src/servers/media/NodeManager.cpp
b/src/servers/media/NodeManager.cpp
index 9a79db8..4c9e1a8 100644
--- a/src/servers/media/NodeManager.cpp
+++ b/src/servers/media/NodeManager.cpp
@@ -161,7 +161,7 @@ NodeManager::RegisterNode(media_addon_id addOnID, int32
flavorID,
node.creator = -1; // will be set later
node.ref_count = 1;
- if (node.kinds & B_TIME_SOURCE
+ if ((node.kinds & B_TIME_SOURCE) != 0
&& strcmp(node.name, "System clock") == 0) {
// This may happen when media_addon_server crash,
// we will replace the old timesource.
############################################################################
Commit: 866084f7a92203364536c609c681880406567586
URL: http://cgit.haiku-os.org/haiku/commit/?id=866084f7a922
Author: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date: Sun Apr 3 22:39:18 2016 UTC
MediaPrefs: No need to start media services anymore
* This will cause troubles as the launch_daemon is
doing this job for us.
----------------------------------------------------------------------------
diff --git a/src/preferences/media/MediaWindow.cpp
b/src/preferences/media/MediaWindow.cpp
index 0e9a9d4..31304d0 100644
--- a/src/preferences/media/MediaWindow.cpp
+++ b/src/preferences/media/MediaWindow.cpp
@@ -658,7 +658,6 @@ MediaWindow::_RestartMediaServices(void* data)
MediaWindow* window = (MediaWindow*)data;
shutdown_media_server();
- launch_media_server();
if (window->fRestartAlert != NULL
&& window->fRestartAlert->Lock()) {
############################################################################
Commit: 53c3fa513774538d62d125eaf293477452fc76c9
URL: http://cgit.haiku-os.org/haiku/commit/?id=53c3fa513774
Author: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date: Sat Apr 2 13:49:01 2016 UTC
Introduce functionality for syncing with the media services
* The global synchro semaphore is provided with the purpose of
being used to avoid threads lock up when the media_server is in
an undefined state. There's still room for improvements.
* BMediaRoster::SyncToServices lock up on a semaphore until
the multi_audio correctly connected to the mixer.
----------------------------------------------------------------------------
diff --git a/headers/os/media/MediaRoster.h b/headers/os/media/MediaRoster.h
index 477c796..78f85b5 100644
--- a/headers/os/media/MediaRoster.h
+++ b/headers/os/media/MediaRoster.h
@@ -42,7 +42,11 @@ public:
// same time.
// Check if the media services are running.
- static bool IsRunning();
+ static bool IsRunning();
+
+ // This functions blocks until the media services are available,
+ // don't abuse of it.
+ static status_t SyncToServices(bigtime_t
timeout = -1);
// Getting common instances of system nodes:
status_t
GetVideoInput(media_node* _node);
diff --git a/headers/private/media/ServerInterface.h
b/headers/private/media/ServerInterface.h
index 177b18a..8ee1fe0 100644
--- a/headers/private/media/ServerInterface.h
+++ b/headers/private/media/ServerInterface.h
@@ -28,6 +28,9 @@ enum {
// add_system_beep_event()
MEDIA_SERVER_ADD_SYSTEM_BEEP_EVENT,
+ // sent by the rescan thread
+ MEDIA_SERVER_RESCAN_COMPLETED,
+
// media add-on server
MEDIA_ADD_ON_SERVER_PLAY_MEDIA = '_TRU'
};
@@ -370,6 +373,7 @@ struct server_register_app_request : request_data {
};
struct server_register_app_reply : reply_data {
+ sem_id global_synchro;
};
struct server_unregister_app_request : request_data {
diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp
index 61d8509..1410ec0 100644
--- a/src/kits/media/MediaRoster.cpp
+++ b/src/kits/media/MediaRoster.cpp
@@ -107,6 +107,7 @@ static bool sServerIsUp = false;
static List<RosterNotification> sNotificationList;
static BLocker sInitLocker("BMediaRoster::Roster locker");
static List<LocalNode> sRegisteredNodes;
+static sem_id sGlobalSynchro = -1;
class MediaRosterUndertaker {
@@ -3344,6 +3345,27 @@ BMediaRoster::IsRunning()
}
+status_t
+BMediaRoster::SyncToServices(bigtime_t timeout)
+{
+ if (!IsRunning())
+ return B_ERROR;
+
+ TRACE("BMediaRoster::SyncToServer: Syncing to the media server");
+
+ // This sem is valid only when the server started
+ // but it's not ready to supply the services.
+ if (sGlobalSynchro > -1)
+ acquire_sem_etc(sGlobalSynchro, 1, B_RELATIVE_TIMEOUT, timeout);
+
+ // TODO: Ideally this function should take into account
+ // the startup latencies of the system nodes and sleep
+ // for the resulting sum.
+
+ return B_OK;
+}
+
+
ssize_t
BMediaRoster::AudioBufferSizeFor(int32 channelCount, uint32 sampleFormat,
float frameRate, bus_type busKind)
@@ -3445,7 +3467,9 @@ BMediaRoster::MessageReceived(BMessage* message)
// Send the notification to our subscribers
if (BMediaRoster::IsRunning()) {
+ SyncToServices();
sServerIsUp = true;
+ sGlobalSynchro = -1;
// Wait for media services to wake up
// TODO: This should be solved so that the
server
// have a way to notify us when the system is
really
diff --git a/src/servers/media/AppManager.cpp b/src/servers/media/AppManager.cpp
index 761ddef..b0ae064 100644
--- a/src/servers/media/AppManager.cpp
+++ b/src/servers/media/AppManager.cpp
@@ -50,11 +50,14 @@ AppManager::AppManager()
:
BLocker("media app manager")
{
+ fGlobalSynchro = create_sem(0, "media server global synchro");
}
AppManager::~AppManager()
{
+ if (fGlobalSynchro != -1)
+ delete_sem(fGlobalSynchro);
}
@@ -67,7 +70,8 @@ AppManager::HasTeam(team_id team)
status_t
-AppManager::RegisterTeam(team_id team, const BMessenger& messenger)
+AppManager::RegisterTeam(team_id team, const BMessenger& messenger,
+ sem_id* sync)
{
BAutolock lock(this);
@@ -84,6 +88,8 @@ AppManager::RegisterTeam(team_id team, const BMessenger&
messenger)
return B_NO_MEMORY;
}
+ *sync = fGlobalSynchro;
+
return B_OK;
}
@@ -151,6 +157,13 @@ AppManager::Dump()
void
+AppManager::UnlockGlobalSynchro()
+{
+ delete_sem(fGlobalSynchro);
+}
+
+
+void
AppManager::_CleanupTeam(team_id team)
{
ASSERT(!IsLocked());
diff --git a/src/servers/media/AppManager.h b/src/servers/media/AppManager.h
index 0bc57fb..5fe9df2 100644
--- a/src/servers/media/AppManager.h
+++ b/src/servers/media/AppManager.h
@@ -18,7 +18,7 @@ public:
~AppManager();
status_t RegisterTeam(team_id
team,
- const
BMessenger& messenger);
+ const
BMessenger& messenger, sem_id* sync);
status_t UnregisterTeam(team_id
team);
bool HasTeam(team_id team);
@@ -28,6 +28,8 @@ public:
void Dump();
+ void UnlockGlobalSynchro();
+
private:
void _CleanupTeam(team_id
team);
@@ -35,6 +37,7 @@ private:
typedef std::map<team_id, BMessenger> AppMap;
AppMap fMap;
+ sem_id fGlobalSynchro;
};
diff --git a/src/servers/media/DefaultManager.cpp
b/src/servers/media/DefaultManager.cpp
index 6e00e93..a598225 100644
--- a/src/servers/media/DefaultManager.cpp
+++ b/src/servers/media/DefaultManager.cpp
@@ -16,9 +16,11 @@
#include <TimeSource.h>
#include <string.h>
+#include "debug.h"
#include "DormantNodeManager.h"
+#include "media_server.h"
#include "NodeManager.h"
-#include "debug.h"
+
/* no locking used in this file, we assume that the caller (NodeManager) does
it.
*/
@@ -411,6 +413,9 @@ DefaultManager::_RescanThread()
add_on_server_rescan_finished_notify_command cmd;
SendToAddOnServer(ADD_ON_SERVER_RESCAN_FINISHED_NOTIFY,
&cmd,
sizeof(cmd));
+
+ BMessage msg(MEDIA_SERVER_RESCAN_COMPLETED);
+ be_app->PostMessage(&msg);
}
locker.Lock();
diff --git a/src/servers/media/media_server.cpp
b/src/servers/media/media_server.cpp
index 9ed51d5..369bc77 100644
--- a/src/servers/media/media_server.cpp
+++ b/src/servers/media/media_server.cpp
@@ -305,7 +305,7 @@ ServerApp::_HandleMessage(int32 code, const void* data,
size_t size)
server_register_app_reply reply;
status_t status =
gAppManager->RegisterTeam(request.team,
- request.messenger);
+ request.messenger, &reply.global_synchro);
request.SendReply(status, &reply, sizeof(reply));
break;
}
@@ -938,6 +938,12 @@ ServerApp::MessageReceived(BMessage* msg)
gMediaFilesManager->HandleAddSystemBeepEvent(msg);
break;
+ case MEDIA_SERVER_RESCAN_COMPLETED:
+ {
+ gAppManager->UnlockGlobalSynchro();
+ break;
+ }
+
case B_SOME_APP_QUIT:
{
BString mimeSig;
############################################################################
Commit: c131229f0800fcbce8eb304dab1e48484dcb47a0
URL: http://cgit.haiku-os.org/haiku/commit/?id=c131229f0800
Author: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date: Sun Apr 3 23:07:01 2016 UTC
media_server: Add notifications
----------------------------------------------------------------------------
diff --git a/headers/private/media/MediaMisc.h
b/headers/private/media/MediaMisc.h
index f476375..b22944c 100644
--- a/headers/private/media/MediaMisc.h
+++ b/headers/private/media/MediaMisc.h
@@ -7,6 +7,19 @@
#ifndef _MEDIA_MISC_H_
#define _MEDIA_MISC_H_
+
+// Used by Haiku apps to make media services notifications
+void
+progress_startup(int stage,
+ bool (*progress)(int stage, const char* message, void* cookie),
+ void* cookie);
+
+void
+progress_shutdown(int stage,
+ bool (*progress)(int stage, const char* message, void* cookie),
+ void* cookie);
+
+
#define IS_INVALID_NODE(_node) ((_node).node <= 0 ||
(_node).port <= 0)
#define IS_INVALID_NODEID(_id) ((_id) <= 0)
#define IS_INVALID_SOURCE(_src) ((_src).port <= 0)
diff --git a/src/servers/media/media_server.cpp
b/src/servers/media/media_server.cpp
index 369bc77..46b8ac1 100644
--- a/src/servers/media/media_server.cpp
+++ b/src/servers/media/media_server.cpp
@@ -143,6 +143,8 @@ ServerApp::ReadyToRun()
{
gNodeManager->LoadState();
+ progress_startup(50, NULL, NULL);
+
// make sure any previous media_addon_server is gone
_QuitAddOnServer();
// and start a new one
@@ -941,6 +943,7 @@ ServerApp::MessageReceived(BMessage* msg)
case MEDIA_SERVER_RESCAN_COMPLETED:
{
gAppManager->UnlockGlobalSynchro();
+ progress_startup(100, NULL, NULL);
break;
}
############################################################################
Revision: hrev50183
Commit: a0b3904a33dc5566e404a87fee827c06e7f92e6b
URL: http://cgit.haiku-os.org/haiku/commit/?id=a0b3904a33dc
Author: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date: Sun Apr 3 23:09:33 2016 UTC
launch_media_server: Remove notifications handled elsewhere
----------------------------------------------------------------------------
diff --git a/src/kits/media/MediaDefs.cpp b/src/kits/media/MediaDefs.cpp
index 3127bed..6b80ed0 100644
--- a/src/kits/media/MediaDefs.cpp
+++ b/src/kits/media/MediaDefs.cpp
@@ -1414,8 +1414,6 @@ launch_media_server(bigtime_t timeout,
snooze(1000000);
}
- progress_startup(50, progress, cookie);
-
status_t err = be_roster->Launch(B_MEDIA_SERVER_SIGNATURE);
if (err != B_OK)
return err;
@@ -1431,7 +1429,6 @@ launch_media_server(bigtime_t timeout,
if (messenger.IsValid()) {
messenger.SendMessage(&msg, &reply, 2000000, 2000000);
err = B_OK;
- progress_startup(100, progress, cookie);
break;
}
}