CMMLTagUtils.cpp

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2005 Zentaro Kavanagh
00003 //
00004 //Copyright (C) 2005 Commonwealth Scientific and Industrial Research
00005 //   Organisation (CSIRO) Australia
00006 //
00007 //Redistribution and use in source and binary forms, with or without
00008 //modification, are permitted provided that the following conditions
00009 //are met:
00010 //
00011 //- Redistributions of source code must retain the above copyright
00012 //  notice, this list of conditions and the following disclaimer.
00013 //
00014 //- Redistributions in binary form must reproduce the above copyright
00015 //  notice, this list of conditions and the following disclaimer in the
00016 //  documentation and/or other materials provided with the distribution.
00017 //
00018 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00019 //  may be used to endorse or promote products derived from this software 
00020 //  without specific prior written permission.
00021 //
00022 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00025 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00026 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 //===========================================================================
00034 
00035 #include "stdafx.h"
00036 
00037 #include <libCMMLParse/CMMLTagUtils.h>
00038 #include <libTemporalURI/C_TimeStamp.h>
00039 
00040 #include <fstream>
00041 
00042 #undef DEBUG
00043 
00046 C_ClipTagList *CMMLTagUtils::getClipsFrom(C_ClipTagList *inClipTagList, LOOG_INT64 inTimeInDirectShowUnits)
00047 {
00048 
00049 #ifdef DEBUG
00050         fstream locDebugFile;
00051         locDebugFile.open("G:\\Logs\\getClipsFrom.log", ios_base::out);
00052 #endif
00053 
00054         C_ClipTagList *locClipTagList = new C_ClipTagList;
00055 
00056         bool locAlreadyEncounteredClipInTimeRange = false;
00057 
00058         for (unsigned long i = 0; i < inClipTagList->numTags(); i++) {
00059                 C_ClipTag *locTag = inClipTagList->getTag(i);
00060 
00061 #ifdef DEBUG
00062                 locDebugFile << "Processing tag " << i << endl;
00063 #endif
00064                 
00065                 // Convert the time stamp from a string to time in DirectSeconds(TM)
00066                 wstring locStart = locTag->start();
00067                 C_TimeStamp locTimeStamp;
00068                 if (!locTimeStamp.parseTimeStamp(StringHelper::toNarrowStr(locStart))) {
00069 #ifdef DEBUG
00070                         locDebugFile << "Couldn't parse time stamp: " << 
00071                                 StringHelper::toNarrowStr(locStart) << endl;
00072 #endif
00073                         // Mmm, couldn't parse the time stamp for this clip ... so, err,
00074                         // let's just skip it.  Yeah, that's a grreeeeat idea ...
00075                         continue;
00076                 }
00077                 LOOG_INT64 locStartTime = locTimeStamp.toHunNanos();
00078 
00079                 if (locStartTime >= inTimeInDirectShowUnits) {
00080 #ifdef DEBUG
00081                         locDebugFile << "Found clip with greater start time " << locStartTime << endl;
00082 #endif
00083                         if (!locAlreadyEncounteredClipInTimeRange) {
00084                                 {
00085                                         // Only add the previous clip to the clip list if its end time
00086                                         // is beyond the requested time
00087                                         wstring locEnd = locTag->end();
00088                                         C_TimeStamp locEndTimeStamp;
00089                                         if (locEndTimeStamp.parseTimeStamp(StringHelper::toNarrowStr(locEnd))) {
00090                                                 // Clip has an end time: check if it's before the requested time
00091                                                 LOOG_INT64 locEndTime = locEndTimeStamp.toHunNanos();
00092                                                 if (    locEndTime != 0
00093                                                         &&      locEndTime >= locStartTime
00094                                                         &&      locEndTime < inTimeInDirectShowUnits) {
00095 #ifdef DEBUG
00096                                                 locDebugFile << "Skipping add due to end time " << locEndTime << endl;
00097 #endif
00098                                                         continue;
00099                                                 }
00100                                         }
00101                                 }
00102 
00103                                 // If we're not the very first clip ...
00104                                 if (i > 0) {
00105 #ifdef DEBUG
00106                                         locDebugFile << "Cloning previous clip " << i << endl;
00107 #endif
00108                                         C_ClipTag *locClipInTimeRange = inClipTagList->getTag(i - 1);
00109                                         locClipTagList->addTag(locClipInTimeRange->clone());
00110                                 }
00111                                 locAlreadyEncounteredClipInTimeRange = true;
00112                         }
00113 #ifdef DEBUG
00114                         locDebugFile << "Cloning clip " << i << endl;
00115 #endif
00116                         locClipTagList->addTag(locTag->clone());
00117                 }
00118         }
00119 
00120 #ifdef DEBUG
00121         locDebugFile.close();
00122 #endif
00123         return locClipTagList;
00124 }

Generated on Tue Feb 15 14:54:13 2005 for oggdsf by  doxygen 1.3.9