"Fossies" - the Fresh Open Source Software Archive

Member "bayonne-1.2.16/server/audio.cpp" (11 Dec 2002, 2854 Bytes) of package /linux/misc/old/bayonne-1.2.16.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "audio.cpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2000-2001 Open Source Telecom Corporation.
    2 //  
    3 // This program is free software; you can redistribute it and/or modify
    4 // it under the terms of the GNU General Public License as published by
    5 // the Free Software Foundation; either version 2 of the License, or
    6 // (at your option) any later version.
    7 // 
    8 // This program is distributed in the hope that it will be useful,
    9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11 // GNU General Public License for more details.
   12 // 
   13 // You should have received a copy of the GNU General Public License
   14 // along with this program; if not, write to the Free Software 
   15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   16 
   17 #include "server.h"
   18 
   19 #ifdef  CCXX_NAMESPACES
   20 namespace ost {
   21 using namespace std;
   22 #endif
   23 
   24 #ifdef  XML_SCRIPTS
   25 
   26 URLAudio::URLAudio() :
   27 AudioFile(), URLStream()
   28 {
   29     offset = 0;
   30     setProtocol(protocolHttp1_0);
   31 }
   32 
   33 URLAudio::~URLAudio()
   34 {
   35     AudioFile::close();
   36 }
   37 
   38 bool URLAudio::afOpen(const char *path)
   39 {
   40     offset = 0;
   41 
   42     if(!strnicmp(path, "http:", 5))
   43         setProxy(keyproxy.getHTTPServer(), keyproxy.getHTTPPort());
   44     else
   45         setProxy(NULL, 0);
   46 
   47     if(URLStream::errSuccess == get(path, 0))
   48     {
   49         file.fd = so;
   50         return true;
   51     }
   52     file.fd = -1;
   53     return false;
   54 }
   55 
   56 bool URLAudio::isOpen(void)
   57 {
   58     if(so > -1)
   59         return true;
   60 
   61     return false;
   62 }
   63 
   64 bool URLAudio::hasPositioning(void)
   65 {
   66     if(Socket::state == Socket::STREAM)
   67         return true;
   68 
   69     return false;
   70 }
   71 
   72 unsigned long URLAudio::getTransfered(void)
   73 {
   74     unsigned long pos;
   75 
   76     if(so < 0)
   77         return 0;
   78 
   79     if(Socket::state == Socket::STREAM)
   80         pos = ::lseek(so, 0l, SEEK_CUR) - getHeader();
   81     else
   82         pos = offset;
   83 
   84     return toSamples(getEncoding(), pos);
   85 }
   86 
   87 bool URLAudio::afPeek(unsigned char *buffer, unsigned len)
   88 {
   89     int got;
   90     if(Socket::state == Socket::STREAM)
   91         got = ::read(so, buffer, len);
   92     else
   93         got = ::recv(so, buffer, len, MSG_PEEK | MSG_WAITALL);
   94     if(got < (int)len)
   95         return false;
   96     return true;
   97 }
   98 
   99 bool URLAudio::afSeek(unsigned long pos)
  100 {
  101     char temp[128];
  102     unsigned len;
  103     if(Socket::state == Socket::STREAM)
  104     {
  105         ::lseek(so, pos, SEEK_SET);
  106         return true;
  107     }
  108     if(offset == pos)
  109         return true;
  110 
  111     if(offset > pos)
  112         return false;   
  113 
  114     while(offset < pos)
  115     {
  116         len = pos - offset;
  117         if(len < sizeof(temp))
  118             len = sizeof(temp);
  119         len = ::recv(so, temp, len, MSG_WAITALL);
  120         if(len < 1)
  121             return false;
  122         offset += len;
  123     }
  124     return true;
  125 }
  126 
  127 int URLAudio::afRead(unsigned char *buffer, unsigned len)
  128 {
  129     if(Socket::state == Socket::STREAM)
  130         len = ::read(so, buffer, len);
  131     else
  132         len = ::recv(so, buffer, len, MSG_WAITALL);
  133     if(len > 0)
  134         offset += len;
  135     return len;
  136 }
  137 
  138 
  139 void URLAudio::afClose(void)
  140 {
  141     if(file.fd != -1 && file.fd != so)
  142         ::close(file.fd);
  143     file.fd = -1;
  144     URLStream::close();
  145 }
  146 
  147 #endif
  148 
  149 #ifdef  CCXX_NAMESPACES
  150 };
  151 #endif
  152 
  153 
  154