00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "stdafx.h"
00036
00037 #include <libOOOggChef/AnnodexRecomposer.h>
00038 #include <libOOOggChef/CMMLRecomposer.h>
00039 #include <libOOOggChef/utils.h>
00040
00041 #include <libilliCore/StringHelper.h>
00042 #include <libOOOgg/libOOOgg.h>
00043 #include <libCMMLTags/libCMMLTags.h>
00044 #include <libTemporalURI/C_TimeStamp.h>
00045 #include <libCMMLParse/CMMLParser.h>
00046 #include <libCMMLParse/CMMLTagUtils.h>
00047
00048 #include <fstream>
00049 #include <iostream>
00050 #include <string>
00051 #include <vector>
00052
00053 using namespace std;
00054
00055 #undef DEBUG
00056
00057 CMMLRecomposer::CMMLRecomposer(string inFilename, BufferWriter inBufferWriter, void* inBufferWriterUserData)
00058 : mCMMLFilename(inFilename)
00059 , mBufferWriter(inBufferWriter)
00060 , mBufferWriterUserData(inBufferWriterUserData)
00061 {
00062 }
00063
00064
00065 CMMLRecomposer::~CMMLRecomposer(void)
00066 {
00067 }
00068
00069
00070 bool CMMLRecomposer::recomposeStreamFrom(double inStartingTimeOffset, const vector<string>* inWantedMIMETypes)
00071 {
00072
00073 if (wantOnlyCMML(inWantedMIMETypes) && inStartingTimeOffset == 0) {
00074 sendFile(mCMMLFilename, mBufferWriter, mBufferWriterUserData);
00075 return true;
00076 }
00077
00078 #ifdef DEBUG
00079 mDebugFile.open("G:\\Logs\\CMMLRecomposer.log", ios_base::out);
00080 mDebugFile << "CMMLRecomposer 1 " << endl;
00081 #endif
00082
00083
00084 C_CMMLDoc *locCMML = new C_CMMLDoc;
00085 CMMLParser locCMMLParser;
00086 locCMMLParser.parseDocFromFile(StringHelper::toWStr(mCMMLFilename), locCMML);
00087
00088
00089 bool locReturnValue = false;
00090
00091
00092
00093
00094 C_CMMLRootTag *locCMMLRoot = NULL;
00095 C_StreamTag *locStream = NULL;
00096
00097 if (locCMML == NULL) {
00098 goto cleanup;
00099 }
00100
00101
00102
00103
00104
00105 locCMMLRoot = locCMML->root();
00106 if (locCMMLRoot == NULL) {
00107 goto cleanup;
00108 }
00109
00110
00111 locStream = locCMMLRoot->stream();
00112 #if 0
00113 C_HeadTag *locHead = locCMMLRoot->head();
00114 C_ClipTagList *locClipList = locCMMLRoot->clipList();
00115 #endif
00116
00117
00118
00119
00120
00121 if (wantOnlyCMML(inWantedMIMETypes) || inWantedMIMETypes->at(0) == "*/*") {
00122 C_CMMLDoc* locCMMLDoc = locCMML->clone();
00123
00124
00125 if (locCMMLDoc && locCMMLDoc->root() && locCMMLDoc->root()->clipList()) {
00126
00127
00128
00129 #ifdef DEBUG
00130 mDebugFile << "Got here 1" << endl;
00131 #endif
00132
00133
00134 C_TimeStamp locTimeStamp;
00135 locTimeStamp.parseTimeStamp(inStartingTimeOffset);
00136 LOOG_INT64 locTime = locTimeStamp.toHunNanos();
00137
00138 #ifdef DEBUG
00139 mDebugFile << "locTime: " << locTime << endl;
00140 #endif
00141
00142
00143 C_ClipTagList *locRequestedClips =
00144 CMMLTagUtils::getClipsFrom(locCMMLDoc->root()->clipList(), locTime);
00145
00146
00147
00148
00149 locCMMLDoc->root()->setClipList(locRequestedClips);
00150 }
00151
00152
00153 string locCMMLDocString =
00154 StringHelper::toNarrowStr(locCMMLDoc->toString());
00155 mBufferWriter((unsigned char *) locCMMLDocString.c_str(),
00156 (unsigned long) locCMMLDocString.size(), mBufferWriterUserData);
00157
00158
00159 locReturnValue = true;
00160 } else {
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 }
00175
00176 #if 0
00177 C_ImportTagList *locImportTagList = locStream->importList();
00178 if (locImportTagList == NULL) {
00179 goto cleanup;
00180 }
00181 #endif
00182
00183 cleanup:
00184 if (locCMML) {
00185 delete locCMML;
00186 locCMML = NULL;
00187 }
00188
00189 #ifdef DEBUG
00190 mDebugFile.close();
00191 #endif
00192
00193 return locReturnValue;
00194 }
00195
00196
00197 bool CMMLRecomposer::acceptOggPage(OggPage*)
00198 {
00199 return true;
00200 }
00201