Commit Graph

1962 Commits

Author SHA1 Message Date
Max Kellermann
a1b430cb88 oggvorbis: don't detect OGG header if stream is not seekable
If the input stream is not seekable, the try_decode() function
consumes valuable data, which is not available to the decode()
function anymore.  This means that the decode() function does not
parse the header correctly.  Better skip the detection if we cannot
seek.  Or implement better buffering, something like unread() or
buffered rewind().
2008-08-26 08:27:13 +02:00
Max Kellermann
7bbca0842d added AacBuffer.decoder
We need the decoder object at several places in the AAC plugin.  Add
it to mp3DecodeData, so we don't have to pass it around in every
function.
2008-08-26 08:27:13 +02:00
Max Kellermann
468f61d587 mp3: added mp3DecodeData.decoder
We need the decoder object at several places in the mp3 plugin.  Add
it to mp3DecodeData, so we don't have to pass it around in every
function.
2008-08-26 08:27:13 +02:00
Max Kellermann
7653ab434e mp3: audio_linear_dither() returns mpd_sint16
The return value of audio_linear_dither() is always casted to
mpd_sint16.  Returning long does not make sense, and consumed 8 bytes
on a 64 bit platform.
2008-08-26 08:27:13 +02:00
Max Kellermann
9c823d67a7 mp3: changed outputBuffer's type to mpd_sint16[]
The output buffer always contains mpd_sint16; declaring it with that
type saves several casts.
2008-08-26 08:27:13 +02:00
Max Kellermann
2a9608536c mp3: moved num_samples calculation out of the loop
The previous patch removed all loop specific dependencies from the
num_samples formula; we can now calculate it before entering the loop.
2008-08-26 08:27:13 +02:00
Max Kellermann
3f55b5a1e4 mp3: eliminated outputPtr
The output buffer is always flushed after being appended to, which
allows us to assume it is always empty.  Always start writing at
outputBuffer, don't remember outputPtr.
2008-08-26 08:27:13 +02:00
Max Kellermann
f0bcb4a44a mp3: don't do a second flush in mp3_decode()
The previous patch made mp3Read() flush the output buffer in every
iteration, which means we can eliminate the flush check after invoking
mp3Read().
2008-08-26 08:27:13 +02:00
Max Kellermann
2e8bd3ae1d mp3: always flush directly after decoding/dithering
Since we try to fill the buffer in every iteration, we assume that we
should flush the output buffer at the end of each iteration.
2008-08-26 08:27:12 +02:00
Max Kellermann
af83ac5ec6 mp3: dither a whole block at a time
Fill the whole output buffer at a time by using dither_buffer()'s
ability to decode blocks.  Calculate how many samples fit into the
output buffer before each invocation.
2008-08-26 08:27:12 +02:00
Max Kellermann
e99536e8eb mp3: moved dropSamplesAtEnd check out of the loop
Simplifying loops for performance: why check dropSamplesAtEnd in every
iteration, when we could modify the loop boundary?  The (writable)
variable samplesLeft can be eliminated; add a write-once variable
pcm_length instead, which is used for the loop condition.
2008-08-26 08:27:12 +02:00
Max Kellermann
e4c6c01903 mp3: make samplesPerFrame more local
The variable samplesPerFrame is used only in one single closure.  Make
it local to this closure.  The compiler will probably convert it to a
register anyway.
2008-08-26 08:27:12 +02:00
Max Kellermann
60a155624c mp3: unsigned integers 2008-08-26 08:27:12 +02:00
Max Kellermann
f667da1b46 mp3: removed double cmd==STOP check
cmd has already been checked before, it cannot have changed meanwhile
because it is a local variable.
2008-08-26 08:27:12 +02:00
Max Kellermann
09fbbdc366 mp3: moved code to dither_buffer()
Preparing for simplifying and thus speeding up the dithering code:
moved dithering to a separate function which contains a trivial loop.
With this patch, only one sample is dithered at a time, but the
following patches will allow us to dither a whole block at a time,
without complicated buffer length checks.
2008-08-26 08:27:12 +02:00
Max Kellermann
d9583aa95b mp3: don't check dropSamplesAtStart in the loop
Performance improvement by moving stuff out of a loop: skip part of
the first frame before entering the loop.
2008-08-26 08:27:12 +02:00
Max Kellermann
df251a9960 assert song->url != NULL 2008-08-26 08:27:11 +02:00
Max Kellermann
e99333167e aac: support decoding AAC streams
Copy some code from aac_decode() to aac_stream_decode() and apply
necessary changes to allow streaming audio data.  Both functions might
be merged later.
2008-08-26 08:27:11 +02:00
Max Kellermann
5300f79ca9 aac: splitted aac_parse_header() from initAacBuffer()
initAacBuffer() should really only initialize the buffer; currently,
it also reads data from the input stream and parses the header.  All
of the AAC buffer code should probably be moved to a separate library
anyway.
2008-08-26 08:27:11 +02:00
Max Kellermann
351dda01bd aac: check buffer lengths
The AAC plugin sometimes does not check the length of available data
when checking for magic prefixes.  Add length checks.
2008-08-26 08:27:11 +02:00
Max Kellermann
9131f9ebfe aac: use fillAacBuffer() instead of manual reading
Eliminate some duplicated code by using fillAacBuffer().
2008-08-26 08:27:11 +02:00
Max Kellermann
00c47b3c85 find AAC frames
Find AAC frames in the input and skip invalid data.  This prepares AAC
streaming.
2008-08-26 08:27:11 +02:00
Max Kellermann
f43e39047d aac: moved code to adts_check_frame()
adts_check_frame() checks whether the buffer head is an AAC frame, and
returns the frame length.
2008-08-26 08:27:11 +02:00
Max Kellermann
b7ad3e4121 aac: moved code to aac_buffer_shift()
Shifting from the buffer queue is a common operation, and should be
provided as a separate function.  Move code to aac_buffer_shift() and
add a bunch of assertions.
2008-08-26 08:27:11 +02:00
Max Kellermann
a3cc928c71 aac: use inputStreamAtEOF()
When checking for EOF, we should not check whether the read request
has been fully satisified.  The InputStream API does not guarantee
that readFromInputStream() always fills the whole buffer, if EOF is
not reached.  Since there is the function inputStreamAtEOF() dedicated
for this purpose, we should use it for EOF checking after
readFromInputStream()==0.
2008-08-26 08:27:10 +02:00
Max Kellermann
35858dfe3a aac: don't depend on consumed data in fillAacBuffer()
Fill the AacBuffer even when nothing has been consumed yet.  The
function should not check for consumed data, but for free space at the
end of the buffer.
2008-08-26 08:27:10 +02:00
Max Kellermann
2a14141121 aac: simplified fillAacBuffer()
Return instead of putting all the code into a if-closure.  That saves
one level of indentation.
2008-08-26 08:27:10 +02:00
Max Kellermann
1d18f0089a aac: make adtsParse() void
adtsParse() always returns 1, and its caller does not use the return
value.
2008-08-26 08:27:10 +02:00
Max Kellermann
0ca8f9ac49 aac: use size_t 2008-08-26 08:27:10 +02:00
Max Kellermann
a6332fd13b aac: removed unused initAacBuffer() parameters
Since we eliminated the parameters retFileread and retTagsize in all
callers, we can now safely remove it from the function prototype.
2008-08-26 08:27:10 +02:00
Max Kellermann
4ca24b960b eliminate unused variables in the AAC decoder 2008-08-26 08:27:10 +02:00
Max Kellermann
82ca4cf8ce added InputStream.ready
The flag "ready" indicates whether the input stream is ready and it
has parsed all meta data.  Previously, it was impossible for
decodeStart() to see the content type of HTTP input streams, because
at that time, the HTTP response wasn't parsed yet.
2008-08-26 08:27:10 +02:00
Max Kellermann
6120635f06 added decoder_plugin_register()
With the functions decoder_plugin_register() and
decoder_plugin_unregister(), decoder plugins can register a
"secondary" plugin, like the flac input plugin does this for
"oggflac".
2008-08-26 08:27:09 +02:00
Max Kellermann
a68ef497f5 don't call quitDecode() in waitOnDecode()
To make the code more consistent, call quitDecode() only at the end of
decodeParent().
2008-08-26 08:27:09 +02:00
Max Kellermann
e8bd9ddc9f moved code to player_thread.c
Move code which runs in the player thread to player_thread.c.  Having
a lot of player thread code in decode.c isn't easy to understand.
2008-08-26 08:27:09 +02:00
Max Kellermann
6104e9690e moved code to crossfade.c
decode.c should be a lot smaller; start by moving all code which
handles cross-fading to crossfade.c.  Also includes camelCase
conversion.
2008-08-26 08:27:09 +02:00
Max Kellermann
2650b9eb31 added inline function audio_format_time_to_size()
Make the code more readable by hiding big formulas in an inline
function with a nice name.
2008-08-26 08:27:09 +02:00
Max Kellermann
0aedf7dd5a pass max_chunks to calculateCrossFadeChunks()
Make calculateCrossFadeChunks() more generic and portable by
eliminating global variable access.
2008-08-26 08:27:09 +02:00
Max Kellermann
0fc2422cd0 converted MpdTagItem.type to an enum
Don't use CPP macros when you can use C enum... this also allows
better type checking.
2008-08-26 08:27:09 +02:00
Max Kellermann
e754ed01a7 renamed functions in decoder_list.h
InputPlugin to decoder_plugin, and no camelCase.
2008-08-26 08:27:09 +02:00
Max Kellermann
772d3da98a no camel case in struct decoder_plugin 2008-08-26 08:27:08 +02:00
Max Kellermann
f1a014d094 renamed the InputPlugin function types
Continuing the effort to rename InputPlugin to decoder_plugin...
2008-08-26 08:27:08 +02:00
Max Kellermann
41c5fbbb07 renamed inputPlugin.* to decoder_list.*
Since inputPlugin.c manages the list of registered decoders, we should
rename the source file.
2008-08-26 08:27:08 +02:00
Max Kellermann
f5711e28da moved decoder externs to inputPlugin.c
The decoder_plugin instances are only used inputPlugin.c, so move them
from the header file.
2008-08-26 08:27:08 +02:00
Max Kellermann
e41be362a1 renamed InputPlugin to struct decoder_plugin
"decoder plugin" is a better name than "input plugin", since the
plugin does not actually do the input - InputStream does.  Also don't
use typedef, so we can forward-declare it if required.
2008-08-26 08:27:08 +02:00
Max Kellermann
cdaa26c81d no busy-waiting for the player process
The function player_command() inherited the busy-waiting algorithm
from the old code; throw in a wait_main_task() to do idle waiting.
2008-08-26 08:27:08 +02:00
Max Kellermann
b1de50f994 converted PlayerControl.state to enum
Don't write CPP when you can express the same in C...  macros vs enum
is a good example for that.
2008-08-26 08:27:08 +02:00
Max Kellermann
efde884a13 added PlayerControl.command
PlayerControl.command replaces the old attributes play, stop, pause,
closeAudio, lockQueue, unlockQueue, seek.  The main thread waits for
each command synchronously, so there can only be one command enabled
at a time anyway.
2008-08-26 08:27:07 +02:00
Max Kellermann
c7384b65ac eliminate OUTPUT_BUFFER_DC_STOP, OUTPUT_BUFFER_DC_SEEK
(Ab)use the decoder_command enumeration, which has nearly the same
values and the same meaning.
2008-08-26 08:27:07 +02:00
Max Kellermann
67bf4b448d added decoder_get_url()
The wavpack decoder plugin implements a hack, and it needs the song
URL for that.  This API (and the hack) should be revised later, but
add that function for now.
2008-08-26 08:27:07 +02:00