int dfs_open(struct file *filp, char *name) { struct filsys *fs; struct inode *inode; int rc; fs = (struct filsys *) filp->fs->data; switch (filp->flags & (O_CREAT | O_EXCL | O_TRUNC | O_SPECIAL)) { case 0: case O_EXCL: // Open existing file rc = open_existing(fs, name, &inode); break; case O_CREAT: // Open file, create new file if it does not exists rc = open_always(fs, name, filp->mode, &inode); break; case O_CREAT | O_EXCL: case O_CREAT | O_TRUNC | O_EXCL: // Create new file, fail if it exists rc = create_new(fs, name, NOINODE, filp->mode, &inode); filp->flags |= F_MODIFIED; break; case O_TRUNC: case O_TRUNC | O_EXCL: // Open and truncate existing file rc = truncate_existing(fs, name, &inode); filp->flags |= F_MODIFIED; break; case O_CREAT | O_TRUNC: // Create new file, unlink existing file if it exists rc = create_always(fs, name, filp->mode, &inode); filp->flags |= F_MODIFIED; break; case O_SPECIAL: // Create new file with special inode number rc = create_new(fs, name, filp->flags >> 24, filp->mode, &inode); filp->flags |= F_MODIFIED; break; default: return -EINVAL; } if (rc < 0) return rc; if (filp->flags & O_APPEND) filp->pos = inode->desc->size; filp->data = inode; filp->mode = inode->desc->mode; filp->owner = inode->desc->uid; filp->group = inode->desc->gid; return 0; }
int dfs_open(struct file *filp, char *name, int mode) { struct filsys *fs; struct inode *inode; int len; fs = (struct filsys *) filp->fs->data; len = strlen(name); switch (filp->flags & (VFS_O_CREAT | VFS_O_EXCL | VFS_O_TRUNC | VFS_O_SPECIAL)) { case 0: case VFS_O_EXCL: // Open existing file inode = open_existing(fs, name, len); break; case VFS_O_CREAT: // Open file, create new file if it does not exists inode = open_always(fs, name, len, mode); break; case VFS_O_CREAT | VFS_O_EXCL: case VFS_O_CREAT | VFS_O_TRUNC | VFS_O_EXCL: // Create new file, unlink existing file if it exists inode = create_new(fs, name, len, mode); break; case VFS_O_TRUNC: case VFS_O_TRUNC | VFS_O_EXCL: // Open and truncate existing file inode = truncate_existing(fs, name, len); filp->flags |= F_MODIFIED; break; case VFS_O_CREAT | VFS_O_TRUNC: // Create new file, fail if it exists inode = create_always(fs, name, len, -1, mode); break; case VFS_O_SPECIAL: // Create new file with special inode number inode = create_always(fs, name, len, filp->flags >> 24, mode); break; default: return -1; } if (!inode) return -1; if (filp->flags & VFS_O_APPEND) filp->pos = (int) inode->desc->size; filp->data = inode; return 0; }
static int avi_open(const char* filename, const BITMAPINFOHEADER* pbmih, const WAVEFORMATEX* pwfex) { int error = 1; int result = 0; do { // close existing first DRV_AviEnd(); if(!truncate_existing(filename)) break; if(!pbmih) break; // create the object avi_create(&avi_file); // set video size and framerate /*avi_file->start_scanline = vsi->start_scanline; avi_file->end_scanline = vsi->end_scanline; avi_file->fps = vsi->fps; avi_file->fps_scale = 16777216-1; avi_file->convert_buffer = new u8[256*384*3];*/ // open the file if(FAILED(AVIFileOpen(&avi_file->avi_file, filename, OF_CREATE | OF_WRITE, NULL))) break; // create the video stream set_video_format(pbmih, avi_file); memset(&avi_file->avi_video_header, 0, sizeof(AVISTREAMINFO)); avi_file->avi_video_header.fccType = streamtypeVIDEO; avi_file->avi_video_header.dwScale = 6*355*263; avi_file->avi_video_header.dwRate = 33513982; avi_file->avi_video_header.dwSuggestedBufferSize = avi_file->bitmap_format.biSizeImage; if(FAILED(AVIFileCreateStream(avi_file->avi_file, &avi_file->streams[VIDEO_STREAM], &avi_file->avi_video_header))) break; if(use_prev_options) { avi_file->compress_options[VIDEO_STREAM] = saved_avi_info.compress_options[VIDEO_STREAM]; avi_file->compress_options_ptr[VIDEO_STREAM] = &avi_file->compress_options[0]; } else { // get compression options memset(&avi_file->compress_options[VIDEO_STREAM], 0, sizeof(AVICOMPRESSOPTIONS)); avi_file->compress_options_ptr[VIDEO_STREAM] = &avi_file->compress_options[0]; //retryAviSaveOptions: //mbg merge 7/17/06 removed error = 0; if(!AVISaveOptions(MainWindow->getHWnd(), 0, 1, &avi_file->streams[VIDEO_STREAM], &avi_file->compress_options_ptr[VIDEO_STREAM])) break; error = 1; } // create compressed stream if(FAILED(AVIMakeCompressedStream(&avi_file->compressed_streams[VIDEO_STREAM], avi_file->streams[VIDEO_STREAM], &avi_file->compress_options[VIDEO_STREAM], NULL))) break; // set the stream format if(FAILED(AVIStreamSetFormat(avi_file->compressed_streams[VIDEO_STREAM], 0, (void*)&avi_file->bitmap_format, avi_file->bitmap_format.biSize))) break; // add sound (if requested) if(pwfex) { // add audio format set_sound_format(pwfex, avi_file); // create the audio stream memset(&avi_file->avi_sound_header, 0, sizeof(AVISTREAMINFO)); avi_file->avi_sound_header.fccType = streamtypeAUDIO; avi_file->avi_sound_header.dwQuality = (DWORD)-1; avi_file->avi_sound_header.dwScale = avi_file->wave_format.nBlockAlign; avi_file->avi_sound_header.dwRate = avi_file->wave_format.nAvgBytesPerSec; avi_file->avi_sound_header.dwSampleSize = avi_file->wave_format.nBlockAlign; avi_file->avi_sound_header.dwInitialFrames = 1; if(FAILED(AVIFileCreateStream(avi_file->avi_file, &avi_file->streams[AUDIO_STREAM], &avi_file->avi_sound_header))) break; // AVISaveOptions doesn't seem to work for audio streams // so here we just copy the pointer for the compressed stream avi_file->compressed_streams[AUDIO_STREAM] = avi_file->streams[AUDIO_STREAM]; // set the stream format if(FAILED(AVIStreamSetFormat(avi_file->compressed_streams[AUDIO_STREAM], 0, (void*)&avi_file->wave_format, sizeof(WAVEFORMATEX)))) break; } // initialize counters avi_file->video_frames = 0; avi_file->sound_samples = 0; avi_file->tBytes = 0; avi_file->ByteBuffer = 0; avi_file->audio_buffer_pos = 0; // success error = 0; result = 1; avi_file->valid = 1; } while(0); if(!result) { avi_destroy(&avi_file); if(error) EMU_PrintError("Error writing AVI file"); } return result; }
static int avi_open(const char* filename, const BITMAPINFOHEADER* pbmih, const WAVEFORMATEX* pwfex, const struct VideoSystemInfo* vsi) { int error = 1; int result = 0; do { // close existing first FCEUI_AviEnd(); if(!truncate_existing(filename)) break; if(!pbmih) break; // create the object avi_create(&avi_file); // set video size and framerate avi_file->start_scanline = vsi->start_scanline; avi_file->end_scanline = vsi->end_scanline; //zero 20-oct-2012 - AVIFileClose has bugs in it which cause overflows in the calculation of dwTotalFrames, so some programs are unhappy with the resulting files. //so I reduced the precision here by the minimum number of shifts necessary to make it not overflow avi_file->fps = vsi->fps >> 3; avi_file->fps_scale = (16 * 1024 * 1024) >> 3; avi_file->convert_buffer = (uint8*)malloc(VIDEO_WIDTH*(vsi->end_scanline-vsi->start_scanline)*3); // open the file if(FAILED(AVIFileOpen(&avi_file->avi_file, filename, OF_CREATE | OF_WRITE, NULL))) break; // create the video stream set_video_format(pbmih, avi_file); memset(&avi_file->avi_video_header, 0, sizeof(AVISTREAMINFO)); avi_file->avi_video_header.fccType = streamtypeVIDEO; avi_file->avi_video_header.dwScale = avi_file->fps_scale; avi_file->avi_video_header.dwRate = avi_file->fps; avi_file->avi_video_header.dwSuggestedBufferSize = avi_file->bitmap_format.biSizeImage; if(FAILED(AVIFileCreateStream(avi_file->avi_file, &avi_file->streams[VIDEO_STREAM], &avi_file->avi_video_header))) break; if(use_prev_options) { avi_file->compress_options[VIDEO_STREAM] = saved_avi_info.compress_options[VIDEO_STREAM]; avi_file->compress_options_ptr[VIDEO_STREAM] = &avi_file->compress_options[0]; } else { // get compression options memset(&avi_file->compress_options[VIDEO_STREAM], 0, sizeof(AVICOMPRESSOPTIONS)); avi_file->compress_options_ptr[VIDEO_STREAM] = &avi_file->compress_options[0]; //retryAviSaveOptions: //mbg merge 7/17/06 removed error = 0; if(!AVISaveOptions(hAppWnd, 0, 1, &avi_file->streams[VIDEO_STREAM], &avi_file->compress_options_ptr[VIDEO_STREAM])) break; error = 1; } // create compressed stream if(FAILED(AVIMakeCompressedStream(&avi_file->compressed_streams[VIDEO_STREAM], avi_file->streams[VIDEO_STREAM], &avi_file->compress_options[VIDEO_STREAM], NULL))) break; // set the stream format if(FAILED(AVIStreamSetFormat(avi_file->compressed_streams[VIDEO_STREAM], 0, (void*)&avi_file->bitmap_format, avi_file->bitmap_format.biSize))) break; // add sound (if requested) if(pwfex) { // add audio format set_sound_format(pwfex, avi_file); // create the audio stream memset(&avi_file->avi_sound_header, 0, sizeof(AVISTREAMINFO)); avi_file->avi_sound_header.fccType = streamtypeAUDIO; avi_file->avi_sound_header.dwQuality = (DWORD)-1; avi_file->avi_sound_header.dwScale = avi_file->wave_format.nBlockAlign; avi_file->avi_sound_header.dwRate = avi_file->wave_format.nAvgBytesPerSec; avi_file->avi_sound_header.dwSampleSize = avi_file->wave_format.nBlockAlign; avi_file->avi_sound_header.dwInitialFrames = 1; if(FAILED(AVIFileCreateStream(avi_file->avi_file, &avi_file->streams[AUDIO_STREAM], &avi_file->avi_sound_header))) break; // AVISaveOptions doesn't seem to work for audio streams // so here we just copy the pointer for the compressed stream avi_file->compressed_streams[AUDIO_STREAM] = avi_file->streams[AUDIO_STREAM]; // set the stream format if(FAILED(AVIStreamSetFormat(avi_file->compressed_streams[AUDIO_STREAM], 0, (void*)&avi_file->wave_format, sizeof(WAVEFORMATEX)))) break; } // initialize counters avi_file->video_frames = 0; avi_file->sound_samples = 0; avi_file->tBytes = 0; avi_file->ByteBuffer = 0; avi_file->audio_buffer_pos = 0; // success error = 0; result = 1; avi_file->valid = 1; } while(0); if(!result) { avi_destroy(&avi_file); if(error) FCEUD_PrintError("Error writing AVI file"); } return result; }
int AVIBegin(const char* filename, struct AVIFile* _avi_out) { AVIFile& avi = *_avi_out; int result = 0; do { if(!avi.video_added) break; if(!truncate_existing(filename)) break; // open the file if(FAILED(AVIFileOpen(&avi.avi_file, filename, OF_CREATE | OF_WRITE, NULL))) break; // create the video stream memset(&avi.avi_video_header, 0, sizeof(AVISTREAMINFO)); avi.avi_video_header.fccType = streamtypeVIDEO; avi.avi_video_header.dwScale = ONE_DOT_CYCLE*SNES_HCOUNTER_MAX*SNES_MAX_NTSC_VCOUNTER; avi.avi_video_header.dwRate = (int)NTSC_MASTER_CLOCK; avi.avi_video_header.dwSuggestedBufferSize = avi.bitmap_format.biSizeImage; if(FAILED(AVIFileCreateStream(avi.avi_file, &avi.streams[VIDEO_STREAM], &avi.avi_video_header))) break; if(use_prev_options) { avi.compress_options[VIDEO_STREAM] = saved_avi_info.compress_options[VIDEO_STREAM]; avi.compress_options_ptr[VIDEO_STREAM] = &avi.compress_options[0]; } else { // get compression options memset(&avi.compress_options[VIDEO_STREAM], 0, sizeof(AVICOMPRESSOPTIONS)); avi.compress_options_ptr[VIDEO_STREAM] = &avi.compress_options[0]; if(!AVISaveOptions(GUI.hWnd, 0, 1, &avi.streams[VIDEO_STREAM], &avi.compress_options_ptr[VIDEO_STREAM])) break; } // create compressed stream if(FAILED(AVIMakeCompressedStream(&avi.compressed_streams[VIDEO_STREAM], avi.streams[VIDEO_STREAM], &avi.compress_options[VIDEO_STREAM], NULL))) break; // set the stream format if(FAILED(AVIStreamSetFormat(avi.compressed_streams[VIDEO_STREAM], 0, (void*)&avi.bitmap_format, avi.bitmap_format.biSize))) break; // add sound (if requested) if(avi.sound_added) { // create the audio stream memset(&avi.avi_sound_header, 0, sizeof(AVISTREAMINFO)); avi.avi_sound_header.fccType = streamtypeAUDIO; avi.avi_sound_header.dwQuality = (DWORD)-1; avi.avi_sound_header.dwScale = avi.wave_format.nBlockAlign; avi.avi_sound_header.dwRate = avi.wave_format.nAvgBytesPerSec; avi.avi_sound_header.dwSampleSize = avi.wave_format.nBlockAlign; avi.avi_sound_header.dwInitialFrames = 1; if(FAILED(AVIFileCreateStream(avi.avi_file, &avi.streams[AUDIO_STREAM], &avi.avi_sound_header))) break; // AVISaveOptions doesn't seem to work for audio streams // so here we just copy the pointer for the compressed stream avi.compressed_streams[AUDIO_STREAM] = avi.streams[AUDIO_STREAM]; // set the stream format if(FAILED(AVIStreamSetFormat(avi.compressed_streams[AUDIO_STREAM], 0, (void*)&avi.wave_format, sizeof(WAVEFORMATEX)))) break; } // initialize counters avi.video_frames = 0; avi.sound_samples = 0; avi.tBytes = 0; avi.ByteBuffer = 0; avi.audio_buffer_pos = 0; strncpy(saved_cur_avi_fnameandext,filename,MAX_PATH); strncpy(saved_avi_fname,filename,MAX_PATH); char* dot = strrchr(saved_avi_fname, '.'); if(dot && dot > strrchr(saved_avi_fname, '/') && dot > strrchr(saved_avi_fname, '\\')) { strcpy(saved_avi_ext,dot); dot[0]='\0'; } // success result = 1; avi.valid = true; } while(false); if(!result) { clean_up(&avi); avi.valid = false; } return result; }
int AVIBegin(const char* filename, struct AVIFile* _avi_out) { AVIFile& avi = *_avi_out; int result = 0; do { if(!avi.video_added) break; if(!truncate_existing(filename)) break; // open the file if(FAILED(AVIFileOpen(&avi.avi_file, filename, OF_CREATE | OF_WRITE, NULL))) break; // create the video stream memset(&avi.avi_video_header, 0, sizeof(AVISTREAMINFO)); avi.avi_video_header.fccType = streamtypeVIDEO; avi.avi_video_header.dwScale = avi.frameskip; avi.avi_video_header.dwRate = avi.fps; avi.avi_video_header.dwSuggestedBufferSize = avi.bitmap_format.biSizeImage; if(FAILED(AVIFileCreateStream(avi.avi_file, &avi.streams[VIDEO_STREAM], &avi.avi_video_header))) break; // get compression options memset(&avi.compress_options[VIDEO_STREAM], 0, sizeof(AVICOMPRESSOPTIONS)); avi.compress_options_ptr[VIDEO_STREAM] = &avi.compress_options[0]; if(!AVISaveOptions(GUI.hWnd, 0, 1, &avi.streams[VIDEO_STREAM], &avi.compress_options_ptr[VIDEO_STREAM])) break; // create compressed stream if(FAILED(AVIMakeCompressedStream(&avi.compressed_streams[VIDEO_STREAM], avi.streams[VIDEO_STREAM], &avi.compress_options[VIDEO_STREAM], NULL))) break; // set the stream format if(FAILED(AVIStreamSetFormat(avi.compressed_streams[VIDEO_STREAM], 0, (void*)&avi.bitmap_format, avi.bitmap_format.biSize))) break; // add sound (if requested) if(avi.sound_added) { // create the audio stream memset(&avi.avi_sound_header, 0, sizeof(AVISTREAMINFO)); avi.avi_sound_header.fccType = streamtypeAUDIO; avi.avi_sound_header.dwQuality = (DWORD)-1; avi.avi_sound_header.dwScale = avi.wave_format.nBlockAlign; avi.avi_sound_header.dwRate = avi.wave_format.nAvgBytesPerSec; avi.avi_sound_header.dwSampleSize = avi.wave_format.nBlockAlign; avi.avi_sound_header.dwInitialFrames = 1; if(FAILED(AVIFileCreateStream(avi.avi_file, &avi.streams[AUDIO_STREAM], &avi.avi_sound_header))) break; // AVISaveOptions doesn't seem to work for audio streams // so here we just copy the pointer for the compressed stream avi.compressed_streams[AUDIO_STREAM] = avi.streams[AUDIO_STREAM]; // set the stream format if(FAILED(AVIStreamSetFormat(avi.compressed_streams[AUDIO_STREAM], 0, (void*)&avi.wave_format, sizeof(WAVEFORMATEX)))) break; } // initialize counters avi.video_frames = 0; avi.sound_samples = 0; // success result = 1; avi.valid = true; } while(false); if(!result) { clean_up(&avi); avi.valid = false; } return result; }