mirror of
https://github.com/nu774/fdkaac.git
synced 2025-06-05 23:29:14 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
8c47bcc8dc | |||
1703d1f8cf | |||
4140443408 | |||
a1b4f691f5 |
20
ChangeLog
20
ChangeLog
@ -1,7 +1,23 @@
|
||||
2014-08-13 nu774 <honeycomb77@gmail.com>
|
||||
2014-09-13 nu774 <honeycomb77@gmail.com>
|
||||
|
||||
* update ChangeLog [HEAD]
|
||||
|
||||
* bump version [v0.6.1]
|
||||
|
||||
2014-09-12 nu774 <honeycomb77@gmail.com>
|
||||
|
||||
* write actual number of channels to mp4a box
|
||||
|
||||
2014-08-17 nu774 <honeycomb77@gmail.com>
|
||||
|
||||
* update INSTALL [origin/master]
|
||||
|
||||
* add m4 macros
|
||||
|
||||
2014-08-13 nu774 <honeycomb77@gmail.com>
|
||||
|
||||
* update ChangeLog
|
||||
|
||||
* bump version [v0.6.0]
|
||||
|
||||
2014-08-12 nu774 <honeycomb77@gmail.com>
|
||||
@ -12,7 +28,7 @@
|
||||
|
||||
2014-07-30 nu774 <honeycomb77@gmail.com>
|
||||
|
||||
* update ChangeLog [origin/master]
|
||||
* update ChangeLog
|
||||
|
||||
* win32compat: fix aacenc_printf() not to write junk characters [v0.5.4]
|
||||
|
||||
|
73
src/m4af.c
73
src/m4af.c
@ -103,12 +103,37 @@ typedef struct m4af_box_parser_t {
|
||||
int (*handler)(m4af_ctx_t *ctx, uint32_t name, uint64_t size);
|
||||
} m4af_box_parser_t;
|
||||
|
||||
static
|
||||
int m4af_write_null_cb(void *cookie, const void *data, uint32_t size)
|
||||
{
|
||||
int64_t *pos = cookie;
|
||||
*pos += size;
|
||||
return 0;
|
||||
}
|
||||
static
|
||||
int m4af_seek_null_cb(void *cookie, int64_t off, int whence)
|
||||
{
|
||||
int64_t *pos = cookie;
|
||||
*pos = off; /* XXX: we use only SEEK_SET */
|
||||
return 0;
|
||||
}
|
||||
static
|
||||
int64_t m4af_tell_null_cb(void *cookie)
|
||||
{
|
||||
return *((int64_t*)cookie);
|
||||
}
|
||||
|
||||
static m4af_io_callbacks_t m4af_null_io_callbacks = {
|
||||
0, m4af_write_null_cb, m4af_seek_null_cb, m4af_tell_null_cb
|
||||
};
|
||||
|
||||
static
|
||||
int64_t m4af_timestamp(void)
|
||||
{
|
||||
return (int64_t)(time(0)) + (((1970 - 1904) * 365) + 17) * 24 * 60 * 60;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
||||
*/
|
||||
@ -664,7 +689,7 @@ void m4af_write_stco_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
||||
m4af_track_t *track = &ctx->track[track_idx];
|
||||
uint32_t i;
|
||||
m4af_chunk_entry_t *index = track->chunk_table;
|
||||
int is_co64 = (ctx->mdat_pos + ctx->mdat_size > UINT32_MAX);
|
||||
int is_co64 = index[track->num_chunks - 1].offset > 0xffffffff;
|
||||
int64_t pos = m4af_tell(ctx);
|
||||
|
||||
m4af_write32(ctx, 0); /* size */
|
||||
@ -1012,7 +1037,7 @@ void m4af_write_hdlr_box(m4af_ctx_t *ctx, uint32_t track_idx, const char *type)
|
||||
/* reserved[0] */
|
||||
m4af_write(ctx, !strcmp(type, "mdir") ? "appl" : "\0\0\0\0", 4);
|
||||
/* reserved[1], reserved[2], name */
|
||||
m4af_write(ctx, reserved_and_name, (pos & 1) ? 9 : 10);
|
||||
m4af_write(ctx, reserved_and_name, 9);
|
||||
m4af_update_box_size(ctx, pos);
|
||||
}
|
||||
|
||||
@ -1317,28 +1342,59 @@ void m4af_finalize_mdat(m4af_ctx_t *ctx)
|
||||
m4af_set_pos(ctx, ctx->mdat_pos + ctx->mdat_size);
|
||||
}
|
||||
|
||||
static
|
||||
uint64_t m4af_patch_moov(m4af_ctx_t *ctx, uint32_t moov_size, uint32_t offset)
|
||||
{
|
||||
int64_t pos = 0;
|
||||
uint32_t moov_size2;
|
||||
int i, j;
|
||||
m4af_io_callbacks_t io_reserve = ctx->io;
|
||||
void *io_cookie_reserve = ctx->io_cookie;
|
||||
|
||||
for (i = 0; i < ctx->num_tracks; ++i)
|
||||
for (j = 0; j < ctx->track[i].num_chunks; ++j)
|
||||
ctx->track[i].chunk_table[j].offset += offset;
|
||||
|
||||
ctx->io = m4af_null_io_callbacks;
|
||||
ctx->io_cookie = &pos;
|
||||
moov_size2 = m4af_write_moov_box(ctx);
|
||||
|
||||
if (moov_size2 != moov_size) {
|
||||
/* stco -> co64 switching */
|
||||
for (i = 0; i < ctx->num_tracks; ++i)
|
||||
for (j = 0; j < ctx->track[i].num_chunks; ++j)
|
||||
ctx->track[i].chunk_table[j].offset += moov_size2 - moov_size;
|
||||
moov_size2 = m4af_write_moov_box(ctx);
|
||||
}
|
||||
ctx->io = io_reserve;
|
||||
ctx->io_cookie = io_cookie_reserve;
|
||||
return moov_size2;
|
||||
}
|
||||
|
||||
static
|
||||
void m4af_shift_mdat_pos(m4af_ctx_t *ctx, uint32_t offset)
|
||||
{
|
||||
unsigned i, j;
|
||||
int64_t begin, end;
|
||||
char buf[8192];
|
||||
char *buf;
|
||||
|
||||
buf = malloc(1024*1024*2);
|
||||
|
||||
end = ctx->mdat_pos + ctx->mdat_size;
|
||||
for (; (begin = m4af_max(ctx->mdat_pos, end - 8192)) < end; end = begin) {
|
||||
for (; (begin = m4af_max(ctx->mdat_pos, end - 1024*1024*2)) < end;
|
||||
end = begin) {
|
||||
m4af_set_pos(ctx, begin);
|
||||
ctx->io.read(ctx->io_cookie, buf, end - begin);
|
||||
m4af_set_pos(ctx, begin + offset);
|
||||
m4af_write(ctx, buf, end - begin);
|
||||
}
|
||||
for (i = 0; i < ctx->num_tracks; ++i)
|
||||
for (j = 0; j < ctx->track[i].num_chunks; ++j)
|
||||
ctx->track[i].chunk_table[j].offset += offset;
|
||||
ctx->mdat_pos += offset;
|
||||
m4af_set_pos(ctx, ctx->mdat_pos - 16);
|
||||
m4af_write_free_box(ctx, 0);
|
||||
m4af_write(ctx, "\0\0\0\0mdat", 8);
|
||||
m4af_finalize_mdat(ctx);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
int m4af_finalize(m4af_ctx_t *ctx, int optimize)
|
||||
@ -1367,7 +1423,8 @@ int m4af_finalize(m4af_ctx_t *ctx, int optimize)
|
||||
moov_size = m4af_write_moov_box(ctx);
|
||||
if (optimize) {
|
||||
int64_t pos;
|
||||
m4af_shift_mdat_pos(ctx, moov_size + 1024);
|
||||
uint32_t moov_size2 = m4af_patch_moov(ctx, moov_size, moov_size + 1024);
|
||||
m4af_shift_mdat_pos(ctx, moov_size2 + 1024);
|
||||
m4af_set_pos(ctx, 32);
|
||||
m4af_write_moov_box(ctx);
|
||||
pos = m4af_tell(ctx);
|
||||
|
13
src/main.c
13
src/main.c
@ -563,11 +563,20 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
|
||||
++encoded;
|
||||
if (encoded == 1 || encoded == 3)
|
||||
continue;
|
||||
obp = &obuf[flip];
|
||||
if (write_sample(params->output_fp, m4af, obp) < 0)
|
||||
|
||||
if (write_sample(params->output_fp, m4af, &obuf[flip]) < 0)
|
||||
goto END;
|
||||
++frames_written;
|
||||
} while (remaining > 0);
|
||||
/*
|
||||
* When interrupted, we haven't pulled out last extrapolated frames
|
||||
* from the reader. Therefore, we have to write the final outcome.
|
||||
*/
|
||||
if (g_interrupted) {
|
||||
if (write_sample(params->output_fp, m4af, &obp[flip^1]) < 0)
|
||||
goto END;
|
||||
++frames_written;
|
||||
}
|
||||
}
|
||||
DONE:
|
||||
if (!params->silent)
|
||||
|
Reference in New Issue
Block a user