├── documents └── 感知接入SDK接口文档_1.1.doc ├── include ├── XClient.h ├── XClientDLL.h ├── x264.h └── xvid.h ├── lib ├── dbghelp.lib ├── libeay32.dll ├── libeay32.lib ├── libx264.lib └── libxvidcore.lib └── rtsp_stack ├── AMRAudioRTPSink.cpp ├── AMRAudioRTPSink.h ├── AMRAudioSource.cpp ├── AMRAudioSource.h ├── AudioRTPSink.cpp ├── AudioRTPSink.h ├── Base64.cpp ├── Base64.h ├── BasicHashTable.cpp ├── BasicHashTable.h ├── BasicTaskScheduler.cpp ├── BasicTaskScheduler0.cpp ├── BasicUDPSink.cpp ├── BasicUDPSink.h ├── BasicUsageEnvironment.cpp ├── BasicUsageEnvironment.h ├── BasicUsageEnvironment0.cpp ├── BasicUsageEnvironment0.h ├── BasicUsageEnvironment_version.h ├── Boolean.h ├── Debug.h ├── DelayQueue.cpp ├── DelayQueue.h ├── EncoderMediaSession.h ├── EncoderMediaSubsession.cpp ├── EncoderMediaSubsession.h ├── EncoderSource.cpp ├── EncoderSource.h ├── FramedFilter.cpp ├── FramedFilter.h ├── FramedSource.cpp ├── FramedSource.h ├── GroupEId.cpp ├── GroupEId.h ├── Groupsock.cpp ├── Groupsock.h ├── GroupsockHelper.cpp ├── GroupsockHelper.h ├── H264VideoRTPSink.cpp ├── H264VideoRTPSink.h ├── HandlerSet.h ├── HashTable.cpp ├── HashTable.h ├── IOHandlers.cpp ├── IOHandlers.h ├── Locale.cpp ├── Locale.h ├── MPEG4ESVideoRTPSink.cpp ├── MPEG4ESVideoRTPSink.h ├── Makefile ├── Media.cpp ├── Media.h ├── MediaSession.h ├── MediaSink.cpp ├── MediaSink.h ├── MediaSource.cpp ├── MediaSource.h ├── MultiFramedRTPSink.cpp ├── MultiFramedRTPSink.h ├── NetAddress.cpp ├── NetAddress.h ├── NetCommon.h ├── NetInterface.cpp ├── NetInterface.h ├── RTCP.cpp ├── RTCP.h ├── RTPInterface.cpp ├── RTPInterface.h ├── RTPSink.cpp ├── RTPSink.h ├── RTPSource.cpp ├── RTPSource.h ├── RTSPCommon.cpp ├── RTSPCommon.h ├── RTSPEncoderSession.cpp ├── RTSPSdk.cpp ├── RTSPSdk.h ├── RTSPServer.cpp ├── RTSPServer.h ├── ServerMediaSession.cpp ├── ServerMediaSession.h ├── TunnelEncaps.h ├── UsageEnvironment.cpp ├── UsageEnvironment.h ├── UsageEnvironment_version.h ├── VideoRTPSink.cpp ├── VideoRTPSink.h ├── bn.h ├── crypto.h ├── e_os.h ├── err.h ├── groupsock_version.h ├── httpHash.cpp ├── inet.c ├── liveMedia_version.h ├── mainSdk.cpp ├── rand.h ├── rsa.h ├── rsa_crypto.cpp ├── rsa_crypto.h ├── rtcp_from_spec.c ├── rtcp_from_spec.h ├── strDup.cpp ├── strDup.h ├── xvid_interface.cpp └── xvid_interface.h /documents/感知接入SDK接口文档_1.1.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waydeom/opencamera/4d6fe6de266739482b47c0ecc6cde6488ffc861d/documents/感知接入SDK接口文档_1.1.doc -------------------------------------------------------------------------------- /include/XClient.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waydeom/opencamera/4d6fe6de266739482b47c0ecc6cde6488ffc861d/include/XClient.h -------------------------------------------------------------------------------- /include/XClientDLL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waydeom/opencamera/4d6fe6de266739482b47c0ecc6cde6488ffc861d/include/XClientDLL.h -------------------------------------------------------------------------------- /lib/dbghelp.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waydeom/opencamera/4d6fe6de266739482b47c0ecc6cde6488ffc861d/lib/dbghelp.lib -------------------------------------------------------------------------------- /lib/libeay32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waydeom/opencamera/4d6fe6de266739482b47c0ecc6cde6488ffc861d/lib/libeay32.dll -------------------------------------------------------------------------------- /lib/libeay32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waydeom/opencamera/4d6fe6de266739482b47c0ecc6cde6488ffc861d/lib/libeay32.lib -------------------------------------------------------------------------------- /lib/libx264.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waydeom/opencamera/4d6fe6de266739482b47c0ecc6cde6488ffc861d/lib/libx264.lib -------------------------------------------------------------------------------- /lib/libxvidcore.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waydeom/opencamera/4d6fe6de266739482b47c0ecc6cde6488ffc861d/lib/libxvidcore.lib -------------------------------------------------------------------------------- /rtsp_stack/AMRAudioRTPSink.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // RTP sink for AMR audio (RFC 3267) 19 | // Implementation 20 | 21 | // NOTE: At present, this is just a limited implementation, supporting: 22 | // octet-alignment only; no interleaving; no frame CRC; no robust-sorting. 23 | 24 | #include "AMRAudioRTPSink.h" 25 | #include "AMRAudioSource.h" 26 | #include "Debug.h" 27 | 28 | AMRAudioRTPSink* 29 | AMRAudioRTPSink::createNew(UsageEnvironment& env, void* owner, Groupsock* RTPgs, 30 | unsigned char rtpPayloadFormat, 31 | Boolean sourceIsWideband, 32 | unsigned numChannelsInSource) { 33 | return new AMRAudioRTPSink(env, owner, RTPgs, rtpPayloadFormat, 34 | sourceIsWideband, numChannelsInSource); 35 | } 36 | 37 | AMRAudioRTPSink 38 | ::AMRAudioRTPSink(UsageEnvironment& env, void* owner, Groupsock* RTPgs, 39 | unsigned char rtpPayloadFormat, 40 | Boolean sourceIsWideband, unsigned numChannelsInSource) 41 | : AudioRTPSink(env, owner, RTPgs, rtpPayloadFormat, 42 | sourceIsWideband ? 16000 : 8000, 43 | sourceIsWideband ? "AMR-WB": "AMR", 44 | numChannelsInSource), 45 | fSourceIsWideband(sourceIsWideband), fFmtpSDPLine(NULL) { 46 | } 47 | 48 | AMRAudioRTPSink::~AMRAudioRTPSink() { 49 | delete[] fFmtpSDPLine; 50 | } 51 | 52 | Boolean AMRAudioRTPSink::sourceIsCompatibleWithUs(MediaSource& source) { 53 | // Our source must be an AMR audio source: 54 | if (!source.isAMRAudioSource()) return False; 55 | 56 | // Also, the source must be wideband iff we asked for this: 57 | AMRAudioSource& amrSource = (AMRAudioSource&)source; 58 | if ((amrSource.isWideband()^fSourceIsWideband) != 0) return False; 59 | 60 | // Also, the source must have the same number of channels that we 61 | // specified. (It could, in principle, have more, but we don't 62 | // support that.) 63 | if (amrSource.numChannels() != numChannels()) return False; 64 | 65 | // Also, because in our current implementation we output only one 66 | // frame in each RTP packet, this means that for multi-channel audio, 67 | // each 'frame-block' will be split over multiple RTP packets, which 68 | // may violate the spec. Warn about this: 69 | if (amrSource.numChannels() > 1) { 70 | envir() << "AMRAudioRTPSink: Warning: Input source has " << amrSource.numChannels() 71 | << " audio channels. In the current implementation, the multi-frame frame-block will be split over multiple RTP packets\n"; 72 | } 73 | 74 | return True; 75 | } 76 | 77 | void AMRAudioRTPSink::doSpecialFrameHandling(unsigned fragmentationOffset, 78 | unsigned char* frameStart, 79 | unsigned numBytesInFrame, 80 | struct timeval frameTimestamp, 81 | unsigned numRemainingBytes) { 82 | // If this is the 1st frame in the 1st packet, set the RTP 'M' (marker) 83 | // bit (because this is considered the start of a talk spurt): 84 | if (isFirstPacket() && isFirstFrameInPacket()) { 85 | setMarkerBit(); 86 | } 87 | 88 | // If this is the first frame in the packet, set the 1-byte payload 89 | // header (using CMR 15) 90 | if (isFirstFrameInPacket()) { 91 | u_int8_t payloadHeader = 0xF0; 92 | setSpecialHeaderBytes(&payloadHeader, 1, 0); 93 | } 94 | 95 | // Set the TOC field for the current frame, based on the "FT" and "Q" 96 | // values from our source: 97 | AMRAudioSource* amrSource = (AMRAudioSource*)fSource; 98 | if (amrSource == NULL) return; // sanity check 99 | 100 | u_int8_t toc = amrSource->lastFrameHeader(); 101 | Debug(ckite_log_message, "Last frame toc is %d\n", toc); 102 | // Clear the "F" bit, because we're the last frame in this packet: ##### 103 | toc &=~ 0x80; 104 | if (numFramesUsedSoFar() != specialHeaderSize() - 2) 105 | toc |= 0x80; 106 | setSpecialHeaderBytes(&toc, 1, 1+numFramesUsedSoFar()); 107 | 108 | // Important: Also call our base class's doSpecialFrameHandling(), 109 | // to set the packet's timestamp: 110 | MultiFramedRTPSink::doSpecialFrameHandling(fragmentationOffset, 111 | frameStart, numBytesInFrame, 112 | frameTimestamp, 113 | numRemainingBytes); 114 | } 115 | 116 | Boolean AMRAudioRTPSink 117 | ::frameCanAppearAfterPacketStart(unsigned char const* /*frameStart*/, 118 | unsigned /*numBytesInFrame*/) const { 119 | // For now, pack only one AMR frame into each outgoing RTP packet: ##### 120 | //return False; 121 | return True; 122 | } 123 | 124 | unsigned AMRAudioRTPSink::specialHeaderSize() const { 125 | // For now, because we're packing only one frame per packet, 126 | // there's just a 1-byte payload header, plus a 1-byte TOC ##### 127 | //return 2; 128 | return 11; 129 | } 130 | 131 | char const* AMRAudioRTPSink::auxSDPLine() { 132 | if (fFmtpSDPLine == NULL) { 133 | // Generate a "a=fmtp:" line with "octet-aligned=1" 134 | // (That is the only non-default parameter.) 135 | char buf[100]; 136 | sprintf(buf, "a=fmtp:%d octet-align=1\r\n", rtpPayloadType()); 137 | delete[] fFmtpSDPLine; fFmtpSDPLine = strDup(buf); 138 | } 139 | return fFmtpSDPLine; 140 | } 141 | -------------------------------------------------------------------------------- /rtsp_stack/AMRAudioRTPSink.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // RTP sink for AMR audio (RFC 3267) 19 | // C++ header 20 | 21 | #ifndef _AMR_AUDIO_RTP_SINK_HH 22 | #define _AMR_AUDIO_RTP_SINK_HH 23 | 24 | #ifndef _AUDIO_RTP_SINK_HH 25 | #include "AudioRTPSink.h" 26 | #endif 27 | 28 | class AMRAudioRTPSink: public AudioRTPSink { 29 | public: 30 | static AMRAudioRTPSink* createNew(UsageEnvironment& env, 31 | void* owner, 32 | Groupsock* RTPgs, 33 | unsigned char rtpPayloadFormat, 34 | Boolean sourceIsWideband = False, 35 | unsigned numChannelsInSource = 1); 36 | 37 | Boolean sourceIsWideband() const { return fSourceIsWideband; } 38 | 39 | protected: 40 | AMRAudioRTPSink(UsageEnvironment& env, void* owner, Groupsock* RTPgs, 41 | unsigned char rtpPayloadFormat, 42 | Boolean sourceIsWideband, unsigned numChannelsInSource); 43 | // called only by createNew() 44 | 45 | virtual ~AMRAudioRTPSink(); 46 | 47 | private: // redefined virtual functions: 48 | virtual Boolean sourceIsCompatibleWithUs(MediaSource& source); 49 | virtual void doSpecialFrameHandling(unsigned fragmentationOffset, 50 | unsigned char* frameStart, 51 | unsigned numBytesInFrame, 52 | struct timeval frameTimestamp, 53 | unsigned numRemainingBytes); 54 | virtual Boolean 55 | frameCanAppearAfterPacketStart(unsigned char const* frameStart, 56 | unsigned numBytesInFrame) const; 57 | 58 | virtual unsigned specialHeaderSize() const; 59 | virtual char const* auxSDPLine(); 60 | 61 | private: 62 | Boolean fSourceIsWideband; 63 | char* fFmtpSDPLine; 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /rtsp_stack/AMRAudioSource.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // A source object for AMR audio sources 19 | // Implementation 20 | 21 | #include "AMRAudioSource.h" 22 | 23 | AMRAudioSource::AMRAudioSource(UsageEnvironment& env, 24 | Boolean isWideband, unsigned numChannels) 25 | : FramedSource(env), 26 | fIsWideband(isWideband), fNumChannels(numChannels), fLastFrameHeader(0) { 27 | } 28 | 29 | AMRAudioSource::~AMRAudioSource() { 30 | } 31 | 32 | Boolean AMRAudioSource::isAMRAudioSource() const { 33 | return True; 34 | } 35 | -------------------------------------------------------------------------------- /rtsp_stack/AMRAudioSource.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // A source object for AMR audio sources 19 | // C++ header 20 | 21 | #ifndef _AMR_AUDIO_SOURCE_HH 22 | #define _AMR_AUDIO_SOURCE_HH 23 | 24 | #ifndef _FRAMED_SOURCE_HH 25 | #include "FramedSource.h" 26 | #endif 27 | 28 | class AMRAudioSource: public FramedSource { 29 | public: 30 | Boolean isWideband() const { return fIsWideband; } 31 | unsigned numChannels() const { return fNumChannels; } 32 | virtual Boolean isAMRAudioSource() const; 33 | 34 | u_int8_t lastFrameHeader() const { return fLastFrameHeader; } 35 | // The frame header for the most recently read frame (RFC 3267, sec. 5.3) 36 | 37 | protected: 38 | AMRAudioSource(UsageEnvironment& env, Boolean isWideband, unsigned numChannels); 39 | // virtual base class 40 | virtual ~AMRAudioSource(); 41 | 42 | private: 43 | // redefined virtual functions: 44 | //virtual Boolean isAMRAudioSource() const; 45 | 46 | protected: 47 | Boolean fIsWideband; 48 | unsigned fNumChannels; 49 | u_int8_t fLastFrameHeader; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /rtsp_stack/AudioRTPSink.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // A generic RTP sink for audio codecs (abstract base class) 19 | // Implementation 20 | 21 | #include "AudioRTPSink.h" 22 | 23 | AudioRTPSink::AudioRTPSink(UsageEnvironment& env, 24 | void* owner, 25 | Groupsock* rtpgs, unsigned char rtpPayloadType, 26 | unsigned rtpTimestampFrequency, 27 | char const* rtpPayloadFormatName, 28 | unsigned numChannels) 29 | : MultiFramedRTPSink(env, owner, rtpgs, rtpPayloadType, rtpTimestampFrequency, 30 | rtpPayloadFormatName, numChannels) { 31 | } 32 | 33 | AudioRTPSink::~AudioRTPSink() { 34 | } 35 | 36 | char const* AudioRTPSink::sdpMediaType() const { 37 | return "audio"; 38 | } 39 | -------------------------------------------------------------------------------- /rtsp_stack/AudioRTPSink.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // A generic RTP sink for audio codecs (abstract base class) 19 | // C++ header 20 | 21 | #ifndef _AUDIO_RTP_SINK_HH 22 | #define _AUDIO_RTP_SINK_HH 23 | 24 | #ifndef _MULTI_FRAMED_RTP_SINK_HH 25 | #include "MultiFramedRTPSink.h" 26 | #endif 27 | 28 | class AudioRTPSink: public MultiFramedRTPSink { 29 | protected: 30 | AudioRTPSink(UsageEnvironment& env, 31 | void* owner, 32 | Groupsock* rtpgs, unsigned char rtpPayloadType, 33 | unsigned rtpTimestampFrequency, 34 | char const* rtpPayloadFormatName, 35 | unsigned numChannels = 1); 36 | // (we're an abstract base class) 37 | virtual ~AudioRTPSink(); 38 | 39 | private: // redefined virtual functions: 40 | virtual char const* sdpMediaType() const; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /rtsp_stack/Base64.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Base64 encoding and decoding 19 | // implementation 20 | 21 | #include "Base64.h" 22 | #include "strDup.h" 23 | #include 24 | 25 | static char base64DecodeTable[256]; 26 | 27 | static void initBase64DecodeTable() { 28 | int i; 29 | for (i = 0; i < 256; ++i) base64DecodeTable[i] = (char)0x80; 30 | // default value: invalid 31 | 32 | for (i = 'A'; i <= 'Z'; ++i) base64DecodeTable[i] = 0 + (i - 'A'); 33 | for (i = 'a'; i <= 'z'; ++i) base64DecodeTable[i] = 26 + (i - 'a'); 34 | for (i = '0'; i <= '9'; ++i) base64DecodeTable[i] = 52 + (i - '0'); 35 | base64DecodeTable[(unsigned char)'+'] = 62; 36 | base64DecodeTable[(unsigned char)'/'] = 63; 37 | base64DecodeTable[(unsigned char)'='] = 0; 38 | } 39 | 40 | unsigned char* base64Decode(char* in, unsigned& resultSize, 41 | Boolean trimTrailingZeros) { 42 | static Boolean haveInitedBase64DecodeTable = False; 43 | if (!haveInitedBase64DecodeTable) { 44 | initBase64DecodeTable(); 45 | haveInitedBase64DecodeTable = True; 46 | } 47 | 48 | unsigned char* out = (unsigned char*)strDupSize(in); // ensures we have enough space 49 | int k = 0; 50 | int const jMax = strlen(in) - 3; 51 | // in case "in" is not a multiple of 4 bytes (although it should be) 52 | for (int j = 0; j < jMax; j += 4) { 53 | char inTmp[4], outTmp[4]; 54 | for (int i = 0; i < 4; ++i) { 55 | inTmp[i] = in[i+j]; 56 | outTmp[i] = base64DecodeTable[(unsigned char)inTmp[i]]; 57 | if ((outTmp[i]&0x80) != 0) outTmp[i] = 0; // pretend the input was 'A' 58 | } 59 | 60 | out[k++] = (outTmp[0]<<2) | (outTmp[1]>>4); 61 | out[k++] = (outTmp[1]<<4) | (outTmp[2]>>2); 62 | out[k++] = (outTmp[2]<<6) | outTmp[3]; 63 | } 64 | 65 | if (trimTrailingZeros) { 66 | while (k > 0 && out[k-1] == '\0') --k; 67 | } 68 | resultSize = k; 69 | unsigned char* result = new unsigned char[resultSize]; 70 | memmove(result, out, resultSize); 71 | delete[] out; 72 | 73 | return result; 74 | } 75 | 76 | static const char base64Char[] = 77 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 78 | 79 | char* base64Encode(char const* origSigned, unsigned origLength) { 80 | unsigned char const* orig = (unsigned char const*)origSigned; // in case any input bytes have the MSB set 81 | if (orig == NULL) return NULL; 82 | 83 | unsigned const numOrig24BitValues = origLength/3; 84 | Boolean havePadding = origLength > numOrig24BitValues*3; 85 | Boolean havePadding2 = origLength == numOrig24BitValues*3 + 2; 86 | unsigned const numResultBytes = 4*(numOrig24BitValues + havePadding); 87 | char* result = new char[numResultBytes+1]; // allow for trailing '\0' 88 | 89 | // Map each full group of 3 input bytes into 4 output base-64 characters: 90 | unsigned i; 91 | for (i = 0; i < numOrig24BitValues; ++i) { 92 | result[4*i+0] = base64Char[(orig[3*i]>>2)&0x3F]; 93 | result[4*i+1] = base64Char[(((orig[3*i]&0x3)<<4) | (orig[3*i+1]>>4))&0x3F]; 94 | result[4*i+2] = base64Char[((orig[3*i+1]<<2) | (orig[3*i+2]>>6))&0x3F]; 95 | result[4*i+3] = base64Char[orig[3*i+2]&0x3F]; 96 | } 97 | 98 | // Now, take padding into account. (Note: i == numOrig24BitValues) 99 | if (havePadding) { 100 | result[4*i+0] = base64Char[(orig[3*i]>>2)&0x3F]; 101 | if (havePadding2) { 102 | result[4*i+1] = base64Char[(((orig[3*i]&0x3)<<4) | (orig[3*i+1]>>4))&0x3F]; 103 | result[4*i+2] = base64Char[(orig[3*i+1]<<2)&0x3F]; 104 | } else { 105 | result[4*i+1] = base64Char[((orig[3*i]&0x3)<<4)&0x3F]; 106 | result[4*i+2] = '='; 107 | } 108 | result[4*i+3] = '='; 109 | } 110 | 111 | result[numResultBytes] = '\0'; 112 | return result; 113 | } 114 | -------------------------------------------------------------------------------- /rtsp_stack/Base64.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Base64 encoding and decoding 19 | // C++ header 20 | 21 | #ifndef _BASE64_HH 22 | #define _BASE64_HH 23 | 24 | #ifndef _BOOLEAN_HH 25 | #include "Boolean.h" 26 | #endif 27 | 28 | unsigned char* base64Decode(char* in, unsigned& resultSize, 29 | Boolean trimTrailingZeros = True); 30 | // returns a newly allocated array - of size "resultSize" - that 31 | // the caller is responsible for delete[]ing. 32 | 33 | char* base64Encode(char const* orig, unsigned origLength); 34 | // returns a 0-terminated string that 35 | // the caller is responsible for delete[]ing. 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /rtsp_stack/BasicHashTable.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Basic Hash Table implementation 18 | // C++ header 19 | 20 | #ifndef _BASIC_HASH_TABLE_HH 21 | #define _BASIC_HASH_TABLE_HH 22 | 23 | #ifndef _HASH_TABLE_HH 24 | #include "HashTable.h" 25 | #endif 26 | 27 | // A simple hash table implementation, inspired by the hash table 28 | // implementation used in Tcl 7.6: 29 | 30 | #define SMALL_HASH_TABLE_SIZE 4 31 | 32 | class BasicHashTable: public HashTable { 33 | private: 34 | class TableEntry; // forward 35 | 36 | public: 37 | BasicHashTable(int keyType); 38 | virtual ~BasicHashTable(); 39 | 40 | // Used to iterate through the members of the table: 41 | class Iterator; friend class Iterator; // to make Sun's C++ compiler happy 42 | class Iterator: public HashTable::Iterator { 43 | public: 44 | Iterator(BasicHashTable& table); 45 | 46 | private: // implementation of inherited pure virtual functions 47 | void* next(char const*& key); // returns 0 if none 48 | 49 | private: 50 | BasicHashTable& fTable; 51 | unsigned fNextIndex; // index of next bucket to be enumerated after this 52 | TableEntry* fNextEntry; // next entry in the current bucket 53 | }; 54 | 55 | private: // implementation of inherited pure virtual functions 56 | virtual void* Add(char const* key, void* value); 57 | // Returns the old value if different, otherwise 0 58 | virtual Boolean Remove(char const* key); 59 | virtual void* Lookup(char const* key) const; 60 | // Returns 0 if not found 61 | virtual unsigned numEntries() const; 62 | 63 | private: 64 | class TableEntry { 65 | public: 66 | TableEntry* fNext; 67 | char const* key; 68 | void* value; 69 | }; 70 | 71 | TableEntry* lookupKey(char const* key, unsigned& index) const; 72 | // returns entry matching "key", or NULL if none 73 | Boolean keyMatches(char const* key1, char const* key2) const; 74 | // used to implement "lookupKey()" 75 | 76 | TableEntry* insertNewEntry(unsigned index, char const* key); 77 | // creates a new entry, and inserts it in the table 78 | void assignKey(TableEntry* entry, char const* key); 79 | // used to implement "insertNewEntry()" 80 | 81 | void deleteEntry(unsigned index, TableEntry* entry); 82 | void deleteKey(TableEntry* entry); 83 | // used to implement "deleteEntry()" 84 | 85 | void rebuild(); // rebuilds the table as its size increases 86 | 87 | unsigned hashIndexFromKey(char const* key) const; 88 | // used to implement many of the routines above 89 | 90 | unsigned randomIndex(unsigned long i) const { 91 | return (((i*1103515245) >> fDownShift) & fMask); 92 | } 93 | 94 | private: 95 | TableEntry** fBuckets; // pointer to bucket array 96 | TableEntry* fStaticBuckets[SMALL_HASH_TABLE_SIZE];// used for small tables 97 | unsigned fNumBuckets, fNumEntries, fRebuildSize, fDownShift, fMask; 98 | int fKeyType; 99 | }; 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /rtsp_stack/BasicTaskScheduler0.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Basic Usage Environment: for a simple, non-scripted, console application 18 | // Implementation 19 | 20 | #include "BasicUsageEnvironment0.h" 21 | #include "HandlerSet.h" 22 | #include 23 | 24 | ////////// A subclass of DelayQueueEntry, 25 | ////////// used to implement BasicTaskScheduler0::scheduleDelayedTask() 26 | 27 | class AlarmHandler: public DelayQueueEntry { 28 | public: 29 | AlarmHandler(TaskFunc* proc, void* clientData, DelayInterval timeToDelay) 30 | : DelayQueueEntry(timeToDelay), fProc(proc), fClientData(clientData) { 31 | } 32 | 33 | private: // redefined virtual functions 34 | virtual void handleTimeout() { 35 | (*fProc)(fClientData); 36 | DelayQueueEntry::handleTimeout(); 37 | } 38 | 39 | private: 40 | TaskFunc* fProc; 41 | void* fClientData; 42 | }; 43 | 44 | 45 | ////////// BasicTaskScheduler0 ////////// 46 | 47 | BasicTaskScheduler0::BasicTaskScheduler0() 48 | : fLastHandledSocketNum(-1) { 49 | fHandlers = new HandlerSet; 50 | } 51 | 52 | BasicTaskScheduler0::~BasicTaskScheduler0() { 53 | delete fHandlers; 54 | } 55 | 56 | TaskToken BasicTaskScheduler0::scheduleDelayedTask(int64_t microseconds, 57 | TaskFunc* proc, 58 | void* clientData) { 59 | // fprintf(stderr, "microseconds = %u\n", microseconds); 60 | // fprintf(stderr, "proc = %x\n", proc); 61 | // fprintf(stderr, "clientData = %x\n", clientData); 62 | if (microseconds < 0) microseconds = 0; 63 | DelayInterval timeToDelay((long)(microseconds/1000000), (long)(microseconds%1000000)); 64 | AlarmHandler* alarmHandler = new AlarmHandler(proc, clientData, timeToDelay); 65 | if (!alarmHandler) // add by wayde 66 | { 67 | fprintf(stderr, "alarmHandler is NULL.\n"); 68 | return NULL; 69 | } 70 | fDelayQueue.addEntry(alarmHandler); 71 | 72 | return (void*)(alarmHandler->token()); 73 | } 74 | 75 | void BasicTaskScheduler0::unscheduleDelayedTask(TaskToken& prevTask) { 76 | DelayQueueEntry* alarmHandler = fDelayQueue.removeEntry((long)prevTask); 77 | prevTask = NULL; 78 | delete alarmHandler; 79 | } 80 | 81 | void BasicTaskScheduler0::doEventLoop(char* watchVariable) { 82 | // Repeatedly loop, handling readble sockets and timed events: 83 | while (1) { 84 | if (watchVariable != NULL && *watchVariable != 0) break; 85 | SingleStep(); 86 | } 87 | } 88 | 89 | 90 | ////////// HandlerSet (etc.) implementation ////////// 91 | 92 | HandlerDescriptor::HandlerDescriptor(HandlerDescriptor* nextHandler) 93 | : conditionSet(0), handlerProc(NULL) { 94 | // Link this descriptor into a doubly-linked list: 95 | if (nextHandler == this) { // initialization 96 | fNextHandler = fPrevHandler = this; 97 | } else { 98 | fNextHandler = nextHandler; 99 | fPrevHandler = nextHandler->fPrevHandler; 100 | nextHandler->fPrevHandler = this; 101 | fPrevHandler->fNextHandler = this; 102 | } 103 | } 104 | 105 | HandlerDescriptor::~HandlerDescriptor() { 106 | // Unlink this descriptor from a doubly-linked list: 107 | fNextHandler->fPrevHandler = fPrevHandler; 108 | fPrevHandler->fNextHandler = fNextHandler; 109 | } 110 | 111 | HandlerSet::HandlerSet() 112 | : fHandlers(&fHandlers) { 113 | fHandlers.socketNum = -1; // shouldn't ever get looked at, but in case... 114 | } 115 | 116 | HandlerSet::~HandlerSet() { 117 | // Delete each handler descriptor: 118 | while (fHandlers.fNextHandler != &fHandlers) { 119 | delete fHandlers.fNextHandler; // changes fHandlers->fNextHandler 120 | } 121 | } 122 | 123 | void HandlerSet 124 | ::assignHandler(int socketNum, int conditionSet, TaskScheduler::BackgroundHandlerProc* handlerProc, void* clientData) { 125 | // First, see if there's already a handler for this socket: 126 | HandlerDescriptor* handler = lookupHandler(socketNum); 127 | if (handler == NULL) { // No existing handler, so create a new descr: 128 | handler = new HandlerDescriptor(fHandlers.fNextHandler); 129 | handler->socketNum = socketNum; 130 | } 131 | 132 | handler->conditionSet = conditionSet; 133 | handler->handlerProc = handlerProc; 134 | handler->clientData = clientData; 135 | } 136 | 137 | void HandlerSet::clearHandler(int socketNum) { 138 | HandlerDescriptor* handler = lookupHandler(socketNum); 139 | delete handler; 140 | } 141 | 142 | void HandlerSet::moveHandler(int oldSocketNum, int newSocketNum) { 143 | HandlerDescriptor* handler = lookupHandler(oldSocketNum); 144 | if (handler != NULL) { 145 | handler->socketNum = newSocketNum; 146 | } 147 | } 148 | 149 | HandlerDescriptor* HandlerSet::lookupHandler(int socketNum) { 150 | HandlerDescriptor* handler; 151 | HandlerIterator iter(*this); 152 | while ((handler = iter.next()) != NULL) { 153 | if (handler->socketNum == socketNum) break; 154 | } 155 | return handler; 156 | } 157 | 158 | HandlerIterator::HandlerIterator(HandlerSet& handlerSet) 159 | : fOurSet(handlerSet) { 160 | reset(); 161 | } 162 | 163 | HandlerIterator::~HandlerIterator() { 164 | } 165 | 166 | void HandlerIterator::reset() { 167 | fNextPtr = fOurSet.fHandlers.fNextHandler; 168 | } 169 | 170 | HandlerDescriptor* HandlerIterator::next() { 171 | HandlerDescriptor* result = fNextPtr; 172 | if (result == &fOurSet.fHandlers) { // no more 173 | result = NULL; 174 | } else { 175 | fNextPtr = fNextPtr->fNextHandler; 176 | } 177 | 178 | return result; 179 | } 180 | -------------------------------------------------------------------------------- /rtsp_stack/BasicUDPSink.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2009 Live Networks, Inc. All rights reserved. 18 | // A simple UDP sink (i.e., without RTP or other headers added); one frame per packet 19 | // Implementation 20 | 21 | #include "BasicUDPSink.h" 22 | #include "GroupsockHelper.h" 23 | 24 | BasicUDPSink* BasicUDPSink::createNew(UsageEnvironment& env, Groupsock* gs, 25 | unsigned maxPayloadSize) { 26 | return new BasicUDPSink(env, gs, maxPayloadSize); 27 | } 28 | 29 | BasicUDPSink::BasicUDPSink(UsageEnvironment& env, Groupsock* gs, 30 | unsigned maxPayloadSize) 31 | : MediaSink(env), 32 | fGS(gs), fMaxPayloadSize(maxPayloadSize) { 33 | fOutputBuffer = new unsigned char[fMaxPayloadSize]; 34 | } 35 | 36 | BasicUDPSink::~BasicUDPSink() { 37 | delete[] fOutputBuffer; 38 | } 39 | 40 | Boolean BasicUDPSink::continuePlaying() { 41 | // Record the fact that we're starting to play now: 42 | gettimeofday(&fNextSendTime, NULL); 43 | 44 | // Arrange to get and send the first payload. 45 | // (This will also schedule any future sends.) 46 | continuePlaying1(); 47 | return True; 48 | } 49 | 50 | void BasicUDPSink::continuePlaying1() { 51 | if (fSource != NULL) { 52 | fSource->getNextFrame(fOutputBuffer, fMaxPayloadSize, 53 | afterGettingFrame, this, 54 | onSourceClosure, this); 55 | } 56 | } 57 | 58 | void BasicUDPSink::afterGettingFrame(void* clientData, unsigned frameSize, 59 | unsigned numTruncatedBytes, 60 | struct timeval /*presentationTime*/, 61 | unsigned durationInMicroseconds) { 62 | BasicUDPSink* sink = (BasicUDPSink*)clientData; 63 | sink->afterGettingFrame1(frameSize, numTruncatedBytes, durationInMicroseconds); 64 | } 65 | 66 | void BasicUDPSink::afterGettingFrame1(unsigned frameSize, unsigned numTruncatedBytes, 67 | unsigned durationInMicroseconds) { 68 | if (numTruncatedBytes > 0) { 69 | envir() << "BasicUDPSink::afterGettingFrame1(): The input frame data was too large for our spcified maximum payload size (" 70 | << fMaxPayloadSize << "). " 71 | << numTruncatedBytes << " bytes of trailing data was dropped!\n"; 72 | } 73 | 74 | // Send the packet: 75 | fGS->output(envir(), fGS->ttl(), fOutputBuffer, frameSize); 76 | 77 | // Figure out the time at which the next packet should be sent, based 78 | // on the duration of the payload that we just read: 79 | fNextSendTime.tv_usec += durationInMicroseconds; 80 | fNextSendTime.tv_sec += fNextSendTime.tv_usec/1000000; 81 | fNextSendTime.tv_usec %= 1000000; 82 | 83 | struct timeval timeNow; 84 | gettimeofday(&timeNow, NULL); 85 | int uSecondsToGo; 86 | if (fNextSendTime.tv_sec < timeNow.tv_sec) { 87 | uSecondsToGo = 0; // prevents integer underflow if too far behind 88 | } else { 89 | uSecondsToGo = (fNextSendTime.tv_sec - timeNow.tv_sec)*1000000 90 | + (fNextSendTime.tv_usec - timeNow.tv_usec); 91 | } 92 | 93 | // Delay this amount of time: 94 | nextTask() = envir().taskScheduler().scheduleDelayedTask(uSecondsToGo, 95 | (TaskFunc*)sendNext, this); 96 | } 97 | 98 | // The following is called after each delay between packet sends: 99 | void BasicUDPSink::sendNext(void* firstArg) { 100 | BasicUDPSink* sink = (BasicUDPSink*)firstArg; 101 | sink->continuePlaying1(); 102 | } 103 | -------------------------------------------------------------------------------- /rtsp_stack/BasicUDPSink.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // A simple UDP sink (i.e., without RTP or other headers added); one frame per packet 19 | // C++ header 20 | 21 | #ifndef _SIMPLE_UDP_SINK_HH 22 | #define _SIMPLE_UDP_SINK_HH 23 | 24 | #ifndef _MEDIA_SINK_HH 25 | #include "MediaSink.h" 26 | #endif 27 | #ifndef _GROUPSOCK_HH 28 | #include "Groupsock.h" 29 | #endif 30 | 31 | class BasicUDPSink: public MediaSink { 32 | public: 33 | static BasicUDPSink* createNew(UsageEnvironment& env, Groupsock* gs, 34 | unsigned maxPayloadSize = 1450); 35 | protected: 36 | BasicUDPSink(UsageEnvironment& env, Groupsock* gs, unsigned maxPayloadSize); 37 | // called only by createNew() 38 | virtual ~BasicUDPSink(); 39 | 40 | private: // redefined virtual functions: 41 | virtual Boolean continuePlaying(); 42 | 43 | private: 44 | void continuePlaying1(); 45 | 46 | static void afterGettingFrame(void* clientData, unsigned frameSize, 47 | unsigned numTruncatedBytes, 48 | struct timeval presentationTime, 49 | unsigned durationInMicroseconds); 50 | void afterGettingFrame1(unsigned frameSize, unsigned numTruncatedBytes, 51 | unsigned durationInMicroseconds); 52 | 53 | static void sendNext(void* firstArg); 54 | 55 | private: 56 | Groupsock* fGS; 57 | unsigned fMaxPayloadSize; 58 | unsigned char* fOutputBuffer; 59 | struct timeval fNextSendTime; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /rtsp_stack/BasicUsageEnvironment.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Basic Usage Environment: for a simple, non-scripted, console application 18 | // Implementation 19 | 20 | #include "BasicUsageEnvironment.h" 21 | #include 22 | 23 | ////////// BasicUsageEnvironment ////////// 24 | 25 | #if defined(__WIN32__) || defined(_WIN32) 26 | extern "C" int initializeWinsockIfNecessary(); 27 | #endif 28 | 29 | BasicUsageEnvironment::BasicUsageEnvironment(TaskScheduler& taskScheduler) 30 | : BasicUsageEnvironment0(taskScheduler) { 31 | #if defined(__WIN32__) || defined(_WIN32) 32 | if (!initializeWinsockIfNecessary()) { 33 | setResultErrMsg("Failed to initialize 'winsock': "); 34 | reportBackgroundError(); 35 | abort(); 36 | } 37 | #endif 38 | } 39 | 40 | BasicUsageEnvironment::~BasicUsageEnvironment() { 41 | } 42 | 43 | BasicUsageEnvironment* 44 | BasicUsageEnvironment::createNew(TaskScheduler& taskScheduler) { 45 | return new BasicUsageEnvironment(taskScheduler); 46 | } 47 | 48 | int BasicUsageEnvironment::getErrno() const { 49 | #if defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_WCE) 50 | return WSAGetLastError(); 51 | #else 52 | return errno; 53 | #endif 54 | } 55 | 56 | UsageEnvironment& BasicUsageEnvironment::operator<<(char const* str) { 57 | if (str == NULL) str = "(NULL)"; // sanity check 58 | fprintf(stderr, "%s", str); 59 | return *this; 60 | } 61 | 62 | UsageEnvironment& BasicUsageEnvironment::operator<<(int i) { 63 | fprintf(stderr, "%d", i); 64 | return *this; 65 | } 66 | 67 | UsageEnvironment& BasicUsageEnvironment::operator<<(unsigned u) { 68 | fprintf(stderr, "%u", u); 69 | return *this; 70 | } 71 | 72 | UsageEnvironment& BasicUsageEnvironment::operator<<(double d) { 73 | fprintf(stderr, "%f", d); 74 | return *this; 75 | } 76 | 77 | UsageEnvironment& BasicUsageEnvironment::operator<<(void* p) { 78 | fprintf(stderr, "%p", p); 79 | return *this; 80 | } 81 | -------------------------------------------------------------------------------- /rtsp_stack/BasicUsageEnvironment.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Basic Usage Environment: for a simple, non-scripted, console application 18 | // C++ header 19 | 20 | #ifndef _BASIC_USAGE_ENVIRONMENT_HH 21 | #define _BASIC_USAGE_ENVIRONMENT_HH 22 | 23 | #ifndef _BASIC_USAGE_ENVIRONMENT0_HH 24 | #include "BasicUsageEnvironment0.h" 25 | #endif 26 | 27 | class BasicUsageEnvironment: public BasicUsageEnvironment0 { 28 | public: 29 | static BasicUsageEnvironment* createNew(TaskScheduler& taskScheduler); 30 | 31 | // redefined virtual functions: 32 | virtual int getErrno() const; 33 | 34 | virtual UsageEnvironment& operator<<(char const* str); 35 | virtual UsageEnvironment& operator<<(int i); 36 | virtual UsageEnvironment& operator<<(unsigned u); 37 | virtual UsageEnvironment& operator<<(double d); 38 | virtual UsageEnvironment& operator<<(void* p); 39 | 40 | protected: 41 | BasicUsageEnvironment(TaskScheduler& taskScheduler); 42 | // called only by "createNew()" (or subclass constructors) 43 | virtual ~BasicUsageEnvironment(); 44 | }; 45 | 46 | 47 | class BasicTaskScheduler: public BasicTaskScheduler0 { 48 | public: 49 | static BasicTaskScheduler* createNew(); 50 | virtual ~BasicTaskScheduler(); 51 | 52 | protected: 53 | BasicTaskScheduler(); 54 | // called only by "createNew()" 55 | 56 | protected: 57 | // Redefined virtual functions: 58 | virtual void SingleStep(unsigned maxDelayTime); 59 | 60 | virtual void setBackgroundHandling(int socketNum, int conditionSet, BackgroundHandlerProc* handlerProc, void* clientData); 61 | virtual void moveSocketHandling(int oldSocketNum, int newSocketNum); 62 | 63 | protected: 64 | // To implement background operations: 65 | int fMaxNumSockets; 66 | fd_set fReadSet; 67 | fd_set fWriteSet; 68 | fd_set fExceptionSet; 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /rtsp_stack/BasicUsageEnvironment0.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Basic Usage Environment: for a simple, non-scripted, console application 18 | // Implementation 19 | 20 | #include "BasicUsageEnvironment0.h" 21 | #include 22 | 23 | ////////// BasicUsageEnvironment ////////// 24 | 25 | BasicUsageEnvironment0::BasicUsageEnvironment0(TaskScheduler& taskScheduler) 26 | : UsageEnvironment(taskScheduler), 27 | fBufferMaxSize(RESULT_MSG_BUFFER_MAX) { 28 | reset(); 29 | } 30 | 31 | BasicUsageEnvironment0::~BasicUsageEnvironment0() { 32 | } 33 | 34 | void BasicUsageEnvironment0::reset() { 35 | fCurBufferSize = 0; 36 | fResultMsgBuffer[fCurBufferSize] = '\0'; 37 | } 38 | 39 | 40 | // Implementation of virtual functions: 41 | 42 | char const* BasicUsageEnvironment0::getResultMsg() const { 43 | return fResultMsgBuffer; 44 | } 45 | 46 | void BasicUsageEnvironment0::setResultMsg(MsgString msg) { 47 | reset(); 48 | appendToResultMsg(msg); 49 | } 50 | 51 | void BasicUsageEnvironment0::setResultMsg(MsgString msg1, MsgString msg2) { 52 | setResultMsg(msg1); 53 | appendToResultMsg(msg2); 54 | } 55 | 56 | void BasicUsageEnvironment0::setResultMsg(MsgString msg1, MsgString msg2, 57 | MsgString msg3) { 58 | setResultMsg(msg1, msg2); 59 | appendToResultMsg(msg3); 60 | } 61 | 62 | void BasicUsageEnvironment0::setResultErrMsg(MsgString msg, int err) { 63 | setResultMsg(msg); 64 | 65 | #ifndef _WIN32_WCE 66 | appendToResultMsg(strerror(err == 0 ? getErrno() : err)); 67 | #endif 68 | } 69 | 70 | void BasicUsageEnvironment0::appendToResultMsg(MsgString msg) { 71 | char* curPtr = &fResultMsgBuffer[fCurBufferSize]; 72 | unsigned spaceAvailable = fBufferMaxSize - fCurBufferSize; 73 | unsigned msgLength = strlen(msg); 74 | 75 | // Copy only enough of "msg" as will fit: 76 | if (msgLength > spaceAvailable-1) { 77 | msgLength = spaceAvailable-1; 78 | } 79 | 80 | memmove(curPtr, (char*)msg, msgLength); 81 | fCurBufferSize += msgLength; 82 | fResultMsgBuffer[fCurBufferSize] = '\0'; 83 | } 84 | 85 | void BasicUsageEnvironment0::reportBackgroundError() { 86 | fputs(getResultMsg(), stderr); 87 | } 88 | 89 | -------------------------------------------------------------------------------- /rtsp_stack/BasicUsageEnvironment0.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Basic Usage Environment: for a simple, non-scripted, console application 18 | // C++ header 19 | 20 | #ifndef _BASIC_USAGE_ENVIRONMENT0_HH 21 | #define _BASIC_USAGE_ENVIRONMENT0_HH 22 | 23 | #ifndef _BASICUSAGEENVIRONMENT_VERSION_HH 24 | #include "BasicUsageEnvironment_version.h" 25 | #endif 26 | 27 | #ifndef _USAGE_ENVIRONMENT_HH 28 | #include "UsageEnvironment.h" 29 | #endif 30 | 31 | #ifndef _DELAY_QUEUE_HH 32 | #include "DelayQueue.h" 33 | #endif 34 | 35 | #define RESULT_MSG_BUFFER_MAX 1000 36 | 37 | // An abstract base class, useful for subclassing 38 | // (e.g., to redefine the implementation of "operator<<") 39 | class BasicUsageEnvironment0: public UsageEnvironment { 40 | public: 41 | // redefined virtual functions: 42 | virtual MsgString getResultMsg() const; 43 | 44 | virtual void setResultMsg(MsgString msg); 45 | virtual void setResultMsg(MsgString msg1, 46 | MsgString msg2); 47 | virtual void setResultMsg(MsgString msg1, 48 | MsgString msg2, 49 | MsgString msg3); 50 | virtual void setResultErrMsg(MsgString msg, int err = 0); 51 | 52 | virtual void appendToResultMsg(MsgString msg); 53 | 54 | virtual void reportBackgroundError(); 55 | 56 | protected: 57 | BasicUsageEnvironment0(TaskScheduler& taskScheduler); 58 | virtual ~BasicUsageEnvironment0(); 59 | 60 | private: 61 | void reset(); 62 | 63 | char fResultMsgBuffer[RESULT_MSG_BUFFER_MAX]; 64 | unsigned fCurBufferSize; 65 | unsigned fBufferMaxSize; 66 | }; 67 | 68 | class HandlerSet; // forward 69 | 70 | // An abstract base class, useful for subclassing 71 | // (e.g., to redefine the implementation of socket event handling) 72 | class BasicTaskScheduler0: public TaskScheduler { 73 | public: 74 | virtual ~BasicTaskScheduler0(); 75 | 76 | virtual void SingleStep(unsigned maxDelayTime = 0) = 0; 77 | // "maxDelayTime" is in microseconds. It allows a subclass to impose a limit 78 | // on how long "select()" can delay, in case it wants to also do polling. 79 | // 0 (the default value) means: There's no maximum; just look at the delay queue 80 | 81 | public: 82 | // Redefined virtual functions: 83 | virtual TaskToken scheduleDelayedTask(int64_t microseconds, TaskFunc* proc, 84 | void* clientData); 85 | virtual void unscheduleDelayedTask(TaskToken& prevTask); 86 | 87 | virtual void doEventLoop(char* watchVariable); 88 | 89 | protected: 90 | BasicTaskScheduler0(); 91 | 92 | protected: 93 | // To implement delayed operations: 94 | DelayQueue fDelayQueue; 95 | 96 | // To implement background reads: 97 | HandlerSet* fHandlers; 98 | int fLastHandledSocketNum; 99 | }; 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /rtsp_stack/BasicUsageEnvironment_version.h: -------------------------------------------------------------------------------- 1 | // Version information for the "BasicUsageEnvironment" library 2 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 3 | 4 | #ifndef _BASICUSAGEENVIRONMENT_VERSION_HH 5 | #define _BASICUSAGEENVIRONMENT_VERSION_HH 6 | 7 | #define BASICUSAGEENVIRONMENT_LIBRARY_VERSION_STRING "2010.05.29" 8 | #define BASICUSAGEENVIRONMENT_LIBRARY_VERSION_INT 1275091200 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /rtsp_stack/Boolean.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | #ifndef _BOOLEAN_HH 17 | #define _BOOLEAN_HH 18 | 19 | #ifdef __BORLANDC__ 20 | #define Boolean bool 21 | #define False false 22 | #define True true 23 | #else 24 | typedef unsigned Boolean; 25 | #ifndef False 26 | const Boolean False = 0; 27 | #endif 28 | #ifndef True 29 | const Boolean True = 1; 30 | #endif 31 | 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /rtsp_stack/Debug.h: -------------------------------------------------------------------------------- 1 | //#define CKITE_DEBUG 2 | 3 | #if defined(CKITE_DEBUG) 4 | #define ckite_use_debug 1 5 | #else 6 | #define ckite_use_debug 0 7 | #endif 8 | 9 | #if ckite_use_debug == 1 10 | #define showlog fprintf 11 | #else 12 | #define showlog 13 | #endif 14 | 15 | typedef enum 16 | { 17 | ckite_log_message, //message 18 | ckite_log_warning, //warning 19 | ckite_log_error, //error 20 | ckite_log_misc //miscarriage 21 | } ckite_log_level; 22 | 23 | #ifndef __WIN32__ 24 | #define Debug(Level,fmt,...) \ 25 | do{ \ 26 | if (Level == ckite_log_message) { \ 27 | showlog(stderr, "[info]:"fmt"", ##__VA_ARGS__);}\ 28 | else if (Level == ckite_log_warning) { \ 29 | showlog(stderr, "[warning]:"fmt"", ##__VA_ARGS__);}\ 30 | else if (Level == ckite_log_warning) { \ 31 | showlog(stderr, "[error]:"fmt"", #__VA_ARGS__);}\ 32 | else if (Level == ckite_log_warning) { \ 33 | showlog(stderr, "[misc]:"fmt"", ##__VA_ARGS__);}\ 34 | }while(0) 35 | #else 36 | #define Debug 37 | #endif 38 | -------------------------------------------------------------------------------- /rtsp_stack/DelayQueue.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010, Live Networks, Inc. All rights reserved 17 | // Help by Carlo Bonamico to get working for Windows 18 | // Delay queue 19 | // Implementation 20 | #include "DelayQueue.h" 21 | #include "GroupsockHelper.h" 22 | 23 | static const int MILLION = 1000000; 24 | 25 | ///// Timeval ///// 26 | 27 | int Timeval::operator>=(const Timeval& arg2) const { 28 | return seconds() > arg2.seconds() 29 | || (seconds() == arg2.seconds() 30 | && useconds() >= arg2.useconds()); 31 | } 32 | 33 | void Timeval::operator+=(const DelayInterval& arg2) { 34 | secs() += arg2.seconds(); usecs() += arg2.useconds(); 35 | if (useconds() >= MILLION) { 36 | usecs() -= MILLION; 37 | ++secs(); 38 | } 39 | } 40 | 41 | void Timeval::operator-=(const DelayInterval& arg2) { 42 | secs() -= arg2.seconds(); usecs() -= arg2.useconds(); 43 | if ((int)useconds() < 0) { 44 | usecs() += MILLION; 45 | --secs(); 46 | } 47 | if ((int)seconds() < 0) 48 | secs() = usecs() = 0; 49 | 50 | } 51 | 52 | DelayInterval operator-(const Timeval& arg1, const Timeval& arg2) { 53 | time_base_seconds secs = arg1.seconds() - arg2.seconds(); 54 | time_base_seconds usecs = arg1.useconds() - arg2.useconds(); 55 | 56 | if ((int)usecs < 0) { 57 | usecs += MILLION; 58 | --secs; 59 | } 60 | if ((int)secs < 0) 61 | return DELAY_ZERO; 62 | else 63 | return DelayInterval(secs, usecs); 64 | } 65 | 66 | 67 | ///// DelayInterval ///// 68 | 69 | DelayInterval operator*(short arg1, const DelayInterval& arg2) { 70 | time_base_seconds result_seconds = arg1*arg2.seconds(); 71 | time_base_seconds result_useconds = arg1*arg2.useconds(); 72 | 73 | time_base_seconds carry = result_useconds/MILLION; 74 | result_useconds -= carry*MILLION; 75 | result_seconds += carry; 76 | 77 | return DelayInterval(result_seconds, result_useconds); 78 | } 79 | 80 | #ifndef INT_MAX 81 | #define INT_MAX 0x7FFFFFFF 82 | #endif 83 | const DelayInterval DELAY_ZERO(0, 0); 84 | const DelayInterval DELAY_SECOND(1, 0); 85 | const DelayInterval ETERNITY(INT_MAX, MILLION-1); 86 | // used internally to make the implementation work 87 | 88 | 89 | ///// DelayQueueEntry ///// 90 | 91 | long DelayQueueEntry::tokenCounter = 0; 92 | 93 | DelayQueueEntry::DelayQueueEntry(DelayInterval delay) 94 | : fDeltaTimeRemaining(delay) { 95 | fNext = fPrev = this; 96 | fToken = ++tokenCounter; 97 | } 98 | 99 | DelayQueueEntry::~DelayQueueEntry() { 100 | } 101 | 102 | void DelayQueueEntry::handleTimeout() { 103 | delete this; 104 | } 105 | 106 | 107 | ///// DelayQueue ///// 108 | 109 | DelayQueue::DelayQueue() 110 | : DelayQueueEntry(ETERNITY) { 111 | fLastSyncTime = TimeNow(); 112 | } 113 | 114 | DelayQueue::~DelayQueue() { 115 | while (fNext != this) removeEntry(fNext); 116 | } 117 | 118 | void DelayQueue::addEntry(DelayQueueEntry* newEntry) { 119 | synchronize(); 120 | 121 | DelayQueueEntry* cur = head(); 122 | while (newEntry->fDeltaTimeRemaining >= cur->fDeltaTimeRemaining) { 123 | newEntry->fDeltaTimeRemaining -= cur->fDeltaTimeRemaining; 124 | cur = cur->fNext; 125 | } 126 | 127 | cur->fDeltaTimeRemaining -= newEntry->fDeltaTimeRemaining; 128 | 129 | // Add "newEntry" to the queue, just before "cur": 130 | newEntry->fNext = cur; 131 | newEntry->fPrev = cur->fPrev; 132 | cur->fPrev = newEntry->fPrev->fNext = newEntry; 133 | } 134 | 135 | void DelayQueue::updateEntry(DelayQueueEntry* entry, DelayInterval newDelay) { 136 | if (entry == NULL) return; 137 | 138 | removeEntry(entry); 139 | entry->fDeltaTimeRemaining = newDelay; 140 | addEntry(entry); 141 | } 142 | 143 | void DelayQueue::updateEntry(long tokenToFind, DelayInterval newDelay) { 144 | DelayQueueEntry* entry = findEntryByToken(tokenToFind); 145 | updateEntry(entry, newDelay); 146 | } 147 | 148 | void DelayQueue::removeEntry(DelayQueueEntry* entry) { 149 | if (entry == NULL || entry->fNext == NULL) return; 150 | 151 | entry->fNext->fDeltaTimeRemaining += entry->fDeltaTimeRemaining; 152 | entry->fPrev->fNext = entry->fNext; 153 | entry->fNext->fPrev = entry->fPrev; 154 | entry->fNext = entry->fPrev = NULL; 155 | // in case we should try to remove it again 156 | } 157 | 158 | DelayQueueEntry* DelayQueue::removeEntry(long tokenToFind) { 159 | DelayQueueEntry* entry = findEntryByToken(tokenToFind); 160 | removeEntry(entry); 161 | return entry; 162 | } 163 | 164 | DelayInterval const& DelayQueue::timeToNextAlarm() { 165 | if (head()->fDeltaTimeRemaining == DELAY_ZERO) return DELAY_ZERO; // a common case 166 | 167 | synchronize(); 168 | return head()->fDeltaTimeRemaining; 169 | } 170 | 171 | void DelayQueue::handleAlarm() { 172 | if (head()->fDeltaTimeRemaining != DELAY_ZERO) synchronize(); 173 | 174 | if (head()->fDeltaTimeRemaining == DELAY_ZERO) { 175 | // This event is due to be handled: 176 | DelayQueueEntry* toRemove = head(); 177 | removeEntry(toRemove); // do this first, in case handler accesses queue 178 | 179 | toRemove->handleTimeout(); 180 | } 181 | } 182 | 183 | DelayQueueEntry* DelayQueue::findEntryByToken(long tokenToFind) { 184 | DelayQueueEntry* cur = head(); 185 | while (cur != this) { 186 | if (cur->token() == tokenToFind) return cur; 187 | cur = cur->fNext; 188 | } 189 | 190 | return NULL; 191 | } 192 | 193 | void DelayQueue::synchronize() { 194 | // First, figure out how much time has elapsed since the last sync: 195 | EventTime timeNow = TimeNow(); 196 | if (timeNow < fLastSyncTime) { 197 | // The system clock has apparently gone back in time; reset our sync time and return: 198 | fLastSyncTime = timeNow; 199 | return; 200 | } 201 | DelayInterval timeSinceLastSync = timeNow - fLastSyncTime; 202 | fLastSyncTime = timeNow; 203 | 204 | // Then, adjust the delay queue for any entries whose time is up: 205 | DelayQueueEntry* curEntry = head(); 206 | while (timeSinceLastSync >= curEntry->fDeltaTimeRemaining) { 207 | timeSinceLastSync -= curEntry->fDeltaTimeRemaining; 208 | curEntry->fDeltaTimeRemaining = DELAY_ZERO; 209 | curEntry = curEntry->fNext; 210 | } 211 | curEntry->fDeltaTimeRemaining -= timeSinceLastSync; 212 | } 213 | 214 | 215 | ///// EventTime ///// 216 | 217 | EventTime TimeNow() { 218 | struct timeval tvNow; 219 | 220 | gettimeofday(&tvNow, NULL); 221 | 222 | return EventTime(tvNow.tv_sec, tvNow.tv_usec); 223 | } 224 | 225 | const EventTime THE_END_OF_TIME(INT_MAX); 226 | -------------------------------------------------------------------------------- /rtsp_stack/DelayQueue.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010, Live Networks, Inc. All rights reserved 17 | // Delay queue 18 | // C++ header 19 | 20 | #ifndef _DELAY_QUEUE_HH 21 | #define _DELAY_QUEUE_HH 22 | 23 | #ifndef _NET_COMMON_H 24 | #include "NetCommon.h" 25 | #endif 26 | 27 | #ifdef TIME_BASE 28 | typedef TIME_BASE time_base_seconds; 29 | #else 30 | typedef long time_base_seconds; 31 | #endif 32 | 33 | ///// A "Timeval" can be either an absolute time, or a time interval ///// 34 | 35 | class Timeval { 36 | public: 37 | time_base_seconds seconds() const { 38 | return fTv.tv_sec; 39 | } 40 | time_base_seconds seconds() { 41 | return fTv.tv_sec; 42 | } 43 | time_base_seconds useconds() const { 44 | return fTv.tv_usec; 45 | } 46 | time_base_seconds useconds() { 47 | return fTv.tv_usec; 48 | } 49 | 50 | int operator>=(Timeval const& arg2) const; 51 | int operator<=(Timeval const& arg2) const { 52 | return arg2 >= *this; 53 | } 54 | int operator<(Timeval const& arg2) const { 55 | return !(*this >= arg2); 56 | } 57 | int operator>(Timeval const& arg2) const { 58 | return arg2 < *this; 59 | } 60 | int operator==(Timeval const& arg2) const { 61 | return *this >= arg2 && arg2 >= *this; 62 | } 63 | int operator!=(Timeval const& arg2) const { 64 | return !(*this == arg2); 65 | } 66 | 67 | void operator+=(class DelayInterval const& arg2); 68 | void operator-=(class DelayInterval const& arg2); 69 | // returns ZERO iff arg2 >= arg1 70 | 71 | protected: 72 | Timeval(time_base_seconds seconds, time_base_seconds useconds) { 73 | fTv.tv_sec = seconds; fTv.tv_usec = useconds; 74 | } 75 | 76 | private: 77 | time_base_seconds& secs() { 78 | return (time_base_seconds&)fTv.tv_sec; 79 | } 80 | time_base_seconds& usecs() { 81 | return (time_base_seconds&)fTv.tv_usec; 82 | } 83 | 84 | struct timeval fTv; 85 | }; 86 | 87 | #ifndef max 88 | inline Timeval max(Timeval const& arg1, Timeval const& arg2) { 89 | return arg1 >= arg2 ? arg1 : arg2; 90 | } 91 | #endif 92 | #ifndef min 93 | inline Timeval min(Timeval const& arg1, Timeval const& arg2) { 94 | return arg1 <= arg2 ? arg1 : arg2; 95 | } 96 | #endif 97 | 98 | class DelayInterval operator-(Timeval const& arg1, Timeval const& arg2); 99 | // returns ZERO iff arg2 >= arg1 100 | 101 | 102 | ///// DelayInterval ///// 103 | 104 | class DelayInterval: public Timeval { 105 | public: 106 | DelayInterval(time_base_seconds seconds, time_base_seconds useconds) 107 | : Timeval(seconds, useconds) {} 108 | }; 109 | 110 | DelayInterval operator*(short arg1, DelayInterval const& arg2); 111 | 112 | extern DelayInterval const DELAY_ZERO; 113 | extern DelayInterval const DELAY_SECOND; 114 | DelayInterval const DELAY_MINUTE = 60*DELAY_SECOND; 115 | DelayInterval const DELAY_HOUR = 60*DELAY_MINUTE; 116 | DelayInterval const DELAY_DAY = 24*DELAY_HOUR; 117 | 118 | ///// EventTime ///// 119 | 120 | class EventTime: public Timeval { 121 | public: 122 | EventTime(unsigned secondsSinceEpoch = 0, 123 | unsigned usecondsSinceEpoch = 0) 124 | // We use the Unix standard epoch: January 1, 1970 125 | : Timeval(secondsSinceEpoch, usecondsSinceEpoch) {} 126 | }; 127 | 128 | EventTime TimeNow(); 129 | 130 | extern EventTime const THE_END_OF_TIME; 131 | 132 | 133 | ///// DelayQueueEntry ///// 134 | 135 | class DelayQueueEntry { 136 | public: 137 | virtual ~DelayQueueEntry(); 138 | 139 | long token() { 140 | return fToken; 141 | } 142 | 143 | protected: // abstract base class 144 | DelayQueueEntry(DelayInterval delay); 145 | 146 | virtual void handleTimeout(); 147 | 148 | private: 149 | friend class DelayQueue; 150 | DelayQueueEntry* fNext; 151 | DelayQueueEntry* fPrev; 152 | DelayInterval fDeltaTimeRemaining; 153 | 154 | long fToken; 155 | static long tokenCounter; 156 | }; 157 | 158 | ///// DelayQueue ///// 159 | 160 | class DelayQueue: public DelayQueueEntry { 161 | public: 162 | DelayQueue(); 163 | virtual ~DelayQueue(); 164 | 165 | void addEntry(DelayQueueEntry* newEntry); // returns a token for the entry 166 | void updateEntry(DelayQueueEntry* entry, DelayInterval newDelay); 167 | void updateEntry(long tokenToFind, DelayInterval newDelay); 168 | void removeEntry(DelayQueueEntry* entry); // but doesn't delete it 169 | DelayQueueEntry* removeEntry(long tokenToFind); // but doesn't delete it 170 | 171 | DelayInterval const& timeToNextAlarm(); 172 | void handleAlarm(); 173 | 174 | private: 175 | DelayQueueEntry* head() { return fNext; } 176 | DelayQueueEntry* findEntryByToken(long token); 177 | void synchronize(); // bring the 'time remaining' fields up-to-date 178 | 179 | EventTime fLastSyncTime; 180 | }; 181 | 182 | #endif 183 | -------------------------------------------------------------------------------- /rtsp_stack/EncoderMediaSession.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // A data structure that represents a session that consists of 19 | // potentially multiple (audio and/or video) sub-sessions 20 | // (This data structure is used for media *streamers* - i.e., servers. 21 | // For media receivers, use "MediaSession" instead.) 22 | // C++ header 23 | 24 | #ifndef _ENCODER_MEDIA_SESSION_HH 25 | #define _ENCODER_MEDIA_SESSION_HH 26 | 27 | #ifndef _MEDIA_HH 28 | #include "Media.h" 29 | #endif 30 | #ifndef _GROUPEID_HH 31 | #include "GroupEId.h" 32 | #endif 33 | #ifndef _RTP_INTERFACE_HH 34 | #include "RTPInterface.h" // for ServerRequestAlternativeByteHandler 35 | #endif 36 | 37 | class EncoderMediaSession: public Medium { 38 | public: 39 | static EncoderMediaSession* createNew(UsageEnvironment& env, 40 | char const* streamName = NULL, 41 | char const* mac = NULL, 42 | char const* sn = NULL, 43 | const int cam_id = 1, 44 | char const* info = NULL, 45 | char const* description = NULL, 46 | Boolean isSSM = False, 47 | char const* miscSDPLines = NULL); 48 | 49 | virtual ~EncoderMediaSession(); 50 | 51 | static Boolean lookupByName(UsageEnvironment& env, 52 | char const* mediumName, 53 | EncoderMediaSession*& resultSession); 54 | 55 | char* generateSDPDescription(); // based on the entire session 56 | // Note: The caller is responsible for freeing the returned string 57 | 58 | char const* streamName() const { return fStreamName; } 59 | 60 | Boolean addSubsession(EncoderMediaSession* subsession); 61 | 62 | void testScaleFactor(float& scale); // sets "scale" to the actual supported scale 63 | float duration() const; 64 | // a result == 0 means an unbounded session (the default) 65 | // a result < 0 means: subsession durations differ; the result is -(the largest) 66 | // a result > 0 means: this is the duration of a bounded session 67 | 68 | unsigned referenceCount() const { return fReferenceCount; } 69 | void incrementReferenceCount() { ++fReferenceCount; } 70 | void decrementReferenceCount() { if (fReferenceCount > 0) --fReferenceCount; } 71 | Boolean& deleteWhenUnreferenced() { return fDeleteWhenUnreferenced; } 72 | 73 | protected: 74 | EncoderMediaSession(UsageEnvironment& env, char const* streamName, 75 | char const* info, char const* description, 76 | Boolean isSSM, char const* miscSDPLines); 77 | // called only by "createNew()" 78 | 79 | private: // redefined virtual functions 80 | virtual Boolean isServerMediaSession() const; 81 | 82 | private: 83 | Boolean fIsSSM; 84 | 85 | // Linkage fields: 86 | friend class ServerMediaSubsessionIterator; 87 | ServerMediaSubsession* fSubsessionsHead; 88 | ServerMediaSubsession* fSubsessionsTail; 89 | unsigned fSubsessionCounter; 90 | 91 | char* fStreamName; 92 | char* fInfoSDPString; 93 | char* fDescriptionSDPString; 94 | char* fMiscSDPLines; 95 | struct timeval fCreationTime; 96 | unsigned fReferenceCount; 97 | Boolean fDeleteWhenUnreferenced; 98 | }; 99 | 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /rtsp_stack/EncoderMediaSubsession.h: -------------------------------------------------------------------------------- 1 | #ifndef ENCODER_MEDIA_SUBSESSION_H 2 | #define ENCODER_MEDIA_SUBSESSION_H 3 | 4 | class EncoderMediaSubsession: public ServerMediaSubsession { 5 | public: 6 | static EncoderMediaSubsession* createNew(UsageEnvironment& env, void* owner, Boolean isAudio, Boolean reuseFirstSource, 7 | portNumBits initialPortNum = 6970); 8 | void SetVideoParameters(unsigned char channel, int width, int height, int bitrate, int framerate, int keyinterval, char *type); 9 | void SetAudioParameters(int bitrate, int framelength, int samplerate, char *type); 10 | protected: // we're a virtual base class 11 | EncoderMediaSubsession(UsageEnvironment& env, void* owner, Boolean isAudio, Boolean reuseFirstSource, 12 | portNumBits initialPortNum = 6970); 13 | virtual ~EncoderMediaSubsession(); 14 | 15 | protected: // redefined virtual functions 16 | virtual char const* sdpLines(); 17 | virtual void getStreamParameters(unsigned clientSessionId, 18 | netAddressBits clientAddress, 19 | Port const& clientRTPPort, 20 | Port const& clientRTCPPort, 21 | int tcpSocketNum, 22 | unsigned char rtpChannelId, 23 | unsigned char rtcpChannelId, 24 | netAddressBits& destinationAddress, 25 | u_int8_t& destinationTTL, 26 | Boolean& isMulticast, 27 | Port& serverRTPPort, 28 | Port& serverRTCPPort, 29 | void*& streamToken); 30 | virtual void startStream(unsigned clientSessionId, void* streamToken, 31 | TaskFunc* rtcpRRHandler, 32 | void* rtcpRRHandlerClientData, 33 | unsigned short& rtpSeqNum, 34 | unsigned& rtpTimestamp, 35 | ServerRequestAlternativeByteHandler* serverRequestAlternativeByteHandler, 36 | void* serverRequestAlternativeByteHandlerClientData, 37 | void* videofp, 38 | unsigned int fMagic, 39 | Boolean isResponse); 40 | virtual void pauseStream(unsigned clientSessionId, void* streamToken); 41 | virtual void seekStream(unsigned clientSessionId, void* streamToken, double seekNPT); 42 | virtual void setStreamScale(unsigned clientSessionId, void* streamToken, float scale); 43 | virtual void deleteStream(unsigned clientSessionId, void*& streamToken); 44 | 45 | protected: // new virtual functions, possibly redefined by subclasses 46 | virtual char const* getAuxSDPLine(RTPSink* rtpSink, 47 | FramedSource* inputSource); 48 | virtual void seekStreamSource(FramedSource* inputSource, double seekNPT); 49 | virtual void setStreamSourceScale(FramedSource* inputSource, float scale); 50 | virtual void closeStreamSource(FramedSource *inputSource); 51 | 52 | protected: // new virtual functions, defined by all subclasses 53 | virtual FramedSource* createNewVideoSource(unsigned clientSessionId, 54 | unsigned& estBitrate); 55 | virtual FramedSource* createNewAudioSource(unsigned clientSessionId, 56 | unsigned& estBitrate); 57 | // "estBitrate" is the stream's estimated bitrate, in kbps 58 | virtual RTPSink* createNewRTPSink(Groupsock* rtpGroupsock, 59 | unsigned char rtpPayloadTypeIfDynamic, 60 | FramedSource* inputSource); 61 | 62 | private: 63 | void setSDPLinesFromRTPSink(RTPSink* rtpSink, FramedSource* inputSource, unsigned estBitrate); 64 | // used to implement "sdpLines()" 65 | 66 | private: 67 | FramedSource* fMediaSource; 68 | Boolean fIsAudio; 69 | Boolean fReuseFirstSource; 70 | portNumBits fInitialPortNum; 71 | HashTable* fDestinationsHashTable; // indexed by client session id 72 | void* fLastStreamToken; 73 | char* fSDPLines; 74 | char fCNAME[100]; // for RTCP 75 | void* fOwner; 76 | friend class StreamState; 77 | 78 | // Video or audio parameters 79 | unsigned char fChannel; 80 | int fWidth; 81 | int fHeight; 82 | int fVideoBitrate; 83 | int fFramerate; 84 | int fKeyInterval; 85 | int fAudioBitrate; 86 | int fFrameLength; 87 | int fSamplerate; 88 | char vType[10]; 89 | char aType[10]; 90 | }; 91 | 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /rtsp_stack/EncoderSource.h: -------------------------------------------------------------------------------- 1 | #ifndef ENCODER_SOURCE_H_ 2 | #define ENCODER_SOURCE_H_ 3 | 4 | #include "FramedSource.h" 5 | #include "AMRAudioSource.h" 6 | #ifdef SDKH264 7 | #include "x264.h" 8 | #endif 9 | 10 | class TimeCode { 11 | public: 12 | TimeCode(); 13 | virtual ~TimeCode(); 14 | 15 | int operator==(TimeCode const& arg2); 16 | unsigned days, hours, minutes, seconds, pictures; 17 | }; 18 | 19 | class EncoderVideoSource: public FramedSource 20 | { 21 | public: 22 | enum VideoCodec { VIDEO_RAW, VIDEO_MPEG4, VIDEO_H264 }; 23 | 24 | static EncoderVideoSource* createNew(UsageEnvironment& env, unsigned int width, 25 | unsigned int height, unsigned int framerate, unsigned int bitrate, unsigned int keyinterval, char *type); 26 | void setPlayTime(unsigned int time) { playTime = time; } 27 | void setPauseTime(unsigned int time) { pauseTime = time; } 28 | void setPlayFile(FILE *videofp) { fp = videofp;} 29 | void setChannelNumber(unsigned char channel) {fChannel = channel;} 30 | 31 | Boolean& pictureEndMarker() { return fPictureEndMarker; } 32 | void reset(); 33 | u_int8_t profile_and_level_indication() const { 34 | return fProfileAndLevelIndication; 35 | } 36 | unsigned char* getConfigBytes(unsigned& numBytes) const; 37 | Boolean currentNALUnitEndsAccessUnit() {return True;} 38 | protected: 39 | EncoderVideoSource(UsageEnvironment& env, unsigned int width, unsigned int height, unsigned int framerate, unsigned int bitrate, unsigned int keyinterval, VideoCodec codec,char *type); 40 | virtual ~EncoderVideoSource(); 41 | private: // redefined virtual functions 42 | virtual void doGetNextFrame(); 43 | virtual Boolean isMPEG4VideoStreamFramer() const; 44 | virtual Boolean isH264VideoStreamFramer() const; 45 | void MPEG4_doGetNextFrame(); 46 | void H264_doGetNextFrame(); 47 | int computePresentationTime(); 48 | int getLivehdFrame(void); 49 | private: 50 | FILE* fp; 51 | #if SDKH264 52 | x264_t *x264_handle; 53 | x264_param_t m_param; 54 | x264_picture_t m_pic; 55 | #endif 56 | unsigned char fChannel; 57 | unsigned int fWidth; 58 | unsigned int fHeight; 59 | unsigned int playTime; 60 | unsigned int pauseTime; 61 | unsigned char* fBuffer; 62 | unsigned int fBitrate; // in kbps 63 | unsigned int fFramerate; 64 | unsigned int fKeyInterval; 65 | VideoCodec fCodec; 66 | void* fEncoderHandle; 67 | private: 68 | unsigned int fStartTime; 69 | unsigned int fCurrTime; 70 | Boolean fPictureEndMarker; 71 | unsigned fPictureCount; 72 | u_int8_t fProfileAndLevelIndication; 73 | unsigned char* fConfigBytes; 74 | unsigned fNumConfigBytes; 75 | char mediaType[10]; 76 | char *more_nal[4]; 77 | int more_nal_len[4]; 78 | }; 79 | 80 | class EncoderAudioSource: public AMRAudioSource 81 | { 82 | public: 83 | enum AudioCodec { AUDIO_RAW, AUDIO_AMRNB, AUDIO_AMRWB }; 84 | static EncoderAudioSource* createNew(UsageEnvironment& env, unsigned int samplerate, unsigned int framelength, 85 | unsigned int bitrate, char *type); 86 | protected: 87 | EncoderAudioSource(UsageEnvironment& env, unsigned int samplerate, unsigned int framelength, 88 | unsigned int bitrate, AudioCodec codec,char *type); 89 | virtual ~EncoderAudioSource(); 90 | private: // redefined virtual functions 91 | virtual void doGetNextFrame(); 92 | virtual Boolean isAMRAudioSource() const; 93 | int computeAudioPresentationTime(); 94 | 95 | 96 | private: 97 | FILE* fp; 98 | unsigned char* fBuffer; 99 | unsigned int fSampleRate; 100 | unsigned int fFrameLength; // in samples 101 | unsigned int fBitrate; // in kbps 102 | AudioCodec fCodec; 103 | int *fAudioCodec; 104 | unsigned int fStartTime; 105 | unsigned int fCurrTime; 106 | char mediaType[10]; 107 | }; 108 | #endif 109 | -------------------------------------------------------------------------------- /rtsp_stack/FramedFilter.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2009 Live Networks, Inc. All rights reserved. 18 | // Framed Filters 19 | // Implementation 20 | 21 | #include "FramedFilter.h" 22 | 23 | ////////// FramedFilter ////////// 24 | #include 25 | 26 | FramedFilter::FramedFilter(UsageEnvironment& env, 27 | FramedSource* inputSource) 28 | : FramedSource(env), 29 | fInputSource(inputSource) { 30 | } 31 | 32 | FramedFilter::~FramedFilter() { 33 | Medium::close(fInputSource); 34 | } 35 | 36 | // Default implementations of needed virtual functions. These merely 37 | // call the same function in the input source - i.e., act like a 'null filter 38 | 39 | char const* FramedFilter::MIMEtype() const { 40 | if (fInputSource == NULL) return ""; 41 | 42 | return fInputSource->MIMEtype(); 43 | } 44 | 45 | void FramedFilter::getAttributes() const { 46 | if (fInputSource != NULL) fInputSource->getAttributes(); 47 | } 48 | 49 | void FramedFilter::doStopGettingFrames() { 50 | if (fInputSource != NULL) fInputSource->stopGettingFrames(); 51 | } 52 | -------------------------------------------------------------------------------- /rtsp_stack/FramedFilter.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2009 Live Networks, Inc. All rights reserved. 18 | // Framed Filters 19 | // C++ header 20 | 21 | #ifndef _FRAMED_FILTER_HH 22 | #define _FRAMED_FILTER_HH 23 | 24 | #ifndef _FRAMED_SOURCE_HH 25 | #include "FramedSource.h" 26 | #endif 27 | 28 | class FramedFilter: public FramedSource { 29 | public: 30 | FramedSource* inputSource() const { return fInputSource; } 31 | 32 | // Call before destruction if you want to prevent the destructor from closing the input source 33 | void detachInputSource() { fInputSource = NULL; } 34 | 35 | protected: 36 | FramedFilter(UsageEnvironment& env, FramedSource* inputSource); 37 | // abstract base class 38 | virtual ~FramedFilter(); 39 | 40 | protected: 41 | // Redefined virtual functions (with default 'null' implementations): 42 | virtual char const* MIMEtype() const; 43 | virtual void getAttributes() const; 44 | virtual void doStopGettingFrames(); 45 | 46 | protected: 47 | FramedSource* fInputSource; 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /rtsp_stack/FramedSource.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Framed Sources 19 | // Implementation 20 | 21 | #include "FramedSource.h" 22 | #include 23 | 24 | ////////// FramedSource ////////// 25 | 26 | FramedSource::FramedSource(UsageEnvironment& env) 27 | : MediaSource(env), 28 | fAfterGettingFunc(NULL), fAfterGettingClientData(NULL), 29 | fOnCloseFunc(NULL), fOnCloseClientData(NULL), 30 | fIsCurrentlyAwaitingData(False) { 31 | fPresentationTime.tv_sec = fPresentationTime.tv_usec = 0; // initially 32 | } 33 | 34 | FramedSource::~FramedSource() { 35 | } 36 | 37 | Boolean FramedSource::isFramedSource() const { 38 | return True; 39 | } 40 | 41 | Boolean FramedSource::lookupByName(UsageEnvironment& env, char const* sourceName, 42 | FramedSource*& resultSource) { 43 | resultSource = NULL; // unless we succeed 44 | 45 | MediaSource* source; 46 | if (!MediaSource::lookupByName(env, sourceName, source)) return False; 47 | 48 | if (!source->isFramedSource()) { 49 | env.setResultMsg(sourceName, " is not a framed source"); 50 | return False; 51 | } 52 | 53 | resultSource = (FramedSource*)source; 54 | return True; 55 | } 56 | 57 | void FramedSource::getNextFrame(unsigned char* to, unsigned maxSize, 58 | afterGettingFunc* afterGettingFunc, 59 | void* afterGettingClientData, 60 | onCloseFunc* onCloseFunc, 61 | void* onCloseClientData) { 62 | // Make sure we're not already being read: 63 | if (fIsCurrentlyAwaitingData) { 64 | envir() << "FramedSource[" << this << "]::getNextFrame(): attempting to read more than once at the same time!\n"; 65 | abort(); 66 | } 67 | 68 | fTo = to; 69 | fMaxSize = maxSize; 70 | fNumTruncatedBytes = 0; // by default; could be changed by doGetNextFrame() 71 | fDurationInMicroseconds = 0; // by default; could be changed by doGetNextFrame() 72 | fAfterGettingFunc = afterGettingFunc; 73 | fAfterGettingClientData = afterGettingClientData; 74 | fOnCloseFunc = onCloseFunc; 75 | fOnCloseClientData = onCloseClientData; 76 | fIsCurrentlyAwaitingData = True; 77 | 78 | doGetNextFrame(); 79 | } 80 | 81 | void FramedSource::afterGetting(FramedSource* source) { 82 | source->fIsCurrentlyAwaitingData = False; 83 | // indicates that we can be read again 84 | // Note that this needs to be done here, in case the "fAfterFunc" 85 | // called below tries to read another frame (which it usually will) 86 | 87 | if (source->fAfterGettingFunc != NULL) { 88 | (*(source->fAfterGettingFunc))(source->fAfterGettingClientData, 89 | source->fFrameSize, source->fNumTruncatedBytes, 90 | source->fPresentationTime, 91 | source->fDurationInMicroseconds); 92 | } 93 | } 94 | 95 | void FramedSource::handleClosure(void* clientData) { 96 | FramedSource* source = (FramedSource*)clientData; 97 | source->fIsCurrentlyAwaitingData = False; // because we got a close instead 98 | if (source->fOnCloseFunc != NULL) { 99 | (*(source->fOnCloseFunc))(source->fOnCloseClientData); 100 | } 101 | } 102 | 103 | void FramedSource::stopGettingFrames() { 104 | fIsCurrentlyAwaitingData = False; // indicates that we can be read again 105 | 106 | // Perform any specialized action now: 107 | doStopGettingFrames(); 108 | } 109 | 110 | void FramedSource::doStopGettingFrames() { 111 | // Default implementation: Do nothing 112 | // Subclasses may wish to specialize this so as to ensure that a 113 | // subsequent reader can pick up where this one left off. 114 | } 115 | 116 | unsigned FramedSource::maxFrameSize() const { 117 | // By default, this source has no maximum frame size. 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /rtsp_stack/FramedSource.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Framed Sources 19 | // C++ header 20 | 21 | #ifndef _FRAMED_SOURCE_HH 22 | #define _FRAMED_SOURCE_HH 23 | 24 | #ifndef _NET_COMMON_H 25 | #include "NetCommon.h" 26 | #endif 27 | #ifndef _MEDIA_SOURCE_HH 28 | #include "MediaSource.h" 29 | #endif 30 | 31 | class FramedSource: public MediaSource { 32 | public: 33 | static Boolean lookupByName(UsageEnvironment& env, char const* sourceName, 34 | FramedSource*& resultSource); 35 | 36 | typedef void (afterGettingFunc)(void* clientData, unsigned frameSize, 37 | unsigned numTruncatedBytes, 38 | struct timeval presentationTime, 39 | unsigned durationInMicroseconds); 40 | typedef void (onCloseFunc)(void* clientData); 41 | void getNextFrame(unsigned char* to, unsigned maxSize, 42 | afterGettingFunc* afterGettingFunc, 43 | void* afterGettingClientData, 44 | onCloseFunc* onCloseFunc, 45 | void* onCloseClientData); 46 | 47 | static void handleClosure(void* clientData); 48 | // This should be called (on ourself) if the source is discovered 49 | // to be closed (i.e., no longer readable) 50 | 51 | void stopGettingFrames(); 52 | 53 | virtual unsigned maxFrameSize() const; 54 | // size of the largest possible frame that we may serve, or 0 55 | // if no such maximum is known (default) 56 | 57 | virtual void doGetNextFrame() = 0; 58 | // called by getNextFrame() 59 | 60 | Boolean isCurrentlyAwaitingData() const {return fIsCurrentlyAwaitingData;} 61 | 62 | protected: 63 | FramedSource(UsageEnvironment& env); // abstract base class 64 | virtual ~FramedSource(); 65 | 66 | static void afterGetting(FramedSource* source); 67 | // doGetNextFrame() should arrange for this to be called after the 68 | // frame has been read (*iff* it is read successfully) 69 | 70 | virtual void doStopGettingFrames(); 71 | 72 | protected: 73 | // The following variables are typically accessed/set by doGetNextFrame() 74 | unsigned char* fTo; // in 75 | unsigned fMaxSize; // in 76 | unsigned fFrameSize; // out 77 | unsigned fNumTruncatedBytes; // out 78 | struct timeval fPresentationTime; // out 79 | unsigned fDurationInMicroseconds; // out 80 | 81 | private: 82 | // redefined virtual functions: 83 | virtual Boolean isFramedSource() const; 84 | 85 | private: 86 | afterGettingFunc* fAfterGettingFunc; 87 | void* fAfterGettingClientData; 88 | onCloseFunc* fOnCloseFunc; 89 | void* fOnCloseClientData; 90 | 91 | Boolean fIsCurrentlyAwaitingData; 92 | }; 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /rtsp_stack/GroupEId.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010, Live Networks, Inc. All rights reserved 17 | // "Group Endpoint Id" 18 | // Implementation 19 | 20 | #include "GroupEId.h" 21 | #include "strDup.h" 22 | #include 23 | 24 | ////////// Scope ////////// 25 | 26 | void Scope::assign(u_int8_t ttl, const char* publicKey) { 27 | fTTL = ttl; 28 | 29 | fPublicKey = strDup(publicKey == NULL ? "nokey" : publicKey); 30 | } 31 | 32 | void Scope::clean() { 33 | delete[] fPublicKey; 34 | fPublicKey = NULL; 35 | } 36 | 37 | 38 | Scope::Scope(u_int8_t ttl, const char* publicKey) { 39 | assign(ttl, publicKey); 40 | } 41 | 42 | Scope::Scope(const Scope& orig) { 43 | assign(orig.ttl(), orig.publicKey()); 44 | } 45 | 46 | Scope& Scope::operator=(const Scope& rightSide) { 47 | if (&rightSide != this) { 48 | if (publicKey() == NULL 49 | || strcmp(publicKey(), rightSide.publicKey()) != 0) { 50 | clean(); 51 | assign(rightSide.ttl(), rightSide.publicKey()); 52 | } else { // need to assign TTL only 53 | fTTL = rightSide.ttl(); 54 | } 55 | } 56 | 57 | return *this; 58 | } 59 | 60 | Scope::~Scope() { 61 | clean(); 62 | } 63 | 64 | unsigned Scope::publicKeySize() const { 65 | return fPublicKey == NULL ? 0 : strlen(fPublicKey); 66 | } 67 | 68 | ////////// GroupEId ////////// 69 | 70 | GroupEId::GroupEId(struct in_addr const& groupAddr, 71 | portNumBits portNum, Scope const& scope, 72 | unsigned numSuccessiveGroupAddrs) { 73 | struct in_addr sourceFilterAddr; 74 | sourceFilterAddr.s_addr = ~0; // indicates no source filter 75 | 76 | init(groupAddr, sourceFilterAddr, portNum, scope, numSuccessiveGroupAddrs); 77 | } 78 | 79 | GroupEId::GroupEId(struct in_addr const& groupAddr, 80 | struct in_addr const& sourceFilterAddr, 81 | portNumBits portNum, 82 | unsigned numSuccessiveGroupAddrs) { 83 | init(groupAddr, sourceFilterAddr, portNum, 255, numSuccessiveGroupAddrs); 84 | } 85 | 86 | GroupEId::GroupEId() { 87 | } 88 | 89 | Boolean GroupEId::isSSM() const { 90 | return fSourceFilterAddress.s_addr != netAddressBits(~0); 91 | } 92 | 93 | 94 | void GroupEId::init(struct in_addr const& groupAddr, 95 | struct in_addr const& sourceFilterAddr, 96 | portNumBits portNum, 97 | Scope const& scope, 98 | unsigned numSuccessiveGroupAddrs) { 99 | fGroupAddress = groupAddr; 100 | fSourceFilterAddress = sourceFilterAddr; 101 | fNumSuccessiveGroupAddrs = numSuccessiveGroupAddrs; 102 | fPortNum = portNum; 103 | fScope = scope; 104 | } 105 | -------------------------------------------------------------------------------- /rtsp_stack/GroupEId.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "multikit" Multicast Application Shell 17 | // Copyright (c) 1996-2010, Live Networks, Inc. All rights reserved 18 | // "Group Endpoint Id" 19 | // C++ header 20 | 21 | #ifndef _GROUPEID_HH 22 | #define _GROUPEID_HH 23 | 24 | #ifndef _BOOLEAN_HH 25 | #include "Boolean.h" 26 | #endif 27 | 28 | #ifndef _NET_ADDRESS_HH 29 | #include "NetAddress.h" 30 | #endif 31 | 32 | const u_int8_t MAX_TTL = 255; 33 | 34 | class Scope { 35 | public: 36 | Scope(u_int8_t ttl = 0, const char* publicKey = NULL); 37 | Scope(const Scope& orig); 38 | Scope& operator=(const Scope& rightSide); 39 | ~Scope(); 40 | 41 | u_int8_t ttl() const 42 | { return fTTL; } 43 | 44 | const char* publicKey() const 45 | { return fPublicKey; } 46 | unsigned publicKeySize() const; 47 | 48 | private: 49 | void assign(u_int8_t ttl, const char* publicKey); 50 | void clean(); 51 | 52 | u_int8_t fTTL; 53 | char* fPublicKey; 54 | }; 55 | 56 | class GroupEId { 57 | public: 58 | GroupEId(struct in_addr const& groupAddr, 59 | portNumBits portNum, Scope const& scope, 60 | unsigned numSuccessiveGroupAddrs = 1); 61 | // used for a 'source-independent multicast' group 62 | GroupEId(struct in_addr const& groupAddr, 63 | struct in_addr const& sourceFilterAddr, 64 | portNumBits portNum, 65 | unsigned numSuccessiveGroupAddrs = 1); 66 | // used for a 'source-specific multicast' group 67 | GroupEId(); // used only as a temp constructor prior to initialization 68 | 69 | struct in_addr const& groupAddress() const { return fGroupAddress; } 70 | struct in_addr const& sourceFilterAddress() const { return fSourceFilterAddress; } 71 | 72 | Boolean isSSM() const; 73 | 74 | unsigned numSuccessiveGroupAddrs() const { 75 | // could be >1 for hier encoding 76 | return fNumSuccessiveGroupAddrs; 77 | } 78 | 79 | portNumBits portNum() const { return fPortNum; } 80 | 81 | const Scope& scope() const { return fScope; } 82 | 83 | private: 84 | void init(struct in_addr const& groupAddr, 85 | struct in_addr const& sourceFilterAddr, 86 | portNumBits portNum, 87 | Scope const& scope, 88 | unsigned numSuccessiveGroupAddrs); 89 | 90 | private: 91 | struct in_addr fGroupAddress; 92 | struct in_addr fSourceFilterAddress; 93 | unsigned fNumSuccessiveGroupAddrs; 94 | portNumBits fPortNum; 95 | Scope fScope; 96 | }; 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /rtsp_stack/GroupsockHelper.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "mTunnel" multicast access service 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Helper routines to implement 'group sockets' 19 | // C++ header 20 | 21 | #ifndef _GROUPSOCK_HELPER_HH 22 | #define _GROUPSOCK_HELPER_HH 23 | 24 | #ifndef _NET_ADDRESS_HH 25 | #include "NetAddress.h" 26 | #endif 27 | 28 | int setupDatagramSocket(UsageEnvironment& env, Port port); 29 | int setupStreamSocket(UsageEnvironment& env, 30 | Port port, Boolean makeNonBlocking = True); 31 | 32 | int readSocket(UsageEnvironment& env, 33 | int socket, unsigned char* buffer, unsigned bufferSize, 34 | struct sockaddr_in& fromAddress, 35 | struct timeval* timeout = NULL); 36 | 37 | int readSocketExact(UsageEnvironment& env, 38 | int socket, unsigned char* buffer, unsigned bufferSize, 39 | struct sockaddr_in& fromAddress, 40 | struct timeval* timeout = NULL); 41 | // like "readSocket()", except that it rereads as many times as needed until 42 | // *exactly* "bufferSize" bytes are read. 43 | 44 | Boolean writeSocket(UsageEnvironment& env, 45 | int socket, struct in_addr address, Port port, 46 | u_int8_t ttlArg, 47 | unsigned char* buffer, unsigned bufferSize); 48 | 49 | unsigned getSendBufferSize(UsageEnvironment& env, int socket); 50 | unsigned getReceiveBufferSize(UsageEnvironment& env, int socket); 51 | unsigned setSendBufferTo(UsageEnvironment& env, 52 | int socket, unsigned requestedSize); 53 | unsigned setReceiveBufferTo(UsageEnvironment& env, 54 | int socket, unsigned requestedSize); 55 | unsigned increaseSendBufferTo(UsageEnvironment& env, 56 | int socket, unsigned requestedSize); 57 | unsigned increaseReceiveBufferTo(UsageEnvironment& env, 58 | int socket, unsigned requestedSize); 59 | 60 | Boolean makeSocketNonBlocking(int sock); 61 | Boolean makeSocketBlocking(int sock); 62 | 63 | Boolean socketJoinGroup(UsageEnvironment& env, int socket, 64 | netAddressBits groupAddress); 65 | Boolean socketLeaveGroup(UsageEnvironment&, int socket, 66 | netAddressBits groupAddress); 67 | 68 | // source-specific multicast join/leave 69 | Boolean socketJoinGroupSSM(UsageEnvironment& env, int socket, 70 | netAddressBits groupAddress, 71 | netAddressBits sourceFilterAddr); 72 | Boolean socketLeaveGroupSSM(UsageEnvironment&, int socket, 73 | netAddressBits groupAddress, 74 | netAddressBits sourceFilterAddr); 75 | 76 | Boolean getSourcePort(UsageEnvironment& env, int socket, Port& port); 77 | 78 | netAddressBits ourIPAddress(UsageEnvironment& env); // in network order 79 | 80 | // IP addresses of our sending and receiving interfaces. (By default, these 81 | // are INADDR_ANY (i.e., 0), specifying the default interface.) 82 | extern netAddressBits SendingInterfaceAddr; 83 | extern netAddressBits ReceivingInterfaceAddr; 84 | 85 | // Allocates a randomly-chosen IPv4 SSM (multicast) address: 86 | netAddressBits chooseRandomIPv4SSMAddress(UsageEnvironment& env); 87 | 88 | // Returns a simple "hh:mm:ss" string, for use in debugging output (e.g.) 89 | char const* timestampString(); 90 | 91 | 92 | #ifdef HAVE_SOCKADDR_LEN 93 | #define SET_SOCKADDR_SIN_LEN(var) var.sin_len = sizeof var 94 | #else 95 | #define SET_SOCKADDR_SIN_LEN(var) 96 | #endif 97 | 98 | #define MAKE_SOCKADDR_IN(var,adr,prt) /*adr,prt must be in network order*/\ 99 | struct sockaddr_in var;\ 100 | var.sin_family = AF_INET;\ 101 | var.sin_addr.s_addr = (adr);\ 102 | var.sin_port = (prt);\ 103 | SET_SOCKADDR_SIN_LEN(var); 104 | 105 | 106 | // By default, we create sockets with the SO_REUSE_* flag set. 107 | // If, instead, you want to create sockets without the SO_REUSE_* flags, 108 | // Then enclose the creation code with: 109 | // { 110 | // NoReuse dummy; 111 | // ... 112 | // } 113 | class NoReuse { 114 | public: 115 | NoReuse(); 116 | ~NoReuse(); 117 | }; 118 | 119 | 120 | #if (defined(__WIN32__) || defined(_WIN32)) && !defined(IMN_PIM) 121 | // For Windoze, we need to implement our own gettimeofday() 122 | extern int gettimeofday(struct timeval*, int*); 123 | #endif 124 | 125 | // The following are implemented in inet.c: 126 | extern "C" netAddressBits our_inet_addr(char const*); 127 | extern "C" char* our_inet_ntoa(struct in_addr); 128 | extern "C" struct hostent* our_gethostbyname(char* name); 129 | extern "C" void our_srandom(unsigned int x); 130 | extern "C" long our_random(); 131 | extern "C" u_int32_t our_random32(); // because "our_random()" returns a 31-bit number 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /rtsp_stack/H264VideoRTPSink.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // RTP sink for H.264 video (RFC 3984) 19 | // C++ header 20 | 21 | #ifndef _H264_VIDEO_RTP_SINK_H 22 | #define _H264_VIDEO_RTP_SINK_H 23 | 24 | #ifndef _VIDEO_RTP_SINK_H 25 | #include "VideoRTPSink.h" 26 | #endif 27 | #ifndef _FRAMED_FILTER_H 28 | #include "FramedFilter.h" 29 | #endif 30 | 31 | class H264FUAFragmenter; 32 | 33 | class H264VideoRTPSink: public VideoRTPSink { 34 | public: 35 | static H264VideoRTPSink* createNew(UsageEnvironment& env, 36 | void* owner, 37 | Groupsock* RTPgs, 38 | unsigned char rtpPayloadFormat/*, 39 | unsigned profile_level_id, 40 | char const* sprop_parameter_sets_str*/); 41 | void setVideoSize(int width_E, int height_E) {fWidth = width_E, fHeight = height_E;} 42 | protected: 43 | H264VideoRTPSink(UsageEnvironment& env, void* owner, Groupsock* RTPgs, 44 | unsigned char rtpPayloadFormat/*, 45 | unsigned profile_level_id, 46 | char const* sprop_parameter_sets_str*/); 47 | // called only by createNew() 48 | 49 | virtual ~H264VideoRTPSink(); 50 | 51 | protected: // redefined virtual functions: 52 | virtual char const* auxSDPLine(); 53 | 54 | private: // redefined virtual functions: 55 | virtual Boolean sourceIsCompatibleWithUs(MediaSource& source); 56 | virtual Boolean continuePlaying(); 57 | virtual void stopPlaying(); 58 | virtual void doSpecialFrameHandling(unsigned fragmentationOffset, 59 | unsigned char* frameStart, 60 | unsigned numBytesInFrame, 61 | struct timeval frameTimestamp, 62 | unsigned numRemainingBytes); 63 | virtual Boolean frameCanAppearAfterPacketStart(unsigned char const* frameStart, 64 | unsigned numBytesInFrame) const; 65 | 66 | protected: 67 | H264FUAFragmenter* fOurFragmenter; 68 | 69 | private: 70 | char* fFmtpSDPLine; 71 | int fWidth; 72 | int fHeight; 73 | }; 74 | 75 | 76 | ////////// H264FUAFragmenter definition ////////// 77 | 78 | // Because of the ideosyncracies of the H.264 RTP payload format, we implement 79 | // "H264VideoRTPSink" using a separate "H264FUAFragmenter" class that delivers, 80 | // to the "H264VideoRTPSink", only fragments that will fit within an outgoing 81 | // RTP packet. I.e., we implement fragmentation in this separate "H264FUAFragmenter" 82 | // class, rather than in "H264VideoRTPSink". 83 | // (Note: This class should be used only by "H264VideoRTPSink", or a subclass.) 84 | 85 | class H264FUAFragmenter: public FramedFilter{ 86 | public: 87 | H264FUAFragmenter(UsageEnvironment& env, FramedSource* inputSource, 88 | unsigned inputBufferMax, unsigned maxOutputPacketSize); 89 | virtual ~H264FUAFragmenter(); 90 | 91 | Boolean lastFragmentCompletedNALUnit() const { return fLastFragmentCompletedNALUnit; } 92 | 93 | private: // redefined virtual functions: 94 | virtual void doGetNextFrame(); 95 | 96 | private: 97 | static void afterGettingFrame(void* clientData, unsigned frameSize, 98 | unsigned numTruncatedBytes, 99 | struct timeval presentationTime, 100 | unsigned durationInMicroseconds); 101 | void afterGettingFrame1(unsigned frameSize, 102 | unsigned numTruncatedBytes, 103 | struct timeval presentationTime, 104 | unsigned durationInMicroseconds); 105 | 106 | private: 107 | unsigned fInputBufferSize; 108 | unsigned fMaxOutputPacketSize; 109 | unsigned char* fInputBuffer; 110 | unsigned fNumValidDataBytes; 111 | unsigned fCurDataOffset; 112 | unsigned fSaveNumTruncatedBytes; 113 | Boolean fLastFragmentCompletedNALUnit; 114 | }; 115 | 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /rtsp_stack/HandlerSet.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Basic Usage Environment: for a simple, non-scripted, console application 18 | // C++ header 19 | 20 | #ifndef _HANDLER_SET_HH 21 | #define _HANDLER_SET_HH 22 | 23 | #ifndef _BOOLEAN_HH 24 | #include "Boolean.h" 25 | #endif 26 | 27 | ////////// HandlerSet (etc.) definition ////////// 28 | 29 | class HandlerDescriptor { 30 | HandlerDescriptor(HandlerDescriptor* nextHandler); 31 | virtual ~HandlerDescriptor(); 32 | 33 | public: 34 | int socketNum; 35 | int conditionSet; 36 | TaskScheduler::BackgroundHandlerProc* handlerProc; 37 | void* clientData; 38 | 39 | private: 40 | // Descriptors are linked together in a doubly-linked list: 41 | friend class HandlerSet; 42 | friend class HandlerIterator; 43 | HandlerDescriptor* fNextHandler; 44 | HandlerDescriptor* fPrevHandler; 45 | }; 46 | 47 | class HandlerSet { 48 | public: 49 | HandlerSet(); 50 | virtual ~HandlerSet(); 51 | 52 | void assignHandler(int socketNum, int conditionSet, TaskScheduler::BackgroundHandlerProc* handlerProc, void* clientData); 53 | void clearHandler(int socketNum); 54 | void moveHandler(int oldSocketNum, int newSocketNum); 55 | 56 | private: 57 | HandlerDescriptor* lookupHandler(int socketNum); 58 | 59 | private: 60 | friend class HandlerIterator; 61 | HandlerDescriptor fHandlers; 62 | }; 63 | 64 | class HandlerIterator { 65 | public: 66 | HandlerIterator(HandlerSet& handlerSet); 67 | virtual ~HandlerIterator(); 68 | 69 | HandlerDescriptor* next(); // returns NULL if none 70 | void reset(); 71 | 72 | private: 73 | HandlerSet& fOurSet; 74 | HandlerDescriptor* fNextPtr; 75 | }; 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /rtsp_stack/HashTable.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Generic Hash Table 18 | // Implementation 19 | 20 | #include "HashTable.h" 21 | 22 | HashTable::HashTable() { 23 | } 24 | 25 | HashTable::~HashTable() { 26 | } 27 | 28 | HashTable::Iterator::Iterator() { 29 | } 30 | 31 | HashTable::Iterator::~Iterator() {} 32 | 33 | void* HashTable::RemoveNext() { 34 | Iterator* iter = Iterator::create(*this); 35 | char const* key; 36 | void* removedValue = iter->next(key); 37 | if (removedValue != 0) Remove(key); 38 | 39 | delete iter; 40 | return removedValue; 41 | } 42 | -------------------------------------------------------------------------------- /rtsp_stack/HashTable.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Generic Hash Table 18 | // C++ header 19 | 20 | #ifndef _HASH_TABLE_HH 21 | #define _HASH_TABLE_HH 22 | 23 | #ifndef _BOOLEAN_HH 24 | #include "Boolean.h" 25 | #endif 26 | 27 | class HashTable { 28 | public: 29 | virtual ~HashTable(); 30 | 31 | // The following must be implemented by a particular 32 | // implementation (subclass): 33 | static HashTable* create(int keyType); 34 | 35 | virtual void* Add(char const* key, void* value) = 0; 36 | // Returns the old value if different, otherwise 0 37 | virtual Boolean Remove(char const* key) = 0; 38 | virtual void* Lookup(char const* key) const = 0; 39 | // Returns 0 if not found 40 | virtual unsigned numEntries() const = 0; 41 | Boolean IsEmpty() const { return numEntries() == 0; } 42 | 43 | // Used to iterate through the members of the table: 44 | class Iterator { 45 | public: 46 | // The following must be implemented by a particular 47 | // implementation (subclass): 48 | static Iterator* create(HashTable& hashTable); 49 | 50 | virtual ~Iterator(); 51 | 52 | virtual void* next(char const*& key) = 0; // returns 0 if none 53 | 54 | protected: 55 | Iterator(); // abstract base class 56 | }; 57 | 58 | // A shortcut that can be used to successively remove each of 59 | // the entries in the table (e.g., so that their values can be 60 | // deleted, if they happen to be pointers to allocated memory). 61 | void* RemoveNext(); 62 | 63 | protected: 64 | HashTable(); // abstract base class 65 | }; 66 | 67 | // Warning: The following are deliberately the same as in 68 | // Tcl's hash table implementation 69 | int const STRING_HASH_KEYS = 0; 70 | int const ONE_WORD_HASH_KEYS = 1; 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /rtsp_stack/IOHandlers.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "mTunnel" multicast access service 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // IO event handlers 19 | // Implementation 20 | 21 | #include "IOHandlers.h" 22 | #include "TunnelEncaps.h" 23 | 24 | //##### TEMP: Use a single buffer, sized for UDP tunnels: 25 | //##### This assumes that the I/O handlers are non-reentrant 26 | static unsigned const maxPacketLength = 50*1024; // bytes 27 | // This is usually overkill, because UDP packets are usually no larger 28 | // than the typical Ethernet MTU (1500 bytes). However, I've seen 29 | // reports of Windows Media Servers sending UDP packets as large as 30 | // 27 kBytes. These will probably undego lots of IP-level 31 | // fragmentation, but that occurs below us. We just have to hope that 32 | // fragments don't get lost. 33 | static unsigned const ioBufferSize 34 | = maxPacketLength + TunnelEncapsulationTrailerMaxSize; 35 | static unsigned char ioBuffer[ioBufferSize]; 36 | 37 | 38 | void socketReadHandler(Socket* sock, int /*mask*/) { 39 | unsigned bytesRead; 40 | struct sockaddr_in fromAddress; 41 | UsageEnvironment& saveEnv = sock->env(); 42 | // because handleRead(), if it fails, may delete "sock" 43 | if (!sock->handleRead(ioBuffer, ioBufferSize, bytesRead, fromAddress)) { 44 | saveEnv.reportBackgroundError(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rtsp_stack/IOHandlers.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "mTunnel" multicast access service 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // IO event handlers 19 | // C++ header 20 | 21 | #ifndef _IO_HANDLERS_HH 22 | #define _IO_HANDLERS_HH 23 | 24 | #ifndef _NET_INTERFACE_HH 25 | #include "NetInterface.h" 26 | #endif 27 | 28 | // Handles incoming data on sockets: 29 | void socketReadHandler(Socket* sock, int mask); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /rtsp_stack/Locale.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Support for temporarily setting the locale (e.g., to POSIX) for (e.g.) parsing or printing 19 | // floating-point numbers in protocol headers, or calling toupper()/tolower() on human-input strings. 20 | // Implementation 21 | 22 | #include "Locale.h" 23 | #include "strDup.h" 24 | 25 | Locale::Locale(char const* newLocale, int category) 26 | : fCategory(category) { 27 | #ifndef LOCALE_NOT_USED 28 | fPrevLocale = strDup(setlocale(category, NULL)); 29 | setlocale(category, newLocale); 30 | #endif 31 | } 32 | 33 | Locale::~Locale() { 34 | #ifndef LOCALE_NOT_USED 35 | if (fPrevLocale != NULL) { 36 | setlocale(fCategory, fPrevLocale); 37 | delete[] fPrevLocale; 38 | } 39 | #endif 40 | } 41 | -------------------------------------------------------------------------------- /rtsp_stack/Locale.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Support for temporarily setting the locale (e.g., to POSIX) for (e.g.) parsing or printing 19 | // floating-point numbers in protocol headers, or calling toupper()/tolower() on human-input strings. 20 | // C++ header 21 | 22 | #ifndef _LOCALE_HH 23 | #define _LOCALE_HH 24 | 25 | // If you're on a system that (for whatever reason) doesn't have the "setlocale()" function, then 26 | // add "-DLOCALE_NOT_USED" to your "config.*" file. 27 | 28 | #ifndef LOCALE_NOT_USED 29 | #include 30 | #else 31 | #ifndef LC_ALL 32 | #define LC_ALL 0 33 | #endif 34 | #ifndef LC_NUMERIC 35 | #define LC_NUMERIC 4 36 | #endif 37 | #endif 38 | 39 | class Locale { 40 | public: 41 | Locale(char const* newLocale, int category = LC_ALL); 42 | virtual ~Locale(); 43 | 44 | private: 45 | int fCategory; 46 | char* fPrevLocale; 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /rtsp_stack/MPEG4ESVideoRTPSink.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // RTP sink for MPEG-4 Elementary Stream video (RFC 3016) 19 | // Implementation 20 | 21 | #include "MPEG4ESVideoRTPSink.h" 22 | #include "EncoderSource.h" 23 | #include "RTSPSdk.h" 24 | //#define CIF_CONFIG "\x00\x00\x01\xb0\x08\x00\x00\x01\xb5\x09\x00\x00\x01\x00\x00\x00\x01\x20\x00\x84\x40\x7d\x32\x9c\x2c\x10\x90\x51\x8f" // default value 25 | //#define QCIF_CONFIG "\x00\x00\x01\xb0\x08\x00\x00\x01\xb5\x09\x00\x00\x01\x00\x00\x00\x01\x20\x00\x84\x40\xfa\x31\xf6\x0b\x08\x24\x28\xc7" // default value 26 | 27 | MPEG4ESVideoRTPSink 28 | ::MPEG4ESVideoRTPSink(UsageEnvironment& env, void* owner, Groupsock* RTPgs, 29 | unsigned char rtpPayloadFormat, 30 | u_int32_t rtpTimestampFrequency) 31 | : VideoRTPSink(env, owner, RTPgs, rtpPayloadFormat, rtpTimestampFrequency, "MP4V-ES"), 32 | fVOPIsPresent(False), fFmtpSDPLine(NULL) { 33 | } 34 | 35 | MPEG4ESVideoRTPSink::~MPEG4ESVideoRTPSink() { 36 | delete[] fFmtpSDPLine; 37 | } 38 | 39 | MPEG4ESVideoRTPSink* 40 | MPEG4ESVideoRTPSink::createNew(UsageEnvironment& env, void* owner, Groupsock* RTPgs, 41 | unsigned char rtpPayloadFormat, 42 | u_int32_t rtpTimestampFrequency) { 43 | return new MPEG4ESVideoRTPSink(env, owner, RTPgs, rtpPayloadFormat, 44 | rtpTimestampFrequency); 45 | } 46 | 47 | Boolean MPEG4ESVideoRTPSink::sourceIsCompatibleWithUs(MediaSource& source) { 48 | // Our source must be an appropriate framer: 49 | return source.isMPEG4VideoStreamFramer(); 50 | } 51 | 52 | #define VOP_START_CODE 0x000001B6 53 | 54 | void MPEG4ESVideoRTPSink 55 | ::doSpecialFrameHandling(unsigned fragmentationOffset, 56 | unsigned char* frameStart, 57 | unsigned numBytesInFrame, 58 | struct timeval frameTimestamp, 59 | unsigned numRemainingBytes) { 60 | if (fragmentationOffset == 0) { 61 | // Begin by inspecting the 4-byte code at the start of the frame: 62 | if (numBytesInFrame < 4) return; // shouldn't happen 63 | unsigned startCode = (frameStart[0]<<24) | (frameStart[1]<<16) 64 | | (frameStart[2]<<8) | frameStart[3]; 65 | 66 | fVOPIsPresent = startCode == VOP_START_CODE; 67 | } 68 | 69 | // Set the RTP 'M' (marker) bit iff this frame ends a VOP 70 | // (and there are no fragments remaining). 71 | // This relies on the source being a "MPEG4VideoStreamFramer". 72 | EncoderVideoSource* framerSource = (EncoderVideoSource*)fSource; 73 | if (framerSource != NULL && framerSource->pictureEndMarker() 74 | && numRemainingBytes == 0) { 75 | setMarkerBit(); 76 | framerSource->pictureEndMarker() = False; 77 | } 78 | 79 | // Also set the RTP timestamp. (We do this for each frame 80 | // in the packet, to ensure that the timestamp of the VOP (if present) 81 | // gets used.) 82 | setTimestamp(frameTimestamp); 83 | } 84 | 85 | Boolean MPEG4ESVideoRTPSink::allowFragmentationAfterStart() const { 86 | return True; 87 | } 88 | 89 | Boolean MPEG4ESVideoRTPSink 90 | ::frameCanAppearAfterPacketStart(unsigned char const* /*frameStart*/, 91 | unsigned /*numBytesInFrame*/) const { 92 | // Once we've packed a VOP into the packet, then no other 93 | // frame can be packed into it: 94 | return !fVOPIsPresent; 95 | } 96 | 97 | char const* MPEG4ESVideoRTPSink::auxSDPLine() { 98 | // Generate a new "a=fmtp:" line each time, using parameters from 99 | // our framer source (in case they've changed since the last time that 100 | // we were called): 101 | EncoderVideoSource* framerSource = (EncoderVideoSource*)fSource; 102 | // if (framerSource == NULL) return NULL; // we don't yet have a source 103 | 104 | int profile_level_id = 0; 105 | #if 0 106 | if (framerSource) 107 | framerSource->profile_and_level_indication(); 108 | if (profile_level_id == 0) 109 | profile_level_id = 8; // default value 110 | #endif 111 | 112 | unsigned int configLength = 0; 113 | unsigned char configString[100] = {0}; 114 | unsigned char *config = NULL; 115 | if (framerSource) 116 | config = framerSource->getConfigBytes(configLength); 117 | if (config == NULL) 118 | { 119 | getVideoCodecConfig(fWidth,fHeight,&profile_level_id,configString, &configLength); // 120 | if (profile_level_id == 0) 121 | profile_level_id = 8; // default value 122 | config = configString; 123 | configLength = configLength; 124 | } 125 | char const* fmtpFmt = 126 | "a=fmtp:%d " 127 | "profile-level-id=%d;" 128 | "config="; 129 | unsigned fmtpFmtSize = strlen(fmtpFmt) 130 | + 3 /* max char len */ 131 | + 3 /* max char len */ 132 | + 2*configLength /* 2*, because each byte prints as 2 chars */ 133 | + 2 /* trailing \r\n */ 134 | + 256; 135 | char* fmtp = new char[fmtpFmtSize]; 136 | sprintf(fmtp, fmtpFmt, rtpPayloadType(), profile_level_id); 137 | char* endPtr = &fmtp[strlen(fmtp)]; 138 | for (unsigned i = 0; i < configLength; ++i) { 139 | sprintf(endPtr, "%02X", config[i]); 140 | endPtr += 2; 141 | } 142 | endPtr += sprintf(endPtr, "\r\n"); 143 | //endPtr += sprintf(endPtr, "a=framerate:10\r\n"); 144 | // endPtr += sprintf(endPtr, "a=framesize:96 352-288\r\n"); 145 | 146 | delete[] fFmtpSDPLine; 147 | fFmtpSDPLine = strDup(fmtp); 148 | delete[] fmtp; 149 | return fFmtpSDPLine; 150 | } 151 | -------------------------------------------------------------------------------- /rtsp_stack/MPEG4ESVideoRTPSink.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // RTP sink for MPEG-4 Elementary Stream video (RFC 3016) 19 | // C++ header 20 | 21 | #ifndef _MPEG4ES_VIDEO_RTP_SINK_HH 22 | #define _MPEG4ES_VIDEO_RTP_SINK_HH 23 | 24 | #ifndef _VIDEO_RTP_SINK_HH 25 | #include "VideoRTPSink.h" 26 | #endif 27 | 28 | class MPEG4ESVideoRTPSink: public VideoRTPSink { 29 | public: 30 | static MPEG4ESVideoRTPSink* createNew(UsageEnvironment& env, 31 | void* owner, 32 | Groupsock* RTPgs, 33 | unsigned char rtpPayloadFormat, 34 | u_int32_t rtpTimestampFrequency = 90000); 35 | 36 | void setVideoSize(int width, int height) { fWidth = width, fHeight = height; } 37 | protected: 38 | MPEG4ESVideoRTPSink(UsageEnvironment& env, void* owner, Groupsock* RTPgs, 39 | unsigned char rtpPayloadFormat, 40 | u_int32_t rtpTimestampFrequency); 41 | // called only by createNew() 42 | 43 | virtual ~MPEG4ESVideoRTPSink(); 44 | protected: // redefined virtual functions: 45 | virtual Boolean sourceIsCompatibleWithUs(MediaSource& source); 46 | 47 | virtual void doSpecialFrameHandling(unsigned fragmentationOffset, 48 | unsigned char* frameStart, 49 | unsigned numBytesInFrame, 50 | struct timeval frameTimestamp, 51 | unsigned numRemainingBytes); 52 | virtual Boolean allowFragmentationAfterStart() const; 53 | virtual Boolean 54 | frameCanAppearAfterPacketStart(unsigned char const* frameStart, 55 | unsigned numBytesInFrame) const; 56 | 57 | virtual char const* auxSDPLine(); 58 | 59 | protected: 60 | Boolean fVOPIsPresent; 61 | 62 | private: 63 | char* fFmtpSDPLine; 64 | int fWidth; 65 | int fHeight; 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /rtsp_stack/Makefile: -------------------------------------------------------------------------------- 1 | ENCSOURCE = undefined 2 | H264 = defined 3 | MPEG4 = undefined 4 | AMRNB = undefined 5 | 6 | #FLAGS += -DSTARV_TEST 7 | #FLAGS += -DENC_SOURCE 8 | 9 | ifeq (defined, $(H264)) 10 | FLAGS += -DSDKH264 11 | OBJECTS += H264VideoRTPSink.o 12 | ifeq (defined, $(ENCSOURCE)) 13 | LIBS += -lx264 14 | endif 15 | endif 16 | 17 | ifeq (defined, $(MPEG4)) 18 | FLAGS += -DSDKMPEG4 19 | OBJECTS += xvid_interface.o 20 | ifeq (defined, $(ENCSOURCE)) 21 | LIBS += -lxvidcore 22 | endif 23 | endif 24 | 25 | ifeq (defined, $(AMRNB)) 26 | FLAGS += -DSDKAMR 27 | ifeq (defined, $(ENCSOURCE)) 28 | LIBS += -lopencore-amrnb 29 | endif 30 | endif 31 | 32 | LIBS += -lpthread -lssl 33 | CC = g++ 34 | FLAGS += -g 35 | OBJECTS += AMRAudioRTPSink.o AMRAudioSource.o AudioRTPSink.o \ 36 | BasicHashTable.o \ 37 | BasicTaskScheduler.o BasicTaskScheduler0.o BasicUDPSink.o BasicUsageEnvironment.o \ 38 | BasicUsageEnvironment0.o DelayQueue.o \ 39 | EncoderMediaSubsession.o EncoderSource.o FramedFilter.o \ 40 | FramedSource.o GroupEId.o Groupsock.o GroupsockHelper.o HashTable.o \ 41 | inet.o IOHandlers.o Locale.o Media.o MediaSink.o \ 42 | MediaSource.o MPEG4ESVideoRTPSink.o \ 43 | MultiFramedRTPSink.o NetAddress.o NetInterface.o \ 44 | rsa_crypto.o RTCP.o rtcp_from_spec.o RTPInterface.o \ 45 | RTPSink.o RTPSource.o RTSPCommon.o RTSPEncoderSession.o \ 46 | RTSPServer.o ServerMediaSession.o strDup.o mainSdk.o \ 47 | UsageEnvironment.o VideoRTPSink.o RTSPSdk.o Base64.o \ 48 | 49 | rtsp_protocol: $(OBJECTS) 50 | $(CC) -o $@ $^ $(LIBS) 51 | .cpp.o: 52 | $(CC) -c $(FLAGS) $< 53 | .PHONY clean: 54 | clean: 55 | -rm rtsp_protocol $(OBJECTS) 56 | -------------------------------------------------------------------------------- /rtsp_stack/Media.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Media 19 | // Implementation 20 | 21 | #include "Media.h" 22 | #include "HashTable.h" 23 | #include "Debug.h" 24 | 25 | // A data structure for looking up a Medium by its string name 26 | class MediaLookupTable { 27 | public: 28 | static MediaLookupTable* ourMedia(UsageEnvironment& env); 29 | 30 | Medium* lookup(char const* name) const; 31 | // Returns NULL if none already exists 32 | 33 | void addNew(Medium* medium, char* mediumName); 34 | void remove(char const* name); 35 | 36 | void generateNewName(char* mediumName, unsigned maxLen); 37 | 38 | protected: 39 | MediaLookupTable(UsageEnvironment& env); 40 | virtual ~MediaLookupTable(); 41 | 42 | private: 43 | UsageEnvironment& fEnv; 44 | HashTable* fTable; 45 | unsigned fNameGenerator; 46 | }; 47 | 48 | 49 | ////////// Medium ////////// 50 | 51 | Medium::Medium(UsageEnvironment& env) 52 | : fEnviron(env), fNextTask(NULL) { 53 | // First generate a name for the new medium: 54 | MediaLookupTable::ourMedia(env)->generateNewName(fMediumName, mediumNameMaxLen); 55 | env.setResultMsg(fMediumName); 56 | 57 | // Then add it to our table: 58 | MediaLookupTable::ourMedia(env)->addNew(this, fMediumName); 59 | } 60 | 61 | Medium::~Medium() { 62 | // Remove any tasks that might be pending for us: 63 | fEnviron.taskScheduler().unscheduleDelayedTask(fNextTask); 64 | } 65 | 66 | Boolean Medium::lookupByName(UsageEnvironment& env, char const* mediumName, 67 | Medium*& resultMedium) { 68 | resultMedium = MediaLookupTable::ourMedia(env)->lookup(mediumName); 69 | if (resultMedium == NULL) { 70 | env.setResultMsg("Medium ", mediumName, " does not exist"); 71 | return False; 72 | } 73 | 74 | return True; 75 | } 76 | 77 | void Medium::close(UsageEnvironment& env, char const* name) { 78 | MediaLookupTable::ourMedia(env)->remove(name); 79 | } 80 | 81 | void Medium::close(Medium* medium) { 82 | if (medium == NULL) return; 83 | 84 | close(medium->envir(), medium->name()); 85 | } 86 | 87 | Boolean Medium::isSource() const { 88 | return False; // default implementation 89 | } 90 | 91 | Boolean Medium::isSink() const { 92 | return False; // default implementation 93 | } 94 | 95 | Boolean Medium::isRTCPInstance() const { 96 | return False; // default implementation 97 | } 98 | 99 | Boolean Medium::isRTSPClient() const { 100 | return False; // default implementation 101 | } 102 | 103 | Boolean Medium::isRTSPServer() const { 104 | return False; // default implementation 105 | } 106 | 107 | Boolean Medium::isMediaSession() const { 108 | return False; // default implementation 109 | } 110 | 111 | Boolean Medium::isServerMediaSession() const { 112 | return False; // default implementation 113 | } 114 | 115 | Boolean Medium::isDarwinInjector() const { 116 | return False; // default implementation 117 | } 118 | 119 | 120 | ////////// _Tables implementation ////////// 121 | 122 | _Tables* _Tables::getOurTables(UsageEnvironment& env) { 123 | if (env.liveMediaPriv == NULL) { 124 | env.liveMediaPriv = new _Tables(env); 125 | } 126 | return (_Tables*)(env.liveMediaPriv); 127 | } 128 | 129 | void _Tables::reclaimIfPossible() { 130 | if (mediaTable == NULL && socketTable == NULL) { 131 | fEnv.liveMediaPriv = NULL; 132 | delete this; 133 | } 134 | } 135 | 136 | _Tables::_Tables(UsageEnvironment& env) 137 | : mediaTable(NULL), socketTable(NULL), fEnv(env) { 138 | } 139 | 140 | _Tables::~_Tables() { 141 | } 142 | 143 | 144 | ////////// MediaLookupTable implementation ////////// 145 | 146 | MediaLookupTable* MediaLookupTable::ourMedia(UsageEnvironment& env) { 147 | _Tables* ourTables = _Tables::getOurTables(env); 148 | if (ourTables->mediaTable == NULL) { 149 | // Create a new table to record the media that are to be created in 150 | // this environment: 151 | ourTables->mediaTable = new MediaLookupTable(env); 152 | } 153 | return (MediaLookupTable*)(ourTables->mediaTable); 154 | } 155 | 156 | Medium* MediaLookupTable::lookup(char const* name) const { 157 | return (Medium*)(fTable->Lookup(name)); 158 | } 159 | 160 | void MediaLookupTable::addNew(Medium* medium, char* mediumName) { 161 | fTable->Add(mediumName, (void*)medium); 162 | } 163 | 164 | void MediaLookupTable::remove(char const* name) { 165 | Medium* medium = lookup(name); 166 | if (medium != NULL) { 167 | fTable->Remove(name); 168 | if (fTable->IsEmpty()) { 169 | // We can also delete ourselves (to reclaim space): 170 | _Tables* ourTables = _Tables::getOurTables(fEnv); 171 | delete this; 172 | ourTables->mediaTable = NULL; 173 | ourTables->reclaimIfPossible(); 174 | } 175 | Debug(ckite_log_message, "medium = 0x%x\n", medium); 176 | delete medium; 177 | } 178 | } 179 | 180 | void MediaLookupTable::generateNewName(char* mediumName, 181 | unsigned /*maxLen*/) { 182 | // We should really use snprintf() here, but not all systems have it 183 | sprintf(mediumName, "liveMedia%d", fNameGenerator++); 184 | } 185 | 186 | MediaLookupTable::MediaLookupTable(UsageEnvironment& env) 187 | : fEnv(env), fTable(HashTable::create(STRING_HASH_KEYS)), fNameGenerator(0) { 188 | } 189 | 190 | MediaLookupTable::~MediaLookupTable() { 191 | delete fTable; 192 | } 193 | -------------------------------------------------------------------------------- /rtsp_stack/Media.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Medium 19 | // C++ header 20 | 21 | #ifndef _MEDIA_HH 22 | #define _MEDIA_HH 23 | 24 | #ifndef _LIVEMEDIA_VERSION_HH 25 | #include "liveMedia_version.h" 26 | #endif 27 | 28 | #ifndef _BOOLEAN_HH 29 | #include "Boolean.h" 30 | #endif 31 | 32 | #ifndef _USAGE_ENVIRONMENT_HH 33 | #include "UsageEnvironment.h" 34 | #endif 35 | 36 | // Lots of files end up needing the following, so just #include them here: 37 | #ifndef _NET_COMMON_H 38 | #include "NetCommon.h" 39 | #endif 40 | #include 41 | 42 | // The following makes the Borland compiler happy: 43 | #ifdef __BORLANDC__ 44 | #define _strnicmp strnicmp 45 | #define fabsf(x) fabs(x) 46 | #endif 47 | 48 | #define mediumNameMaxLen 30 49 | 50 | class Medium { 51 | public: 52 | static Boolean lookupByName(UsageEnvironment& env, 53 | char const* mediumName, 54 | Medium*& resultMedium); 55 | static void close(UsageEnvironment& env, char const* mediumName); 56 | static void close(Medium* medium); // alternative close() method using ptrs 57 | // (has no effect if medium == NULL) 58 | 59 | UsageEnvironment& envir() const {return fEnviron;} 60 | 61 | char const* name() const {return fMediumName;} 62 | 63 | // Test for specific types of media: 64 | virtual Boolean isSource() const; 65 | virtual Boolean isSink() const; 66 | virtual Boolean isRTCPInstance() const; 67 | virtual Boolean isRTSPClient() const; 68 | virtual Boolean isRTSPServer() const; 69 | virtual Boolean isMediaSession() const; 70 | virtual Boolean isServerMediaSession() const; 71 | virtual Boolean isDarwinInjector() const; 72 | 73 | protected: 74 | Medium(UsageEnvironment& env); // abstract base class 75 | virtual ~Medium(); // instances are deleted using close() only 76 | 77 | TaskToken& nextTask() { 78 | return fNextTask; 79 | } 80 | 81 | private: 82 | friend class MediaLookupTable; 83 | UsageEnvironment& fEnviron; 84 | char fMediumName[mediumNameMaxLen]; 85 | TaskToken fNextTask; 86 | }; 87 | 88 | // The structure pointed to by the "liveMediaPriv" UsageEnvironment field: 89 | class _Tables { 90 | public: 91 | static _Tables* getOurTables(UsageEnvironment& env); 92 | // returns a pointer to an "ourTables" structure (creating it if necessary) 93 | void reclaimIfPossible(); 94 | // used to delete ourselves when we're no longer used 95 | 96 | void* mediaTable; 97 | void* socketTable; 98 | 99 | protected: 100 | _Tables(UsageEnvironment& env); 101 | virtual ~_Tables(); 102 | 103 | private: 104 | UsageEnvironment& fEnv; 105 | }; 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /rtsp_stack/MediaSink.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Media Sinks 19 | // C++ header 20 | 21 | #ifndef _MEDIA_SINK_HH 22 | #define _MEDIA_SINK_HH 23 | 24 | #ifndef _FRAMED_SOURCE_HH 25 | #include "FramedSource.h" 26 | #endif 27 | 28 | class MediaSink: public Medium { 29 | public: 30 | static Boolean lookupByName(UsageEnvironment& env, char const* sinkName, 31 | MediaSink*& resultSink); 32 | 33 | typedef void (afterPlayingFunc)(void* clientData); 34 | Boolean startPlaying(MediaSource& source, 35 | afterPlayingFunc* afterFunc, 36 | void* afterClientData); 37 | virtual void stopPlaying(); 38 | 39 | // Test for specific types of sink: 40 | virtual Boolean isRTPSink() const; 41 | 42 | FramedSource* source () const {return fSource;} 43 | 44 | protected: 45 | MediaSink(UsageEnvironment& env); // abstract base class 46 | virtual ~MediaSink(); 47 | 48 | virtual Boolean sourceIsCompatibleWithUs(MediaSource& source); 49 | // called by startPlaying() 50 | virtual Boolean continuePlaying() = 0; 51 | // called by startPlaying() 52 | 53 | static void onSourceClosure(void* clientData); 54 | // should be called (on ourselves) by continuePlaying() when it 55 | // discovers that the source we're playing from has closed. 56 | 57 | FramedSource* fSource; 58 | 59 | private: 60 | // redefined virtual functions: 61 | virtual Boolean isSink() const; 62 | 63 | private: 64 | // The following fields are used when we're being played: 65 | afterPlayingFunc* fAfterFunc; 66 | void* fAfterClientData; 67 | }; 68 | 69 | // A data structure that a sink may use for an output packet: 70 | class OutPacketBuffer { 71 | public: 72 | OutPacketBuffer(unsigned preferredPacketSize, unsigned maxPacketSize); 73 | ~OutPacketBuffer(); 74 | 75 | static unsigned maxSize; 76 | 77 | unsigned char* curPtr() const {return &fBuf[fPacketStart + fCurOffset];} 78 | unsigned totalBytesAvailable() const { 79 | return fLimit - (fPacketStart + fCurOffset); 80 | } 81 | unsigned totalBufferSize() const { return fLimit; } 82 | unsigned char* packet() const {return &fBuf[fPacketStart];} 83 | unsigned curPacketSize() const {return fCurOffset;} 84 | 85 | void increment(unsigned numBytes) {fCurOffset += numBytes;} 86 | 87 | void enqueue(unsigned char const* from, unsigned numBytes); 88 | void enqueueWord(unsigned word); 89 | void insert(unsigned char const* from, unsigned numBytes, unsigned toPosition); 90 | void insertWord(unsigned word, unsigned toPosition); 91 | void extract(unsigned char* to, unsigned numBytes, unsigned fromPosition); 92 | unsigned extractWord(unsigned fromPosition); 93 | 94 | void skipBytes(unsigned numBytes); 95 | 96 | Boolean isPreferredSize() const {return fCurOffset >= fPreferred;} 97 | Boolean wouldOverflow(unsigned numBytes) const { 98 | return (fCurOffset+numBytes) > fMax; 99 | } 100 | unsigned numOverflowBytes(unsigned numBytes) const { 101 | return (fCurOffset+numBytes) - fMax; 102 | } 103 | Boolean isTooBigForAPacket(unsigned numBytes) const { 104 | return numBytes > fMax; 105 | } 106 | 107 | void setOverflowData(unsigned overflowDataOffset, 108 | unsigned overflowDataSize, 109 | struct timeval const& presentationTime, 110 | unsigned durationInMicroseconds); 111 | unsigned overflowDataSize() const {return fOverflowDataSize;} 112 | struct timeval overflowPresentationTime() const {return fOverflowPresentationTime;} 113 | unsigned overflowDurationInMicroseconds() const {return fOverflowDurationInMicroseconds;} 114 | Boolean haveOverflowData() const {return fOverflowDataSize > 0;} 115 | void useOverflowData(); 116 | 117 | void adjustPacketStart(unsigned numBytes); 118 | void resetPacketStart(); 119 | void resetOffset() { fCurOffset = 0; } 120 | void resetOverflowData() { fOverflowDataOffset = fOverflowDataSize = 0; } 121 | 122 | private: 123 | unsigned fPacketStart, fCurOffset, fPreferred, fMax, fLimit; 124 | unsigned char* fBuf; 125 | 126 | unsigned fOverflowDataOffset, fOverflowDataSize; 127 | struct timeval fOverflowPresentationTime; 128 | unsigned fOverflowDurationInMicroseconds; 129 | }; 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /rtsp_stack/MediaSource.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2009 Live Networks, Inc. All rights reserved. 18 | // Media Sources 19 | // Implementation 20 | 21 | #include "MediaSource.h" 22 | 23 | ////////// MediaSource ////////// 24 | 25 | MediaSource::MediaSource(UsageEnvironment& env) 26 | : Medium(env) { 27 | } 28 | 29 | MediaSource::~MediaSource() { 30 | } 31 | 32 | Boolean MediaSource::isSource() const { 33 | return True; 34 | } 35 | 36 | char const* MediaSource::MIMEtype() const { 37 | return "application/OCTET-STREAM"; // default type 38 | } 39 | 40 | Boolean MediaSource::isFramedSource() const { 41 | return False; // default implementation 42 | } 43 | Boolean MediaSource::isRTPSource() const { 44 | return False; // default implementation 45 | } 46 | Boolean MediaSource::isMPEG1or2VideoStreamFramer() const { 47 | return False; // default implementation 48 | } 49 | Boolean MediaSource::isMPEG4VideoStreamFramer() const { 50 | return False; // default implementation 51 | } 52 | Boolean MediaSource::isH264VideoStreamFramer() const { 53 | return False; // default implementation 54 | } 55 | Boolean MediaSource::isDVVideoStreamFramer() const { 56 | return False; // default implementation 57 | } 58 | Boolean MediaSource::isJPEGVideoSource() const { 59 | return False; // default implementation 60 | } 61 | Boolean MediaSource::isAMRAudioSource() const { 62 | return False; // default implementation 63 | } 64 | 65 | Boolean MediaSource::lookupByName(UsageEnvironment& env, 66 | char const* sourceName, 67 | MediaSource*& resultSource) { 68 | resultSource = NULL; // unless we succeed 69 | 70 | Medium* medium; 71 | if (!Medium::lookupByName(env, sourceName, medium)) return False; 72 | 73 | if (!medium->isSource()) { 74 | env.setResultMsg(sourceName, " is not a media source"); 75 | return False; 76 | } 77 | 78 | resultSource = (MediaSource*)medium; 79 | return True; 80 | } 81 | 82 | void MediaSource::getAttributes() const { 83 | // Default implementation 84 | envir().setResultMsg(""); 85 | } 86 | -------------------------------------------------------------------------------- /rtsp_stack/MediaSource.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Media Sources 19 | // C++ header 20 | 21 | #ifndef _MEDIA_SOURCE_HH 22 | #define _MEDIA_SOURCE_HH 23 | 24 | #ifndef _MEDIA_HH 25 | #include "Media.h" 26 | #endif 27 | 28 | class MediaSource: public Medium { 29 | public: 30 | static Boolean lookupByName(UsageEnvironment& env, char const* sourceName, 31 | MediaSource*& resultSource); 32 | virtual void getAttributes() const; 33 | // attributes are returned in "env's" 'result message' 34 | 35 | // The MIME type of this source: 36 | virtual char const* MIMEtype() const; 37 | 38 | // Test for specific types of source: 39 | virtual Boolean isFramedSource() const; 40 | virtual Boolean isRTPSource() const; 41 | virtual Boolean isMPEG1or2VideoStreamFramer() const; 42 | virtual Boolean isMPEG4VideoStreamFramer() const; 43 | virtual Boolean isH264VideoStreamFramer() const; 44 | virtual Boolean isDVVideoStreamFramer() const; 45 | virtual Boolean isJPEGVideoSource() const; 46 | virtual Boolean isAMRAudioSource() const; 47 | 48 | protected: 49 | MediaSource(UsageEnvironment& env); // abstract base class 50 | virtual ~MediaSource(); 51 | 52 | private: 53 | // redefined virtual functions: 54 | virtual Boolean isSource() const; 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /rtsp_stack/MultiFramedRTPSink.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // RTP sink for a common kind of payload format: Those which pack multiple, 19 | // complete codec frames (as many as possible) into each RTP packet. 20 | // C++ header 21 | 22 | #ifndef _MULTI_FRAMED_RTP_SINK_HH 23 | #define _MULTI_FRAMED_RTP_SINK_HH 24 | 25 | #ifndef _RTP_SINK_HH 26 | #include "RTPSink.h" 27 | #endif 28 | 29 | class MultiFramedRTPSink: public RTPSink { 30 | public: 31 | void setPacketSizes(unsigned preferredPacketSize, unsigned maxPacketSize); 32 | 33 | protected: 34 | MultiFramedRTPSink(UsageEnvironment& env, 35 | void* owner, 36 | Groupsock* rtpgs, unsigned char rtpPayloadType, 37 | unsigned rtpTimestampFrequency, 38 | char const* rtpPayloadFormatName, 39 | unsigned numChannels = 1); 40 | // we're a virtual base class 41 | 42 | virtual ~MultiFramedRTPSink(); 43 | 44 | virtual void doSpecialFrameHandling(unsigned fragmentationOffset, 45 | unsigned char* frameStart, 46 | unsigned numBytesInFrame, 47 | struct timeval frameTimestamp, 48 | unsigned numRemainingBytes); 49 | // perform any processing specific to the particular payload format 50 | virtual Boolean allowFragmentationAfterStart() const; 51 | // whether a frame can be fragmented if other frame(s) appear earlier 52 | // in the packet (by default: False) 53 | virtual Boolean allowOtherFramesAfterLastFragment() const; 54 | // whether other frames can be packed into a packet following the 55 | // final fragment of a previous, fragmented frame (by default: False) 56 | virtual Boolean frameCanAppearAfterPacketStart(unsigned char const* frameStart, 57 | unsigned numBytesInFrame) const; 58 | // whether this frame can appear in position >1 in a pkt (default: True) 59 | virtual unsigned specialHeaderSize() const; 60 | // returns the size of any special header used (following the RTP header) (default: 0) 61 | virtual unsigned frameSpecificHeaderSize() const; 62 | // returns the size of any frame-specific header used (before each frame 63 | // within the packet) (default: 0) 64 | virtual unsigned computeOverflowForNewFrame(unsigned newFrameSize) const; 65 | // returns the number of overflow bytes that would be produced by adding a new 66 | // frame of size "newFrameSize" to the current RTP packet. 67 | // (By default, this just calls "numOverflowBytes()", but subclasses can redefine 68 | // this to (e.g.) impose a granularity upon RTP payload fragments.) 69 | 70 | // Functions that might be called by doSpecialFrameHandling(), or other subclass virtual functions: 71 | Boolean isFirstPacket() const { return fIsFirstPacket; } 72 | Boolean isFirstFrameInPacket() const { return fNumFramesUsedSoFar == 0; } 73 | Boolean curFragmentationOffset() const { return fCurFragmentationOffset; } 74 | void setMarkerBit(); 75 | void setTimestamp(struct timeval timestamp); 76 | void setSpecialHeaderWord(unsigned word, /* 32 bits, in host order */ 77 | unsigned wordPosition = 0); 78 | void setSpecialHeaderBytes(unsigned char const* bytes, unsigned numBytes, 79 | unsigned bytePosition = 0); 80 | void setFrameSpecificHeaderWord(unsigned word, /* 32 bits, in host order */ 81 | unsigned wordPosition = 0); 82 | void setFrameSpecificHeaderBytes(unsigned char const* bytes, unsigned numBytes, 83 | unsigned bytePosition = 0); 84 | void setFramePadding(unsigned numPaddingBytes); 85 | unsigned numFramesUsedSoFar() const { return fNumFramesUsedSoFar; } 86 | unsigned ourMaxPacketSize() const { return fOurMaxPacketSize; } 87 | 88 | public: // redefined virtual functions: 89 | virtual void stopPlaying(); 90 | 91 | protected: // redefined virtual functions: 92 | virtual Boolean continuePlaying(); 93 | 94 | private: 95 | void buildAndSendPacket(Boolean isFirstPacket); 96 | void packFrame(); 97 | void sendPacketIfNecessary(); 98 | static void sendNext(void* firstArg); 99 | friend void sendNext(void*); 100 | 101 | static void afterGettingFrame(void* clientData, 102 | unsigned numBytesRead, unsigned numTruncatedBytes, 103 | struct timeval presentationTime, 104 | unsigned durationInMicroseconds); 105 | void afterGettingFrame1(unsigned numBytesRead, unsigned numTruncatedBytes, 106 | struct timeval presentationTime, 107 | unsigned durationInMicroseconds); 108 | Boolean isTooBigForAPacket(unsigned numBytes) const; 109 | 110 | static void ourHandleClosure(void* clientData); 111 | 112 | private: 113 | OutPacketBuffer* fOutBuf; 114 | void* fOwner; 115 | 116 | Boolean fNoFramesLeft; 117 | unsigned fNumFramesUsedSoFar; 118 | unsigned fCurFragmentationOffset; 119 | Boolean fPreviousFrameEndedFragmentation; 120 | 121 | Boolean fIsFirstPacket; 122 | struct timeval fNextSendTime; 123 | unsigned fTimestampPosition; 124 | unsigned fSpecialHeaderPosition; 125 | unsigned fSpecialHeaderSize; // size in bytes of any special header used 126 | unsigned fCurFrameSpecificHeaderPosition; 127 | unsigned fCurFrameSpecificHeaderSize; // size in bytes of cur frame-specific header 128 | unsigned fTotalFrameSpecificHeaderSizes; // size of all frame-specific hdrs in pkt 129 | unsigned fOurMaxPacketSize; 130 | }; 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /rtsp_stack/NetAddress.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "mTunnel" multicast access service 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Network Addresses 19 | // C++ header 20 | 21 | #ifndef _NET_ADDRESS_HH 22 | #define _NET_ADDRESS_HH 23 | 24 | #ifndef _HASH_TABLE_HH 25 | #include "HashTable.h" 26 | #endif 27 | 28 | #ifndef _USAGE_ENVIRONMENT_HH 29 | #include "UsageEnvironment.h" 30 | #endif 31 | 32 | #ifndef _NET_COMMON_H 33 | #include "NetCommon.h" 34 | #endif 35 | 36 | 37 | // Definition of a type representing a low-level network address. 38 | // At present, this is 32-bits, for IPv4. Later, generalize it, 39 | // to allow for IPv6. 40 | typedef u_int32_t netAddressBits; 41 | 42 | class NetAddress { 43 | public: 44 | NetAddress(u_int8_t const* data, 45 | unsigned length = 4 /* default: 32 bits */); 46 | NetAddress(unsigned length = 4); // sets address data to all-zeros 47 | NetAddress(NetAddress const& orig); 48 | NetAddress& operator=(NetAddress const& rightSide); 49 | virtual ~NetAddress(); 50 | 51 | unsigned length() const { return fLength; } 52 | u_int8_t const* data() const // always in network byte order 53 | { return fData; } 54 | 55 | private: 56 | void assign(u_int8_t const* data, unsigned length); 57 | void clean(); 58 | 59 | unsigned fLength; 60 | u_int8_t* fData; 61 | }; 62 | 63 | class NetAddressList { 64 | public: 65 | NetAddressList(char const* hostname); 66 | NetAddressList(NetAddressList const& orig); 67 | NetAddressList& operator=(NetAddressList const& rightSide); 68 | virtual ~NetAddressList(); 69 | 70 | unsigned numAddresses() const { return fNumAddresses; } 71 | 72 | NetAddress const* firstAddress() const; 73 | 74 | // Used to iterate through the addresses in a list: 75 | class Iterator { 76 | public: 77 | Iterator(NetAddressList const& addressList); 78 | NetAddress const* nextAddress(); // NULL iff none 79 | private: 80 | NetAddressList const& fAddressList; 81 | unsigned fNextIndex; 82 | }; 83 | 84 | private: 85 | void assign(netAddressBits numAddresses, NetAddress** addressArray); 86 | void clean(); 87 | 88 | friend class Iterator; 89 | unsigned fNumAddresses; 90 | NetAddress** fAddressArray; 91 | }; 92 | 93 | typedef u_int16_t portNumBits; 94 | 95 | class Port { 96 | public: 97 | Port(portNumBits num /* in host byte order */); 98 | 99 | portNumBits num() const // in network byte order 100 | { return fPortNum; } 101 | 102 | private: 103 | portNumBits fPortNum; // stored in network byte order 104 | #ifdef IRIX 105 | portNumBits filler; // hack to overcome a bug in IRIX C++ compiler 106 | #endif 107 | }; 108 | 109 | UsageEnvironment& operator<<(UsageEnvironment& s, const Port& p); 110 | 111 | 112 | // A generic table for looking up objects by (address1, address2, port) 113 | class AddressPortLookupTable { 114 | public: 115 | AddressPortLookupTable(); 116 | virtual ~AddressPortLookupTable(); 117 | 118 | void* Add(netAddressBits address1, netAddressBits address2, 119 | Port port, void* value); 120 | // Returns the old value if different, otherwise 0 121 | Boolean Remove(netAddressBits address1, netAddressBits address2, 122 | Port port); 123 | void* Lookup(netAddressBits address1, netAddressBits address2, 124 | Port port); 125 | // Returns 0 if not found 126 | 127 | // Used to iterate through the entries in the table 128 | class Iterator { 129 | public: 130 | Iterator(AddressPortLookupTable& table); 131 | virtual ~Iterator(); 132 | 133 | void* next(); // NULL iff none 134 | 135 | private: 136 | HashTable::Iterator* fIter; 137 | }; 138 | 139 | private: 140 | friend class Iterator; 141 | HashTable* fTable; 142 | }; 143 | 144 | 145 | Boolean IsMulticastAddress(netAddressBits address); 146 | 147 | #endif 148 | -------------------------------------------------------------------------------- /rtsp_stack/NetCommon.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | /* "groupsock" interface 17 | * Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | * Common include files, typically used for networking 19 | */ 20 | 21 | #ifndef _NET_COMMON_H 22 | #define _NET_COMMON_H 23 | 24 | 25 | #if defined(IMN_PIM) 26 | #include "IMN_PIMNetCommon.h" 27 | 28 | #elif defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_WCE) 29 | /* Windows */ 30 | #if defined(WINNT) || defined(_WINNT) || defined(__BORLANDC__) || defined(__MINGW32__) || defined(_WIN32_WCE) 31 | #define _MSWSOCK_ 32 | #include 33 | #include 34 | #endif 35 | #include 36 | #include 37 | 38 | #define closeSocket closesocket 39 | #define EWOULDBLOCK WSAEWOULDBLOCK 40 | #define EINPROGRESS WSAEWOULDBLOCK 41 | #ifdef EAGAIN 42 | #undef EAGAIN 43 | #endif 44 | #define EAGAIN WSAEWOULDBLOCK 45 | #ifdef EINTR 46 | #undef EINTR 47 | #endif 48 | #define EINTR WSAEINTR 49 | 50 | #if defined(_WIN32_WCE) 51 | #define NO_STRSTREAM 1 52 | #endif 53 | 54 | /* Definitions of size-specific types: */ 55 | typedef __int64 int64_t; 56 | typedef unsigned __int64 u_int64_t; 57 | typedef unsigned u_int32_t; 58 | typedef unsigned short u_int16_t; 59 | typedef unsigned char u_int8_t; 60 | 61 | #elif defined(VXWORKS) 62 | /* VxWorks */ 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | 71 | typedef unsigned int u_int32_t; 72 | typedef unsigned short u_int16_t; 73 | typedef unsigned char u_int8_t; 74 | 75 | #else 76 | /* Unix */ 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | #include 88 | #include 89 | #if defined(_QNX4) 90 | #include 91 | #include 92 | #endif 93 | 94 | #define closeSocket close 95 | 96 | #ifdef SOLARIS 97 | #define u_int64_t uint64_t 98 | #define u_int32_t uint32_t 99 | #define u_int16_t uint16_t 100 | #define u_int8_t uint8_t 101 | #endif 102 | #endif 103 | 104 | #ifndef SOCKLEN_T 105 | #define SOCKLEN_T int 106 | #endif 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /rtsp_stack/NetInterface.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "mTunnel" multicast access service 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Network Interfaces 19 | // Implementation 20 | 21 | #include "NetInterface.h" 22 | #include "GroupsockHelper.h" 23 | 24 | #ifndef NO_SSTREAM 25 | #include 26 | #endif 27 | #include 28 | 29 | ////////// NetInterface ////////// 30 | 31 | UsageEnvironment* NetInterface::DefaultUsageEnvironment = NULL; 32 | 33 | NetInterface::NetInterface() { 34 | } 35 | 36 | NetInterface::~NetInterface() { 37 | } 38 | 39 | 40 | ////////// NetInterface ////////// 41 | 42 | DirectedNetInterface::DirectedNetInterface() { 43 | } 44 | 45 | DirectedNetInterface::~DirectedNetInterface() { 46 | } 47 | 48 | 49 | ////////// DirectedNetInterfaceSet ////////// 50 | 51 | DirectedNetInterfaceSet::DirectedNetInterfaceSet() 52 | : fTable(HashTable::create(ONE_WORD_HASH_KEYS)) { 53 | } 54 | 55 | DirectedNetInterfaceSet::~DirectedNetInterfaceSet() { 56 | delete fTable; 57 | } 58 | 59 | DirectedNetInterface* 60 | DirectedNetInterfaceSet::Add(DirectedNetInterface const* interf) { 61 | return (DirectedNetInterface*) fTable->Add((char*)interf, (void*)interf); 62 | } 63 | 64 | Boolean 65 | DirectedNetInterfaceSet::Remove(DirectedNetInterface const* interf) { 66 | return fTable->Remove((char*)interf); 67 | } 68 | 69 | DirectedNetInterfaceSet::Iterator:: 70 | Iterator(DirectedNetInterfaceSet& interfaces) 71 | : fIter(HashTable::Iterator::create(*(interfaces.fTable))) { 72 | } 73 | 74 | DirectedNetInterfaceSet::Iterator::~Iterator() { 75 | delete fIter; 76 | } 77 | 78 | DirectedNetInterface* DirectedNetInterfaceSet::Iterator::next() { 79 | char const* key; // dummy 80 | return (DirectedNetInterface*) fIter->next(key); 81 | }; 82 | 83 | 84 | ////////// Socket ////////// 85 | 86 | int Socket::DebugLevel = 1; // default value 87 | 88 | Socket::Socket(UsageEnvironment& env, Port port) 89 | : fEnv(DefaultUsageEnvironment != NULL ? *DefaultUsageEnvironment : env), fPort(port) { 90 | fSocketNum = setupDatagramSocket(fEnv, port); 91 | } 92 | 93 | Socket::~Socket() { 94 | closeSocket(fSocketNum); 95 | } 96 | 97 | Boolean Socket::changePort(Port newPort) { 98 | int oldSocketNum = fSocketNum; 99 | closeSocket(fSocketNum); 100 | fSocketNum = setupDatagramSocket(fEnv, newPort); 101 | if (fSocketNum < 0) { 102 | fEnv.taskScheduler().turnOffBackgroundReadHandling(oldSocketNum); 103 | return False; 104 | } 105 | 106 | if (fSocketNum != oldSocketNum) { // the socket number has changed, so move any event handling for it: 107 | fEnv.taskScheduler().moveSocketHandling(oldSocketNum, fSocketNum); 108 | } 109 | return True; 110 | } 111 | 112 | UsageEnvironment& operator<<(UsageEnvironment& s, const Socket& sock) { 113 | return s << timestampString() << " Socket(" << sock.socketNum() << ")"; 114 | } 115 | 116 | ////////// SocketLookupTable ////////// 117 | 118 | SocketLookupTable::SocketLookupTable() 119 | : fTable(HashTable::create(ONE_WORD_HASH_KEYS)) { 120 | } 121 | 122 | SocketLookupTable::~SocketLookupTable() { 123 | delete fTable; 124 | } 125 | 126 | Socket* SocketLookupTable::Fetch(UsageEnvironment& env, Port port, 127 | Boolean& isNew) { 128 | isNew = False; 129 | Socket* sock; 130 | do { 131 | sock = (Socket*) fTable->Lookup((char*)(long)(port.num())); 132 | if (sock == NULL) { // we need to create one: 133 | sock = CreateNew(env, port); 134 | if (sock == NULL || sock->socketNum() < 0) break; 135 | 136 | fTable->Add((char*)(long)(port.num()), (void*)sock); 137 | isNew = True; 138 | } 139 | 140 | return sock; 141 | } while (0); 142 | 143 | delete sock; 144 | return NULL; 145 | } 146 | 147 | Boolean SocketLookupTable::Remove(Socket const* sock) { 148 | return fTable->Remove( (char*)(long)(sock->port().num()) ); 149 | } 150 | 151 | ////////// NetInterfaceTrafficStats ////////// 152 | 153 | NetInterfaceTrafficStats::NetInterfaceTrafficStats() { 154 | fTotNumPackets = fTotNumBytes = 0.0; 155 | } 156 | 157 | void NetInterfaceTrafficStats::countPacket(unsigned packetSize) { 158 | fTotNumPackets += 1.0; 159 | fTotNumBytes += packetSize; 160 | } 161 | 162 | Boolean NetInterfaceTrafficStats::haveSeenTraffic() const { 163 | return fTotNumPackets != 0.0; 164 | } 165 | -------------------------------------------------------------------------------- /rtsp_stack/NetInterface.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "mTunnel" multicast access service 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Network Interfaces 19 | // C++ header 20 | 21 | #ifndef _NET_INTERFACE_HH 22 | #define _NET_INTERFACE_HH 23 | 24 | #ifndef _NET_ADDRESS_HH 25 | #include "NetAddress.h" 26 | #endif 27 | 28 | class NetInterface { 29 | public: 30 | virtual ~NetInterface(); 31 | 32 | static UsageEnvironment* DefaultUsageEnvironment; 33 | // if non-NULL, used for each new interfaces 34 | 35 | protected: 36 | NetInterface(); // virtual base class 37 | }; 38 | 39 | class DirectedNetInterface: public NetInterface { 40 | public: 41 | virtual ~DirectedNetInterface(); 42 | 43 | virtual Boolean write(unsigned char* data, unsigned numBytes) = 0; 44 | 45 | virtual Boolean SourceAddrOKForRelaying(UsageEnvironment& env, 46 | unsigned addr) = 0; 47 | 48 | protected: 49 | DirectedNetInterface(); // virtual base class 50 | }; 51 | 52 | class DirectedNetInterfaceSet { 53 | public: 54 | DirectedNetInterfaceSet(); 55 | virtual ~DirectedNetInterfaceSet(); 56 | 57 | DirectedNetInterface* Add(DirectedNetInterface const* interf); 58 | // Returns the old value if different, otherwise 0 59 | Boolean Remove(DirectedNetInterface const* interf); 60 | 61 | Boolean IsEmpty() { return fTable->IsEmpty(); } 62 | 63 | // Used to iterate through the interfaces in the set 64 | class Iterator { 65 | public: 66 | Iterator(DirectedNetInterfaceSet& interfaces); 67 | virtual ~Iterator(); 68 | 69 | DirectedNetInterface* next(); // NULL iff none 70 | 71 | private: 72 | HashTable::Iterator* fIter; 73 | }; 74 | 75 | private: 76 | friend class Iterator; 77 | HashTable* fTable; 78 | }; 79 | 80 | class Socket: public NetInterface { 81 | public: 82 | virtual ~Socket(); 83 | 84 | virtual Boolean handleRead(unsigned char* buffer, unsigned bufferMaxSize, 85 | unsigned& bytesRead, 86 | struct sockaddr_in& fromAddress) = 0; 87 | // Returns False on error; resultData == NULL if data ignored 88 | 89 | int socketNum() const { return fSocketNum; } 90 | 91 | Port port() const { 92 | return fPort; 93 | } 94 | 95 | UsageEnvironment& env() const { return fEnv; } 96 | 97 | static int DebugLevel; 98 | 99 | protected: 100 | Socket(UsageEnvironment& env, Port port); // virtual base class 101 | 102 | Boolean changePort(Port newPort); // will also cause socketNum() to change 103 | 104 | private: 105 | int fSocketNum; 106 | UsageEnvironment& fEnv; 107 | Port fPort; 108 | }; 109 | 110 | UsageEnvironment& operator<<(UsageEnvironment& s, const Socket& sock); 111 | 112 | // A data structure for looking up a Socket by port: 113 | 114 | class SocketLookupTable { 115 | public: 116 | virtual ~SocketLookupTable(); 117 | 118 | Socket* Fetch(UsageEnvironment& env, Port port, Boolean& isNew); 119 | // Creates a new Socket if none already exists 120 | Boolean Remove(Socket const* sock); 121 | 122 | protected: 123 | SocketLookupTable(); // abstract base class 124 | virtual Socket* CreateNew(UsageEnvironment& env, Port port) = 0; 125 | 126 | private: 127 | HashTable* fTable; 128 | }; 129 | 130 | // A data structure for counting traffic: 131 | 132 | class NetInterfaceTrafficStats { 133 | public: 134 | NetInterfaceTrafficStats(); 135 | 136 | void countPacket(unsigned packetSize); 137 | 138 | float totNumPackets() const {return fTotNumPackets;} 139 | float totNumBytes() const {return fTotNumBytes;} 140 | 141 | Boolean haveSeenTraffic() const; 142 | 143 | private: 144 | float fTotNumPackets; 145 | float fTotNumBytes; 146 | }; 147 | 148 | #endif 149 | -------------------------------------------------------------------------------- /rtsp_stack/RTPInterface.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // An abstraction of a network interface used for RTP (or RTCP). 19 | // (This allows the RTP-over-TCP hack (RFC 2326, section 10.12) to 20 | // be implemented transparently.) 21 | // C++ header 22 | 23 | #ifndef _RTP_INTERFACE_HH 24 | #define _RTP_INTERFACE_HH 25 | 26 | #ifndef _MEDIA_HH 27 | #include "Media.h" 28 | #endif 29 | #ifndef _GROUPSOCK_HH 30 | #include "Groupsock.h" 31 | #endif 32 | 33 | // Typedef for an optional auxilliary handler function, to be called 34 | // when each new packet is read: 35 | typedef void AuxHandlerFunc(void* clientData, unsigned char* packet, 36 | unsigned packetSize); 37 | 38 | typedef void ServerRequestAlternativeByteHandler(void* instance, u_int8_t requestByte); 39 | // A hack that allows a handler for RTP/RTCP packets received over TCP to process RTSP commands that may also appear within 40 | // the same TCP connection. A RTSP server implementation would supply a function like this - as a parameter to 41 | // "ServerMediaSubsession::startStream()". 42 | 43 | class tcpStreamRecord { 44 | public: 45 | tcpStreamRecord(int streamSocketNum, unsigned char streamChannelId, 46 | tcpStreamRecord* next); 47 | virtual ~tcpStreamRecord(); 48 | 49 | public: 50 | tcpStreamRecord* fNext; 51 | int fStreamSocketNum; 52 | unsigned char fStreamChannelId; 53 | }; 54 | 55 | class RTPInterface { 56 | public: 57 | RTPInterface(Medium* owner, Groupsock* gs); 58 | virtual ~RTPInterface(); 59 | 60 | Groupsock* gs() const { return fGS; } 61 | 62 | void setStreamSocket(int sockNum, unsigned char streamChannelId); 63 | void addStreamSocket(int sockNum, unsigned char streamChannelId); 64 | void removeStreamSocket(int sockNum, unsigned char streamChannelId); 65 | void setServerRequestAlternativeByteHandler(ServerRequestAlternativeByteHandler* handler, void* clientData); 66 | 67 | int sendPacket(unsigned char* packet, unsigned packetSize); 68 | void startNetworkReading(TaskScheduler::BackgroundHandlerProc* 69 | handlerProc); 70 | Boolean handleRead(unsigned char* buffer, unsigned bufferMaxSize, 71 | unsigned& bytesRead, 72 | struct sockaddr_in& fromAddress); 73 | void stopNetworkReading(); 74 | 75 | UsageEnvironment& envir() const { return fOwner->envir(); } 76 | 77 | void setAuxilliaryReadHandler(AuxHandlerFunc* handlerFunc, 78 | void* handlerClientData) { 79 | fAuxReadHandlerFunc = handlerFunc; 80 | fAuxReadHandlerClientData = handlerClientData; 81 | } 82 | 83 | // A hack for supporting handlers for RTCP packets arriving interleaved over TCP: 84 | int nextTCPReadStreamSocketNum() const { return fNextTCPReadStreamSocketNum; } 85 | unsigned char nextTCPReadStreamChannelId() const { return fNextTCPReadStreamChannelId; } 86 | tcpStreamRecord* fTCPStreams; // optional, for RTP-over-TCP streaming/receiving 87 | private: 88 | friend class SocketDescriptor; 89 | Medium* fOwner; 90 | Groupsock* fGS; 91 | 92 | unsigned short fNextTCPReadSize; 93 | // how much data (if any) is available to be read from the TCP stream 94 | int fNextTCPReadStreamSocketNum; 95 | unsigned char fNextTCPReadStreamChannelId; 96 | TaskScheduler::BackgroundHandlerProc* fReadHandlerProc; // if any 97 | 98 | AuxHandlerFunc* fAuxReadHandlerFunc; 99 | void* fAuxReadHandlerClientData; 100 | }; 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /rtsp_stack/RTSPCommon.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Common routines used by both RTSP clients and servers 19 | // C++ header 20 | 21 | #ifndef _RTSP_COMMON_HH 22 | #define _RTSP_COMMON_HH 23 | 24 | #ifndef _BOOLEAN_HH 25 | #include "Boolean.h" 26 | #endif 27 | #ifndef __win32__ 28 | #include 29 | #endif 30 | 31 | #if defined(__WIN32__) || defined(_WIN32) || defined(_QNX4) 32 | #define _strncasecmp _strnicmp 33 | #define snprintf _snprintf 34 | #else 35 | #define _strncasecmp strncasecmp 36 | #endif 37 | 38 | #define RTSP_PARAM_STRING_MAX 200 39 | 40 | typedef enum StreamingMode { 41 | RTP_UDP, 42 | RTP_TCP, 43 | RAW_UDP 44 | } StreamingMode; 45 | 46 | Boolean parseRTSPRequestString(char const *reqStr, unsigned reqStrSize, 47 | char *resultCmdName, 48 | unsigned resultCmdNameMaxSize, 49 | char* resultURLPreSuffix, 50 | unsigned resultURLPreSuffixMaxSize, 51 | char* resultURLSuffix, 52 | unsigned resultURLSuffixMaxSize, 53 | char* resultCSeq, 54 | unsigned resultCSeqMaxSize); 55 | 56 | Boolean parseRTSPResponseString(char const* reqStr, 57 | unsigned reqStrSize, 58 | char* resultCode, 59 | unsigned resultCodeMaxSize, 60 | char* resultStatus, 61 | unsigned resultStatusMaxSize, 62 | char* contentType, 63 | unsigned contentTypeMaxSize, 64 | char* challenge, 65 | unsigned challengeMaxSize, 66 | unsigned int* contentLength, 67 | unsigned char** content); 68 | 69 | Boolean parseRangeParam(char const* paramStr, double& rangeStart, double& rangeEnd); 70 | Boolean parseRangeHeader(char const* buf, double& rangeStart, double& rangeEnd); 71 | Boolean parseSpecifiedStringParam(char const* buf, char *find_str, char *specified_str, Boolean specified_str_len); 72 | Boolean parseRTSPGetPostString(char const *reqStr, 73 | unsigned reqStrSize, 74 | char *reqMethod, 75 | unsigned reqMethodSize, 76 | char *cookie, 77 | unsigned cookieSize, 78 | char *contentType, 79 | unsigned contentTypeSize, 80 | char *pragma, 81 | unsigned pragmaSize, 82 | char *cacheControl, 83 | unsigned cacheControlSize); 84 | 85 | void get_DirOrFile(char const *dir, char *response, int response_code); 86 | void parseTimeRange_getStartFileDir(char const *buf, char *time, char *time_range_start[]); 87 | void parseTime_GetEndTime(char *time1, char *time2, char *year, char *month, char *day, char *hour, char *minute, char *second); 88 | void parseTime_searchTimeDir(char *response, char *dir, time_t start_time_day, 89 | time_t end_time_day, time_t start_time_sec, time_t end_time_sec); 90 | void parseTokenFromURLSuffix(char *suffixWithToken, char *suffix, char *token); 91 | 92 | void parseTransportHeader(char const* buf, 93 | StreamingMode& streamingMode, 94 | char*& streamingModeString, 95 | char*& destinationAddressStr, 96 | unsigned char& destinationTTL, 97 | unsigned short& clientRTPPortNum, // if UDP 98 | unsigned short& clientRTCPPortNum, // if UDP 99 | unsigned char& rtpChannelId, // if TCP 100 | unsigned char& rtcpChannelId // if TCP 101 | ); 102 | 103 | Boolean parsePlayNowHeader(char const* buf); 104 | int HexToDec(char *); 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /rtsp_stack/RTSPSdk.h: -------------------------------------------------------------------------------- 1 | #ifndef _RTSP_SDK_H 2 | #define _RTSP_SDK_h 3 | 4 | #define FrameTime_t int 5 | 6 | void getVideoCodecConfig(int width, int height, int *profile_level_id, unsigned char *config, unsigned int *config_length); 7 | void getServerInfo(char *host, unsigned short *port, int defaultType); 8 | void getDeviceInfo(unsigned char channel, char *ip, unsigned short *port, char *mac); 9 | void getHttpServerInfo(char *host, unsigned short *port); 10 | void getUserAgent(char *ua_buf, int buf_len); 11 | enum State{READY,KEYFAILED, DNSFAILED, SETUP, PLAY}; 12 | int setSessionState(char *session_name, int st); 13 | int getSessionState(char *session_name); 14 | void setSSRCMask(char *type, unsigned int mask); 15 | void *getSSRCMask(void); 16 | extern int httpRequestKey(char *recvBuffer, char *mac); 17 | extern void realEntryMain(unsigned char channel); 18 | extern void getListenPortByChannel(unsigned short *port, unsigned char channel); 19 | extern void* getFileHandle( int camid, char* filename, char* sdp, int* sdpSize); 20 | extern void releaseFileHandle( void* handle ); 21 | extern void getRecordDirectories( int camid, char** dirList, int* count, int* index, int* total_count); 22 | extern void getRecordFiles( int camid, char* time, char** fileList, int* count, int* index, int* total_count); 23 | extern void getStoreVideoFrame( void* handle, FrameTime_t* offset, unsigned char* framebuf, int* framesize, int* videoType, bool force_I_frame); 24 | extern void getStoreAudioFrame( void* handle, FrameTime_t* offset, unsigned char* framebuf, int* framesize, int* audioType); 25 | extern void getRealVideoFrame( unsigned char channel, void *handle, char* session_name, unsigned char *framebuf, int *framesize, int *videoType); 26 | extern void getRealAudioFrame( void *handle, char* session_name, char *framebuf, int *framesize, int*audioType); 27 | extern void getSubsessionParaConfig(char *session_name, int width, int height, unsigned int& video_bitrate, unsigned int& framerate, unsigned int& keyinterval, 28 | unsigned int& audio_bitrate, unsigned int& framelenght, unsigned int& samplerate); 29 | extern void getStoreFileResolution(char *file_name, int& width, int &height); 30 | extern void getUpgradeStatus(char *upgrade_version, char *upgrade_status); 31 | extern void readkey(unsigned char channel, char *chCode); 32 | extern void writekey(unsigned char channel, char const *chCode); 33 | enum _camchannel 34 | { 35 | CAMERA_CHANNEL_FALG, 36 | CAMERA_CHANNEL_1, 37 | CAMERA_CHANNEL_2, 38 | CAMERA_CHANNEL_3, 39 | CAMERA_CHANNEL_4, 40 | CAMERA_CHANNEL_5, 41 | CAMERA_CHANNEL_6, 42 | CAMERA_CHANNEL_7, 43 | CAMERA_CHANNEL_8, 44 | CAMERA_CHANNEL_9, 45 | CAMERA_CHANNEL_10, 46 | CAMERA_CHANNEL_11, 47 | CAMERA_CHANNEL_12, 48 | CAMERA_CHANNEL_13, 49 | CAMERA_CHANNEL_14, 50 | CAMERA_CHANNEL_15, 51 | CAMERA_CHANNEL_16, 52 | }; 53 | #endif 54 | -------------------------------------------------------------------------------- /rtsp_stack/TunnelEncaps.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "mTunnel" multicast access service 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // Encapsulation trailer for tunnels 19 | // C++ header 20 | 21 | #ifndef _TUNNEL_ENCAPS_HH 22 | #define _TUNNEL_ENCAPS_HH 23 | 24 | #ifndef _NET_ADDRESS_HH 25 | #include "NetAddress.h" 26 | #endif 27 | 28 | typedef u_int16_t Cookie; 29 | 30 | class TunnelEncapsulationTrailer { 31 | // The trailer is layed out as follows: 32 | // bytes 0-1: source 'cookie' 33 | // bytes 2-3: destination 'cookie' 34 | // bytes 4-7: address 35 | // bytes 8-9: port 36 | // byte 10: ttl 37 | // byte 11: command 38 | 39 | // Optionally, there may also be a 4-byte 'auxilliary address' 40 | // (e.g., for 'source-specific multicast' preceding this) 41 | // bytes -4 through -1: auxilliary address 42 | 43 | public: 44 | Cookie& srcCookie() 45 | { return *(Cookie*)byteOffset(0); } 46 | Cookie& dstCookie() 47 | { return *(Cookie*)byteOffset(2); } 48 | u_int32_t& address() 49 | { return *(u_int32_t*)byteOffset(4); } 50 | Port& port() 51 | { return *(Port*)byteOffset(8); } 52 | u_int8_t& ttl() 53 | { return *(u_int8_t*)byteOffset(10); } 54 | u_int8_t& command() 55 | { return *(u_int8_t*)byteOffset(11); } 56 | 57 | u_int32_t& auxAddress() 58 | { return *(u_int32_t*)byteOffset(-4); } 59 | 60 | private: 61 | inline char* byteOffset(int charIndex) 62 | { return ((char*)this) + charIndex; } 63 | }; 64 | 65 | const unsigned TunnelEncapsulationTrailerSize = 12; // bytes 66 | const unsigned TunnelEncapsulationTrailerAuxSize = 4; // bytes 67 | const unsigned TunnelEncapsulationTrailerMaxSize 68 | = TunnelEncapsulationTrailerSize + TunnelEncapsulationTrailerAuxSize; 69 | 70 | // Command codes: 71 | // 0: unused 72 | const u_int8_t TunnelDataCmd = 1; 73 | const u_int8_t TunnelJoinGroupCmd = 2; 74 | const u_int8_t TunnelLeaveGroupCmd = 3; 75 | const u_int8_t TunnelTearDownCmd = 4; 76 | const u_int8_t TunnelProbeCmd = 5; 77 | const u_int8_t TunnelProbeAckCmd = 6; 78 | const u_int8_t TunnelProbeNackCmd = 7; 79 | const u_int8_t TunnelJoinRTPGroupCmd = 8; 80 | const u_int8_t TunnelLeaveRTPGroupCmd = 9; 81 | // 0x0A through 0x10: currently unused. 82 | const u_int8_t TunnelExtensionFlag = 0x80; // a flag, not a cmd code 83 | const u_int8_t TunnelDataAuxCmd 84 | = (TunnelExtensionFlag|TunnelDataCmd); 85 | const u_int8_t TunnelJoinGroupAuxCmd 86 | = (TunnelExtensionFlag|TunnelJoinGroupCmd); 87 | const u_int8_t TunnelLeaveGroupAuxCmd 88 | = (TunnelExtensionFlag|TunnelLeaveGroupCmd); 89 | // Note: the TearDown, Probe, ProbeAck, ProbeNack cmds have no Aux version 90 | // 0x84 through 0x87: currently unused. 91 | const u_int8_t TunnelJoinRTPGroupAuxCmd 92 | = (TunnelExtensionFlag|TunnelJoinRTPGroupCmd); 93 | const u_int8_t TunnelLeaveRTPGroupAuxCmd 94 | = (TunnelExtensionFlag|TunnelLeaveRTPGroupCmd); 95 | // 0x8A through 0xFF: currently unused 96 | 97 | inline Boolean TunnelIsAuxCmd(u_int8_t cmd) { 98 | return (cmd&TunnelExtensionFlag) != 0; 99 | } 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /rtsp_stack/UsageEnvironment.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Usage Environment 18 | // Implementation 19 | 20 | #include "UsageEnvironment.h" 21 | #include 22 | 23 | void UsageEnvironment::reclaim() { 24 | // We delete ourselves only if we have no remainining state: 25 | if (liveMediaPriv == NULL && groupsockPriv == NULL) delete this; 26 | } 27 | 28 | UsageEnvironment::UsageEnvironment(TaskScheduler& scheduler) 29 | : liveMediaPriv(NULL), groupsockPriv(NULL), fScheduler(scheduler) { 30 | } 31 | 32 | UsageEnvironment::~UsageEnvironment() { 33 | } 34 | 35 | TaskScheduler::TaskScheduler() { 36 | } 37 | 38 | TaskScheduler::~TaskScheduler() { 39 | } 40 | 41 | void TaskScheduler::rescheduleDelayedTask(TaskToken& task, 42 | int64_t microseconds, TaskFunc* proc, 43 | void* clientData) { 44 | unscheduleDelayedTask(task); 45 | task = scheduleDelayedTask(microseconds, proc, clientData); 46 | } 47 | -------------------------------------------------------------------------------- /rtsp_stack/UsageEnvironment.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // Usage Environment 18 | // C++ header 19 | 20 | #ifndef _USAGE_ENVIRONMENT_HH 21 | #define _USAGE_ENVIRONMENT_HH 22 | 23 | #ifndef _USAGEENVIRONMENT_VERSION_HH 24 | #include "UsageEnvironment_version.h" 25 | #endif 26 | 27 | #ifndef _NETCOMMON_H 28 | #include "NetCommon.h" 29 | #endif 30 | 31 | #ifndef _STRDUP_HH 32 | // "strDup()" is used often, so include this here, so everyone gets it: 33 | #include "strDup.h" 34 | #endif 35 | 36 | #ifndef NULL 37 | #define NULL 0 38 | #endif 39 | 40 | #ifdef __BORLANDC__ 41 | #define _setmode setmode 42 | #define _O_BINARY O_BINARY 43 | #endif 44 | 45 | class TaskScheduler; // forward 46 | 47 | // An abstract base class, subclassed for each use of the library 48 | 49 | class UsageEnvironment { 50 | public: 51 | void reclaim(); 52 | 53 | // task scheduler: 54 | TaskScheduler& taskScheduler() const {return fScheduler;} 55 | 56 | // result message handling: 57 | typedef char const* MsgString; 58 | virtual MsgString getResultMsg() const = 0; 59 | 60 | virtual void setResultMsg(MsgString msg) = 0; 61 | virtual void setResultMsg(MsgString msg1, MsgString msg2) = 0; 62 | virtual void setResultMsg(MsgString msg1, MsgString msg2, MsgString msg3) = 0; 63 | virtual void setResultErrMsg(MsgString msg, int err = 0) = 0; 64 | // like setResultMsg(), except that an 'errno' message is appended. (If "err == 0", the "getErrno()" code is used instead.) 65 | 66 | virtual void appendToResultMsg(MsgString msg) = 0; 67 | 68 | virtual void reportBackgroundError() = 0; 69 | // used to report a (previously set) error message within 70 | // a background event 71 | 72 | // 'errno' 73 | virtual int getErrno() const = 0; 74 | 75 | // 'console' output: 76 | virtual UsageEnvironment& operator<<(char const* str) = 0; 77 | virtual UsageEnvironment& operator<<(int i) = 0; 78 | virtual UsageEnvironment& operator<<(unsigned u) = 0; 79 | virtual UsageEnvironment& operator<<(double d) = 0; 80 | virtual UsageEnvironment& operator<<(void* p) = 0; 81 | 82 | // a pointer to additional, optional, client-specific state 83 | void* liveMediaPriv; 84 | void* groupsockPriv; 85 | 86 | protected: 87 | UsageEnvironment(TaskScheduler& scheduler); // abstract base class 88 | virtual ~UsageEnvironment(); // we are deleted only by reclaim() 89 | 90 | private: 91 | TaskScheduler& fScheduler; 92 | }; 93 | 94 | 95 | typedef void TaskFunc(void* clientData); 96 | typedef void* TaskToken; 97 | 98 | class TaskScheduler { 99 | public: 100 | virtual ~TaskScheduler(); 101 | 102 | virtual TaskToken scheduleDelayedTask(int64_t microseconds, TaskFunc* proc, 103 | void* clientData) = 0; 104 | // Schedules a task to occur (after a delay) when we next 105 | // reach a scheduling point. 106 | // (Does not delay if "microseconds" <= 0) 107 | // Returns a token that can be used in a subsequent call to 108 | // unscheduleDelayedTask() 109 | 110 | virtual void unscheduleDelayedTask(TaskToken& prevTask) = 0; 111 | // (Has no effect if "prevTask" == NULL) 112 | // Sets "prevTask" to NULL afterwards. 113 | 114 | virtual void rescheduleDelayedTask(TaskToken& task, 115 | int64_t microseconds, TaskFunc* proc, 116 | void* clientData); 117 | // Combines "unscheduleDelayedTask()" with "scheduleDelayedTask()" 118 | // (setting "task" to the new task token). 119 | 120 | // For handling socket operations in the background (from the event loop): 121 | typedef void BackgroundHandlerProc(void* clientData, int mask); 122 | // Possible bits to set in "mask". (These are deliberately defined 123 | // the same as those in Tcl, to make a Tcl-based subclass easy.) 124 | #define SOCKET_READABLE (1<<1) 125 | #define SOCKET_WRITABLE (1<<2) 126 | #define SOCKET_EXCEPTION (1<<3) 127 | virtual void setBackgroundHandling(int socketNum, int conditionSet, BackgroundHandlerProc* handlerProc, void* clientData) = 0; 128 | void disableBackgroundHandling(int socketNum) { setBackgroundHandling(socketNum, 0, NULL, NULL); } 129 | virtual void moveSocketHandling(int oldSocketNum, int newSocketNum) = 0; 130 | // Changes any socket handling for "oldSocketNum" so that occurs with "newSocketNum" instead. 131 | 132 | virtual void doEventLoop(char* watchVariable = NULL) = 0; 133 | // Stops the current thread of control from proceeding, 134 | // but allows delayed tasks (and/or background I/O handling) 135 | // to proceed. 136 | // (If "watchVariable" is not NULL, then we return from this 137 | // routine when *watchVariable != 0) 138 | 139 | // The following two functions are deprecated, and are provided for backwards-compatibility only: 140 | void turnOnBackgroundReadHandling(int socketNum, BackgroundHandlerProc* handlerProc, void* clientData) { 141 | setBackgroundHandling(socketNum, SOCKET_READABLE, handlerProc, clientData); 142 | } 143 | void turnOffBackgroundReadHandling(int socketNum) { disableBackgroundHandling(socketNum); } 144 | 145 | protected: 146 | TaskScheduler(); // abstract base class 147 | }; 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /rtsp_stack/UsageEnvironment_version.h: -------------------------------------------------------------------------------- 1 | // Version information for the "UsageEnvironment" library 2 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 3 | 4 | #ifndef _USAGEENVIRONMENT_VERSION_HH 5 | #define _USAGEENVIRONMENT_VERSION_HH 6 | 7 | #define USAGEENVIRONMENT_LIBRARY_VERSION_STRING "2010.05.29" 8 | #define USAGEENVIRONMENT_LIBRARY_VERSION_INT 1275091200 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /rtsp_stack/VideoRTPSink.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // A generic RTP sink for video codecs (abstract base class) 19 | // Implementation 20 | 21 | #include "VideoRTPSink.h" 22 | 23 | VideoRTPSink::VideoRTPSink(UsageEnvironment& env, 24 | void* owner, 25 | Groupsock* rtpgs, unsigned char rtpPayloadType, 26 | unsigned rtpTimestampFrequency, 27 | char const* rtpPayloadFormatName) 28 | : MultiFramedRTPSink(env, owner, rtpgs, rtpPayloadType, rtpTimestampFrequency, 29 | rtpPayloadFormatName) { 30 | } 31 | 32 | VideoRTPSink::~VideoRTPSink() { 33 | } 34 | 35 | char const* VideoRTPSink::sdpMediaType() const { 36 | return "video"; 37 | } 38 | -------------------------------------------------------------------------------- /rtsp_stack/VideoRTPSink.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // "liveMedia" 17 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 18 | // A generic RTP sink for video codecs (abstract base class) 19 | // C++ header 20 | 21 | #ifndef _VIDEO_RTP_SINK_HH 22 | #define _VIDEO_RTP_SINK_HH 23 | 24 | #ifndef _MULTI_FRAMED_RTP_SINK_HH 25 | #include "MultiFramedRTPSink.h" 26 | #endif 27 | 28 | class VideoRTPSink: public MultiFramedRTPSink { 29 | protected: 30 | VideoRTPSink(UsageEnvironment& env, 31 | void* owner, 32 | Groupsock* rtpgs, unsigned char rtpPayloadType, 33 | unsigned rtpTimestampFrequency, 34 | char const* rtpPayloadFormatName); 35 | // (we're an abstract base class) 36 | virtual ~VideoRTPSink(); 37 | 38 | private: // redefined virtual functions: 39 | virtual char const* sdpMediaType() const; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /rtsp_stack/groupsock_version.h: -------------------------------------------------------------------------------- 1 | // Version information for the "groupsock" library 2 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 3 | 4 | #ifndef _GROUPSOCK_VERSION_HH 5 | #define _GROUPSOCK_VERSION_HH 6 | 7 | #define GROUPSOCK_LIBRARY_VERSION_STRING "2010.05.29" 8 | #define GROUPSOCK_LIBRARY_VERSION_INT 1275091200 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /rtsp_stack/httpHash.cpp: -------------------------------------------------------------------------------- 1 | class CHashElem 2 | { 3 | public: 4 | ~CHashElem(){ } 5 | int Key; 6 | int Val; 7 | CHashElem *pNext; 8 | }; 9 | 10 | class CHash 11 | { 12 | public: 13 | CHash(int iSlots = 10); 14 | ~CHash(); 15 | 16 | public: 17 | bool QueryValue(const int Key,int & Val); 18 | bool Remove(const int Key); 19 | int GetSlotNum(); 20 | int GetLength(); 21 | bool Insert(int Key, int Val); 22 | CHashElem* QueryElem(const int iIndex); 23 | 24 | protected: 25 | 26 | CHashElem **m_pHashSlots; 27 | int m_iNumSlots; 28 | int m_iLength; 29 | 30 | }; 31 | 32 | 33 | CHash::CHash(int iSlots) 34 | { 35 | if (iSlots < 5) iSlots = 5; 36 | m_pHashSlots = new CHashElem*[iSlots]; 37 | for(int i=0;ipNext; 55 | delete phe; 56 | phe = pNext; 57 | } 58 | } 59 | delete m_pHashSlots; 60 | m_pHashSlots = 0; 61 | } 62 | } 63 | 64 | 65 | bool CHash::QueryValue(const int Key,int& Val) 66 | { 67 | bool bRet=false; 68 | unsigned int num=(unsigned int)Key%m_iNumSlots; 69 | if (num >= 0) 70 | { 71 | CHashElem *pElem = m_pHashSlots[num]; 72 | while (pElem) 73 | { 74 | if (pElem->Key==Key) 75 | { 76 | Val=pElem->Val; 77 | bRet=true; 78 | } 79 | pElem = pElem->pNext; 80 | } 81 | 82 | } 83 | return bRet; 84 | 85 | } 86 | CHashElem* CHash::QueryElem(const int iIndex) 87 | { 88 | CHashElem *pElem=0; 89 | int iSlot=0; 90 | pElem=m_pHashSlots[0]; 91 | for(int i=0;i<=iIndex;i++) 92 | { 93 | BEGIN: 94 | if(iSlotpNext; 105 | 106 | } 107 | } 108 | else 109 | { 110 | pElem=0; 111 | break; 112 | } 113 | 114 | } 115 | return pElem; 116 | 117 | } 118 | 119 | bool CHash::Insert(int Key, int Val) 120 | { 121 | bool bRet=false; 122 | unsigned int num=(unsigned int)Key%m_iNumSlots; 123 | if (num >= 0) 124 | { 125 | if (m_pHashSlots[num]) 126 | { 127 | CHashElem *pIns = m_pHashSlots[num]; 128 | while (pIns->pNext) 129 | { 130 | pIns = pIns->pNext; 131 | } 132 | pIns->pNext = new CHashElem; 133 | pIns->pNext->pNext = 0; 134 | pIns->pNext->Val = Val; 135 | pIns->pNext->Key = Key; 136 | bRet=true; 137 | m_iLength++; 138 | } 139 | else 140 | { 141 | m_pHashSlots[num] = new CHashElem; 142 | m_pHashSlots[num]->pNext = 0; 143 | m_pHashSlots[num]->Key = Key; 144 | m_pHashSlots[num]->Val = Val; 145 | bRet=true; 146 | m_iLength++; 147 | } 148 | } 149 | return bRet; 150 | } 151 | 152 | 153 | 154 | bool CHash::Remove(const int Key) 155 | { 156 | bool bRet=false; 157 | unsigned int num=(unsigned int)Key%m_iNumSlots; 158 | if (num >= 0) 159 | { 160 | CHashElem *pElem = m_pHashSlots[num]; 161 | CHashElem *pPrev = 0; 162 | while (pElem) 163 | { 164 | if (pElem->Key==Key) 165 | { 166 | if (pPrev) 167 | { 168 | pPrev->pNext = pElem->pNext; 169 | } 170 | else 171 | { 172 | m_pHashSlots[num] = pElem->pNext; 173 | } 174 | delete pElem; 175 | bRet=true; 176 | m_iLength--; 177 | break; 178 | } 179 | pPrev = pElem; 180 | pElem = pElem->pNext; 181 | } 182 | } 183 | return bRet; 184 | } 185 | int CHash::GetLength() 186 | { 187 | return m_iLength; 188 | } 189 | int CHash::GetSlotNum() 190 | { 191 | return m_iNumSlots; 192 | } 193 | -------------------------------------------------------------------------------- /rtsp_stack/liveMedia_version.h: -------------------------------------------------------------------------------- 1 | // Version information for the "liveMedia" library 2 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 3 | 4 | #ifndef _LIVEMEDIA_VERSION_HH 5 | #define _LIVEMEDIA_VERSION_HH 6 | 7 | #define LIVEMEDIA_LIBRARY_VERSION_STRING "2010.05.29" 8 | #define LIVEMEDIA_LIBRARY_VERSION_INT 1275091200 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /rtsp_stack/rand.h: -------------------------------------------------------------------------------- 1 | /* crypto/rand/rand.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_RAND_H 60 | #define HEADER_RAND_H 61 | 62 | #include 63 | #include 64 | #include 65 | 66 | #if defined(OPENSSL_SYS_WINDOWS) 67 | #include 68 | #endif 69 | 70 | #ifdef __cplusplus 71 | extern "C" { 72 | #endif 73 | 74 | #if defined(OPENSSL_FIPS) 75 | #define FIPS_RAND_SIZE_T size_t 76 | #endif 77 | 78 | /* Already defined in ossl_typ.h */ 79 | /* typedef struct rand_meth_st RAND_METHOD; */ 80 | 81 | struct rand_meth_st 82 | { 83 | void (*seed)(const void *buf, int num); 84 | int (*bytes)(unsigned char *buf, int num); 85 | void (*cleanup)(void); 86 | void (*add)(const void *buf, int num, double entropy); 87 | int (*pseudorand)(unsigned char *buf, int num); 88 | int (*status)(void); 89 | }; 90 | 91 | #ifdef BN_DEBUG 92 | extern int rand_predictable; 93 | #endif 94 | 95 | int RAND_set_rand_method(const RAND_METHOD *meth); 96 | const RAND_METHOD *RAND_get_rand_method(void); 97 | #ifndef OPENSSL_NO_ENGINE 98 | int RAND_set_rand_engine(ENGINE *engine); 99 | #endif 100 | RAND_METHOD *RAND_SSLeay(void); 101 | void RAND_cleanup(void ); 102 | int RAND_bytes(unsigned char *buf,int num); 103 | int RAND_pseudo_bytes(unsigned char *buf,int num); 104 | void RAND_seed(const void *buf,int num); 105 | void RAND_add(const void *buf,int num,double entropy); 106 | int RAND_load_file(const char *file,long max_bytes); 107 | int RAND_write_file(const char *file); 108 | const char *RAND_file_name(char *file,size_t num); 109 | int RAND_status(void); 110 | int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes); 111 | int RAND_egd(const char *path); 112 | int RAND_egd_bytes(const char *path,int bytes); 113 | int RAND_poll(void); 114 | 115 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) 116 | 117 | void RAND_screen(void); 118 | int RAND_event(UINT, WPARAM, LPARAM); 119 | 120 | #endif 121 | 122 | /* BEGIN ERROR CODES */ 123 | /* The following lines are auto generated by the script mkerr.pl. Any changes 124 | * made after this point may be overwritten when the script is next run. 125 | */ 126 | void ERR_load_RAND_strings(void); 127 | 128 | /* Error codes for the RAND functions. */ 129 | 130 | /* Function codes. */ 131 | #define RAND_F_RAND_GET_RAND_METHOD 101 132 | #define RAND_F_SSLEAY_RAND_BYTES 100 133 | 134 | /* Reason codes. */ 135 | #define RAND_R_PRNG_NOT_SEEDED 100 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | #endif 141 | -------------------------------------------------------------------------------- /rtsp_stack/rsa_crypto.cpp: -------------------------------------------------------------------------------- 1 | #include "rsa_crypto.h" 2 | #include 3 | #include 4 | #include "Debug.h" 5 | // This function should be rewritten on a specific platform 6 | 7 | char* get_public_key() 8 | { 9 | return NULL; 10 | } 11 | 12 | 13 | void* init_crypto_key(unsigned char* pub_key, unsigned int pub_key_len, unsigned char* priv_key, unsigned int priv_key_len) 14 | { 15 | RSA* rsa = RSA_new(); 16 | unsigned char* pub, *priv; 17 | pub = new unsigned char[pub_key_len/2]; 18 | priv = new unsigned char[priv_key_len/2]; 19 | hex2array((char*)pub_key, pub_key_len, pub, pub_key_len/2); 20 | hex2array((char*)priv_key, priv_key_len, priv, priv_key_len/2); 21 | rsa->n = BN_bin2bn(pub, pub_key_len/2, rsa->n); 22 | rsa->d = BN_bin2bn(priv, priv_key_len/2, rsa->d); 23 | rsa->e = BN_bin2bn(crypto_common, 1, rsa->e); 24 | delete [] pub; 25 | delete [] priv; 26 | return rsa; 27 | } 28 | 29 | int crypto_encode(void* handle, unsigned char* input, unsigned int input_length, 30 | unsigned char* output, unsigned int output_length) 31 | { 32 | RSA* rsa = (RSA*)handle; 33 | unsigned char* pack_output = new unsigned char[output_length]; 34 | 35 | int num = RSA_public_encrypt(input_length, input, pack_output, rsa, 36 | RSA_PKCS1_PADDING); 37 | if (num > 0) 38 | { 39 | num = array2hex(pack_output, num, (char*)output, output_length); 40 | } 41 | else if (num == -1) 42 | { 43 | unsigned long err = ERR_get_error(); 44 | Debug(ckite_log_message, "Error string %s\n", ERR_error_string(err, NULL)); 45 | } 46 | delete [] pack_output; 47 | return num; 48 | } 49 | 50 | int crypto_decode(void* handle, unsigned char* input, unsigned int input_length, 51 | unsigned char* output, unsigned int output_length) 52 | { 53 | RSA* rsa = (RSA*)handle; 54 | unsigned char* pack_input = new unsigned char[input_length/2]; 55 | hex2array((char*)input, input_length, pack_input, input_length/2); 56 | int num = RSA_private_decrypt(input_length/2, pack_input, output, rsa, 57 | RSA_PKCS1_PADDING); 58 | 59 | return num; 60 | } 61 | 62 | void release_crypto_key(void* handle) 63 | { 64 | RSA* rsa = (RSA*)handle; 65 | delete rsa; 66 | } 67 | 68 | int hex_digit(unsigned char hex) 69 | { 70 | if (hex >= '0' && hex <= '9') 71 | return hex - '0'; 72 | if (hex >= 'A' && hex <= 'F') 73 | return hex - 'A' + 10; 74 | if (hex >= 'a' && hex <= 'f') 75 | return hex - 'a' + 10; 76 | return 0; 77 | } 78 | 79 | char hex_value(unsigned int digit) 80 | { 81 | if (digit >= 0 && digit <= 9) 82 | return '0' + digit; 83 | else if (digit >= 10 && digit <= 15) 84 | return 'A' + (digit-10); 85 | else 86 | return '0'; 87 | } 88 | 89 | int hex2array(char* hex, int hex_len, unsigned char* array, int array_len) 90 | { 91 | int i; 92 | if (array_len < hex_len/2) 93 | return -1; 94 | if (hex_len & 1) // hex_len must be even! 95 | return -1; 96 | for (i=0; i> 4); 111 | hex[2*i+1] = hex_value(array[i] & 0x0f); 112 | } 113 | return 2*array_len; 114 | } 115 | -------------------------------------------------------------------------------- /rtsp_stack/rsa_crypto.h: -------------------------------------------------------------------------------- 1 | #ifndef _RSA_CRYPTO_H_ 2 | #define _RSA_CRYPTO_H_ 3 | 4 | #include "e_os.h" 5 | 6 | #include "crypto.h" 7 | #include "err.h" 8 | //#include "rand.h" 9 | #include "bn.h" 10 | #include "rsa.h" 11 | 12 | const unsigned char crypto_common[] = "\x11"; 13 | 14 | char* get_public_key(); 15 | void* init_crypto_key(unsigned char* pub_key, unsigned int pub_key_len, unsigned char* priv_key, unsigned int priv_key_len); 16 | int crypto_encode(void* handle, unsigned char* input, unsigned int input_length, 17 | unsigned char* output, unsigned int output_length); 18 | int crypto_decode(void* handle, unsigned char* input, unsigned int input_length, 19 | unsigned char* output, unsigned int output_length); 20 | void release_crypto_key(void* handle); 21 | 22 | int hex2array(char* hex, int hex_len, unsigned char* array, int array_len); 23 | int array2hex(unsigned char* array, int array_len, char* hex, int hex_len); 24 | void readkey(char *chCode); 25 | void writekey(char const *chCode); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /rtsp_stack/rtcp_from_spec.h: -------------------------------------------------------------------------------- 1 | /* RTCP code taken directly from the most recent RTP specification: 2 | * draft-ietf-avt-rtp-new-11.txt 3 | * C header 4 | */ 5 | 6 | #ifndef _RTCP_FROM_SPEC_H 7 | #define _RTCP_FROM_SPEC_H 8 | 9 | #include 10 | 11 | /* Definitions of _ANSI_ARGS and EXTERN that will work in either 12 | C or C++ code: 13 | */ 14 | #undef _ANSI_ARGS_ 15 | #if ((defined(__STDC__) || defined(SABER)) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) || defined(USE_PROTOTYPE) 16 | # define _ANSI_ARGS_(x) x 17 | #else 18 | # define _ANSI_ARGS_(x) () 19 | #endif 20 | #ifdef __cplusplus 21 | # define EXTERN extern "C" 22 | #else 23 | # define EXTERN extern 24 | #endif 25 | 26 | /* The code from the spec assumes a type "event"; make this a void*: */ 27 | typedef void* event; 28 | 29 | #define EVENT_UNKNOWN 0 30 | #define EVENT_REPORT 1 31 | #define EVENT_BYE 2 32 | 33 | /* The code from the spec assumes a type "time_tp"; make this a double: */ 34 | typedef double time_tp; 35 | 36 | /* The code from the spec assumes a type "packet"; make this a void*: */ 37 | typedef void* packet; 38 | 39 | #define PACKET_UNKNOWN_TYPE 0 40 | #define PACKET_RTP 1 41 | #define PACKET_RTCP_REPORT 2 42 | #define PACKET_BYE 3 43 | 44 | /* The code from the spec calls drand48(), but we have drand30() instead */ 45 | #define drand48 drand30 46 | 47 | /* The code calls "exit()", but we don't want to exit, so make it a noop: */ 48 | #define exit(n) do {} while (0) 49 | 50 | #ifndef FALSE 51 | #define FALSE 0 52 | #endif 53 | #ifndef TRUE 54 | #define TRUE 1 55 | #endif 56 | 57 | /* EXPORTS: */ 58 | 59 | EXTERN void OnExpire _ANSI_ARGS_((event, int, int, double, int, double*, int*, time_tp, time_tp*, int*)); 60 | 61 | EXTERN void OnReceive _ANSI_ARGS_((packet, event, int*, int*, int*, double*, double*, double, double)); 62 | 63 | /* IMPORTS: */ 64 | 65 | EXTERN void Schedule _ANSI_ARGS_((double,event)); 66 | EXTERN void Reschedule _ANSI_ARGS_((double,event)); 67 | EXTERN void SendRTCPReport _ANSI_ARGS_((event)); 68 | EXTERN void SendBYEPacket _ANSI_ARGS_((event)); 69 | EXTERN int TypeOfEvent _ANSI_ARGS_((event)); 70 | EXTERN int SentPacketSize _ANSI_ARGS_((event)); 71 | EXTERN int PacketType _ANSI_ARGS_((packet)); 72 | EXTERN int ReceivedPacketSize _ANSI_ARGS_((packet)); 73 | EXTERN int NewMember _ANSI_ARGS_((packet)); 74 | EXTERN int NewSender _ANSI_ARGS_((packet)); 75 | EXTERN void AddMember _ANSI_ARGS_((packet)); 76 | EXTERN void AddSender _ANSI_ARGS_((packet)); 77 | EXTERN void RemoveMember _ANSI_ARGS_((packet)); 78 | EXTERN void RemoveSender _ANSI_ARGS_((packet)); 79 | EXTERN double drand30 _ANSI_ARGS_((void)); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /rtsp_stack/strDup.cpp: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 17 | // A C++ equivalent to the standard C routine "strdup()". 18 | // This generates a char* that can be deleted using "delete[]" 19 | // Implementation 20 | 21 | #include "strDup.h" 22 | #include "string.h" 23 | 24 | char* strDup(char const* str) { 25 | if (str == NULL) return NULL; 26 | size_t len = strlen(str) + 1; 27 | char* copy = new char[len]; 28 | 29 | if (copy != NULL) { 30 | memcpy(copy, str, len); 31 | } 32 | return copy; 33 | } 34 | 35 | char* strDupSize(char const* str) { 36 | if (str == NULL) return NULL; 37 | size_t len = strlen(str) + 1; 38 | char* copy = new char[len]; 39 | return copy; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /rtsp_stack/strDup.h: -------------------------------------------------------------------------------- 1 | /********** 2 | This library is free software; you can redistribute it and/or modify it under 3 | the terms of the GNU Lesser General Public License as published by the 4 | Free Software Foundation; either version 2.1 of the License, or (at your 5 | option) any later version. (See .) 6 | 7 | This library is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License 13 | along with this library; if not, write to the Free Software Foundation, Inc., 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | **********/ 16 | 17 | #ifndef _STRDUP_HH 18 | #define _STRDUP_HH 19 | 20 | // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 21 | // A C++ equivalent to the standard C routine "strdup()". 22 | // This generates a char* that can be deleted using "delete[]" 23 | // Header 24 | 25 | char* strDup(char const* str); 26 | // Note: strDup(NULL) returns NULL 27 | 28 | char* strDupSize(char const* str); 29 | // Like "strDup()", except that it *doesn't* copy the original. 30 | // (Instead, it just allocates a string of the same size as the original.) 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /rtsp_stack/xvid_interface.h: -------------------------------------------------------------------------------- 1 | #ifndef XVID_INTERFACE_H_ 2 | #define XVID_INTERFACE_H_ 3 | 4 | void* xvid_enc_init(int width, int height, int bitrate, int framerate, int key_interval, int use_assembler); 5 | 6 | int xvid_encode_frame(void* handle, unsigned char* frame, int width, int height, unsigned char* bitstream, unsigned int inrc); 7 | 8 | void xvid_release(void* handle); 9 | 10 | #endif 11 | --------------------------------------------------------------------------------