Set Wavpack compression mode based on compression level.

This commit is contained in:
Moinak Ghosh 2014-09-17 21:43:00 +05:30
parent af39994a59
commit f34962f8cc
4 changed files with 19 additions and 7 deletions

View file

@ -63,7 +63,8 @@ ssize_t packpnm_filter(struct filter_info *fi, void *filter_private);
#endif
#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,
ssize_t out_len);
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) {
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)) {
munmap(mapbuf, len1);
free(out);

View file

@ -49,6 +49,7 @@ struct filter_info {
int fd;
int compressing, block_size;
int *type_ptr;
int cmp_level;
};
struct filter_flags {

View file

@ -867,7 +867,8 @@ setup_extractor(pc_ctx_t *pctx)
static ssize_t
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;
int64_t wrtn;
@ -879,6 +880,7 @@ process_by_filter(int fd, int *typ, struct archive *target_arc,
fi.compressing = cmp;
fi.block_size = AW_BLOCK_SIZE;
fi.type_ptr = typ;
fi.cmp_level = level;
wrtn = (*(typetab[(*typ >> 3)].filter_func))(&fi, typetab[(*typ >> 3)].filter_private);
if (wrtn == FILTER_RETURN_ERROR) {
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);
}
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) {
close(fd);
return (-1);
@ -999,7 +1002,8 @@ do_map:
}
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) {
return (-1);
} 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) {
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) {
archive_set_error(ar, archive_errno(aw),
"%s", archive_error_string(aw));

View file

@ -307,7 +307,7 @@ pack_audio(WavpackContext *wpc, read_data *rdat)
* pack_file() in cli/wavpack.c and unpack_file() in cli/wvunpack.c
*/
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;
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));
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);
if (*out_buf == NULL) {
log_msg(LOG_ERR, 1, "malloc failed.");