<commit_before>//  
// Copyright (C) 2006 SIPez LLC. 
// Licensed to SIPfoundry under a Contributor Agreement. 
//
// Copyright (C) 2004-2006 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp.  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
///////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
//  G.729 enabling controls.  Currently only on VxWorks and Windows
//////////////////////////////////////////////////////////////////////////////

#undef PLATFORM_SUPPORTS_G729

#if (defined(_VXWORKS) || defined(WIN32)) /* [ */
#define PLATFORM_SUPPORTS_G729
#endif /* if (defined(_VXWORKS) || defined(WIN32)) ] */

//////////////////////////////////////////////////////////////////////////////

// SYSTEM INCLUDES
#include <assert.h>
#include <string.h>

// APPLICATION INCLUDES
#include <utl/UtlDListIterator.h>
#include <os/OsWriteLock.h>
#include <os/OsReadLock.h>
#include <net/SdpCodecFactory.h>
#include <sdp/SdpCodec.h>
#include <net/NameValueTokenizer.h>

#define VERBOSE_CODEC_FACTORY
#undef VERBOSE_CODEC_FACTORY

// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// STATIC VARIABLE INITIALIZATIONS
SdpCodecFactory* SdpCodecFactory::spInstance = NULL;
OsBSem SdpCodecFactory::sLock(OsBSem::Q_PRIORITY, OsBSem::FULL);

/* //////////////////////////// PUBLIC //////////////////////////////////// */

/* ============================ CREATORS ================================== */

SdpCodecFactory* SdpCodecFactory::getSdpCodecFactory()
{
   // If the object already exists, then use it
   if (spInstance == NULL)
   {

       // If the object does not yet exist, then acquire
       // the lock to ensure that only one instance of the object is 
       // created
       sLock.acquire();
       if (spInstance == NULL)
           spInstance = new SdpCodecFactory();

       sLock.release();

   }

   return spInstance;
}


// Constructor
SdpCodecFactory::SdpCodecFactory(int numCodecs, SdpCodec* codecs[]) :
    mReadWriteMutex(OsRWMutex::Q_FIFO)
{
   mCodecCPULimit = SdpCodec::SDP_CODEC_CPU_HIGH ;
   addCodecs(numCodecs, codecs);
}

// Copy constructor
SdpCodecFactory::SdpCodecFactory(const SdpCodecFactory& rSdpCodecFactory) :
    mReadWriteMutex(OsRWMutex::Q_FIFO)
{
    *this = rSdpCodecFactory;
}

// Destructor
SdpCodecFactory::~SdpCodecFactory()
{
    mCodecs.destroyAll();
}

/* ============================ MANIPULATORS ============================== */

// Assignment operator
SdpCodecFactory& 
SdpCodecFactory::operator=(const SdpCodecFactory& rhs)
{
   if (this == &rhs)            // handle the assignment to self case
      return *this;

    OsReadLock thatLock(((SdpCodecFactory&)rhs).mReadWriteMutex);
    OsWriteLock thisLock(mReadWriteMutex);
    mCodecs.destroyAll();
    UtlDListIterator iterator(((SdpCodecFactory&)rhs).mCodecs);
    const SdpCodec* codecFound;

    while((codecFound = (SdpCodec*) iterator()))
    {
        mCodecs.insert(new SdpCodec(*codecFound));
    }

    mCodecCPULimit = rhs.mCodecCPULimit;
    
   return *this;
}

void SdpCodecFactory::addCodecs(int numCodecs, SdpCodec* codecs[])
{
   OsWriteLock lock(mReadWriteMutex);
   for(int index = 0; index < numCodecs; index++)
   {
       addCodecNoLock(*(codecs[index]));
   }
}

void SdpCodecFactory::addCodec(SdpCodec& newCodec)
{
    OsWriteLock lock(mReadWriteMutex);
    addCodecNoLock(newCodec);
}

