Media.hh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved.
  16. // Medium
  17. // C++ header
  18. #ifndef _MEDIA_HH
  19. #define _MEDIA_HH
  20. #ifndef _LIVEMEDIA_VERSION_HH
  21. #include "liveMedia_version.hh"
  22. #endif
  23. #ifndef _HASH_TABLE_HH
  24. #include "HashTable.hh"
  25. #endif
  26. #ifndef _USAGE_ENVIRONMENT_HH
  27. #include "UsageEnvironment.hh"
  28. #endif
  29. // Lots of files end up needing the following, so just #include them here:
  30. #ifndef _NET_COMMON_H
  31. #include "NetCommon.h"
  32. #endif
  33. #include <stdio.h>
  34. // The following makes the Borland compiler happy:
  35. #ifdef __BORLANDC__
  36. #define _strnicmp strnicmp
  37. #define fabsf(x) fabs(x)
  38. #endif
  39. #define mediumNameMaxLen 30
  40. class Medium {
  41. public:
  42. static Boolean lookupByName(UsageEnvironment& env,
  43. char const* mediumName,
  44. Medium*& resultMedium);
  45. static void close(UsageEnvironment& env, char const* mediumName);
  46. static void close(Medium* medium); // alternative close() method using ptrs
  47. // (has no effect if medium == NULL)
  48. UsageEnvironment& envir() const {return fEnviron;}
  49. char const* name() const {return fMediumName;}
  50. // Test for specific types of media:
  51. virtual Boolean isSource() const;
  52. virtual Boolean isSink() const;
  53. virtual Boolean isRTCPInstance() const;
  54. virtual Boolean isRTSPClient() const;
  55. virtual Boolean isRTSPServer() const;
  56. virtual Boolean isMediaSession() const;
  57. virtual Boolean isServerMediaSession() const;
  58. protected:
  59. friend class MediaLookupTable;
  60. Medium(UsageEnvironment& env); // abstract base class
  61. virtual ~Medium(); // instances are deleted using close() only
  62. TaskToken& nextTask() {
  63. return fNextTask;
  64. }
  65. private:
  66. UsageEnvironment& fEnviron;
  67. char fMediumName[mediumNameMaxLen];
  68. TaskToken fNextTask;
  69. };
  70. // A data structure for looking up a Medium by its string name.
  71. // (It is used only to implement "Medium", but we make it visible here, in case developers want to use it to iterate over
  72. // the whole set of "Medium" objects that we've created.)
  73. class MediaLookupTable {
  74. public:
  75. static MediaLookupTable* ourMedia(UsageEnvironment& env);
  76. HashTable const& getTable() { return *fTable; }
  77. protected:
  78. MediaLookupTable(UsageEnvironment& env);
  79. virtual ~MediaLookupTable();
  80. private:
  81. friend class Medium;
  82. Medium* lookup(char const* name) const;
  83. // Returns NULL if none already exists
  84. void addNew(Medium* medium, char* mediumName);
  85. void remove(char const* name);
  86. void generateNewName(char* mediumName, unsigned maxLen);
  87. private:
  88. UsageEnvironment& fEnv;
  89. HashTable* fTable;
  90. unsigned fNameGenerator;
  91. };
  92. // The structure pointed to by the "liveMediaPriv" UsageEnvironment field:
  93. class _Tables {
  94. public:
  95. static _Tables* getOurTables(UsageEnvironment& env, Boolean createIfNotPresent = True);
  96. // returns a pointer to a "_Tables" structure (creating it if necessary)
  97. void reclaimIfPossible();
  98. // used to delete ourselves when we're no longer used
  99. MediaLookupTable* mediaTable;
  100. void* socketTable;
  101. protected:
  102. _Tables(UsageEnvironment& env);
  103. virtual ~_Tables();
  104. private:
  105. UsageEnvironment& fEnv;
  106. };
  107. #endif