Commit 913064d6 authored by Max Kellermann's avatar Max Kellermann

Merge branch 'v0.18.x'

parents fb45b8a5 09384df3
......@@ -49,6 +49,10 @@ ver 0.18.12 (not yet released)
* database
- proxy: fix build failure with libmpdclient 2.2
- proxy: fix add/search and other commands with libmpdclient < 2.9
* decoder
- audiofile: improve responsiveness
- audiofile: fix WAV stream playback
- dsdiff, dsf: fix stream playback
ver 0.18.11 (2014/05/12)
* decoder
......
......@@ -32,12 +32,27 @@
#include <af_vfs.h>
#include <assert.h>
#include <stdio.h>
/* pick 1020 since its devisible for 8,16,24, and 32-bit audio */
#define CHUNK_SIZE 1020
static constexpr Domain audiofile_domain("audiofile");
struct AudioFileInputStream {
Decoder *const decoder;
InputStream &is;
size_t Read(void *buffer, size_t size) {
/* libaudiofile does not like partial reads at all,
and wil abort playback; therefore always force full
reads */
return decoder_read_full(decoder, is, buffer, size)
? size
: 0;
}
};
gcc_pure
static int
audiofile_get_duration(Path path_fs)
......@@ -57,29 +72,26 @@ audiofile_get_duration(Path path_fs)
static ssize_t
audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
{
InputStream &is = *(InputStream *)vfile->closure;
Error error;
size_t nbytes = is.LockRead(data, length, error);
if (nbytes == 0 && error.IsDefined()) {
LogError(error);
return -1;
}
AudioFileInputStream &afis = *(AudioFileInputStream *)vfile->closure;
return nbytes;
return afis.Read(data, length);
}
static AFfileoffset
audiofile_file_length(AFvirtualfile *vfile)
{
InputStream &is = *(InputStream *)vfile->closure;
AudioFileInputStream &afis = *(AudioFileInputStream *)vfile->closure;
InputStream &is = afis.is;
return is.GetSize();
}
static AFfileoffset
audiofile_file_tell(AFvirtualfile *vfile)
{
InputStream &is = *(InputStream *)vfile->closure;
AudioFileInputStream &afis = *(AudioFileInputStream *)vfile->closure;
InputStream &is = afis.is;
return is.GetOffset();
}
......@@ -95,7 +107,8 @@ static AFfileoffset
audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset _offset,
int is_relative)
{
InputStream &is = *(InputStream *)vfile->closure;
AudioFileInputStream &afis = *(AudioFileInputStream *)vfile->closure;
InputStream &is = afis.is;
InputStream::offset_type offset = _offset;
if (is_relative)
......@@ -110,10 +123,10 @@ audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset _offset,
}
static AFvirtualfile *
setup_virtual_fops(InputStream &stream)
setup_virtual_fops(AudioFileInputStream &afis)
{
AFvirtualfile *vf = new AFvirtualfile();
vf->closure = &stream;
vf->closure = &afis;
vf->write = nullptr;
vf->read = audiofile_file_read;
vf->length = audiofile_file_length;
......@@ -180,7 +193,8 @@ audiofile_stream_decode(Decoder &decoder, InputStream &is)
return;
}
vf = setup_virtual_fops(is);
AudioFileInputStream afis{&decoder, is};
vf = setup_virtual_fops(afis);
af_fp = afOpenVirtualFile(vf, "r", nullptr);
if (af_fp == AF_NULL_FILEHANDLE) {
......
......@@ -45,14 +45,6 @@ DsdId::Equals(const char *s) const
return memcmp(value, s, sizeof(value)) == 0;
}
bool
dsdlib_read(Decoder *decoder, InputStream &is,
void *data, size_t length)
{
size_t nbytes = decoder_read(decoder, is, data, length);
return nbytes == length;
}
/**
* Skip the #input_stream to the specified offset.
*/
......@@ -123,7 +115,7 @@ dsdlib_tag_id3(InputStream &is,
id3_byte_t *dsdid3data;
dsdid3data = dsdid3;
if (!dsdlib_read(nullptr, is, dsdid3data, count))
if (!decoder_read_full(nullptr, is, dsdid3data, count))
return;
id3_tag = id3_tag_parse(dsdid3data, count);
......
......@@ -59,10 +59,6 @@ public:
};
bool
dsdlib_read(Decoder *decoder, InputStream &is,
void *data, size_t length);
bool
dsdlib_skip_to(Decoder *decoder, InputStream &is,
uint64_t offset);
......
......@@ -90,14 +90,14 @@ static bool
dsdiff_read_id(Decoder *decoder, InputStream &is,
DsdId *id)
{
return dsdlib_read(decoder, is, id, sizeof(*id));
return decoder_read_full(decoder, is, id, sizeof(*id));
}
static bool
dsdiff_read_chunk_header(Decoder *decoder, InputStream &is,
DsdiffChunkHeader *header)
{
return dsdlib_read(decoder, is, header, sizeof(*header));
return decoder_read_full(decoder, is, header, sizeof(*header));
}
static bool
......@@ -109,8 +109,7 @@ dsdiff_read_payload(Decoder *decoder, InputStream &is,
if (size != (uint64_t)length)
return false;
size_t nbytes = decoder_read(decoder, is, data, length);
return nbytes == length;
return decoder_read_full(decoder, is, data, length);
}
/**
......@@ -142,8 +141,8 @@ dsdiff_read_prop_snd(Decoder *decoder, InputStream &is,
} else if (header.id.Equals("CHNL")) {
uint16_t channels;
if (header.GetSize() < sizeof(channels) ||
!dsdlib_read(decoder, is,
&channels, sizeof(channels)) ||
!decoder_read_full(decoder, is,
&channels, sizeof(channels)) ||
!dsdlib_skip_to(decoder, is, chunk_end_offset))
return false;
......@@ -151,8 +150,8 @@ dsdiff_read_prop_snd(Decoder *decoder, InputStream &is,
} else if (header.id.Equals("CMPR")) {
DsdId type;
if (header.GetSize() < sizeof(type) ||
!dsdlib_read(decoder, is,
&type, sizeof(type)) ||
!decoder_read_full(decoder, is,
&type, sizeof(type)) ||
!dsdlib_skip_to(decoder, is, chunk_end_offset))
return false;
......@@ -205,7 +204,7 @@ dsdiff_handle_native_tag(InputStream &is,
struct dsdiff_native_tag metatag;
if (!dsdlib_read(nullptr, is, &metatag, sizeof(metatag)))
if (!decoder_read_full(nullptr, is, &metatag, sizeof(metatag)))
return;
uint32_t length = FromBE32(metatag.size);
......@@ -218,7 +217,7 @@ dsdiff_handle_native_tag(InputStream &is,
char *label;
label = string;
if (!dsdlib_read(nullptr, is, label, (size_t)length))
if (!decoder_read_full(nullptr, is, label, (size_t)length))
return;
string[length] = '\0';
......@@ -325,7 +324,7 @@ dsdiff_read_metadata(Decoder *decoder, InputStream &is,
DsdiffChunkHeader *chunk_header)
{
DsdiffHeader header;
if (!dsdlib_read(decoder, is, &header, sizeof(header)) ||
if (!decoder_read_full(decoder, is, &header, sizeof(header)) ||
!header.id.Equals("FRM8") ||
!header.format.Equals("DSD "))
return false;
......@@ -388,10 +387,10 @@ dsdiff_decode_chunk(Decoder &decoder, InputStream &is,
now_size = now_frames * frame_size;
}
size_t nbytes = decoder_read(decoder, is, buffer, now_size);
if (nbytes != now_size)
if (!decoder_read_full(&decoder, is, buffer, now_size))
return false;
const size_t nbytes = now_size;
chunk_size -= nbytes;
if (lsbitfirst)
......
......@@ -100,7 +100,7 @@ dsf_read_metadata(Decoder *decoder, InputStream &is,
DsfMetaData *metadata)
{
DsfHeader dsf_header;
if (!dsdlib_read(decoder, is, &dsf_header, sizeof(dsf_header)) ||
if (!decoder_read_full(decoder, is, &dsf_header, sizeof(dsf_header)) ||
!dsf_header.id.Equals("DSD "))
return false;
......@@ -114,7 +114,8 @@ dsf_read_metadata(Decoder *decoder, InputStream &is,
/* read the 'fmt ' chunk of the DSF file */
DsfFmtChunk dsf_fmt_chunk;
if (!dsdlib_read(decoder, is, &dsf_fmt_chunk, sizeof(dsf_fmt_chunk)) ||
if (!decoder_read_full(decoder, is,
&dsf_fmt_chunk, sizeof(dsf_fmt_chunk)) ||
!dsf_fmt_chunk.id.Equals("fmt "))
return false;
......@@ -140,7 +141,7 @@ dsf_read_metadata(Decoder *decoder, InputStream &is,
/* read the 'data' chunk of the DSF file */
DsfDataChunk data_chunk;
if (!dsdlib_read(decoder, is, &data_chunk, sizeof(data_chunk)) ||
if (!decoder_read_full(decoder, is, &data_chunk, sizeof(data_chunk)) ||
!data_chunk.id.Equals("data"))
return false;
......@@ -244,10 +245,10 @@ dsf_decode_chunk(Decoder &decoder, InputStream &is,
now_size = now_frames * frame_size;
}
size_t nbytes = decoder_read(&decoder, is, buffer, now_size);
if (nbytes != now_size)
if (!decoder_read_full(&decoder, is, buffer, now_size))
return false;
const size_t nbytes = now_size;
chunk_size -= nbytes;
if (bitreverse)
......
......@@ -36,6 +36,7 @@
#include <ogg/ogg.h>
#include <string.h>
#include <stdio.h>
static constexpr opus_int32 opus_sample_rate = 48000;
......
......@@ -31,6 +31,7 @@
#include <glib.h>
#include <string>
#include <stdio.h>
#include <stdio.h>
......
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