📄 codecs.cxx
字号:
/* * codecs.cxx * * H.323 protocol handler * * Open H323 Library * * Copyright (c) 1998-2000 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Open H323 Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Portions of this code were written with the assisance of funding from * Vovida Networks, Inc. http://www.vovida.com. * * Contributor(s): ______________________________________. * * $Log: codecs.cxx,v $ * Revision 1.52 2000/07/14 14:08:10 robertj * Fixed stream based codec so can support stream "frames" less than maximum specified. * * Revision 1.51 2000/05/16 02:04:17 craigs * Added access functions for silence compression mode * * Revision 1.50 2000/05/04 11:52:35 robertj * Added Packets Too Late statistics, requiring major rearrangement of jitter * buffer code, not also changes semantics of codec Write() function slightly. * * Revision 1.49 2000/05/02 04:32:26 robertj * Fixed copyright notice comment. * * Revision 1.48 2000/04/28 12:58:37 robertj * Changed silence detection code so does not PTRACE unless threshold actually changes. * * Revision 1.47 2000/04/10 18:52:45 robertj * Improved "bootstrap" of silence detection algorithm. * * Revision 1.46 2000/03/23 03:00:06 robertj * Changed framed codec so only writes max of bytesPerFrame regardless of length. * * Revision 1.45 2000/02/04 05:11:19 craigs * Updated for new Makefiles and for new video transmission code * * Revision 1.44 2000/01/13 04:03:45 robertj * Added video transmission * * Revision 1.43 1999/12/31 00:05:36 robertj * Added Microsoft ACM G.723.1 codec capability. * * Revision 1.42 1999/12/23 23:02:35 robertj * File reorganision for separating RTP from H.323 and creation of LID for VPB support. * * Revision 1.41 1999/12/21 07:36:43 craigs * Fixed problem in H323VideoCodec destructor that caused hang or segv on exit * * Revision 1.40 1999/11/29 08:59:09 craigs * Added new code for new video code interface * * Revision 1.39 1999/11/29 04:50:11 robertj * Added adaptive threshold calculation to silence detection. * * Revision 1.38 1999/11/20 00:53:47 robertj * Fixed ability to have variable sized frames in single RTP packet under G.723.1 * * Revision 1.37 1999/11/13 14:10:59 robertj * Changes to make silence detection selectable. * * Revision 1.36 1999/11/11 23:28:46 robertj * Added first cut silence detection algorithm. * * Revision 1.35 1999/11/04 00:45:07 robertj * Added extra constructors for nonStandard codecs and fixed receiveAndTransmitAudioCapability problem. * * Revision 1.34 1999/11/01 00:51:13 robertj * Fixed problem where codec close does not dispose of attached channel. * * Revision 1.33 1999/10/19 00:04:57 robertj * Changed OpenAudioChannel and OpenVideoChannel to allow a codec AttachChannel with no autodelete. * * Revision 1.32 1999/10/14 12:02:40 robertj * Fixed assignment of t35 info in nonstandard capabilities (wrong way around). * * Revision 1.31 1999/10/10 23:00:15 craigs * Fixed problem with raw channel ptrs not being NULLed out after deletion * * Revision 1.30 1999/10/09 02:15:08 craigs * Added codec to OpenVideoDevice and OpenAudioChannel * * Revision 1.29 1999/10/09 01:20:48 robertj * Fixed error in G711 packet size and trace message * * Revision 1.28 1999/10/08 09:59:03 robertj * Rewrite of capability for sending multiple audio frames * * Revision 1.27 1999/10/08 08:32:22 robertj * Fixed misleading trace text. * * Revision 1.26 1999/10/08 04:58:38 robertj * Added capability for sending multiple audio frames in single RTP packet * * Revision 1.25 1999/09/23 07:25:12 robertj * Added open audio and video function to connection and started multi-frame codec send functionality. * * Revision 1.24 1999/09/21 14:51:34 robertj * Fixed NonStandardCapabilityInfo class virtual destructor (and name). * * Revision 1.23 1999/09/21 14:14:36 robertj * Added non-standard codec capability classes * * Revision 1.22 1999/09/21 08:10:03 craigs * Added support for video devices and H261 codec * * Revision 1.21 1999/09/18 13:24:38 craigs * Added ability to disable jitter buffer * Added ability to access entire RTP packet in codec Write * * Revision 1.20 1999/09/13 13:59:14 robertj * Removed incorrect comment. * * Revision 1.19 1999/09/08 04:05:49 robertj * Added support for video capabilities & codec, still needs the actual codec itself! * * Revision 1.18 1999/08/31 12:34:18 robertj * Added gatekeeper support. * * Revision 1.17 1999/08/25 05:05:36 robertj * Added UserInput capability. * Allowed the attachment of a channel on a codec to optionally delete the channel object, * Improved opening of audio codecs, PSoundChannel creation now in endpoint. * * Revision 1.16 1999/07/16 16:05:48 robertj * Added "human readable" codec type name display. * * Revision 1.15 1999/07/16 15:01:30 robertj * Added message print when starting GSM codec. * * Revision 1.14 1999/07/15 14:45:36 robertj * Added propagation of codec open error to shut down logical channel. * Fixed control channel start up bug introduced with tunnelling. * * Revision 1.13 1999/07/13 09:53:24 robertj * Fixed some problems with jitter buffer and added more debugging. * * Revision 1.12 1999/07/10 02:42:53 robertj * Fixed interopability problem with NetMetting 2.1 G711 capability. * * Revision 1.11 1999/07/09 06:09:49 robertj * Major implementation. An ENORMOUS amount of stuff added everywhere. * * Revision 1.10 1999/06/24 13:32:45 robertj * Fixed ability to change sound device on codec and fixed NM3 G.711 compatibility * * Revision 1.9 1999/06/22 13:49:40 robertj * Added GSM support and further RTP protocol enhancements. * * Revision 1.8 1999/06/14 15:08:40 robertj * Added GSM codec class frame work (still no actual codec). * * Revision 1.7 1999/06/14 08:44:58 robertj * Fixed sound buffers to be correct size for stream based audio. * GNU C++ compatibility * * Revision 1.6 1999/06/14 06:39:08 robertj * Fixed problem with getting transmit flag to channel from PDU negotiator * * Revision 1.5 1999/06/14 05:15:55 robertj * Changes for using RTP sessions correctly in H323 Logical Channel context * * Revision 1.4 1999/06/13 12:41:14 robertj * Implement logical channel transmitter. * Fixed H245 connect on receiving call. * * Revision 1.3 1999/06/09 05:26:19 robertj * Major restructuring of classes. * * Revision 1.2 1999/06/06 06:06:36 robertj * Changes for new ASN compiler and v2 protocol ASN files. * * Revision 1.1 1999/01/16 01:31:04 robertj * Initial revision * */#include <ptlib.h>//#include <ptlib/svcproc.h>#include "codecs.h"#include "channels.h"#include "h323pdu.h"#include "videoio.h"#define new PNEW#if !PTRACING // Stuff to remove unised parameters warning#define PTRACE_bitRateRestriction#define PTRACE_type#endifextern "C" { unsigned char linear2ulaw(int pcm_val); int ulaw2linear(unsigned char u_val); unsigned char linear2alaw(int pcm_val); int alaw2linear(unsigned char u_val);};/////////////////////////////////////////////////////////////////////////////H323Codec::H323Codec(Direction dir){ direction = dir; rtpPayloadType = RTP_DataFrame::DynamicBase;}BOOL H323Codec::Open(H323Connection & /*connection*/){ return TRUE;}void H323Codec::OnFlowControl(long PTRACE_bitRateRestriction){ PTRACE(3, "Codec\tOnFlowControl: " << PTRACE_bitRateRestriction);}void H323Codec::OnMiscellaneousCommand(const H245_MiscellaneousCommand_type & PTRACE_type){ PTRACE(3, "Codec\tOnMiscellaneousCommand: " << PTRACE_type.GetTagName());}void H323Codec::OnMiscellaneousIndication(const H245_MiscellaneousIndication_type & PTRACE_type){ PTRACE(3, "Codec\tOnMiscellaneousIndication: " << PTRACE_type.GetTagName());}/////////////////////////////////////////////////////////////////////////////H323VideoCodec::H323VideoCodec(Direction dir) : H323Codec(dir){ rawDevice = NULL; deleteDevice = FALSE; videoInput = width = height = 0;}H323VideoCodec::~H323VideoCodec(){ Close(); if (rawDevice != NULL) rawDevice->SetNow(0); if (deleteDevice) delete rawDevice; rawDevice = NULL;}BOOL H323VideoCodec::Open(H323Connection & connection){ return connection.OpenVideoDevice(direction == Encoder, *this);}unsigned H323VideoCodec::GetTimeUnits() const{ return 90; // Assuming standard 90kHz sample rate}BOOL H323VideoCodec::NeedsJitterBuffer() const{ return FALSE;}void H323VideoCodec::OnMiscellaneousCommand(const H245_MiscellaneousCommand_type & type){ switch (type.GetTag()) { case H245_MiscellaneousCommand_type::e_videoFreezePicture : OnFreezePicture(); break; case H245_MiscellaneousCommand_type::e_videoFastUpdatePicture : OnFastUpdatePicture(); break; case H245_MiscellaneousCommand_type::e_videoFastUpdateGOB : { const H245_MiscellaneousCommand_type_videoFastUpdateGOB & fuGOB = type; OnFastUpdateGOB(fuGOB.m_firstGOB, fuGOB.m_numberOfGOBs); break; } case H245_MiscellaneousCommand_type::e_videoFastUpdateMB : { const H245_MiscellaneousCommand_type_videoFastUpdateMB & fuMB = type; OnFastUpdateMB(fuMB.HasOptionalField(H245_MiscellaneousCommand_type_videoFastUpdateMB::e_firstGOB) ? (int)fuMB.m_firstGOB : -1, fuMB.HasOptionalField(H245_MiscellaneousCommand_type_videoFastUpdateMB::e_firstMB) ? (int)fuMB.m_firstMB : -1, fuMB.m_numberOfMBs); break; } } H323Codec::OnMiscellaneousCommand(type);}void H323VideoCodec::OnFreezePicture(){}void H323VideoCodec::OnFastUpdatePicture(){}void H323VideoCodec::OnFastUpdateGOB(unsigned /*firstGOB*/, unsigned /*numberOfGOBs*/){}void H323VideoCodec::OnFastUpdateMB(int /*firstGOB*/, int /*firstMB*/, unsigned /*numberOfMBs*/){}void H323VideoCodec::OnMiscellaneousIndication(const H245_MiscellaneousIndication_type & type){ switch (type.GetTag()) { case H245_MiscellaneousIndication_type::e_videoIndicateReadyToActivate : OnVideoIndicateReadyToActivate(); break; case H245_MiscellaneousIndication_type::e_videoTemporalSpatialTradeOff : OnVideoTemporalSpatialTradeOff(); break; case H245_MiscellaneousIndication_type::e_videoNotDecodedMBs : { const H245_MiscellaneousIndication_type_videoNotDecodedMBs & vndMB = type; OnVideoNotDecodedMBs(vndMB.m_firstMB, vndMB.m_numberOfMBs, vndMB.m_temporalReference); break; } } H323Codec::OnMiscellaneousIndication(type);}void H323VideoCodec::OnVideoIndicateReadyToActivate(){}void H323VideoCodec::OnVideoTemporalSpatialTradeOff(){}void H323VideoCodec::OnVideoNotDecodedMBs(unsigned /*firstMB*/, unsigned /*numberOfMBs*/, unsigned /*temporalReference*/){}BOOL H323VideoCodec::AttachDevice(H323VideoDevice * channel, BOOL autoDelete){ if (deleteDevice) delete rawDevice; rawDevice = channel; deleteDevice = autoDelete; return channel != NULL;}void H323VideoCodec::Close(){ if (rawDevice != NULL) rawDevice->Close();}/////////////////////////////////////////////////////////////////////////////H323AudioCodec::H323AudioCodec(Direction dir, unsigned samples) : H323Codec(dir){ samplesPerFrame = samples; rawDataChannel = NULL; deleteChannel = FALSE; // Start off in silent mode inTalkBurst = FALSE; // Initialise the adaptive threshold variables. SetSilenceDetectionMode(AdaptiveSilenceDetection);}H323AudioCodec::~H323AudioCodec(){ Close(); if (deleteChannel) delete rawDataChannel; rawDataChannel = NULL;}BOOL H323AudioCodec::Open(H323Connection & connection){ return connection.OpenAudioChannel(direction == Encoder, samplesPerFrame*2, *this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -