From: Bram R. <bra...@ph...> - 2006-01-31 09:07:06
|
Hi Erwin, others, Here my thoughts on the implementation of file size truncation on windows. Currently, files are closed by function p_close_idx() in module cpfspd_low. Possible reasons to close a file are: - application request - application opens new file while many files already open (least recently used file is closed) - atexit function when application terminates Main issue: the file header info is required in order to calculate the file size. This info is not available in p_close_idx(). In many cases, this info is not even in the application anymore. Note that p_close_idx() already writes the number of images at the beginning of the file (hence, it adapts the file header) in case the actual file contains more images than the data in the file header. Simple approach The win32 api has calls to set file size. Maybe this works for files opened unbuffered and asynchronously. If this is true, then this simple approach will work. Therefore, the approach must be: - move to beginning of the file - read the header - calculate file length - set file length - close file Extended approach It may be required to close the file first, then reopen it in normal mode. This results in a slightly more extended approach: - perform regular close of the file - reopen the file (normal mode) - read the header - calculate file length - set file length - close file Other notes Module cpfspd_low. - Add required functionality in p_close_idx(). - File size calculation is analogous to file positioning when accessing an image, see e.g. cpfspd_low.c function p_read_image() lines 1593-1610. Some win API background info for use in cpfspd_fio: - OpenFile() http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/openfile.asp - ReOpenFile() http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/reopenfile.asp - SetFilePointer() http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/setfilepointer.asp - SetEndOfFile() http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/setendoffile.asp - CloseHandle() http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/closehandle.asp Examples of most of these calls are already in cpfspd_fio.c I expect, when reopening the file in the new mode, all regular file access works as expected. Hence, first reopen the file in normal buffered mode; then perform the regular p_read_header() (which uses fio_read functions) will work as usual. I expect, only new code is to be added. No existing code needs modification. Regards, Bram. -- A.K. (Bram) Riemens Principal Scientist, DSP group, Philips Research Office: WO-p-94, Postbox WO02 High Tech Campus 36 (WO), 5656 AE Eindhoven, The Netherlands Tel: +31 40 27 43833, Fax: +31 40 27 44675 E-mail: bra...@ph... Erwin de Kock 30-01-2006 21:15 To Bram Riemens/EHV/RESEARCH/PHILIPS@PHILIPS cc Subject Re: [Pfs...@sf...] Linux, cygwin, and different yuv file sizes Classification Unclassified Hi Bram, Thanks for the response. I am using your software in our open source project at http://sourceforge.net/projects/y-api. The internal tool pts is not available for the general public so I prefer your suggestion to adapt the file size when closing the file. Then I can check against expected output using "diff -q". I am willing to help with this change, but I have to familiarize myself with your code. I will contact you if I have questions :) Best regards, --Erwin |