mirror of
https://github.com/nu774/fdkaac.git
synced 2025-06-05 23:29:14 +02:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
5af13f7d79 | |||
5c534696a9 | |||
33e12bc4f5 | |||
bfb6aa3cb8 | |||
360cf7dc8b | |||
43ab433178 | |||
47c164c85a | |||
d52b8bbf13 | |||
f67cfe227e | |||
e476728e77 | |||
dac71de305 | |||
61b6a9e383 | |||
5888fddccf | |||
c5c459082a | |||
00799c5e44 | |||
6887939854 | |||
6854317606 | |||
8960a17764 |
@ -32,7 +32,7 @@ AC_CHECK_TYPES([ptrdiff_t])
|
||||
|
||||
AC_SYS_LARGEFILE
|
||||
AC_FUNC_FSEEKO
|
||||
AC_CHECK_FUNCS([gettimeofday nl_langinfo strdup])
|
||||
AC_CHECK_FUNCS([gettimeofday nl_langinfo strdup _vscprintf])
|
||||
AC_CHECK_FUNC(getopt_long)
|
||||
AM_CONDITIONAL([FDK_NO_GETOPT_LONG],[test "$ac_cv_func_getopt_long" != "yes"])
|
||||
AC_SEARCH_LIBS([aacEncOpen],[fdk-aac],[],[],[])
|
||||
|
@ -142,7 +142,7 @@ int aac_encode_frame(HANDLE_AACENCODER encoder,
|
||||
unsigned channel_mode, obytes;
|
||||
|
||||
channel_mode = aacEncoder_GetParam(encoder, AACENC_CHANNELMODE);
|
||||
obytes = 6144 / 8 * channel_mode;
|
||||
obytes = 6144 / 8 * channel_mode + 7;
|
||||
if (!*output || *osize < obytes) {
|
||||
*osize = obytes;
|
||||
*output = realloc(*output, obytes);
|
||||
|
@ -20,5 +20,6 @@ FILE *aacenc_fopen(const char *name, const char *mode);
|
||||
void aacenc_getmainargs(int *argc, char ***argv);
|
||||
char *aacenc_to_utf8(const char *s);
|
||||
int aacenc_fprintf(FILE *fp, const char *fmt, ...);
|
||||
const char *aacenc_basename(const char *path);
|
||||
|
||||
#endif
|
||||
|
@ -48,6 +48,16 @@ int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/*
|
||||
* Different from POSIX basename() when path ends with /.
|
||||
* Since we use this only for a regular file, the difference doesn't matter.
|
||||
*/
|
||||
const char *aacenc_basename(const char *path)
|
||||
{
|
||||
const char *p = strrchr(path, '/');
|
||||
return p ? p + 1: path;
|
||||
}
|
||||
|
||||
#ifndef HAVE_ICONV
|
||||
char *aacenc_to_utf8(const char *s)
|
||||
{
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/timeb.h>
|
||||
@ -74,6 +75,17 @@ FILE *aacenc_fopen(const char *name, const char *mode)
|
||||
return fp;
|
||||
}
|
||||
|
||||
static char **__aacenc_argv__;
|
||||
|
||||
static
|
||||
void aacenc_free_mainargs(void)
|
||||
{
|
||||
char **p = __aacenc_argv__;
|
||||
for (; *p; ++p)
|
||||
free(*p);
|
||||
free(__aacenc_argv__);
|
||||
}
|
||||
|
||||
void aacenc_getmainargs(int *argc, char ***argv)
|
||||
{
|
||||
int i;
|
||||
@ -85,6 +97,8 @@ void aacenc_getmainargs(int *argc, char ***argv)
|
||||
for (i = 0; i < *argc; ++i)
|
||||
codepage_encode_wchar(CP_UTF8, wargv[i], &(*argv)[i]);
|
||||
(*argv)[*argc] = 0;
|
||||
__aacenc_argv__ = *argv;
|
||||
atexit(aacenc_free_mainargs);
|
||||
}
|
||||
|
||||
char *aacenc_to_utf8(const char *s)
|
||||
@ -92,6 +106,20 @@ char *aacenc_to_utf8(const char *s)
|
||||
return _strdup(s);
|
||||
}
|
||||
|
||||
#if defined(__MINGW32__) && !defined(HAVE__VSCPRINTF)
|
||||
int _vscprintf(const char *fmt, va_list ap)
|
||||
{
|
||||
static int (*fp_vscprintf)(const char *, va_list) = 0;
|
||||
if (!fp_vscprintf) {
|
||||
HANDLE h = GetModuleHandleA("msvcrt.dll");
|
||||
FARPROC fp = GetProcAddress(h, "_vscprintf");
|
||||
InterlockedCompareExchangePointer(&fp_vscprintf, fp, 0);
|
||||
}
|
||||
assert(fp_vscprintf);
|
||||
return fp_vscprintf(fmt, ap);
|
||||
}
|
||||
#endif
|
||||
|
||||
int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@ -126,3 +154,15 @@ int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
||||
return cnt;
|
||||
}
|
||||
|
||||
const char *aacenc_basename(const char *path)
|
||||
{
|
||||
/*
|
||||
* Since path is encoded with UTF-8, naive usage of strrchr() shoule be safe.
|
||||
*/
|
||||
const char *p = strrchr(path, '/');
|
||||
const char *q = strrchr(path, '\\');
|
||||
const char *r = strrchr(path, ':');
|
||||
if (q > p) p = q;
|
||||
if (r > p) p = r;
|
||||
return p ? p + 1 : path;
|
||||
}
|
||||
|
37
src/m4af.c
37
src/m4af.c
@ -456,12 +456,18 @@ int m4af_add_itmf_int16_tag(m4af_writer_t *ctx, uint32_t type, int value)
|
||||
return m4af_add_itmf_short_tag(ctx, type, M4AF_INTEGER, &data, 2);
|
||||
}
|
||||
|
||||
int m4af_add_itmf_int32_tag(m4af_writer_t *ctx, uint32_t type, int value)
|
||||
int m4af_add_itmf_int32_tag(m4af_writer_t *ctx, uint32_t type, uint32_t value)
|
||||
{
|
||||
uint32_t data = m4af_htob32(value);
|
||||
return m4af_add_itmf_short_tag(ctx, type, M4AF_INTEGER, &data, 4);
|
||||
}
|
||||
|
||||
int m4af_add_itmf_int64_tag(m4af_writer_t *ctx, uint32_t type, uint64_t value)
|
||||
{
|
||||
uint64_t data = m4af_htob64(value);
|
||||
return m4af_add_itmf_short_tag(ctx, type, M4AF_INTEGER, &data, 8);
|
||||
}
|
||||
|
||||
int m4af_add_itmf_track_tag(m4af_writer_t *ctx, int track, int total)
|
||||
{
|
||||
uint16_t data[4] = { 0 };
|
||||
@ -509,15 +515,6 @@ void m4af_update_size(m4af_writer_t *ctx, int64_t pos)
|
||||
m4af_set_pos(ctx, current_pos);
|
||||
}
|
||||
|
||||
static
|
||||
int m4af_head_version(m4af_writer_t *ctx, int track_idx)
|
||||
{
|
||||
m4af_track_t *track = &ctx->track[track_idx];
|
||||
return track->duration > UINT32_MAX
|
||||
|| track->creation_time > UINT32_MAX
|
||||
|| track->modification_time > UINT32_MAX;
|
||||
}
|
||||
|
||||
static
|
||||
void m4af_descriptor(m4af_writer_t *ctx, uint32_t tag, uint32_t size)
|
||||
{
|
||||
@ -829,7 +826,9 @@ void m4af_mdhd_box(m4af_writer_t *ctx, int track_idx)
|
||||
{
|
||||
m4af_track_t *track = &ctx->track[track_idx];
|
||||
int64_t pos = m4af_tell(ctx);
|
||||
uint8_t version = m4af_head_version(ctx, track_idx);
|
||||
uint8_t version = (track->creation_time > UINT32_MAX ||
|
||||
track->modification_time > UINT32_MAX ||
|
||||
track->duration > UINT32_MAX);
|
||||
|
||||
m4af_write(ctx, "\0\0\0\0mdhd", 8);
|
||||
m4af_write(ctx, &version, 1);
|
||||
@ -892,7 +891,11 @@ void m4af_tkhd_box(m4af_writer_t *ctx, int track_idx)
|
||||
{
|
||||
m4af_track_t *track = &ctx->track[track_idx];
|
||||
int64_t pos = m4af_tell(ctx);
|
||||
uint8_t version = m4af_head_version(ctx, track_idx);
|
||||
int64_t duration =
|
||||
(double)track->duration / track->timescale * ctx->timescale + .5;
|
||||
uint8_t version = (track->creation_time > UINT32_MAX ||
|
||||
track->modification_time > UINT32_MAX ||
|
||||
duration > UINT32_MAX);
|
||||
m4af_write(ctx, "\0\0\0\0tkhd", 8);
|
||||
m4af_write(ctx, &version, 1);
|
||||
m4af_write(ctx, "\0\0\007", 3); /* flags */
|
||||
@ -902,14 +905,14 @@ void m4af_tkhd_box(m4af_writer_t *ctx, int track_idx)
|
||||
m4af_write32(ctx, track_idx + 1);
|
||||
m4af_write(ctx, "\0\0\0\0" /* reserved */
|
||||
, 4);
|
||||
m4af_write64(ctx, track->duration);
|
||||
m4af_write64(ctx, duration);
|
||||
} else {
|
||||
m4af_write32(ctx, track->creation_time);
|
||||
m4af_write32(ctx, track->modification_time);
|
||||
m4af_write32(ctx, track_idx + 1);
|
||||
m4af_write(ctx, "\0\0\0\0" /* reserved */
|
||||
, 4);
|
||||
m4af_write32(ctx, track->duration);
|
||||
m4af_write32(ctx, duration);
|
||||
}
|
||||
m4af_write(ctx,
|
||||
"\0\0\0\0" /* reserved[0] */
|
||||
@ -950,7 +953,7 @@ int64_t m4af_movie_duration(m4af_writer_t *ctx)
|
||||
unsigned i;
|
||||
for (i = 0; i < ctx->num_tracks; ++i) {
|
||||
double x = ctx->track[i].duration;
|
||||
int64_t duration = x * ctx->track[i].timescale / ctx->timescale + .5;
|
||||
int64_t duration = x / ctx->track[i].timescale * ctx->timescale + .5;
|
||||
if (duration > movie_duration)
|
||||
movie_duration = duration;
|
||||
}
|
||||
@ -961,8 +964,10 @@ static
|
||||
void m4af_mvhd_box(m4af_writer_t *ctx)
|
||||
{
|
||||
int64_t pos = m4af_tell(ctx);
|
||||
uint8_t version = m4af_head_version(ctx, 0);
|
||||
int64_t movie_duration = m4af_movie_duration(ctx);
|
||||
uint8_t version = (ctx->creation_time > UINT32_MAX ||
|
||||
ctx->modification_time > UINT32_MAX ||
|
||||
movie_duration > UINT32_MAX);
|
||||
|
||||
m4af_write(ctx, "\0\0\0\0mvhd", 8);
|
||||
m4af_write(ctx, &version, 1);
|
||||
|
@ -103,7 +103,9 @@ int m4af_add_itmf_int8_tag(m4af_writer_t *ctx, uint32_t type, int value);
|
||||
|
||||
int m4af_add_itmf_int16_tag(m4af_writer_t *ctx, uint32_t type, int value);
|
||||
|
||||
int m4af_add_itmf_int32_tag(m4af_writer_t *ctx, uint32_t type, int value);
|
||||
int m4af_add_itmf_int32_tag(m4af_writer_t *ctx, uint32_t type, uint32_t value);
|
||||
|
||||
int m4af_add_itmf_int64_tag(m4af_writer_t *ctx, uint32_t type, uint64_t value);
|
||||
|
||||
int m4af_add_itmf_track_tag(m4af_writer_t *ctx, int track, int total);
|
||||
|
||||
|
451
src/main.c
451
src/main.c
@ -8,9 +8,15 @@
|
||||
#if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#if HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#elif defined(_MSC_VER)
|
||||
# define SCNd64 "I64d"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
@ -97,12 +103,26 @@ PROGNAME " %s\n"
|
||||
" 6: LATM MCP=1\n"
|
||||
" 7: LATM MCP=0\n"
|
||||
" 10: LOAS/LATM (LATM within LOAS)\n"
|
||||
" -c, --adts-crc-check Add CRC protection on ADTS header\n"
|
||||
" -C, --adts-crc-check Add CRC protection on ADTS header\n"
|
||||
" -h, --header-period <n> StreamMuxConfig/PCE repetition period in\n"
|
||||
" transport layer\n"
|
||||
"\n"
|
||||
" -o <filename> Output filename\n"
|
||||
" --ignore-length Ignore length of WAV header\n"
|
||||
" --ignorelength Ignore length of WAV header\n"
|
||||
"\n"
|
||||
"Options for raw (headerless) input:\n"
|
||||
" -R, --raw Treat input as raw (by default WAV is\n"
|
||||
" assumed)\n"
|
||||
" --raw-channels <n> Number of channels (default: 2)\n"
|
||||
" --raw-rate <n> Sample rate (default: 44100)\n"
|
||||
" --raw-format <spec> Sample format, default is \"S16L\".\n"
|
||||
" Spec is as follows:\n"
|
||||
" 1st char: S(igned)|U(nsigned)|F(loat)\n"
|
||||
" 2nd part: bits per channel\n"
|
||||
" Last char: L(ittle)|B(ig)\n"
|
||||
" Last char can be omitted, in which case L is\n"
|
||||
" assumed. Spec is case insensitive, therefore\n"
|
||||
" \"u16b\" is same as \"U16B\".\n"
|
||||
"\n"
|
||||
"Tagging options:\n"
|
||||
" --title <string>\n"
|
||||
@ -117,12 +137,16 @@ PROGNAME " %s\n"
|
||||
" --track <number[/total]>\n"
|
||||
" --disk <number[/total]>\n"
|
||||
" --tempo <n>\n"
|
||||
" --tag <fcc>:<value> Set iTunes predefined tag with four char code.\n"
|
||||
" --long-tag <name>:<value> Set arbitrary tag as iTunes custom metadata.\n"
|
||||
, fdkaac_version);
|
||||
}
|
||||
|
||||
typedef struct aacenc_tag_entry_t {
|
||||
uint32_t tag;
|
||||
const char *name;
|
||||
const char *data;
|
||||
uint32_t data_size;
|
||||
} aacenc_tag_entry_t;
|
||||
|
||||
typedef struct aacenc_param_ex_t {
|
||||
@ -132,17 +156,48 @@ typedef struct aacenc_param_ex_t {
|
||||
char *output_filename;
|
||||
unsigned ignore_length;
|
||||
|
||||
int is_raw;
|
||||
unsigned raw_channels;
|
||||
unsigned raw_rate;
|
||||
const char *raw_format;
|
||||
|
||||
aacenc_tag_entry_t *tag_table;
|
||||
unsigned tag_count;
|
||||
unsigned tag_table_capacity;
|
||||
} aacenc_param_ex_t;
|
||||
|
||||
static
|
||||
void param_add_itmf_entry(aacenc_param_ex_t *params, uint32_t tag,
|
||||
const char *key, const char *value, uint32_t size)
|
||||
{
|
||||
aacenc_tag_entry_t *entry;
|
||||
if (params->tag_count == params->tag_table_capacity) {
|
||||
unsigned newsize = params->tag_table_capacity;
|
||||
newsize = newsize ? newsize * 2 : 1;
|
||||
params->tag_table =
|
||||
realloc(params->tag_table, newsize * sizeof(aacenc_tag_entry_t));
|
||||
params->tag_table_capacity = newsize;
|
||||
}
|
||||
entry = params->tag_table + params->tag_count;
|
||||
entry->tag = tag;
|
||||
if (tag == M4AF_FOURCC('-','-','-','-'))
|
||||
entry->name = key;
|
||||
entry->data = value;
|
||||
entry->data_size = size;
|
||||
params->tag_count++;
|
||||
}
|
||||
|
||||
static
|
||||
int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
||||
{
|
||||
int ch;
|
||||
unsigned n;
|
||||
aacenc_tag_entry_t *tag;
|
||||
|
||||
#define OPT_RAW_CHANNELS M4AF_FOURCC('r','c','h','n')
|
||||
#define OPT_RAW_RATE M4AF_FOURCC('r','r','a','t')
|
||||
#define OPT_RAW_FORMAT M4AF_FOURCC('r','f','m','t')
|
||||
#define OPT_SHORT_TAG M4AF_FOURCC('s','t','a','g')
|
||||
#define OPT_LONG_TAG M4AF_FOURCC('l','t','a','g')
|
||||
|
||||
static struct option long_options[] = {
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
@ -154,28 +209,36 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
||||
{ "lowdelay-sbr", no_argument, 0, 'L' },
|
||||
{ "sbr-signaling", required_argument, 0, 's' },
|
||||
{ "transport-format", required_argument, 0, 'f' },
|
||||
{ "adts-crc-check", no_argument, 0, 'c' },
|
||||
{ "adts-crc-check", no_argument, 0, 'C' },
|
||||
{ "header-period", required_argument, 0, 'P' },
|
||||
|
||||
{ "ignore-length", no_argument, 0, 'I' },
|
||||
{ "ignorelength", no_argument, 0, 'I' },
|
||||
|
||||
{ "title", required_argument, 0, M4AF_TAG_TITLE },
|
||||
{ "artist", required_argument, 0, M4AF_TAG_ARTIST },
|
||||
{ "album", required_argument, 0, M4AF_TAG_ALBUM },
|
||||
{ "genre", required_argument, 0, M4AF_TAG_GENRE },
|
||||
{ "date", required_argument, 0, M4AF_TAG_DATE },
|
||||
{ "composer", required_argument, 0, M4AF_TAG_COMPOSER },
|
||||
{ "grouping", required_argument, 0, M4AF_TAG_GROUPING },
|
||||
{ "comment", required_argument, 0, M4AF_TAG_COMMENT },
|
||||
{ "album-artist", required_argument, 0, M4AF_TAG_ALBUM_ARTIST },
|
||||
{ "track", required_argument, 0, M4AF_TAG_TRACK },
|
||||
{ "disk", required_argument, 0, M4AF_TAG_DISK },
|
||||
{ "tempo", required_argument, 0, M4AF_TAG_TEMPO },
|
||||
{ "raw", no_argument, 0, 'R' },
|
||||
{ "raw-channels", required_argument, 0, OPT_RAW_CHANNELS },
|
||||
{ "raw-rate", required_argument, 0, OPT_RAW_RATE },
|
||||
{ "raw-format", required_argument, 0, OPT_RAW_FORMAT },
|
||||
|
||||
{ "title", required_argument, 0, M4AF_TAG_TITLE },
|
||||
{ "artist", required_argument, 0, M4AF_TAG_ARTIST },
|
||||
{ "album", required_argument, 0, M4AF_TAG_ALBUM },
|
||||
{ "genre", required_argument, 0, M4AF_TAG_GENRE },
|
||||
{ "date", required_argument, 0, M4AF_TAG_DATE },
|
||||
{ "composer", required_argument, 0, M4AF_TAG_COMPOSER },
|
||||
{ "grouping", required_argument, 0, M4AF_TAG_GROUPING },
|
||||
{ "comment", required_argument, 0, M4AF_TAG_COMMENT },
|
||||
{ "album-artist", required_argument, 0, M4AF_TAG_ALBUM_ARTIST },
|
||||
{ "track", required_argument, 0, M4AF_TAG_TRACK },
|
||||
{ "disk", required_argument, 0, M4AF_TAG_DISK },
|
||||
{ "tempo", required_argument, 0, M4AF_TAG_TEMPO },
|
||||
{ "tag", required_argument, 0, OPT_SHORT_TAG },
|
||||
{ "long-tag", required_argument, 0, OPT_LONG_TAG },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
params->afterburner = 1;
|
||||
|
||||
aacenc_getmainargs(&argc, &argv);
|
||||
while ((ch = getopt_long(argc, argv, "hp:b:m:w:a:Ls:f:cP:Io:",
|
||||
while ((ch = getopt_long(argc, argv, "hp:b:m:w:a:Ls:f:CP:Io:R",
|
||||
long_options, 0)) != EOF) {
|
||||
switch (ch) {
|
||||
case 'h':
|
||||
@ -248,6 +311,26 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
||||
case 'I':
|
||||
params->ignore_length = 1;
|
||||
break;
|
||||
case 'R':
|
||||
params->is_raw = 1;
|
||||
break;
|
||||
case OPT_RAW_CHANNELS:
|
||||
if (sscanf(optarg, "%u", &n) != 1) {
|
||||
fprintf(stderr, "invalid arg for raw-channels\n");
|
||||
return -1;
|
||||
}
|
||||
params->raw_channels = n;
|
||||
break;
|
||||
case OPT_RAW_RATE:
|
||||
if (sscanf(optarg, "%u", &n) != 1) {
|
||||
fprintf(stderr, "invalid arg for raw-rate\n");
|
||||
return -1;
|
||||
}
|
||||
params->raw_rate = n;
|
||||
break;
|
||||
case OPT_RAW_FORMAT:
|
||||
params->raw_format = optarg;
|
||||
break;
|
||||
case M4AF_TAG_TITLE:
|
||||
case M4AF_TAG_ARTIST:
|
||||
case M4AF_TAG_ALBUM:
|
||||
@ -260,18 +343,40 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
||||
case M4AF_TAG_TRACK:
|
||||
case M4AF_TAG_DISK:
|
||||
case M4AF_TAG_TEMPO:
|
||||
if (params->tag_count == params->tag_table_capacity) {
|
||||
unsigned newsize = params->tag_table_capacity;
|
||||
newsize = newsize ? newsize * 2 : 1;
|
||||
params->tag_table =
|
||||
realloc(params->tag_table,
|
||||
newsize * sizeof(aacenc_tag_entry_t));
|
||||
params->tag_table_capacity = newsize;
|
||||
param_add_itmf_entry(params, ch, 0, optarg, strlen(optarg));
|
||||
break;
|
||||
case OPT_SHORT_TAG:
|
||||
case OPT_LONG_TAG:
|
||||
{
|
||||
char *val;
|
||||
size_t klen;
|
||||
unsigned fcc = M4AF_FOURCC('-','-','-','-');
|
||||
|
||||
if ((val = strchr(optarg, ':')) == 0) {
|
||||
fprintf(stderr, "invalid arg for tag\n");
|
||||
return -1;
|
||||
}
|
||||
*val++ = '\0';
|
||||
if (ch == OPT_SHORT_TAG) {
|
||||
/*
|
||||
* take care of U+00A9(COPYRIGHT SIGN).
|
||||
* 1) if length of fcc is 3, we prepend '\xa9'.
|
||||
* 2) U+00A9 becomes "\xc2\xa9" in UTF-8. Therefore
|
||||
* we remove first '\xc2'.
|
||||
*/
|
||||
if (optarg[0] == '\xc2')
|
||||
++optarg;
|
||||
if ((klen = strlen(optarg))== 3)
|
||||
fcc = 0xa9;
|
||||
else if (klen != 4) {
|
||||
fprintf(stderr, "invalid arg for tag\n");
|
||||
return -1;
|
||||
}
|
||||
for (; *optarg; ++optarg)
|
||||
fcc = ((fcc << 8) | (*optarg & 0xff));
|
||||
}
|
||||
param_add_itmf_entry(params, fcc, optarg, val, strlen(val));
|
||||
}
|
||||
tag = params->tag_table + params->tag_count;
|
||||
tag->tag = ch;
|
||||
tag->data = optarg;
|
||||
params->tag_count++;
|
||||
break;
|
||||
default:
|
||||
return usage(), -1;
|
||||
@ -279,6 +384,7 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
||||
}
|
||||
if (argc == optind)
|
||||
return usage(), -1;
|
||||
|
||||
if (!params->bitrate && !params->bitrate_mode) {
|
||||
fprintf(stderr, "bitrate or bitrate-mode is mandatory\n");
|
||||
return -1;
|
||||
@ -290,6 +396,15 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
||||
}
|
||||
if (params->bitrate && params->bitrate < 10000)
|
||||
params->bitrate *= 1000;
|
||||
|
||||
if (params->is_raw) {
|
||||
if (!params->raw_channels)
|
||||
params->raw_channels = 2;
|
||||
if (!params->raw_rate)
|
||||
params->raw_rate = 44100;
|
||||
if (!params->raw_format)
|
||||
params->raw_format = "S16L";
|
||||
}
|
||||
params->input_filename = argv[optind];
|
||||
return 0;
|
||||
};
|
||||
@ -363,67 +478,159 @@ END:
|
||||
return rc;
|
||||
}
|
||||
|
||||
static
|
||||
void put_tag_entry(m4af_writer_t *m4af, const aacenc_tag_entry_t *tag)
|
||||
{
|
||||
unsigned m, n = 0;
|
||||
|
||||
switch (tag->tag) {
|
||||
case M4AF_TAG_TRACK:
|
||||
if (sscanf(tag->data, "%u/%u", &m, &n) >= 1)
|
||||
m4af_add_itmf_track_tag(m4af, m, n);
|
||||
break;
|
||||
case M4AF_TAG_DISK:
|
||||
if (sscanf(tag->data, "%u/%u", &m, &n) >= 1)
|
||||
m4af_add_itmf_disk_tag(m4af, m, n);
|
||||
break;
|
||||
case M4AF_TAG_GENRE_ID3:
|
||||
if (sscanf(tag->data, "%u", &n) == 1)
|
||||
m4af_add_itmf_genre_tag(m4af, n);
|
||||
break;
|
||||
case M4AF_TAG_TEMPO:
|
||||
if (sscanf(tag->data, "%u", &n) == 1)
|
||||
m4af_add_itmf_int16_tag(m4af, tag->tag, n);
|
||||
break;
|
||||
case M4AF_TAG_COMPILATION:
|
||||
case M4AF_FOURCC('a','k','I','D'):
|
||||
case M4AF_FOURCC('h','d','v','d'):
|
||||
case M4AF_FOURCC('p','c','s','t'):
|
||||
case M4AF_FOURCC('p','g','a','p'):
|
||||
case M4AF_FOURCC('r','t','n','g'):
|
||||
case M4AF_FOURCC('s','t','i','k'):
|
||||
if (sscanf(tag->data, "%u", &n) == 1)
|
||||
m4af_add_itmf_int8_tag(m4af, tag->tag, n);
|
||||
break;
|
||||
case M4AF_FOURCC('a','t','I','D'):
|
||||
case M4AF_FOURCC('c','m','I','D'):
|
||||
case M4AF_FOURCC('c','n','I','D'):
|
||||
case M4AF_FOURCC('g','e','I','D'):
|
||||
case M4AF_FOURCC('s','f','I','D'):
|
||||
case M4AF_FOURCC('t','v','s','n'):
|
||||
case M4AF_FOURCC('t','v','s','s'):
|
||||
if (sscanf(tag->data, "%u", &n) == 1)
|
||||
m4af_add_itmf_int32_tag(m4af, tag->tag, n);
|
||||
break;
|
||||
case M4AF_FOURCC('p','l','I','D'):
|
||||
{
|
||||
int64_t qn;
|
||||
if (sscanf(tag->data, "%" SCNd64, &qn) == 1)
|
||||
m4af_add_itmf_int64_tag(m4af, tag->tag, qn);
|
||||
break;
|
||||
}
|
||||
case M4AF_TAG_ARTWORK:
|
||||
{
|
||||
int data_type = 0;
|
||||
if (!memcmp(tag->data, "GIF", 3))
|
||||
data_type = M4AF_GIF;
|
||||
else if (!memcmp(tag->data, "\xff\xd8\xff", 3))
|
||||
data_type = M4AF_JPEG;
|
||||
else if (!memcmp(tag->data, "\x89PNG", 4))
|
||||
data_type = M4AF_PNG;
|
||||
if (data_type)
|
||||
m4af_add_itmf_short_tag(m4af, tag->tag, data_type,
|
||||
tag->data, tag->data_size);
|
||||
break;
|
||||
}
|
||||
case M4AF_FOURCC('-','-','-','-'):
|
||||
{
|
||||
char *u8 = aacenc_to_utf8(tag->data);
|
||||
m4af_add_itmf_long_tag(m4af, tag->name, u8);
|
||||
free(u8);
|
||||
break;
|
||||
}
|
||||
case M4AF_TAG_TITLE:
|
||||
case M4AF_TAG_ARTIST:
|
||||
case M4AF_TAG_ALBUM:
|
||||
case M4AF_TAG_GENRE:
|
||||
case M4AF_TAG_DATE:
|
||||
case M4AF_TAG_COMPOSER:
|
||||
case M4AF_TAG_GROUPING:
|
||||
case M4AF_TAG_COMMENT:
|
||||
case M4AF_TAG_LYRICS:
|
||||
case M4AF_TAG_TOOL:
|
||||
case M4AF_TAG_ALBUM_ARTIST:
|
||||
case M4AF_TAG_DESCRIPTION:
|
||||
case M4AF_TAG_LONG_DESCRIPTION:
|
||||
case M4AF_TAG_COPYRIGHT:
|
||||
case M4AF_FOURCC('a','p','I','D'):
|
||||
case M4AF_FOURCC('c','a','t','g'):
|
||||
case M4AF_FOURCC('k','e','y','w'):
|
||||
case M4AF_FOURCC('p','u','r','d'):
|
||||
case M4AF_FOURCC('p','u','r','l'):
|
||||
case M4AF_FOURCC('s','o','a','a'):
|
||||
case M4AF_FOURCC('s','o','a','l'):
|
||||
case M4AF_FOURCC('s','o','a','r'):
|
||||
case M4AF_FOURCC('s','o','c','o'):
|
||||
case M4AF_FOURCC('s','o','n','m'):
|
||||
case M4AF_FOURCC('s','o','s','n'):
|
||||
case M4AF_FOURCC('t','v','e','n'):
|
||||
case M4AF_FOURCC('t','v','n','n'):
|
||||
case M4AF_FOURCC('t','v','s','h'):
|
||||
case M4AF_FOURCC('x','i','d',' '):
|
||||
case M4AF_FOURCC('\xa9','e','n','c'):
|
||||
case M4AF_FOURCC('\xa9','s','t','3'):
|
||||
{
|
||||
char *u8 = aacenc_to_utf8(tag->data);
|
||||
m4af_add_itmf_string_tag(m4af, tag->tag, u8);
|
||||
free(u8);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
fprintf(stderr, "WARNING: unknown/unsupported tag: %c%c%c%c\n",
|
||||
tag->tag >> 24, (tag->tag >> 16) & 0xff,
|
||||
(tag->tag >> 8) & 0xff, tag->tag & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void put_tool_tag(m4af_writer_t *m4af, const aacenc_param_ex_t *params,
|
||||
HANDLE_AACENCODER encoder)
|
||||
{
|
||||
char tool_info[256];
|
||||
char *p = tool_info;
|
||||
LIB_INFO *lib_info = 0;
|
||||
|
||||
p += sprintf(p, PROGNAME " %s, ", fdkaac_version);
|
||||
|
||||
lib_info = calloc(FDK_MODULE_LAST, sizeof(LIB_INFO));
|
||||
if (aacEncGetLibInfo(lib_info) == AACENC_OK) {
|
||||
int i;
|
||||
for (i = 0; i < FDK_MODULE_LAST; ++i)
|
||||
if (lib_info[i].module_id == FDK_AACENC)
|
||||
break;
|
||||
p += sprintf(p, "libfdk-aac %s, ", lib_info[i].versionStr);
|
||||
}
|
||||
free(lib_info);
|
||||
if (params->bitrate_mode)
|
||||
sprintf(p, "VBR mode %d", params->bitrate_mode);
|
||||
else
|
||||
sprintf(p, "CBR %dkbps",
|
||||
aacEncoder_GetParam(encoder, AACENC_BITRATE) / 1000);
|
||||
|
||||
m4af_add_itmf_string_tag(m4af, M4AF_TAG_TOOL, tool_info);
|
||||
}
|
||||
|
||||
static
|
||||
int finalize_m4a(m4af_writer_t *m4af, const aacenc_param_ex_t *params,
|
||||
HANDLE_AACENCODER encoder)
|
||||
{
|
||||
unsigned i;
|
||||
aacenc_tag_entry_t *tag = params->tag_table;
|
||||
for (i = 0; i < params->tag_count; ++i, ++tag)
|
||||
put_tag_entry(m4af, tag);
|
||||
|
||||
for (i = 0; i < params->tag_count; ++i, ++tag) {
|
||||
switch (tag->tag) {
|
||||
case M4AF_TAG_TRACK:
|
||||
{
|
||||
unsigned m, n = 0;
|
||||
if (sscanf(tag->data, "%u/%u", &m, &n) >= 1)
|
||||
m4af_add_itmf_track_tag(m4af, m, n);
|
||||
break;
|
||||
}
|
||||
case M4AF_TAG_DISK:
|
||||
{
|
||||
unsigned m, n = 0;
|
||||
if (sscanf(tag->data, "%u/%u", &m, &n) >= 1)
|
||||
m4af_add_itmf_disk_tag(m4af, m, n);
|
||||
break;
|
||||
}
|
||||
case M4AF_TAG_TEMPO:
|
||||
{
|
||||
unsigned n;
|
||||
if (sscanf(tag->data, "%u", &n) == 1)
|
||||
m4af_add_itmf_int16_tag(m4af, tag->tag, n);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
char *u8 = aacenc_to_utf8(tag->data);
|
||||
m4af_add_itmf_string_tag(m4af, tag->tag, u8);
|
||||
free(u8);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
char tool_info[256];
|
||||
char *p = tool_info;
|
||||
LIB_INFO *lib_info = 0;
|
||||
put_tool_tag(m4af, params, encoder);
|
||||
|
||||
p += sprintf(p, PROGNAME " %s, ", fdkaac_version);
|
||||
|
||||
lib_info = calloc(FDK_MODULE_LAST, sizeof(LIB_INFO));
|
||||
if (aacEncGetLibInfo(lib_info) == AACENC_OK) {
|
||||
for (i = 0; i < FDK_MODULE_LAST; ++i)
|
||||
if (lib_info[i].module_id == FDK_AACENC)
|
||||
break;
|
||||
p += sprintf(p, "libfdk-aac %s, ", lib_info[i].versionStr);
|
||||
}
|
||||
free(lib_info);
|
||||
if (params->bitrate_mode)
|
||||
sprintf(p, "VBR mode %d", params->bitrate_mode);
|
||||
else
|
||||
sprintf(p, "CBR %dkbps",
|
||||
aacEncoder_GetParam(encoder, AACENC_BITRATE) / 1000);
|
||||
|
||||
m4af_add_itmf_string_tag(m4af, M4AF_TAG_TOOL, tool_info);
|
||||
}
|
||||
if (m4af_finalize(m4af) < 0) {
|
||||
fprintf(stderr, "ERROR: failed to finalize m4a\n");
|
||||
return -1;
|
||||
@ -431,17 +638,6 @@ int finalize_m4a(m4af_writer_t *m4af, const aacenc_param_ex_t *params,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
const char *basename(const char *filename)
|
||||
{
|
||||
char *p = strrchr(filename, '/');
|
||||
#ifdef _WIN32
|
||||
char *q = strrchr(filename, '\\');
|
||||
if (p < q) p = q;
|
||||
#endif
|
||||
return p ? p + 1 : filename;
|
||||
}
|
||||
|
||||
static
|
||||
char *generate_output_filename(const char *filename, const char *ext)
|
||||
{
|
||||
@ -452,7 +648,7 @@ char *generate_output_filename(const char *filename, const char *ext)
|
||||
p = malloc(ext_len + 6);
|
||||
sprintf(p, "stdin%s", ext);
|
||||
} else {
|
||||
const char *base = basename(filename);
|
||||
const char *base = aacenc_basename(filename);
|
||||
size_t ilen = strlen(base);
|
||||
const char *ext_org = strrchr(base, '.');
|
||||
if (ext_org) ilen = ext_org - base;
|
||||
@ -462,9 +658,45 @@ char *generate_output_filename(const char *filename, const char *ext)
|
||||
return p;
|
||||
}
|
||||
|
||||
static
|
||||
int parse_raw_spec(const char *spec, pcm_sample_description_t *desc)
|
||||
{
|
||||
unsigned bits;
|
||||
unsigned char c_type, c_endian = 'L';
|
||||
int type;
|
||||
|
||||
if (sscanf(spec, "%c%u%c", &c_type, &bits, &c_endian) < 2)
|
||||
return -1;
|
||||
c_type = toupper(c_type);
|
||||
c_endian = toupper(c_endian);
|
||||
|
||||
if (c_type == 'S')
|
||||
type = 1;
|
||||
else if (c_type == 'U')
|
||||
type = 2;
|
||||
else if (c_type == 'F')
|
||||
type = 4;
|
||||
else
|
||||
return -1;
|
||||
|
||||
if (c_endian == 'B')
|
||||
type |= 8;
|
||||
else if (c_endian != 'L')
|
||||
return -1;
|
||||
|
||||
if (c_type == 'F' && bits != 32 && bits != 64)
|
||||
return -1;
|
||||
if (c_type != 'F' && (bits < 8 || bits > 32))
|
||||
return -1;
|
||||
|
||||
desc->sample_type = type;
|
||||
desc->bits_per_channel = bits;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
wav_io_context_t wav_io = { read_callback, seek_callback };
|
||||
wav_io_context_t wav_io = { read_callback, seek_callback, tell_callback };
|
||||
m4af_io_callbacks_t m4af_io = {
|
||||
write_callback, seek_callback, tell_callback };
|
||||
aacenc_param_ex_t params = { 0 };
|
||||
@ -493,13 +725,30 @@ int main(int argc, char **argv)
|
||||
strerror(errno));
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (fstat(fileno(ifp), &stb) == 0 && (stb.st_mode & S_IFMT) != S_IFREG)
|
||||
if (fstat(fileno(ifp), &stb) == 0 && (stb.st_mode & S_IFMT) != S_IFREG) {
|
||||
wav_io.seek = 0;
|
||||
|
||||
if ((wavf = wav_open(&wav_io, ifp, params.ignore_length)) == 0) {
|
||||
fprintf(stderr, "ERROR: broken / unsupported input file\n");
|
||||
goto END;
|
||||
wav_io.tell = 0;
|
||||
}
|
||||
if (!params.is_raw) {
|
||||
if ((wavf = wav_open(&wav_io, ifp, params.ignore_length)) == 0) {
|
||||
fprintf(stderr, "ERROR: broken / unsupported input file\n");
|
||||
goto END;
|
||||
}
|
||||
} else {
|
||||
int bytes_per_channel;
|
||||
pcm_sample_description_t desc = { 0 };
|
||||
if (parse_raw_spec(params.raw_format, &desc) < 0) {
|
||||
fprintf(stderr, "ERROR: invalid raw-format spec\n");
|
||||
goto END;
|
||||
}
|
||||
desc.sample_rate = params.raw_rate;
|
||||
desc.channels_per_frame = params.raw_channels;
|
||||
bytes_per_channel = (desc.bits_per_channel + 7) / 8;
|
||||
desc.bytes_per_frame = params.raw_channels * bytes_per_channel;
|
||||
if ((wavf = raw_open(&wav_io, ifp, &desc)) == 0) {
|
||||
fprintf(stderr, "ERROR: failed to open raw input\n");
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
sample_format = wav_get_format(wavf);
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
#include <time.h>
|
||||
#if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
@ -51,11 +53,14 @@ void aacenc_progress_init(aacenc_progress_t *progress, int64_t total,
|
||||
void aacenc_progress_update(aacenc_progress_t *progress, int64_t current,
|
||||
int period)
|
||||
{
|
||||
int percent = 100.0 * current / progress->total + .5;
|
||||
double seconds = current / progress->timescale;
|
||||
double ellapsed = (aacenc_timer() - progress->start) / 1000.0;
|
||||
double eta = ellapsed * (progress->total / (double)current - 1.0);
|
||||
double speed = ellapsed ? seconds / ellapsed : 0.0;
|
||||
double speed = ellapsed ? seconds / ellapsed : 1.0;
|
||||
int percent = progress->total ? 100.0 * current / progress->total + .5
|
||||
: 100;
|
||||
double eta = current ? ellapsed * (progress->total / (double)current - 1.0)
|
||||
: progress->total ? DBL_MAX : 0;
|
||||
|
||||
if (current < progress->processed + period)
|
||||
return;
|
||||
|
||||
@ -80,7 +85,7 @@ void aacenc_progress_finish(aacenc_progress_t *progress, int64_t current)
|
||||
double ellapsed = (aacenc_timer() - progress->start) / 1000.0;
|
||||
aacenc_progress_update(progress, current, 0);
|
||||
if (progress->total == INT64_MAX)
|
||||
fprintf(stderr, "\n%" PRId64 "samples processed in ", current);
|
||||
fprintf(stderr, "\n%" PRId64 " samples processed in ", current);
|
||||
else
|
||||
fprintf(stderr, "\n%" PRId64 "/%" PRId64 " samples processed in ",
|
||||
current, progress->total);
|
||||
|
@ -38,6 +38,7 @@ struct wav_reader_t {
|
||||
pcm_sample_description_t sample_format;
|
||||
int64_t length;
|
||||
int64_t position;
|
||||
int32_t data_offset;
|
||||
int ignore_length;
|
||||
int last_error;
|
||||
wav_io_context_t io;
|
||||
@ -91,7 +92,7 @@ int riff_read(wav_reader_t *reader, void *buffer, uint32_t size)
|
||||
}
|
||||
|
||||
static
|
||||
int riff_skip(wav_reader_t *reader, uint32_t count)
|
||||
int riff_skip(wav_reader_t *reader, int64_t count)
|
||||
{
|
||||
char buff[8192];
|
||||
int rc;
|
||||
@ -114,6 +115,37 @@ int riff_skip(wav_reader_t *reader, uint32_t count)
|
||||
return reader->last_error ? -1 : 0;
|
||||
}
|
||||
|
||||
static
|
||||
int riff_seek(wav_reader_t *reader, int64_t off, int whence)
|
||||
{
|
||||
int rc;
|
||||
if (reader->last_error)
|
||||
return -1;
|
||||
if (!reader->io.seek)
|
||||
goto FAIL;
|
||||
if ((rc = reader->io.seek(reader->io_cookie, off, whence)) < 0)
|
||||
goto FAIL;
|
||||
return 0;
|
||||
FAIL:
|
||||
reader->last_error = WAV_IO_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static
|
||||
int64_t riff_tell(wav_reader_t *reader)
|
||||
{
|
||||
int64_t off;
|
||||
|
||||
if (reader->last_error || !reader->io.tell)
|
||||
return -1;
|
||||
off = reader->io.tell(reader->io_cookie);
|
||||
if (off < 0) {
|
||||
reader->last_error = WAV_IO_ERROR;
|
||||
return -1;
|
||||
}
|
||||
return off;
|
||||
}
|
||||
|
||||
static
|
||||
int riff_read16(wav_reader_t *reader, uint16_t *value)
|
||||
{
|
||||
@ -209,9 +241,8 @@ int riff_ds64(wav_reader_t *reader, int64_t *length)
|
||||
fcc == RIFF_FOURCC('d','s','6','4') && chunk_size >= 28);
|
||||
TRY_IO(riff_scan(reader, "QQQL",
|
||||
&riff_size, length, &sample_count, &table_size) != 4);
|
||||
if (table_size == 0)
|
||||
return 0;
|
||||
reader->last_error = WAV_UNSUPPORTED_FORMAT;
|
||||
TRY_IO(riff_skip(reader, (chunk_size - 27) & ~1));
|
||||
reader->data_offset += (chunk_size + 9) & ~1;
|
||||
FAIL:
|
||||
return -1;
|
||||
}
|
||||
@ -290,6 +321,8 @@ int wav_parse(wav_reader_t *reader, int64_t *data_length)
|
||||
TRY_IO(riff_read32(reader, &fcc));
|
||||
if (fcc != RIFF_FOURCC('W','A','V','E'))
|
||||
goto FAIL;
|
||||
reader->data_offset = 12;
|
||||
|
||||
if (container == RIFF_FOURCC('R','F','6','4'))
|
||||
riff_ds64(reader, data_length);
|
||||
while ((fcc = riff_next_chunk(reader, &chunk_size)) != 0) {
|
||||
@ -299,9 +332,12 @@ int wav_parse(wav_reader_t *reader, int64_t *data_length)
|
||||
} else if (fcc == RIFF_FOURCC('d','a','t','a')) {
|
||||
if (container == RIFF_FOURCC('R','I','F','F'))
|
||||
*data_length = chunk_size;
|
||||
reader->data_offset += 8;
|
||||
break;
|
||||
} else
|
||||
} else {
|
||||
TRY_IO(riff_skip(reader, (chunk_size + 1) & ~1));
|
||||
}
|
||||
reader->data_offset += (chunk_size + 9) & ~1;
|
||||
}
|
||||
if (fcc == RIFF_FOURCC('d','a','t','a'))
|
||||
return 0;
|
||||
@ -312,8 +348,9 @@ FAIL:
|
||||
wav_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
||||
int ignore_length)
|
||||
{
|
||||
wav_reader_t *reader;
|
||||
wav_reader_t *reader = 0;
|
||||
int64_t data_length;
|
||||
unsigned bpf;
|
||||
|
||||
if ((reader = calloc(1, sizeof(wav_reader_t))) == 0)
|
||||
return 0;
|
||||
@ -324,10 +361,43 @@ wav_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
||||
free(reader);
|
||||
return 0;
|
||||
}
|
||||
if (ignore_length || !data_length ||
|
||||
data_length % reader->sample_format.bytes_per_frame != 0)
|
||||
bpf = reader->sample_format.bytes_per_frame;
|
||||
if (ignore_length || !data_length || data_length % bpf)
|
||||
reader->length = INT64_MAX;
|
||||
else
|
||||
reader->length = data_length / reader->sample_format.bytes_per_frame;
|
||||
reader->length = data_length / bpf;
|
||||
|
||||
if (reader->length == INT64_MAX && reader->io.seek && reader->io.tell) {
|
||||
if (reader->io.seek(reader->io_cookie, 0, SEEK_END) >= 0) {
|
||||
int64_t size = reader->io.tell(reader->io_cookie);
|
||||
if (size > 0)
|
||||
reader->length = (size - reader->data_offset) / bpf;
|
||||
reader->io.seek(reader->io_cookie, reader->data_offset, SEEK_SET);
|
||||
}
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
wav_reader_t *raw_open(wav_io_context_t *io_ctx, void *io_cookie,
|
||||
const pcm_sample_description_t *desc)
|
||||
{
|
||||
wav_reader_t *reader = 0;
|
||||
|
||||
if ((reader = calloc(1, sizeof(wav_reader_t))) == 0)
|
||||
return 0;
|
||||
memcpy(&reader->io, io_ctx, sizeof(wav_io_context_t));
|
||||
memcpy(&reader->sample_format, desc, sizeof(pcm_sample_description_t));
|
||||
reader->io_cookie = io_cookie;
|
||||
if (io_ctx->seek && io_ctx->tell) {
|
||||
if (reader->io.seek(reader->io_cookie, 0, SEEK_END) >= 0) {
|
||||
int64_t size = reader->io.tell(reader->io_cookie);
|
||||
if (size > 0)
|
||||
reader->length = size / desc->bytes_per_frame;
|
||||
reader->io.seek(reader->io_cookie, reader->data_offset, SEEK_SET);
|
||||
}
|
||||
} else
|
||||
reader->length = INT64_MAX;
|
||||
return reader;
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,16 +16,20 @@ enum wav_error_code {
|
||||
|
||||
typedef int (*wav_read_callback)(void *cookie, void *data, uint32_t size);
|
||||
typedef int (*wav_seek_callback)(void *cookie, int64_t off, int whence);
|
||||
typedef int64_t (*wav_tell_callback)(void *cookie);
|
||||
|
||||
typedef struct wav_io_context_t {
|
||||
wav_read_callback read;
|
||||
wav_seek_callback seek;
|
||||
wav_tell_callback tell;
|
||||
} wav_io_context_t;
|
||||
|
||||
typedef struct wav_reader_t wav_reader_t;
|
||||
|
||||
wav_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
||||
int ignore_length);
|
||||
wav_reader_t *raw_open(wav_io_context_t *io_ctx, void *io_cookie,
|
||||
const pcm_sample_description_t *desc);
|
||||
const pcm_sample_description_t *wav_get_format(wav_reader_t *reader);
|
||||
int wav_read_frames(wav_reader_t *reader, void *buffer, unsigned nframes);
|
||||
int64_t wav_get_length(wav_reader_t *reader);
|
||||
|
Reference in New Issue
Block a user