mirror of
https://github.com/nu774/fdkaac.git
synced 2025-06-05 23:29:14 +02:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
4d060c0da0 | |||
1184a1f52b | |||
93fb917b75 |
72
src/m4af.c
72
src/m4af.c
@ -426,52 +426,68 @@ int m4af_write_sample(m4af_ctx_t *ctx, uint32_t track_idx, const void *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int m4af_add_itmf_entry(m4af_ctx_t *ctx)
|
m4af_itmf_entry_t *m4af_find_itmf_slot(m4af_ctx_t *ctx, uint32_t fcc,
|
||||||
|
const char *name)
|
||||||
{
|
{
|
||||||
m4af_itmf_entry_t *entry;
|
m4af_itmf_entry_t *entry = ctx->itmf_table;
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
fcc = M4AF_FOURCC('-','-','-','-');
|
||||||
|
|
||||||
|
if (fcc != M4AF_TAG_ARTWORK)
|
||||||
|
for (; entry != ctx->itmf_table + ctx->num_tags; ++entry)
|
||||||
|
if (fcc == entry->fcc && (!name || !strcmp(name, entry->name)))
|
||||||
|
return entry;
|
||||||
|
|
||||||
if (ctx->num_tags == ctx->itmf_table_capacity) {
|
if (ctx->num_tags == ctx->itmf_table_capacity) {
|
||||||
uint32_t new_size = ctx->itmf_table_capacity;
|
uint32_t new_size = ctx->itmf_table_capacity;
|
||||||
new_size = new_size ? new_size * 2 : 1;
|
new_size = new_size ? new_size * 2 : 1;
|
||||||
entry = m4af_realloc(ctx->itmf_table, new_size * sizeof(*entry));
|
entry = m4af_realloc(ctx->itmf_table, new_size * sizeof(*entry));
|
||||||
if (entry == 0) {
|
if (entry == 0) {
|
||||||
ctx->last_error = M4AF_NO_MEMORY;
|
ctx->last_error = M4AF_NO_MEMORY;
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
ctx->itmf_table = entry;
|
ctx->itmf_table = entry;
|
||||||
ctx->itmf_table_capacity = new_size;
|
ctx->itmf_table_capacity = new_size;
|
||||||
}
|
}
|
||||||
++ctx->num_tags;
|
entry = &ctx->itmf_table[ctx->num_tags++];
|
||||||
return 0;
|
memset(entry, 0, sizeof(m4af_itmf_entry_t));
|
||||||
|
entry->fcc = fcc;
|
||||||
|
if (name) {
|
||||||
|
char *name_copy = m4af_realloc(0, strlen(name) + 1);
|
||||||
|
if (!name_copy) {
|
||||||
|
ctx->last_error = M4AF_NO_MEMORY;
|
||||||
|
--ctx->num_tags;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
strcpy(name_copy, name);
|
||||||
|
entry->name = name_copy;
|
||||||
|
}
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m4af_add_itmf_long_tag(m4af_ctx_t *ctx, const char *name,
|
int m4af_add_itmf_long_tag(m4af_ctx_t *ctx, const char *name,
|
||||||
const char *data)
|
const char *data)
|
||||||
{
|
{
|
||||||
m4af_itmf_entry_t *entry;
|
m4af_itmf_entry_t *entry;
|
||||||
|
char *data_copy = 0;
|
||||||
size_t name_len = strlen(name);
|
size_t name_len = strlen(name);
|
||||||
size_t data_len = strlen(data);
|
size_t data_len = strlen(data);
|
||||||
char *name_copy = m4af_realloc(0, name_len + 1);
|
if (!name_len || !data_len)
|
||||||
char *data_copy = m4af_realloc(0, data_len);
|
return 0;
|
||||||
if (!name_copy || !data_copy) {
|
|
||||||
|
if ((entry = m4af_find_itmf_slot(ctx, 0, name)) == 0)
|
||||||
|
goto FAIL;
|
||||||
|
entry->type_code = M4AF_UTF8;
|
||||||
|
if ((data_copy = m4af_realloc(entry->data, data_len)) == 0) {
|
||||||
ctx->last_error = M4AF_NO_MEMORY;
|
ctx->last_error = M4AF_NO_MEMORY;
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
if (m4af_add_itmf_entry(ctx) < 0)
|
|
||||||
goto FAIL;
|
|
||||||
memcpy(name_copy, name, name_len + 1);
|
|
||||||
memcpy(data_copy, data, data_len);
|
memcpy(data_copy, data, data_len);
|
||||||
entry = ctx->itmf_table + ctx->num_tags - 1;
|
|
||||||
entry->fcc = M4AF_FOURCC('-','-','-','-');
|
|
||||||
entry->name = name_copy;
|
|
||||||
entry->type_code = M4AF_UTF8;
|
|
||||||
entry->data = data_copy;
|
entry->data = data_copy;
|
||||||
entry->data_size = data_len;
|
entry->data_size = data_len;
|
||||||
return 0;
|
return 0;
|
||||||
FAIL:
|
FAIL:
|
||||||
if (name_copy)
|
|
||||||
m4af_free(name_copy);
|
|
||||||
if (data_copy)
|
|
||||||
m4af_free(data_copy);
|
|
||||||
return ctx->last_error;
|
return ctx->last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,24 +496,22 @@ int m4af_add_itmf_short_tag(m4af_ctx_t *ctx, uint32_t fcc,
|
|||||||
uint32_t data_size)
|
uint32_t data_size)
|
||||||
{
|
{
|
||||||
m4af_itmf_entry_t *entry;
|
m4af_itmf_entry_t *entry;
|
||||||
char *data_copy = m4af_realloc(0, data_size);
|
char *data_copy = 0;
|
||||||
if (!data_copy) {
|
|
||||||
|
if (!data_size)
|
||||||
|
return 0;
|
||||||
|
if ((entry = m4af_find_itmf_slot(ctx, fcc, 0)) == 0)
|
||||||
|
goto FAIL;
|
||||||
|
entry->type_code = type_code;
|
||||||
|
if ((data_copy = m4af_realloc(entry->data, data_size)) == 0) {
|
||||||
ctx->last_error = M4AF_NO_MEMORY;
|
ctx->last_error = M4AF_NO_MEMORY;
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
if (m4af_add_itmf_entry(ctx) < 0)
|
|
||||||
goto FAIL;
|
|
||||||
entry = ctx->itmf_table + ctx->num_tags - 1;
|
|
||||||
entry->fcc = fcc;
|
|
||||||
entry->name = 0;
|
|
||||||
entry->type_code = type_code;
|
|
||||||
memcpy(data_copy, data, data_size);
|
memcpy(data_copy, data, data_size);
|
||||||
entry->data = data_copy;
|
entry->data = data_copy;
|
||||||
entry->data_size = data_size;
|
entry->data_size = data_size;
|
||||||
return 0;
|
return 0;
|
||||||
FAIL:
|
FAIL:
|
||||||
if (data_copy)
|
|
||||||
m4af_free(data_copy);
|
|
||||||
return ctx->last_error;
|
return ctx->last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +166,28 @@ void tag_put_number_pair(m4af_ctx_t *m4af, uint32_t fcc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
const char *aacenc_json_object_get_string(JSON_Object *obj, const char *key,
|
||||||
|
char *buf)
|
||||||
|
{
|
||||||
|
JSON_Value_Type type;
|
||||||
|
const char *val = 0;
|
||||||
|
|
||||||
|
type = json_value_get_type(json_object_get_value(obj, key));
|
||||||
|
if (type == JSONString)
|
||||||
|
val = json_object_get_string(obj, key);
|
||||||
|
else if (type == JSONNumber) {
|
||||||
|
double num = json_object_get_number(obj, key);
|
||||||
|
sprintf(buf, "%.15g", num);
|
||||||
|
val = buf;
|
||||||
|
} else if (type == JSONBoolean) {
|
||||||
|
int n = json_object_get_boolean(obj, key);
|
||||||
|
sprintf(buf, "%d", n);
|
||||||
|
val = buf;
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
void aacenc_put_tags_from_json(m4af_ctx_t *m4af, const char *json_filename)
|
void aacenc_put_tags_from_json(m4af_ctx_t *m4af, const char *json_filename)
|
||||||
{
|
{
|
||||||
char *data = 0;
|
char *data = 0;
|
||||||
@ -202,37 +224,29 @@ void aacenc_put_tags_from_json(m4af_ctx_t *m4af, const char *json_filename)
|
|||||||
nelts = json_object_get_count(root);
|
nelts = json_object_get_count(root);
|
||||||
for (i = 0; i < nelts; ++i) {
|
for (i = 0; i < nelts; ++i) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
const char *key = 0;
|
const char *key = json_object_get_name(root, i);
|
||||||
const char *val = 0;
|
const char *val = aacenc_json_object_get_string(root, key, buf);
|
||||||
uint32_t fcc = 0;
|
uint32_t fcc = get_tag_fcc_from_name(key);
|
||||||
JSON_Value_Type type;
|
|
||||||
|
|
||||||
key = json_object_get_name(root, i);
|
|
||||||
type = json_value_get_type(json_object_get_value(root, key));
|
|
||||||
if (type == JSONString)
|
|
||||||
val = json_object_get_string(root, key);
|
|
||||||
else if (type == JSONNumber) {
|
|
||||||
double num = json_object_get_number(root, key);
|
|
||||||
sprintf(buf, "%g", num);
|
|
||||||
val = buf;
|
|
||||||
} else if (type == JSONBoolean) {
|
|
||||||
int n = json_object_get_boolean(root, key);
|
|
||||||
sprintf(buf, "%d", n);
|
|
||||||
val = buf;
|
|
||||||
}
|
|
||||||
fcc = get_tag_fcc_from_name(key);
|
|
||||||
if (!val || !fcc)
|
if (!val || !fcc)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (fcc) {
|
switch (fcc) {
|
||||||
case TAG_TOTAL_DISCS:
|
case TAG_TOTAL_DISCS:
|
||||||
total_discs = strdup(val); break;
|
total_discs = realloc(total_discs, strlen(val) + 1);
|
||||||
|
strcpy(total_discs, val);
|
||||||
|
break;
|
||||||
case TAG_TOTAL_TRACKS:
|
case TAG_TOTAL_TRACKS:
|
||||||
total_tracks = strdup(val); break;
|
total_tracks = realloc(total_tracks, strlen(val) + 1);
|
||||||
|
strcpy(total_tracks, val);
|
||||||
|
break;
|
||||||
case M4AF_TAG_DISK:
|
case M4AF_TAG_DISK:
|
||||||
disc = strdup(val); break;
|
disc = realloc(disc, strlen(val) + 1);
|
||||||
|
strcpy(disc, val);
|
||||||
|
break;
|
||||||
case M4AF_TAG_TRACK:
|
case M4AF_TAG_TRACK:
|
||||||
track = strdup(val); break;
|
track = realloc(track, strlen(val) + 1);
|
||||||
|
strcpy(track, val);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
entry.tag = fcc;
|
entry.tag = fcc;
|
||||||
|
Reference in New Issue
Block a user