Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Foobar as a UPnP renderer (player (Read 20063 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Foobar as a UPnP renderer (player

Reply #25
Now I need to know what functions to call:
to add filename to playlist
to play the file
pause
stop
get file position ifo during playback
and set the seek postiion

Can anyone help with this?

Darren

Foobar as a UPnP renderer (player

Reply #26
Can I do that from the UPnP code that is now running in another thread?
Yes.
If I include the foobar.h header on the upnp.c i get the 100+ errors report.
Because including C++ code from C file won't work. You will need to convert upnp.c to C++.


I tried invoking a foobar play command in the thread that is running the UPnP stack.
I get an error that the command must be run in the original thread.

How can I do that?

Thank you
Darren

Getting to the home stretch on this! (although my try to rewrite it later more colsly assoc. with Foobar2000)

Foobar as a UPnP renderer (player

Reply #27
Use main_thread_callback.

ETA: Sorry about that previous statement, it should have been rather "yes, unless the command can be called from the main thread only". Not all API functions have to.
Full-quoting makes you scroll past the same junk over and over.

Foobar as a UPnP renderer (player

Reply #28
Thank you!  Could you please give me an example of using the main_thread_callback in conjunction with the play command?  Please?

Darren

Foobar as a UPnP renderer (player

Reply #29
Depends on where you want to use it. If it's from an existing class, you can simply derive from main_thread_callback and provide its service interface. I assume you want to plug it into existing C code instead, so I'd use a helper class for delegation like this (not guaranteed to be 100% correct, I'm writing it out of my head only):
Code: [Select]
class PlayAction : public main_thread_callback {
  protected:
    playback_control::t_track_command m_command;
    bool m_paused;

  public:
    PlayAction(playback_control::t_track_command p_command = playback_control::track_command_play, bool p_paused = false)
      : m_command(p_command),
        m_paused(p_paused)
    {
    }

    virtual void callback_run()
    {
      static_api_ptr_t<playback_control> pc;
      pc->start(m_command, m_paused);
    }
};

// ...

void on_command_play()
{
  static_api_ptr_t<main_thread_callback_manager> mtcm;
  mtcm->add_callback(new service_impl_t<PlayAction>(playback_control::track_command_play));
}
Note I didn't know what "play command" you really had had in mind, but I used playback_control::start() as to show how to pass any arguments.

Anyway, this is a generic example. If you are going to support several commands, creating such class for each of them might be unnecessarily complex. In that case, it might be better to have just one class, encompassing interface for more commands at once, which will then invoke different methods in its callback_run() depending on what has been set. Or have most of the logic in the class itself and pass only the original events into it. There are many solutions as always, use the one which suits you best.
Full-quoting makes you scroll past the same junk over and over.

Foobar as a UPnP renderer (player

Reply #30
I am figuring this out.  Still having a little trouble.  Is there a way to access the main_thread_callback for only one instance of one command?  What would the code look like for that? (instead of creating a class)

Thank you

Darren