From c1ac15cd973a5c400f02770282e2c1536cdecefd Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sat, 11 Nov 2006 23:15:33 +0000 Subject: [PATCH] win32 cleanups, fixes for 48k flac playing slowly. --- src/ff-plugins.h | 2 + src/os-win32-u.c | 185 --------------------------------- src/os-win32.c | 167 +++++++++++++++++++++++++++++ src/plugins/out-daap-proto.c | 3 + src/plugins/ssc-ffmpeg.c | 28 ++++- src/scan-wma.c | 4 +- src/win32.h | 2 + win32/mt-daapd.vcproj | 3 - win32/out-daap/out-daap.vcproj | 3 - 9 files changed, 200 insertions(+), 197 deletions(-) delete mode 100644 src/os-win32-u.c diff --git a/src/ff-plugins.h b/src/ff-plugins.h index 150d5182..f9988230 100644 --- a/src/ff-plugins.h +++ b/src/ff-plugins.h @@ -22,6 +22,8 @@ #ifndef _FF_PLUGINS_H_ #define _FF_PLUGINS_H_ +#include "ff-dbstruct.h" + /* Plugin types */ #define PLUGIN_OUTPUT 1 #define PLUGIN_SCANNER 2 diff --git a/src/os-win32-u.c b/src/os-win32-u.c deleted file mode 100644 index 66cb7cca..00000000 --- a/src/os-win32-u.c +++ /dev/null @@ -1,185 +0,0 @@ -/** - * Win32 os functions that require unicode - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include - -#include -#include - -#include "daapd.h" -#include "win32.h" -#include "err.h" -#include "os-win32.h" -#include "util.h" - -/* opendir/closedir/readdir emulation taken from emacs. Thanks. :) */ -DIR *os_opendir(char *filename) { - DIR *dirp; - - /* Opening is done by FindFirstFile. However, a read is inherent to - this operation, so we defer the open until read time. */ - - if (!(dirp = (DIR *) malloc (sizeof (DIR)))) - return NULL; - - dirp->dir_find_handle = INVALID_HANDLE_VALUE; - dirp->dd_fd = 0; - dirp->dd_loc = 0; - dirp->dd_size = 0; - - strncpy (dirp->dir_pathname, filename,PATH_MAX); - dirp->dir_pathname[PATH_MAX] = '\0'; - - return dirp; -} - -void os_closedir(DIR *dirp) { - /* If we have a find-handle open, close it. */ - if (dirp->dir_find_handle != INVALID_HANDLE_VALUE) { - FindClose(dirp->dir_find_handle); - } - free((char *) dirp); -} - - -int os_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { - char filename[PATH_MAX + 1]; - WCHAR utf16[PATH_MAX + 1]; - int ln; - - if (dirp->dir_find_handle == INVALID_HANDLE_VALUE) { - /* If we aren't dir_finding, do a find-first, otherwise do a find-next. */ - strncpy (filename, dirp->dir_pathname,PATH_MAX - 3); - ln = (int) strlen (filename) - 1; - if(filename[ln] != '\\') - strcat (filename, "\\"); - strcat (filename, "*"); - - /* filename is utf-8... let's convert to unicode */ - util_utf8toutf16((unsigned char *)&utf16,sizeof(utf16),filename,(int)strlen(filename)); - - dirp->dir_find_handle = FindFirstFileW(utf16, &dirp->dir_find_data); - - if (dirp->dir_find_handle == INVALID_HANDLE_VALUE) { - *result=NULL; - return 2; - } - } else { - if (!FindNextFileW(dirp->dir_find_handle, &dirp->dir_find_data)) { - *result = NULL; - return 0; - } - } - - /* Emacs never uses this value, so don't bother making it match - value returned by stat(). */ - entry->d_ino = 1; - - memset(entry->d_name,0,MAXNAMLEN+1); - util_utf16toutf8(entry->d_name,MAXNAMLEN+1, - (unsigned char *)&dirp->dir_find_data.cFileName, - (int)wcslen(dirp->dir_find_data.cFileName)*2); - entry->d_namlen = (int) strlen (entry->d_name); - - entry->d_reclen = sizeof (struct dirent) - MAXNAMLEN + 3 + - entry->d_namlen - entry->d_namlen % 4; - - entry->d_type = 0; - if(dirp->dir_find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - entry->d_type |= DT_DIR; - } else if(dirp->dir_find_data.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) { - entry->d_type |= DT_REG; - } - - /* - if (dir_is_fat) - _strlwr (dir_static.d_name); - else if (!NILP (Vw32_downcase_file_names)) { - register char *p; - for (p = dir_static.d_name; *p; p++) - if (*p >= 'a' && *p <= 'z') - break; - if (!*p) - _strlwr (dir_static.d_name); - } - */ - *result = entry; - return 0; -} - -/** - * this is now pretty close to a true realpath implementation - */ -char *os_realpath(const char *pathname, char *resolved_path) { - char *ptr; - WCHAR utf16_rel_path[PATH_MAX+1]; - WCHAR utf16_path[PATH_MAX+1]; - - /* need to take the utf-8 and convert to utf-16, then _fullpath, then back */ - util_utf8toutf16((unsigned char *)&utf16_rel_path,PATH_MAX * sizeof(WCHAR),(char*)pathname,(int)strlen(pathname)); - if(!_wfullpath(utf16_path,utf16_rel_path,PATH_MAX)) { - DPRINTF(E_FATAL,L_MISC,"Could not realpath %s\n",pathname); - } - util_utf16toutf8((unsigned char *)resolved_path,PATH_MAX,(unsigned char *)&utf16_path, - util_utf16_byte_len((unsigned char *)utf16_path)); - - ptr = resolved_path; - while(*ptr) { -// *ptr = tolower(*ptr); - if(*ptr == '/') - *ptr = '\\'; - ptr++; - } - - while(resolved_path[strlen(resolved_path)-1] == '\\') { - resolved_path[strlen(resolved_path)-1] = '\x0'; - } - - return &resolved_path[0]; -} - -int os_lstat(const char *path, struct _stat *sb) { - return os_stat(path,sb); -} - -int os_stat(const char *path, struct _stat *sb) { - WCHAR utf16_path[PATH_MAX+1]; - - memset(utf16_path,0,sizeof(utf16_path)); - util_utf8toutf16((unsigned char *)&utf16_path,PATH_MAX * 2,(char*)path,(int)strlen(path)); - - return _wstat(utf16_path,sb); -} - -/* FIXME: mode */ -int os_open(const char *filename, int oflag) { - WCHAR utf16_path[PATH_MAX+1]; - int fd; - - memset(utf16_path,0,sizeof(utf16_path)); - util_utf8toutf16((unsigned char *)&utf16_path,PATH_MAX * 2,(char*)filename,(int)strlen(filename)); - - fd = _wopen(utf16_path, oflag | O_BINARY); - return fd; -} - -FILE *os_fopen(const char *filename, const char *mode) { - WCHAR utf16_path[PATH_MAX+1]; - WCHAR utf16_mode[10]; - - memset(utf16_path,0,sizeof(utf16_path)); - memset(utf16_mode,0,sizeof(utf16_mode)); - util_utf8toutf16((unsigned char *)&utf16_path,PATH_MAX * 2,(char*)filename,(int)strlen(filename)); - util_utf8toutf16((unsigned char *)&utf16_mode,10 * 2,(char*)mode,(int)strlen(mode)); - return _wfopen((wchar_t *)&utf16_path, (wchar_t *)&utf16_mode); -} - - diff --git a/src/os-win32.c b/src/os-win32.c index 41e5401e..62b70bd7 100644 --- a/src/os-win32.c +++ b/src/os-win32.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include "daapd.h" #include "win32.h" @@ -638,4 +640,169 @@ int os_unload(void *handle) { return TRUE; } +// Unicody stuff + +/* opendir/closedir/readdir emulation taken from emacs. Thanks. :) */ +DIR *os_opendir(char *filename) { + DIR *dirp; + + /* Opening is done by FindFirstFile. However, a read is inherent to + this operation, so we defer the open until read time. */ + + if (!(dirp = (DIR *) malloc (sizeof (DIR)))) + return NULL; + + dirp->dir_find_handle = INVALID_HANDLE_VALUE; + dirp->dd_fd = 0; + dirp->dd_loc = 0; + dirp->dd_size = 0; + + strncpy (dirp->dir_pathname, filename,PATH_MAX); + dirp->dir_pathname[PATH_MAX] = '\0'; + + return dirp; +} + +void os_closedir(DIR *dirp) { + /* If we have a find-handle open, close it. */ + if (dirp->dir_find_handle != INVALID_HANDLE_VALUE) { + FindClose(dirp->dir_find_handle); + } + free((char *) dirp); +} + + +int os_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { + char filename[PATH_MAX + 1]; + WCHAR utf16[PATH_MAX + 1]; + int ln; + + if (dirp->dir_find_handle == INVALID_HANDLE_VALUE) { + /* If we aren't dir_finding, do a find-first, otherwise do a find-next. */ + strncpy (filename, dirp->dir_pathname,PATH_MAX - 3); + ln = (int) strlen (filename) - 1; + if(filename[ln] != '\\') + strcat (filename, "\\"); + strcat (filename, "*"); + + /* filename is utf-8... let's convert to unicode */ + util_utf8toutf16((unsigned char *)&utf16,sizeof(utf16),filename,(int)strlen(filename)); + + dirp->dir_find_handle = FindFirstFileW(utf16, &dirp->dir_find_data); + + if (dirp->dir_find_handle == INVALID_HANDLE_VALUE) { + *result=NULL; + return 2; + } + } else { + if (!FindNextFileW(dirp->dir_find_handle, &dirp->dir_find_data)) { + *result = NULL; + return 0; + } + } + + /* Emacs never uses this value, so don't bother making it match + value returned by stat(). */ + entry->d_ino = 1; + + memset(entry->d_name,0,MAXNAMLEN+1); + util_utf16toutf8(entry->d_name,MAXNAMLEN+1, + (unsigned char *)&dirp->dir_find_data.cFileName, + (int)wcslen(dirp->dir_find_data.cFileName)*2); + entry->d_namlen = (int) strlen (entry->d_name); + + entry->d_reclen = sizeof (struct dirent) - MAXNAMLEN + 3 + + entry->d_namlen - entry->d_namlen % 4; + + entry->d_type = 0; + if(dirp->dir_find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + entry->d_type |= DT_DIR; + } else if(dirp->dir_find_data.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) { + entry->d_type |= DT_REG; + } + + /* + if (dir_is_fat) + _strlwr (dir_static.d_name); + else if (!NILP (Vw32_downcase_file_names)) { + register char *p; + for (p = dir_static.d_name; *p; p++) + if (*p >= 'a' && *p <= 'z') + break; + if (!*p) + _strlwr (dir_static.d_name); + } + */ + *result = entry; + return 0; +} + +/** + * this is now pretty close to a true realpath implementation + */ +char *os_realpath(const char *pathname, char *resolved_path) { + char *ptr; + WCHAR utf16_rel_path[PATH_MAX+1]; + WCHAR utf16_path[PATH_MAX+1]; + + /* need to take the utf-8 and convert to utf-16, then _fullpath, then back */ + util_utf8toutf16((unsigned char *)&utf16_rel_path,PATH_MAX * sizeof(WCHAR),(char*)pathname,(int)strlen(pathname)); + if(!_wfullpath(utf16_path,utf16_rel_path,PATH_MAX)) { + DPRINTF(E_FATAL,L_MISC,"Could not realpath %s\n",pathname); + } + util_utf16toutf8((unsigned char *)resolved_path,PATH_MAX,(unsigned char *)&utf16_path, + util_utf16_byte_len((unsigned char *)utf16_path)); + + ptr = resolved_path; + while(*ptr) { +// *ptr = tolower(*ptr); + if(*ptr == '/') + *ptr = '\\'; + ptr++; + } + + while(resolved_path[strlen(resolved_path)-1] == '\\') { + resolved_path[strlen(resolved_path)-1] = '\x0'; + } + + return &resolved_path[0]; +} + + +int os_stat(const char *path, struct _stat *sb) { + WCHAR utf16_path[PATH_MAX+1]; + + memset(utf16_path,0,sizeof(utf16_path)); + util_utf8toutf16((unsigned char *)&utf16_path,PATH_MAX * 2,(char*)path,(int)strlen(path)); + + return _wstat(utf16_path,sb); +} + +int os_lstat(const char *path, struct _stat *sb) { + return os_stat(path,sb); +} +/* FIXME: mode */ +int os_open(const char *filename, int oflag) { + WCHAR utf16_path[PATH_MAX+1]; + int fd; + + memset(utf16_path,0,sizeof(utf16_path)); + util_utf8toutf16((unsigned char *)&utf16_path,PATH_MAX * 2,(char*)filename,(int)strlen(filename)); + + fd = _wopen(utf16_path, oflag | O_BINARY); + return fd; +} + +FILE *os_fopen(const char *filename, const char *mode) { + WCHAR utf16_path[PATH_MAX+1]; + WCHAR utf16_mode[10]; + + memset(utf16_path,0,sizeof(utf16_path)); + memset(utf16_mode,0,sizeof(utf16_mode)); + util_utf8toutf16((unsigned char *)&utf16_path,PATH_MAX * 2,(char*)filename,(int)strlen(filename)); + util_utf8toutf16((unsigned char *)&utf16_mode,10 * 2,(char*)mode,(int)strlen(mode)); + return _wfopen((wchar_t *)&utf16_path, (wchar_t *)&utf16_mode); +} + + diff --git a/src/plugins/out-daap-proto.c b/src/plugins/out-daap-proto.c index a2053293..e1327d7b 100644 --- a/src/plugins/out-daap-proto.c +++ b/src/plugins/out-daap-proto.c @@ -2,6 +2,9 @@ * $Id: $ */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include #include diff --git a/src/plugins/ssc-ffmpeg.c b/src/plugins/ssc-ffmpeg.c index 84f4d8ef..76b2f8f8 100644 --- a/src/plugins/ssc-ffmpeg.c +++ b/src/plugins/ssc-ffmpeg.c @@ -69,6 +69,12 @@ typedef struct tag_ssc_handle { char *error; int raw; + + int channels; + int sample_rate; + int bits_per_sample; + uint32_t samples; + FILE *fin; char file_buffer[256]; char *file_buffer_ptr; @@ -196,6 +202,15 @@ int ssc_ffmpeg_open(void *vp, MP3FILE *pmp3) { } if(handle->raw) { + handle->bits_per_sample = 16; + handle->sample_rate = 44100; + + if(pmp3->bits_per_sample) + handle->bits_per_sample = pmp3->bits_per_sample; + handle->channels = 2; + handle->samples = (uint32_t)pmp3->sample_count; + handle->sample_rate = pmp3->samplerate; + _ppi->log(E_DBG,"opening file raw\n"); handle->pCodec = avcodec_find_decoder(id); if(!handle->pCodec) { @@ -451,9 +466,9 @@ int ssc_ffmpeg_read(void *vp, char *buffer, int len) { if(!handle->wav_offset) { /* generate the wav header */ if(handle->raw) { - channels = 2; - sample_rate = 44100; - bits_per_sample = 16; + channels = handle->channels; + sample_rate = handle->sample_rate; + bits_per_sample = handle->bits_per_sample; } else { channels = handle->pCodecCtx->channels; sample_rate = handle->pCodecCtx->sample_rate; @@ -477,7 +492,12 @@ int ssc_ffmpeg_read(void *vp, char *buffer, int len) { if(handle->duration) duration = handle->duration; - data_len = ((bits_per_sample * sample_rate * channels / 8) * (duration/1000)); + if(handle->samples) { + data_len = ((bits_per_sample * channels / 8) * handle->samples); + } else { + data_len = ((bits_per_sample * sample_rate * channels / 8) * (duration/1000)); + } + byte_rate = sample_rate * channels * bits_per_sample / 8; block_align = channels * bits_per_sample / 8; diff --git a/src/scan-wma.c b/src/scan-wma.c index 654b0cba..02ed8d37 100644 --- a/src/scan-wma.c +++ b/src/scan-wma.c @@ -391,8 +391,8 @@ int wma_parse_header_extension(int fd, int size, MP3FILE *pmp3) { if(sh.size <= sizeof(sh)) return TRUE; /* guess we're done! */ - bytes_left -= sh.size; - lseek(fd,current + sh.size,SEEK_SET); + bytes_left -= (long)sh.size; + lseek(fd,current + (long)sh.size,SEEK_SET); } return TRUE; diff --git a/src/win32.h b/src/win32.h index 2c5fe04b..ce23add0 100644 --- a/src/win32.h +++ b/src/win32.h @@ -56,6 +56,8 @@ typedef UINT16 uint16_t; typedef INT16 int16_t; typedef UINT32 uint32_t; typedef INT32 int32_t; +typedef UINT64 uint64_t; +typedef INT64 int64_t; /* Funtion fixups */ diff --git a/win32/mt-daapd.vcproj b/win32/mt-daapd.vcproj index 9a478e35..5112a1a1 100644 --- a/win32/mt-daapd.vcproj +++ b/win32/mt-daapd.vcproj @@ -165,9 +165,6 @@ - - diff --git a/win32/out-daap/out-daap.vcproj b/win32/out-daap/out-daap.vcproj index 70783324..a45d73ab 100644 --- a/win32/out-daap/out-daap.vcproj +++ b/win32/out-daap/out-daap.vcproj @@ -120,9 +120,6 @@ - -