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 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00015 **********/ 00016 // "liveMedia" 00017 // Copyright (c) 1996-2005 Live Networks, Inc. All rights reserved. 00018 // A template for a MediaSource encapsulating an audio/video input device 00019 // Implementation 00020 00021 #include "DeviceSource.hh" 00022 00023 DeviceSource* 00024 DeviceSource::createNew(UsageEnvironment& env, 00025 DeviceParameters params) { 00026 return new DeviceSource(env, params); 00027 } 00028 00029 DeviceSource::DeviceSource(UsageEnvironment& env, 00030 DeviceParameters params) 00031 : FramedSource(env), fParams(params) { 00032 // Any initialization of the device would be done here 00033 } 00034 00035 DeviceSource::~DeviceSource() { 00036 } 00037 00038 void DeviceSource::doGetNextFrame() { 00039 00040 // Arrange here for our "deliverFrame" member function to be called 00041 // when the next frame of data becomes available from the device. 00042 // This must be done in a non-blocking fashion - i.e., so that we 00043 // return immediately from this function even if no data is 00044 // currently available. 00045 // 00046 // If the device can be implemented as a readable socket, then one easy 00047 // way to do this is using a call to 00048 // envir().taskScheduler().turnOnBackgroundReadHandling( ... ) 00049 // (See examples of this call in the "liveMedia" directory.) 00050 00051 // If, for some reason, the source device stops being readable 00052 // (e.g., it gets closed), then you do the following: 00053 if (0 /* the source stops being readable */) { 00054 handleClosure(this); 00055 return; 00056 } 00057 } 00058 00059 void DeviceSource::deliverFrame() { 00060 // This would be called when new frame data is available from the device. 00061 // This function should deliver the next frame of data from the device, 00062 // using the following parameters (class members): 00063 // 'in' parameters (these should *not* be modified by this function): 00064 // fTo: The frame data is copied to this address. 00065 // (Note that the variable "fTo" is *not* modified. Instead, 00066 // the frame data is copied to the address pointed to by "fTo".) 00067 // fMaxSize: This is the maximum number of bytes that can be copied 00068 // (If the actual frame is larger than this, then it should 00069 // be truncated, and "fNumTruncatedBytes" set accordingly.) 00070 // 'out' parameters (these are modified by this function): 00071 // fFrameSize: Should be set to the delivered frame size (<= fMaxSize). 00072 // fNumTruncatedBytes: Should be set iff the delivered frame would have been 00073 // bigger than "fMaxSize", in which case it's set to the number of bytes 00074 // that have been omitted. 00075 // fPresentationTime: Should be set to the frame's presentation time 00076 // (seconds, microseconds). 00077 // fDurationInMicroseconds: Should be set to the frame's duration, if known. 00078 if (!isCurrentlyAwaitingData()) return; // we're not ready for the data yet 00079 00080 // Deliver the data here: 00081 00082 // After delivering the data, switch to another task, and inform 00083 // the reader that he has data: 00084 nextTask() 00085 = envir().taskScheduler().scheduleDelayedTask(0, (TaskFunc*)afterGetting, 00086 this); 00087 }
1.5.5