mpg123-1.31.3

This commit is contained in:
Ozkan Sezer
2023-03-21 14:40:24 +03:00
parent ca2c1da3f4
commit 89d671ef14
20 changed files with 136 additions and 84 deletions

View File

@@ -171,14 +171,15 @@ void print_stat(mpg123_handle *fr, long offset, out123_handle *ao, int draw_bar
static int old_term_width = -1;
size_t buffered;
off_t decoded;
off_t elapsed;
off_t remain;
off_t length;
double elapsed;
double remain;
double length;
off_t frame;
off_t frames;
off_t rframes;
int spf;
double basevol, realvol;
long inrate;
long rate;
int framesize;
struct mpg123_frameinfo mi;
@@ -186,7 +187,7 @@ void print_stat(mpg123_handle *fr, long offset, out123_handle *ao, int draw_bar
char *line = NULL;
#ifndef __OS2__
#ifndef WIN32
#ifndef _WIN32
#ifndef GENERIC
/* Only generate new stat line when stderr is ready... don't overfill... */
{
@@ -204,11 +205,13 @@ void print_stat(mpg123_handle *fr, long offset, out123_handle *ao, int draw_bar
#endif
#endif
#endif
if(mpg123_getformat(fr, &inrate, NULL, NULL))
return;
if(out123_getformat(ao, &rate, NULL, NULL, &framesize))
return;
buffered = out123_buffered(ao)/framesize;
decoded = mpg123_tell(fr);
length = mpg123_length(fr);
length = (double)mpg123_length(fr)/inrate;
frame = mpg123_tellframe(fr);
frames = mpg123_framelength(fr);
spf = mpg123_spf(fr);
@@ -222,7 +225,7 @@ void print_stat(mpg123_handle *fr, long offset, out123_handle *ao, int draw_bar
Buffering makes the relationships between the numbers non-trivial. */
rframes = frames-frame;
// May be negative, a countdown. Buffer only confuses in paused (looping) mode, though.
elapsed = decoded + offset*spf - (paused ? 0 : buffered);
elapsed = (double)(decoded + offset*spf)/inrate - (double)(paused ? 0 : buffered)/rate;
remain = elapsed > 0 ? length - elapsed : length;
if( MPG123_OK == mpg123_info(fr, &mi)
&& MPG123_OK == mpg123_getvolume(fr, &basevol, &realvol, NULL) )
@@ -263,8 +266,8 @@ void print_stat(mpg123_handle *fr, long offset, out123_handle *ao, int draw_bar
? malloc(linelen+1) /* Only malloc if it is a really long line. */
: linebuf; /* Small buffer on stack is enough. */
tim[0] = (double)elapsed/rate;
tim[1] = (double)remain/rate;
tim[0] = elapsed;
tim[1] = remain;
tim[2] = (double)buffered/rate;
for(ti=0; ti<3; ++ti)
{

View File

@@ -179,6 +179,10 @@ void compat_binmode(int fd, int enable)
it late to some official APIs, that's still fine with us.
*/
#ifdef WANT_WIN32_UNICODE
typedef HRESULT (__stdcall *PCA_ptr)( const wchar_t *, const wchar_t*, unsigned long, wchar_t **);
#endif
char* compat_catpath(const char *prefix, const char* path)
{
char *ret = NULL;
@@ -193,8 +197,7 @@ char* compat_catpath(const char *prefix, const char* path)
ThOr: I presume this hack is for supporting pre-8 Windows, as
from Windows 8 on, this is documented in the API.
*/
HRESULT (__stdcall *mypac)( const wchar_t *in, const wchar_t* more
, unsigned long flags, wchar_t **out ) = NULL;
PCA_ptr mypac = NULL;
HMODULE pathcch = NULL;
if(!prefix && !path)
@@ -207,7 +210,7 @@ char* compat_catpath(const char *prefix, const char* path)
/* Again: I presume this whole fun is to get at PathAllocCombine
even when pathcch.h is not available (like in MinGW32). */
if( (pathcch = GetModuleHandleA("kernelbase")) )
mypac = (void *)GetProcAddress(pathcch, "PathAllocCombine");
mypac = (PCA_ptr) GetProcAddress(pathcch, "PathAllocCombine");
if(mypac) /* PATHCCH_ALLOW_LONG_PATH = 1 per API docs */
{
debug("Actually calling PathAllocCombine!");

View File

@@ -12,6 +12,8 @@
#include "config.h"
/* This source file does need _POSIX_SOURCE to get some sigaction. */
#define _POSIX_SOURCE
/* Fix pedantic error about w2upath being unused */
#define HIDE_w2upath
#include "compat.h"
#ifdef _MSC_VER
@@ -87,7 +89,7 @@ void *compat_dlsym(void *handle, const char *name)
if(!handle)
return NULL;
#ifdef WANT_WIN32_UNICODE
sym = GetProcAddress(handle, name);
sym = (void *)(uintptr_t)GetProcAddress(handle, name);
#else
sym = dlsym(handle, name);
#endif

View File

@@ -26,6 +26,7 @@ static wchar_t* u2wpath(const char *upath)
return wpath;
}
#ifndef HIDE_w2upath
/* Convert Windows wide character paths to unix UTF-8. */
static char* w2upath(const wchar_t *wpath)
{
@@ -37,6 +38,7 @@ static char* w2upath(const wchar_t *wpath)
*p = '/';
return upath;
}
#endif
/* An absolute path that is too long and not already marked with
\\?\ can be marked as a long one and still work. */

View File

@@ -26,7 +26,7 @@
#include "out123.h"
#include <stdarg.h>
#include <ctype.h>
#if !defined (WIN32) || defined (__CYGWIN__)
#if !defined (_WIN32) || defined (__CYGWIN__)
#include <sys/wait.h>
#include <sys/socket.h>
#endif
@@ -397,7 +397,7 @@ int control_generic (mpg123_handle *fr)
outstream = stdout;
out_is_term = stdout_is_term;
}
#ifndef WIN32
#ifndef _WIN32
setlinebuf(outstream);
#else /* perhaps just use setvbuf as it's C89 */
/*

View File

@@ -499,7 +499,10 @@ static unsigned char pretab_choice[2][22] =
static int III_dequantize_sample(mpg123_handle *fr, real xr[SBLIMIT][SSLIMIT],int *scf, struct gr_info_s *gr_info,int sfreq,int part2bits)
{
int shift = 1 + gr_info->scalefac_scale;
real *xrpnt = (real *) xr;
// Pointer cast to make pedantic compilers happy.
real *xrpnt = (real*)xr;
// Some compiler freaks out over &xr[SBLIMIT][0], which is the same.
real *xrpntlimit = (real*)xr+SBLIMIT*SSLIMIT;
int l[3],l3;
int part2remain = gr_info->part2_3_length - part2bits;
const short *me;
@@ -552,10 +555,10 @@ static int III_dequantize_sample(mpg123_handle *fr, real xr[SBLIMIT][SSLIMIT],in
}
}
#define CHECK_XRPNT if(xrpnt >= &xr[SBLIMIT][0]) \
#define CHECK_XRPNT if(xrpnt >= xrpntlimit) \
{ \
if(NOQUIET) \
error2("attempted xrpnt overflow (%p !< %p)", (void*) xrpnt, (void*) &xr[SBLIMIT][0]); \
error2("attempted xrpnt overflow (%p !< %p)", (void*) xrpnt, (void*) xrpntlimit); \
return 1; \
}
@@ -992,7 +995,7 @@ static int III_dequantize_sample(mpg123_handle *fr, real xr[SBLIMIT][SSLIMIT],in
gr_info->maxb = 1;
}
while(xrpnt < &xr[SBLIMIT][0])
while(xrpnt < xrpntlimit)
*xrpnt++ = DOUBLE_TO_REAL(0.0);
while( part2remain > 16 )

View File

@@ -169,11 +169,10 @@ static void wait_for_buffer(WAVEHDR* hdr, HANDLE hEvent)
static int get_formats_win32(out123_handle *ao)
{
WAVEOUTCAPSA caps;
MMRESULT mr;
int ret = 0;
UINT dev_id = dev_select(ao);
mr = waveOutGetDevCaps(dev_id, &caps, sizeof(caps));
MMRESULT mr = waveOutGetDevCaps(dev_id, &caps, sizeof(caps));
if(mr != MMSYSERR_NOERROR)
return 0; /* no formats? */
@@ -369,6 +368,21 @@ static int enumerate_win32( out123_handle *ao, int (*store_device)(void *devlist
memset(id, 0, sizeof(id));
memset(&caps, 0, sizeof(caps));
mr = waveOutGetDevCaps(i, &caps, sizeof(caps));
if (mr != MMSYSERR_NOERROR) {
switch(mr) {
case MMSYSERR_BADDEVICEID:
error("enumerate_win32: Specified device identifier is out of range.");
break;
case MMSYSERR_NODRIVER:
error("enumerate_win32: No device driver is present.");
break;
case MMSYSERR_NOMEM:
error("enumerate_win32: Unable to allocate or lock memory.");
break;
default:
merror("enumerate_win32: Uknown error 0x%x.", mr);
}
}
mdebug("waveOutGetDevCaps mr %x", mr);
snprintf(id, sizeof(id) - 1, "%u", i);
store_device(devlist, id, caps.szPname);

View File

@@ -518,7 +518,6 @@ static int close_win32(out123_handle *ao)
static int enumerate_win32( out123_handle *ao, int (*store_device)(void *devlist
, const char *name, const char *description), void *devlist )
{
int len;
char *pszID = NULL, *pszDesc = NULL;
HRESULT hr = S_OK;
UINT pcDevices = 0, i = 0;
@@ -614,6 +613,7 @@ static int init_win32(out123_handle* ao){
ao->close = close_win32;
ao->userptr = NULL;
ao->enumerate = enumerate_win32;
ao->deinit = deinit_win32;
/* Success */
return 0;

View File

@@ -2377,24 +2377,31 @@ syn123_setup_resample( syn123_handle *sh, long inrate, long outrate
}
rd->stage_history = sth;
}
struct decimator_state *nd = safe_realloc( rd->decim
, sizeof(*rd->decim)*decim_stages );
struct lpf4_hist *ndh = safe_realloc( rd->decim_hist
, sizeof(*rd->decim_hist)*decim_stages*channels );
if(nd)
rd->decim = nd;
if(ndh)
rd->decim_hist = ndh;
if(!nd || !ndh)
if(decim_stages)
{
perror("cannot allocate decimator state");
err = SYN123_DOOM;
goto setup_resample_cleanup;
struct decimator_state *nd = safe_realloc( rd->decim
, sizeof(*rd->decim)*decim_stages );
struct lpf4_hist *ndh = safe_realloc( rd->decim_hist
, sizeof(*rd->decim_hist)*decim_stages*channels );
if(nd)
rd->decim = nd;
if(ndh)
rd->decim_hist = ndh;
if(!nd || !ndh)
{
perror("cannot allocate decimator state");
err = SYN123_DOOM;
goto setup_resample_cleanup;
}
} else
{
free(rd->decim); rd->decim = NULL;
free(rd->decim_hist); rd->decim_hist = NULL;
}
// Link up the common memory blocks after each realloc.
for(unsigned int dc=0; dc<decim_stages; ++dc)
{
rd->decim[dc].ch = ndh+dc*channels;
rd->decim[dc].ch = rd->decim_hist+dc*channels;
rd->decim[dc].out_hist = rd->stage_history
? rd->stage_history+(dc+1)*STAGE_HISTORY*channels
: NULL;

View File

@@ -18,7 +18,7 @@
/* import DLL symbols on windows */
#include "httpget.h"
#if WIN32
#if _WIN32
#include "win32_support.h"
#endif

View File

@@ -53,6 +53,7 @@ static DWORD wrap_auth(winhttp_handle *nh){
ret = WinHttpSetCredentials(nh->request, WINHTTP_AUTH_TARGET_SERVER, mode, nh->comps.lpszUserName, nh->comps.lpszPassword, NULL);
return GetLastError();
}
return TRUE;
}
#if DEBUG
@@ -95,6 +96,7 @@ net123_handle *net123_open_winhttp(const char *url, const char * const *client_h
DWORD headerlen;
const LPCWSTR useragent = MPG123WSTR(PACKAGE_NAME) L"/" MPG123WSTR(PACKAGE_VERSION);
WINHTTP_STATUS_CALLBACK cb;
net123_handle *handle = NULL;
if(!WinHttpCheckPlatform())
return NULL;
@@ -105,7 +107,7 @@ net123_handle *net123_open_winhttp(const char *url, const char * const *client_h
winhttp_handle *ret = calloc(1, sizeof(winhttp_handle));
if (!ret) goto cleanup;
net123_handle *handle = calloc(1, sizeof(net123_handle));
handle = calloc(1, sizeof(net123_handle));
if (!handle) {
free(ret);
goto cleanup;
@@ -178,7 +180,7 @@ net123_handle *net123_open_winhttp(const char *url, const char * const *client_h
if (!res) {
res = GetLastError();
error1("WinHttpSendRequest failed with %lu", res);
error1("WinHttpSendRequest failed with %d", res);
if(res == ERROR_WINHTTP_SECURE_FAILURE){
res = *(DWORD *)ret->additionalInfo;
error("Additionally, the ERROR_WINHTTP_SECURE_FAILURE failed with:");
@@ -221,8 +223,10 @@ net123_handle *net123_open_winhttp(const char *url, const char * const *client_h
cleanup:
debug("net123_open error");
if (urlW) free(urlW);
net123_close(handle);
handle = NULL;
if (handle) {
net123_close(handle);
handle = NULL;
}
return handle;
}

View File

@@ -73,13 +73,14 @@ net123_handle *net123_open_wininet(const char *url, const char * const *client_h
size_t ii;
WINBOOL res;
DWORD headerlen;
net123_handle *ret = NULL;
const LPCWSTR useragent = MPG123WSTR(PACKAGE_NAME) L"/" MPG123WSTR(PACKAGE_VERSION);
INTERNET_STATUS_CALLBACK cb;
win32_utf8_wide(url, &urlW, NULL);
if(urlW == NULL) goto cleanup;
net123_handle *ret = calloc(1, sizeof(net123_handle));
ret = calloc(1, sizeof(net123_handle));
wininet_handle *wh = calloc(1, sizeof(wininet_handle));
if(!ret || !wh)
{
@@ -158,7 +159,7 @@ net123_handle *net123_open_wininet(const char *url, const char * const *client_h
if (!res) {
res = GetLastError();
error1("HttpSendRequestW failed with %lu", res);
error1("HttpSendRequestW failed with %d", res);
goto cleanup;
}
debug("HttpSendRequestW OK");
@@ -196,8 +197,10 @@ net123_handle *net123_open_wininet(const char *url, const char * const *client_h
cleanup:
debug("net123_open error");
if (urlW) free(urlW);
net123_close(ret);
ret = NULL;
if(ret) {
net123_close(ret);
ret = NULL;
}
return ret;
}
@@ -219,7 +222,7 @@ static size_t net123_read(net123_handle *nh, void *buf, size_t bufsize){
/* is this needed? */
to_copy = bufsize > ULONG_MAX ? ULONG_MAX : bufsize;
if(!InternetReadFile(wh->request, buf, to_copy, &bytesread)){
error1("InternetReadFile exited with %d", GetLastError());
error1("InternetReadFile exited with %ld", GetLastError());
return EOF;
}
return bytesread;

View File

@@ -30,10 +30,10 @@
#include "config.h"
#include "compat.h"
#include <ctype.h>
#if WIN32
#if _WIN32
#include "win32_support.h"
#endif
#if defined(WIN32) && defined(DYNAMIC_BUILD)
#if defined(_WIN32) && defined(DYNAMIC_BUILD)
#define LINK_MPG123_DLL
#endif
#include "out123.h"
@@ -108,7 +108,9 @@ static int realtime = FALSE;
#ifdef HAVE_WINDOWS_H
static int w32_priority = 0;
#endif
#ifdef HAVE_SETPRIORITY
static int aggressive = FALSE;
#endif
static double preload = 0.2;
static long outflags = 0;
double preamp = 0.;

View File

@@ -29,7 +29,7 @@
static HANDLE consoleintput = INVALID_HANDLE_VALUE;
static HANDLE consoleoutput = INVALID_HANDLE_VALUE;
static HANDLE getconsoleintput(void){
DWORD mode, r;
DWORD mode;
if(consoleintput == INVALID_HANDLE_VALUE){
consoleintput = CreateFileW(L"CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if(consoleintput == INVALID_HANDLE_VALUE || consoleintput == NULL)
@@ -55,7 +55,6 @@ int term_have_fun(int fd, int want_visuals)
return 0;
}
static DWORD lastmode;
int term_setup(void)
{
return 0;

View File

@@ -99,6 +99,7 @@ ssize_t win32_net_read (int fildes, void *buf, size_t nbyte)
return ret;
}
/*
static int get_sock_ch (int sock)
{
char c;
@@ -108,6 +109,7 @@ static int get_sock_ch (int sock)
return (((int) c)&0xff);
return -1;
}
*/
ssize_t win32_net_write (int fildes, const void *buf, size_t nbyte)
{