Set Wavpack compression mode based on compression level.
This commit is contained in:
parent
af39994a59
commit
f34962f8cc
4 changed files with 19 additions and 7 deletions
|
@ -63,7 +63,8 @@ ssize_t packpnm_filter(struct filter_info *fi, void *filter_private);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _ENABLE_WAVPACK_
|
#ifdef _ENABLE_WAVPACK_
|
||||||
extern size_t wavpack_filter_encode(uchar_t *in_buf, size_t len, uchar_t **out_buf);
|
extern size_t wavpack_filter_encode(uchar_t *in_buf, size_t len, uchar_t **out_buf,
|
||||||
|
int cmp_level);
|
||||||
extern size_t wavpack_filter_decode(uchar_t *in_buf, size_t len, uchar_t **out_buf,
|
extern size_t wavpack_filter_decode(uchar_t *in_buf, size_t len, uchar_t **out_buf,
|
||||||
ssize_t out_len);
|
ssize_t out_len);
|
||||||
ssize_t wavpack_filter(struct filter_info *fi, void *filter_private);
|
ssize_t wavpack_filter(struct filter_info *fi, void *filter_private);
|
||||||
|
@ -484,7 +485,7 @@ wavpack_filter(struct filter_info *fi, void *filter_private)
|
||||||
*/
|
*/
|
||||||
if (fi->compressing) {
|
if (fi->compressing) {
|
||||||
out = NULL;
|
out = NULL;
|
||||||
len = wavpack_filter_encode(mapbuf, len, &out);
|
len = wavpack_filter_encode(mapbuf, len, &out, fi->cmp_level);
|
||||||
if (len == 0 || len >= (len1 - 8)) {
|
if (len == 0 || len >= (len1 - 8)) {
|
||||||
munmap(mapbuf, len1);
|
munmap(mapbuf, len1);
|
||||||
free(out);
|
free(out);
|
||||||
|
|
|
@ -49,6 +49,7 @@ struct filter_info {
|
||||||
int fd;
|
int fd;
|
||||||
int compressing, block_size;
|
int compressing, block_size;
|
||||||
int *type_ptr;
|
int *type_ptr;
|
||||||
|
int cmp_level;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct filter_flags {
|
struct filter_flags {
|
||||||
|
|
|
@ -867,7 +867,8 @@ setup_extractor(pc_ctx_t *pctx)
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
process_by_filter(int fd, int *typ, struct archive *target_arc,
|
process_by_filter(int fd, int *typ, struct archive *target_arc,
|
||||||
struct archive *source_arc, struct archive_entry *entry, int cmp)
|
struct archive *source_arc, struct archive_entry *entry, int cmp,
|
||||||
|
int level)
|
||||||
{
|
{
|
||||||
struct filter_info fi;
|
struct filter_info fi;
|
||||||
int64_t wrtn;
|
int64_t wrtn;
|
||||||
|
@ -879,6 +880,7 @@ process_by_filter(int fd, int *typ, struct archive *target_arc,
|
||||||
fi.compressing = cmp;
|
fi.compressing = cmp;
|
||||||
fi.block_size = AW_BLOCK_SIZE;
|
fi.block_size = AW_BLOCK_SIZE;
|
||||||
fi.type_ptr = typ;
|
fi.type_ptr = typ;
|
||||||
|
fi.cmp_level = level;
|
||||||
wrtn = (*(typetab[(*typ >> 3)].filter_func))(&fi, typetab[(*typ >> 3)].filter_private);
|
wrtn = (*(typetab[(*typ >> 3)].filter_func))(&fi, typetab[(*typ >> 3)].filter_private);
|
||||||
if (wrtn == FILTER_RETURN_ERROR) {
|
if (wrtn == FILTER_RETURN_ERROR) {
|
||||||
log_msg(LOG_ERR, 0, "Error invoking filter module: %s",
|
log_msg(LOG_ERR, 0, "Error invoking filter module: %s",
|
||||||
|
@ -942,7 +944,8 @@ copy_file_data(pc_ctx_t *pctx, struct archive *arc, struct archive_entry *entry,
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
pctx->ctype = typ;
|
pctx->ctype = typ;
|
||||||
rv = process_by_filter(fd, &(pctx->ctype), arc, NULL, entry, 1);
|
rv = process_by_filter(fd, &(pctx->ctype), arc, NULL, entry,
|
||||||
|
1, pctx->level);
|
||||||
if (rv == FILTER_RETURN_ERROR) {
|
if (rv == FILTER_RETURN_ERROR) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
@ -999,7 +1002,8 @@ do_map:
|
||||||
}
|
}
|
||||||
|
|
||||||
munmap(mapbuf, len);
|
munmap(mapbuf, len);
|
||||||
rv = process_by_filter(fd, &(pctx->ctype), arc, NULL, entry, 1);
|
rv = process_by_filter(fd, &(pctx->ctype), arc, NULL, entry,
|
||||||
|
1, pctx->level);
|
||||||
if (rv == FILTER_RETURN_ERROR) {
|
if (rv == FILTER_RETURN_ERROR) {
|
||||||
return (-1);
|
return (-1);
|
||||||
} else if (rv == FILTER_RETURN_SKIP) {
|
} else if (rv == FILTER_RETURN_SKIP) {
|
||||||
|
@ -1211,7 +1215,7 @@ copy_data_out(struct archive *ar, struct archive *aw, struct archive_entry *entr
|
||||||
if (typetab[(typ >> 3)].filter_func != NULL) {
|
if (typetab[(typ >> 3)].filter_func != NULL) {
|
||||||
int64_t rv;
|
int64_t rv;
|
||||||
|
|
||||||
rv = process_by_filter(-1, &typ, aw, ar, entry, 0);
|
rv = process_by_filter(-1, &typ, aw, ar, entry, 0, 0);
|
||||||
if (rv == FILTER_RETURN_ERROR) {
|
if (rv == FILTER_RETURN_ERROR) {
|
||||||
archive_set_error(ar, archive_errno(aw),
|
archive_set_error(ar, archive_errno(aw),
|
||||||
"%s", archive_error_string(aw));
|
"%s", archive_error_string(aw));
|
||||||
|
|
|
@ -307,7 +307,7 @@ pack_audio(WavpackContext *wpc, read_data *rdat)
|
||||||
* pack_file() in cli/wavpack.c and unpack_file() in cli/wvunpack.c
|
* pack_file() in cli/wavpack.c and unpack_file() in cli/wvunpack.c
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
wavpack_filter_encode(uchar_t *in_buf, size_t len, uchar_t **out_buf)
|
wavpack_filter_encode(uchar_t *in_buf, size_t len, uchar_t **out_buf, int cmp_level)
|
||||||
{
|
{
|
||||||
uint32_t total_samples = 0, bcount;
|
uint32_t total_samples = 0, bcount;
|
||||||
WavpackConfig loc_config;
|
WavpackConfig loc_config;
|
||||||
|
@ -325,6 +325,12 @@ wavpack_filter_encode(uchar_t *in_buf, size_t len, uchar_t **out_buf)
|
||||||
memset(&loc_config, 0, sizeof (loc_config));
|
memset(&loc_config, 0, sizeof (loc_config));
|
||||||
adobe_mode = 0;
|
adobe_mode = 0;
|
||||||
|
|
||||||
|
if (cmp_level < 6) {
|
||||||
|
loc_config.flags |= CONFIG_FAST_FLAG;
|
||||||
|
} else if (cmp_level > 8) {
|
||||||
|
loc_config.flags |= CONFIG_HIGH_FLAG;
|
||||||
|
}
|
||||||
|
|
||||||
*out_buf = (uchar_t *)malloc(len);
|
*out_buf = (uchar_t *)malloc(len);
|
||||||
if (*out_buf == NULL) {
|
if (*out_buf == NULL) {
|
||||||
log_msg(LOG_ERR, 1, "malloc failed.");
|
log_msg(LOG_ERR, 1, "malloc failed.");
|
||||||
|
|
Loading…
Reference in a new issue