[haiku-bugs] [Haiku] #7206: Stopping/starting add-ons when they are not needed/needed

  • From: "Karvjorm" <trac@xxxxxxxxxxxx>
  • Date: Thu, 10 Feb 2011 16:58:10 -0000

#7206: Stopping/starting add-ons when they are not needed/needed
-----------------------------------------+-----------------------------
   Reporter:  Karvjorm                   |       Owner:  korli
       Type:  enhancement                |      Status:  new
   Priority:  normal                     |   Milestone:  R1
  Component:  Add-Ons/Input Methods      |     Version:  R1/Development
   Keywords:  mediaplayer mixer add-ons  |  Blocked By:
Has a Patch:  0                          |    Platform:  All
   Blocking:                             |
-----------------------------------------+-----------------------------
 I was wondering why tracker complained about missing mixer when I tried to
 play some .wav file with the mediaplayer. When studying that problem I
 noticed another problem. After reading syslog messages I noticed that the
 media mixer add-ons continues to run in it's loop also after track is
 played in the mediaplayer. Couldn't it be better not to keep system
 resources in use when they are not actually needed.

 The problem is that I do not really understand how these things works. But
 I suppose that

 {{{
 event->type = BTimedEventQueue::B_STOP;
 AudioMixer::HandleEvent(event, static_cast<bigtime_t>(0), true);
 }}}

 '''BTimedEventQueue::B_STOP''' type event should have created after a
 track is played. And '''BTimedEventQueue::B_START''' type event should
 have created when user clicks the "Play again" button in the MediaPlayer.

 But if I understand syslog messages

 {{{
 KERN: Received buffer 10089 usec late
 KERN: sending notify
 }}}

 correct, those B_STOP event types are never created.

 Could it be possible to send some message from the mediaplayer that
 informs the mixer add-ons that you can now stop looping and create a
 B_STOP event. I tried to design some mechanism but this does not work. I
 will only show it to make my idea more understandable. Here is the
 MediaPlayer code:

 {{{
 Index: src/apps/mediaplayer/interface/DurationView.cpp
 ===================================================================
 --- src/apps/mediaplayer/interface/DurationView.cpp     (revision 40419)
 +++ src/apps/mediaplayer/interface/DurationView.cpp     (working copy)
 @@ -7,6 +7,7 @@
  #include "DurationView.h"

  #include <LayoutUtils.h>
 +#include <MediaRoster.h>

  #include "DurationToString.h"

 @@ -139,7 +140,12 @@

         char string[64];
         duration_to_string(duration, string, sizeof(string));
 -
 +       if (strncmp(string, "0:00", sizeof("0:00")) == 0){
 +               BMessage msg(static_cast<uint32>(1951));
 +               msg.AddBool("track_end", true);
 +               BMediaRoster::Roster()->PostMessage(&msg);
 +               //debug_printf("generated string: %s\n", string);
 +       }
         SetText(string);
  }
 }}}

 And then the mixer add-ons code:

 {{{
 status_t
  AudioMixer::HandleMessage(int32 message, const void *data, size_t size)
  {
 +       status_t ret = B_ERROR;
 +       const int32 v1951 = 1951;
         // since we're using a mediaeventlooper, there shouldn't be any
 messages
 -       return B_ERROR;
 +       switch (message) {
 +               case v1951:
 +                       {
 +
 debug_printf("AudioMixer::HandleMessage(1951)\n");
 +                               bool* boolean_value = NULL;
 +                               *boolean_value = false;
 +                               ret =
 static_cast<BMessage*>(data)->FindBool("track_end",
 +                                       boolean_value);
 +                               if (ret == B_OK) {
 +                                       if (boolean_value) {
 +                                               media_timed_event* event =
 NULL;
 +                                               event->type =
 BTimedEventQueue::B_STOP;
 +
 AudioMixer::HandleEvent(event, static_cast<bigtime_t>(0), true);
 +                                       }
 +                               }
 +                       }
 +                       break;
 +               default:
 +                       break;
 +       }
 +       return ret;
  }
 }}}

 Then also equivalent mechanism should have needed for the B_START event
 type. With that solution there can be a clipping problem at the beginning
 of track stream after "Play again", but maybe it is not a big problem.

-- 
Ticket URL: <http://dev.haiku-os.org/ticket/7206>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: