testProgs/MPEG2TransportStreamIndexer.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 // Copyright (c) 1996-2014, Live Networks, Inc.  All rights reserved
00017 // A program that reads an existing MPEG-2 Transport Stream file,
00018 // and generates a separate index file that can be used - by our RTSP server
00019 // implementation - to support 'trick play' operations when streaming the
00020 // Transport Stream file.
00021 // main program
00022 
00023 #include <liveMedia.hh>
00024 #include <BasicUsageEnvironment.hh>
00025 
00026 void afterPlaying(void* clientData); // forward
00027 
00028 UsageEnvironment* env;
00029 char const* programName;
00030 
00031 void usage() {
00032   *env << "usage: " << programName << " <transport-stream-file-name>\n";
00033   *env << "\twhere <transport-stream-file-name> ends with \".ts\"\n";
00034   exit(1);
00035 }
00036 
00037 int main(int argc, char const** argv) {
00038   // Begin by setting up our usage environment:
00039   TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00040   env = BasicUsageEnvironment::createNew(*scheduler);
00041 
00042   // Parse the command line:
00043   programName = argv[0];
00044   if (argc != 2) usage();
00045 
00046   char const* inputFileName = argv[1];
00047   // Check whether the input file name ends with ".ts":
00048   int len = strlen(inputFileName);
00049   if (len < 4 || strcmp(&inputFileName[len-3], ".ts") != 0) {
00050     *env << "ERROR: input file name \"" << inputFileName
00051          << "\" does not end with \".ts\"\n";
00052     usage();
00053   }
00054 
00055   // Open the input file (as a 'byte stream file source'):
00056   FramedSource* input
00057     = ByteStreamFileSource::createNew(*env, inputFileName, TRANSPORT_PACKET_SIZE);
00058   if (input == NULL) {
00059     *env << "Failed to open input file \"" << inputFileName << "\" (does it exist?)\n";
00060     exit(1);
00061   }
00062 
00063   // Create a filter that indexes the input Transport Stream data:
00064   FramedSource* indexer
00065     = MPEG2IFrameIndexFromTransportStream::createNew(*env, input);
00066 
00067   // The output file name is the same as the input file name, except with suffix ".tsx":
00068   char* outputFileName = new char[len+2]; // allow for trailing x\0
00069   sprintf(outputFileName, "%sx", inputFileName);
00070 
00071   // Open the output file (for writing), as a 'file sink':
00072   MediaSink* output = FileSink::createNew(*env, outputFileName);
00073   if (output == NULL) {
00074     *env << "Failed to open output file \"" << outputFileName << "\"\n";
00075     exit(1);
00076   }
00077 
00078   // Start playing, to generate the output index file:
00079   *env << "Writing index file \"" << outputFileName << "\"...";
00080   output->startPlaying(*indexer, afterPlaying, NULL);
00081 
00082   env->taskScheduler().doEventLoop(); // does not return
00083 
00084   return 0; // only to prevent compiler warning
00085 }
00086 
00087 void afterPlaying(void* /*clientData*/) {
00088   *env << "...done\n";
00089   exit(0);
00090 }

Generated on Tue Mar 25 14:35:36 2014 for live by  doxygen 1.5.2