home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / openh323.tar.gz / openh323.tar / openh323 / src / mediafmt.cxx < prev    next >
C/C++ Source or Header  |  2002-12-03  |  9KB  |  329 lines

  1. /*
  2.  * mediafmt.cxx
  3.  *
  4.  * Media Format descriptions
  5.  *
  6.  * Open H323 Library
  7.  *
  8.  * Copyright (c) 1999-2000 Equivalence Pty. Ltd.
  9.  *
  10.  * The contents of this file are subject to the Mozilla Public License
  11.  * Version 1.0 (the "License"); you may not use this file except in
  12.  * compliance with the License. You may obtain a copy of the License at
  13.  * http://www.mozilla.org/MPL/
  14.  *
  15.  * Software distributed under the License is distributed on an "AS IS"
  16.  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  17.  * the License for the specific language governing rights and limitations
  18.  * under the License.
  19.  *
  20.  * The Original Code is Open H323 Library.
  21.  *
  22.  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
  23.  *
  24.  * Contributor(s): ______________________________________.
  25.  *
  26.  * $Log: mediafmt.cxx,v $
  27.  * Revision 1.11  2002/12/03 09:20:01  craigs
  28.  * Fixed problem with RFC2833 and a dynamic RTP type using the same RTP payload number
  29.  *
  30.  * Revision 1.10  2002/12/02 03:06:26  robertj
  31.  * Fixed over zealous removal of code when NO_AUDIO_CODECS set.
  32.  *
  33.  * Revision 1.9  2002/10/30 05:54:17  craigs
  34.  * Fixed compatibilty problems with G.723.1 6k3 and 5k3
  35.  *
  36.  * Revision 1.8  2002/08/05 10:03:48  robertj
  37.  * Cosmetic changes to normalise the usage of pragma interface/implementation.
  38.  *
  39.  * Revision 1.7  2002/06/25 08:30:13  robertj
  40.  * Changes to differentiate between stright G.723.1 and G.723.1 Annex A using
  41.  *   the OLC dataType silenceSuppression field so does not send SID frames
  42.  *   to receiver codecs that do not understand them.
  43.  *
  44.  * Revision 1.6  2002/01/22 07:08:26  robertj
  45.  * Added IllegalPayloadType enum as need marker for none set
  46.  *   and MaxPayloadType is a legal value.
  47.  *
  48.  * Revision 1.5  2001/12/11 04:27:28  craigs
  49.  * Added support for 5.3kbps G723.1
  50.  *
  51.  * Revision 1.4  2001/09/21 02:51:45  robertj
  52.  * Implemented static object for all "known" media formats.
  53.  * Added default session ID to media format description.
  54.  *
  55.  * Revision 1.3  2001/05/11 04:43:43  robertj
  56.  * Added variable names for standard PCM-16 media format name.
  57.  *
  58.  * Revision 1.2  2001/02/09 05:13:56  craigs
  59.  * Added pragma implementation to (hopefully) reduce the executable image size
  60.  * under Linux
  61.  *
  62.  * Revision 1.1  2001/01/25 07:27:16  robertj
  63.  * Major changes to add more flexible OpalMediaFormat class to normalise
  64.  *   all information about media types, especially codecs.
  65.  *
  66.  */
  67.  
  68. #include <ptlib.h>
  69.  
  70. #ifdef __GNUC__
  71. #pragma implementation "mediafmt.h"
  72. #endif
  73.  
  74. #include "mediafmt.h"
  75.  
  76. #include "rtp.h"
  77.  
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80.  
  81. OpalMediaFormat const OpalPCM16(
  82.   OPAL_PCM16,
  83.   OpalMediaFormat::DefaultAudioSessionID,
  84.   RTP_DataFrame::L16_Mono,
  85.   TRUE,   // Needs jitter
  86.   128000, // bits/sec
  87.   16, // bytes/frame
  88.   8, // 1 millisecond
  89.   OpalMediaFormat::AudioTimeUnits
  90. );
  91.  
  92. OpalMediaFormat const OpalG711uLaw(
  93.   OPAL_G711_ULAW_64K,
  94.   OpalMediaFormat::DefaultAudioSessionID,
  95.   RTP_DataFrame::PCMU,
  96.   TRUE,   // Needs jitter
  97.   64000, // bits/sec
  98.   8, // bytes/frame
  99.   8, // 1 millisecond/frame
  100.   OpalMediaFormat::AudioTimeUnits
  101. );
  102.  
  103. OpalMediaFormat const OpalG711ALaw(
  104.   OPAL_G711_ALAW_64K,
  105.   OpalMediaFormat::DefaultAudioSessionID,
  106.   RTP_DataFrame::PCMA,
  107.   TRUE,   // Needs jitter
  108.   64000, // bits/sec
  109.   8, // bytes/frame
  110.   8, // 1 millisecond/frame
  111.   OpalMediaFormat::AudioTimeUnits
  112. );
  113.  
  114. OpalMediaFormat const OpalG728(  
  115.   OPAL_G728,
  116.   OpalMediaFormat::DefaultAudioSessionID,
  117.   RTP_DataFrame::G728,
  118.   TRUE, // Needs jitter
  119.   16000,// bits/sec
  120.   5,    // bytes
  121.   20,   // 2.5 milliseconds
  122.   OpalMediaFormat::AudioTimeUnits
  123. );
  124.  
  125. OpalMediaFormat const OpalG729( 
  126.   OPAL_G729,
  127.   OpalMediaFormat::DefaultAudioSessionID,
  128.   RTP_DataFrame::G729,
  129.   TRUE, // Needs jitter
  130.   8000, // bits/sec
  131.   10,   // bytes
  132.   80,   // 10 milliseconds
  133.   OpalMediaFormat::AudioTimeUnits
  134. );
  135.  
  136. OpalMediaFormat const OpalG729A( 
  137.   OPAL_G729A,
  138.   OpalMediaFormat::DefaultAudioSessionID,
  139.   RTP_DataFrame::G729,
  140.   TRUE, // Needs jitter
  141.   8000, // bits/sec
  142.   10,   // bytes
  143.   80,   // 10 milliseconds
  144.   OpalMediaFormat::AudioTimeUnits
  145. );
  146.  
  147. OpalMediaFormat const OpalG729B(
  148.   OPAL_G729B,
  149.   OpalMediaFormat::DefaultAudioSessionID,
  150.   RTP_DataFrame::G729,
  151.   TRUE, // Needs jitter
  152.   8000, // bits/sec
  153.   10,   // bytes
  154.   80,   // 10 milliseconds
  155.   OpalMediaFormat::AudioTimeUnits
  156. );
  157.  
  158. OpalMediaFormat const OpalG729AB(
  159.   OPAL_G729AB,
  160.   OpalMediaFormat::DefaultAudioSessionID,
  161.   RTP_DataFrame::G729,
  162.   TRUE, // Needs jitter
  163.   8000, // bits/sec
  164.   10,   // bytes
  165.   80,   // 10 milliseconds
  166.   OpalMediaFormat::AudioTimeUnits
  167. );
  168.  
  169. OpalMediaFormat const OpalG7231_6k3(
  170.   OPAL_G7231_6k3,
  171.   OpalMediaFormat::DefaultAudioSessionID,
  172.   RTP_DataFrame::G7231,
  173.   TRUE, // Needs jitter
  174.   6400, // bits/sec
  175.   24,   // bytes
  176.   240,  // 30 milliseconds
  177.   OpalMediaFormat::AudioTimeUnits
  178. );
  179.  
  180. OpalMediaFormat const OpalG7231_5k3(
  181.   OPAL_G7231_5k3,
  182.   OpalMediaFormat::DefaultAudioSessionID,
  183.   RTP_DataFrame::G7231,
  184.   TRUE, // Needs jitter
  185.   5300, // bits/sec
  186.   24,   // bytes
  187.   240,  // 30 milliseconds
  188.   OpalMediaFormat::AudioTimeUnits
  189. );
  190.  
  191. OpalMediaFormat const OpalG7231A_6k3(
  192.   OPAL_G7231A_6k3,
  193.   OpalMediaFormat::DefaultAudioSessionID,
  194.   RTP_DataFrame::G7231,
  195.   TRUE, // Needs jitter
  196.   6400, // bits/sec
  197.   24,   // bytes
  198.   240,  // 30 milliseconds
  199.   OpalMediaFormat::AudioTimeUnits
  200. );
  201.  
  202. OpalMediaFormat const OpalG7231A_5k3(
  203.   OPAL_G7231A_5k3,
  204.   OpalMediaFormat::DefaultAudioSessionID,
  205.   RTP_DataFrame::G7231,
  206.   TRUE, // Needs jitter
  207.   5300, // bits/sec
  208.   24,   // bytes
  209.   240,  // 30 milliseconds
  210.   OpalMediaFormat::AudioTimeUnits
  211. );
  212.  
  213. OpalMediaFormat const OpalGSM0610(
  214.   OPAL_GSM0610,
  215.   OpalMediaFormat::DefaultAudioSessionID,
  216.   RTP_DataFrame::GSM,
  217.   TRUE,  // Needs jitter
  218.   13200, // bits/sec
  219.   33,    // bytes
  220.   160,   // 20 milliseconds
  221.   OpalMediaFormat::AudioTimeUnits
  222. );
  223.  
  224.  
  225. /////////////////////////////////////////////////////////////////////////////
  226.  
  227. OpalMediaFormat::OpalMediaFormat()
  228. {
  229.   rtpPayloadType = RTP_DataFrame::IllegalPayloadType;
  230.  
  231.   needsJitter = FALSE;
  232.   bandwidth = 0;
  233.   frameSize = 0;
  234.   frameTime = 0;
  235.   timeUnits = 0;
  236. }
  237.  
  238.  
  239. OpalMediaFormat::OpalMediaFormat(const char * search, BOOL exact)
  240.   : PCaselessString(search)
  241. {
  242.   rtpPayloadType = RTP_DataFrame::MaxPayloadType;
  243.  
  244.   needsJitter = FALSE;
  245.   bandwidth = 0;
  246.   frameSize = 0;
  247.   frameTime = 0;
  248.   timeUnits = 0;
  249.  
  250.   const List & registeredFormats = GetRegisteredMediaFormats();
  251.   for (PINDEX i = 0; i < registeredFormats.GetSize(); i++) {
  252.     if (exact ? (registeredFormats[i] == search)
  253.               : (registeredFormats[i].Find(search) != P_MAX_INDEX)) {
  254.       *this = registeredFormats[i];
  255.       return;
  256.     }
  257.   }
  258. }
  259.  
  260.  
  261. OpalMediaFormat::OpalMediaFormat(const char * fullName,
  262.                                  unsigned dsid,
  263.                                  RTP_DataFrame::PayloadTypes pt,
  264.                                  BOOL     nj,
  265.                                  unsigned bw,
  266.                                  PINDEX   fs,
  267.                                  unsigned ft,
  268.                                  unsigned tu)
  269.   : PCaselessString(fullName)
  270. {
  271.   rtpPayloadType = pt;
  272.   defaultSessionID = dsid;
  273.   needsJitter = nj;
  274.   bandwidth = bw;
  275.   frameSize = fs;
  276.   frameTime = ft;
  277.   timeUnits = tu;
  278.  
  279.   PINDEX i;
  280.   List & registeredFormats = GetMediaFormatsList();
  281.  
  282.   if ((i = registeredFormats.GetValuesIndex(*this)) != P_MAX_INDEX) {
  283.     *this = registeredFormats[i]; // Already registered, use previous values
  284.     return;
  285.   }
  286.  
  287.   // assume non-dynamic payload types are correct and do not need deconflicting
  288.   if (rtpPayloadType < RTP_DataFrame::DynamicBase) {
  289.     registeredFormats.Append(this);
  290.     return;
  291.   }
  292.  
  293.   // find the next unused dynamic number, and find anything with the new 
  294.   // rtp payload type if it is explicitly required
  295.   OpalMediaFormat * match = NULL;
  296.   RTP_DataFrame::PayloadTypes nextUnused = RTP_DataFrame::DynamicBase;
  297.   do {
  298.     for (i = 0; i < registeredFormats.GetSize(); i++) {
  299.       if (registeredFormats[i].GetPayloadType() == nextUnused) {
  300.         nextUnused = (RTP_DataFrame::PayloadTypes)(nextUnused + 1);
  301.         break;
  302.       }
  303.       if ((rtpPayloadType >= RTP_DataFrame::DynamicBase) && 
  304.           (registeredFormats[i].GetPayloadType() == rtpPayloadType))
  305.         match = ®isteredFormats[i];
  306.     }
  307.   } while (i < registeredFormats.GetSize());
  308.  
  309.   // if new format requires a specific payload type in the dynamic range, 
  310.   // then move the old format to the next unused format
  311.   if (match != NULL)
  312.     match->rtpPayloadType = nextUnused;
  313.   else
  314.     rtpPayloadType = nextUnused;
  315.  
  316.   registeredFormats.Append(this);
  317. }
  318.  
  319.  
  320. OpalMediaFormat::List & OpalMediaFormat::GetMediaFormatsList()
  321. {
  322.   static List registeredFormats;
  323.   registeredFormats.DisallowDeleteObjects();
  324.   return registeredFormats;
  325. }
  326.  
  327.  
  328. // End of File ///////////////////////////////////////////////////////////////
  329.