void AVFmfWriter::WriteFrame(Mat img) { double dst = (double)nframes; _fwrite_nolock(&dst, sizeof(double), 1, fp); _fwrite_nolock(img.data, sizeof(unsigned char), SizeY*SizeX, fp); }
//void FmfWriter::WriteFrame(TimeStamp st, Image img) void AVFmfWriter::WriteFrame(Image img) { //double dst = (double) st.seconds; double dst = (double)nframes; _fwrite_nolock(&dst, sizeof(double), 1, fp); _fwrite_nolock(img.GetData(), img.GetDataSize(), 1, fp); }
void AVFmfWriter::WriteHeader() { //write FMF header data _fwrite_nolock(&fmfVersion, sizeof(unsigned __int32), 1, fp); _fwrite_nolock(&SizeY, sizeof(unsigned __int32), 1, fp); _fwrite_nolock(&SizeX, sizeof(unsigned __int32), 1, fp); _fwrite_nolock(&bytesPerChunk, sizeof(unsigned __int64), 1, fp); _fwrite_nolock(&nframes, sizeof(unsigned __int64), 1, fp); }
// Writes a string to stdout. Does not write the string's null terminator, but // _does_ append a newline to the output. Return 0 on success; EOF on failure. extern "C" int __cdecl puts(char const* const string) { _VALIDATE_RETURN(string != nullptr, EINVAL, EOF); FILE* const stream = stdout; _VALIDATE_STREAM_ANSI_RETURN(stream, EINVAL, EOF); size_t const length = strlen(string); return __acrt_lock_stream_and_call(stream, [&]() -> int { __acrt_stdio_temporary_buffering_guard const buffering(stream); size_t const bytes_written = _fwrite_nolock(string, 1, length, stream); // If we failed to write the entire string, or if we fail to write the // newline, reset the buffering and return failure: if (bytes_written != length || _fputc_nolock('\n', stream) == EOF) { return EOF; } return 0; }); }
static unsigned __stdcall video_output_thread_func(void *prm) { video_output_thread_t *thread_data = reinterpret_cast<video_output_thread_t *>(prm); CONVERT_CF_DATA *pixel_data = thread_data->pixel_data; WaitForSingleObject(thread_data->he_out_start, INFINITE); while (false == thread_data->abort) { //映像データをパイプに for (int i = 0; i < 1 + thread_data->repeat; i++) for (int j = 0; j < pixel_data->count; j++) _fwrite_nolock((void *)pixel_data->data[j], 1, pixel_data->size[j], thread_data->f_out); thread_data->repeat = 0; SetEvent(thread_data->he_out_fin); WaitForSingleObject(thread_data->he_out_start, INFINITE); } return 0; }
int AVFmfWriter::Close() { //seek to location in file where nframes is stored and replace fseek (fp, 20, SEEK_SET ); _fwrite_nolock(&nframes, sizeof(unsigned __int64), 1, fp); fclose(fp); fclose(flog); fclose(ftraj); fp = NULL; flog = NULL; ftraj = NULL; return 1; }
// Writes data from the provided buffer to the specified stream. The function // writes 'count' elements of 'size' size to the stream, and returns when // either all of the elements have been written or no more data can be written // (e.g. if EOF is encountered or an error occurs). // // Returns the number of "whole" elements that were written to the stream. This // may be fewer than the requested number of an error occurs or EOF is encountered. // In this case, ferror() or feof() should be used to distinguish between the two // conditions. extern "C" size_t __cdecl fwrite( void const* const buffer, size_t const size, size_t const count, FILE* const stream ) { if (size == 0 || count == 0) return 0; // The _nolock version will do the rest of the validation. _VALIDATE_RETURN(stream != nullptr, EINVAL, 0); return __acrt_lock_stream_and_call(stream, [&]() -> size_t { __acrt_stdio_temporary_buffering_guard const buffering(stream); return _fwrite_nolock(buffer, size, count, stream); }); }
int __cdecl fputs( const char* string, FILE* stream ) { REG2 int buffing; REG1 size_t length; REG3 size_t ndone; _VALIDATE_RETURN((string != NULL), EINVAL, EOF); _VALIDATE_RETURN((stream != NULL), EINVAL, EOF); _VALIDATE_STREAM_ANSI_RETURN(stream, EINVAL, EOF); length = strlen(string); _lock_str(stream); __try { buffing = _stbuf(stream); ndone = _fwrite_nolock(string, 1, length, stream); _ftbuf(buffing, stream); } __finally { _unlock_str(stream); } return (ndone == length ? 0 : EOF); }
void Storage::Save() { FILE* f = 0; fopen_s( &f, FileName.c_str(), "wb" ); if ( f == 0 ) return; // Number of probes what we have int num_probes = probes.size(); fwrite( &num_probes, 4, 1, f ); std::set<UserInput>::iterator It = probes.begin(); for( ; It != probes.end(); ++It ) { // Saving probe UserInput& ui = *It; // probe hints int record_guess = ui.guess; fwrite( &record_guess, 4, 1, f ); int record_inplace = ui.inplace; fwrite( &record_inplace, 4, 1, f ); // number of history records int num_records = ui.history.size(); fwrite( &num_records, 4, 1, f ); HistoryT::iterator It2 = ui.history.begin(); for( ; It2 != ui.history.end(); ++It2 ) { UserInput& record = *It2; // history record value int record_value = record; fwrite( &record_value, 4, 1, f ); // history record hints record_guess = record.guess; fwrite( &record_guess, 4, 1, f ); record_inplace = record.inplace; fwrite( &record_inplace, 4, 1, f ); } // number of digits with minimal invariance int min_size = ui.min_variants.size(); fwrite( &min_size, 4, 1, f ); // invariance value int min_value = 0; if ( min_size ) min_value = ui.min_variants.begin()->second; fwrite( &min_value, 4, 1, f ); // save digits MinimalsT::iterator It3 = ui.min_variants.begin(); int* buf = new int[min_size]; int* ptr = buf; for( ; It3 != ui.min_variants.end(); ++It3 ) *(ptr++) = It3->first; _fwrite_nolock( buf, 4, min_size, f ); _fflush_nolock(f); delete[] buf; } fclose(f); }
BOOL check_x264_mp4_output(const char *exe_path, const char *temp_filename) { BOOL ret = FALSE; std::string exe_message; PROCESS_INFORMATION pi = { 0 }; const int TEST_WIDTH = 160; const int TEST_HEIGHT = 120; std::vector<char> test_buffer(TEST_WIDTH * TEST_HEIGHT * 3 / 2, 0); PIPE_SET pipes = { 0 }; InitPipes(&pipes); pipes.stdIn.mode = AUO_PIPE_ENABLE; pipes.stdOut.mode = AUO_PIPE_DISABLE; pipes.stdErr.mode = AUO_PIPE_ENABLE; pipes.stdIn.bufferSize = test_buffer.size(); char test_path[1024] = { 0 }; for (int i = 0; !i || PathFileExists(test_path); i++) { char test_filename[32] = { 0 }; sprintf_s(test_filename, _countof(test_filename), "_test_%d.mp4", i); PathCombineLong(test_path, _countof(test_path), temp_filename, test_filename); } char exe_dir[1024] = { 0 }; strcpy_s(exe_dir, _countof(exe_dir), exe_path); PathRemoveFileSpecFixed(exe_dir); char fullargs[8192] = { 0 }; sprintf_s(fullargs, _countof(fullargs), "\"%s\" --fps 1 --frames 1 --input-depth 8 --input-res %dx%d -o \"%s\" --input-csp nv12 -", exe_path, TEST_WIDTH, TEST_HEIGHT, test_path); if ((ret = RunProcess(fullargs, exe_dir, &pi, &pipes, NORMAL_PRIORITY_CLASS, TRUE, FALSE)) == RP_SUCCESS) { while (WAIT_TIMEOUT == WaitForInputIdle(pi.hProcess, LOG_UPDATE_INTERVAL)) log_process_events(); _fwrite_nolock(&test_buffer[0], 1, test_buffer.size(), pipes.f_stdin); auto read_stderr = [](PIPE_SET *pipes) { DWORD pipe_read = 0; if (!PeekNamedPipe(pipes->stdErr.h_read, NULL, 0, NULL, &pipe_read, NULL)) return -1; if (pipe_read) { ReadFile(pipes->stdErr.h_read, pipes->read_buf + pipes->buf_len, sizeof(pipes->read_buf) - pipes->buf_len - 1, &pipe_read, NULL); pipes->buf_len += pipe_read; pipes->read_buf[pipes->buf_len] = '\0'; } return (int)pipe_read; }; while (WAIT_TIMEOUT == WaitForSingleObject(pi.hProcess, 10)) { if (read_stderr(&pipes)) { exe_message += pipes.read_buf; pipes.buf_len = 0; } else { log_process_events(); } } CloseStdIn(&pipes); while (read_stderr(&pipes) > 0) { exe_message += pipes.read_buf; pipes.buf_len = 0; } log_process_events(); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); if (std::string::npos == exe_message.find("not compiled with MP4 output")) ret = TRUE; } if (pipes.stdIn.mode) CloseHandle(pipes.stdIn.h_read); if (pipes.stdOut.mode) CloseHandle(pipes.stdOut.h_read); if (pipes.stdErr.mode) CloseHandle(pipes.stdErr.h_read); if (PathFileExists(test_path)) remove(test_path); return ret; }