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

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

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