Using audio in user plugins

Discussion about user contributed plugins

Moderator: Moderator

Fredde
veteran
Posts: 288
Joined: Tue Dec 06, 2005 7:18 am
Location: Sweden

Using audio in user plugins

Postby Fredde » Thu Mar 13, 2008 7:27 am

I have watched magicamun development of the vbox plugin (looks great btw). It seems to be some trouble with playing audio.

I also try to play audio from the python plugin, but it doesn't really work as expected. I use the following code to lauch a media-file:

Code: Select all

Simplefile track;
track.path = "path to file";
track.name = "name of file";
track.type = "type of track";

S_Audio_s::get_instance()->p->set_cur_nr(track);
S_Audio_s::get_instance()->p->addfile(track);
S_Audio_s::get_instance()->p->set_streaming(track.type == "web");


The code kind of works :?

The media-file starts playing, but when it ends one of two things can occur depending on the current playlist.

1. The playlist is empty
mms crash

2. The playlist is not empty
mms continue to play audio files from the playlist.

The crash (empty playlist) comes from the following code in plugins/feature/audio/audio.hpp (method check_audio_state)

Code: Select all

...
        else if ((opts.shuffle() == dgettext("mms-audio", "off") && audio_state->p->p_cur_nr() != playlist.back()) ||
            opts.shuffle() != dgettext("mms-audio", "off") || conv::stob(opts.repeat()) ||
            audio_state->queue_size() > 0) {
          // next takes care of checking random modes
          audio_state->p->next();
          update_playlist_view();
...

I think it's the comparison below that generates the crash:

Code: Select all

audio_state->p->p_cur_nr() != playlist.back()

It compairs a SimpleFile to nothing (code in operator!=) which crash mms.

It seems the audio in mms is depending on the playlist and it makes it hard to use it in other plugins.

User avatar
magicamun
master
Posts: 688
Joined: Thu Feb 28, 2008 7:42 am
Location: Germany

Postby magicamun » Thu Mar 13, 2008 7:54 am

Hi Fredde - this is what i PN'ed today to arj :

Hi Andreas - i found out, that restore_playback is never reached when the playlist wasn't active.

When starting without having an active playlist nothing is to be suspended,
In this case pos is undefined - its negative values. Furthermore i think that restore_playback should look like this one - but as stated in the beginninng - restore_playback is never reached, when no playlist was/is active

It still does not work for this case - but i think it's because of the above

And the Info is never displayed - this is very strange to me.

Code:

Code: Select all

void Audio_s::suspend_normal_audio_and_play_track(const Simplefile &file)
{
     pos = p->getpos();
     printf("position in playlist %d\n", pos);
   if (playing) {
      printf("suspend\n");
      suspend_playback();
   }
  p->addfile(file);
}

void Audio_s::suspend_playback()
{
  suspended = true;

  pos = p->getpos();
  printf("position in playlist %d\n", pos);
  track = p->p_cur_nr();
  p->stop();

  sleep(1);
}

void Audio_s::restore_playback()
{
   printf("restore\n");
  if (suspended) {
    audio->check_mount_before(track.type);
    p->addfile(track);
    p->set_cur_nr(track);
    p->setpos(pos);
    suspended = false;
  } else {
     printf("Stop\n");
     p->stop();
  }
}



At least within mms (C-Code) the Crash does not occur - but there is some strange behaviour at least - we're two now ;-)

Fredde
veteran
Posts: 288
Joined: Tue Dec 06, 2005 7:18 am
Location: Sweden

Postby Fredde » Thu Mar 13, 2008 9:14 am

I have tried different ways to play a audio file (also tried suspend_normal_audio_and_play_track method).

If the playlist is empty mms crash (after audio file is complete) with the following back trace:

Code: Select all

#0  0x0808dfba in Simplefile::operator!= ()
#1  0xb7534e2c in AudioTemplate<Simplefile>::check_audio_state ()
   from /usr/lib/mms/plugins/lib_feature_audio.so
#2  0xb750a45c in boost::detail::function::void_function_obj_invoker0<boost::_bi::bind_t<void, boost::_mfi::mf0<void, Audio>, boost::_bi::list1<boost::_bi::value<Audio*> > >, void>::invoke () from /usr/lib/mms/plugins/lib_feature_audio.so
#3  0x0808d7c6 in boost::function0<void, std::allocator<void> >::operator() ()
#4  0x080b43c6 in Updater::run ()
#5  0xb7e3c813 in ?? () from /usr/lib/libccgnu2-1.5.so.0
#6  0xb7db14bb in start_thread () from /lib/libpthread.so.0
#7  0xb7a3576e in clone () from /lib/libc.so.6

Fredde
veteran
Posts: 288
Joined: Tue Dec 06, 2005 7:18 am
Location: Sweden

Postby Fredde » Thu Mar 13, 2008 9:52 am

magicamun wrote:At least within mms (C-Code) the Crash does not occur - but there is some strange behaviour at least - we're two now ;-)


Exactly how (code) do you start an audio file? Maybe I'am doing something wrong :(

User avatar
magicamun
master
Posts: 688
Joined: Thu Feb 28, 2008 7:42 am
Location: Germany

Postby magicamun » Thu Mar 13, 2008 7:15 pm

that's how :

Code: Select all

              sprintf(buffer, "%s %s %s %s", dgettext("mms-vbox", "Call from"), callerid.c_str(), dgettext("mms-vbox", "at"), timestr.c_str());
               buf.assign(buffer);
               
              cur_track.id = 4711;
              cur_track.name = buf;
              cur_track.path = "/tmp/mms-vbox.wav";
              cur_track.type = "media-file";
              
              printf("%s\n", buf.c_str());
              as->suspend_normal_audio_and_play_track(cur_track);
              printf("bla\n");
              


are you using rc4 ? - that crashed too - i am on bzr ...

[EDIT] : If the Playlist is empty it crashes - if playlist is not empty - it doesn't

User avatar
arj
Site Admin
Posts: 2316
Joined: Thu Dec 01, 2005 8:51 pm
Location: Denmark
Contact:

Postby arj » Thu Mar 13, 2008 11:40 pm

Yeah audio playback is currently tied too much to the playlist. Radio is even implemented by adding itself to the playlist. :( I'll take a look this weekend.

Edit: 1x666 :twisted: :twisted: :twisted:

User avatar
arj
Site Admin
Posts: 2316
Joined: Thu Dec 01, 2005 8:51 pm
Location: Denmark
Contact:

Postby arj » Fri Mar 14, 2008 8:53 pm

This should have been fixed in revno 1486. Please read changelog to see what has changed.

Thanks guys!

User avatar
magicamun
master
Posts: 688
Joined: Thu Feb 28, 2008 7:42 am
Location: Germany

Postby magicamun » Sat Mar 15, 2008 9:38 am

arj: I am absolutely sorry - it doesn't fix the problem :

If Playlist is empty - Crash

If Playlist is not empty - it Starts playing playlist - even if it wasn#t active - and with that i get a dialog-error "Konnte die Datei nicht öffnen" - "Could not open file" - but it continues playing

If Playlost was active and not empty - everything is fine.

btw : I am on revision 1487 actually

User avatar
arj
Site Admin
Posts: 2316
Joined: Thu Dec 01, 2005 8:51 pm
Location: Denmark
Contact:

Postby arj » Sat Mar 15, 2008 11:08 am

How exactly are you using the api?

suspend should only be used if something is playing. Otherwise one should use the external_plugin_playback function.

User avatar
magicamun
master
Posts: 688
Joined: Thu Feb 28, 2008 7:42 am
Location: Germany

Postby magicamun » Sat Mar 15, 2008 1:11 pm

my fault - everythings fine now

User avatar
arj
Site Admin
Posts: 2316
Joined: Thu Dec 01, 2005 8:51 pm
Location: Denmark
Contact:

Postby arj » Sat Mar 15, 2008 1:15 pm

Goodie. Is it working fine for you also Fredde?

Fredde
veteran
Posts: 288
Joined: Tue Dec 06, 2005 7:18 am
Location: Sweden

Postby Fredde » Sat Mar 15, 2008 3:51 pm

Yeah! Working, no crash when playlist is empty :D

Fredde
veteran
Posts: 288
Joined: Tue Dec 06, 2005 7:18 am
Location: Sweden

Postby Fredde » Mon Mar 17, 2008 8:20 am

I think I found a bug using the method external_plugin_playback.

The attribute is_external_source is never set to false after using the above method.

This means that using audio in a plugin and then playing a track from the mms playlist (containing two or more tracks,
repeat = no, shuffle = off), it will never continue to the next track (automatically) in the mms playlist.

User avatar
magicamun
master
Posts: 688
Joined: Thu Feb 28, 2008 7:42 am
Location: Germany

Postby magicamun » Mon Mar 17, 2008 2:10 pm

confirmed :-(

User avatar
arj
Site Admin
Posts: 2316
Joined: Thu Dec 01, 2005 8:51 pm
Location: Denmark
Contact:

Postby arj » Mon Mar 17, 2008 7:37 pm

Fixed in revno 1499. Thanks


Return to “user plugins”

Who is online

Users browsing this forum: No registered users and 2 guests