diff options
author | Marcus Müller <mmueller@gnuradio.org> | 2020-04-11 00:46:24 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2020-04-13 15:55:41 +0200 |
commit | 337b99e78fddb4589ebbc793d7f4784daa4314d8 (patch) | |
tree | 1f0003755f7a13056ce2600475298a4dbcaa6ef0 /gr-audio/lib/oss/oss_source.cc | |
parent | 0f88db1ef0569bf6fcd5e9c843da38d487a6f54b (diff) |
audio: replace stderr logging by calls to GR's logging facilties
This is a bit special, in that audio systems tend to have their own ways
of going wrong, and there's platform-specific development debugging
infrastructure in there, which I intentionally did not touch.
I did touch a few commented lines of code in the intention of, if you
enable that line of logging, it should be consistent with the rest.
There's copious amounts of untouched stderr-logging in `#if 0`-disabled
code in OSX's infrastructure.
Diffstat (limited to 'gr-audio/lib/oss/oss_source.cc')
-rw-r--r-- | gr-audio/lib/oss/oss_source.cc | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/gr-audio/lib/oss/oss_source.cc b/gr-audio/lib/oss/oss_source.cc index 2792d70a99..0ac46007b2 100644 --- a/gr-audio/lib/oss/oss_source.cc +++ b/gr-audio/lib/oss/oss_source.cc @@ -52,8 +52,9 @@ oss_source::oss_source(int sampling_rate, const std::string device_name, bool ok d_chunk_size(0) { if ((d_fd = open(d_device_name.c_str(), O_RDONLY)) < 0) { - fprintf(stderr, "audio_oss_source: "); - perror(d_device_name.c_str()); + GR_LOG_ERROR(d_logger, + boost::format("opening device %s: %s") % d_device_name % + strerror(errno)); throw std::runtime_error("audio_oss_source"); } @@ -68,31 +69,36 @@ oss_source::oss_source(int sampling_rate, const std::string device_name, bool ok int format = AFMT_S16_NE; int orig_format = format; if (ioctl(d_fd, SNDCTL_DSP_SETFMT, &format) < 0) { - std::cerr << "audio_oss_source: " << d_device_name << " ioctl failed\n"; - perror(d_device_name.c_str()); + GR_LOG_ERROR(d_logger, + boost::format("%s ioctl failed %s") % d_device_name % + strerror(errno)); throw std::runtime_error("audio_oss_source"); } if (format != orig_format) { - fprintf(stderr, "audio_oss_source: unable to support format %d\n", orig_format); - fprintf(stderr, " card requested %d instead.\n", format); + GR_LOG_ERROR( + d_logger, + boost::format("%s unable to support format %d. card requested %d instead.") % + orig_format % format); } // set to stereo no matter what. Some hardware only does stereo int channels = 2; if (ioctl(d_fd, SNDCTL_DSP_CHANNELS, &channels) < 0 || channels != 2) { - perror("audio_oss_source: could not set STEREO mode"); + GR_LOG_ERROR(d_logger, + boost::format("could not set STEREO mode: %s") % strerror(errno)); throw std::runtime_error("audio_oss_source"); } // set sampling freq int sf = sampling_rate; if (ioctl(d_fd, SNDCTL_DSP_SPEED, &sf) < 0) { - std::cerr << "audio_oss_source: " << d_device_name << ": invalid sampling_rate " - << sampling_rate << "\n"; + GR_LOG_ERROR(d_logger, + boost::format("ERROR %s: invalid sampling_rate %d") % d_device_name % + sampling_rate); sampling_rate = 8000; if (ioctl(d_fd, SNDCTL_DSP_SPEED, &sf) < 0) { - std::cerr << "audio_oss_source: failed to set sampling_rate to 8000\n"; + GR_LOG_ERROR(d_logger, "failed to set sampling_rate to 8000"); throw std::runtime_error("audio_oss_source"); } } @@ -127,12 +133,13 @@ int oss_source::work(int noutput_items, int result_nbytes = read(d_fd, d_buffer, nbytes); if (result_nbytes < 0) { - perror("audio_oss_source"); + GR_LOG_ERROR(d_logger, + boost::format("audio_oss_source: %s") % strerror(errno)); return -1; // say we're done } if ((result_nbytes & (bytes_per_item - 1)) != 0) { - fprintf(stderr, "audio_oss_source: internal error.\n"); + GR_LOG_ERROR(d_logger, "internal error."); throw std::runtime_error("internal error"); } |