Prepare support for compression levels (archive + flac)
This commit is contained in:
parent
86d3735ea8
commit
df83c0381e
|
@ -276,6 +276,21 @@ SndFileSource::SndFileSource (Session& s, const AudioFileSource& other, const st
|
||||||
throw failed_constructor();
|
throw failed_constructor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* setting flac compression quality above the default does not produce a significant size
|
||||||
|
* improvement (not for large raw recordings anyway, the_CLA tests 2017-10-02, >> 250MB files,
|
||||||
|
* ~1% smaller), but does have a significant encoding speed penalty.
|
||||||
|
*
|
||||||
|
* We still may expose this as option someday though, perhaps for opposite reason: "fast encoding"
|
||||||
|
*/
|
||||||
|
double flac_quality = 1; // libsndfile uses range 0..1 (mapped to flac 0..8), default is (5/8)
|
||||||
|
if (sf_command (_sndfile, SFC_SET_COMPRESSION_LEVEL, &flac_quality, sizeof (double)) != SF_TRUE) {
|
||||||
|
char errbuf[256];
|
||||||
|
sf_error_str (_sndfile, errbuf, sizeof (errbuf) - 1);
|
||||||
|
error << string_compose (_("Cannot set flac compression level: %1"), errbuf) << endmsg;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Sample buf[8192];
|
Sample buf[8192];
|
||||||
samplecnt_t off = 0;
|
samplecnt_t off = 0;
|
||||||
float peak = 0;
|
float peak = 0;
|
||||||
|
|
|
@ -16,6 +16,11 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -337,7 +342,7 @@ FileArchive::do_extract (struct archive* a)
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
FileArchive::create (const std::string& srcdir)
|
FileArchive::create (const std::string& srcdir, CompressionLevel compression_level)
|
||||||
{
|
{
|
||||||
if (_req.is_remote ()) {
|
if (_req.is_remote ()) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -357,11 +362,11 @@ FileArchive::create (const std::string& srcdir)
|
||||||
filemap[*f] = f->substr (p_len);
|
filemap[*f] = f->substr (p_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return create (filemap);
|
return create (filemap, compression_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
FileArchive::create (const std::map<std::string, std::string>& filemap)
|
FileArchive::create (const std::map<std::string, std::string>& filemap, CompressionLevel compression_level)
|
||||||
{
|
{
|
||||||
struct archive *a;
|
struct archive *a;
|
||||||
struct archive_entry *entry;
|
struct archive_entry *entry;
|
||||||
|
@ -385,10 +390,21 @@ FileArchive::create (const std::map<std::string, std::string>& filemap)
|
||||||
|
|
||||||
a = archive_write_new ();
|
a = archive_write_new ();
|
||||||
archive_write_set_format_pax_restricted (a);
|
archive_write_set_format_pax_restricted (a);
|
||||||
archive_write_add_filter_lzma (a);
|
|
||||||
|
if (compression_level != CompressNone) {
|
||||||
|
archive_write_add_filter_lzma (a);
|
||||||
|
char buf[48];
|
||||||
|
sprintf (buf, "lzma:compression-level=%u,lzma:threads=0", (uint32_t) compression_level);
|
||||||
|
archive_write_set_options (a, buf);
|
||||||
|
}
|
||||||
|
|
||||||
archive_write_open_filename (a, _req.url);
|
archive_write_open_filename (a, _req.url);
|
||||||
entry = archive_entry_new ();
|
entry = archive_entry_new ();
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
const int64_t archive_start_time = g_get_monotonic_time();
|
||||||
|
#endif
|
||||||
|
|
||||||
for (std::map<std::string, std::string>::const_iterator f = filemap.begin (); f != filemap.end (); ++f) {
|
for (std::map<std::string, std::string>::const_iterator f = filemap.begin (); f != filemap.end (); ++f) {
|
||||||
char buf[8192];
|
char buf[8192];
|
||||||
const char* filepath = f->first.c_str ();
|
const char* filepath = f->first.c_str ();
|
||||||
|
@ -433,5 +449,10 @@ FileArchive::create (const std::map<std::string, std::string>& filemap)
|
||||||
archive_write_close (a);
|
archive_write_close (a);
|
||||||
archive_write_free (a);
|
archive_write_free (a);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
const int64_t elapsed_time_us = g_get_monotonic_time() - archive_start_time;
|
||||||
|
std::cerr << "archived in " << std::fixed << std::setprecision (2) << elapsed_time_us / 1000000. << " sec\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,17 @@ class LIBPBD_API FileArchive
|
||||||
int inflate (const std::string& destdir);
|
int inflate (const std::string& destdir);
|
||||||
std::vector<std::string> contents ();
|
std::vector<std::string> contents ();
|
||||||
|
|
||||||
int create (const std::string& srcdir);
|
/* these are mapped to libarchive's lzmaz
|
||||||
int create (const std::map <std::string, std::string>& filemap);
|
* compression level 0..9
|
||||||
|
*/
|
||||||
|
enum CompressionLevel {
|
||||||
|
CompressNone = -1,
|
||||||
|
CompressFast = 0,
|
||||||
|
CompressGood = 6
|
||||||
|
};
|
||||||
|
|
||||||
|
int create (const std::string& srcdir, CompressionLevel compression_level = CompressGood);
|
||||||
|
int create (const std::map <std::string, std::string>& filemap, CompressionLevel compression_level = CompressGood);
|
||||||
|
|
||||||
PBD::Signal2<void, size_t, size_t> progress; // TODO
|
PBD::Signal2<void, size_t, size_t> progress; // TODO
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user