From fa02aa1d7ab03948198dad8329ea0bcf6b176a60 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 14 Aug 2021 20:42:55 +0200 Subject: [PATCH] mp4: Reduce indentation in modify_moov(). If the condition of the if clause is true, we return early, so the else clause can be made unconditional. No real change. --- mp4.c | 133 +++++++++++++++++++++++++++------------------------------- 1 file changed, 61 insertions(+), 72 deletions(-) diff --git a/mp4.c b/mp4.c index d83bc9df..bec03710 100644 --- a/mp4.c +++ b/mp4.c @@ -1408,83 +1408,72 @@ static uint32_t modify_moov(struct mp4 *f, void **out_buffer, *out_buffer = membuffer_detach(buf); membuffer_free(buf); return 1; - } else { - udta_offset = get_position(f); - udta_size = read_int32(f); - if (!find_atom_v2 (f, udta_offset + 8, udta_size - 8, "meta", 4, "ilst")) { - struct membuffer *buf; - void *new_meta_buffer; - uint32_t new_meta_size; - - if (!create_meta(&f->meta, &new_meta_buffer, &new_meta_size)) - return 0; - - buf = membuffer_create(); - set_position(f, total_base); - membuffer_transfer_from_file(buf, f, - (uint32_t)(udta_offset - total_base)); - - membuffer_write_int32(buf, udta_size + 8 + new_meta_size); - membuffer_write_atom_name(buf, "udta"); - membuffer_transfer_from_file(buf, f, udta_size); - - membuffer_write_atom(buf, "meta", new_meta_size, - new_meta_buffer); - free(new_meta_buffer); - - *out_size = membuffer_get_size(buf); - *out_buffer = membuffer_detach(buf); - membuffer_free(buf); - return 1; - } - meta_offset = get_position(f); - meta_size = read_int32(f); - if (!find_atom(f, meta_offset + 12, meta_size - 12, "ilst")) - return 0; //shouldn't happen, find_atom_v2 above takes care of it - ilst_offset = get_position(f); - ilst_size = read_int32(f); - - if (!create_ilst(&f->meta, &new_ilst_buffer, &new_ilst_size)) + } + udta_offset = get_position(f); + udta_size = read_int32(f); + if (!find_atom_v2 (f, udta_offset + 8, udta_size - 8, "meta", 4, "ilst")) { + struct membuffer *buf; + void *new_meta_buffer; + uint32_t new_meta_size; + + if (!create_meta(&f->meta, &new_meta_buffer, &new_meta_size)) return 0; - size_delta = new_ilst_size - (ilst_size - 8); + buf = membuffer_create(); + set_position(f, total_base); + membuffer_transfer_from_file(buf, f, + (uint32_t)(udta_offset - total_base)); - *out_size = total_size + size_delta; - *out_buffer = para_malloc(*out_size); - p_out = (uint8_t *) * out_buffer; + membuffer_write_int32(buf, udta_size + 8 + new_meta_size); + membuffer_write_atom_name(buf, "udta"); + membuffer_transfer_from_file(buf, f, udta_size); - set_position(f, total_base); - read_data(f, p_out, - (uint32_t) (udta_offset - total_base)); - p_out += (uint32_t) (udta_offset - total_base); - *(uint32_t *) p_out = fix_byte_order_32(read_int32(f) + size_delta); - p_out += 4; - read_data(f, p_out, 4); - p_out += 4; - read_data(f, p_out, - (uint32_t) (meta_offset - udta_offset - 8)); - p_out += (uint32_t) (meta_offset - udta_offset - 8); - *(uint32_t *) p_out = fix_byte_order_32(read_int32(f) + size_delta); - p_out += 4; - read_data(f, p_out, 4); - p_out += 4; - read_data(f, p_out, - (uint32_t) (ilst_offset - meta_offset - 8)); - p_out += (uint32_t) (ilst_offset - meta_offset - 8); - *(uint32_t *) p_out = fix_byte_order_32(read_int32(f) + size_delta); - p_out += 4; - read_data(f, p_out, 4); - p_out += 4; - - memcpy(p_out, new_ilst_buffer, new_ilst_size); - p_out += new_ilst_size; - - set_position(f, ilst_offset + ilst_size); - read_data(f, p_out, (uint32_t) (total_size - - (ilst_offset - total_base) - ilst_size)); - - free(new_ilst_buffer); + membuffer_write_atom(buf, "meta", new_meta_size, + new_meta_buffer); + free(new_meta_buffer); + + *out_size = membuffer_get_size(buf); + *out_buffer = membuffer_detach(buf); + membuffer_free(buf); + return 1; } + meta_offset = get_position(f); + meta_size = read_int32(f); + if (!find_atom(f, meta_offset + 12, meta_size - 12, "ilst")) + return 0; /* shouldn't happen, find_atom_v2 above takes care of it */ + ilst_offset = get_position(f); + ilst_size = read_int32(f); + if (!create_ilst(&f->meta, &new_ilst_buffer, &new_ilst_size)) + return 0; + size_delta = new_ilst_size - (ilst_size - 8); + *out_size = total_size + size_delta; + *out_buffer = para_malloc(*out_size); + p_out = (uint8_t *)*out_buffer; + set_position(f, total_base); + read_data(f, p_out, (uint32_t) (udta_offset - total_base)); + p_out += (uint32_t) (udta_offset - total_base); + *(uint32_t *)p_out = fix_byte_order_32(read_int32(f) + size_delta); + p_out += 4; + read_data(f, p_out, 4); + p_out += 4; + read_data(f, p_out, (uint32_t) (meta_offset - udta_offset - 8)); + p_out += (uint32_t) (meta_offset - udta_offset - 8); + *(uint32_t *)p_out = fix_byte_order_32(read_int32(f) + size_delta); + p_out += 4; + read_data(f, p_out, 4); + p_out += 4; + read_data(f, p_out, (uint32_t) (ilst_offset - meta_offset - 8)); + p_out += (uint32_t) (ilst_offset - meta_offset - 8); + *(uint32_t *)p_out = fix_byte_order_32(read_int32(f) + size_delta); + p_out += 4; + read_data(f, p_out, 4); + p_out += 4; + memcpy(p_out, new_ilst_buffer, new_ilst_size); + p_out += new_ilst_size; + set_position(f, ilst_offset + ilst_size); + read_data(f, p_out, (uint32_t) (total_size + - (ilst_offset - total_base) - ilst_size)); + free(new_ilst_buffer); return 1; } -- 2.39.5