win32 cleanups, fixes for 48k flac playing slowly.

This commit is contained in:
Ron Pedde 2006-11-11 23:15:33 +00:00
parent fbbe214f26
commit c1ac15cd97
9 changed files with 200 additions and 197 deletions

View File

@ -22,6 +22,8 @@
#ifndef _FF_PLUGINS_H_ #ifndef _FF_PLUGINS_H_
#define _FF_PLUGINS_H_ #define _FF_PLUGINS_H_
#include "ff-dbstruct.h"
/* Plugin types */ /* Plugin types */
#define PLUGIN_OUTPUT 1 #define PLUGIN_OUTPUT 1
#define PLUGIN_SCANNER 2 #define PLUGIN_SCANNER 2

View File

@ -1,185 +0,0 @@
/**
* Win32 os functions that require unicode
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#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);
}

View File

@ -10,6 +10,8 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <pthread.h> #include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "daapd.h" #include "daapd.h"
#include "win32.h" #include "win32.h"
@ -638,4 +640,169 @@ int os_unload(void *handle) {
return TRUE; 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);
}

View File

@ -2,6 +2,9 @@
* $Id: $ * $Id: $
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>

View File

@ -69,6 +69,12 @@ typedef struct tag_ssc_handle {
char *error; char *error;
int raw; int raw;
int channels;
int sample_rate;
int bits_per_sample;
uint32_t samples;
FILE *fin; FILE *fin;
char file_buffer[256]; char file_buffer[256];
char *file_buffer_ptr; char *file_buffer_ptr;
@ -196,6 +202,15 @@ int ssc_ffmpeg_open(void *vp, MP3FILE *pmp3) {
} }
if(handle->raw) { 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"); _ppi->log(E_DBG,"opening file raw\n");
handle->pCodec = avcodec_find_decoder(id); handle->pCodec = avcodec_find_decoder(id);
if(!handle->pCodec) { if(!handle->pCodec) {
@ -451,9 +466,9 @@ int ssc_ffmpeg_read(void *vp, char *buffer, int len) {
if(!handle->wav_offset) { if(!handle->wav_offset) {
/* generate the wav header */ /* generate the wav header */
if(handle->raw) { if(handle->raw) {
channels = 2; channels = handle->channels;
sample_rate = 44100; sample_rate = handle->sample_rate;
bits_per_sample = 16; bits_per_sample = handle->bits_per_sample;
} else { } else {
channels = handle->pCodecCtx->channels; channels = handle->pCodecCtx->channels;
sample_rate = handle->pCodecCtx->sample_rate; sample_rate = handle->pCodecCtx->sample_rate;
@ -477,7 +492,12 @@ int ssc_ffmpeg_read(void *vp, char *buffer, int len) {
if(handle->duration) if(handle->duration)
duration = handle->duration; duration = handle->duration;
if(handle->samples) {
data_len = ((bits_per_sample * channels / 8) * handle->samples);
} else {
data_len = ((bits_per_sample * sample_rate * channels / 8) * (duration/1000)); data_len = ((bits_per_sample * sample_rate * channels / 8) * (duration/1000));
}
byte_rate = sample_rate * channels * bits_per_sample / 8; byte_rate = sample_rate * channels * bits_per_sample / 8;
block_align = channels * bits_per_sample / 8; block_align = channels * bits_per_sample / 8;

View File

@ -391,8 +391,8 @@ int wma_parse_header_extension(int fd, int size, MP3FILE *pmp3) {
if(sh.size <= sizeof(sh)) if(sh.size <= sizeof(sh))
return TRUE; /* guess we're done! */ return TRUE; /* guess we're done! */
bytes_left -= sh.size; bytes_left -= (long)sh.size;
lseek(fd,current + sh.size,SEEK_SET); lseek(fd,current + (long)sh.size,SEEK_SET);
} }
return TRUE; return TRUE;

View File

@ -56,6 +56,8 @@ typedef UINT16 uint16_t;
typedef INT16 int16_t; typedef INT16 int16_t;
typedef UINT32 uint32_t; typedef UINT32 uint32_t;
typedef INT32 int32_t; typedef INT32 int32_t;
typedef UINT64 uint64_t;
typedef INT64 int64_t;
/* Funtion fixups */ /* Funtion fixups */

View File

@ -165,9 +165,6 @@
<File <File
RelativePath="..\src\mp3-scanner.c"> RelativePath="..\src\mp3-scanner.c">
</File> </File>
<File
RelativePath="..\src\os-win32-u.c">
</File>
<File <File
RelativePath="..\src\os-win32.c"> RelativePath="..\src\os-win32.c">
</File> </File>

View File

@ -120,9 +120,6 @@
<File <File
RelativePath="..\..\src\plugins\compat.c"> RelativePath="..\..\src\plugins\compat.c">
</File> </File>
<File
RelativePath="..\..\src\plugins\out-daap-db.c">
</File>
<File <File
RelativePath="..\..\src\plugins\out-daap-proto.c"> RelativePath="..\..\src\plugins\out-daap-proto.c">
</File> </File>