liveMedia/DeviceSource.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 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2008 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   // Arrange here for our "deliverFrame" member function to be called
00040   // when the next frame of data becomes available from the device.
00041   // This must be done in a non-blocking fashion - i.e., so that we
00042   // return immediately from this function even if no data is
00043   // currently available.
00044   //
00045   // If the device can be implemented as a readable socket, then one easy
00046   // way to do this is using a call to
00047   //     envir().taskScheduler().turnOnBackgroundReadHandling( ... )
00048   // (See examples of this call in the "liveMedia" directory.)
00049 
00050   // If, for some reason, the source device stops being readable
00051   // (e.g., it gets closed), then you do the following:
00052   if (0 /* the source stops being readable */) {
00053     handleClosure(this);
00054     return;
00055   }
00056 }
00057 
00058 void DeviceSource::deliverFrame() {
00059   // This would be called when new frame data is available from the device.
00060   // This function should deliver the next frame of data from the device,
00061   // using the following parameters (class members):
00062   // 'in' parameters (these should *not* be modified by this function):
00063   //     fTo: The frame data is copied to this address.
00064   //         (Note that the variable "fTo" is *not* modified.  Instead,
00065   //          the frame data is copied to the address pointed to by "fTo".)
00066   //     fMaxSize: This is the maximum number of bytes that can be copied
00067   //         (If the actual frame is larger than this, then it should
00068   //          be truncated, and "fNumTruncatedBytes" set accordingly.)
00069   // 'out' parameters (these are modified by this function):
00070   //     fFrameSize: Should be set to the delivered frame size (<= fMaxSize).
00071   //     fNumTruncatedBytes: Should be set iff the delivered frame would have been
00072   //         bigger than "fMaxSize", in which case it's set to the number of bytes
00073   //         that have been omitted.
00074   //     fPresentationTime: Should be set to the frame's presentation time
00075   //         (seconds, microseconds).
00076   //     fDurationInMicroseconds: Should be set to the frame's duration, if known.
00077   if (!isCurrentlyAwaitingData()) return; // we're not ready for the data yet
00078 
00079   // Deliver the data here:
00080 
00081   // After delivering the data, inform the reader that it is now available:
00082   FramedSource::afterGetting(this);
00083 }

Generated on Tue Jul 22 06:39:05 2008 for live by  doxygen 1.5.2