Commit 352d7f47 authored by Max Kellermann's avatar Max Kellermann

decoder/{dsf,dsdiff}: convert to C++

parent 1fcf35ad
...@@ -448,12 +448,12 @@ endif ...@@ -448,12 +448,12 @@ endif
libdecoder_plugins_a_SOURCES = \ libdecoder_plugins_a_SOURCES = \
src/decoder/pcm_decoder_plugin.c \ src/decoder/pcm_decoder_plugin.c \
src/decoder/dsdiff_decoder_plugin.c \ src/decoder/DsdiffDecoderPlugin.cxx \
src/decoder/dsdiff_decoder_plugin.h \ src/decoder/DsdiffDecoderPlugin.hxx \
src/decoder/dsf_decoder_plugin.c \ src/decoder/DsfDecoderPlugin.cxx \
src/decoder/dsf_decoder_plugin.h \ src/decoder/DsfDecoderPlugin.hxx \
src/decoder/dsdlib.c \ src/decoder/DsdLib.cxx \
src/decoder/dsdlib.h \ src/decoder/DsdLib.hxx \
src/DecoderBuffer.cxx src/DecoderBuffer.hxx \ src/DecoderBuffer.cxx src/DecoderBuffer.hxx \
src/DecoderPlugin.cxx \ src/DecoderPlugin.cxx \
src/DecoderList.cxx src/DecoderList.hxx src/DecoderList.cxx src/DecoderList.hxx
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
#include "conf.h" #include "conf.h"
#include "mpd_error.h" #include "mpd_error.h"
#include "decoder/pcm_decoder_plugin.h" #include "decoder/pcm_decoder_plugin.h"
#include "decoder/dsdiff_decoder_plugin.h" #include "decoder/DsdiffDecoderPlugin.hxx"
#include "decoder/dsf_decoder_plugin.h" #include "decoder/DsfDecoderPlugin.hxx"
#include "decoder/FlacDecoderPlugin.h" #include "decoder/FlacDecoderPlugin.h"
#include "decoder/OpusDecoderPlugin.h" #include "decoder/OpusDecoderPlugin.h"
#include "decoder/VorbisDecoderPlugin.h" #include "decoder/VorbisDecoderPlugin.h"
......
/* /*
* Copyright (C) 2012 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -24,13 +24,14 @@ ...@@ -24,13 +24,14 @@
*/ */
#include "config.h" #include "config.h"
#include "dsf_decoder_plugin.h" #include "DsdLib.hxx"
#include "decoder_api.h" #include "decoder_api.h"
#include "util/bit_reverse.h" #include "util/bit_reverse.h"
#include "tag_handler.h" #include "tag_handler.h"
extern "C" {
#include "tag_id3.h" #include "tag_id3.h"
#include "dsdlib.h" }
#include "dsdiff_decoder_plugin.h"
#include <unistd.h> #include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */ #include <stdio.h> /* for SEEK_SET, SEEK_CUR */
...@@ -42,8 +43,8 @@ ...@@ -42,8 +43,8 @@
bool bool
dsdlib_id_equals(const struct dsdlib_id *id, const char *s) dsdlib_id_equals(const struct dsdlib_id *id, const char *s)
{ {
assert(id != NULL); assert(id != nullptr);
assert(s != NULL); assert(s != nullptr);
assert(strlen(s) == sizeof(id->value)); assert(strlen(s) == sizeof(id->value));
return memcmp(id->value, s, sizeof(id->value)) == 0; return memcmp(id->value, s, sizeof(id->value)) == 0;
...@@ -65,7 +66,7 @@ dsdlib_skip_to(struct decoder *decoder, struct input_stream *is, ...@@ -65,7 +66,7 @@ dsdlib_skip_to(struct decoder *decoder, struct input_stream *is,
goffset offset) goffset offset)
{ {
if (input_stream_is_seekable(is)) if (input_stream_is_seekable(is))
return input_stream_seek(is, offset, SEEK_SET, NULL); return input_stream_seek(is, offset, SEEK_SET, nullptr);
if (input_stream_get_offset(is) > offset) if (input_stream_get_offset(is) > offset)
return false; return false;
...@@ -98,7 +99,7 @@ dsdlib_skip(struct decoder *decoder, struct input_stream *is, ...@@ -98,7 +99,7 @@ dsdlib_skip(struct decoder *decoder, struct input_stream *is,
return true; return true;
if (input_stream_is_seekable(is)) if (input_stream_is_seekable(is))
return input_stream_seek(is, delta, SEEK_CUR, NULL); return input_stream_seek(is, delta, SEEK_CUR, nullptr);
char buffer[8192]; char buffer[8192];
while (delta > 0) { while (delta > 0) {
...@@ -132,10 +133,10 @@ dsdlib_tag_id3(struct input_stream *is, ...@@ -132,10 +133,10 @@ dsdlib_tag_id3(struct input_stream *is,
if (tagoffset == 0) if (tagoffset == 0)
return; return;
if (!dsdlib_skip_to(NULL, is, tagoffset)) if (!dsdlib_skip_to(nullptr, is, tagoffset))
return; return;
struct id3_tag *id3_tag = NULL; struct id3_tag *id3_tag = nullptr;
id3_length_t count; id3_length_t count;
/* Prevent broken files causing problems */ /* Prevent broken files causing problems */
...@@ -154,11 +155,11 @@ dsdlib_tag_id3(struct input_stream *is, ...@@ -154,11 +155,11 @@ dsdlib_tag_id3(struct input_stream *is,
id3_byte_t *dsdid3data; id3_byte_t *dsdid3data;
dsdid3data = dsdid3; dsdid3data = dsdid3;
if (!dsdlib_read(NULL, is, dsdid3data, count)) if (!dsdlib_read(nullptr, is, dsdid3data, count))
return; return;
id3_tag = id3_tag_parse(dsdid3data, count); id3_tag = id3_tag_parse(dsdid3data, count);
if (id3_tag == NULL) if (id3_tag == nullptr)
return; return;
scan_id3_tag(id3_tag, handler, handler_ctx); scan_id3_tag(id3_tag, handler, handler_ctx);
......
/* /*
* Copyright (C) 2012 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,8 +17,12 @@ ...@@ -17,8 +17,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_DECODER_DSDLIB_H #ifndef MPD_DECODER_DSDLIB_HXX
#define MPD_DECODER_DSDLIB_H #define MPD_DECODER_DSDLIB_HXX
#include <stdlib.h>
#include <glib.h>
struct dsdlib_id { struct dsdlib_id {
char value[4]; char value[4];
......
/* /*
* Copyright (C) 2003-2012 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
......
/* /*
* Copyright (C) 2012 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -28,11 +28,11 @@ ...@@ -28,11 +28,11 @@
*/ */
#include "config.h" #include "config.h"
#include "dsf_decoder_plugin.h" #include "DsfDecoderPlugin.hxx"
#include "decoder_api.h" #include "decoder_api.h"
#include "audio_check.h" #include "audio_check.h"
#include "util/bit_reverse.h" #include "util/bit_reverse.h"
#include "dsdlib.h" #include "DsdLib.hxx"
#include "tag_handler.h" #include "tag_handler.h"
#include <unistd.h> #include <unistd.h>
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "dsf" #define G_LOG_DOMAIN "dsf"
struct dsf_metadata { struct DsfMetaData {
unsigned sample_rate, channels; unsigned sample_rate, channels;
bool bitreverse; bool bitreverse;
uint64_t chunk_size; uint64_t chunk_size;
...@@ -51,7 +51,7 @@ struct dsf_metadata { ...@@ -51,7 +51,7 @@ struct dsf_metadata {
#endif #endif
}; };
struct dsf_header { struct DsfHeader {
/** DSF header id: "DSD " */ /** DSF header id: "DSD " */
struct dsdlib_id id; struct dsdlib_id id;
/** DSD chunk size, including id = 28 */ /** DSD chunk size, including id = 28 */
...@@ -63,8 +63,7 @@ struct dsf_header { ...@@ -63,8 +63,7 @@ struct dsf_header {
}; };
/** DSF file fmt chunk */ /** DSF file fmt chunk */
struct dsf_fmt_chunk { struct DsfFmtChunk {
/** id: "fmt " */ /** id: "fmt " */
struct dsdlib_id id; struct dsdlib_id id;
/** fmt chunk size, including id, normally 52 */ /** fmt chunk size, including id, normally 52 */
...@@ -89,7 +88,7 @@ struct dsf_fmt_chunk { ...@@ -89,7 +88,7 @@ struct dsf_fmt_chunk {
uint32_t reserved; uint32_t reserved;
}; };
struct dsf_data_chunk { struct DsfDataChunk {
struct dsdlib_id id; struct dsdlib_id 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;
...@@ -100,10 +99,10 @@ struct dsf_data_chunk { ...@@ -100,10 +99,10 @@ struct dsf_data_chunk {
*/ */
static bool static bool
dsf_read_metadata(struct decoder *decoder, struct input_stream *is, dsf_read_metadata(struct decoder *decoder, struct input_stream *is,
struct dsf_metadata *metadata) DsfMetaData *metadata)
{ {
uint64_t chunk_size; uint64_t chunk_size;
struct dsf_header 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 ")) !dsdlib_id_equals(&dsf_header.id, "DSD "))
return false; return false;
...@@ -121,7 +120,7 @@ dsf_read_metadata(struct decoder *decoder, struct input_stream *is, ...@@ -121,7 +120,7 @@ dsf_read_metadata(struct decoder *decoder, struct input_stream *is,
#endif #endif
/* read the 'fmt ' chunk of the DSF file */ /* read the 'fmt ' chunk of the DSF file */
struct dsf_fmt_chunk 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 ")) !dsdlib_id_equals(&dsf_fmt_chunk.id, "fmt "))
return false; return false;
...@@ -150,7 +149,7 @@ dsf_read_metadata(struct decoder *decoder, struct input_stream *is, ...@@ -150,7 +149,7 @@ dsf_read_metadata(struct decoder *decoder, struct input_stream *is,
return false; return false;
/* read the 'data' chunk of the DSF file */ /* read the 'data' chunk of the DSF file */
struct dsf_data_chunk 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")) !dsdlib_id_equals(&data_chunk.id, "data"))
return false; return false;
...@@ -280,12 +279,8 @@ dsf_decode_chunk(struct decoder *decoder, struct input_stream *is, ...@@ -280,12 +279,8 @@ dsf_decode_chunk(struct decoder *decoder, struct input_stream *is,
static void static void
dsf_stream_decode(struct decoder *decoder, struct input_stream *is) dsf_stream_decode(struct decoder *decoder, struct input_stream *is)
{ {
struct dsf_metadata metadata = {
.sample_rate = 0,
.channels = 0,
};
/* check if it is a proper DSF file */ /* check if it is a proper DSF file */
DsfMetaData metadata;
if (!dsf_read_metadata(decoder, is, &metadata)) if (!dsf_read_metadata(decoder, is, &metadata))
return; return;
...@@ -317,12 +312,8 @@ dsf_scan_stream(struct input_stream *is, ...@@ -317,12 +312,8 @@ dsf_scan_stream(struct input_stream *is,
G_GNUC_UNUSED const struct tag_handler *handler, G_GNUC_UNUSED const struct tag_handler *handler,
G_GNUC_UNUSED void *handler_ctx) G_GNUC_UNUSED void *handler_ctx)
{ {
struct dsf_metadata metadata = {
.sample_rate = 0,
.channels = 0,
};
/* check DSF metadata */ /* check DSF metadata */
DsfMetaData metadata;
if (!dsf_read_metadata(NULL, is, &metadata)) if (!dsf_read_metadata(NULL, is, &metadata))
return false; return false;
...@@ -356,9 +347,14 @@ static const char *const dsf_mime_types[] = { ...@@ -356,9 +347,14 @@ static const char *const dsf_mime_types[] = {
}; };
const struct decoder_plugin dsf_decoder_plugin = { const struct decoder_plugin dsf_decoder_plugin = {
.name = "dsf", "dsf",
.stream_decode = dsf_stream_decode, nullptr,
.scan_stream = dsf_scan_stream, nullptr,
.suffixes = dsf_suffixes, dsf_stream_decode,
.mime_types = dsf_mime_types, nullptr,
nullptr,
dsf_scan_stream,
nullptr,
dsf_suffixes,
dsf_mime_types,
}; };
/* /*
* Copyright (C) 2012 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment