"Fossies" - the Fresh Open Source Software Archive

Member "bayonne-1.2.16/drivers/aculab/record.cpp" (11 Dec 2002, 4881 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 "record.cpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2002 David Kerry.
    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 // As a special exception to the GNU General Public License, permission is
   18 // granted for additional uses of the text contained in its release
   19 // of Bayonne as noted here.
   20 //
   21 // This exception is that permission is hereby granted to link Bayonne
   22 // with the Aculab telephony libraries to produce a executable image
   23 // without requiring Aculab's libraries to be supplied in a free software
   24 // license as long as each source file so linked contains this exclusion
   25 // and the unaltered Aculab source files are made available.
   26 //
   27 // This exception does not however invalidate any other reasons why
   28 // the resulting executable file might be covered by the GNU General
   29 // public license or invalidate the licensing requirements of any
   30 // other component or library.
   31 //
   32 // This exception applies only to the code released by OST under the
   33 // name Bayonne.  If you copy code from other releases into a copy of
   34 // Bayonne, as the General Public License permits, the exception does not
   35 // apply to the code that you add in this way.  To avoid misleading
   36 // anyone as to the status of such modified files, you must delete
   37 // this exception notice from them.
   38 //
   39 // If you write modifications of your own to Bayonne, it is your choice
   40 // whether to permit this exception to apply to your modifications.
   41 // If you do not wish that, delete this exception notice, at which
   42 // point the terms of your modification would be covered under the GPL
   43 // as explicitly stated in "COPYING".
   44 
   45 
   46 #include "driver.h"
   47 
   48 #ifdef    CCXX_NAMESPACES
   49 using namespace std;
   50 namespace ost {
   51 #endif
   52 
   53 bool AculabTrunk::recordHandler(TrunkEvent *event)
   54 {
   55     struct tm *dt, tbuf;
   56     struct stat ino;
   57     char buffer[32];
   58     const char *ext;
   59     Audio::Info info;
   60     unsigned mask;
   61     
   62     switch(event->id)
   63     {
   64     case TRUNK_STOP_STATE:
   65         endTimer();
   66         handler = &AculabTrunk::stepHandler;
   67         StopRecordFile();
   68         Trunk::flags.dsp=DSP_MODE_INACTIVE;
   69         return true;
   70     case TRUNK_DTMF_KEYUP:
   71         mask = (1 << event->parm.dtmf.digit);
   72         if(!(mask & data.record.term)) {
   73             return false;
   74         }
   75         endTimer();
   76         StopRecordFile();
   77         Trunk::flags.dsp=DSP_MODE_INACTIVE;
   78         trunkSignal(TRUNK_SIGNAL_STEP);
   79         handler = &AculabTrunk::stepHandler;
   80         return true;
   81     case TRUNK_ENTER_STATE:
   82         enterState("record");
   83         status[id] = 'r';
   84 
   85         setTimer(data.record.timeout);
   86         if(data.record.term) {
   87             setDTMFDetect(true);
   88         }
   89         else {
   90             Trunk::setDTMFDetect();
   91         }
   92 
   93         ext = strrchr(data.record.name, '/');
   94         if(!ext)
   95             ext = data.record.name;
   96 
   97         ext = strrchr(ext, '.');
   98 
   99         info.format = raw;
  100         info.encoding = mulawAudio;
  101         info.order = 0;
  102         info.annotation = (char *)data.record.annotation;
  103         info.rate = 8000;
  104 
  105         if(!ext) 
  106         {
  107             ext = data.record.extension;
  108             strcat(data.record.name, ext);
  109         }
  110 
  111         if(!stricmp(ext, ".al")) {
  112             info.encoding = alawAudio;
  113         }
  114         else if(!stricmp(ext, ".au"))
  115         {
  116             info.format = sun;
  117             info.order = __BIG_ENDIAN;
  118         }
  119         else if(!stricmp(ext, ".wav"))
  120         {
  121             info.format = riff;
  122             info.order = __LITTLE_ENDIAN;
  123         }
  124 
  125         close();
  126 
  127         filename=data.record.name;
  128 
  129         if(data.record.offset != (unsigned long)-1)
  130         {
  131             open(data.record.name);
  132             setPosition(data.record.offset);
  133         }
  134         else if(data.record.append)
  135             open(data.record.name);
  136         else
  137             create(data.record.name, &info);
  138         
  139         setSymbol(SYM_OFFSET, "0");
  140         setSymbol(SYM_RECORDED, "0");
  141 
  142         if(!isOpen())
  143         {
  144             slog(Slog::levelError) << name<<": "<<data.record.name << ": cannot open" << endl;
  145             setSymbol(SYM_ERROR, "record-failed");
  146             trunkSignal(TRUNK_SIGNAL_ERROR);
  147             handler = &AculabTrunk::stepHandler;
  148             return true;
  149         }
  150         if(data.record.append) {
  151             setPosition();
  152         }
  153 
  154         dt = localtime_r(&ino.st_ctime, &tbuf);
  155         sprintf(buffer, "%04d%02d%02d,%02d%02d%02d",
  156             dt->tm_year + 1900, dt->tm_mon + 1, dt->tm_mday,
  157             dt->tm_hour, dt->tm_min, dt->tm_sec);
  158         setSymbol(SYM_CREATED, buffer);
  159                 if(data.record.info)
  160                 {
  161                         sprintf(buffer, "%ld", getPosition());
  162                         setSymbol(SYM_OFFSET, buffer);
  163                 }
  164         else
  165             StartRecordFile();
  166         Trunk::flags.dsp=DSP_MODE_VOICE;
  167         return true;
  168     }
  169     return false;
  170 }
  171 
  172 #ifdef    CCXX_NAMESPACES
  173 };
  174 #endif