LCOV - code coverage report
Current view: top level - src/media/audio/sound - dtmf.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 5 27 18.5 %
Date: 2024-04-25 08:05:53 Functions: 1 3 33.3 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
       5             :  *  Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
       6             :  *
       7             :  *  This program is free software; you can redistribute it and/or modify
       8             :  *  it under the terms of the GNU General Public License as published by
       9             :  *  the Free Software Foundation; either version 3 of the License, or
      10             :  *  (at your option) any later version.
      11             :  *
      12             :  *  This program is distributed in the hope that it will be useful,
      13             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :  *  GNU General Public License for more details.
      16             :  *
      17             :  *  You should have received a copy of the GNU General Public License
      18             :  *  along with this program; if not, write to the Free Software
      19             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
      20             :  */
      21             : 
      22             : #include "dtmf.h"
      23             : 
      24             : namespace jami {
      25             : 
      26          33 : DTMF::DTMF(unsigned int sampleRate, AVSampleFormat sampleFormat)
      27          33 :     : currentTone_(0)
      28          33 :     , newTone_(0)
      29          33 :     , dtmfgenerator_(sampleRate, sampleFormat)
      30          33 : {}
      31             : 
      32             : void
      33           0 : DTMF::startTone(char code)
      34             : {
      35           0 :     newTone_ = code;
      36           0 : }
      37             : 
      38             : bool
      39           0 : DTMF::generateDTMF(AVFrame* buffer)
      40             : {
      41             :     try {
      42           0 :         if (currentTone_ != 0) {
      43             :             // Currently generating a DTMF tone
      44           0 :             if (currentTone_ == newTone_) {
      45             :                 // Continue generating the same tone
      46           0 :                 dtmfgenerator_.getNextSamples(buffer);
      47           0 :                 return true;
      48           0 :             } else if (newTone_ != 0) {
      49             :                 // New tone requested
      50           0 :                 dtmfgenerator_.getSamples(buffer, newTone_);
      51           0 :                 currentTone_ = newTone_;
      52           0 :                 return true;
      53             :             } else {
      54             :                 // Stop requested
      55           0 :                 currentTone_ = newTone_;
      56           0 :                 return false;
      57             :             }
      58             :         } else {
      59             :             // Not generating any DTMF tone
      60           0 :             if (newTone_) {
      61             :                 // Requested to generate a DTMF tone
      62           0 :                 dtmfgenerator_.getSamples(buffer, newTone_);
      63           0 :                 currentTone_ = newTone_;
      64           0 :                 return true;
      65             :             } else
      66           0 :                 return false;
      67             :         }
      68           0 :     } catch (const DTMFException& e) {
      69             :         // invalid key
      70           0 :         return false;
      71           0 :     }
      72             : }
      73             : 
      74             : } // namespace jami

Generated by: LCOV version 1.14