hxplayercontrol.cpp

来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 1,296 行 · 第 1/3 页

CPP
1,296
字号
         //cerr << "j=" << *m_children[i].m_consumed <<          //   " time=" << m_children[i].q[*m_children[i].m_consumed].time <<          //   " etime=" << m_children[i].q[*m_children[i].m_consumed].etime <<          //   " len=" << m_children[i].q[*m_children[i].m_consumed].len << endl;         *m_children[i].m_consumed = (*m_children[i].m_consumed + 1) % NUM_SCOPEBUFS;      }   }}void PlayerControl::cleanUpStream(int playerIndex){   stop(playerIndex);}bool PlayerControl::isPlaying(int playerIndex) const{   return m_children[playerIndex].isplaying;}bool PlayerControl::isLocal(int playerIndex) const{   return m_children[playerIndex].islocal;}void PlayerControl::setFadeout(bool fadeout, unsigned long fadelength, int playerIndex){   sendsetfade(m_children[playerIndex].m_pipeB[1], fadeout, fadelength);}void PlayerControl::addScopeBuf(struct DelayQueue *item, int playerIndex) {   if (playerIndex >=0 && playerIndex < nNumPlayers)   {      if (m_children[playerIndex].scopebuftail)      {         item->fwd = 0;         m_children[playerIndex].scopebuftail->fwd = item;         m_children[playerIndex].scopebuftail = item;         m_children[playerIndex].scopecount++;      }      else      {         item->fwd = 0;         m_children[playerIndex].scopebufhead = item;         m_children[playerIndex].scopebuftail = item;         m_children[playerIndex].scopecount = 1;      }   }}DelayQueue *PlayerControl::getScopeBuf(int playerIndex){   if (playerIndex >=0 && playerIndex < nNumPlayers)   {      struct DelayQueue *item = m_children[playerIndex].scopebufhead;         if (item)      {         m_children[playerIndex].scopebufhead = item->fwd;         m_children[playerIndex].scopecount--;         if (!m_children[playerIndex].scopebufhead)            m_children[playerIndex].scopebuftail = 0;      }      return item;   }   else      return 0;}int PlayerControl::getScopeCount(int playerIndex){   return (playerIndex >= 0 && playerIndex < nNumPlayers ? m_children[playerIndex].scopecount : 0);}int PlayerControl::peekScopeTime(unsigned long &t, int playerIndex){   if (playerIndex >=0 && playerIndex < nNumPlayers)   {      if (m_children[playerIndex].scopebufhead)         t = m_children[playerIndex].scopebufhead->time;      else         return -1;      return 0;   }   return -1;}void PlayerControl::clearScopeQ(int playerIndex){   if (playerIndex < 0)   {      for (int i=0; i<nNumPlayers; i++)         clearScopeQ(i);   }   else   {      sendscopeclear(m_children[playerIndex].m_pipeB[1]);      struct DelayQueue *item;      while ((item = getScopeBuf(playerIndex)))         if (item->allocd)            delete item;   }}void PlayerControl::enableEQ(bool enabled){   int i;   unsigned char c = (char) enabled;   for (i=0; i<nNumPlayers; i++)      sendmessage(m_children[i].m_pipeB[1], ENABLEEQ, (unsigned char *) &c, 1);   m_eq_enabled = enabled;}bool PlayerControl::isEQenabled(){   return m_eq_enabled;}void PlayerControl::updateEQgains(){   sendupdateeqgains();}int PlayerControl::numPlugins() const{   return m_numPlugins;}int PlayerControl::getPluginInfo(int index, const char *&description, const char *&copyright, const char *&moreinfourl) const{   if (m_pluginInfo && index < m_numPlugins)   {      description = m_pluginInfo[index]->description;      copyright   = m_pluginInfo[index]->copyright;      moreinfourl = m_pluginInfo[index]->moreinfourl;            return 0;   }   return -1;}const MimeList *PlayerControl::getMimeList() const{   return mimehead;}int PlayerControl::getMimeListLen() const{   return mimelistlen;}HelixSimplePlayer::metaData *PlayerControl::getMetaData(int playerIndex ){   return m_children[playerIndex].md;}bool PlayerControl::sendsetoutputsink(){   int i;   char c = (char) m_api;   bool ok = false;   for (i=0; i<nNumPlayers; i++)      ok |= sendmessage(m_children[i].m_pipeB[1], OUTPUTSINK, (unsigned char *) &c, 1);    return ok;}bool PlayerControl::sendsetdevice(){   if (!m_device)      return false;   int i, len = strlen( m_device );   bool ok = false;   for (i=0; i<nNumPlayers; i++)      ok |= sendmessage(m_children[i].m_pipeB[1], DEVICE, (unsigned char *) m_device, len + 1);   return ok;}bool PlayerControl::sendinit(){   int i;   bool ok = false;   for (i=0; i<nNumPlayers; i++)      ok |= sendrequest(m_children[i].m_pipeB[1], INIT);   return ok;}bool PlayerControl::sendupdateeqgains(){   unsigned char buf[ 65535 ];   int bandGain;   uint i;   bool ok = false;   memcpy((void *) buf, (void *) &m_preamp, sizeof(m_preamp));   i = m_equalizerGains.size();   memcpy( (void *) &buf[ sizeof(m_preamp) ], (void *) &i, sizeof(int) );   for ( i = 0; i < m_equalizerGains.size(); i++ )   {      bandGain = m_equalizerGains[i];      memcpy((void *)&buf[ sizeof(m_preamp) + (i+1) * sizeof(int) ], (void *) &bandGain, sizeof(int));   }   for ( i = 0; i < (uint) nNumPlayers; i++ )      ok |= sendmessage(m_children[i].m_pipeB[1], UPDATEEQGAINS, buf, sizeof(m_preamp) + (m_equalizerGains.size()+1) * sizeof(int));   return ok;}// children send this!bool PlayerControl::sendnotifyuser(unsigned long code, const char *moreinfo, const char *moreinfourl){   int len1 = strlen(moreinfo), len2 = strlen(moreinfourl), len;   unsigned char buf[65536];   memcpy( (void *) buf, (void *) &code, sizeof(unsigned long) );   len = sizeof(unsigned long);   memcpy( (void *) &buf[ len ], (void *) moreinfo, len1 + 1);   len += len1 + 1;   memcpy( (void *) &buf[ len ], (void *) moreinfourl, len2 + 1);   len += len2 + 1;   return (sendmessage(m_children[m_index].m_pipeA[1], NOTIFYUSER, buf, len));}// children send this!bool PlayerControl::sendinterruptuser(unsigned long code, const char *moreinfo, const char *moreinfourl){   int len1 = strlen(moreinfo), len2 = strlen(moreinfourl), len;   unsigned char buf[65536];   memcpy( (void *) buf, (void *) &code, sizeof(unsigned long) );   len = sizeof(unsigned long);   memcpy( (void *) &buf[ len ], (void *) moreinfo, len1 + 1);   len += len1 + 1;   memcpy( (void *) &buf[ len ], (void *) moreinfourl, len2 + 1);   len += len2 + 1;   return (sendmessage(m_children[m_index].m_pipeA[1], INTERRUPTUSER, buf, len));}// children send this!bool PlayerControl::sendcontacting(const char *host){   int len = strlen(host);   return (sendmessage(m_children[m_index].m_pipeA[1], CONTACTING, (unsigned char *) host, len + 1));}// children send this!bool PlayerControl::sendbuffering(int percentage){   return (sendmessage(m_children[m_index].m_pipeA[1], BUFFERING, (unsigned char *) &percentage, sizeof(unsigned long)));}///////////// statics //////////////bool PlayerControl::getmessage(int fd, msgid &m, unsigned char *buf, int &sz){   int nbytes = 0, bytes = 0;   unsigned char mm;   bytes = read(fd, (void *) &mm, 1);   if (bytes <= 0)      return false;   m = (msgid) mm;   nbytes = bytes;   nbytes = 0;   char *tmp = (char *) &sz;   while ( bytes > 0 && 4 != nbytes )   {      bytes = read(fd, (void *) &tmp[ nbytes ], 4 - nbytes);      nbytes += bytes;   }   if (sz)   {      nbytes = 0;      while ( bytes > 0 && sz != nbytes )      {         bytes = read(fd, (void *) &buf[ nbytes ], sz - nbytes);         nbytes += bytes;      }   }   return (nbytes > 0);}bool PlayerControl::sendmessage(int fd, msgid m, unsigned char *buf, int sz){   unsigned char hdr[5];   hdr[0] = (unsigned char) m;   int ret = 0;   memcpy(&hdr[1], (void *) &sz, 4);   ret = write(fd, (void *) hdr, 5);   if (sz)      ret += write(fd, (void *) buf, sz);   return (ret == (sz + 5));}bool PlayerControl::sendsetURL(int fd, const char *url, bool islocal){   int len = strlen(url);   unsigned char* buf = new unsigned char[ len + 2 ];   buf[0] = (unsigned char) islocal;   memcpy((void *) &buf[1], (void *) url, len + 1);  // go ahead and send the null, what the hell   bool r = sendmessage(fd, SETURL, (unsigned char *)buf, len + 2);   delete [] buf;   return r;}bool PlayerControl::sendstart(int fd, bool fadin, unsigned long fadetime){   unsigned char buf[32];   buf[0] = (unsigned char) fadin;   memcpy( (void *) &buf[1], (void *) &fadetime, sizeof(unsigned long) );   return sendmessage(fd, START, buf, sizeof(unsigned long) + 1);}bool PlayerControl::sendsetvolume(int fd, unsigned long volume){   return sendmessage(fd, SETVOLUME, (unsigned char *) &volume, sizeof(unsigned long));}bool PlayerControl::sendvolume(int fd, unsigned long volume){   return sendmessage(fd, VOLUME, (unsigned char *) &volume, sizeof(unsigned long));}bool PlayerControl::sendsetfade(int fd, bool fadeout, unsigned long fadelength){   unsigned char buf[ sizeof(bool) + sizeof(unsigned long) ];   buf[0] = (char )fadeout;   memcpy((void *) &buf[1], (void *) &fadelength, sizeof(unsigned long));   return sendmessage(fd, SETFADE, buf, 1 + sizeof(unsigned long));}bool PlayerControl::sendplugins(int fd, HelixSimplePlayer *player){   unsigned char buf[65536];   int sz, slen;   int nplugins = player->numPlugins();   const char *description, *copyright, *moreinfourl;   memcpy( (void *) buf, (void *) &nplugins, sizeof(nplugins) );   sz = sizeof(nplugins);   for (int i = 0; i < nplugins; i++)   {      player->getPluginInfo(i, description, copyright, moreinfourl);      slen = strlen(description);      memcpy( (void *) &buf[sz], (void *) description, slen + 1 ); // expecting the null            sz += slen + 1;      slen = strlen(copyright);      memcpy( (void *) &buf[sz], (void *) copyright, slen + 1 ); // expecting the null            sz += slen + 1;      slen = strlen(moreinfourl);      memcpy( (void *) &buf[sz], (void *) moreinfourl, slen + 1 ); // expecting the null            sz += slen + 1;   }   cerr << "CHILD: nplugins " << nplugins << " sz " << sz << endl;   return sendmessage(fd, PLUGINS, buf, sz);}bool PlayerControl::sendmimetypes(int fd, HelixSimplePlayer *player){   unsigned char buf[65536];   int sz, slen;   int mimelistlen = player->getMimeListLen();   const MimeList *mimelisthead = player->getMimeList();   memcpy( (void *) buf, (void *) &mimelistlen, sizeof(mimelistlen) );   sz = sizeof(mimelistlen);   while (mimelisthead)   {      slen = strlen(mimelisthead->mimetypes);      memcpy( (void *) &buf[sz], (void *) mimelisthead->mimetypes, slen + 1 ); // expecting the null            sz += slen + 1;      slen = strlen(mimelisthead->mimeexts);      memcpy( (void *) &buf[sz], (void *) mimelisthead->mimeexts, slen + 1 ); // expecting the null            sz += slen + 1;      mimelisthead = mimelisthead->fwd;   }   return sendmessage(fd, MIMETYPES, buf, sz);}bool PlayerControl::sendscopebuf(int fd, DelayQueue *item){   unsigned char buf[65536];   int len = 0;   if (len + 2 * sizeof(unsigned long) + 4 * sizeof(int) + sizeof(double) < 65536)   {      memcpy( (void *) buf, (void *) &item->len, sizeof(int) ); len += sizeof(int);      memcpy( (void *) &buf[len], (void *) &item->time, sizeof(unsigned long) ); len += sizeof(unsigned long);      memcpy( (void *) &buf[len], (void *) &item->etime, sizeof(unsigned long) ); len += sizeof(unsigned long);      memcpy( (void *) &buf[len], (void *) &item->nchan, sizeof(int) ); len += sizeof(int);      memcpy( (void *) &buf[len], (void *) &item->bps, sizeof(int) ); len += sizeof(int);      memcpy( (void *) &buf[len], (void *) &item->tps, sizeof(double) ); len += sizeof(double);      memcpy( (void *) &buf[len], (void *) &item->spb, sizeof(int) ); len += sizeof(int);      memcpy( (void *) &buf[len], (void *) item->buf, item->len ); len += item->len;            return sendmessage(fd, SCOPEBUF, buf, len);   }   return false;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?