void SdpCodecFactory::bindPayloadTypes()
{
    int unusedDynamicPayloadId = 
        SdpCodec::SDP_CODEC_MAXIMUM_STATIC_CODEC + 1;
    SdpCodec* codecWithoutPayloadId = NULL;
    UtlString prevSubmimeType = "none";
    UtlString actualSubmimeType;

    // Find a codec which does not have its payload type set
    // Cheat a little and make the codec writeable
    while((codecWithoutPayloadId = (SdpCodec*) getCodecByType(-1)))
    {
        // Find an unused dynamic payload type id
        while(getCodecByType(unusedDynamicPayloadId))
        {
            // Assuming all codecs with same submime type are stored
            // sequentially, only increment payload id for different submime types
            codecWithoutPayloadId->getEncodingName(actualSubmimeType);
            if (prevSubmimeType.compareTo(actualSubmimeType, UtlString::ignoreCase) != 0)
            {
                // Increment payload id for new submime type
                unusedDynamicPayloadId++;
                prevSubmimeType = actualSubmimeType;
            }
            else
            {<commit_msg>Fix typo in comments.<commit_after>//  
// Copyright (C) 2006 SIPez LLC. 
// Licensed to SIPfoundry under a Contributor Agreement. 
//
// Copyright (C) 2004-2006 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp.  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
///////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
//  G.729 enabling controls.  Currently only on VxWorks and Windows
//////////////////////////////////////////////////////////////////////////////

#undef PLATFORM_SUPPORTS_G729

#if (defined(_VXWORKS) || defined(WIN32)) /* [ */
#define PLATFORM_SUPPORTS_G729
#endif /* if (defined(_VXWORKS) || defined(WIN32)) ] */

//////////////////////////////////////////////////////////////////////////////

// SYSTEM INCLUDES
#include <assert.h>
#include <string.h>

// APPLICATION INCLUDES
#include <utl/UtlDListIterator.h>
#include <os/OsWriteLock.h>
#include <os/OsReadLock.h>
#include <net/SdpCodecFactory.h>
#include <sdp/SdpCodec.h>
#include <net/NameValueTokenizer.h>

#define VERBOSE_CODEC_FACTORY
#undef VERBOSE_CODEC_FACTORY

// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// STATIC VARIABLE INITIALIZATIONS
SdpCodecFactory* SdpCodecFactory::spInstance = NULL;
OsBSem SdpCodecFactory::sLock(OsBSem::Q_PRIORITY, OsBSem::FULL);

/* //////////////////////////// PUBLIC //////////////////////////////////// */

/* ============================ CREATORS ================================== */

SdpCodecFactory* SdpCodecFactory::getSdpCodecFactory()
{
   // If the object already exists, then use it
   if (spInstance == NULL)
   {

       // If the object does not yet exist, then acquire
       // the lock to ensure that only one instance of the object is 
       // created
       sLock.acquire();
       if (spInstance == NULL)
           spInstance = new SdpCodecFactory();

       sLock.release();

   }

   return spInstance;
}


// Constructor
SdpCodecFactory::SdpCodecFactory(int numCodecs, SdpCodec* codecs[]) :
    mReadWriteMutex(OsRWMutex::Q_FIFO)
{
   mCodecCPULimit = SdpCodec::SDP_CODEC_CPU_HIGH ;
   addCodecs(numCodecs, codecs);
}

// Copy constructor
SdpCodecFactory::SdpCodecFactory(const SdpCodecFactory& rSdpCodecFactory) :
    mReadWriteMutex(OsRWMutex::Q_FIFO)
{
    *this = rSdpCodecFactory;
}

// Destructor
SdpCodecFactory::~SdpCodecFactory()
{
    mCodecs.destroyAll();
}

/* ============================ MANIPULATORS ============================== */

// Assignment operator
SdpCodecFactory& 
SdpCodecFactory::operator=(const SdpCodecFactory& rhs)
{
   if (this == &rhs)            // handle the assignment to self case
      return *this;

    OsReadLock thatLock(((SdpCodecFactory&)rhs).mReadWriteMutex);
    OsWriteLock thisLock(mReadWriteMutex);
    mCodecs.destroyAll();
    UtlDListIterator iterator(((SdpCodecFactory&)rhs).mCodecs);
    const SdpCodec* codecFound;

    while((codecFound = (SdpCodec*) iterator()))
    {
        mCodecs.insert(new SdpCodec(*codecFound));
    }

    mCodecCPULimit = rhs.mCodecCPULimit;
    
   return *this;
}

void SdpCodecFactory::addCodecs(int numCodecs, SdpCodec* codecs[])
{
   OsWriteLock lock(mReadWriteMutex);
   for(int index = 0; index < numCodecs; index++)
   {
       addCodecNoLock(*(codecs[index]));
   }
}

void SdpCodecFactory::addCodec(SdpCodec& newCodec)
{
    OsWriteLock lock(mReadWriteMutex);
    addCodecNoLock(newCodec);
}

void SdpCodecFactory::bindPayloadTypes()
{
    int unusedDynamicPayloadId = 
        SdpCodec::SDP_CODEC_MAXIMUM_STATIC_CODEC + 1;
    SdpCodec* codecWithoutPayloadId = NULL;
    UtlString prevSubmimeType = "none";
    UtlString actualSubmimeType;

    // Find a codec which does not have its payload type set
    // Cheat a little and make the codec writable
    while((codecWithoutPayloadId = (SdpCodec*) getCodecByType(-1)))
    {
        // Find an unused dynamic payload type id
        while(getCodecByType(unusedDynamicPayloadId))
        {
            // Assuming all codecs with same submime type are stored
            // sequentially, only increment payload id for different submime types
            codecWithoutPayloadId->getEncodingName(actualSubmimeType);
            if (prevSubmimeType.compareTo(actualSubmimeType, UtlString::ignoreCase) != 0)
            {
                // Increment payload id for new submime type
                unusedDynamicPayloadId++;
                prevSubmimeType = actualSubmimeType;
            }
            else
            {
{'fraction_non_alphanumeric': 0.20238482384823847, 'fraction_numerical': 0.008021680216802168, 'mean_word_length': 2.464513706346226, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1773898', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2800, 'n_words': 605}