Charles Keepax [Thu, 8 Nov 2018 17:12:32 +0000 (17:12 +0000)]
tinycompress: Update headers to include AUDIOCODEC_BESPOKE
commit dbb6b94339e8 ("ALSA: compress: Add SND_AUDIOCODEC_BESPOKE") added
an additional CODEC type for bespoke CODECs. Update the local headers to
include this.
Reported-by: Andrew Ford <andrew.ford@cirrus.com> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: Vinod Koul <vkoul@kernel.org>
We get a warning in crecord for incorrect print specifier, fix it by using
right one %u for unsigned int
crecord.c:380:17: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘unsigned int’ [-Wformat=]
fprintf(finfo, "Recording file %s On Card %u device %u, with buffer of %lu bytes\n",
We get a warning in cplay for incorrect print specifier, fix it by using
right one %ld for long unsigned int.
cplay.c:327:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
fprintf(stderr, "codec ID %d is not supported\n", codec_id);
Charles Keepax [Fri, 13 Apr 2018 11:58:59 +0000 (12:58 +0100)]
crecord: Use whole buffer requested by user
Currently, crecord will only actually use 1 fragment worth of its
internal buffer no matter what the user requests. Correct this so that
the whole buffer requested by the user is used for copying data.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Katsuhiro Suzuki [Tue, 23 Jan 2018 02:33:11 +0000 (11:33 +0900)]
cplay: fix size and nmemb of mp3 header of fread
This patch swaps 'size' and 'nmemb' arguments of fread.
The fread returns always 1 (because 'nmemb' is 1) so checking
the return value is always failure.
This patch adds a -I command line option to set the codec ID,
either from a defined set of string values or as a number.
After discussion with Vinod it was agreed that we should only
allow writing to a file if we support creating the correct container
file format for that data. As we currently only have support for
creating WAV files only PCM data can be written to a file. Other
formats can be sent raw to stdout.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
- Incorrect indenting of arguments to capture_samples()
- Wrap long line in capture_samples()
- Added a blank line in main() for readability
- Deleted extra trailing blank line at end of file
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Vinod Koul [Sat, 9 Jan 2016 08:12:46 +0000 (13:42 +0530)]
tinycompress: crec: make functions static
Sparse rightly complains some functions should be static so make them static
crec.c:113:26: warning: symbol 'blank_wave_header' was not declared. Should it be static?
crec.c:239:6: warning: symbol 'capture_samples' was not declared. Should it be static?
Vinod Koul [Sat, 9 Jan 2016 08:12:46 +0000 (13:42 +0530)]
tinycompress: cplay: make functions static
Sparse rightly complains some functions should be static so make them static
cplay.c:100:5: warning: symbol 'parse_mp3_header' was not declared. Should it be static?
cplay.c:129:5: warning: symbol 'check_codec_format_supported' was not declared. Should it be static?
../../include/tinycompress/tinymp3.h:66:11: warning: symbol 'mp3_sample_rates' was not declared. Should it be static?
../../include/tinycompress/tinymp3.h:72:11: warning: symbol 'mp3_bit_rates' was not declared. Should it be static?
crec: Always read whole number of fragments when length limit specified
This patch removes the lines that adjusted the read size to exactly
read to the end of the calculated length in bytes. Doing this could
lead to invalid fragment sizes being requested which may then cause
a read error on some codecs.
Instead we keep reading whole fragments until we have >= length bytes
of data captured.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Vinod Koul [Fri, 8 May 2015 10:30:02 +0000 (16:00 +0530)]
cplay: check the values of fread
This fixes the following warning:
cplay.c: In function ‘play_samples’:
cplay.c:219:7: warning: ignoring return value of ‘fread’, declared with
attribute warn_unused_result [-Wunused-result]
fread(&header, sizeof(header), 1, file);
Qais Yousef [Tue, 5 May 2015 10:21:11 +0000 (11:21 +0100)]
tinycompress.h: explicitly include required headers
tinycompress.h was relying on other files to include linux/types.h and stdbool.h
which are required by it. Explicitly include it to fix compile errors when external
program tries to include this header.
The code was not compiling when mode was not passed to open()
while using O_CREAT offset. Passed mode to the open() alongwith
O_CREAT to specify the attributes of file and fix compile issue.
Signed-off-by: Ammar Zahid Ali Syed <ammar.zhd@googlemail.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Vinod Koul [Thu, 19 Jun 2014 09:33:17 +0000 (15:03 +0530)]
tinycompress: update headers for packed, aligned
commit "6b24a8dd: ALSA: compress: fix the struct alignment to 4 bytes" updated
compress struct to force packed and aligned to 4 bytes. Update here a s well
Vinod Koul [Thu, 19 Jun 2014 09:27:59 +0000 (14:57 +0530)]
tinycompress: update compress headers for sample rate field
commit "929559b: ALSA: compress: add num_sample_rates in snd_codec_desc" adds
array for passing sample rate instead of bit map. Update the local header as
well
compress: compress_wait() must return error if timed out
The caller must be certain that a return of 0 really means
that compress is ready for more data, so when poll() returns
0 for a timeout we must report that as an error.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
compress: Must check for POLLERR before POLLOUT/POLLIN
In the case of error the ALSA compressed driver sets revents as
(POLLOUT | POLLWRNORM | POLLERR) or (POLLIN | POLLWRNORM | POLLERR).
So we can't assume that POLLOUT or POLLIN indicate success, we must
check for POLLERR first.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Support for non-blocking I/O, based on API of main alsalib.
In non-blocking mode a compress_write() will return without
blocking after it has written all bytes that will fit in the
buffer and compress_read() will return after it has read all
bytes available from the buffer. Use compress_wait() to wait
for free write space or available read bytes.
Non-blocking mode is enabled and disabled using compress_nonblock().
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
compress: do not poll if enough space to write remaining data
Changes the poll logic in compress_write() to prevent
it polling if there is enough available space to write
all remaining data. Previously the logic always polled for
an entire fragment to become available before starting the
first write.
This change allows short writes of < frag_size, which is likely
at the end of a stream.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
The compress API are expected to return a negative value on an error
with errno indicating the type of error. But in some cases, this is
not happening.
The fix is the oops function always returns -1 and the actual
error number is determined by the global variable errno.
Signed-off-by: Lakshmi N Vinnakota <lakshmi.n.vinnakota@intel.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Fixes the oops() in compress_get_hpointer() to return
-ENODATA instead of errno if the sample rate is zero.
The value in errno here is not related to the reason
we are returning an error.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Vinod Koul [Sun, 24 Feb 2013 14:22:21 +0000 (19:52 +0530)]
tinycompress: version 0.1.0
First version release of tinycompress library
dc06a66 tinycompress: version 0.1.0 10fef72 tinycompres: remove unused variable e0810c0 tinycompress: add gapless meta data APIs 8f18a69 cplay: support auto-configuration of fragment size and count 495e5b4 compress: Add makefile for building under standard linux d815993 compress: Add missing header includes bb2650a compress: Block if unable to write all data in single write() acc0960 compress: Allow client to pass "don't care" for fragment size/number e24adce compress: Handle case of pause() during compress_write() 83f0278 compress: Remove hardcoded limit on length of poll() wait f9f3d07 compress: Fix incorrect error message on compress_resume() 14af3b0 compress: Change running from bitfield to plain int eb63cc9 compress: Remove unused buffer_size member from struct compress 21663cc compress: Change compress_write() to take buffer as const void * 0d20d8b compress: Add function to get timestamp in samples 0931870 compress: fix arithmetic exception in compress_get_hpointer 00732dc compress: cache the config values passed 2a455ef compress: remove unused variables 7191a18 compress: make variable 'running' as unsigned dca2963 compress: Do not put newlines on error messages 24a91e3 compress: Return error messages correctly from compress_open 590afad compress: Return error when failing to allocate compress struct 30b28ff compress: Extend limit on error messages bbb37bb compress: add compress_resume cf2e8d4 compress: write when we have a fragment to write 5d5a573 compress: fix the timestamp calculation 55b29e9 initial creation
Vinod Koul [Fri, 22 Feb 2013 09:49:02 +0000 (15:19 +0530)]
tinycompress: add gapless meta data APIs
Based on newly introduced kernel API, we add gapless metatdata to the library.
Since kernel can recieve only key/value pairs for metadata we add a structure for
gapless_metdata and handle this in library
cplay: support auto-configuration of fragment size and count
Default the fragment size and count to zero to take advantage
of the auto-configuration support that was added to tinycompress.
If user doesn't override these by specifying -f and -b values
on the command line, they will be passed to tinycompress as zero
and tinycompress will query the driver for size and count.
compress: Block if unable to write all data in single write()
Previously compress_write() would only block on poll() if the
available space < fragment_size. If the device has a small fragment
size this could lead to it never blocking and instead looping around
doing many small writes. This is bad for power saving.
If we were unable to write all the remaining data in a single write
we want to block until the device reaches a buffer high water mark,
to allow the CPU to sleep.
This change will always attempt to issue the first write providing
avail >= fragment_size. All subsequent loops will block on poll()
before attempting another write() unless there is enough buffer space
to write all remaining data.
compress: Allow client to pass "don't care" for fragment size/number
Client cannot know what is a sensible fragment size and count
for the device unless it has prior knowledge of the precise
hardware. To allow for generic clients not hardcoded for particular
hardware, this change allows fragment_size and fragments to be
passed as 0, meaning "don't care" and tinycompress will choose
default values read from the driver.
compress: Handle case of pause() during compress_write()
If stream is paused() during a compress_write() the poll()
will return 0 or -EBADFD, or the write() will return -EBADFD.
This is not an error so compress_write() should not pass an
error code to the caller. It should abort the write and then
return the number of bytes it had written up to that point.
compress: Remove hardcoded limit on length of poll() wait
For best power-saving we want to sleep on poll() for as long as
possible, we don't want to wake unnecessarily for arbitrary time
limits. Adds function compress_set_max_poll_wait() so that
client can configure the poll() timeout.
compress: Change running from bitfield to plain int
Declaring running as a single-bit bitfield does not save any space
or give any coding advantages, but does leave potential opportunities
for the compiler to be inefficient in how it handles bitfields compared
to how it would handle a machine int.
compress: Add function to get timestamp in samples
The compress_get_hpointer() converts the timestamp into actual
time. But Android needs it in samples. To avoid the inefficiency
of using compress_get_hpointer() and converting into time and then
back into samples, this change adds compress_get_tstamp() which
returns the raw sample count.
Charles Keepax [Fri, 25 Jan 2013 10:43:14 +0000 (10:43 +0000)]
compress: Do not put newlines on error messages
In the oops function text is appended onto the end of the supplied error
message, so newlines appear in the middle of error messages. This patch
removes all newlines from supplied error messages.
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Charles Keepax [Fri, 25 Jan 2013 10:43:13 +0000 (10:43 +0000)]
compress: Return error messages correctly from compress_open
The allocated compress object will be freed and bad_compress will be
returned, so error messages written to the allocated compress struct
will be lost. This patch writes error messages to bad_compress for error
paths in compress_open, ensuring that error messages are returned
correctly.
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>