Opened 13 years ago

Last modified 9 years ago

#7206 new enhancement

Stopping/starting add-ons when they are not needed/needed

Reported by: Karvjorm Owned by: nobody
Priority: normal Milestone: R1
Component: Add-Ons/Media/Mixer Version: R1/Development
Keywords: mediaplayer mixer add-ons Cc: Karvjorm
Blocked By: Blocking:
Platform: All

Description

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.

Change History (3)

comment:1 by korli, 13 years ago

Please explain how this is related to input methods? Is this report related to MediaPlayer?

in reply to:  1 comment:2 by Karvjorm, 13 years ago

Replying to korli:

Please explain how this is related to input methods? Is this report related to MediaPlayer?

Sorry, I looked at syslog messages that they were printed in the mixer input methods or something like that (when I selected targets here in the ticket settings). This is related both MediaPlayer and media mixer add-ons, but I guessed that bigger problems were in mixer and selected it.

comment:3 by modeenf, 9 years ago

Component: Add-Ons/Input MethodsAdd-Ons/Media/Mixer
Owner: changed from korli to nobody

Move this to the right on?

Note: See TracTickets for help on using tickets.