From 68b719391cf2844f60db75714e6d85bffc43638c Mon Sep 17 00:00:00 2001 From: K Henriksson Date: Sun, 4 Apr 2021 12:33:58 -0700 Subject: [PATCH 01/10] Add tip regarding mount dependencies Requested in #65. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 79dc7e19..a6418492 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ following entry in `/etc/fstab`: At this point the files `/mnt/music/**.flac` and `/mnt/music/**.ogg` will show up as `/mnt/mp3/**.mp3`. +**Tip:** If your mp3fs mount fails because the underlying filesystem hasn't +been mounted yet, try adding the `x-systemd.requires-mounts-for=/mnt/music` +mount option, where `/mnt/music` would be the location of the underlying mount. + ## How it Works When a file is opened, the decoder and encoder are initialised and the file From 55aa6f5a68ae0673c0582780d70d43aba6a6b543 Mon Sep 17 00:00:00 2001 From: K Henriksson Date: Thu, 8 Apr 2021 21:12:39 -0700 Subject: [PATCH 02/10] Reformat markdown according to latest pandoc --- INSTALL.md | 16 +++++------ Makefile.am | 6 ++-- NEWS.md | 72 ++++++++++++++++++++++++------------------------ README.md | 10 +++---- docker/README.md | 18 ++++++------ mp3fs.1.md | 35 ++++++++++------------- 6 files changed, 75 insertions(+), 82 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 9b49257c..2a9561d0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -4,17 +4,17 @@ mp3fs requires the following libraries: - - fuse (\>= 2.6.0) - - flac++ (\>= 1.1.4) - - libvorbis (\>= 1.3.0) - - lame - - libid3tag +- fuse (>= 2.6.0) +- flac++ (>= 1.1.4) +- libvorbis (>= 1.3.0) +- lame +- libid3tag If building from git, you'll also need: - - autoconf - - automake - - pandoc +- autoconf +- automake +- pandoc The commands to install the prerequisites follow. diff --git a/Makefile.am b/Makefile.am index 84b5d9ab..2bbbc478 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,14 +44,12 @@ faststaticcheck: @statictest/checkall fast # The special logic for mp3fs.1.md is because it needs certain features for -# manpage output. The weird sed logic is there to preserve '.\ ' sequences, -# and the check is made automatically passing because the headers aren't -# preserved properly. +# manpage output. The weird sed logic is there to preserve '.\ ' sequences. mdcheck: @set -e ; for f in *.md */*.md ; do \ echo "Checking format for $$f." ; \ if [ "$$f" = mp3fs.1.md ] ; then \ - sed 's/\.\\/!./g' "$$f" | pandoc -d .pandocfmt.yaml -f markdown -t markdown | sed 's/!\./.\\/g' | diff -u $$f - || : ; \ + sed 's/\.\\/!./g' "$$f" | pandoc -d .pandocfmt.yaml -f markdown -t markdown | sed 's/!\./.\\/g' | diff -u $$f - ; \ else \ pandoc -d .pandocfmt.yaml "$$f" | diff -u "$$f" - ; \ fi ; \ diff --git a/NEWS.md b/NEWS.md index 759cf852..f734dce5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,36 +11,36 @@ This contains various bug fixes, mostly. Fixes/improvements: - - Recognize upper/mixed case in input filenames - - Fix file size handling with and without cache - - Various code simplifications/cleanup +- Recognize upper/mixed case in input filenames +- Fix file size handling with and without cache +- Various code simplifications/cleanup New features: - - Log lines now include thread ID and can be customized. +- Log lines now include thread ID and can be customized. ## Important changes in 1.0 (2020-05-24) -mp3fs 1.0 is finally here\! +mp3fs 1.0 is finally here! Fixes/code improvements: - - Many, many bug fixes (buffer overflows, memory leaks, and others) - - Memory handling improvements (using RAII with C++ nearly everywhere) - - Adopting C++11 and modernizing code - - Static tests for code (e.g. clang-format, clang-tidy, IWYU) +- Many, many bug fixes (buffer overflows, memory leaks, and others) +- Memory handling improvements (using RAII with C++ nearly everywhere) +- Adopting C++11 and modernizing code +- Static tests for code (e.g. clang-format, clang-tidy, IWYU) New features: - - Ogg Vorbis decoding support - - MP3 VBR encoding support - - Improved, much more customizable logging +- Ogg Vorbis decoding support +- MP3 VBR encoding support +- Improved, much more customizable logging Other: - - Docs licensed under GPL 3+ (now entire codebase is distributable as GPL 3) - - All docs switched to Markdown (including manpage, using pandoc) - - Docker image now available +- Docs licensed under GPL 3+ (now entire codebase is distributable as GPL 3) +- All docs switched to Markdown (including manpage, using pandoc) +- Docker image now available ## Important changes in 0.91 (2014-05-14) @@ -48,23 +48,23 @@ This contains mainly bug fixes. Changes in this release: - - Fixed a segfault caused by an overflow reading the list of available +- Fixed a segfault caused by an overflow reading the list of available decoders. - - A number of problems with the previous distribution tar are now fixed. - - The output of `mp3fs --version` has been made more complete. +- A number of problems with the previous distribution tar are now fixed. +- The output of `mp3fs --version` has been made more complete. ## Important changes in 0.9 (2014-04-06) -This is a major new release, and brings us very close to a 1.0 release\! +This is a major new release, and brings us very close to a 1.0 release! Changes in this release: - - All transcoding code has been completely rewritten. Encoding and decoding +- All transcoding code has been completely rewritten. Encoding and decoding have been abstracted out into base classes defining interfaces that can be implemented by different codec classes, with just a FLAC decoder and MP3 encoder at the moment. - - The build system has been modified as well to support this usage. - - A number of small bugs or code inefficiencies have been fixed. +- The build system has been modified as well to support this usage. +- A number of small bugs or code inefficiencies have been fixed. ## Important changes in 0.32 (2012-06-18) @@ -72,10 +72,10 @@ This release has a lot of bug fixes and some code cleanup. Changes in this release: - - The file size calculation should always be correct. - - A crash affecting programs like scp that might try to access past the end +- The file size calculation should always be correct. +- A crash affecting programs like scp that might try to access past the end of the file has been fixed. - - Too many other little fixes were made to list here. See the ChangeLog for +- Too many other little fixes were made to list here. See the ChangeLog for full details. ## Important changes in 0.31 (2011-12-04) @@ -84,11 +84,11 @@ This is a minor update, with bug fixes and a new feature. Changes in this release: - - The ReplayGain support added earlier now can be configured through the +- The ReplayGain support added earlier now can be configured through the command line. - - Filename translation (from .flac to .mp3) is now fixed on filesystems such - as XFS that do not populate dirent.d\_type. - - A couple other minor bugs fixes and changes were made. +- Filename translation (from .flac to .mp3) is now fixed on filesystems such + as XFS that do not populate dirent.d_type. +- A couple other minor bugs fixes and changes were made. ## Important changes in 0.30 (2010-12-01) @@ -97,17 +97,17 @@ release. Changes in this release: - - Support for additional metadata tags has been added. (From Gregor Zurowski) - - Documentation improvements: the help message is more useful, and a man page +- Support for additional metadata tags has been added. (From Gregor Zurowski) +- Documentation improvements: the help message is more useful, and a man page has been added. - - Choosing bitrate is now done with a command-line or mount option, rather +- Choosing bitrate is now done with a command-line or mount option, rather than the old comma syntax. - - A new option to select LAME encoding quality is now available. (From Gregor +- A new option to select LAME encoding quality is now available. (From Gregor Zurowski) - - Debug output can be enabled at runtime. - - Old external libraries included in distribution (StringIO, talloc) have +- Debug output can be enabled at runtime. +- Old external libraries included in distribution (StringIO, talloc) have been removed and replaced. - - Numerous bug fixes have been made. (Some from Gregor Zurowski) +- Numerous bug fixes have been made. (Some from Gregor Zurowski) ... diff --git a/README.md b/README.md index a6418492..53ce5a5a 100644 --- a/README.md +++ b/README.md @@ -69,11 +69,11 @@ mp3fs uses Git for revision control. You can obtain the full repository with: mp3fs is written in a mixture of C and C++ and uses the following libraries: - - [FUSE](http://fuse.sourceforge.net/) - - [FLAC](http://flac.sourceforge.net/) - - [libvorbis](http://www.xiph.org/vorbis/) - - [LAME](http://lame.sourceforge.net/) - - [libid3tag](http://www.underbit.com/products/mad/) +- [FUSE](http://fuse.sourceforge.net/) +- [FLAC](http://flac.sourceforge.net/) +- [libvorbis](http://www.xiph.org/vorbis/) +- [LAME](http://lame.sourceforge.net/) +- [libid3tag](http://www.underbit.com/products/mad/) ## Authors diff --git a/docker/README.md b/docker/README.md index 0a716728..09e417af 100644 --- a/docker/README.md +++ b/docker/README.md @@ -20,24 +20,24 @@ $ docker run --device /dev/fuse \ There's a lot here, so let's unpack the command. - - `docker run` is how you run a docker container. - - `--device /dev/fuse` is needed to allow FUSE access. - - `--cap-add SYS_ADMIN` is necessary to mount filesystems inside Docker +- `docker run` is how you run a docker container. +- `--device /dev/fuse` is needed to allow FUSE access. +- `--cap-add SYS_ADMIN` is necessary to mount filesystems inside Docker containers. This might not be needed in the future for FUSE (see - [docker/for-linux\#321](https://github.com/docker/for-linux/issues/321)), + [docker/for-linux#321](https://github.com/docker/for-linux/issues/321)), but for now it's required. - - `--security-opt apparmor:unconfined` is also needed to mount filesystems +- `--security-opt apparmor:unconfined` is also needed to mount filesystems inside Docker. - - `-v /home/khenriks/Music:/music:ro` mounts the host directory +- `-v /home/khenriks/Music:/music:ro` mounts the host directory `/home/khenriks/Music` read-only in the container. This will be the input for mp3fs. The host directory can be replaced with anything, but `/music` is required because that's where the container expects it. - - `-v /tmp/mp3:/mnt:shared` mounts the directory `/tmp/mp3` inside the +- `-v /tmp/mp3:/mnt:shared` mounts the directory `/tmp/mp3` inside the container. This will be the output from mp3fs. Again, the host directory can be anything, but `/mnt` is required by the container. `shared` makes the mp3fs mount inside the container show up in the host directory outside. - - `khenriks/mp3fs` is the name of the Docker image. - - `-b 256` is the normal mp3fs flag for bitrate. You can use any mp3fs flags +- `khenriks/mp3fs` is the name of the Docker image. +- `-b 256` is the normal mp3fs flag for bitrate. You can use any mp3fs flags here, after the image name. ## Docker Compose diff --git a/mp3fs.1.md b/mp3fs.1.md index 3ab376e8..03f6b767 100644 --- a/mp3fs.1.md +++ b/mp3fs.1.md @@ -1,29 +1,25 @@ -% MP3FS(1) | User Commands --- adjusting: l hyphenate: false -... +title: MP3FS(1) \| User Commands +--- -NAME -==== +# NAME mp3fs - mounts and transcodes FLACs and OGGs to MP3s on the fly -SYNOPSIS -======== +# SYNOPSIS -**mp3fs** \[*OPTION*\]...\ *IN\_DIR* *OUT\_DIR* +**mp3fs** \[*OPTION*\]...\ *IN_DIR* *OUT_DIR* -DESCRIPTION -=========== +# DESCRIPTION -The mp3fs(1) command will mount the directory *IN\_DIR* on *OUT\_DIR*. -Thereafter, accessing *OUT\_DIR* will show the contents of *IN\_DIR*, with all +The mp3fs(1) command will mount the directory *IN_DIR* on *OUT_DIR*. +Thereafter, accessing *OUT_DIR* will show the contents of *IN_DIR*, with all FLAC/Ogg Vorbis files transparently renamed and transcoded to MP3 format upon access. -OPTIONS -======= +# OPTIONS **-b, -obitrate**=*RATE* @@ -73,7 +69,7 @@ OPTIONS : Print usage information. -**--log\_format, -olog\_format**=*FORMAT* +**--log_format, -olog_format**=*FORMAT* : Specify the format to use for log messages, with the following substitutions: @@ -86,19 +82,19 @@ OPTIONS %T - time, formatted as YYYY-MM-DD HH:MM:SS - The default is "[%T] tid=%I %L: %M". + The default is "\[%T\] tid=%I %L: %M". -**--log\_maxlevel, -olog\_maxlevel**=*LEVEL* +**--log_maxlevel, -olog_maxlevel**=*LEVEL* : Set the maximum level of messages to log, either ERROR, INFO, or DEBUG. Defaults to INFO, and forced to DEBUG in debug mode. Note that this does not enable logging; other log flags must be set to specify where to log. -**--log\_stderr, -olog\_stderr** +**--log_stderr, -olog_stderr** : Output logging messages to stderr. Enabled in debug mode. -**--log\_syslog, -olog\_syslog** +**--log_syslog, -olog_syslog** : Output logging messages to the system log. @@ -132,8 +128,7 @@ OPTIONS : Output version information. -COPYRIGHT -========= +# COPYRIGHT Copyright (C) 2006-2008 David Collett and 2008-2013 K.\ Henriksson. This is free software: you are free to change and redistribute it under the terms of From f9409ed7ec006d246c1d0f3929d963d525858256 Mon Sep 17 00:00:00 2001 From: K Henriksson Date: Sun, 25 Apr 2021 21:29:09 -0700 Subject: [PATCH 03/10] Convert mp3fs.h to C++ This uses standard C++ syntax for the params struct. --- src/mp3fs.cc | 4 ++-- src/mp3fs.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mp3fs.cc b/src/mp3fs.cc index f846da90..8c78f4e6 100644 --- a/src/mp3fs.cc +++ b/src/mp3fs.cc @@ -56,7 +56,7 @@ constexpr int kQualityMax = 9; enum { KEY_HELP, KEY_VERSION, KEY_KEEP_OPT }; #define MP3FS_OPT(t, p, v) \ - { t, offsetof(struct mp3fs_params, p), v } + { t, offsetof(mp3fs_params, p), v } // Redefine FUSE_OPT_KEY to avoid warning. #undef FUSE_OPT_KEY @@ -201,7 +201,7 @@ int mp3fs_opt_proc(void* /*unused*/, const char* arg, int key, } // namespace -struct mp3fs_params params = { +mp3fs_params params = { .basepath = nullptr, .bitrate = kDefaultBitrate, .debug = 0, diff --git a/src/mp3fs.h b/src/mp3fs.h index e3149610..d8eeda25 100644 --- a/src/mp3fs.h +++ b/src/mp3fs.h @@ -23,7 +23,7 @@ #define MP3FS_MP3FS_H_ /* Global program parameters */ -extern struct mp3fs_params { +struct mp3fs_params { const char* basepath; int bitrate; int debug; @@ -38,6 +38,8 @@ extern struct mp3fs_params { int quality; unsigned int statcachesize; int vbr; -} params; +}; + +extern mp3fs_params params; #endif // MP3FS_MP3FS_H_ From 65f9fab27807dcbb1bdb71fb8a526a2009d5ca3e Mon Sep 17 00:00:00 2001 From: K Henriksson Date: Tue, 27 Apr 2021 19:40:03 -0700 Subject: [PATCH 04/10] Clean up unused logic in fpcompare --- test/fpcompare.c | 60 +++++++----------------------------------------- 1 file changed, 8 insertions(+), 52 deletions(-) diff --git a/test/fpcompare.c b/test/fpcompare.c index 695eb39b..4d0b9826 100644 --- a/test/fpcompare.c +++ b/test/fpcompare.c @@ -2,8 +2,6 @@ #include #include #include -#include -#include #define NUM_SAMPLES 2048 @@ -47,60 +45,22 @@ int decode_audio_file(ChromaprintContext* ctx, const char* file_name) { } int main(int argc, char** argv) { - int num_file_names = 0; int raw_fingerprint_size[2]; uint32_t* raw_fingerprints[2] = {0}; - char* file_names[2]; ChromaprintContext* chromaprint_ctx; - int algo = CHROMAPRINT_ALGORITHM_DEFAULT, num_failed = 0; - - for (int i = 1; i < argc; i++) { - char* arg = argv[i]; - if (!strcmp(arg, "-algo") && i + 1 < argc) { - const char* v = argv[++i]; - if (!strcmp(v, "test1")) { - algo = CHROMAPRINT_ALGORITHM_TEST1; - } else if (!strcmp(v, "test2")) { - algo = CHROMAPRINT_ALGORITHM_TEST2; - } else if (!strcmp(v, "test3")) { - algo = CHROMAPRINT_ALGORITHM_TEST3; - } else if (!strcmp(v, "test4")) { - algo = CHROMAPRINT_ALGORITHM_TEST4; - } else { - fprintf(stderr, - "WARNING: unknown algorithm, using the default\n"); - } - } else if (!strcmp(arg, "-set") && i + 1 < argc) { - i += 1; - } else if (num_file_names < 2) { - file_names[num_file_names++] = argv[i]; - } - } + int num_failed = 0; - if (num_file_names != 2) { - printf("usage: %s [OPTIONS] FILE1 FILE2\n\n", argv[0]); + if (argc != 3) { + printf("usage: %s FILE1 FILE2\n\n", argv[0]); return 2; } sox_format_init(); - chromaprint_ctx = chromaprint_new(algo); - - for (int i = 1; i < argc; i++) { - char* arg = argv[i]; - if (!strcmp(arg, "-set") && i + 1 < argc) { - char* name = argv[++i]; - char* value = strchr(name, '='); - if (value) { - *value++ = '\0'; - chromaprint_set_option(chromaprint_ctx, name, - (int)strtol(value, NULL, 0)); - } - } - } + chromaprint_ctx = chromaprint_new(CHROMAPRINT_ALGORITHM_DEFAULT); - for (int i = 0; i < num_file_names; i++) { - char* file_name = file_names[i]; + for (int i = 0; i < 2; i++) { + char* file_name = argv[i + 1]; if (!decode_audio_file(chromaprint_ctx, file_name)) { fprintf(stderr, "ERROR: unable to calculate fingerprint for file %s, " @@ -141,12 +101,8 @@ int main(int argc, char** argv) { printf("1.0\n"); } - if (raw_fingerprints[0]) { - chromaprint_dealloc(raw_fingerprints[0]); - } - if (raw_fingerprints[1]) { - chromaprint_dealloc(raw_fingerprints[1]); - } + chromaprint_dealloc(raw_fingerprints[0]); + chromaprint_dealloc(raw_fingerprints[1]); chromaprint_free(chromaprint_ctx); sox_format_quit(); From 3aa58487a66cc8f0d2c0753b93a2d617acf6297c Mon Sep 17 00:00:00 2001 From: K Henriksson Date: Tue, 27 Apr 2021 19:49:53 -0700 Subject: [PATCH 05/10] Address warnings from newest clang-tidy --- src/buffer.cc | 14 +++++++------- src/buffer.h | 17 +++++++++-------- src/codecs/coders.h | 7 ++++--- src/codecs/flac_decoder.cc | 6 +++--- src/codecs/mp3_encoder.cc | 20 +++++++++++--------- src/codecs/mp3_encoder.h | 6 +++--- src/codecs/picture.h | 2 +- src/fuseops.cc | 2 +- src/logging.cc | 3 ++- src/transcode.cc | 4 ++-- test/fpcompare.c | 2 +- 11 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 1d85b0f3..a28460fb 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -29,24 +29,24 @@ void Buffer::write(const std::vector& data, bool extend_buffer) { main_data_.insert(main_data_.end(), data.begin(), data.end()); if (main_data_.size() > static_cast(end_offset_)) { if (extend_buffer) { - end_offset_ = main_data_.size(); + end_offset_ = static_cast(main_data_.size()); } else { main_data_.resize(end_offset_); } } } -void Buffer::write_to(const std::vector& data, std::streamoff offset) { +void Buffer::write_to(const std::vector& data, std::ptrdiff_t offset) { std::copy(data.begin(), data.end(), main_data_.begin() + offset); } void Buffer::write_end(const std::vector& data, - std::streamoff offset) { + std::ptrdiff_t offset) { end_data_ = data; end_offset_ = offset; } -void Buffer::copy_into(uint8_t* out_data, std::streamoff offset, +void Buffer::copy_into(uint8_t* out_data, std::ptrdiff_t offset, size_t size) const { if (!valid_bytes(offset, size)) { Log(ERROR) << "Invalid offset=" << offset << " size=" << size @@ -60,19 +60,19 @@ void Buffer::copy_into(uint8_t* out_data, std::streamoff offset, } else { size_t start_size = main_data_.size() - offset; uint8_t* next = - std::copy_n(main_data_.end() - start_size, start_size, out_data); + std::copy_n(main_data_.begin() + offset, start_size, out_data); std::copy_n(end_data_.begin(), size - start_size, next); } } -bool Buffer::valid_bytes(std::streamoff offset, size_t size) const { +bool Buffer::valid_bytes(std::ptrdiff_t offset, size_t size) const { size_t end = offset + size; return offset >= 0 && end <= this->size() && (end <= main_data_.size() || offset >= end_offset_ || main_data_.size() == static_cast(end_offset_)); } -size_t Buffer::max_valid_bytes(std::streamoff offset) const { +size_t Buffer::max_valid_bytes(std::ptrdiff_t offset) const { if (static_cast(offset) > size()) { return 0; } diff --git a/src/buffer.h b/src/buffer.h index 1b2da7fc..3f869ea8 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -23,7 +23,6 @@ #include #include -#include #include class Buffer { @@ -45,7 +44,7 @@ class Buffer { * Write data to a specified position in the Buffer. Results in undefined * behavior if this section of the Buffer had not previously been filled in. */ - void write_to(const std::vector& data, std::streamoff offset); + void write_to(const std::vector& data, std::ptrdiff_t offset); /** * Write data that will be placed at the end of the Buffer. This overwrites @@ -54,7 +53,7 @@ class Buffer { * to write an empty buffer with an offset; doing so sets the total size of * the Buffer when there is no trailing data. */ - void write_end(const std::vector& data, std::streamoff offset); + void write_end(const std::vector& data, std::ptrdiff_t offset); /** * Give the size of data already written in the main segment. @@ -72,7 +71,7 @@ class Buffer { * * If the given range is not valid, an error will be logged. */ - void copy_into(uint8_t* out_data, std::streamoff offset, size_t size) const; + void copy_into(uint8_t* out_data, std::ptrdiff_t offset, size_t size) const; /** * Return whether the given number of bytes at the given offset are valid @@ -82,13 +81,13 @@ class Buffer { * end_data_ (subject to end_offset_), or overlaps the two and * main_data_.size() == end_offset_. */ - bool valid_bytes(std::streamoff offset, size_t size) const; + bool valid_bytes(std::ptrdiff_t offset, size_t size) const; /** * Return the maximum number of bytes that can be read from offset. This is * the maximum size such that valid_bytes(offset, size) == true. */ - size_t max_valid_bytes(std::streamoff offset) const; + size_t max_valid_bytes(std::ptrdiff_t offset) const; /** * Move end of main segment to start of end segment. @@ -98,12 +97,14 @@ class Buffer { /** * Move end segment to end of main segment. */ - void truncate() { end_offset_ = main_data_.size(); } + void truncate() { + end_offset_ = static_cast(main_data_.size()); + } private: std::vector main_data_; std::vector end_data_; - std::streamoff end_offset_ = 0; + std::ptrdiff_t end_offset_ = 0; }; #endif // MP3FS_BUFFER_H_ diff --git a/src/codecs/coders.h b/src/codecs/coders.h index 04c20b06..a78bdf8d 100644 --- a/src/codecs/coders.h +++ b/src/codecs/coders.h @@ -68,13 +68,14 @@ class Encoder { virtual void set_text_tag(int key, const char* value) = 0; virtual void set_picture_tag(const char* mime_type, int type, const char* description, const uint8_t* data, - int data_length) = 0; + unsigned int data_length) = 0; virtual void set_gain_db(double dbgain) = 0; void set_gain(double gainref, double album_gain, double track_gain); virtual int render_tag(size_t file_size) = 0; virtual size_t calculate_size() const = 0; - virtual int encode_pcm_data(const int32_t* const data[], int numsamples, - int sample_size) = 0; + virtual int encode_pcm_data(const int32_t* const data[], + unsigned int numsamples, + unsigned int sample_size) = 0; virtual int encode_finish() = 0; virtual bool no_partial_encode() { return true; } diff --git a/src/codecs/flac_decoder.cc b/src/codecs/flac_decoder.cc index a32f1a93..5b9f63eb 100644 --- a/src/codecs/flac_decoder.cc +++ b/src/codecs/flac_decoder.cc @@ -97,9 +97,9 @@ int FlacDecoder::process_metadata(Encoder* encoder) { return -1; } - if (encoder->set_stream_params(info.get_total_samples(), - info.get_sample_rate(), - info.get_channels()) == -1) { + if (encoder->set_stream_params( + info.get_total_samples(), static_cast(info.get_sample_rate()), + static_cast(info.get_channels())) == -1) { return -1; } diff --git a/src/codecs/mp3_encoder.cc b/src/codecs/mp3_encoder.cc index beeeac86..675eb498 100644 --- a/src/codecs/mp3_encoder.cc +++ b/src/codecs/mp3_encoder.cc @@ -208,7 +208,7 @@ void Mp3Encoder::set_text_tag(const int key, const char* value) { /* Set an ID3 picture ("APIC") tag. */ void Mp3Encoder::set_picture_tag(const char* mime_type, int type, const char* description, const uint8_t* data, - int data_length) { + unsigned int data_length) { struct id3_frame* frame = id3_frame_new("APIC"); id3_tag_attachframe(id3tag, frame); @@ -269,7 +269,8 @@ int Mp3Encoder::render_tag(size_t file_size) { if (file_size == 0) { file_size = calculate_size(); } - buffer_->write_end(tag1, file_size - id3v1_tag_length); + buffer_->write_end( + tag1, static_cast(file_size - id3v1_tag_length)); return 0; } @@ -314,8 +315,9 @@ size_t Mp3Encoder::calculate_size() const { * -2**(sample_size-1) to 2**(sample_size-1)-1. This is not coincidentally * the format used by the FLAC library. */ -int Mp3Encoder::encode_pcm_data(const int32_t* const data[], int numsamples, - int sample_size) { +int Mp3Encoder::encode_pcm_data(const int32_t* const data[], + unsigned int numsamples, + unsigned int sample_size) { /* * We need to properly resample input data to a format LAME wants. LAME * requires samples in a C89 sized type, left aligned (i.e. scaled to @@ -325,7 +327,7 @@ int Mp3Encoder::encode_pcm_data(const int32_t* const data[], int numsamples, * first to avoid integer overflow. */ std::vector lbuf(numsamples), rbuf(numsamples); - for (int i = 0; i < numsamples; ++i) { + for (unsigned int i = 0; i < numsamples; ++i) { lbuf[i] = data[0][i] << (sizeof(int) * kBitsPerByte - sample_size); /* ignore rbuf for mono data */ if (lame_get_num_channels(lame_encoder) > 1) { @@ -336,9 +338,9 @@ int Mp3Encoder::encode_pcm_data(const int32_t* const data[], int numsamples, // Buffer size formula recommended by LAME docs: 1.25 * samples + 7200 std::vector vbuffer(5 * numsamples / 4 + kBufferSlop); // NOLINT - int len = lame_encode_buffer_int(lame_encoder, &lbuf[0], &rbuf[0], - numsamples, vbuffer.data(), - static_cast(vbuffer.size())); + int len = lame_encode_buffer_int( + lame_encoder, &lbuf[0], &rbuf[0], static_cast(numsamples), + vbuffer.data(), static_cast(vbuffer.size())); if (len < 0) { return -1; } @@ -382,7 +384,7 @@ int Mp3Encoder::encode_finish() { if (vbr_tag_size > MAX_VBR_FRAME_SIZE) { return -1; } - buffer_->write_to(tail, id3size); + buffer_->write_to(tail, static_cast(id3size)); } return len; diff --git a/src/codecs/mp3_encoder.h b/src/codecs/mp3_encoder.h index 9105f536..12501474 100644 --- a/src/codecs/mp3_encoder.h +++ b/src/codecs/mp3_encoder.h @@ -44,12 +44,12 @@ class Mp3Encoder : public Encoder { void set_text_tag(int key, const char* value) override; void set_picture_tag(const char* mime_type, int type, const char* description, const uint8_t* data, - int data_length) override; + unsigned int data_length) override; void set_gain_db(double dbgain) override; int render_tag(size_t file_size) override; size_t calculate_size() const override; - int encode_pcm_data(const int32_t* const data[], int numsamples, - int sample_size) override; + int encode_pcm_data(const int32_t* const data[], unsigned int numsamples, + unsigned int sample_size) override; int encode_finish() override; /* diff --git a/src/codecs/picture.h b/src/codecs/picture.h index 7baeb54f..0dd67e4f 100644 --- a/src/codecs/picture.h +++ b/src/codecs/picture.h @@ -34,7 +34,7 @@ class Picture { bool decode(); - int get_type() const { return type; } + int get_type() const { return static_cast(type); } const char* get_mime_type() const { return mime_type.c_str(); } const char* get_description() const { return description.c_str(); } int get_data_length() const { diff --git a/src/fuseops.cc b/src/fuseops.cc index e9834284..604ddeb1 100644 --- a/src/fuseops.cc +++ b/src/fuseops.cc @@ -140,7 +140,7 @@ int mp3fs_getattr(const char* p, struct stat* stbuf) { return -errno; } - stbuf->st_size = trans.get_size(); + stbuf->st_size = static_cast(trans.get_size()); stbuf->st_blocks = (stbuf->st_size + kBytesPerBlock - 1) / kBytesPerBlock; } diff --git a/src/logging.cc b/src/logging.cc index 42f19e72..fb229c4d 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -43,7 +44,7 @@ std::string MultiSubstitute(std::string src, for (const auto& kv : subs) { if (std::equal(kv.first.begin(), kv.first.end(), it)) { result.append(kv.second); - it += kv.first.length(); + it += static_cast(kv.first.length()); matched = true; break; } diff --git a/src/transcode.cc b/src/transcode.cc index 24c7685e..41feec3c 100644 --- a/src/transcode.cc +++ b/src/transcode.cc @@ -101,7 +101,7 @@ ssize_t Transcoder::read(char* buff, off_t offset, size_t len) { // copy it out. if (buffer_.valid_bytes(offset, len)) { buffer_.copy_into(reinterpret_cast(buff), offset, len); - return len; + return static_cast(len); } while (decoder_ && encoder_ && @@ -124,7 +124,7 @@ ssize_t Transcoder::read(char* buff, off_t offset, size_t len) { buffer_.copy_into(reinterpret_cast(buff), offset, len); Log(DEBUG) << "Successfully read " << len << " bytes."; - return len; + return static_cast(len); } bool Transcoder::finish() { diff --git a/test/fpcompare.c b/test/fpcompare.c index 4d0b9826..3d4ff363 100644 --- a/test/fpcompare.c +++ b/test/fpcompare.c @@ -88,7 +88,7 @@ int main(int argc, char** argv) { int i; for (i = 0; i < raw_fingerprint_size[0] && i < raw_fingerprint_size[1]; i++) { - int32_t thisdiff = raw_fingerprints[0][i] ^ raw_fingerprints[1][i]; + uint32_t thisdiff = raw_fingerprints[0][i] ^ raw_fingerprints[1][i]; setbits += __builtin_popcount(thisdiff); } const int int32_bits = 32; From 55b19981b41c0df3d7cb68c7faa823a1b43f6d35 Mon Sep 17 00:00:00 2001 From: K Henriksson Date: Fri, 30 Apr 2021 21:07:35 -0700 Subject: [PATCH 06/10] Inline cmp_by_atime in StatsCache This is simple enough it should just be a lambda. --- src/stats_cache.cc | 11 ++++------- src/stats_cache.h | 2 -- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/stats_cache.cc b/src/stats_cache.cc index d58f7164..7c8192e9 100644 --- a/src/stats_cache.cc +++ b/src/stats_cache.cc @@ -82,12 +82,6 @@ void StatsCache::put_filesize(const std::string& filename, size_t filesize, } } -/* Compare two cache entries by the access time of the FileStat objects. */ -bool StatsCache::cmp_by_atime(const StatsCache::cache_entry_t& a1, - const StatsCache::cache_entry_t& a2) { - return a1.second.get_atime() < a2.second.get_atime(); -} - /* * Prune invalid and old cache entries until the cache is at 90% of capacity. */ @@ -103,7 +97,10 @@ void StatsCache::prune() { std::back_inserter(sorted_entries)); } /* Sort the entries by access time, with the oldest first */ - std::sort(sorted_entries.begin(), sorted_entries.end(), cmp_by_atime); + std::sort(sorted_entries.begin(), sorted_entries.end(), + [](const cache_entry_t& a, const cache_entry_t& b) { + return a.second.get_atime() < b.second.get_atime(); + }); /* * Remove all invalid cache entries. Don't bother removing invalid diff --git a/src/stats_cache.h b/src/stats_cache.h index 33b3895d..386ff265 100644 --- a/src/stats_cache.h +++ b/src/stats_cache.h @@ -63,8 +63,6 @@ class StatsCache { using cache_entry_t = std::pair; - static bool cmp_by_atime(const cache_entry_t& a1, const cache_entry_t& a2); - void prune(); void remove_entry(const std::string& file, const FileStat& file_stat); From dc8285ec70754a5806eb3ef6a9c9a907288e2f5f Mon Sep 17 00:00:00 2001 From: K Henriksson Date: Fri, 30 Apr 2021 22:02:12 -0700 Subject: [PATCH 07/10] Apply naming standards across the codebase --- .clang-tidy | 40 ++++++++++++++- src/codecs/coders.cc | 10 ++-- src/codecs/coders.h | 2 +- src/codecs/flac_decoder.cc | 41 +++++++-------- src/codecs/flac_decoder.h | 8 +-- src/codecs/mp3_encoder.cc | 97 ++++++++++++++++++------------------ src/codecs/mp3_encoder.h | 10 ++-- src/codecs/picture.cc | 8 +-- src/codecs/picture.h | 16 +++--- src/codecs/vorbis_decoder.cc | 40 +++++++-------- src/codecs/vorbis_decoder.h | 8 +-- src/fuseops.cc | 20 ++++---- src/logging.cc | 44 ++++++++-------- src/logging.h | 35 +++++++------ src/mp3fs.cc | 10 ++-- src/mp3fs.h | 4 +- src/path.cc | 6 +-- src/path.h | 4 +- statictest/check_tidy | 6 ++- 19 files changed, 227 insertions(+), 182 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index b3d3ec0d..c5f7d665 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,4 +7,42 @@ Checks: >- modernize-*,-modernize-use-trailing-return-type,-modernize-avoid-c-arrays, hicpp-member-init,hicpp-multiway-paths-covered WarningsAsErrors: '*' -... +CheckOptions: + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.ClassMethodCase + value: CamelCase + - key: readability-identifier-naming.EnumCase + value: CamelCase + - key: readability-identifier-naming.EnumConstantCase + value: UPPER_CASE + - key: readability-identifier-naming.FunctionCase + value: lower_case + - key: readability-identifier-naming.GlobalConstantCase + value: CamelCase + - key: readability-identifier-naming.GlobalConstantPrefix + value: k + - key: readability-identifier-naming.StaticConstantCase + value: CamelCase + - key: readability-identifier-naming.StaticConstantPrefix + value: k + - key: readability-identifier-naming.MacroDefinitionCase + value: UPPER_CASE + - key: readability-identifier-naming.MacroDefinitionIgnoredRegexp + value: MP3FS_[A-Z0-9_]+_ + - key: readability-identifier-naming.MemberCase + value: lower_case + - key: readability-identifier-naming.MethodCase + value: lower_case + - key: readability-identifier-naming.NamespaceCase + value: lower_case + - key: readability-identifier-naming.ParameterCase + value: lower_case + - key: readability-identifier-naming.PrivateMemberSuffix + value: _ + - key: readability-identifier-naming.TypeAliasCase + value: lower_case + - key: readability-identifier-naming.TypeAliasSuffix + value: _t + - key: readability-identifier-naming.VariableCase + value: lower_case diff --git a/src/codecs/coders.cc b/src/codecs/coders.cc index 1bc5d5de..bd49a563 100644 --- a/src/codecs/coders.cc +++ b/src/codecs/coders.cc @@ -51,15 +51,15 @@ constexpr double kDefaultGain = 89.0; } void Encoder::set_gain(double gainref, double album_gain, double track_gain) { - if (gainref == invalid_db) { + if (gainref == kInvalidDb) { gainref = kDefaultGain; } - double dbgain = invalid_db; - if (params.gainmode == 1 && album_gain != invalid_db) { + double dbgain = kInvalidDb; + if (params.gainmode == 1 && album_gain != kInvalidDb) { dbgain = album_gain; } else if ((params.gainmode == 1 || params.gainmode == 2) && - track_gain != invalid_db) { + track_gain != kInvalidDb) { dbgain = track_gain; } @@ -68,7 +68,7 @@ void Encoder::set_gain(double gainref, double album_gain, double track_gain) { * value for dbgain is set in the above if statements according to * the value of gainmode. Obey the gainref option here. */ - if (dbgain != invalid_db) { + if (dbgain != kInvalidDb) { set_gain_db(params.gainref - gainref + dbgain); } } diff --git a/src/codecs/coders.h b/src/codecs/coders.h index a78bdf8d..deacd404 100644 --- a/src/codecs/coders.h +++ b/src/codecs/coders.h @@ -86,7 +86,7 @@ class Encoder { static std::unique_ptr CreateEncoder(const std::string& file_type, Buffer* buffer); - constexpr static double invalid_db = 1000.0; + constexpr static double kInvalidDb = 1000.0; }; /* Decoder class interface */ diff --git a/src/codecs/flac_decoder.cc b/src/codecs/flac_decoder.cc index 5b9f63eb..bb1e25fc 100644 --- a/src/codecs/flac_decoder.cc +++ b/src/codecs/flac_decoder.cc @@ -91,15 +91,16 @@ time_t FlacDecoder::mtime() { * parameters. */ int FlacDecoder::process_metadata(Encoder* encoder) { - encoder_c = encoder; - if (!process_until_end_of_metadata() || !has_streaminfo) { + encoder_c_ = encoder; + if (!process_until_end_of_metadata() || !has_streaminfo_) { Log(ERROR) << "FLAC is invalid."; return -1; } - if (encoder->set_stream_params( - info.get_total_samples(), static_cast(info.get_sample_rate()), - static_cast(info.get_channels())) == -1) { + if (encoder->set_stream_params(info_.get_total_samples(), + static_cast(info_.get_sample_rate()), + static_cast(info_.get_channels())) == + -1) { return -1; } @@ -113,7 +114,7 @@ int FlacDecoder::process_metadata(Encoder* encoder) { * with most work handled by write_callback(). */ int FlacDecoder::process_single_fr(Encoder* encoder) { - encoder_c = encoder; + encoder_c_ = encoder; if (get_state() < FLAC__STREAM_DECODER_END_OF_STREAM) { if (!process_single()) { Log(ERROR) << "Error reading FLAC."; @@ -136,8 +137,8 @@ void FlacDecoder::metadata_callback(const FLAC__StreamMetadata* metadata) { switch (metadata->type) { case FLAC__METADATA_TYPE_STREAMINFO: { /* Set our copy of STREAMINFO data. */ - info = FLAC::Metadata::StreamInfo(metadata); - has_streaminfo = true; + info_ = FLAC::Metadata::StreamInfo(metadata); + has_streaminfo_ = true; Log(DEBUG) << "FLAC processing STREAMINFO"; @@ -145,9 +146,9 @@ void FlacDecoder::metadata_callback(const FLAC__StreamMetadata* metadata) { } case FLAC__METADATA_TYPE_VORBIS_COMMENT: { const FLAC::Metadata::VorbisComment vc(metadata); - double gainref = Encoder::invalid_db, - album_gain = Encoder::invalid_db, - track_gain = Encoder::invalid_db; + double gainref = Encoder::kInvalidDb, + album_gain = Encoder::kInvalidDb, + track_gain = Encoder::kInvalidDb; Log(DEBUG) << "FLAC processing VORBIS_COMMENT"; @@ -159,10 +160,10 @@ void FlacDecoder::metadata_callback(const FLAC__StreamMetadata* metadata) { std::transform(fname.begin(), fname.end(), fname.begin(), ::toupper); - auto it = metatag_map.find(fname); - if (it != metatag_map.end()) { - encoder_c->set_text_tag(it->second, - comment.get_field_value()); + auto it = kMetatagMap.find(fname); + if (it != kMetatagMap.end()) { + encoder_c_->set_text_tag(it->second, + comment.get_field_value()); } else if (fname == "REPLAYGAIN_REFERENCE_LOUDNESS") { gainref = strtod(comment.get_field_value(), nullptr); } else if (fname == "REPLAYGAIN_ALBUM_GAIN") { @@ -172,7 +173,7 @@ void FlacDecoder::metadata_callback(const FLAC__StreamMetadata* metadata) { } } - encoder_c->set_gain(gainref, album_gain, track_gain); + encoder_c_->set_gain(gainref, album_gain, track_gain); break; } @@ -182,7 +183,7 @@ void FlacDecoder::metadata_callback(const FLAC__StreamMetadata* metadata) { Log(DEBUG) << "FLAC processing PICTURE"; - encoder_c->set_picture_tag( + encoder_c_->set_picture_tag( picture.get_mime_type(), picture.get_type(), reinterpret_cast(picture.get_description()), picture.get_data(), picture.get_data_length()); @@ -201,8 +202,8 @@ void FlacDecoder::metadata_callback(const FLAC__StreamMetadata* metadata) { */ FLAC__StreamDecoderWriteStatus FlacDecoder::write_callback( const FLAC__Frame* frame, const FLAC__int32* const buffer[]) { - if (encoder_c->encode_pcm_data(buffer, frame->header.blocksize, - frame->header.bits_per_sample) == -1) { + if (encoder_c_->encode_pcm_data(buffer, frame->header.blocksize, + frame->header.bits_per_sample) == -1) { return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; } @@ -219,7 +220,7 @@ void FlacDecoder::error_callback(FLAC__StreamDecoderErrorStatus status) { * This map associates FLAC values to the standard values in the enum in * coders.h. */ -const FlacDecoder::meta_map_t FlacDecoder::metatag_map = { +const FlacDecoder::meta_map_t FlacDecoder::kMetatagMap = { {"TITLE", METATAG_TITLE}, {"ARTIST", METATAG_ARTIST}, {"ALBUM", METATAG_ALBUM}, diff --git a/src/codecs/flac_decoder.h b/src/codecs/flac_decoder.h index 5bc97654..ae6eb9e7 100644 --- a/src/codecs/flac_decoder.h +++ b/src/codecs/flac_decoder.h @@ -52,12 +52,12 @@ class FlacDecoder : public Decoder, private FLAC::Decoder::File { void error_callback(FLAC__StreamDecoderErrorStatus status) override; private: - Encoder* encoder_c = nullptr; + Encoder* encoder_c_ = nullptr; time_t mtime_ = 0; - FLAC::Metadata::StreamInfo info; - bool has_streaminfo = false; + FLAC::Metadata::StreamInfo info_; + bool has_streaminfo_ = false; using meta_map_t = std::map; - static const meta_map_t metatag_map; + static const meta_map_t kMetatagMap; }; #endif // MP3FS_CODECS_FLAC_DECODER_H_ diff --git a/src/codecs/mp3_encoder.cc b/src/codecs/mp3_encoder.cc index 675eb498..7c6ee613 100644 --- a/src/codecs/mp3_encoder.cc +++ b/src/codecs/mp3_encoder.cc @@ -67,28 +67,28 @@ void lame_debug(const char* fmt, va_list list) { * of memory, these routines will fail silently. */ Mp3Encoder::Mp3Encoder(Buffer* buffer) : buffer_(buffer) { - id3tag = id3_tag_new(); + id3tag_ = id3_tag_new(); Log(DEBUG) << "LAME ready to initialize."; - lame_encoder = lame_init(); + lame_encoder_ = lame_init(); Mp3Encoder::set_text_tag(METATAG_ENCODER, PACKAGE_NAME); /* Set lame parameters. */ if (params.vbr != 0) { - lame_set_VBR(lame_encoder, vbr_mt); - lame_set_VBR_q(lame_encoder, params.quality); - lame_set_VBR_max_bitrate_kbps(lame_encoder, params.bitrate); - lame_set_bWriteVbrTag(lame_encoder, 1); + lame_set_VBR(lame_encoder_, vbr_mt); + lame_set_VBR_q(lame_encoder_, params.quality); + lame_set_VBR_max_bitrate_kbps(lame_encoder_, params.bitrate); + lame_set_bWriteVbrTag(lame_encoder_, 1); } else { - lame_set_quality(lame_encoder, params.quality); - lame_set_brate(lame_encoder, params.bitrate); - lame_set_bWriteVbrTag(lame_encoder, 0); + lame_set_quality(lame_encoder_, params.quality); + lame_set_brate(lame_encoder_, params.bitrate); + lame_set_bWriteVbrTag(lame_encoder_, 0); } - lame_set_errorf(lame_encoder, &lame_error); - lame_set_msgf(lame_encoder, &lame_msg); - lame_set_debugf(lame_encoder, &lame_debug); + lame_set_errorf(lame_encoder_, &lame_error); + lame_set_msgf(lame_encoder_, &lame_msg); + lame_set_debugf(lame_encoder_, &lame_debug); } /* @@ -96,10 +96,10 @@ Mp3Encoder::Mp3Encoder(Buffer* buffer) : buffer_(buffer) { * so we have to check ourselves to avoid this case. */ Mp3Encoder::~Mp3Encoder() { - if (id3tag != nullptr) { - id3_tag_delete(id3tag); + if (id3tag_ != nullptr) { + id3_tag_delete(id3tag_); } - lame_close(lame_encoder); + lame_close(lame_encoder_); } /* @@ -109,14 +109,14 @@ Mp3Encoder::~Mp3Encoder() { */ int Mp3Encoder::set_stream_params(uint64_t num_samples, int sample_rate, int channels) { - lame_set_num_samples(lame_encoder, num_samples); - lame_set_in_samplerate(lame_encoder, sample_rate); - lame_set_num_channels(lame_encoder, channels); + lame_set_num_samples(lame_encoder_, num_samples); + lame_set_in_samplerate(lame_encoder_, sample_rate); + lame_set_num_channels(lame_encoder_, channels); Log(DEBUG) << "LAME partially initialized."; /* Initialise encoder */ - if (lame_init_params(lame_encoder) == -1) { + if (lame_init_params(lame_encoder_) == -1) { Log(ERROR) << "lame_init_params failed."; return -1; } @@ -145,13 +145,13 @@ void Mp3Encoder::set_text_tag(const int key, const char* value) { return; } - auto it = metatag_map.find(key); + auto it = kMetatagMap.find(key); - if (it != metatag_map.end()) { - struct id3_frame* frame = id3_tag_findframe(id3tag, it->second, 0); + if (it != kMetatagMap.end()) { + struct id3_frame* frame = id3_tag_findframe(id3tag_, it->second, 0); if (frame == nullptr) { frame = id3_frame_new(it->second); - id3_tag_attachframe(id3tag, frame); + id3_tag_attachframe(id3tag_, frame); id3_field_settextencoding(id3_frame_field(frame, 0), ID3_FIELD_TEXTENCODING_UTF_8); @@ -172,7 +172,7 @@ void Mp3Encoder::set_text_tag(const int key, const char* value) { } else { tagname = "TPOS"; } - struct id3_frame* frame = id3_tag_findframe(id3tag, tagname, 0); + struct id3_frame* frame = id3_tag_findframe(id3tag_, tagname, 0); const id3_latin1_t* lat; id3_latin1_t* tofree = nullptr; if (frame != nullptr) { @@ -182,7 +182,7 @@ void Mp3Encoder::set_text_tag(const int key, const char* value) { lat = tofree; } else { frame = id3_frame_new(tagname); - id3_tag_attachframe(id3tag, frame); + id3_tag_attachframe(id3tag_, frame); id3_field_settextencoding(id3_frame_field(frame, 0), ID3_FIELD_TEXTENCODING_UTF_8); lat = reinterpret_cast(""); @@ -210,7 +210,7 @@ void Mp3Encoder::set_picture_tag(const char* mime_type, int type, const char* description, const uint8_t* data, unsigned int data_length) { struct id3_frame* frame = id3_frame_new("APIC"); - id3_tag_attachframe(id3tag, frame); + id3_tag_attachframe(id3tag_, frame); id3_field_settextencoding(id3_frame_field(frame, 0), ID3_FIELD_TEXTENCODING_UTF_8); @@ -236,7 +236,7 @@ void Mp3Encoder::set_picture_tag(const char* mime_type, int type, void Mp3Encoder::set_gain_db(const double dbgain) { Log(DEBUG) << "LAME setting gain to " << dbgain << "."; // NOLINTNEXTLINE(readability-magic-numbers) - lame_set_scale(lame_encoder, static_cast(pow(10.0, dbgain / 20))); + lame_set_scale(lame_encoder_, static_cast(pow(10.0, dbgain / 20))); } /* @@ -252,25 +252,26 @@ int Mp3Encoder::render_tag(size_t file_size) { * are buggy. * Some players = iTunes */ - id3_tag_options(id3tag, ID3_TAG_OPTION_COMPRESSION, 0); + id3_tag_options(id3tag_, ID3_TAG_OPTION_COMPRESSION, 0); const int extra_padding = 12; - id3_tag_setlength(id3tag, id3_tag_render(id3tag, nullptr) + extra_padding); + id3_tag_setlength(id3tag_, + id3_tag_render(id3tag_, nullptr) + extra_padding); // write v2 tag - id3size = id3_tag_render(id3tag, nullptr); - std::vector tag24(id3size); - id3_tag_render(id3tag, tag24.data()); + id3size_ = id3_tag_render(id3tag_, nullptr); + std::vector tag24(id3size_); + id3_tag_render(id3tag_, tag24.data()); buffer_->write(tag24, true); // Write v1 tag at end of buffer. - id3_tag_options(id3tag, ID3_TAG_OPTION_ID3V1, ~0); - std::vector tag1(id3v1_tag_length); - id3_tag_render(id3tag, tag1.data()); + id3_tag_options(id3tag_, ID3_TAG_OPTION_ID3V1, ~0); + std::vector tag1(kId3v1TagLength); + id3_tag_render(id3tag_, tag1.data()); if (file_size == 0) { file_size = calculate_size(); } buffer_->write_end( - tag1, static_cast(file_size - id3v1_tag_length)); + tag1, static_cast(file_size - kId3v1TagLength)); return 0; } @@ -293,15 +294,15 @@ int Mp3Encoder::render_tag(size_t file_size) { size_t Mp3Encoder::calculate_size() const { const int conversion_factor = 144000; if (params.vbr != 0) { - return id3size + id3v1_tag_length + MAX_VBR_FRAME_SIZE + - static_cast(lame_get_totalframes(lame_encoder)) * + return id3size_ + kId3v1TagLength + MAX_VBR_FRAME_SIZE + + static_cast(lame_get_totalframes(lame_encoder_)) * conversion_factor * params.bitrate / - lame_get_in_samplerate(lame_encoder); + lame_get_in_samplerate(lame_encoder_); } - return id3size + id3v1_tag_length + - static_cast(lame_get_totalframes(lame_encoder)) * + return id3size_ + kId3v1TagLength + + static_cast(lame_get_totalframes(lame_encoder_)) * conversion_factor * params.bitrate / - lame_get_out_samplerate(lame_encoder); + lame_get_out_samplerate(lame_encoder_); } /* @@ -330,7 +331,7 @@ int Mp3Encoder::encode_pcm_data(const int32_t* const data[], for (unsigned int i = 0; i < numsamples; ++i) { lbuf[i] = data[0][i] << (sizeof(int) * kBitsPerByte - sample_size); /* ignore rbuf for mono data */ - if (lame_get_num_channels(lame_encoder) > 1) { + if (lame_get_num_channels(lame_encoder_) > 1) { rbuf[i] = data[1][i] << (sizeof(int) * kBitsPerByte - sample_size); } } @@ -339,7 +340,7 @@ int Mp3Encoder::encode_pcm_data(const int32_t* const data[], std::vector vbuffer(5 * numsamples / 4 + kBufferSlop); // NOLINT int len = lame_encode_buffer_int( - lame_encoder, &lbuf[0], &rbuf[0], static_cast(numsamples), + lame_encoder_, &lbuf[0], &rbuf[0], static_cast(numsamples), vbuffer.data(), static_cast(vbuffer.size())); if (len < 0) { return -1; @@ -359,7 +360,7 @@ int Mp3Encoder::encode_pcm_data(const int32_t* const data[], int Mp3Encoder::encode_finish() { std::vector vbuffer(kBufferSlop); - int len = lame_encode_flush(lame_encoder, vbuffer.data(), + int len = lame_encode_flush(lame_encoder_, vbuffer.data(), static_cast(vbuffer.size())); if (len < 0) { return -1; @@ -379,12 +380,12 @@ int Mp3Encoder::encode_finish() { */ if (params.vbr != 0) { std::vector tail(MAX_VBR_FRAME_SIZE); - size_t vbr_tag_size = lame_get_lametag_frame(lame_encoder, tail.data(), + size_t vbr_tag_size = lame_get_lametag_frame(lame_encoder_, tail.data(), MAX_VBR_FRAME_SIZE); if (vbr_tag_size > MAX_VBR_FRAME_SIZE) { return -1; } - buffer_->write_to(tail, static_cast(id3size)); + buffer_->write_to(tail, static_cast(id3size_)); } return len; @@ -394,7 +395,7 @@ int Mp3Encoder::encode_finish() { * This map contains the association from the standard values in the enum in * coders.h to ID3 values. */ -const Mp3Encoder::meta_map_t Mp3Encoder::metatag_map = { +const Mp3Encoder::meta_map_t Mp3Encoder::kMetatagMap = { {METATAG_TITLE, "TIT2"}, {METATAG_ARTIST, "TPE1"}, {METATAG_ALBUM, "TALB"}, {METATAG_GENRE, "TCON"}, {METATAG_DATE, "TDRC"}, {METATAG_COMPOSER, "TCOM"}, diff --git a/src/codecs/mp3_encoder.h b/src/codecs/mp3_encoder.h index 12501474..6db283fa 100644 --- a/src/codecs/mp3_encoder.h +++ b/src/codecs/mp3_encoder.h @@ -34,7 +34,7 @@ class Buffer; class Mp3Encoder : public Encoder { public: - static const size_t id3v1_tag_length = 128; + static const size_t kId3v1TagLength = 128; explicit Mp3Encoder(Buffer* buffer); ~Mp3Encoder() override; @@ -60,12 +60,12 @@ class Mp3Encoder : public Encoder { bool no_partial_encode() override { return params.vbr != 0; } private: - lame_t lame_encoder; - struct id3_tag* id3tag; - size_t id3size = 0; + lame_t lame_encoder_; + struct id3_tag* id3tag_; + size_t id3size_ = 0; Buffer* buffer_; using meta_map_t = std::map; - static const meta_map_t metatag_map; + static const meta_map_t kMetatagMap; }; #endif // MP3FS_CODECS_MP3_ENCODER_H_ diff --git a/src/codecs/picture.cc b/src/codecs/picture.cc index 7b65ef29..2b49e1d4 100644 --- a/src/codecs/picture.cc +++ b/src/codecs/picture.cc @@ -34,16 +34,16 @@ constexpr int kUnusedMetadataBytes = 16; bool Picture::decode() { std::string picture_data_str; - if (!consume_decode_uint32(&type) || !consume_decode_string(&mime_type) || - !consume_decode_string(&description) || + if (!consume_decode_uint32(&type_) || !consume_decode_string(&mime_type_) || + !consume_decode_string(&description_) || !consume_no_decode(kUnusedMetadataBytes) || !consume_decode_string(&picture_data_str)) { Log(ERROR) << "Couldn't decode picture data as valid data."; return false; } - picture_data.assign(picture_data_str.c_str(), - picture_data_str.c_str() + picture_data_str.size()); + picture_data_.assign(picture_data_str.c_str(), + picture_data_str.c_str() + picture_data_str.size()); return true; } diff --git a/src/codecs/picture.h b/src/codecs/picture.h index 0dd67e4f..108bdfe8 100644 --- a/src/codecs/picture.h +++ b/src/codecs/picture.h @@ -34,13 +34,13 @@ class Picture { bool decode(); - int get_type() const { return static_cast(type); } - const char* get_mime_type() const { return mime_type.c_str(); } - const char* get_description() const { return description.c_str(); } + int get_type() const { return static_cast(type_); } + const char* get_mime_type() const { return mime_type_.c_str(); } + const char* get_description() const { return description_.c_str(); } int get_data_length() const { - return static_cast(picture_data.size()); + return static_cast(picture_data_.size()); } - const uint8_t* get_data() const { return picture_data.data(); } + const uint8_t* get_data() const { return picture_data_.data(); } private: bool consume_decode_uint32(uint32_t* out); @@ -54,9 +54,9 @@ class Picture { std::vector data_; size_t data_off_; - uint32_t type = 0; - std::string mime_type, description; - std::vector picture_data; + uint32_t type_ = 0; + std::string mime_type_, description_; + std::vector picture_data_; }; #endif // MP3FS_CODECS_PICTURE_H_ diff --git a/src/codecs/vorbis_decoder.cc b/src/codecs/vorbis_decoder.cc index 166ace2e..27f206ac 100644 --- a/src/codecs/vorbis_decoder.cc +++ b/src/codecs/vorbis_decoder.cc @@ -41,7 +41,7 @@ * after the decoding process has finished. */ VorbisDecoder::~VorbisDecoder() { - ov_clear(&vf); + ov_clear(&vf_); Log(DEBUG) << "Ogg Vorbis decoder: Closed."; } @@ -67,7 +67,7 @@ int VorbisDecoder::open_file(const char* filename) { mtime_ = s.st_mtime; /* Initialise decoder */ - if (ov_open(file, &vf, nullptr, 0) < 0) { + if (ov_open(file, &vf_, nullptr, 0) < 0) { Log(ERROR) << "Ogg Vorbis decoder: Initialization failed."; fclose(file); return -1; @@ -90,33 +90,33 @@ time_t VorbisDecoder::mtime() { int VorbisDecoder::process_metadata(Encoder* encoder) { vorbis_comment* vc = nullptr; - if ((vi = ov_info(&vf, -1)) == nullptr) { + if ((vi_ = ov_info(&vf_, -1)) == nullptr) { Log(ERROR) << "Ogg Vorbis decoder: Failed to retrieve the file info."; return -1; } - if (vi->channels > 2) { + if (vi_->channels > 2) { Log(ERROR) << "Ogg Vorbis decoder: Only mono/stereo audio currently " "supported."; return -1; } - if (encoder->set_stream_params(ov_pcm_total(&vf, -1), - static_cast(vi->rate), - vi->channels) == -1) { + if (encoder->set_stream_params(ov_pcm_total(&vf_, -1), + static_cast(vi_->rate), + vi_->channels) == -1) { Log(ERROR) << "Ogg Vorbis decoder: Failed to set encoder stream parameters."; return -1; } - if ((vc = ov_comment(&vf, -1)) == nullptr) { + if ((vc = ov_comment(&vf_, -1)) == nullptr) { Log(ERROR) << "Ogg Vorbis decoder: Failed to retrieve the Ogg Vorbis comment."; return -1; } - double gainref = Encoder::invalid_db, album_gain = Encoder::invalid_db, - track_gain = Encoder::invalid_db; + double gainref = Encoder::kInvalidDb, album_gain = Encoder::kInvalidDb, + track_gain = Encoder::kInvalidDb; for (int i = 0; i < vc->comments; ++i) { /* @@ -142,9 +142,9 @@ int VorbisDecoder::process_metadata(Encoder* encoder) { * Set the encoder's text tag if it's in the metatag_map, or else, * prepare the ReplayGain. */ - auto it = metatag_map.find(tagname); + auto it = kMetatagMap.find(tagname); - if (it != metatag_map.end()) { + if (it != kMetatagMap.end()) { encoder->set_text_tag(it->second, tagvalue.c_str()); } else if (tagname == "METADATA_BLOCK_PICTURE") { char* data; @@ -192,13 +192,13 @@ int VorbisDecoder::process_single_fr(Encoder* encoder) { std::vector decode_buffer(buffer_size); int64_t read_bytes = ov_read( - &vf, reinterpret_cast(decode_buffer.data()), - static_cast(2 * decode_buffer.size()), 0, 2, 1, ¤t_section); + &vf_, reinterpret_cast(decode_buffer.data()), + static_cast(2 * decode_buffer.size()), 0, 2, 1, ¤t_section_); int64_t total_samples = read_bytes / 2; if (total_samples > 0) { - int64_t samples_per_channel = total_samples / vi->channels; + int64_t samples_per_channel = total_samples / vi_->channels; if (samples_per_channel < 1) { Log(ERROR) << "Ogg Vorbis decoder: Not enough samples per channel."; @@ -206,14 +206,14 @@ int VorbisDecoder::process_single_fr(Encoder* encoder) { } std::vector> encode_buffer( - vi->channels, std::vector(samples_per_channel)); - int32_t* encode_buffer_ptr[vi->channels]; + vi_->channels, std::vector(samples_per_channel)); + int32_t* encode_buffer_ptr[vi_->channels]; - for (int channel = 0; channel < vi->channels; ++channel) { + for (int channel = 0; channel < vi_->channels; ++channel) { encode_buffer_ptr[channel] = encode_buffer[channel].data(); for (int64_t i = 0; i < samples_per_channel; ++i) { encode_buffer[channel][i] = - decode_buffer[i * vi->channels + channel]; + decode_buffer[i * vi_->channels + channel]; } } @@ -240,7 +240,7 @@ int VorbisDecoder::process_single_fr(Encoder* encoder) { return -1; } -const VorbisDecoder::meta_map_t VorbisDecoder::metatag_map = { +const VorbisDecoder::meta_map_t VorbisDecoder::kMetatagMap = { {"TITLE", METATAG_TITLE}, {"ARTIST", METATAG_ARTIST}, {"ALBUM", METATAG_ALBUM}, diff --git a/src/codecs/vorbis_decoder.h b/src/codecs/vorbis_decoder.h index a0c3d6d3..eea4348f 100644 --- a/src/codecs/vorbis_decoder.h +++ b/src/codecs/vorbis_decoder.h @@ -40,11 +40,11 @@ class VorbisDecoder : public Decoder { private: time_t mtime_; - OggVorbis_File vf; - vorbis_info* vi; - int current_section; + OggVorbis_File vf_; + vorbis_info* vi_; + int current_section_; using meta_map_t = std::map; - static const meta_map_t metatag_map; + static const meta_map_t kMetatagMap; }; #endif // MP3FS_CODECS_VORBIS_DECODER_H_ diff --git a/src/fuseops.cc b/src/fuseops.cc index 604ddeb1..fcd08cc6 100644 --- a/src/fuseops.cc +++ b/src/fuseops.cc @@ -67,7 +67,7 @@ int mp3fs_readlink(const char* p, char* buf, size_t size) { Path path = Path::FromMp3fsRelative(p); Log(INFO) << "readlink " << path; - ssize_t len = readlink(path.TranscodeSource().c_str(), buf, size - 2); + ssize_t len = readlink(path.transcode_source().c_str(), buf, size - 2); if (len == -1) { return -errno; } @@ -90,14 +90,14 @@ int mp3fs_readdir(const char* p, void* buf, fuse_fill_dir_t filler, #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wignored-attributes" std::unique_ptr dp( - opendir(path.NormalSource().c_str()), closedir); + opendir(path.normal_source().c_str()), closedir); #pragma GCC diagnostic pop if (!dp) { return -errno; } while (struct dirent* de = readdir(dp.get())) { - const std::string origfile = path.NormalSource() + "/" + de->d_name; + const std::string origfile = path.normal_source() + "/" + de->d_name; struct stat st = {}; if (lstat(origfile.c_str(), &st) == -1) { @@ -123,11 +123,11 @@ int mp3fs_getattr(const char* p, struct stat* stbuf) { Log(INFO) << "getattr " << path; /* pass-through for regular files */ - if (lstat(path.NormalSource().c_str(), stbuf) == 0) { + if (lstat(path.normal_source().c_str(), stbuf) == 0) { return 0; } - if (lstat(path.TranscodeSource().c_str(), stbuf) == -1) { + if (lstat(path.transcode_source().c_str(), stbuf) == -1) { return -errno; } @@ -135,7 +135,7 @@ int mp3fs_getattr(const char* p, struct stat* stbuf) { * Get size for resulting mp3 from regular file, otherwise it's a * symbolic link. */ if (S_ISREG(stbuf->st_mode)) { - Transcoder trans(path.TranscodeSource()); + Transcoder trans(path.transcode_source()); if (!trans.open()) { return -errno; } @@ -152,7 +152,7 @@ int mp3fs_open(const char* p, struct fuse_file_info* fi) { Path path = Path::FromMp3fsRelative(p); Log(INFO) << "open " << path; - int fd = open(path.NormalSource().c_str(), fi->flags); + int fd = open(path.normal_source().c_str(), fi->flags); if (fd != -1) { // File exists and was successfully opened. fi->fh = reinterpret_cast(new FileReader(fd)); @@ -163,7 +163,7 @@ int mp3fs_open(const char* p, struct fuse_file_info* fi) { } // File does not exist; try again after translating path. - std::unique_ptr trans(new Transcoder(path.TranscodeSource())); + std::unique_ptr trans(new Transcoder(path.transcode_source())); if (!trans->open()) { return -errno; } @@ -199,11 +199,11 @@ int mp3fs_statfs(const char* p, struct statvfs* stbuf) { Log(INFO) << "statfs " << path; /* pass-through for regular files */ - if (statvfs(path.NormalSource().c_str(), stbuf) == 0) { + if (statvfs(path.normal_source().c_str(), stbuf) == 0) { return 0; } - if (statvfs(path.TranscodeSource().c_str(), stbuf) == 0) { + if (statvfs(path.transcode_source().c_str(), stbuf) == 0) { return 0; } diff --git a/src/logging.cc b/src/logging.cc index fb229c4d..255957c2 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -36,8 +36,8 @@ namespace { Logging* logging; constexpr size_t kTimeBufferSize = 30; -std::string MultiSubstitute(std::string src, - std::unordered_map subs) { +std::string multi_substitute( + std::string src, std::unordered_map subs) { std::string result; for (auto it = src.cbegin(); it != src.cend();) { bool matched = false; @@ -58,7 +58,7 @@ std::string MultiSubstitute(std::string src, } } // namespace -Logging::Logging(std::string logfile, level max_level, std::string log_format, +Logging::Logging(std::string logfile, Level max_level, std::string log_format, bool to_stderr, bool to_syslog) : max_level_(max_level), log_format_(std::move(log_format)), @@ -87,14 +87,14 @@ Logging::Logger::~Logger() { std::ostringstream tid_stream; tid_stream << std::this_thread::get_id(); - std::string msg = MultiSubstitute(logging_->log_format_, - {{"%T", time_string}, - {"%I", tid_stream.str()}, - {"%L", level_name_map_.at(loglevel_)}, - {"%M", str()}}); + std::string msg = multi_substitute(logging_->log_format_, + {{"%T", time_string}, + {"%I", tid_stream.str()}, + {"%L", kLevelNameMap.at(loglevel_)}, + {"%M", str()}}); if (logging_->to_syslog_) { - syslog(syslog_level_map_.at(loglevel_), "%s", msg.c_str()); + syslog(kSyslogLevelMap.at(loglevel_), "%s", msg.c_str()); } if (logging_->logfile_.is_open()) { logging_->logfile_ << msg << std::endl; @@ -104,48 +104,48 @@ Logging::Logger::~Logger() { } } -const std::map Logging::Logger::syslog_level_map_ = { +const std::map Logging::Logger::kSyslogLevelMap = { {ERROR, LOG_ERR}, {INFO, LOG_INFO}, {DEBUG, LOG_DEBUG}, }; -const std::map Logging::Logger::level_name_map_ = { +const std::map Logging::Logger::kLevelNameMap = { {ERROR, "ERROR"}, {INFO, "INFO"}, {DEBUG, "DEBUG"}, }; -Logging::Logger Log(Logging::level lev) { +Logging::Logger Log(Logging::Level lev) { return {lev, logging}; } -Logging::level StringToLevel(std::string level) { - static const std::map level_map = { +Logging::Level string_to_level(std::string level) { + static const std::map kLevelMap = { {"DEBUG", DEBUG}, {"INFO", INFO}, {"ERROR", ERROR}, }; - auto it = level_map.find(level); + auto it = kLevelMap.find(level); - if (it == level_map.end()) { + if (it == kLevelMap.end()) { std::cerr << "Invalid logging level string: " << level << std::endl; - return Logging::level::INVALID; + return Logging::Level::INVALID; } return it->second; } -bool InitLogging(std::string logfile, Logging::level max_level, - std::string log_format, bool to_stderr, bool to_syslog) { - if (max_level == Logging::level::INVALID) { +bool init_logging(std::string logfile, Logging::Level max_level, + std::string log_format, bool to_stderr, bool to_syslog) { + if (max_level == Logging::Level::INVALID) { return false; } logging = new Logging(logfile, max_level, log_format, to_stderr, to_syslog); - return !logging->GetFail(); + return !logging->get_fail(); } -void log_with_level(Logging::level level, const char* prefix, +void log_with_level(Logging::Level level, const char* prefix, const char* format, va_list ap) { // This copy is because we call vsnprintf twice, and ap is undefined after // the first call. diff --git a/src/logging.h b/src/logging.h index cbc1eea6..2a8e7cfa 100644 --- a/src/logging.h +++ b/src/logging.h @@ -29,7 +29,7 @@ class Logging { public: - enum class level { INVALID = 0, ERROR = 1, INFO = 2, DEBUG = 3 }; + enum class Level { INVALID = 0, ERROR = 1, INFO = 2, DEBUG = 3 }; /* * Arguments: @@ -40,48 +40,51 @@ class Logging { * to_stderr: Whether to write log output to stderr. * to_syslog: Whether to write log output to syslog. */ - explicit Logging(std::string logfile, level max_level, + explicit Logging(std::string logfile, Level max_level, std::string log_format, bool to_stderr, bool to_syslog); - bool GetFail() const { return logfile_.fail(); } + bool get_fail() const { return logfile_.fail(); } private: class Logger : public std::ostringstream { public: - Logger(level loglevel, Logging* logging) + Logger(Level loglevel, Logging* logging) : loglevel_(loglevel), logging_(logging) {} Logger() = default; ~Logger() override; private: - const level loglevel_ = level::DEBUG; + const Level loglevel_ = Level::DEBUG; Logging* logging_ = nullptr; - static const std::map syslog_level_map_; - static const std::map level_name_map_; + static const std::map kSyslogLevelMap; + static const std::map kLevelNameMap; }; - friend Logger Log(level lev); + friend Logger Log(Level lev); // NOLINT(readability-identifier-naming) friend Logger; std::ofstream logfile_; - const level max_level_; + const Level max_level_; const std::string log_format_; const bool to_stderr_; const bool to_syslog_; }; -Logging::level StringToLevel(std::string level); +Logging::Level string_to_level(std::string level); -bool InitLogging(std::string logfile, Logging::level max_level, - std::string log_format, bool to_stderr, bool to_syslog); +bool init_logging(std::string logfile, Logging::Level max_level, + std::string log_format, bool to_stderr, bool to_syslog); -constexpr auto ERROR = Logging::level::ERROR; -constexpr auto INFO = Logging::level::INFO; -constexpr auto DEBUG = Logging::level::DEBUG; +// NOLINTNEXTLINE(readability-identifier-naming) +constexpr auto ERROR = Logging::Level::ERROR; +// NOLINTNEXTLINE(readability-identifier-naming) +constexpr auto INFO = Logging::Level::INFO; +// NOLINTNEXTLINE(readability-identifier-naming) +constexpr auto DEBUG = Logging::Level::DEBUG; -void log_with_level(Logging::level level, const char* prefix, +void log_with_level(Logging::Level level, const char* prefix, const char* format, va_list ap); #endif // MP3FS_LOGGING_H_ diff --git a/src/mp3fs.cc b/src/mp3fs.cc index 8c78f4e6..dfa02a66 100644 --- a/src/mp3fs.cc +++ b/src/mp3fs.cc @@ -56,7 +56,7 @@ constexpr int kQualityMax = 9; enum { KEY_HELP, KEY_VERSION, KEY_KEEP_OPT }; #define MP3FS_OPT(t, p, v) \ - { t, offsetof(mp3fs_params, p), v } + { t, offsetof(Mp3fsParams, p), v } // Redefine FUSE_OPT_KEY to avoid warning. #undef FUSE_OPT_KEY @@ -201,7 +201,7 @@ int mp3fs_opt_proc(void* /*unused*/, const char* arg, int key, } // namespace -mp3fs_params params = { +Mp3fsParams params = { .basepath = nullptr, .bitrate = kDefaultBitrate, .debug = 0, @@ -239,9 +239,9 @@ int main(int argc, char* argv[]) { params.log_maxlevel = "DEBUG"; } - if (!InitLogging(params.logfile, StringToLevel(params.log_maxlevel), - params.log_format, params.log_stderr != 0, - params.log_syslog != 0)) { + if (!init_logging(params.logfile, string_to_level(params.log_maxlevel), + params.log_format, params.log_stderr != 0, + params.log_syslog != 0)) { std::cerr << "Failed to initialize logging module." << std::endl; std::cerr << "Maybe log file couldn't be opened for writing?" << std::endl; diff --git a/src/mp3fs.h b/src/mp3fs.h index d8eeda25..ddc41e1b 100644 --- a/src/mp3fs.h +++ b/src/mp3fs.h @@ -23,7 +23,7 @@ #define MP3FS_MP3FS_H_ /* Global program parameters */ -struct mp3fs_params { +struct Mp3fsParams { const char* basepath; int bitrate; int debug; @@ -40,6 +40,6 @@ struct mp3fs_params { int vbr; }; -extern mp3fs_params params; +extern Mp3fsParams params; #endif // MP3FS_MP3FS_H_ diff --git a/src/path.cc b/src/path.cc index ad7fca8d..99bf6443 100644 --- a/src/path.cc +++ b/src/path.cc @@ -29,12 +29,12 @@ #include "codecs/coders.h" #include "mp3fs.h" -std::string Path::NormalSource() const { +std::string Path::normal_source() const { return std::string(params.basepath) + relative_path_; } -std::string Path::TranscodeSource() const { - const std::string source = NormalSource(); +std::string Path::transcode_source() const { + const std::string source = normal_source(); const size_t dot_idx = source.rfind('.'); const size_t slash_idx = source.rfind('/'); const std::string source_dir = source.substr(0, slash_idx); diff --git a/src/path.h b/src/path.h index b9b27f4d..73149e18 100644 --- a/src/path.h +++ b/src/path.h @@ -36,7 +36,7 @@ class Path { * This returns the path in the source directory assuming no change in * extension. */ - std::string NormalSource() const; + std::string normal_source() const; /** * Return source path for transcoded files. @@ -46,7 +46,7 @@ class Path { * decoder extensions. If none of those exist, the same value as * NormalSource will be returned. */ - std::string TranscodeSource() const; + std::string transcode_source() const; friend std::ostream& operator<<(std::ostream&, const Path&); diff --git a/statictest/check_tidy b/statictest/check_tidy index e8984e32..5d43abac 100755 --- a/statictest/check_tidy +++ b/statictest/check_tidy @@ -10,14 +10,16 @@ if [[ "$(uname -s)" = Darwin* ]] ; then fi check_tidy_single () { + # Disable naming check on Travis due to old clang-tidy version. + [ "$TRAVIS" = true ] && DISABLE_NAMING=--checks=-readability-identifier-naming file=$1 if [[ "$file" = *.c ]] ; then lang_flags=(--language=c -std=c11) else lang_flags=(--language=c++ -std=c++11) fi - clang-tidy --quiet "$file" -- "${CXXFLAGS[@]}" "${lang_flags[@]}" \ - -Wno-unknown-warning-option + clang-tidy --quiet "$file" $DISABLE_NAMING -- \ + "${CXXFLAGS[@]}" "${lang_flags[@]}" -Wno-unknown-warning-option } if in_main ; then From e2a8e990bc48e3e7fe2dad1b08e61a57a334b0e7 Mon Sep 17 00:00:00 2001 From: K Henriksson Date: Sun, 13 Jun 2021 10:46:14 -0700 Subject: [PATCH 08/10] Use apt for Debian and Ubuntu package installation It was mentioned in #67 that aptitude isn't present by default in Debian, and apt seems to be the preferred tool now. --- INSTALL.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 2a9561d0..28584d12 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -18,15 +18,7 @@ If building from git, you'll also need: The commands to install the prerequisites follow. -### Debian - - aptitude install libfuse-dev libflac++-dev libvorbis-dev libmp3lame-dev libid3tag0-dev - -If building from git: - - aptitude install autoconf automake pandoc - -### Ubuntu +### Debian / Ubuntu apt install libfuse-dev libflac++-dev libvorbis-dev libmp3lame-dev libid3tag0-dev From 8ce2f43d23d7af5c34f277a76fd7e86259a6dcd0 Mon Sep 17 00:00:00 2001 From: K Henriksson Date: Sun, 13 Jun 2021 12:48:40 -0700 Subject: [PATCH 09/10] Update Travis build environment This also switches to a newer method for specifying extra packages to install. --- .travis.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 62689b92..26fa38a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,18 @@ -dist: bionic -sudo: required +dist: focal language: cpp compiler: - clang - gcc -before_install: - - sudo apt-get update -qq - - sudo apt-get install -qq --no-install-recommends libfuse-dev libflac++-dev libvorbis-dev libmp3lame-dev libid3tag0-dev pandoc libsox-dev libchromaprint-dev python3-mutagen +addons: + apt: + packages: + - libchromaprint-dev + - libflac++-dev + - libfuse-dev + - libid3tag0-dev + - libmp3lame-dev + - libsox-dev + - libvorbis-dev + - pandoc + - python3-mutagen script: ./autogen.sh && ./configure && make && make check && make staticcheck From 0bda17029964239f2ba03093f5ac138d30a5bec2 Mon Sep 17 00:00:00 2001 From: K Henriksson Date: Sun, 13 Jun 2021 14:26:33 -0700 Subject: [PATCH 10/10] Switch build status button to travis-ci.com --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 53ce5a5a..db6200d4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # mp3fs [![Build -Status](https://travis-ci.org/khenriks/mp3fs.svg?branch=master)](https://travis-ci.org/khenriks/mp3fs) +Status](https://travis-ci.com/khenriks/mp3fs.svg?branch=master)](https://travis-ci.com/khenriks/mp3fs) Web site: