decoder/dsdlib: convert struct dsdlib_id to a class
This commit is contained in:
parent
c37edfd3e9
commit
fd3dc7e5fb
@ -41,13 +41,12 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool
|
bool
|
||||||
dsdlib_id_equals(const struct dsdlib_id *id, const char *s)
|
DsdId::Equals(const char *s) const
|
||||||
{
|
{
|
||||||
assert(id != nullptr);
|
|
||||||
assert(s != nullptr);
|
assert(s != nullptr);
|
||||||
assert(strlen(s) == sizeof(id->value));
|
assert(strlen(s) == sizeof(value));
|
||||||
|
|
||||||
return memcmp(id->value, s, sizeof(id->value)) == 0;
|
return memcmp(value, s, sizeof(value)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -20,18 +20,20 @@
|
|||||||
#ifndef MPD_DECODER_DSDLIB_HXX
|
#ifndef MPD_DECODER_DSDLIB_HXX
|
||||||
#define MPD_DECODER_DSDLIB_HXX
|
#define MPD_DECODER_DSDLIB_HXX
|
||||||
|
|
||||||
|
#include "Compiler.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct Decoder;
|
struct Decoder;
|
||||||
struct InputStream;
|
struct InputStream;
|
||||||
|
|
||||||
struct dsdlib_id {
|
struct DsdId {
|
||||||
char value[4];
|
char value[4];
|
||||||
};
|
|
||||||
|
|
||||||
bool
|
gcc_pure
|
||||||
dsdlib_id_equals(const struct dsdlib_id *id, const char *s);
|
bool Equals(const char *s) const;
|
||||||
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
dsdlib_read(Decoder *decoder, InputStream &is,
|
dsdlib_read(Decoder *decoder, InputStream &is,
|
||||||
|
@ -42,13 +42,13 @@
|
|||||||
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
|
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
|
||||||
|
|
||||||
struct DsdiffHeader {
|
struct DsdiffHeader {
|
||||||
struct dsdlib_id id;
|
DsdId id;
|
||||||
uint32_t size_high, size_low;
|
uint32_t size_high, size_low;
|
||||||
struct dsdlib_id format;
|
DsdId format;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DsdiffChunkHeader {
|
struct DsdiffChunkHeader {
|
||||||
struct dsdlib_id id;
|
DsdId id;
|
||||||
uint32_t size_high, size_low;
|
uint32_t size_high, size_low;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +92,7 @@ dsdiff_init(const config_param ¶m)
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
dsdiff_read_id(Decoder *decoder, InputStream &is,
|
dsdiff_read_id(Decoder *decoder, InputStream &is,
|
||||||
struct dsdlib_id *id)
|
DsdId *id)
|
||||||
{
|
{
|
||||||
return dsdlib_read(decoder, is, id, sizeof(*id));
|
return dsdlib_read(decoder, is, id, sizeof(*id));
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ dsdiff_read_prop_snd(Decoder *decoder, InputStream &is,
|
|||||||
if (chunk_end_offset > end_offset)
|
if (chunk_end_offset > end_offset)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (dsdlib_id_equals(&header.id, "FS ")) {
|
if (header.id.Equals("FS ")) {
|
||||||
uint32_t sample_rate;
|
uint32_t sample_rate;
|
||||||
if (!dsdiff_read_payload(decoder, is, &header,
|
if (!dsdiff_read_payload(decoder, is, &header,
|
||||||
&sample_rate,
|
&sample_rate,
|
||||||
@ -143,7 +143,7 @@ dsdiff_read_prop_snd(Decoder *decoder, InputStream &is,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
metadata->sample_rate = FromBE32(sample_rate);
|
metadata->sample_rate = FromBE32(sample_rate);
|
||||||
} else if (dsdlib_id_equals(&header.id, "CHNL")) {
|
} else if (header.id.Equals("CHNL")) {
|
||||||
uint16_t channels;
|
uint16_t channels;
|
||||||
if (header.GetSize() < sizeof(channels) ||
|
if (header.GetSize() < sizeof(channels) ||
|
||||||
!dsdlib_read(decoder, is,
|
!dsdlib_read(decoder, is,
|
||||||
@ -152,15 +152,15 @@ dsdiff_read_prop_snd(Decoder *decoder, InputStream &is,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
metadata->channels = FromBE16(channels);
|
metadata->channels = FromBE16(channels);
|
||||||
} else if (dsdlib_id_equals(&header.id, "CMPR")) {
|
} else if (header.id.Equals("CMPR")) {
|
||||||
struct dsdlib_id type;
|
DsdId type;
|
||||||
if (header.GetSize() < sizeof(type) ||
|
if (header.GetSize() < sizeof(type) ||
|
||||||
!dsdlib_read(decoder, is,
|
!dsdlib_read(decoder, is,
|
||||||
&type, sizeof(type)) ||
|
&type, sizeof(type)) ||
|
||||||
!dsdlib_skip_to(decoder, is, chunk_end_offset))
|
!dsdlib_skip_to(decoder, is, chunk_end_offset))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!dsdlib_id_equals(&type, "DSD "))
|
if (!type.Equals("DSD "))
|
||||||
/* only uncompressed DSD audio data
|
/* only uncompressed DSD audio data
|
||||||
is implemented */
|
is implemented */
|
||||||
return false;
|
return false;
|
||||||
@ -186,12 +186,12 @@ dsdiff_read_prop(Decoder *decoder, InputStream &is,
|
|||||||
uint64_t prop_size = prop_header->GetSize();
|
uint64_t prop_size = prop_header->GetSize();
|
||||||
InputStream::offset_type end_offset = is.GetOffset() + prop_size;
|
InputStream::offset_type end_offset = is.GetOffset() + prop_size;
|
||||||
|
|
||||||
struct dsdlib_id prop_id;
|
DsdId prop_id;
|
||||||
if (prop_size < sizeof(prop_id) ||
|
if (prop_size < sizeof(prop_id) ||
|
||||||
!dsdiff_read_id(decoder, is, &prop_id))
|
!dsdiff_read_id(decoder, is, &prop_id))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (dsdlib_id_equals(&prop_id, "SND "))
|
if (prop_id.Equals("SND "))
|
||||||
return dsdiff_read_prop_snd(decoder, is, metadata, end_offset);
|
return dsdiff_read_prop_snd(decoder, is, metadata, end_offset);
|
||||||
else
|
else
|
||||||
/* ignore unknown PROP chunk */
|
/* ignore unknown PROP chunk */
|
||||||
@ -264,23 +264,23 @@ dsdiff_read_metadata_extra(Decoder *decoder, InputStream &is,
|
|||||||
uint64_t chunk_size = chunk_header->GetSize();
|
uint64_t chunk_size = chunk_header->GetSize();
|
||||||
|
|
||||||
/* DIIN chunk, is directly followed by other chunks */
|
/* DIIN chunk, is directly followed by other chunks */
|
||||||
if (dsdlib_id_equals(&chunk_header->id, "DIIN"))
|
if (chunk_header->id.Equals("DIIN"))
|
||||||
chunk_size = 0;
|
chunk_size = 0;
|
||||||
|
|
||||||
/* DIAR chunk - DSDIFF native tag for Artist */
|
/* DIAR chunk - DSDIFF native tag for Artist */
|
||||||
if (dsdlib_id_equals(&chunk_header->id, "DIAR")) {
|
if (chunk_header->id.Equals("DIAR")) {
|
||||||
chunk_size = chunk_header->GetSize();
|
chunk_size = chunk_header->GetSize();
|
||||||
metadata->diar_offset = is.GetOffset();
|
metadata->diar_offset = is.GetOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DITI chunk - DSDIFF native tag for Title */
|
/* DITI chunk - DSDIFF native tag for Title */
|
||||||
if (dsdlib_id_equals(&chunk_header->id, "DITI")) {
|
if (chunk_header->id.Equals("DITI")) {
|
||||||
chunk_size = chunk_header->GetSize();
|
chunk_size = chunk_header->GetSize();
|
||||||
metadata->diti_offset = is.GetOffset();
|
metadata->diti_offset = is.GetOffset();
|
||||||
}
|
}
|
||||||
#ifdef HAVE_ID3TAG
|
#ifdef HAVE_ID3TAG
|
||||||
/* 'ID3 ' chunk, offspec. Used by sacdextract */
|
/* 'ID3 ' chunk, offspec. Used by sacdextract */
|
||||||
if (dsdlib_id_equals(&chunk_header->id, "ID3 ")) {
|
if (chunk_header->id.Equals("ID3 ")) {
|
||||||
chunk_size = chunk_header->GetSize();
|
chunk_size = chunk_header->GetSize();
|
||||||
metadata->id3_offset = is.GetOffset();
|
metadata->id3_offset = is.GetOffset();
|
||||||
metadata->id3_size = chunk_size;
|
metadata->id3_size = chunk_size;
|
||||||
@ -331,8 +331,8 @@ dsdiff_read_metadata(Decoder *decoder, InputStream &is,
|
|||||||
{
|
{
|
||||||
DsdiffHeader header;
|
DsdiffHeader header;
|
||||||
if (!dsdlib_read(decoder, is, &header, sizeof(header)) ||
|
if (!dsdlib_read(decoder, is, &header, sizeof(header)) ||
|
||||||
!dsdlib_id_equals(&header.id, "FRM8") ||
|
!header.id.Equals("FRM8") ||
|
||||||
!dsdlib_id_equals(&header.format, "DSD "))
|
!header.format.Equals("DSD "))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -340,11 +340,11 @@ dsdiff_read_metadata(Decoder *decoder, InputStream &is,
|
|||||||
chunk_header))
|
chunk_header))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (dsdlib_id_equals(&chunk_header->id, "PROP")) {
|
if (chunk_header->id.Equals("PROP")) {
|
||||||
if (!dsdiff_read_prop(decoder, is, metadata,
|
if (!dsdiff_read_prop(decoder, is, metadata,
|
||||||
chunk_header))
|
chunk_header))
|
||||||
return false;
|
return false;
|
||||||
} else if (dsdlib_id_equals(&chunk_header->id, "DSD ")) {
|
} else if (chunk_header->id.Equals("DSD ")) {
|
||||||
const uint64_t chunk_size = chunk_header->GetSize();
|
const uint64_t chunk_size = chunk_header->GetSize();
|
||||||
metadata->chunk_size = chunk_size;
|
metadata->chunk_size = chunk_size;
|
||||||
return true;
|
return true;
|
||||||
@ -454,7 +454,7 @@ dsdiff_stream_decode(Decoder &decoder, InputStream &is)
|
|||||||
while (true) {
|
while (true) {
|
||||||
chunk_size = chunk_header.GetSize();
|
chunk_size = chunk_header.GetSize();
|
||||||
|
|
||||||
if (dsdlib_id_equals(&chunk_header.id, "DSD ")) {
|
if (chunk_header.id.Equals("DSD ")) {
|
||||||
if (!dsdiff_decode_chunk(decoder, is,
|
if (!dsdiff_decode_chunk(decoder, is,
|
||||||
metadata.channels,
|
metadata.channels,
|
||||||
chunk_size))
|
chunk_size))
|
||||||
|
@ -54,7 +54,7 @@ struct DsfMetaData {
|
|||||||
|
|
||||||
struct DsfHeader {
|
struct DsfHeader {
|
||||||
/** DSF header id: "DSD " */
|
/** DSF header id: "DSD " */
|
||||||
struct dsdlib_id id;
|
DsdId id;
|
||||||
/** DSD chunk size, including id = 28 */
|
/** DSD chunk size, including id = 28 */
|
||||||
uint32_t size_low, size_high;
|
uint32_t size_low, size_high;
|
||||||
/** total file size */
|
/** total file size */
|
||||||
@ -66,7 +66,7 @@ struct DsfHeader {
|
|||||||
/** DSF file fmt chunk */
|
/** DSF file fmt chunk */
|
||||||
struct DsfFmtChunk {
|
struct DsfFmtChunk {
|
||||||
/** id: "fmt " */
|
/** id: "fmt " */
|
||||||
struct dsdlib_id id;
|
DsdId id;
|
||||||
/** fmt chunk size, including id, normally 52 */
|
/** fmt chunk size, including id, normally 52 */
|
||||||
uint32_t size_low, size_high;
|
uint32_t size_low, size_high;
|
||||||
/** version of this format = 1 */
|
/** version of this format = 1 */
|
||||||
@ -90,7 +90,7 @@ struct DsfFmtChunk {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct DsfDataChunk {
|
struct DsfDataChunk {
|
||||||
struct dsdlib_id id;
|
DsdId id;
|
||||||
/** "data" chunk size, includes header (id+size) */
|
/** "data" chunk size, includes header (id+size) */
|
||||||
uint32_t size_low, size_high;
|
uint32_t size_low, size_high;
|
||||||
};
|
};
|
||||||
@ -105,7 +105,7 @@ dsf_read_metadata(Decoder *decoder, InputStream &is,
|
|||||||
uint64_t chunk_size;
|
uint64_t chunk_size;
|
||||||
DsfHeader dsf_header;
|
DsfHeader dsf_header;
|
||||||
if (!dsdlib_read(decoder, is, &dsf_header, sizeof(dsf_header)) ||
|
if (!dsdlib_read(decoder, is, &dsf_header, sizeof(dsf_header)) ||
|
||||||
!dsdlib_id_equals(&dsf_header.id, "DSD "))
|
!dsf_header.id.Equals("DSD "))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
chunk_size = (uint64_t(FromLE32(dsf_header.size_high)) << 32) |
|
chunk_size = (uint64_t(FromLE32(dsf_header.size_high)) << 32) |
|
||||||
@ -123,7 +123,7 @@ dsf_read_metadata(Decoder *decoder, InputStream &is,
|
|||||||
/* read the 'fmt ' chunk of the DSF file */
|
/* read the 'fmt ' chunk of the DSF file */
|
||||||
DsfFmtChunk dsf_fmt_chunk;
|
DsfFmtChunk dsf_fmt_chunk;
|
||||||
if (!dsdlib_read(decoder, is, &dsf_fmt_chunk, sizeof(dsf_fmt_chunk)) ||
|
if (!dsdlib_read(decoder, is, &dsf_fmt_chunk, sizeof(dsf_fmt_chunk)) ||
|
||||||
!dsdlib_id_equals(&dsf_fmt_chunk.id, "fmt "))
|
!dsf_fmt_chunk.id.Equals("fmt "))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint64_t fmt_chunk_size;
|
uint64_t fmt_chunk_size;
|
||||||
@ -152,7 +152,7 @@ dsf_read_metadata(Decoder *decoder, InputStream &is,
|
|||||||
/* read the 'data' chunk of the DSF file */
|
/* read the 'data' chunk of the DSF file */
|
||||||
DsfDataChunk data_chunk;
|
DsfDataChunk data_chunk;
|
||||||
if (!dsdlib_read(decoder, is, &data_chunk, sizeof(data_chunk)) ||
|
if (!dsdlib_read(decoder, is, &data_chunk, sizeof(data_chunk)) ||
|
||||||
!dsdlib_id_equals(&data_chunk.id, "data"))
|
!data_chunk.id.Equals("data"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* data size of DSF files are padded to multiple of 4096,
|
/* data size of DSF files are padded to multiple of 4096,
|
||||||
|
Loading…
Reference in New Issue
Block a user