00001 /********** 00002 This library is free software; you can redistribute it and/or modify it under 00003 the terms of the GNU Lesser General Public License as published by the 00004 Free Software Foundation; either version 2.1 of the License, or (at your 00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) 00006 00007 This library is distributed in the hope that it will be useful, but WITHOUT 00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00009 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00010 more details. 00011 00012 You should have received a copy of the GNU Lesser General Public License 00013 along with this library; if not, write to the Free Software Foundation, Inc., 00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00015 **********/ 00016 // "liveMedia" 00017 // Copyright (c) 1996-2013 Live Networks, Inc. All rights reserved. 00018 // Medium 00019 // C++ header 00020 00021 #ifndef _MEDIA_HH 00022 #define _MEDIA_HH 00023 00024 #ifndef _LIVEMEDIA_VERSION_HH 00025 #include "liveMedia_version.hh" 00026 #endif 00027 00028 #ifndef _HASH_TABLE_HH 00029 #include "HashTable.hh" 00030 #endif 00031 00032 #ifndef _USAGE_ENVIRONMENT_HH 00033 #include "UsageEnvironment.hh" 00034 #endif 00035 00036 // Lots of files end up needing the following, so just #include them here: 00037 #ifndef _NET_COMMON_H 00038 #include "NetCommon.h" 00039 #endif 00040 #include <stdio.h> 00041 00042 // The following makes the Borland compiler happy: 00043 #ifdef __BORLANDC__ 00044 #define _strnicmp strnicmp 00045 #define fabsf(x) fabs(x) 00046 #endif 00047 00048 #define mediumNameMaxLen 30 00049 00050 class Medium { 00051 public: 00052 static Boolean lookupByName(UsageEnvironment& env, 00053 char const* mediumName, 00054 Medium*& resultMedium); 00055 static void close(UsageEnvironment& env, char const* mediumName); 00056 static void close(Medium* medium); // alternative close() method using ptrs 00057 // (has no effect if medium == NULL) 00058 00059 UsageEnvironment& envir() const {return fEnviron;} 00060 00061 char const* name() const {return fMediumName;} 00062 00063 // Test for specific types of media: 00064 virtual Boolean isSource() const; 00065 virtual Boolean isSink() const; 00066 virtual Boolean isRTCPInstance() const; 00067 virtual Boolean isRTSPClient() const; 00068 virtual Boolean isRTSPServer() const; 00069 virtual Boolean isMediaSession() const; 00070 virtual Boolean isServerMediaSession() const; 00071 virtual Boolean isDarwinInjector() const; 00072 00073 protected: 00074 friend class MediaLookupTable; 00075 Medium(UsageEnvironment& env); // abstract base class 00076 virtual ~Medium(); // instances are deleted using close() only 00077 00078 TaskToken& nextTask() { 00079 return fNextTask; 00080 } 00081 00082 private: 00083 UsageEnvironment& fEnviron; 00084 char fMediumName[mediumNameMaxLen]; 00085 TaskToken fNextTask; 00086 }; 00087 00088 00089 // A data structure for looking up a Medium by its string name. 00090 // (It is used only to implement "Medium", but we make it visible here, in case developers want to use it to iterate over 00091 // the whole set of "Medium" objects that we've created.) 00092 class MediaLookupTable { 00093 public: 00094 static MediaLookupTable* ourMedia(UsageEnvironment& env); 00095 HashTable const& getTable() { return *fTable; } 00096 00097 protected: 00098 MediaLookupTable(UsageEnvironment& env); 00099 virtual ~MediaLookupTable(); 00100 00101 private: 00102 friend class Medium; 00103 00104 Medium* lookup(char const* name) const; 00105 // Returns NULL if none already exists 00106 00107 void addNew(Medium* medium, char* mediumName); 00108 void remove(char const* name); 00109 00110 void generateNewName(char* mediumName, unsigned maxLen); 00111 00112 private: 00113 UsageEnvironment& fEnv; 00114 HashTable* fTable; 00115 unsigned fNameGenerator; 00116 }; 00117 00118 00119 // The structure pointed to by the "liveMediaPriv" UsageEnvironment field: 00120 class _Tables { 00121 public: 00122 static _Tables* getOurTables(UsageEnvironment& env, Boolean createIfNotPresent = True); 00123 // returns a pointer to an "ourTables" structure (creating it if necessary) 00124 void reclaimIfPossible(); 00125 // used to delete ourselves when we're no longer used 00126 00127 MediaLookupTable* mediaTable; 00128 void* socketTable; 00129 00130 protected: 00131 _Tables(UsageEnvironment& env); 00132 virtual ~_Tables(); 00133 00134 private: 00135 UsageEnvironment& fEnv; 00136 }; 00137 00138 #endif
1.5.2