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 3 of the License, or (at your |
5 | option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) |
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-2020 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.hh" |
26 | #endif |
27 | |
28 | #ifndef _HASH_TABLE_HH |
29 | #include "HashTable.hh" |
30 | #endif |
31 | |
32 | #ifndef _USAGE_ENVIRONMENT_HH |
33 | #include "UsageEnvironment.hh" |
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 <stdio.h> |
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 | |
72 | protected: |
73 | friend class MediaLookupTable; |
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 | UsageEnvironment& fEnviron; |
83 | char fMediumName[mediumNameMaxLen]; |
84 | TaskToken fNextTask; |
85 | }; |
86 | |
87 | |
88 | // A data structure for looking up a Medium by its string name. |
89 | // (It is used only to implement "Medium", but we make it visible here, in case developers want to use it to iterate over |
90 | // the whole set of "Medium" objects that we've created.) |
91 | class MediaLookupTable { |
92 | public: |
93 | static MediaLookupTable* ourMedia(UsageEnvironment& env); |
94 | HashTable const& getTable() { return *fTable; } |
95 | |
96 | protected: |
97 | MediaLookupTable(UsageEnvironment& env); |
98 | virtual ~MediaLookupTable(); |
99 | |
100 | private: |
101 | friend class Medium; |
102 | |
103 | Medium* lookup(char const* name) const; |
104 | // Returns NULL if none already exists |
105 | |
106 | void addNew(Medium* medium, char* mediumName); |
107 | void remove(char const* name); |
108 | |
109 | void generateNewName(char* mediumName, unsigned maxLen); |
110 | |
111 | private: |
112 | UsageEnvironment& fEnv; |
113 | HashTable* fTable; |
114 | unsigned fNameGenerator; |
115 | }; |
116 | |
117 | |
118 | // The structure pointed to by the "liveMediaPriv" UsageEnvironment field: |
119 | class _Tables { |
120 | public: |
121 | static _Tables* getOurTables(UsageEnvironment& env, Boolean createIfNotPresent = True); |
122 | // returns a pointer to a "_Tables" structure (creating it if necessary) |
123 | void reclaimIfPossible(); |
124 | // used to delete ourselves when we're no longer used |
125 | |
126 | MediaLookupTable* mediaTable; |
127 | void* socketTable; |
128 | |
129 | protected: |
130 | _Tables(UsageEnvironment& env); |
131 | virtual ~_Tables(); |
132 | |
133 | private: |
134 | UsageEnvironment& fEnv; |
135 | }; |
136 | |
137 | #endif |
138 | |