1
0
Fork 0

Optimized file I/O for chained usage with libavformat

This commit is contained in:
Hendrik Leppkes 2011-03-17 17:22:00 +01:00
parent c65c945277
commit 8862ab84bc
8 changed files with 43 additions and 10 deletions

View File

@ -13,6 +13,7 @@ EXPORTS
bd_close
bd_seek
bd_seek_time
bd_find_seek_point
bd_read
bd_read_skip_still
bd_seek_chapter

View File

@ -76,7 +76,7 @@ static dir_data_t *_open_impl(const char *dirname)
{
dir_data_t *priv;
char *filespec;
wchar_t wfilespec[MAX_PATH];
wchar_t wfilespec[4096 + 1];
int result;
filespec = str_printf("%s" DIR_SEP "*", dirname);
@ -84,7 +84,7 @@ static dir_data_t *_open_impl(const char *dirname)
return NULL;
}
result = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filespec, -1, wfilespec, MAX_PATH);
result = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filespec, -1, wfilespec, 4096);
X_FREE(filespec);
if (!result) {
return NULL;

View File

@ -36,7 +36,7 @@
char *win32_get_font_dir(const char *font_file)
{
wchar_t wdir[MAX_PATH];
wchar_t wdir[MAX_PATH+1] = {0};
if (S_OK != SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, wdir)) {
int lenght = GetWindowsDirectoryW(wdir, MAX_PATH);
if (lenght == 0 || lenght > (MAX_PATH - 8)) {
@ -67,7 +67,7 @@ char *file_get_config_home(void)
char *file_get_data_home(void)
{
wchar_t wdir[MAX_PATH];
wchar_t wdir[MAX_PATH+1] = {0};
/* Get the "Application Data" folder for the user */
if (S_OK == SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
@ -92,7 +92,7 @@ char *file_get_cache_home(void)
const char *file_get_config_system(const char *dir)
{
static char *appdir = NULL;
wchar_t wdir[MAX_PATH];
wchar_t wdir[MAX_PATH+1] = {0};
if (!dir) {
// first call

View File

@ -57,7 +57,7 @@ void *dl_dlopen(const char *path, const char *version)
{
(void)version;
wchar_t wname[MAX_PATH];
wchar_t wname[MAX_PATH+1] = {0};
char *name;
void *result;
int iresult;
@ -125,7 +125,7 @@ const char *dl_get_path(void)
if (!initialized) {
initialized = 1;
static char path[MAX_PATH];
static char path[MAX_PATH + 1];
HMODULE hModule;
wchar_t wpath[MAX_PATH];

View File

@ -107,9 +107,9 @@ static BD_FILE_H *_file_open(const char* filename, const char *mode)
{
BD_FILE_H *file;
FILE *fp;
wchar_t wfilename[MAX_PATH], wmode[8];
wchar_t wfilename[4096 + 1] = {0}, wmode[8] = {0};
if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename, -1, wfilename, MAX_PATH) ||
if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename, -1, wfilename, 4096) ||
!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mode, -1, wmode, 8)) {
BD_DEBUG(DBG_FILE, "Error opening file %s\n", filename);
@ -122,6 +122,9 @@ static BD_FILE_H *_file_open(const char* filename, const char *mode)
return NULL;
}
// Set file buffer
setvbuf(fp, NULL, _IOFBF, 6144 * 10);
file = calloc(1, sizeof(BD_FILE_H));
if (!file) {
BD_DEBUG(DBG_FILE | DBG_CRIT, "Error opening file %s (out of memory)\n", filename);

View File

@ -1684,6 +1684,25 @@ int64_t bd_seek_time(BLURAY *bd, uint64_t tick)
return bd->s_pos;
}
int64_t bd_find_seek_point(BLURAY *bd, uint64_t tick)
{
uint32_t clip_pkt, out_pkt;
NAV_CLIP *clip;
tick /= 2;
if (bd->title &&
tick < bd->title->duration) {
// Find the closest access unit to the requested position
clip = nav_time_search(bd->title, (uint32_t)tick, &clip_pkt, &out_pkt);
return (int64_t)out_pkt * 192;
}
return bd->s_pos;
}
uint64_t bd_tell_time(BLURAY *bd)
{
uint32_t clip_pkt = 0, out_pkt = 0, out_time = 0;

View File

@ -482,6 +482,16 @@ int bd_select_playlist(BLURAY *bd, uint32_t playlist);
*/
uint32_t bd_get_current_title(BLURAY *bd);
/**
*
* Find the byte position to specific time in 90Khz ticks
*
* @param bd BLURAY ojbect
* @param tick tick count
* @return byte position
*/
int64_t bd_find_seek_point(BLURAY *bd, uint64_t tick);
/**
*
* Read from currently selected title file, decrypt if possible

View File

@ -75,7 +75,7 @@ static BD_FILE_H *_bdrom_open_path(void *p, const char *rel_path)
return NULL;
}
fp = file_open(abs_path, "rb");
fp = file_open(abs_path, "rbS");
X_FREE(abs_path);
return fp;