AmPlaylist.h

Go to the documentation of this file.
00001 /*
00002  * $Id: AmPlaylist.h 711 2008-02-10 18:52:44Z sayer $
00003  *
00004  * Copyright (C) 2006 iptelorg GmbH
00005  *
00006  * This file is part of sems, a free SIP media server.
00007  *
00008  * sems is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * sems is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License 
00024  * along with this program; if not, write to the Free Software 
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  */
00028 #ifndef AmPlaylist_h
00029 #define AmPlaylist_h
00030 
00031 #include "AmAudio.h"
00032 #include "AmThread.h"
00033 #include "AmEventQueue.h"
00034 
00035 #include <deque>
00036 using std::deque;
00038 struct AmPlaylistItem
00039 {
00040 
00041   AmAudio* play;
00042   AmAudio* record;
00043 
00044   AmPlaylistItem(AmAudio* play,
00045                  AmAudio* record)
00046     : play(play), record(record) {}
00047 
00048   virtual ~AmPlaylistItem() { }
00049 };
00050 
00059 class AmPlaylist: public AmAudio
00060 {
00061     
00062   AmMutex                items_mut;
00063   deque<AmPlaylistItem*> items;
00064 
00065   AmMutex                cur_mut;
00066   AmPlaylistItem*        cur_item;
00067 
00068   AmEventQueue*          ev_q;
00069 
00070   void updateCurrentItem();
00071   void gotoNextItem(bool notify = true);
00072     
00073  protected:
00074   // Fake implement AmAudio's pure virtual methods
00075   int read(unsigned int user_ts, unsigned int size){ return -1; }
00076   int write(unsigned int user_ts, unsigned int size){ return -1; }
00077     
00078   // override AmAudio
00079   int get(unsigned int user_ts, unsigned char* buffer, unsigned int nb_samples);
00080   int put(unsigned int user_ts, unsigned char* buffer, unsigned int size);
00081         
00082  public:
00083   AmPlaylist(AmEventQueue* q);
00084   ~AmPlaylist();
00085     
00086   bool isEmpty();
00087 
00088   void addToPlaylist(AmPlaylistItem* item);
00089   void addToPlayListFront(AmPlaylistItem* item);
00090   void close(bool notify = true);
00091 };
00092 
00096 class AmPlaylistSeparatorEvent : 
00097   public AmEvent {
00098 public:
00099   AmPlaylistSeparatorEvent(int id)
00100     : AmEvent(id) { }
00101 };
00102 
00110 class AmPlaylistSeparator 
00111   : public AmAudio {
00112   bool notified;
00113   AmEventQueue* ev_q;
00114   int id;
00115 public:  
00116   AmPlaylistSeparator(AmEventQueue* q, int id)
00117     : ev_q(q), notified(false), id(id) { }
00118   ~AmPlaylistSeparator() { }
00119 
00120   int read(unsigned int user_ts, unsigned int size){
00121     if (!notified) 
00122       ev_q->postEvent(new AmPlaylistSeparatorEvent(id)); 
00123     notified = true; 
00124     return 0; 
00125   }
00126   int write(unsigned int user_ts, unsigned int size){
00127     return read(user_ts, size);
00128   }
00129 };
00130 
00131 
00132 
00133 
00134 #endif

Generated on Fri May 16 12:02:05 2008 for SEMS by  doxygen 1.5.1
Home |  Recent changes |  Search |  Glossary |  Sitemap |  Login