From cc69274234892332edb9c8200cba8430eafef31c Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 21 Jun 2021 02:51:14 +0200 Subject: [PATCH] NO-OP: clang-format --- libs/ardour/ardour/ffmpegfileimportable.h | 33 +++++----- libs/ardour/ffmpegfileimportable.cc | 75 ++++++++++++----------- 2 files changed, 56 insertions(+), 52 deletions(-) diff --git a/libs/ardour/ardour/ffmpegfileimportable.h b/libs/ardour/ardour/ffmpegfileimportable.h index b14e8c1a5b..145cb4efe0 100644 --- a/libs/ardour/ardour/ffmpegfileimportable.h +++ b/libs/ardour/ardour/ffmpegfileimportable.h @@ -29,23 +29,25 @@ namespace ARDOUR { -class LIBARDOUR_API FFMPEGFileImportableSource : public ImportableSource { +class LIBARDOUR_API FFMPEGFileImportableSource : public ImportableSource +{ public: enum { ALL_CHANNELS = -1, }; - FFMPEGFileImportableSource(const std::string &path, int channel = ALL_CHANNELS); - virtual ~FFMPEGFileImportableSource(); + + FFMPEGFileImportableSource (const std::string& path, int channel = ALL_CHANNELS); + + virtual ~FFMPEGFileImportableSource (); /* ImportableSource API */ + samplecnt_t read (Sample*, samplecnt_t nframes); uint32_t channels () const { return _channels; } samplecnt_t length () const { return _length; } samplecnt_t samplerate () const { return _samplerate; } - samplepos_t natural_position () const { return _natural_position; } void seek (samplepos_t pos); - samplecnt_t read (Sample*, samplecnt_t nframes); - - bool clamped_at_unity () const { return false; } + samplepos_t natural_position () const { return _natural_position; } + bool clamped_at_unity () const { return false; } std::string format_name () const { return _format_name; } @@ -56,29 +58,30 @@ private: void did_read_data (std::string data, size_t size); std::string _path; - int _channel; + int _channel; - uint32_t _channels; + uint32_t _channels; samplecnt_t _length; samplecnt_t _samplerate; samplepos_t _natural_position; std::string _format_name; PBD::RingBuffer _buffer; - // Set to 1 to indicate that ffmpeg should be terminating. + /* Set to 1 to indicate that ffmpeg should be terminating. */ GATOMIC_QUAL gint _ffmpeg_should_terminate; - // To make sure we don't try to parse partial floats, we might have a couple of bytes - // of leftover unparsable data after any `did_read_data` call. Those couple of bytes are - // stored here until the next `did_read_data` call. + /* To make sure we don't try to parse partial floats, we might have a couple of bytes + * of leftover unparsable data after any `did_read_data` call. Those couple of bytes are + * stored here until the next `did_read_data` call. + */ std::string _leftover_data; samplecnt_t _read_pos; - ARDOUR::SystemExec *_ffmpeg_exec; + ARDOUR::SystemExec* _ffmpeg_exec; PBD::ScopedConnection _ffmpeg_conn; }; -} +} // namespace ARDOUR #endif /* _ardour_ffmpegfile_importable_source_h_ */ diff --git a/libs/ardour/ffmpegfileimportable.cc b/libs/ardour/ffmpegfileimportable.cc index ffdec03d3b..fe8d259acc 100644 --- a/libs/ardour/ffmpegfileimportable.cc +++ b/libs/ardour/ffmpegfileimportable.cc @@ -19,21 +19,22 @@ #include #include -#include "pbd/error.h" #include "pbd/compose.h" +#include "pbd/error.h" #include "pbd/i18n.h" #include "ardour/ffmpegfileimportable.h" #include "ardour/filesystem_paths.h" -namespace ARDOUR { +using namespace ARDOUR; static void -receive_stdout (std::string* out, const std::string& data, size_t size) { +receive_stdout (std::string* out, const std::string& data, size_t size) +{ *out += data; } -FFMPEGFileImportableSource::FFMPEGFileImportableSource(const std::string &path, int channel) +FFMPEGFileImportableSource::FFMPEGFileImportableSource (const std::string& path, int channel) : _path (path) , _channel (channel) , _buffer (32768) @@ -44,11 +45,12 @@ FFMPEGFileImportableSource::FFMPEGFileImportableSource(const std::string &path, std::string ffprobe_exe, unused; if (!ArdourVideoToolPaths::transcoder_exe (unused, ffprobe_exe)) { PBD::error << "FFMPEGFileImportableSource: Can't find ffprobe and ffmpeg" << endmsg; - throw failed_constructor(); + throw failed_constructor (); } - int a = 0; - char **argp = (char **)calloc(10, sizeof(char *)); + int a = 0; + char** argp = (char**)calloc (10, sizeof (char*)); + argp[a++] = strdup (ffprobe_exe.c_str ()); argp[a++] = strdup (_path.c_str ()); argp[a++] = strdup ("-show_streams"); @@ -61,55 +63,56 @@ FFMPEGFileImportableSource::FFMPEGFileImportableSource(const std::string &path, if (exec->start ()) { PBD::error << "FFMPEGFileImportableSource: External decoder (ffprobe) cannot be started." << endmsg; delete exec; - throw failed_constructor(); + throw failed_constructor (); } try { PBD::ScopedConnection c; - std::string ffprobe_output; + std::string ffprobe_output; exec->ReadStdout.connect_same_thread (c, boost::bind (&receive_stdout, &ffprobe_output, _1, _2)); /* wait for ffprobe process to exit */ - exec->wait(); + exec->wait (); namespace pt = boost::property_tree; + pt::ptree root; std::istringstream is (ffprobe_output); - pt::ptree root; + pt::read_json (is, root); // TODO: Find the stream with the most channels, rather than whatever the first one is. - _channels = root.get ("streams..channels"); - _length = root.get ("streams..duration_ts"); - _samplerate = root.get ("streams..sample_rate"); + _channels = root.get ("streams..channels"); + _length = root.get ("streams..duration_ts"); + _samplerate = root.get ("streams..sample_rate"); _natural_position = root.get ("streams..start_pts"); - _format_name = root.get ("streams..codec_long_name"); + _format_name = root.get ("streams..codec_long_name"); delete exec; } catch (...) { PBD::error << "FFMPEGFileImportableSource: Failed to read file metadata" << endmsg; delete exec; - throw failed_constructor(); + throw failed_constructor (); } - if (_channel != ALL_CHANNELS && (_channel < 0 || _channel > (int) channels ())) { - PBD::error << string_compose("FFMPEGFileImportableSource: file only contains %1 channels; %2 is invalid as a channel number", channels(), _channel) << endmsg; - throw failed_constructor(); + if (_channel != ALL_CHANNELS && (_channel < 0 || _channel > (int)channels ())) { + PBD::error << string_compose ("FFMPEGFileImportableSource: file only contains %1 channels; %2 is invalid as a channel number", channels (), _channel) << endmsg; + throw failed_constructor (); } } FFMPEGFileImportableSource::~FFMPEGFileImportableSource () { - reset(); + reset (); } void FFMPEGFileImportableSource::seek (samplepos_t pos) { if (pos < _read_pos) { - reset(); + reset (); } if (!_ffmpeg_exec) { - start_ffmpeg(); + start_ffmpeg (); } while (_read_pos < pos) { @@ -124,7 +127,7 @@ FFMPEGFileImportableSource::seek (samplepos_t pos) Glib::usleep (1000); continue; } - guint inc = std::min(read_space, pos - _read_pos); + guint inc = std::min (read_space, pos - _read_pos); _buffer.increment_read_idx (inc); _read_pos += inc; } @@ -134,7 +137,7 @@ samplecnt_t FFMPEGFileImportableSource::read (Sample* dst, samplecnt_t nframes) { if (!_ffmpeg_exec) { - start_ffmpeg(); + start_ffmpeg (); } samplecnt_t total_read = 0; @@ -163,16 +166,16 @@ FFMPEGFileImportableSource::start_ffmpeg () std::string ffmpeg_exe, unused; ArdourVideoToolPaths::transcoder_exe (ffmpeg_exe, unused); - int a = 0; - char **argp = (char **)calloc(16, sizeof(char *)); - char tmp[32]; + int a = 0; + char** argp = (char**)calloc (16, sizeof (char*)); + char tmp[32]; argp[a++] = strdup (ffmpeg_exe.c_str ()); argp[a++] = strdup ("-nostdin"); argp[a++] = strdup ("-i"); argp[a++] = strdup (_path.c_str ()); if (_channel != ALL_CHANNELS) { argp[a++] = strdup ("-map_channel"); - snprintf (tmp, sizeof(tmp), "0.0.%d", _channel); + snprintf (tmp, sizeof (tmp), "0.0.%d", _channel); argp[a++] = strdup (tmp); } argp[a++] = strdup ("-f"); @@ -187,7 +190,7 @@ FFMPEGFileImportableSource::start_ffmpeg () PBD::info << "Decode command: { " << _ffmpeg_exec->to_s () << "}" << endmsg; if (_ffmpeg_exec->start ()) { PBD::error << "FFMPEGFileImportableSource: External decoder (ffmpeg) cannot be started." << endmsg; - throw std::runtime_error("Failed to start ffmpeg"); + throw std::runtime_error ("Failed to start ffmpeg"); } _ffmpeg_exec->ReadStdout.connect_same_thread (_ffmpeg_conn, boost::bind (&FFMPEGFileImportableSource::did_read_data, this, _1, _2)); @@ -210,11 +213,11 @@ void FFMPEGFileImportableSource::did_read_data (std::string data, size_t size) { // Prepend the left-over data from a previous chunk of received data to this chunk. - data = _leftover_data + data; - samplecnt_t n_samples = data.length () / sizeof(float); + data = _leftover_data + data; + samplecnt_t n_samples = data.length () / sizeof (float); // Stash leftover data. - _leftover_data = data.substr(n_samples * sizeof(float)); + _leftover_data = data.substr (n_samples * sizeof (float)); const char* cur = data.data (); while (n_samples > 0) { @@ -232,14 +235,12 @@ FFMPEGFileImportableSource::did_read_data (std::string data, size_t size) samplecnt_t written = 0; for (int i = 0; i < 2; ++i) { - samplecnt_t cnt = std::min(n_samples, wv.len[i]); - memcpy (wv.buf[i], cur, cnt * sizeof(float)); + samplecnt_t cnt = std::min (n_samples, wv.len[i]); + memcpy (wv.buf[i], cur, cnt * sizeof (float)); written += cnt; n_samples -= cnt; - cur += cnt * sizeof(float); + cur += cnt * sizeof (float); } _buffer.increment_write_idx (written); } } - -}