Changeset 4881 for nanovis/branches/1.1


Ignore:
Timestamp:
Dec 19, 2014, 6:49:27 PM (5 years ago)
Author:
ldelgass
Message:

Fixes for video generation

Location:
nanovis/branches/1.1
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • nanovis/branches/1.1/Command.cpp

    r4879 r4881  
    503503/**
    504504 * Read the requested number of bytes from standard input into the given
    505  * buffer.  The buffer is then decompressed and decoded.
     505 * buffer.  The buffer must have already been allocated for nBytes.  The
     506 * buffer is then decompressed and decoded.
    506507 */
    507508int
     
    13561357                    Volume::valueMin, Volume::valueMax);
    13571358        if (SocketWrite(info, (size_t)cmdLength) != (ssize_t)cmdLength) {
     1359            ERROR("Short write");
    13581360            return TCL_ERROR;
    13591361        }
  • nanovis/branches/1.1/FlowCmd.cpp

    r4874 r4881  
    10651065};
    10661066
    1067 static int
    1068 ppmWriteToFile(Tcl_Interp *interp, const char *path, FlowVideoSwitches *switchesPtr)
    1069 {
    1070     int f;
    1071    
     1067static bool
     1068ppmWriteToFile(const char *path, const unsigned char *imgData,
     1069               int width, int height)
     1070{
    10721071    /* Open the named file for writing. */
    1073     f = creat(path, 0600);
    1074     if (f < 0) {
    1075         Tcl_AppendResult(interp, "can't open temporary image file \"", path,
    1076                          "\": ", Tcl_PosixError(interp), (char *)NULL);
    1077         return TCL_ERROR;
     1072    int fdOut = creat(path, 0600);
     1073    if (fdOut < 0) {
     1074        ERROR("can't open temporary image file \"%s\": %s", path, strerror(errno));
     1075        return false;
    10781076    }
    10791077    // Generate the PPM binary file header
    10801078    char header[200];
    10811079#define PPM_MAXVAL 255
    1082     sprintf(header, "P6 %d %d %d\n", switchesPtr->width, switchesPtr->height,
     1080    sprintf(header, "P6 %d %d %d\n", width, height,
    10831081        PPM_MAXVAL);
    10841082
    10851083    size_t header_length = strlen(header);
    1086     size_t wordsPerRow = (switchesPtr->width * 24 + 31) / 32;
     1084    size_t wordsPerRow = (width * 24 + 31) / 32;
    10871085    size_t bytesPerRow = wordsPerRow * 4;
    1088     size_t rowLength = switchesPtr->width * 3;
    1089     size_t numRecords = switchesPtr->height + 1;
     1086    size_t rowLength = width * 3;
     1087    size_t numRecords = height + 1;
    10901088
    10911089    struct iovec *iov;
     
    10981096    // Now add the image data, reversing the order of the rows.
    10991097    int y;
    1100     unsigned char *srcRowPtr = NanoVis::screenBuffer;
     1098    unsigned char *srcRowPtr = const_cast<unsigned char *>(imgData);
    11011099    /* Reversing the pointers for the image rows.  PPM is top-to-bottom. */
    1102     for (y = switchesPtr->height; y >= 1; y--) {
     1100    for (y = height; y >= 1; y--) {
    11031101        iov[y].iov_base = srcRowPtr;
    11041102        iov[y].iov_len = rowLength;
    11051103        srcRowPtr += bytesPerRow;
    11061104    }
    1107     if (writev(f, iov, numRecords) < 0) {
    1108         Tcl_AppendResult(interp, "writing image to \"", path, "\" failed: ",
    1109                          Tcl_PosixError(interp), (char *)NULL);
     1105    if (writev(fdOut, iov, numRecords) < 0) {
     1106        ERROR("writing image to \"%s\" failed: %s", path, strerror(errno));
    11101107        free(iov);
    1111         close(f);
    1112         return TCL_ERROR;
    1113     }
    1114     close(f);
     1108        close(fdOut);
     1109        return false;
     1110    }
     1111    close(fdOut);
    11151112    free(iov);
    1116     return TCL_OK;
    1117 }
    1118 
    1119 static int
    1120 MakeImageFiles(Tcl_Interp *interp, char *tmpFileName,
    1121                FlowVideoSwitches *switchesPtr, bool *cancelPtr)
     1113    return true;
     1114}
     1115
     1116static bool
     1117MakeImageFiles(char *tmpFileName,
     1118               int width, int height, int numFrames,
     1119               bool *cancelPtr)
    11221120{
    11231121    struct pollfd pollResults;
     
    11311129    oldHeight = NanoVis::winHeight;
    11321130
    1133     if ((switchesPtr->width != oldWidth) ||
    1134         (switchesPtr->height != oldHeight)) {
     1131    if (width != oldWidth ||
     1132        height != oldHeight) {
    11351133        // Resize to the requested size.
    1136         NanoVis::resizeOffscreenBuffer(switchesPtr->width, switchesPtr->height);
     1134        NanoVis::resizeOffscreenBuffer(width, height);
    11371135    }
    11381136    NanoVis::resetFlows();
    11391137    *cancelPtr = false;
    1140     int result = TCL_OK;
     1138    bool result = true;
    11411139    size_t length = strlen(tmpFileName);
    1142     for (int i = 1; i <= switchesPtr->numFrames; i++) {
     1140    for (int i = 1; i <= numFrames; i++) {
    11431141        if (((i & 0xF) == 0) && (poll(&pollResults, 1, timeout) > 0)) {
    11441142            /* If there's another command on stdin, that means the client is
     
    11621160
    11631161        sprintf(tmpFileName + length, "/image%d.ppm", i);
    1164         result = ppmWriteToFile(interp, tmpFileName, switchesPtr);
    1165         if (result != TCL_OK) {
     1162        result = ppmWriteToFile(tmpFileName, NanoVis::screenBuffer,
     1163                                width, height);
     1164        if (!result) {
    11661165            break;
    11671166        }
    11681167    }
    1169     if ((switchesPtr->width != oldWidth) ||
    1170         (switchesPtr->height != oldHeight)) {
     1168    if (width != oldWidth ||
     1169        height != oldHeight) {
    11711170        NanoVis::resizeOffscreenBuffer(oldWidth, oldHeight);
    11721171    }
     
    11931192            switchesPtr->bitRate, switchesPtr->frameRate);
    11941193    TRACE("Enter: %s", cmd);
    1195     FILE *f;
    1196     f = popen(cmd, "r");
     1194    FILE *f = popen(cmd, "r");
    11971195    if (f == NULL) {
    11981196        Tcl_AppendResult(interp, "can't run ffmpeg: ",
     
    12031201    size_t total = 0;
    12041202    for (;;) {
    1205         ssize_t numRead;
    12061203        char buffer[BUFSIZ];
    12071204       
    1208         numRead = fread(buffer, sizeof(unsigned char), BUFSIZ, f);
     1205        ssize_t numRead = fread(buffer, sizeof(unsigned char), BUFSIZ, f);
    12091206        total += numRead;
    12101207        if (numRead == 0) {             // EOF
     
    12871284    size_t length = strlen(tmpFileName);
    12881285    bool canceled = false;
    1289     result = MakeImageFiles(interp, tmpFileName, &switches, &canceled);
     1286    if (MakeImageFiles(tmpFileName,
     1287                       switches.width, switches.height, switches.numFrames,
     1288                       &canceled)) {
     1289        result = TCL_OK;
     1290    } else {
     1291        result = TCL_ERROR;
     1292    }
    12901293    if ((result == TCL_OK) && (!canceled)) {
    12911294        result = MakeMovie(interp, tmpFileName, token, &switches);
  • nanovis/branches/1.1/nanovis.h

    r4874 r4881  
    109109    static void ppmWrite(const char *prefix);
    110110    static void bmpWrite(const char *prefix);
    111     static void bmpWriteToFile(int frame_number, const char* directory_name);
     111    static void bmpWriteToFile(int frameNum, const char* dirName);
    112112 
    113113    static TransferFunction *getTransferFunction(const TransferFunctionId& id);
  • nanovis/branches/1.1/nanovisServer.cpp

    r4875 r4881  
    264264/**
    265265 * \brief Send a command with data payload
    266  *
    267  * data pointer is freed on completion of the response
    268266 */
    269267void
     
    271269{
    272270    size_t numRecords = 2;
    273 
    274271    struct iovec *iov = new iovec[numRecords];
    275272
Note: See TracChangeset for help on using the changeset viewer.