Add option to not use file I/O in libFLAC.

This commit is contained in:
2021-11-12 07:57:00 +00:00
parent 7d55296b5b
commit a01948c29a
5 changed files with 32 additions and 1 deletions

View File

@@ -49,6 +49,9 @@
#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
#include <sys/types.h> /* for off_t */ #include <sys/types.h> /* for off_t */
#define FLAC__off_t __int64 /* use this instead of off_t to fix the 2 GB limit */ #define FLAC__off_t __int64 /* use this instead of off_t to fix the 2 GB limit */
#ifndef FLAC__NO_FILEIO
#if !defined __MINGW32__ #if !defined __MINGW32__
#define fseeko _fseeki64 #define fseeko _fseeki64
#define ftello _ftelli64 #define ftello _ftelli64
@@ -58,6 +61,9 @@
#define ftello ftello64 #define ftello ftello64
#endif #endif
#endif #endif
#endif // FLAC__NO_FILEIO
#else #else
#define FLAC__off_t off_t #define FLAC__off_t off_t
#endif #endif
@@ -148,6 +154,8 @@
#define flac_fprintf fprintf_utf8 #define flac_fprintf fprintf_utf8
#define flac_vfprintf vfprintf_utf8 #define flac_vfprintf vfprintf_utf8
#ifndef FLAC__NO_FILEIO
#include "share/windows_unicode_filenames.h" #include "share/windows_unicode_filenames.h"
#define flac_fopen flac_internal_fopen_utf8 #define flac_fopen flac_internal_fopen_utf8
#define flac_chmod flac_internal_chmod_utf8 #define flac_chmod flac_internal_chmod_utf8
@@ -156,17 +164,21 @@
#define flac_rename flac_internal_rename_utf8 #define flac_rename flac_internal_rename_utf8
#define flac_stat flac_internal_stat64_utf8 #define flac_stat flac_internal_stat64_utf8
#endif
#else #else
#define flac_printf printf #define flac_printf printf
#define flac_fprintf fprintf #define flac_fprintf fprintf
#define flac_vfprintf vfprintf #define flac_vfprintf vfprintf
#ifndef FLAC__NO_FILEIO
#define flac_fopen fopen #define flac_fopen fopen
#define flac_chmod chmod #define flac_chmod chmod
#define flac_unlink unlink #define flac_unlink unlink
#define flac_rename rename #define flac_rename rename
#define flac_stat stat #define flac_stat stat
#endif
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
#define flac_utime(a, b) utimensat (AT_FDCWD, a, *b, 0) #define flac_utime(a, b) utimensat (AT_FDCWD, a, *b, 0)
@@ -175,6 +187,7 @@
#endif #endif
#endif #endif
#ifndef FLAC__NO_FILEIO
#ifdef _WIN32 #ifdef _WIN32
#define flac_stat_s __stat64 /* stat struct */ #define flac_stat_s __stat64 /* stat struct */
#define flac_fstat _fstat64 #define flac_fstat _fstat64
@@ -182,6 +195,7 @@
#define flac_stat_s stat /* stat struct */ #define flac_stat_s stat /* stat struct */
#define flac_fstat fstat #define flac_fstat fstat
#endif #endif
#endif
#ifdef ANDROID #ifdef ANDROID
#include <limits.h> #include <limits.h>

View File

@@ -50,8 +50,10 @@ int printf_utf8(const char *format, ...);
int fprintf_utf8(FILE *stream, const char *format, ...); int fprintf_utf8(FILE *stream, const char *format, ...);
int vfprintf_utf8(FILE *stream, const char *format, va_list argptr); int vfprintf_utf8(FILE *stream, const char *format, va_list argptr);
#ifndef FLAC__NO_FILEIO
#include <windows.h> #include <windows.h>
HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@@ -34,6 +34,8 @@
# include <config.h> # include <config.h>
#endif #endif
#ifndef FLAC__NO_FILEIO
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -3485,3 +3487,5 @@ FLAC__Metadata_ChainStatus get_equivalent_status_(FLAC__Metadata_SimpleIteratorS
return FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; return FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
} }
} }
#endif // FLAC__NO_FILEIO

View File

@@ -106,11 +106,13 @@ static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__u
#if FLAC__HAS_OGG #if FLAC__HAS_OGG
static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample); static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
#endif #endif
#ifndef FLAC__NO_FILEIO
static FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); static FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
static FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); static FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); static FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data); static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
#endif
/*********************************************************************** /***********************************************************************
* *
@@ -500,6 +502,8 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
); );
} }
#ifndef FLAC__NO_FILEIO
static FLAC__StreamDecoderInitStatus init_FILE_internal_( static FLAC__StreamDecoderInitStatus init_FILE_internal_(
FLAC__StreamDecoder *decoder, FLAC__StreamDecoder *decoder,
FILE *file, FILE *file,
@@ -625,6 +629,8 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true); return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
} }
#endif
FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder) FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
{ {
FLAC__bool md5_failed = false; FLAC__bool md5_failed = false;
@@ -3345,7 +3351,6 @@ FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint
return true; return true;
} }
#endif
FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
{ {
@@ -3413,6 +3418,8 @@ FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_d
return feof(decoder->private_->file)? true : false; return feof(decoder->private_->file)? true : false;
} }
#endif // FLAC__NO_FILEIO
FLAC_API const void *FLAC__get_decoder_client_data(FLAC__StreamDecoder *decoder) FLAC_API const void *FLAC__get_decoder_client_data(FLAC__StreamDecoder *decoder)
{ {
return decoder->private_->client_data; return decoder->private_->client_data;

View File

@@ -1415,6 +1415,8 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
return init_FILE_internal_(encoder, file, progress_callback, client_data, /*is_ogg=*/true); return init_FILE_internal_(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
} }
#ifndef FLAC__NO_FILEIO
static FLAC__StreamEncoderInitStatus init_file_internal_( static FLAC__StreamEncoderInitStatus init_file_internal_(
FLAC__StreamEncoder *encoder, FLAC__StreamEncoder *encoder,
const char *filename, const char *filename,
@@ -1465,6 +1467,8 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/true); return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
} }
#endif // FLAC__NO_FILEIO
FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder) FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
{ {
FLAC__bool error = false; FLAC__bool error = false;