Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

/*
 * Copyright 1995, Brown University, Providence, RI
 *
 * Permission to use and modify this software and its documentation for
 * any purpose other than its incorporation into a commercial product is
 * hereby granted without fee.  Permission to copy and distribute this
 * software and its documentation only for non-commercial use is also
 * granted without fee, provided, however, that the above copyright notice
 * appear in all copies, that both that copyright notice and this permission
 * notice appear in supporting documentation, that the name of Brown
 * University not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior permission,
 * and that the person doing the distribution notify Brown University of
 * such distributions outside of his or her organization. Brown University
 * makes no representations about the suitability of this software for
 * any purpose.  It is provided "as is" without express or implied warranty.
 * Brown University requests notification of any modifications to this
 * software or its documentation.
 *
 * Send the following redistribution information:
 *
 *      Name:
 *      Organization:
 *      Address (postal and/or electronic):
 *
 * To:
 *      Software Librarian
 *      Computer Science Department, Box 1910
 *      Brown University
 *      Providence, RI 02912
 *
 *              or
 *
 *      brusd@cs.brown.edu
 *
 * We will acknowledge all electronic notifications.
 */

#include <stdio.h>
#include <iostream.h>
#include "ANIMdisplay.H"
#include "ANIMmpeg.H"
#ifndef NONV
#include "ANIMnv.H"
#endif

extern unsigned long wpixel[256];
extern int quietFlag;

const int NUMMOVIES=20;
int numInput=0;

/* Global file pointer to incoming data. */
char *inputName[NUMMOVIES];

int buffer=TRUE;
int compress=TRUE, cycle=FALSE;
#ifndef NOTHREADS
int mthread=TRUE;
#endif

void
displayMovies(ANIMdisplay **theWindows, ANIMbase **theMovies)
{
   /* Start multithreading after all the images have been init-ed */
   int moviesToDisplay=cycle ? 1 : numInput;

   for (int i=0;i<moviesToDisplay;i++) {
      theMovies[i]->Buffer(buffer, compress);
#ifndef NOTHREADS
      theMovies[i]->MultiThread(mthread);
#endif
   }

   quietFlag=0;
   Boolean workToDo=TRUE;

   if (cycle) {
      int currentMovie=0, frames=0;
      while(1) {
        theWindows[0]->display();
        frames++;
        if (cycle && theWindows[0]->movieDone()) {
            ANIMbase *movie= theWindows[0]->_movie;

                printf("%d %dx%d frames, %s\n",
                   frames, movie->Width, movie->Height, movie->getName());
                fflush(stdout);
                frames=0;
                currentMovie=++currentMovie % numInput;
                theWindows[0]->newMovie(inputName[currentMovie]);
        }
      }
   } else {
      while (workToDo) {
         for (int whichMovie=0;whichMovie<numInput;whichMovie++) {
            theWindows[whichMovie]->display();
         }
      }
   }
}

#ifndef __STDC__
void
#else
int
#endif
main(int argc, char **argv)
{
    char *filename="/home/lsh/tii/mpeg/eggclock.mpg";
    int mark=1;
    ANIMbase *theMovie[NUMMOVIES];
    ANIMdisplay *theWindow[NUMMOVIES];
    char *displayName="";

    /* Initiialize arrays */
    for (int i=0;i<NUMMOVIES; i++) {
         inputName[i] = filename;
         theWindow[i]=NULL;
         theMovie[i]=NULL;
    }

    //
    // Get command line arguments
    //
    argc--;

    while (argc) {
      if (strcmp(argv[mark], "-display") == 0) {
        displayName= argv[++mark];
        argc -= 2; mark++;
      } else if (strcmp(argv[mark], "-no_buffer") == 0) {
         buffer=FALSE;
         argc--; mark++;
      } else if (strcmp(argv[mark], "-no_compress") == 0) {
         compress=FALSE;
         argc--; mark++;
      } else if (strcmp(argv[mark], "-cycle") == 0) {
         cycle=TRUE;
         buffer=FALSE; //for now, or we don't know to cycle
         argc--; mark++;
#ifndef NOTHREADS
      } else if (strcmp(argv[mark], "-no_mthread") == 0) {
         mthread=FALSE;
         argc--; mark++;
#endif
      } else {
        fflush(stdout);
        if (numInput<NUMMOVIES) {
            inputName[numInput] = argv[mark];
            if ((numInput==0) || !cycle) {
#ifndef NONV
              if (strstr(inputName[numInput],"mbone:")!=NULL) {
                 theMovie[numInput]=
                       (ANIMbase *) new ANIMnv(inputName[numInput]);
              } else
#endif
                  theMovie[numInput]=
                       (ANIMbase *) new ANIMmpeg(inputName[numInput]);
              if (!theMovie[numInput]->OkFile()) {
                 fprintf(stderr, "%s: %s not found\n", argv[0],argv[mark]);
                 /* shouldn't have to delete it each time - reuse!*/
                 delete theMovie[numInput];
              } else {
               if (theMovie[numInput]->open()) {
                 if (numInput==0) {
                    theWindow[0]=new ANIMdisplay((ANIMbase *) theMovie[0],
                                        displayName,!cycle);
                 } else {
                     theWindow[numInput]=new ANIMdisplay(
                                     (ANIMbase *) theMovie[numInput],
                                                   theWindow[numInput-1],
                                                   !cycle);
                 }
                 numInput++;
               } else {
                    fprintf(stderr,"%s: %s not an MPEG file\n",
                     argv[0],argv[mark]);
                    delete theMovie[numInput];
                 }
              }
            } else if (cycle) {
                numInput++;
            }
        } else {
               fprintf(stderr, "Can't load file %s - too many\n", argv[mark]);
        }
        argc--; mark++;
      }
    }

    if (numInput) displayMovies(theWindow, (ANIMbase **) theMovie);
    else {
#ifndef NOTHREADS      
       char *threadStr="-no_mthread";
#else
       char *threadStr="";
#endif
       fprintf(stderr,"%s: no files entered\n",argv[0]);
       fprintf(stderr,
         "usage: %s [-display display -no_buffer %s -cycle -no_compress] movie ... \n",
                      argv[0],threadStr);
       exit(1);
    }
}