mirror of
https://github.com/nu774/fdkaac.git
synced 2025-06-05 23:29:14 +02:00
gracefully shutdown on signals
This commit is contained in:
@ -32,7 +32,7 @@ AC_CHECK_TYPES([ptrdiff_t])
|
|||||||
|
|
||||||
AC_SYS_LARGEFILE
|
AC_SYS_LARGEFILE
|
||||||
AC_FUNC_FSEEKO
|
AC_FUNC_FSEEKO
|
||||||
AC_CHECK_FUNCS([gettimeofday nl_langinfo strdup _vscprintf])
|
AC_CHECK_FUNCS([sigaction gettimeofday nl_langinfo strdup _vscprintf])
|
||||||
AC_CHECK_FUNC(getopt_long)
|
AC_CHECK_FUNC(getopt_long)
|
||||||
AM_CONDITIONAL([FDK_NO_GETOPT_LONG],[test "$ac_cv_func_getopt_long" != "yes"])
|
AM_CONDITIONAL([FDK_NO_GETOPT_LONG],[test "$ac_cv_func_getopt_long" != "yes"])
|
||||||
AC_SEARCH_LIBS([aacEncOpen],[fdk-aac],[],[],[])
|
AC_SEARCH_LIBS([aacEncOpen],[fdk-aac],[],[],[])
|
||||||
|
44
src/main.c
44
src/main.c
@ -24,8 +24,13 @@
|
|||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if HAVE_SIGACTION
|
||||||
|
#include <signal.h>
|
||||||
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "wav_reader.h"
|
#include "wav_reader.h"
|
||||||
@ -36,6 +41,40 @@
|
|||||||
|
|
||||||
#define PROGNAME "fdkaac"
|
#define PROGNAME "fdkaac"
|
||||||
|
|
||||||
|
static volatile g_interrupted = 0;
|
||||||
|
|
||||||
|
#if HAVE_SIGACTION
|
||||||
|
static void signal_handler(int signum)
|
||||||
|
{
|
||||||
|
g_interrupted = 1;
|
||||||
|
}
|
||||||
|
static void handle_signals(void)
|
||||||
|
{
|
||||||
|
int i, sigs[] = { SIGINT, SIGHUP, SIGTERM };
|
||||||
|
for (i = 0; i < sizeof(sigs)/sizeof(sigs[0]); ++i) {
|
||||||
|
struct sigaction sa = { 0 };
|
||||||
|
sa.sa_handler = signal_handler;
|
||||||
|
sa.sa_flags |= SA_RESTART;
|
||||||
|
sigaction(sigs[i], &sa, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
static BOOL WINAPI signal_handler(DWORD type)
|
||||||
|
{
|
||||||
|
g_interrupted = 1;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_signals(void)
|
||||||
|
{
|
||||||
|
SetConsoleCtrlHandler(signal_handler, TRUE);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static void handle_signals(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static
|
static
|
||||||
int read_callback(void *cookie, void *data, uint32_t size)
|
int read_callback(void *cookie, void *data, uint32_t size)
|
||||||
{
|
{
|
||||||
@ -462,7 +501,9 @@ int encode(wav_reader_t *wavf, HANDLE_AACENCODER encoder,
|
|||||||
ibuf = malloc(frame_length * format->bytes_per_frame);
|
ibuf = malloc(frame_length * format->bytes_per_frame);
|
||||||
aacenc_progress_init(&progress, wav_get_length(wavf), format->sample_rate);
|
aacenc_progress_init(&progress, wav_get_length(wavf), format->sample_rate);
|
||||||
do {
|
do {
|
||||||
if (nread) {
|
if (g_interrupted)
|
||||||
|
nread = 0;
|
||||||
|
else if (nread) {
|
||||||
if ((nread = wav_read_frames(wavf, ibuf, frame_length)) < 0) {
|
if ((nread = wav_read_frames(wavf, ibuf, frame_length)) < 0) {
|
||||||
fprintf(stderr, "ERROR: read failed\n");
|
fprintf(stderr, "ERROR: read failed\n");
|
||||||
goto END;
|
goto END;
|
||||||
@ -821,6 +862,7 @@ int main(int argc, char **argv)
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
handle_signals();
|
||||||
if (!params.transport_format) {
|
if (!params.transport_format) {
|
||||||
uint32_t scale;
|
uint32_t scale;
|
||||||
unsigned framelen = aacinfo.frameLength;
|
unsigned framelen = aacinfo.frameLength;
|
||||||
|
Reference in New Issue
Block a user