[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdesupport/akode/lib
From:       Allan Sandfeld Jensen <kde () carewolf ! com>
Date:       2005-11-01 13:32:21
Message-ID: 1130851941.843235.12262.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 476527 by carewolf:

Add load-function for streams, and monitor for scopes.


 M  +42 -4     player.cpp  
 M  +50 -24    player.h  


--- trunk/kdesupport/akode/lib/player.cpp #476526:476527
@@ -55,10 +55,13 @@
                    , volume_filter(0)
                    , sink(0)
                    , manager(0)
+                   , monitor(0)
                    , decoder_plugin(0)
                    , resampler_plugin(0)
                    , sample_rate(0)
                    , state(Closed)
+                   , my_file(false)
+                   , start_pos(0)
                    , halt(false)
                    , pause(false)
                    , detached(false)
@@ -75,6 +78,7 @@
     VolumeFilter* volatile volume_filter;
     Sink *sink;
     Player::Manager *manager;
+    Player::Monitor *monitor;
 
     const char* decoder_plugin;
     const char* resampler_plugin;
@@ -85,6 +89,8 @@
 
     unsigned int sample_rate;
     State state;
+    bool my_file;
+    int start_pos;
 
     volatile bool halt;
     volatile bool pause;
@@ -103,7 +109,8 @@
         buffered_decoder.closeDecoder();
 
         delete frame_decoder;
-        delete src;
+        if (my_file)
+            delete src;
 
         frame_decoder = 0;
         src = 0;
@@ -163,6 +170,9 @@
             if (d->volume_filter)
                 d->volume_filter->doFrame(out_frame);
 
+            if (d->monitor)
+                d->monitor->writeFrame(out_frame);
+
             no_error = d->sink->writeFrame(out_frame);
 
             if (!no_error) {
@@ -274,10 +284,33 @@
     }
     // Some of the later code expects it to be closed
     d->src->close();
+    d->my_file = true;
 
-//    d->src = new MMapFile(filename.c_str());
-//    d->src = new LocalFile(filename.c_str());
+    return load();
+}
 
+bool Player::load(File *file) {
+    if (state() == Closed) return false;
+
+    if (state() == Paused || state() == Playing)
+        stop();
+
+    if (state() == Loaded)
+        unload();
+
+    assert(state() == Open);
+
+    if (!file->openRO())
+        return false;
+    file->close();
+
+    d->src = file;
+    d->my_file = false;
+
+    return load();
+}
+
+bool Player::load() {
     if (d->decoder_plugin) {
         if (!d->decoder_handler.load(d->decoder_plugin))
             AKODE_DEBUG("Could not load " << d->decoder_plugin << "-decoder");
@@ -400,7 +433,8 @@
     assert(state() == Loaded);
 
     delete d->frame_decoder;
-    delete d->src;
+    if (d->my_file)
+        delete d->src;
 
     d->frame_decoder = 0;
     d->src = 0;
@@ -584,6 +618,10 @@
     d->manager = manager;
 }
 
+void Player::setMonitor(Monitor *monitor) {
+    d->monitor = monitor;
+}
+
 void Player::setState(Player::State state) {
     d->setState(state);
 }
--- trunk/kdesupport/akode/lib/player.h #476526:476527
@@ -29,7 +29,9 @@
 class Sink;
 class Decoder;
 class Resampler;
+class AudioFrame;
 
+
 //! An implementation of a multithreaded aKode-player
 
 /*!
@@ -58,13 +60,24 @@
     void close();
 
     /*!
-     * Load the file \a filename and prepare for playing.
-     * Return false if the file cannot be loaded or decoded.
+     * Loads the file \a filename and prepares for playing.
+     * Returns false if the file cannot be loaded or decoded.
      *
      * State: \a Open -> \a Loaded
      */
     bool load(const char* filename);
+
     /*!
+     * Loads the file \a file and prepares for playing.
+     * Returns false if the file cannot be loaded or decoded.
+     *
+     * This version allows for overloaded aKode::File objects; usefull for streaming.
+     *
+     * State: \a Open -> \a Loaded
+     */
+    bool load(File* file);
+
+    /*!
      * Unload the file and release any resources allocated while loaded
      *
      * State: \a Loaded -> \a Open
@@ -86,6 +99,7 @@
     void stop();
     /*!
      * Waits for the file to finish playing (eof or error) and calls stop.
+     * This blocks the calling thread, possibly indefinitely if the source is a radio stream.
      *
      * State: \a Playing -> \a Loaded
      */
@@ -110,12 +124,6 @@
      */
     void resume();
 
-    /* Not implemented!
-     * Prepare to crossfade current file, it can now be safely unloaded and a new file loaded.
-     * The crossfade will last for up to \a ms milliseconds.
-     */
-    void crossfade(unsigned int ms) { /*unused arg: */ (void)ms; }
-
     /*!
      * Set the software-volume to \a v. Use a number between 0.0 and 1.0.
      *
@@ -161,25 +169,26 @@
      */
     class Manager {
         Player* m_player;
-        public:
-            /*!
-             * Called for all state changes
-             */
-            virtual void stateChangeEvent(Player::State) {};
-            /*!
-             * Called when a decoder halts because it has reached end of file.
-             * The callee should effect a Player::stop()
-             */
-            virtual void eofEvent() {};
-            /*!
-             * Called when a decoder halts because of a fatal error.
-             * The callee should effect a Player::stop()
-             */
-            virtual void errorEvent() {};
+    public:
+        /*!
+         * Called for all user-generated state changes (User thread)
+         */
+        virtual void stateChangeEvent(Player::State) {};
+        /*!
+         * Called when a decoder halts because it has reached end of file (Local thread).
+         * The callee should effect a Player::stop()
+         */
+        virtual void eofEvent() {};
+        /*!
+         * Called when a decoder halts because of a fatal error (Local thread).
+         * The callee should effect a Player::stop()
+         */
+        virtual void errorEvent() {};
     };
 
     /*!
-     * Sets an associated callback interface
+     * Sets an associated callback interface.
+     * Can only be set before open() is called.
      */
     void setManager(Manager *manager);
 
@@ -192,9 +201,26 @@
      */
     void setResamplerPlugin(const char* plugin);
 
+    /*!
+     * A Monitor is sink-like device.
+     */
+    class Monitor {
+    public:
+        virtual bool writeFrame(AudioFrame* frame) = 0;
+    };
+
+    /*!
+     * Sets a secondary sink to monitor output
+     * Can only be set before play() is called.
+     */
+    void setMonitor(Monitor *monitor);
+
+
     struct private_data;
 private:
     private_data *d;
+
+    bool load();
     void setState(State state);
 };
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic