liveMedia/H263plusVideoStreamFramer.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 // Author Bernhard Feiten
00019 // A filter that breaks up an H.263plus video stream into frames.
00020 //
00021 
00022 #include "H263plusVideoStreamFramer.hh"
00023 #include "H263plusVideoStreamParser.hh"
00024 
00025 #include <string.h>
00026 #include <GroupsockHelper.hh>
00027 
00028 
00031 //public///////////////////////////////////////////////////////////////////////
00032 H263plusVideoStreamFramer* H263plusVideoStreamFramer::createNew(
00033                                                          UsageEnvironment& env,
00034                                                          FramedSource* inputSource)
00035 {
00036    // Need to add source type checking here???  #####
00037    H263plusVideoStreamFramer* fr;
00038    fr = new H263plusVideoStreamFramer(env, inputSource);
00039    return fr;
00040 }
00041 
00042 
00044 H263plusVideoStreamFramer::H263plusVideoStreamFramer(
00045                               UsageEnvironment& env,
00046                               FramedSource* inputSource,
00047                               Boolean createParser)
00048                               : FramedFilter(env, inputSource),
00049                                 fFrameRate(0.0), // until we learn otherwise
00050                                 fPictureEndMarker(False)
00051 {
00052    // Use the current wallclock time as the base 'presentation time':
00053    gettimeofday(&fPresentationTimeBase, NULL);
00054    fParser = createParser ? new H263plusVideoStreamParser(this, inputSource) : NULL;
00055 }
00056 
00058 H263plusVideoStreamFramer::~H263plusVideoStreamFramer()
00059 {
00060    delete   fParser;
00061 }
00062 
00063 
00065 void H263plusVideoStreamFramer::doGetNextFrame()
00066 {
00067   fParser->registerReadInterest(fTo, fMaxSize);
00068   continueReadProcessing();
00069 }
00070 
00071 
00073 Boolean H263plusVideoStreamFramer::isH263plusVideoStreamFramer() const
00074 {
00075   return True;
00076 }
00077 
00079 void H263plusVideoStreamFramer::continueReadProcessing(
00080                                    void* clientData,
00081                                    unsigned char* /*ptr*/, unsigned /*size*/,
00082                                    struct timeval /*presentationTime*/)
00083 {
00084    H263plusVideoStreamFramer* framer = (H263plusVideoStreamFramer*)clientData;
00085    framer->continueReadProcessing();
00086 }
00087 
00089 void H263plusVideoStreamFramer::continueReadProcessing()
00090 {
00091    unsigned acquiredFrameSize;
00092 
00093    u_int64_t frameDuration;  // in ms
00094 
00095    acquiredFrameSize = fParser->parse(frameDuration);
00096 // Calculate some average bitrate information (to be adapted)
00097 //      avgBitrate = (totalBytes * 8 * H263_TIMESCALE) / totalDuration;
00098 
00099    if (acquiredFrameSize > 0) {
00100       // We were able to acquire a frame from the input.
00101       // It has already been copied to the reader's space.
00102       fFrameSize = acquiredFrameSize;
00103 //    fNumTruncatedBytes = fParser->numTruncatedBytes(); // not needed so far
00104 
00105       fFrameRate = frameDuration == 0 ? 0.0 : 1000./(long)frameDuration;
00106 
00107       // Compute "fPresentationTime"
00108       if (acquiredFrameSize == 5) // first frame
00109          fPresentationTime = fPresentationTimeBase;
00110       else
00111          fPresentationTime.tv_usec += (long) frameDuration*1000;
00112 
00113       while (fPresentationTime.tv_usec >= 1000000) {
00114          fPresentationTime.tv_usec -= 1000000;
00115          ++fPresentationTime.tv_sec;
00116       }
00117 
00118       // Compute "fDurationInMicroseconds"
00119       fDurationInMicroseconds = (unsigned int) frameDuration*1000;;
00120 
00121       // Call our own 'after getting' function.  Because we're not a 'leaf'
00122       // source, we can call this directly, without risking infinite recursion.
00123       afterGetting(this);
00124    } else {
00125       // We were unable to parse a complete frame from the input, because:
00126       // - we had to read more data from the source stream, or
00127       // - the source stream has ended.
00128    }
00129 }

Generated on Mon Apr 29 13:28:01 2013 for live by  doxygen 1.5.2