From e4f6a43d63372d9ddc21574d5fc43aea01c9c117 Mon Sep 17 00:00:00 2001 From: Ian Nartowicz Date: Tue, 10 Jun 2014 16:40:52 +0100 Subject: ogg_stream_flush_fill conditional compilation --- plugins/liboggedit/oggedit.h | 2 +- plugins/liboggedit/oggedit_art.c | 10 +++------- plugins/liboggedit/oggedit_flac.c | 13 +++++-------- plugins/liboggedit/oggedit_internal.c | 14 +++++++------- plugins/liboggedit/oggedit_internal.h | 8 ++++++++ plugins/liboggedit/oggedit_opus.c | 8 ++++---- plugins/liboggedit/oggedit_utils.c | 2 +- plugins/liboggedit/oggedit_vorbis.c | 13 +++++-------- 8 files changed, 34 insertions(+), 36 deletions(-) (limited to 'plugins/liboggedit') diff --git a/plugins/liboggedit/oggedit.h b/plugins/liboggedit/oggedit.h index b0a4d9b0..d95d51bd 100644 --- a/plugins/liboggedit/oggedit.h +++ b/plugins/liboggedit/oggedit.h @@ -61,7 +61,7 @@ #define OGGEDIT_STAT_FAILED -13 /* I/O error writing to file (disk full?) */ #define OGGEDIT_WRITE_ERROR -14 -/* Failed to flush pages from a stream, fatal Ogg internal error */ +/* Failed to flush pages from a stream, fatal Ogg internal error (libogg < v1.2.0?)*/ #define OGGEDIT_FLUSH_FAILED -15 /* Renaming tewmporary file failed (usually sticky bit or directory permissions) */ #define OGGEDIT_RENAME_FAILED -16 diff --git a/plugins/liboggedit/oggedit_art.c b/plugins/liboggedit/oggedit_art.c index 83e1c193..79b1e78e 100644 --- a/plugins/liboggedit/oggedit_art.c +++ b/plugins/liboggedit/oggedit_art.c @@ -29,11 +29,7 @@ #endif #include #include -#include -#include -#include "../../deadbeef.h" #include "oggedit_internal.h" -#include "oggedit.h" const char *oggedit_album_art_type(const int type) { @@ -154,9 +150,9 @@ char *oggedit_album_art_tag(DB_FILE *fp, int *res) oggpackB_write(&opb, 3, 32); _oggpackB_string(&opb, memcmp(data, "\x89PNG\x0D\x0A\x1A\x0A", 8) ? "image/jpeg" : "image/png"); _oggpackB_string(&opb, "Album art added from DeaDBeeF"); - oggpackB_write(&opb, 0, 32); - oggpackB_write(&opb, 0, 32); - oggpackB_write(&opb, 0, 32); + oggpackB_write(&opb, 1, 32); /* workaround for opusfile bug */ + oggpackB_write(&opb, 1, 32); + oggpackB_write(&opb, 1, 32); oggpackB_write(&opb, 0, 32); oggpackB_write(&opb, data_length, 32); _oggpack_chars(&opb, data, data_length); diff --git a/plugins/liboggedit/oggedit_flac.c b/plugins/liboggedit/oggedit_flac.c index fd3a71a6..b60a1d5a 100644 --- a/plugins/liboggedit/oggedit_flac.c +++ b/plugins/liboggedit/oggedit_flac.c @@ -30,14 +30,7 @@ #include #include #include -#include -#include -#if HAVE_SYS_SYSLIMITS_H -#include -#endif -#include "../../deadbeef.h" #include "oggedit_internal.h" -#include "oggedit.h" #define PADTYPE 0x01 #define VCTYPE 0x04 @@ -99,11 +92,15 @@ static ogg_packet **metadata_block_packets(DB_FILE *in, ogg_sync_state *oy, cons } *vendor = parse_vendor(headers[0], 4); +#ifdef HAVE_OGG_STREAM_FLUSH_FILL size_t bytes = 0; for (size_t i = 0; i < packets; i++) bytes += headers[i]->bytes; if (bytes < MAXPAYLOAD * (pages-1)) headers[0]->bytes = 4; +#else + headers[0]->bytes = 4; // not safe to pad without ogg_stream_flush_fill +#endif *res = OGGEDIT_OK; return headers; @@ -161,7 +158,7 @@ off_t oggedit_write_flac_metadata(DB_FILE *in, const char *fname, const off_t of const off_t stream_size_k = in->vfs->getlength(in) / 1000; // use file size for now const size_t metadata_size = 4 + vc_size(vendor, num_tags, tags); ptrdiff_t padding = headers[0]->bytes - metadata_size; - if (stream_size_k < 1000 || padding < 0 || (headers[1] && padding > 0) || padding > stream_size_k+metadata_size) { + if (stream_size_k < 1000 || padding < 0 || headers[1] && padding > 0 || padding > stream_size_k+metadata_size) { res = open_temp_file(fname, tempname, &out); if (res) { goto cleanup; diff --git a/plugins/liboggedit/oggedit_internal.c b/plugins/liboggedit/oggedit_internal.c index f12e8d6d..130a6fed 100644 --- a/plugins/liboggedit/oggedit_internal.c +++ b/plugins/liboggedit/oggedit_internal.c @@ -31,16 +31,9 @@ #include #include #include -#include #include #include #include -#include -#if HAVE_SYS_SYSLIMITS_H -#include -#endif -#include "../../deadbeef.h" -#include "oggedit.h" #include "oggedit_internal.h" static char *cat_string(char *dest, const char *src, const char *sep) @@ -279,9 +272,14 @@ int copy_up_to_header(DB_FILE *in, FILE *out, ogg_sync_state *oy, ogg_page *og, long flush_stream(FILE *out, ogg_stream_state *os) { ogg_page og; +#ifdef HAVE_OGG_STREAM_FLUSH_FILL + while (ogg_stream_flush_fill(os, &og, MAXPAYLOAD)) +#else while (ogg_stream_flush(os, &og)) +#endif if (!write_page(out, &og)) return OGGEDIT_WRITE_ERROR; + const long pageno = ogg_stream_check(os) ? OGGEDIT_FLUSH_FAILED : ogg_page_pageno(&og); ogg_stream_clear(os); return pageno; @@ -428,8 +426,10 @@ ogg_packet *fill_vc_packet(const char *magic, const size_t magic_length, const c oggpack_write(&opb, 1, 1); oggpack_writealign(&opb); } +#ifdef HAVE_OGG_STREAM_FLUSH_FILL for (size_t i = 0; i < padding; i++) oggpack_write(&opb, 0, 8); // use oggpack_writecopy when it is fixed +#endif if (oggpack_writecheck(&opb)) return NULL; diff --git a/plugins/liboggedit/oggedit_internal.h b/plugins/liboggedit/oggedit_internal.h index 46a84345..c152c3c1 100644 --- a/plugins/liboggedit/oggedit_internal.h +++ b/plugins/liboggedit/oggedit_internal.h @@ -27,6 +27,14 @@ #ifndef __OGGEDIT_INT_H #define __OGGEDIT_INT_H +#include +#include +#if HAVE_SYS_SYSLIMITS_H +#include +#endif +#include +#include "oggedit.h" + #define OPUSNAME "Opus" #define VORBISNAME "Vorbis" #define FLACNAME "Flac" diff --git a/plugins/liboggedit/oggedit_opus.c b/plugins/liboggedit/oggedit_opus.c index 5d167094..5533a619 100644 --- a/plugins/liboggedit/oggedit_opus.c +++ b/plugins/liboggedit/oggedit_opus.c @@ -30,12 +30,8 @@ #include #include #include -#include #include -#include -#include "../../deadbeef.h" #include "oggedit_internal.h" -#include "oggedit.h" #define TAGMAGIC "OpusTags" @@ -93,8 +89,12 @@ static ptrdiff_t check_opus_header(DB_FILE *in, ogg_sync_state *oy, const off_t if (!*vendor) return OGGEDIT_CANNOT_PARSE_HEADERS; +#ifdef HAVE_OGG_STREAM_FLUSH_FILL if (op.bytes < MAXPAYLOAD * (pages-1)) return 4; // prevent in-place write if the packet is weirdly split into too many pages +#else + return 4; // not safe to pad without ogg_stream_flush_fill +#endif return op.bytes; } diff --git a/plugins/liboggedit/oggedit_utils.c b/plugins/liboggedit/oggedit_utils.c index 2d40e275..c47d90f5 100644 --- a/plugins/liboggedit/oggedit_utils.c +++ b/plugins/liboggedit/oggedit_utils.c @@ -30,8 +30,8 @@ #include #include #include -#include #include +#include "oggedit_internal.h" uint8_t *oggedit_vorbis_channel_map(const int channel_count) { diff --git a/plugins/liboggedit/oggedit_vorbis.c b/plugins/liboggedit/oggedit_vorbis.c index 499c88b0..e1252411 100644 --- a/plugins/liboggedit/oggedit_vorbis.c +++ b/plugins/liboggedit/oggedit_vorbis.c @@ -30,14 +30,7 @@ #include #include #include -#include -#include -#if HAVE_SYS_SYSLIMITS_H -#include -#endif -#include "../../deadbeef.h" #include "oggedit_internal.h" -#include "oggedit.h" #define VCMAGIC "\3vorbis" #define CODEMAGIC "\5vorbis" @@ -76,8 +69,12 @@ static ptrdiff_t check_vorbis_headers(DB_FILE *in, ogg_sync_state *oy, const off if (!*vendor) return OGGEDIT_CANNOT_PARSE_HEADERS; +#ifdef HAVE_OGG_STREAM_FLUSH_FILL if ((vc.bytes + codebooks->bytes) < MAXPAYLOAD * (pages-1)) return 4; // prevent in-place write if the packets are split over too many pages +#else + return 4; // not safe to pad without ogg_stream_flush_fill +#endif return vc.bytes; } @@ -128,7 +125,7 @@ off_t oggedit_write_vorbis_metadata(DB_FILE *in, const char *fname, const off_t const off_t file_size_k = in->vfs->getlength(in) / 1000; const size_t stream_size_k = stream_size ? stream_size / 1000 : file_size_k; if (file_size_k < 100 || padding < 0 || padding > file_size_k/10+stream_size_k+metadata_size) { - res = open_temp_file (fname, tempname, &out); + res = open_temp_file(fname, tempname, &out); if (res) { goto cleanup; } -- cgit v1.2.3