[MPlayer-dev-eng] [PATCH] ao_pcm: use native api for file operations on Win32
Zhou Zongyi
zhouzongyi at pset.suntec.net
Mon Mar 23 08:31:57 CET 2009
Hi, all
When ao pcm writes to a non-disk file (e.g. named pipe) under Win32,
it always add a wave header to the end of the stream, introducing a trailing noise.
You can find information about named pipes on windows by searching "CreateNamedPipe" on MSDN.
The problem is caused by fseek since fseek always returns 0 on Win32 even if the file is not seekable.
On windows we can use GetFileType to determine whether a file is seekable.
So far I have not found an equivelant function in standard C library.
The following patch solve the problem by using WinAPI instead of C functions for file operations.
Index: libao2/ao_pcm.c
===================================================================
--- libao2/ao_pcm.c (revision 29040)
+++ libao2/ao_pcm.c (working copy)
@@ -34,6 +34,15 @@
#include "mp_msg.h"
#include "help_mp.h"
+#ifdef _WIN32
+#include <windows.h>
+static DWORD written;
+#define FILE void
+#define fopen(fname,flag) (void*)CreateFileA(fname,FILE_GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,0)
+#define fclose(fp) CloseHandle((HANDLE)(fp))
+#define fwrite(buf,size,count,fp) WriteFile((HANDLE)(fp),buf,(size)*(count),&written,NULL)
+#define fseek(fp,offset,origin) (GetFileType((HANDLE)(fp)) != FILE_TYPE_DISK || SetFilePointer((HANDLE)(fp),(LONG)(offset),NULL,origin) == -1)
+#endif
static const ao_info_t info =
{
More information about the MPlayer-dev-eng
mailing list