parecord: Automatically detect file format from extension

And fix a small bug in pa_sndfile_format_from_string.
This commit is contained in:
Maarten Bosmans 2011-06-27 01:19:07 +02:00 committed by Colin Guthrie
parent ad1e0431fb
commit aa7bc322e2
2 changed files with 12 additions and 8 deletions

View file

@ -446,7 +446,7 @@ int pa_sndfile_format_from_string(const char *name) {
pa_assert_se(sf_command(NULL, SFC_GET_FORMAT_MAJOR, &fi, sizeof(fi)) == 0); pa_assert_se(sf_command(NULL, SFC_GET_FORMAT_MAJOR, &fi, sizeof(fi)) == 0);
if (strncasecmp(name, fi.extension, strlen(name)) == 0) if (strncasecmp(name, fi.name, strlen(name)) == 0)
return fi.format; return fi.format;
} }

View file

@ -926,8 +926,6 @@ int main(int argc, char *argv[]) {
break; break;
case ARG_FILE_FORMAT: case ARG_FILE_FORMAT:
raw = FALSE;
if (optarg) { if (optarg) {
if ((file_format = pa_sndfile_format_from_string(optarg)) < 0) { if ((file_format = pa_sndfile_format_from_string(optarg)) < 0) {
pa_log(_("Unknown file format %s."), optarg); pa_log(_("Unknown file format %s."), optarg);
@ -986,13 +984,19 @@ int main(int argc, char *argv[]) {
goto quit; goto quit;
} }
/* Transparently upgrade classic .wav to wavex for multichannel audio */
if (file_format <= 0) { if (file_format <= 0) {
if ((sample_spec.channels == 2 && (!channel_map_set || (channel_map.map[0] == PA_CHANNEL_POSITION_LEFT && char *extension;
channel_map.map[1] == PA_CHANNEL_POSITION_RIGHT))) || if (filename && (extension = strrchr(filename, '.')))
(sample_spec.channels == 1 && (!channel_map_set || (channel_map.map[0] == PA_CHANNEL_POSITION_MONO)))) file_format = pa_sndfile_format_from_string(extension+1);
if (file_format <= 0)
file_format = SF_FORMAT_WAV; file_format = SF_FORMAT_WAV;
else /* Transparently upgrade classic .wav to wavex for multichannel audio */
if (file_format == SF_FORMAT_WAV &&
(sample_spec.channels > 2 ||
(channel_map_set &&
!(sample_spec.channels == 1 && channel_map.map[0] == PA_CHANNEL_POSITION_MONO) &&
!(sample_spec.channels == 2 && channel_map.map[0] == PA_CHANNEL_POSITION_LEFT
&& channel_map.map[1] == PA_CHANNEL_POSITION_RIGHT))))
file_format = SF_FORMAT_WAVEX; file_format = SF_FORMAT_WAVEX;
} }