diff options
author | Ian Nartowicz <iann@crunchbang> | 2014-06-14 00:10:49 +0100 |
---|---|---|
committer | Ian Nartowicz <iann@crunchbang> | 2014-06-14 00:10:49 +0100 |
commit | caf400178adbcaaace2a258354b7310067726a04 (patch) | |
tree | b03bd9a087583ee21ac13dd8bf6544db42a67da9 /plugins | |
parent | 17463ab388e7c2a95db8f19e41a1fad459a63717 (diff) |
bitrate for OggFLAC, plus oggedit changes
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/flac/flac.c | 15 | ||||
-rw-r--r-- | plugins/liboggedit/oggedit.h | 1 | ||||
-rw-r--r-- | plugins/liboggedit/oggedit_flac.c | 11 | ||||
-rw-r--r-- | plugins/liboggedit/oggedit_internal.c | 32 | ||||
-rw-r--r-- | plugins/liboggedit/oggedit_internal.h | 2 | ||||
-rw-r--r-- | plugins/liboggedit/oggedit_opus.c | 9 | ||||
-rw-r--r-- | plugins/liboggedit/oggedit_vorbis.c | 5 |
7 files changed, 47 insertions, 28 deletions
diff --git a/plugins/flac/flac.c b/plugins/flac/flac.c index 7cb38458..5deab23e 100644 --- a/plugins/flac/flac.c +++ b/plugins/flac/flac.c @@ -791,9 +791,18 @@ cflac_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) { snprintf (s, sizeof (s), "%d", info.info.fmt.samplerate); deadbeef->pl_add_meta (it, ":SAMPLERATE", s); if ( deadbeef->pl_get_item_duration (it) > 0) { - FLAC__uint64 position; - if (FLAC__stream_decoder_get_decode_position (decoder, &position)) - fsize -= position; + if (!isogg) { + FLAC__uint64 position; + if (FLAC__stream_decoder_get_decode_position (decoder, &position)) + fsize -= position; + } +#if USE_OGGEDIT + else { + const off_t stream_size = oggedit_flac_stream_info(deadbeef->fopen(fname), 0, 0); + if (stream_size > 0) + fsize = stream_size; + } +#endif deadbeef->pl_set_meta_int (it, ":BITRATE", (int)roundf(fsize / deadbeef->pl_get_item_duration (it) * 8 / 1000)); } FLAC__stream_decoder_delete(decoder); diff --git a/plugins/liboggedit/oggedit.h b/plugins/liboggedit/oggedit.h index b0a4d9b0..94f08e32 100644 --- a/plugins/liboggedit/oggedit.h +++ b/plugins/liboggedit/oggedit.h @@ -79,6 +79,7 @@ const char *oggedit_album_art_type(const int type); char *oggedit_album_art_tag(DB_FILE *fp, int *res); /* oggedit_flac.c */ +off_t oggedit_flac_stream_info(DB_FILE *in, const off_t start_offset, const off_t end_offset); off_t oggedit_write_flac_metadata(DB_FILE *in, const char *fname, const off_t offset, const int num_tags, char **tags); /* oggedit_vorbis.c */ diff --git a/plugins/liboggedit/oggedit_flac.c b/plugins/liboggedit/oggedit_flac.c index 7c4e5653..9aa89716 100644 --- a/plugins/liboggedit/oggedit_flac.c +++ b/plugins/liboggedit/oggedit_flac.c @@ -36,6 +36,15 @@ #define VCTYPE 0x04 #define LASTBLOCK 0x80 +off_t oggedit_flac_stream_info(DB_FILE *in, const off_t start_offset, const off_t end_offset) +{ + ogg_sync_state oy; + ogg_sync_init(&oy); + const off_t stream_size = codec_stream_size(in, &oy, start_offset, end_offset, FLACNAME); + cleanup(in, NULL, &oy, NULL); + return stream_size; +} + static void clear_header_list(ogg_packet **headers) { if (headers) { @@ -196,7 +205,7 @@ off_t oggedit_write_flac_metadata(DB_FILE *in, const char *fname, const off_t of /* If we have tempfile, copy the remaining pages */ if (*tempname) { - if ((res = copy_remaining_pages(in, out, &oy, flac_serial, pageno)) < OGGEDIT_EOF) + if ((res = copy_remaining_pages(in, out, &oy, flac_serial, pageno)) <= OGGEDIT_EOF) goto cleanup; if (rename(tempname, fname)) { res = OGGEDIT_RENAME_FAILED; diff --git a/plugins/liboggedit/oggedit_internal.c b/plugins/liboggedit/oggedit_internal.c index 130a6fed..f3c9b2d9 100644 --- a/plugins/liboggedit/oggedit_internal.c +++ b/plugins/liboggedit/oggedit_internal.c @@ -285,25 +285,21 @@ long flush_stream(FILE *out, ogg_stream_state *os) return pageno; } -char *codec_names(DB_FILE *in, ogg_sync_state *oy, const off_t link_offset, int *res) +char *codec_names(DB_FILE *in, ogg_sync_state *oy, const off_t link_offset) { ogg_page og; - *res = skip_to_bos(in, oy, &og, link_offset); + int serial = skip_to_bos(in, oy, &og, link_offset); char *codecs = strdup("Ogg"); - while (codecs && *res > OGGEDIT_EOF && ogg_page_bos(&og)) { + while (codecs && serial > OGGEDIT_EOF && ogg_page_bos(&og)) { codecs = cat_string(codecs, codec_name(&og), strcmp(codecs, "Ogg") ? "/" : " "); - *res = get_page(in, oy, &og); - } - if (!*codecs) { - *res = OGGEDIT_ALLOCATION_FAILURE; - return NULL; + serial = get_page(in, oy, &og); } - if (*res <= OGGEDIT_EOF) { + + if (serial <= OGGEDIT_EOF) { free(codecs); return NULL; } - *res = OGGEDIT_OK; return codecs; } @@ -324,8 +320,9 @@ off_t codec_stream_size(DB_FILE *in, ogg_sync_state *oy, const off_t start_offse /* Skip to the first codec data page */ while (serial > OGGEDIT_EOF && !(ogg_page_granulepos(&og) > 0 && serial == codec_serial)) - if ((serial = get_page(in, oy, &og)) <= OGGEDIT_EOF) - return serial; + serial = get_page(in, oy, &og); + if (serial <= OGGEDIT_EOF) + return serial; off_t stream_size = 0; if (multiplex) { @@ -465,6 +462,8 @@ int copy_remaining_pages(DB_FILE *in, FILE *out, ogg_sync_state *oy, const int c do serial = get_page(in, oy, &og); while (serial > OGGEDIT_EOF && serial == codec_serial && ogg_page_granulepos(&og) <= 0); + if (serial <= OGGEDIT_EOF) + return serial; /* Renumber the rest of this link */ while (serial > OGGEDIT_EOF && !ogg_page_bos(&og)) { @@ -481,8 +480,10 @@ int copy_remaining_pages(DB_FILE *in, FILE *out, ogg_sync_state *oy, const int c /* Blindly copy remaining links */ while (serial > OGGEDIT_EOF) serial = write_page_and_get_next(in, out, oy, &og); + if (serial < OGGEDIT_EOF) + return serial; - return serial; + return OGGEDIT_OK; } int write_all_streams(DB_FILE *in, FILE *out, ogg_sync_state *oy, const off_t offset) @@ -497,8 +498,9 @@ int write_all_streams(DB_FILE *in, FILE *out, ogg_sync_state *oy, const off_t of /* Copy all pages until EOF or next link */ while (serial > OGGEDIT_EOF && !ogg_page_bos(&og)) - if ((serial = write_page_and_get_next(in, out, oy, &og)) < OGGEDIT_EOF) - return serial; + serial = write_page_and_get_next(in, out, oy, &og); + if (serial < OGGEDIT_EOF) + return serial; return OGGEDIT_OK; } diff --git a/plugins/liboggedit/oggedit_internal.h b/plugins/liboggedit/oggedit_internal.h index a52b2ae4..d050ac72 100644 --- a/plugins/liboggedit/oggedit_internal.h +++ b/plugins/liboggedit/oggedit_internal.h @@ -53,7 +53,7 @@ void cleanup(DB_FILE *in, FILE *out, ogg_sync_state *oy, void *buffer); int copy_up_to_codec(DB_FILE *in, FILE *out, ogg_sync_state *oy, ogg_page *og, const off_t start_offset, const off_t link_offset, const char *codec); int copy_up_to_header(DB_FILE *in, FILE *out, ogg_sync_state *oy, ogg_page *og, const int codec_serial); long flush_stream(FILE *out, ogg_stream_state *os); -char *codec_names(DB_FILE *in, ogg_sync_state *oy, const off_t link_offset, int *res); +char *codec_names(DB_FILE *in, ogg_sync_state *oy, const off_t link_offset); off_t codec_stream_size(DB_FILE *in, ogg_sync_state *oy, const off_t start_offset, const off_t end_offset, const char *codec); char *parse_vendor(const ogg_packet *op, const size_t magic_length); int init_read_stream(DB_FILE *in, ogg_sync_state *oy, ogg_stream_state *os, ogg_page *og, const off_t offset, const char *codec); diff --git a/plugins/liboggedit/oggedit_opus.c b/plugins/liboggedit/oggedit_opus.c index 5533a619..21d75360 100644 --- a/plugins/liboggedit/oggedit_opus.c +++ b/plugins/liboggedit/oggedit_opus.c @@ -60,10 +60,9 @@ int oggedit_write_opus_file(DB_FILE *in, const char *outname, const off_t offset off_t oggedit_opus_stream_info(DB_FILE *in, const off_t start_offset, const off_t end_offset, char **codecs) { - int res; ogg_sync_state oy; ogg_sync_init(&oy); - *codecs = codec_names(in, &oy, start_offset, &res); + *codecs = codec_names(in, &oy, start_offset); const off_t stream_size = codec_stream_size(in, &oy, start_offset, end_offset, OPUSNAME); cleanup(in, NULL, &oy, NULL); return stream_size; @@ -174,7 +173,7 @@ off_t oggedit_write_opus_metadata(DB_FILE *in, const char *fname, const off_t of /* If we have tempfile, copy the remaining pages */ if (*tempname) { - if ((res = copy_remaining_pages(in, out, &oy, opus_serial, pageno)) < OGGEDIT_EOF) + if ((res = copy_remaining_pages(in, out, &oy, opus_serial, pageno)) <= OGGEDIT_EOF) goto cleanup; if (rename(tempname, fname)) { res = OGGEDIT_RENAME_FAILED; @@ -193,8 +192,8 @@ cleanup: /* struct timeval timeval; gettimeofday(&timeval, NULL); -int usecs = timeval.tv_sec* 1000000 + timeval.tv_usec; +int usecs = timeval.tv_sec*1000000 + timeval.tv_usec; gettimeofday(&timeval, NULL); -usecs = timeval.tv_sec* 1000000 + timeval.tv_usec - usecs; +usecs = timeval.tv_sec*1000000 + timeval.tv_usec - usecs; fprintf(stderr, "%d micro-seconds\n", usecs); */ diff --git a/plugins/liboggedit/oggedit_vorbis.c b/plugins/liboggedit/oggedit_vorbis.c index e1252411..9d97b076 100644 --- a/plugins/liboggedit/oggedit_vorbis.c +++ b/plugins/liboggedit/oggedit_vorbis.c @@ -37,10 +37,9 @@ off_t oggedit_vorbis_stream_info(DB_FILE *in, const off_t start_offset, const off_t end_offset, char **codecs) { - int res; ogg_sync_state oy; ogg_sync_init(&oy); - *codecs = codec_names(in, &oy, start_offset, &res); + *codecs = codec_names(in, &oy, start_offset); const off_t stream_size = codec_stream_size(in, &oy, start_offset, end_offset, VORBISNAME); cleanup(in, NULL, &oy, NULL); return stream_size; @@ -152,7 +151,7 @@ off_t oggedit_write_vorbis_metadata(DB_FILE *in, const char *fname, const off_t /* If we have tempfile, copy the remaining pages */ if (*tempname) { - if ((res = copy_remaining_pages(in, out, &oy, vorbis_serial, pageno)) < OGGEDIT_EOF) + if ((res = copy_remaining_pages(in, out, &oy, vorbis_serial, pageno)) <= OGGEDIT_EOF) goto cleanup; if (rename(tempname, fname)) { res = OGGEDIT_RENAME_FAILED; |