/* * Common implementation function for Open() and Open_Directory(). */ static int Do_Open( const char *path, int mode, struct File **pFile, int (*openFunc)(struct Mount_Point *mountPoint, const char *path, int mode, struct File **pFile)) { char prefix[MAX_PREFIX_LEN + 1]; const char *suffix; struct Mount_Point *mountPoint; int rc; /* Check whether relative path */ if (*path != '/') Convert_To_Abs_Path(path); if (!Unpack_Path(path, prefix, &suffix)) return ENOTFOUND; /* Get mount point for path */ mountPoint = Lookup_Mount_Point(prefix); if (mountPoint == 0) return ENOTFOUND; /* Call into actual Open() or Open_Directory() function. */ rc = openFunc(mountPoint, suffix, mode, pFile); if (rc == 0) { /* File opened successfully! */ (*pFile)->mode = mode; (*pFile)->mountPoint = mountPoint; } return rc; }
static FileHandle *doOpen(DirHandle *h, const char *name, void *(*openFunc)(const char *filename), int *fileExists, const FileFunctions *fileFuncs) { char *f = __PHYSFS_platformCvtToDependent((char *)(h->opaque), name, NULL); void *rc; FileHandle *retval; BAIL_IF_MACRO(f == NULL, NULL, NULL); if (fileExists != NULL) { *fileExists = __PHYSFS_platformExists(f); if (!(*fileExists)) { free(f); return(NULL); } /* if */ } /* if */ retval = (FileHandle *) malloc(sizeof (FileHandle)); if (!retval) { free(f); BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); } /* if */ rc = openFunc(f); free(f); if (!rc) { free(retval); return(NULL); } /* if */ retval->opaque = (void *) rc; retval->dirHandle = h; retval->funcs = fileFuncs; return(retval); } /* doOpen */
static fvoid *doOpen(dvoid *opaque, const char *name, void *(*openFunc)(const char *filename), int *fileExists) { char *f = __PHYSFS_platformCvtToDependent((char *) opaque, name, NULL); void *rc = NULL; BAIL_IF_MACRO(f == NULL, NULL, NULL); if (fileExists != NULL) { *fileExists = __PHYSFS_platformExists(f); if (!(*fileExists)) { allocator.Free(f); return(NULL); } /* if */ } /* if */ rc = openFunc(f); allocator.Free(f); return((fvoid *) rc); } /* doOpen */
void CheckBegin() { if(avifp) return; if(!openFunc) openFunc = popen; // default if(!closeFunc) closeFunc = pclose; // default avifp = openFunc(VIDEO_CMD.c_str(), "wb"); if(!avifp) return; const unsigned fourcc = BGR16; const unsigned framesize = width*height*2; const unsigned aud_rate = rate; const unsigned aud_chans = chans; const unsigned aud_bits = bits; const unsigned nframes = 0; //unknown const unsigned scale = FPS_SCALE; const unsigned scaled_fps = fps_scaled; const unsigned SIZE_strh_vids = 4 + 4*2 + 2*2 + 8*4 + 2*4; const unsigned SIZE_strf_vids = 4*3 + 2*2 + 4*6; const unsigned SIZE_strl_vids = 4+ 4+(4+SIZE_strh_vids) + 4+(4+SIZE_strf_vids); const unsigned SIZE_strh_auds = 4 + 4*3 + 2*2 + 4*8 + 2*4; const unsigned SIZE_strf_auds = 2*2 + 4*2 + 2*3; const unsigned SIZE_strl_auds = 4+ 4+(4+SIZE_strh_auds) + 4+(4+SIZE_strf_auds); const unsigned SIZE_avih = 4*12; const unsigned SIZE_hdrl = 4+4+ (4+SIZE_avih) + 4 + (4+SIZE_strl_vids) + 4 + (4+SIZE_strl_auds); const unsigned SIZE_movi = 4 + nframes*(4+4+framesize); const unsigned SIZE_avi = 4+4+ (4+SIZE_hdrl) + 4 + (4+SIZE_movi); const unsigned char AVIheader[] = { s4("RIFF"), u32(SIZE_avi), s4("AVI "), // HEADER s4("LIST"), u32(SIZE_hdrl), s4("hdrl"), s4("avih"), u32(SIZE_avih), u32(0), u32(0), u32(0), u32(0), u32(nframes), u32(0), u32(2), // two streams u32(0), u32(0), u32(0), u32(0), u32(0), // VIDEO HEADER s4("LIST"), u32(SIZE_strl_vids), s4("strl"), s4("strh"), u32(SIZE_strh_vids), s4("vids"), u32(0), u32(0), u16(0), u16(0), u32(0), u32(scale), u32(scaled_fps), u32(0), u32(0), u32(0), u32(0), u32(0), u16(0), u16(0), u16(0), u16(0), s4("strf"), u32(SIZE_strf_vids), u32(0), u32(width), u32(height), u16(0), u16(0), u32(fourcc), u32(0), u32(0), u32(0), u32(0), u32(0), // AUDIO HEADER s4("LIST"), u32(SIZE_strl_auds), s4("strl"), s4("strh"), u32(SIZE_strh_auds), s4("auds"), u32(0), //fourcc u32(0), //handler u32(0), //flags u16(0), //prio u16(0), //lang u32(0), //init frames u32(1), //scale u32(aud_rate), u32(0), //start u32(0), //rate*length u32(1048576), //suggested bufsize u32(0), //quality u32(aud_chans * (aud_bits / 8)), //sample size u16(0), //frame size u16(0), u16(0), u16(0), s4("strf"), u32(SIZE_strf_auds), u16(1), // pcm format u16(aud_chans), u32(aud_rate), u32(aud_rate * aud_chans * (aud_bits/8)), // samples per second u16(aud_chans * (aud_bits/8)), //block align u16(aud_bits), //bits u16(0), //cbSize // MOVIE s4("LIST"), u32(SIZE_movi), s4("movi") }; FlushWrite(avifp, AVIheader, sizeof(AVIheader)); }