From 50cb5283a06f41b436e6802962c72452905dfab4 Mon Sep 17 00:00:00 2001 From: Barrett17 Date: Wed, 24 Oct 2018 12:27:14 +0200 Subject: [PATCH] media/codec: Share media_format defs until libmedia2.so --- src/kits/codec/Jamfile | 6 +- src/kits/media/Jamfile | 1 + src/kits/media/MediaDefs.cpp | 233 --------------------------- src/kits/media/MediaDefsNotify.cpp | 250 +++++++++++++++++++++++++++++ 4 files changed, 254 insertions(+), 236 deletions(-) create mode 100644 src/kits/media/MediaDefsNotify.cpp diff --git a/src/kits/codec/Jamfile b/src/kits/codec/Jamfile index 33c5565eeb..51141de33e 100644 --- a/src/kits/codec/Jamfile +++ b/src/kits/codec/Jamfile @@ -6,12 +6,11 @@ if $(CHECK_MALLOC) { SubDirC++Flags -D_NO_INLINE_ASM -fcheck-memory-usage ; } - local architectureObject ; for architectureObject in [ MultiArchSubDirSetup ] { on $(architectureObject) { -SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits media ] ; + SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits media ] ; SharedLibrary [ MultiArchDefaultGristFiles libcodec.so ] : # Adapter Kit @@ -37,8 +36,9 @@ SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits media ] ; # We need this to do not depend on libmedia # will be removed when libmedia2 is introduced - RealtimeAlloc.cpp + MediaDefs.cpp MediaFormats.cpp + RealtimeAlloc.cpp : be localestub shared diff --git a/src/kits/media/Jamfile b/src/kits/media/Jamfile index 79cd511185..9a15c68130 100644 --- a/src/kits/media/Jamfile +++ b/src/kits/media/Jamfile @@ -27,6 +27,7 @@ for architectureObject in [ MultiArchSubDirSetup ] { MediaAddOn.cpp MediaDecoder.cpp MediaDefs.cpp + MediaDefsNotify.cpp MediaEncoder.cpp MediaEventLooper.cpp MediaFile.cpp diff --git a/src/kits/media/MediaDefs.cpp b/src/kits/media/MediaDefs.cpp index d69846832b..d6106ebd4e 100644 --- a/src/kits/media/MediaDefs.cpp +++ b/src/kits/media/MediaDefs.cpp @@ -13,13 +13,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include @@ -1233,237 +1231,6 @@ get_next_file_format(int32* cookie, media_file_format* mff) } -// #pragma mark - - - -// final & verified -const char* B_MEDIA_SERVER_SIGNATURE = "application/x-vnd.Be.media-server"; -const char* B_MEDIA_ADDON_SERVER_SIGNATURE = "application/x-vnd.Be.addon-host"; - -const type_code B_CODEC_TYPE_INFO = 0x040807b2; - - -// #pragma mark - - - -// shutdown_media_server() and launch_media_server() -// are provided by libbe.so in BeOS R5 - -#define MEDIA_SERVICE_NOTIFICATION_ID "MediaServiceNotificationID" - - -void -notify_system(float progress, const char* message) -{ - BNotification notification(B_PROGRESS_NOTIFICATION); - notification.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); - notification.SetProgress(progress); - notification.SetGroup(B_TRANSLATE("Media Service")); - notification.SetContent(message); - - app_info info; - be_app->GetAppInfo(&info); - BBitmap icon(BRect(0, 0, 32, 32), B_RGBA32); - BNode node(&info.ref); - BIconUtils::GetVectorIcon(&node, "BEOS:ICON", &icon); - notification.SetIcon(&icon); - - notification.Send(); -} - - -void -progress_shutdown(int stage, - bool (*progress)(int stage, const char* message, void* cookie), - void* cookie) -{ - // parameter "message" is no longer used. It is kept for compatibility with - // BeOS as this is used as a shutdown_media_server callback. - - TRACE("stage: %i\n", stage); - const char* string = "Unknown stage"; - switch (stage) { - case 10: - string = B_TRANSLATE("Stopping media server" B_UTF8_ELLIPSIS); - break; - case 20: - string = B_TRANSLATE("Waiting for media_server to quit."); - break; - case 40: - string = B_TRANSLATE("Telling media_addon_server to quit."); - break; - case 50: - string = B_TRANSLATE("Waiting for media_addon_server to quit."); - break; - case 70: - string = B_TRANSLATE("Cleaning up."); - break; - case 100: - string = B_TRANSLATE("Done shutting down."); - break; - } - - if (progress == NULL) - notify_system(stage / 100.0f, string); - else - progress(stage, string, cookie); -} - - -status_t -shutdown_media_server(bigtime_t timeout, - bool (*progress)(int stage, const char* message, void* cookie), - void* cookie) -{ - BMessage msg(B_QUIT_REQUESTED); - status_t err = B_MEDIA_SYSTEM_FAILURE; - bool shutdown = false; - - BMediaRoster* roster = BMediaRoster::Roster(&err); - if (roster == NULL || err != B_OK) - return err; - - if (progress == NULL && roster->Lock()) { - MediaRosterEx(roster)->EnableLaunchNotification(true, true); - roster->Unlock(); - } - - if ((err = msg.AddBool("be:_user_request", true)) != B_OK) - return err; - - team_id mediaServer = be_roster->TeamFor(B_MEDIA_SERVER_SIGNATURE); - team_id addOnServer = be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE); - - if (mediaServer != B_ERROR) { - BMessage reply; - BMessenger messenger(B_MEDIA_SERVER_SIGNATURE, mediaServer); - progress_shutdown(10, progress, cookie); - - err = messenger.SendMessage(&msg, &reply, 2000000, 2000000); - reply.FindBool("_shutdown", &shutdown); - if (err == B_TIMED_OUT || shutdown == false) { - if (messenger.IsValid()) - kill_team(mediaServer); - } else if (err != B_OK) - return err; - - progress_shutdown(20, progress, cookie); - - int32 rv; - if (reply.FindInt32("error", &rv) == B_OK && rv != B_OK) - return rv; - } - - if (addOnServer != B_ERROR) { - shutdown = false; - BMessage reply; - BMessenger messenger(B_MEDIA_ADDON_SERVER_SIGNATURE, addOnServer); - progress_shutdown(40, progress, cookie); - - // The media_server usually shutdown the media_addon_server, - // if not let's do something. - if (messenger.IsValid()) { - err = messenger.SendMessage(&msg, &reply, 2000000, 2000000); - reply.FindBool("_shutdown", &shutdown); - if (err == B_TIMED_OUT || shutdown == false) { - if (messenger.IsValid()) - kill_team(addOnServer); - } else if (err != B_OK) - return err; - - progress_shutdown(50, progress, cookie); - - int32 rv; - if (reply.FindInt32("error", &rv) == B_OK && rv != B_OK) - return rv; - } - } - - progress_shutdown(100, progress, cookie); - return B_OK; -} - - -void -progress_startup(int stage, - bool (*progress)(int stage, const char* message, void* cookie), - void* cookie) -{ - // parameter "message" is no longer used. It is kept for compatibility with - // BeOS as this is used as a shutdown_media_server callback. - - TRACE("stage: %i\n", stage); - const char* string = "Unknown stage"; - switch (stage) { - case 10: - string = B_TRANSLATE("Stopping media server" B_UTF8_ELLIPSIS); - break; - case 20: - string = B_TRANSLATE("Stopping media_addon_server."); - break; - case 50: - string = B_TRANSLATE("Starting media_services."); - break; - case 90: - string = B_TRANSLATE("Error occurred starting media services."); - break; - case 100: - string = B_TRANSLATE("Ready for use."); - break; - } - - if (progress == NULL) - notify_system(stage / 100.0f, string); - else - progress(stage, string, cookie); -} - - -status_t -launch_media_server(bigtime_t timeout, - bool (*progress)(int stage, const char* message, void* cookie), - void* cookie, uint32 flags) -{ - if (BMediaRoster::IsRunning()) - return B_ALREADY_RUNNING; - - status_t err = B_MEDIA_SYSTEM_FAILURE; - BMediaRoster* roster = BMediaRoster::Roster(&err); - if (roster == NULL || err != B_OK) - return err; - - if (progress == NULL && roster->Lock()) { - MediaRosterEx(roster)->EnableLaunchNotification(true, true); - roster->Unlock(); - } - - // The media_server crashed - if (be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE)) { - progress_startup(10, progress, cookie); - kill_team(be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE)); - } - - // The media_addon_server crashed - if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) { - progress_startup(20, progress, cookie); - kill_team(be_roster->TeamFor(B_MEDIA_SERVER_SIGNATURE)); - } - - progress_startup(50, progress, cookie); - - err = BLaunchRoster().Start(B_MEDIA_SERVER_SIGNATURE); - - if (err != B_OK) - progress_startup(90, progress, cookie); - else if (progress != NULL) { - progress_startup(100, progress, cookie); - err = B_OK; - } - - return err; -} - - // #pragma mark - media_encode_info diff --git a/src/kits/media/MediaDefsNotify.cpp b/src/kits/media/MediaDefsNotify.cpp new file mode 100644 index 0000000000..b661e3941a --- /dev/null +++ b/src/kits/media/MediaDefsNotify.cpp @@ -0,0 +1,250 @@ +/* + * Copyright 2015, Dario Casalinuovo + * Copyright 2004, 2006, Jérôme Duval. + * Copyright 2003-2004, Andrew Bachmann. + * Copyright 2002-2004, 2006 Marcus Overhagen. + * Copyright 2002, Eric Jaessler. + * All rights reserved. Distributed under the terms of the MIT license. + */ + + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "MediaRosterEx.h" + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "MediaDefs" + +// final & verified +const char* B_MEDIA_SERVER_SIGNATURE = "application/x-vnd.Be.media-server"; +const char* B_MEDIA_ADDON_SERVER_SIGNATURE = "application/x-vnd.Be.addon-host"; + +const type_code B_CODEC_TYPE_INFO = 0x040807b2; + +// shutdown_media_server() and launch_media_server() +// are provided by libbe.so in BeOS R5 + +#define MEDIA_SERVICE_NOTIFICATION_ID "MediaServiceNotificationID" + + +void +notify_system(float progress, const char* message) +{ + BNotification notification(B_PROGRESS_NOTIFICATION); + notification.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); + notification.SetProgress(progress); + notification.SetGroup(B_TRANSLATE("Media Service")); + notification.SetContent(message); + + app_info info; + be_app->GetAppInfo(&info); + BBitmap icon(BRect(0, 0, 32, 32), B_RGBA32); + BNode node(&info.ref); + BIconUtils::GetVectorIcon(&node, "BEOS:ICON", &icon); + notification.SetIcon(&icon); + + notification.Send(); +} + + +void +progress_shutdown(int stage, + bool (*progress)(int stage, const char* message, void* cookie), + void* cookie) +{ + // parameter "message" is no longer used. It is kept for compatibility with + // BeOS as this is used as a shutdown_media_server callback. + + TRACE("stage: %i\n", stage); + const char* string = "Unknown stage"; + switch (stage) { + case 10: + string = B_TRANSLATE("Stopping media server" B_UTF8_ELLIPSIS); + break; + case 20: + string = B_TRANSLATE("Waiting for media_server to quit."); + break; + case 40: + string = B_TRANSLATE("Telling media_addon_server to quit."); + break; + case 50: + string = B_TRANSLATE("Waiting for media_addon_server to quit."); + break; + case 70: + string = B_TRANSLATE("Cleaning up."); + break; + case 100: + string = B_TRANSLATE("Done shutting down."); + break; + } + + if (progress == NULL) + notify_system(stage / 100.0f, string); + else + progress(stage, string, cookie); +} + + +status_t +shutdown_media_server(bigtime_t timeout, + bool (*progress)(int stage, const char* message, void* cookie), + void* cookie) +{ + BMessage msg(B_QUIT_REQUESTED); + status_t err = B_MEDIA_SYSTEM_FAILURE; + bool shutdown = false; + + BMediaRoster* roster = BMediaRoster::Roster(&err); + if (roster == NULL || err != B_OK) + return err; + + if (progress == NULL && roster->Lock()) { + MediaRosterEx(roster)->EnableLaunchNotification(true, true); + roster->Unlock(); + } + + if ((err = msg.AddBool("be:_user_request", true)) != B_OK) + return err; + + team_id mediaServer = be_roster->TeamFor(B_MEDIA_SERVER_SIGNATURE); + team_id addOnServer = be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE); + + if (mediaServer != B_ERROR) { + BMessage reply; + BMessenger messenger(B_MEDIA_SERVER_SIGNATURE, mediaServer); + progress_shutdown(10, progress, cookie); + + err = messenger.SendMessage(&msg, &reply, 2000000, 2000000); + reply.FindBool("_shutdown", &shutdown); + if (err == B_TIMED_OUT || shutdown == false) { + if (messenger.IsValid()) + kill_team(mediaServer); + } else if (err != B_OK) + return err; + + progress_shutdown(20, progress, cookie); + + int32 rv; + if (reply.FindInt32("error", &rv) == B_OK && rv != B_OK) + return rv; + } + + if (addOnServer != B_ERROR) { + shutdown = false; + BMessage reply; + BMessenger messenger(B_MEDIA_ADDON_SERVER_SIGNATURE, addOnServer); + progress_shutdown(40, progress, cookie); + + // The media_server usually shutdown the media_addon_server, + // if not let's do something. + if (messenger.IsValid()) { + err = messenger.SendMessage(&msg, &reply, 2000000, 2000000); + reply.FindBool("_shutdown", &shutdown); + if (err == B_TIMED_OUT || shutdown == false) { + if (messenger.IsValid()) + kill_team(addOnServer); + } else if (err != B_OK) + return err; + + progress_shutdown(50, progress, cookie); + + int32 rv; + if (reply.FindInt32("error", &rv) == B_OK && rv != B_OK) + return rv; + } + } + + progress_shutdown(100, progress, cookie); + return B_OK; +} + + +void +progress_startup(int stage, + bool (*progress)(int stage, const char* message, void* cookie), + void* cookie) +{ + // parameter "message" is no longer used. It is kept for compatibility with + // BeOS as this is used as a shutdown_media_server callback. + + TRACE("stage: %i\n", stage); + const char* string = "Unknown stage"; + switch (stage) { + case 10: + string = B_TRANSLATE("Stopping media server" B_UTF8_ELLIPSIS); + break; + case 20: + string = B_TRANSLATE("Stopping media_addon_server."); + break; + case 50: + string = B_TRANSLATE("Starting media_services."); + break; + case 90: + string = B_TRANSLATE("Error occurred starting media services."); + break; + case 100: + string = B_TRANSLATE("Ready for use."); + break; + } + + if (progress == NULL) + notify_system(stage / 100.0f, string); + else + progress(stage, string, cookie); +} + + +status_t +launch_media_server(bigtime_t timeout, + bool (*progress)(int stage, const char* message, void* cookie), + void* cookie, uint32 flags) +{ + if (BMediaRoster::IsRunning()) + return B_ALREADY_RUNNING; + + status_t err = B_MEDIA_SYSTEM_FAILURE; + BMediaRoster* roster = BMediaRoster::Roster(&err); + if (roster == NULL || err != B_OK) + return err; + + if (progress == NULL && roster->Lock()) { + MediaRosterEx(roster)->EnableLaunchNotification(true, true); + roster->Unlock(); + } + + // The media_server crashed + if (be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE)) { + progress_startup(10, progress, cookie); + kill_team(be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE)); + } + + // The media_addon_server crashed + if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) { + progress_startup(20, progress, cookie); + kill_team(be_roster->TeamFor(B_MEDIA_SERVER_SIGNATURE)); + } + + progress_startup(50, progress, cookie); + + err = BLaunchRoster().Start(B_MEDIA_SERVER_SIGNATURE); + + if (err != B_OK) + progress_startup(90, progress, cookie); + else if (progress != NULL) { + progress_startup(100, progress, cookie); + err = B_OK; + } + + return err; +}