From 4e5b51a5f6f7301f3b8bfb53a7d1c245ce5e5757 Mon Sep 17 00:00:00 2001
From: Laurent Chea <contact@laurentchea.com>
Date: Fri, 12 Dec 2014 00:05:36 +0100
Subject: [PATCH] Media Service restart is now using BNotification instead of a
custom BWindow. Shutdown function shutdown_media_server has been updated,
removing the unused char* message parameter. Fixes #8171.
---
headers/os/media/MediaDefs.h | 2 +-
src/kits/media/MediaDefs.cpp | 20 ++++++---
src/preferences/media/MediaWindow.cpp | 81 +++++++++++++++++++----------------
src/preferences/media/MediaWindow.h | 8 ++--
4 files changed, 62 insertions(+), 49 deletions(-)
diff --git a/headers/os/media/MediaDefs.h b/headers/os/media/MediaDefs.h
index 8cbce1e..139e2a6 100644
a
|
b
|
struct buffer_clone_info;
|
787 | 787 | // currently always return TRUE. A 'stage' value of 100 means the process is |
788 | 788 | // completely finished. |
789 | 789 | status_t shutdown_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT, |
790 | | bool (*progress)(int stage, const char* message, void* cookie) = NULL, |
| 790 | bool (*progress)(int stage, void* cookie) = NULL, |
791 | 791 | void* cookie = NULL); |
792 | 792 | status_t launch_media_server(uint32 flags = 0); |
793 | 793 | |
diff --git a/src/kits/media/MediaDefs.cpp b/src/kits/media/MediaDefs.cpp
index a60facb..0e65bfb 100644
a
|
b
|
const type_code B_CODEC_TYPE_INFO = 0x040807b2;
|
1220 | 1220 | |
1221 | 1221 | status_t |
1222 | 1222 | shutdown_media_server(bigtime_t timeout, |
1223 | | bool (*progress)(int stage, const char* message, void* cookie), |
| 1223 | bool (*progress)(int stage, void* cookie), |
1224 | 1224 | void* cookie) |
1225 | 1225 | { |
1226 | 1226 | BMessage msg(B_QUIT_REQUESTED); |
… |
… |
shutdown_media_server(bigtime_t timeout,
|
1232 | 1232 | |
1233 | 1233 | if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) { |
1234 | 1234 | BMessenger messenger(B_MEDIA_SERVER_SIGNATURE); |
1235 | | progress(10, "Telling media_server to quit.", cookie); |
| 1235 | // "Telling media_server to quit." |
| 1236 | progress(10, cookie); |
1236 | 1237 | |
1237 | 1238 | err = messenger.SendMessage(&msg, &reply, 2000000, 2000000); |
1238 | 1239 | if (err != B_OK) |
… |
… |
shutdown_media_server(bigtime_t timeout,
|
1245 | 1246 | |
1246 | 1247 | if (be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE)) { |
1247 | 1248 | BMessenger messenger(B_MEDIA_ADDON_SERVER_SIGNATURE); |
1248 | | progress(20, "Telling media_addon_server to quit.", cookie); |
| 1249 | // "Telling media_addon_server to quit." |
| 1250 | progress(20, cookie); |
1249 | 1251 | |
1250 | 1252 | err = messenger.SendMessage(&msg, &reply, 2000000, 2000000); |
1251 | 1253 | if (err != B_OK) |
… |
… |
shutdown_media_server(bigtime_t timeout,
|
1257 | 1259 | } |
1258 | 1260 | |
1259 | 1261 | if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) { |
1260 | | progress(40, "Waiting for media_server to quit.", cookie); |
| 1262 | // "Waiting for media_server to quit." |
| 1263 | progress(40, cookie); |
1261 | 1264 | snooze(200000); |
1262 | 1265 | } |
1263 | 1266 | |
1264 | 1267 | if (be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE)) { |
1265 | | progress(50, "Waiting for media_addon_server to quit.", cookie); |
| 1268 | // "Waiting for media_addon_server to quit." |
| 1269 | progress(50, cookie); |
1266 | 1270 | snooze(200000); |
1267 | 1271 | } |
1268 | 1272 | |
1269 | | progress(70, "Cleaning Up.", cookie); |
| 1273 | // "Cleaning Up." |
| 1274 | progress(70, cookie); |
1270 | 1275 | snooze(1000000); |
1271 | 1276 | |
1272 | 1277 | if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) { |
… |
… |
shutdown_media_server(bigtime_t timeout,
|
1277 | 1282 | kill_team(be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE)); |
1278 | 1283 | } |
1279 | 1284 | |
1280 | | progress(100, "Done Shutting Down.", cookie); |
| 1285 | // "Done Shutting Down." |
| 1286 | progress(100, cookie); |
1281 | 1287 | snooze(1000000); |
1282 | 1288 | |
1283 | 1289 | return B_OK; |
diff --git a/src/preferences/media/MediaWindow.cpp b/src/preferences/media/MediaWindow.cpp
index 247259b..6331505 100644
a
|
b
|
|
25 | 25 | #include <Locale.h> |
26 | 26 | #include <MediaRoster.h> |
27 | 27 | #include <MediaTheme.h> |
| 28 | #include <Notification.h> |
28 | 29 | #include <Resources.h> |
29 | 30 | #include <Roster.h> |
30 | 31 | #include <Screen.h> |
… |
… |
MediaWindow::MediaWindow(BRect frame)
|
161 | 162 | fAudioOutputs(5, true), |
162 | 163 | fVideoInputs(5, true), |
163 | 164 | fVideoOutputs(5, true), |
164 | | fAlert(NULL), |
| 165 | fNotificationPopup(NULL), |
165 | 166 | fInitCheck(B_OK) |
166 | 167 | { |
167 | 168 | _InitWindow(); |
… |
… |
MediaWindow::MessageReceived(BMessage* message)
|
314 | 315 | case B_SOME_APP_LAUNCHED: |
315 | 316 | { |
316 | 317 | PRINT_OBJECT(*message); |
317 | | if (fAlert == NULL) |
318 | | break; |
| 318 | if (fNotificationPopup == NULL) |
| 319 | { |
| 320 | fNotificationPopup = new BNotification(B_PROGRESS_NOTIFICATION); |
| 321 | fNotificationPopup->SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); |
| 322 | } |
319 | 323 | |
320 | 324 | BString mimeSig; |
321 | 325 | if (message->FindString("be:signature", &mimeSig) == B_OK |
322 | 326 | && (mimeSig == "application/x-vnd.Be.addon-host" |
323 | 327 | || mimeSig == "application/x-vnd.Be.media-server")) { |
324 | | fAlert->Lock(); |
325 | | fAlert->TextView()->SetText( |
| 328 | fNotificationPopup->SetContent( |
326 | 329 | B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS)); |
327 | | fAlert->Unlock(); |
| 330 | fNotificationPopup->Send(); |
328 | 331 | } |
329 | 332 | break; |
330 | 333 | } |
… |
… |
MediaWindow::_InitMedia(bool first)
|
418 | 421 | if (alert->Go() == 0) |
419 | 422 | return B_ERROR; |
420 | 423 | |
421 | | fAlert = new MediaAlert(BRect(0, 0, 300, 60), "restart_alert", |
422 | | B_TRANSLATE("Restarting media services\nStarting media server" |
423 | | B_UTF8_ELLIPSIS "\n")); |
424 | | fAlert->Show(); |
| 424 | fNotificationPopup = new BNotification(B_PROGRESS_NOTIFICATION); |
| 425 | fNotificationPopup->SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); |
| 426 | fNotificationPopup->SetTitle(B_TRANSLATE("Media Service")); |
| 427 | fNotificationPopup->SetProgress(0); |
| 428 | fNotificationPopup->SetContent( |
| 429 | B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS)); |
| 430 | fNotificationPopup->Send(); |
425 | 431 | |
426 | 432 | Show(); |
427 | 433 | |
… |
… |
MediaWindow::_InitMedia(bool first)
|
435 | 441 | && fListView->ItemAt(0)->IsSelected()) |
436 | 442 | isVideoSelected = false; |
437 | 443 | |
438 | | if ((!first || (first && err) ) && fAlert) { |
439 | | BAutolock locker(fAlert); |
440 | | if (locker.IsLocked()) |
441 | | fAlert->TextView()->SetText( |
442 | | B_TRANSLATE("Ready for use" B_UTF8_ELLIPSIS)); |
| 444 | if ((!first || (first && err) ) && fNotificationPopup) { |
| 445 | fNotificationPopup->SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); |
| 446 | fNotificationPopup->SetProgress(1.0); |
| 447 | fNotificationPopup->SetContent( |
| 448 | B_TRANSLATE("Ready for use" B_UTF8_ELLIPSIS)); |
| 449 | fNotificationPopup->Send(); |
443 | 450 | } |
444 | 451 | |
445 | 452 | while (fListView->CountItems() > 0) |
… |
… |
MediaWindow::_InitMedia(bool first)
|
517 | 524 | else |
518 | 525 | fListView->Select(fListView->IndexOf(audio)); |
519 | 526 | |
520 | | if (fAlert != NULL) { |
521 | | snooze(800000); |
522 | | fAlert->PostMessage(B_QUIT_REQUESTED); |
523 | | } |
524 | | fAlert = NULL; |
525 | | |
526 | 527 | Unlock(); |
527 | 528 | |
528 | 529 | return B_OK; |
… |
… |
status_t
|
648 | 649 | MediaWindow::_RestartMediaServices(void* data) |
649 | 650 | { |
650 | 651 | MediaWindow* window = (MediaWindow*)data; |
651 | | window->fAlert = new MediaAlert(BRect(0, 0, 300, 60), |
652 | | "restart_alert", B_TRANSLATE( |
653 | | "Restarting media services\nShutting down media server\n")); |
654 | 652 | |
655 | | window->fAlert->Show(); |
| 653 | if (window->fNotificationPopup == NULL) |
| 654 | { |
| 655 | window->fNotificationPopup = new BNotification(B_PROGRESS_NOTIFICATION); |
| 656 | window->fNotificationPopup->SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); |
| 657 | } |
| 658 | |
| 659 | window->fNotificationPopup->SetTitle(B_TRANSLATE("Media Service")); |
| 660 | window->fNotificationPopup->SetContent(B_TRANSLATE("Shutting down media server")); |
| 661 | window->fNotificationPopup->Send(); |
656 | 662 | |
657 | 663 | shutdown_media_server(B_INFINITE_TIMEOUT, MediaWindow::_UpdateProgress, |
658 | | window->fAlert); |
| 664 | window->fNotificationPopup); |
| 665 | |
| 666 | window->fNotificationPopup->SetContent( |
| 667 | B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS)); |
| 668 | window->fNotificationPopup->Send(); |
659 | 669 | |
660 | | { |
661 | | BAutolock locker(window->fAlert); |
662 | | if (locker.IsLocked()) |
663 | | window->fAlert->TextView()->SetText( |
664 | | B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS)); |
665 | | } |
666 | 670 | launch_media_server(); |
667 | 671 | |
668 | 672 | return window->PostMessage(ML_INIT_MEDIA); |
… |
… |
MediaWindow::_RestartMediaServices(void* data)
|
670 | 674 | |
671 | 675 | |
672 | 676 | bool |
673 | | MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie) |
| 677 | MediaWindow::_UpdateProgress(int stage, void* infoPopup) |
674 | 678 | { |
675 | | MediaAlert* alert = static_cast<MediaAlert*>(cookie); |
| 679 | BNotification* info = static_cast<BNotification*>(infoPopup); |
676 | 680 | PRINT(("stage : %i\n", stage)); |
677 | 681 | const char* string = "Unknown stage"; |
678 | 682 | switch (stage) { |
… |
… |
MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie)
|
693 | 697 | break; |
694 | 698 | } |
695 | 699 | |
696 | | BAutolock locker(alert); |
697 | | if (locker.IsLocked()) |
698 | | alert->TextView()->SetText(string); |
| 700 | info->SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); |
| 701 | info->SetProgress(stage/100.0); |
| 702 | info->SetTitle(B_TRANSLATE("Media Service")); |
| 703 | info->SetContent(string); |
| 704 | info->Send(); |
| 705 | |
699 | 706 | return true; |
700 | 707 | } |
701 | 708 | |
diff --git a/src/preferences/media/MediaWindow.h b/src/preferences/media/MediaWindow.h
index be0af2f..bd5c8d8 100644
a
|
b
|
|
22 | 22 | #include "MediaIcons.h" |
23 | 23 | #include "MediaListItem.h" |
24 | 24 | #include "MediaViews.h" |
| 25 | #include "Notification.h" |
25 | 26 | |
26 | | |
| 27 | #define MEDIA_SERVICE_NOTIFICATION_ID "MediaServiceNotificationID" |
27 | 28 | #define SETTINGS_FILE "MediaPrefs Settings" |
28 | 29 | |
29 | 30 | |
… |
… |
private:
|
73 | 74 | NodeListItem* _FindNodeListItem(dormant_node_info* info); |
74 | 75 | |
75 | 76 | static status_t _RestartMediaServices(void* data); |
76 | | static bool _UpdateProgress(int stage, const char * message, |
77 | | void * cookie); |
| 77 | static bool _UpdateProgress(int stage, void* infoPopup); |
78 | 78 | |
79 | 79 | void _ClearParamView(); |
80 | 80 | void _MakeParamView(); |
… |
… |
private:
|
111 | 111 | NodeList fVideoInputs; |
112 | 112 | NodeList fVideoOutputs; |
113 | 113 | |
114 | | MediaAlert* fAlert; |
| 114 | BNotification* fNotificationPopup; |
115 | 115 | status_t fInitCheck; |
116 | 116 | }; |
117 | 117 | |