summaryrefslogtreecommitdiffstats
path: root/amarok/src/engine/helix/hxplayercontrol.h
blob: 8ccdd445963226d2f99899045db58b4707f0b3d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/***************************************************************************
 *   Copyright (C) 2006 Paul Cifarelli <paul@cifarelli.net>                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef _HXSPLAY_INCLUDED_
#define _HXSPLAY_INCLUDED_

#include "helix-sp.h"

class PlayerControl
{
public:
   PlayerControl();
   virtual ~PlayerControl();

   int getError() const { return m_err; }

   // init functions
   void init(const char *corelibpath, const char *pluginslibpath, const char *codecspath, int numPlayers = 1);
   void setOutputSink( HelixSimplePlayer::AUDIOAPI out );
   void setDevice( const char *dev );
   int  initDirectSS();
   void tearDown();

   // player functions
   int  setURL(const char *url, 
               int playerIndex,
               bool islocal = true);
   bool done(int playerIndex);
   void start(int playerIndex, 
              bool fadein = false, 
              unsigned long fadetime = 0);
   void stop(int playerIndex = HelixSimplePlayer::ALL_PLAYERS);
   void pause(int playerIndex);
   void resume(int playerIndex);
   void seek(unsigned long pos, int playerIndex);
   unsigned long where(int playerIndex) const;
   unsigned long duration(int playerIndex) const;
   unsigned long getVolume();
   void setVolume(unsigned long vol);
   void dispatch();
   void cleanUpStream(int playerIndex);
   bool isPlaying(int playerIndex) const;
   bool isLocal(int playerIndex) const;
   int numPlayers() const { return nNumPlayers; }

   // crossfade
   void setFadeout(bool fadeout, unsigned long fadelength, int playerIndex);

   // scope
   void addScopeBuf(struct DelayQueue *item, int playerIndex);
   DelayQueue *getScopeBuf(int playerIndex);
   int getScopeCount(int playerIndex);
   int peekScopeTime(unsigned long &t, int playerIndex);
   void clearScopeQ(int playerIndex);

   // equalizer
   void enableEQ(bool enabled);
   bool isEQenabled();
   void updateEQgains();

   // config stuff
   int numPlugins() const;
   int getPluginInfo(int index, 
                     const char *&description, 
                     const char *&copyright, 
                     const char *&moreinfourl) const;
   const MimeList *getMimeList() const;
   int getMimeListLen() const;

   virtual void play_finished(int /*playerIndex*/) {}

   // stream meta data
   HelixSimplePlayer::metaData *getMetaData(int playerIndex);

   // need to simulate these
   virtual void notifyUser(unsigned long/*code*/, const char */*moreinfo*/, const char */*moreinfourl*/) {}
   virtual void interruptUser(unsigned long/*code*/, const char */*moreinfo*/, const char */*moreinfourl*/) {}
   virtual int print2stdout(const char */*fmt*/, ...) { return 0; }
   virtual int print2stderr(const char */*fmt*/, ...) { return 0; }
   virtual void onContacting(const char */*host*/) {}
   virtual void onBuffering(int /*percentage*/) {}

   // children send functions
   bool sendnotifyuser(unsigned long code, const char *moreinfo, const char *moreinfourl);
   bool sendinterruptuser(unsigned long code, const char *moreinfo, const char *moreinfourl);
   bool sendcontacting(const char *host);
   bool sendbuffering(int percentage);
   
protected:
   bool                 m_eq_enabled;
   int                  m_preamp;
   vector<int>          m_equalizerGains;

private:
   int   m_err;
   pid_t iamparent;
   int   m_index; 
   int   nNumPlayers;
   bool  m_inited;

   // not yet initd when these are set
   HelixSimplePlayer::AUDIOAPI m_api;
   char                       *m_device;

   static const int NUM_SCOPEBUFS = 50;

   struct playerChildren
   {
      int m_pipeA[2];
      int m_pipeB[2];
      pid_t m_pid;
      bool isplaying;
      bool islocal;
      bool isready;
      bool isdead;
      HelixSimplePlayer::metaData *md;
      int                scopecount;
      struct DelayQueue *scopebufhead;
      struct DelayQueue *scopebuftail;
      unsigned long *current_time;
      unsigned long *duration;
      DelayQueue *q;
      int *m_current;
      int *m_consumed;
   }  m_children[2];

   unsigned long m_volume;

   // supported mime type list
   MimeList            *mimehead;
   int                  mimelistlen;

   int m_numPlugins;
   struct pluginInfo
   {
      char *description; 
      char *copyright; 
      char *moreinfourl; 
   } **m_pluginInfo;

   // for sharing
   struct stateStuff
   {
      unsigned long current_time;
      unsigned long duration;
      HelixSimplePlayer::metaData md;
      //DelayQueue q[NUM_SCOPEBUFS];
      //unsigned char b[NUM_SCOPEBUFS][65535];
      int m_current;
      int m_consumed;
   } statestuff[2], *pmapped;

   // msgs are a 1 byte code follows by a 4 byte sz.  sz does NOT include the 5 bytes of this hdr
   enum msgid
   {
      READY,
      INIT,
      SETURL,
      START,
      STOP,
      PAUSE,
      RESUME,
      SEEK,
      DONE,
      SETVOLUME,
      VOLUME,
      OUTPUTSINK,
      DEVICE,
      SETFADE,
      ENABLEEQ,
      UPDATEETQGAINS,
      SCOPEBUF,
      SCOPECLEAR,
      METADATAREQ,
      METADATA,
      PLUGINS,
      MIMETYPES,
      CONTACTING,
      BUFFERING,
      NOTIFYUSER,
      INTERRUPTUSER,
      TEARDOWN,
      ERRORCODE
   };

   // utility functions   
   bool sendsetoutputsink();
   bool sendsetdevice();
   bool sendinit();
   bool sendupdateeqgains();

   static bool getmessage(int fd, msgid &m, unsigned char *buf, int &sz);
   static bool sendmessage(int fd, msgid m, unsigned char *buf, int sz);
   static bool sendrequest(int fd, msgid m) { return (sendmessage(fd, m, 0, 0)); }
   static bool sendready(int fd) { return (sendrequest(fd, READY)); }
   static bool sendsetURL(int fd, const char *url, bool islocal);
   static bool sendstart(int fd, bool fadin, unsigned long fadetime);
   static bool sendstop(int fd) { return (sendrequest(fd, STOP)); }
   static bool sendpause(int fd) { return (sendrequest(fd, PAUSE)); }
   static bool sendresume(int fd) { return (sendrequest(fd, RESUME)); }
   static bool senddone(int fd) { return (sendrequest(fd, DONE)); }
   static bool sendsetvolume(int fd, unsigned long volume);
   static bool sendvolume(int fd, unsigned long volume);
   static bool sendsetfade(int fd, bool fadeout, unsigned long fadelength);
   static bool sendteardown(int fd) { return (sendrequest(fd, TEARDOWN)); }
   static bool sendscopeclear(int fd) { return (sendrequest(fd, SCOPECLEAR)); }

   static bool sendplugins(int fd, HelixSimplePlayer *player);
   static bool sendmimetypes(int fd, HelixSimplePlayer *player);
   static bool sendscopebuf(int fd, DelayQueue *item);
};


#endif