Ticket #8171: 0001-Media-Service-restart-is-now-using-BNotification.patch

File 0001-Media-Service-restart-is-now-using-BNotification.patch, 9.2 KB (added by MrPingouin, 9 years ago)
  • headers/os/media/MediaDefs.h

    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;  
    787787// currently always return TRUE. A 'stage' value of 100 means the process is
    788788// completely finished.
    789789status_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,
    791791    void* cookie = NULL);
    792792status_t launch_media_server(uint32 flags = 0);
    793793
  • src/kits/media/MediaDefs.cpp

    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;  
    12201220
    12211221status_t
    12221222shutdown_media_server(bigtime_t timeout,
    1223     bool (*progress)(int stage, const char* message, void* cookie),
     1223    bool (*progress)(int stage, void* cookie),
    12241224    void* cookie)
    12251225{
    12261226    BMessage msg(B_QUIT_REQUESTED);
    shutdown_media_server(bigtime_t timeout,  
    12321232
    12331233    if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) {
    12341234        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);
    12361237
    12371238        err = messenger.SendMessage(&msg, &reply, 2000000, 2000000);
    12381239        if (err != B_OK)
    shutdown_media_server(bigtime_t timeout,  
    12451246
    12461247    if (be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE)) {
    12471248        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);
    12491251
    12501252        err = messenger.SendMessage(&msg, &reply, 2000000, 2000000);
    12511253        if (err != B_OK)
    shutdown_media_server(bigtime_t timeout,  
    12571259    }
    12581260
    12591261    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);
    12611264        snooze(200000);
    12621265    }
    12631266
    12641267    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);
    12661270        snooze(200000);
    12671271    }
    12681272
    1269     progress(70, "Cleaning Up.", cookie);
     1273    // "Cleaning Up."
     1274    progress(70, cookie);
    12701275    snooze(1000000);
    12711276
    12721277    if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) {
    shutdown_media_server(bigtime_t timeout,  
    12771282        kill_team(be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE));
    12781283    }
    12791284
    1280     progress(100, "Done Shutting Down.", cookie);
     1285    // "Done Shutting Down."
     1286    progress(100, cookie);
    12811287    snooze(1000000);
    12821288
    12831289    return B_OK;
  • src/preferences/media/MediaWindow.cpp

    diff --git a/src/preferences/media/MediaWindow.cpp b/src/preferences/media/MediaWindow.cpp
    index 247259b..6331505 100644
    a b  
    2525#include <Locale.h>
    2626#include <MediaRoster.h>
    2727#include <MediaTheme.h>
     28#include <Notification.h>
    2829#include <Resources.h>
    2930#include <Roster.h>
    3031#include <Screen.h>
    MediaWindow::MediaWindow(BRect frame)  
    161162    fAudioOutputs(5, true),
    162163    fVideoInputs(5, true),
    163164    fVideoOutputs(5, true),
    164     fAlert(NULL),
     165    fNotificationPopup(NULL),
    165166    fInitCheck(B_OK)
    166167{
    167168    _InitWindow();
    MediaWindow::MessageReceived(BMessage* message)  
    314315        case B_SOME_APP_LAUNCHED:
    315316        {
    316317            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            }
    319323
    320324            BString mimeSig;
    321325            if (message->FindString("be:signature", &mimeSig) == B_OK
    322326                && (mimeSig == "application/x-vnd.Be.addon-host"
    323327                    || mimeSig == "application/x-vnd.Be.media-server")) {
    324                 fAlert->Lock();
    325                 fAlert->TextView()->SetText(
     328                fNotificationPopup->SetContent(
    326329                    B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS));
    327                 fAlert->Unlock();
     330                fNotificationPopup->Send();
    328331            }
    329332            break;
    330333        }
    MediaWindow::_InitMedia(bool first)  
    418421        if (alert->Go() == 0)
    419422            return B_ERROR;
    420423
    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();
    425431
    426432        Show();
    427433
    MediaWindow::_InitMedia(bool first)  
    435441        && fListView->ItemAt(0)->IsSelected())
    436442        isVideoSelected = false;
    437443
    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();
    443450    }
    444451
    445452    while (fListView->CountItems() > 0)
    MediaWindow::_InitMedia(bool first)  
    517524    else
    518525        fListView->Select(fListView->IndexOf(audio));
    519526
    520     if (fAlert != NULL) {
    521         snooze(800000);
    522         fAlert->PostMessage(B_QUIT_REQUESTED);
    523     }
    524     fAlert = NULL;
    525 
    526527    Unlock();
    527528
    528529    return B_OK;
    status_t  
    648649MediaWindow::_RestartMediaServices(void* data)
    649650{
    650651    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"));
    654652
    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();
    656662
    657663    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();
    659669
    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     }
    666670    launch_media_server();
    667671
    668672    return window->PostMessage(ML_INIT_MEDIA);
    MediaWindow::_RestartMediaServices(void* data)  
    670674
    671675
    672676bool
    673 MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie)
     677MediaWindow::_UpdateProgress(int stage, void* infoPopup)
    674678{
    675     MediaAlert* alert = static_cast<MediaAlert*>(cookie);
     679    BNotification* info = static_cast<BNotification*>(infoPopup);
    676680    PRINT(("stage : %i\n", stage));
    677681    const char* string = "Unknown stage";
    678682    switch (stage) {
    MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie)  
    693697            break;
    694698    }
    695699
    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
    699706    return true;
    700707}
    701708
  • src/preferences/media/MediaWindow.h

    diff --git a/src/preferences/media/MediaWindow.h b/src/preferences/media/MediaWindow.h
    index be0af2f..bd5c8d8 100644
    a b  
    2222#include "MediaIcons.h"
    2323#include "MediaListItem.h"
    2424#include "MediaViews.h"
     25#include "Notification.h"
    2526
    26 
     27#define MEDIA_SERVICE_NOTIFICATION_ID "MediaServiceNotificationID"
    2728#define SETTINGS_FILE "MediaPrefs Settings"
    2829
    2930
    private:  
    7374            NodeListItem*       _FindNodeListItem(dormant_node_info* info);
    7475
    7576    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);
    7878
    7979            void                _ClearParamView();
    8080            void                _MakeParamView();
    private:  
    111111            NodeList            fVideoInputs;
    112112            NodeList            fVideoOutputs;
    113113
    114             MediaAlert*         fAlert;
     114            BNotification*      fNotificationPopup;
    115115            status_t            fInitCheck;
    116116};
    117117