liveMedia/Media.cpp

Go to the documentation of this file.
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 // Media
00019 // Implementation
00020 
00021 #include "Media.hh"
00022 #include "HashTable.hh"
00023 
00025 
00026 Medium::Medium(UsageEnvironment& env)
00027         : fEnviron(env), fNextTask(NULL) {
00028   // First generate a name for the new medium:
00029   MediaLookupTable::ourMedia(env)->generateNewName(fMediumName, mediumNameMaxLen);
00030   env.setResultMsg(fMediumName);
00031 
00032   // Then add it to our table:
00033   MediaLookupTable::ourMedia(env)->addNew(this, fMediumName);
00034 }
00035 
00036 Medium::~Medium() {
00037   // Remove any tasks that might be pending for us:
00038   fEnviron.taskScheduler().unscheduleDelayedTask(fNextTask);
00039 }
00040 
00041 Boolean Medium::lookupByName(UsageEnvironment& env, char const* mediumName,
00042                                   Medium*& resultMedium) {
00043   resultMedium = MediaLookupTable::ourMedia(env)->lookup(mediumName);
00044   if (resultMedium == NULL) {
00045     env.setResultMsg("Medium ", mediumName, " does not exist");
00046     return False;
00047   }
00048 
00049   return True;
00050 }
00051 
00052 void Medium::close(UsageEnvironment& env, char const* name) {
00053   MediaLookupTable::ourMedia(env)->remove(name);
00054 }
00055 
00056 void Medium::close(Medium* medium) {
00057   if (medium == NULL) return;
00058 
00059   close(medium->envir(), medium->name());
00060 }
00061 
00062 Boolean Medium::isSource() const {
00063   return False; // default implementation
00064 }
00065 
00066 Boolean Medium::isSink() const {
00067   return False; // default implementation
00068 }
00069 
00070 Boolean Medium::isRTCPInstance() const {
00071   return False; // default implementation
00072 }
00073 
00074 Boolean Medium::isRTSPClient() const {
00075   return False; // default implementation
00076 }
00077 
00078 Boolean Medium::isRTSPServer() const {
00079   return False; // default implementation
00080 }
00081 
00082 Boolean Medium::isMediaSession() const {
00083   return False; // default implementation
00084 }
00085 
00086 Boolean Medium::isServerMediaSession() const {
00087   return False; // default implementation
00088 }
00089 
00090 Boolean Medium::isDarwinInjector() const {
00091   return False; // default implementation
00092 }
00093 
00094 
00096 
00097 _Tables* _Tables::getOurTables(UsageEnvironment& env, Boolean createIfNotPresent) {
00098   if (env.liveMediaPriv == NULL && createIfNotPresent) {
00099     env.liveMediaPriv = new _Tables(env);
00100   }
00101   return (_Tables*)(env.liveMediaPriv);
00102 }
00103 
00104 void _Tables::reclaimIfPossible() {
00105   if (mediaTable == NULL && socketTable == NULL) {
00106     fEnv.liveMediaPriv = NULL;
00107     delete this;
00108   }
00109 }
00110 
00111 _Tables::_Tables(UsageEnvironment& env)
00112   : mediaTable(NULL), socketTable(NULL), fEnv(env) {
00113 }
00114 
00115 _Tables::~_Tables() {
00116 }
00117 
00118 
00120 
00121 MediaLookupTable* MediaLookupTable::ourMedia(UsageEnvironment& env) {
00122   _Tables* ourTables = _Tables::getOurTables(env);
00123   if (ourTables->mediaTable == NULL) {
00124     // Create a new table to record the media that are to be created in
00125     // this environment:
00126     ourTables->mediaTable = new MediaLookupTable(env);
00127   }
00128   return ourTables->mediaTable;
00129 }
00130 
00131 Medium* MediaLookupTable::lookup(char const* name) const {
00132   return (Medium*)(fTable->Lookup(name));
00133 }
00134 
00135 void MediaLookupTable::addNew(Medium* medium, char* mediumName) {
00136   fTable->Add(mediumName, (void*)medium);
00137 }
00138 
00139 void MediaLookupTable::remove(char const* name) {
00140   Medium* medium = lookup(name);
00141   if (medium != NULL) {
00142     fTable->Remove(name);
00143     if (fTable->IsEmpty()) {
00144       // We can also delete ourselves (to reclaim space):
00145       _Tables* ourTables = _Tables::getOurTables(fEnv);
00146       delete this;
00147       ourTables->mediaTable = NULL;
00148       ourTables->reclaimIfPossible();
00149     }
00150 
00151     delete medium;
00152   }
00153 }
00154 
00155 void MediaLookupTable::generateNewName(char* mediumName,
00156                                        unsigned /*maxLen*/) {
00157   // We should really use snprintf() here, but not all systems have it
00158   sprintf(mediumName, "liveMedia%d", fNameGenerator++);
00159 }
00160 
00161 MediaLookupTable::MediaLookupTable(UsageEnvironment& env)
00162   : fEnv(env), fTable(HashTable::create(STRING_HASH_KEYS)), fNameGenerator(0) {
00163 }
00164 
00165 MediaLookupTable::~MediaLookupTable() {
00166   delete fTable;
00167 }

Generated on Tue Jun 18 13:16:51 2013 for live by  doxygen 1.5.2