avformat/argo_asf: cleanup and NULL-terminate name field in header

Preparation for metadata changes in the following patches. Saves
having to create an extra buffer.

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
This commit is contained in:
Zane van Iperen 2021-10-12 20:45:45 +10:00
parent 2c734a8496
commit 20fa838da5
No known key found for this signature in database
GPG Key ID: 68616B2D8AC4DCC5
2 changed files with 6 additions and 5 deletions

View File

@ -52,8 +52,8 @@ void ff_argo_asf_parse_file_header(ArgoASFFileHeader *hdr, const uint8_t *buf)
hdr->version_minor = AV_RL16(buf + 6);
hdr->num_chunks = AV_RL32(buf + 8);
hdr->chunk_offset = AV_RL32(buf + 12);
for (int i = 0; i < FF_ARRAY_ELEMS(hdr->name); i++)
hdr->name[i] = AV_RL8(buf + 16 + i);
memcpy(hdr->name, buf + 16, ASF_NAME_SIZE);
hdr->name[ASF_NAME_SIZE] = '\0';
}
int ff_argo_asf_validate_file_header(AVFormatContext *s, const ArgoASFFileHeader *hdr)
@ -331,7 +331,7 @@ static void argo_asf_write_file_header(const ArgoASFFileHeader *fhdr, AVIOContex
avio_wl16( pb, fhdr->version_minor);
avio_wl32( pb, fhdr->num_chunks);
avio_wl32( pb, fhdr->chunk_offset);
avio_write(pb, fhdr->name, sizeof(fhdr->name));
avio_write(pb, fhdr->name, ASF_NAME_SIZE);
}
static void argo_asf_write_chunk_header(const ArgoASFChunkHeader *ckhdr, AVIOContext *pb)
@ -368,7 +368,7 @@ static int argo_asf_write_header(AVFormatContext *s)
} else {
len = end - name;
}
memcpy(fhdr.name, name, FFMIN(len, sizeof(fhdr.name)));
memcpy(fhdr.name, name, FFMIN(len, ASF_NAME_SIZE));
chdr.num_blocks = 0;
chdr.num_samples = ASF_SAMPLE_COUNT;

View File

@ -33,6 +33,7 @@
#define ASF_CHUNK_HEADER_SIZE 20
#define ASF_SAMPLE_COUNT 32
#define ASF_MIN_BUFFER_SIZE FFMAX(ASF_FILE_HEADER_SIZE, ASF_CHUNK_HEADER_SIZE)
#define ASF_NAME_SIZE 8
typedef struct ArgoASFFileHeader {
uint32_t magic; /*< Magic Number, {'A', 'S', 'F', '\0'} */
@ -40,7 +41,7 @@ typedef struct ArgoASFFileHeader {
uint16_t version_minor; /*< File Minor Version. */
uint32_t num_chunks; /*< No. chunks in the file. */
uint32_t chunk_offset; /*< Offset to the first chunk from the start of the file. */
int8_t name[8]; /*< Name. */
char name[ASF_NAME_SIZE + 1]; /*< Name, +1 for NULL-terminator. */
} ArgoASFFileHeader;
typedef struct ArgoASFChunkHeader {