Skip to content

Commit

Permalink
Add level 0 Ogg reading capability to tests and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmf01 committed Jul 18, 2024
1 parent f94d34f commit 8c244b8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
30 changes: 17 additions & 13 deletions include/FLAC/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
* This module provides functions for creating and manipulating FLAC
* metadata blocks in memory, and three progressively more powerful
* interfaces for traversing and editing metadata in native FLAC files.
* Note that currently only the Chain interface (level 2) supports Ogg
* FLAC files, and it is read-only i.e. no writing back changed
* metadata to file.
* Note that currently only the Chain interface (level 2) and some
* functions in level 0 supports Ogg FLAC files, and they are
* read-only i.e. no writing back changed metadata to file.
*
* There are three metadata interfaces of increasing complexity:
*
Expand Down Expand Up @@ -144,10 +144,11 @@ extern "C" {
* \{
*/

/** Read the STREAMINFO metadata block of the given FLAC file. This function
* will try to skip any ID3v2 tag at the head of the file.
/** Read the STREAMINFO metadata block of the given FLAC or Ogg FLAC
* file. This function will try to skip any ID3v2 tag at the head
* of the file.
*
* \param filename The path to the FLAC file to read.
* \param filename The path to the FLAC or Ogg FLAC file to read.
* \param streaminfo A pointer to space for the STREAMINFO block. Since
* FLAC__StreamMetadata is a simple structure with no
* memory allocation involved, you pass the address of
Expand All @@ -163,10 +164,11 @@ extern "C" {
*/
FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);

/** Read the VORBIS_COMMENT metadata block of the given FLAC file. This
* function will try to skip any ID3v2 tag at the head of the file.
/** Read the VORBIS_COMMENT metadata block of the given FLAC or Ogg FLAC
* file. This function will try to skip any ID3v2 tag at the head
* of the file.
*
* \param filename The path to the FLAC file to read.
* \param filename The path to the FLAC or Ogg FLAC file to read.
* \param tags The address where the returned pointer will be
* stored. The \a tags object must be deleted by
* the caller using FLAC__metadata_object_delete().
Expand All @@ -182,10 +184,11 @@ FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__St
*/
FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);

/** Read the CUESHEET metadata block of the given FLAC file. This
* function will try to skip any ID3v2 tag at the head of the file.
/** Read the CUESHEET metadata block of the given FLAC or Ogg FLAC
* file. This function will try to skip any ID3v2 tag at the head
* of the file.
*
* \param filename The path to the FLAC file to read.
* \param filename The path to the FLAC or Ogg FLAC file to read.
* \param cuesheet The address where the returned pointer will be
* stored. The \a cuesheet object must be deleted by
* the caller using FLAC__metadata_object_delete().
Expand All @@ -207,7 +210,8 @@ FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__Stre
* function takes a number of parameters that act as constraints to
* the search. The PICTURE block with the largest area matching all
* the constraints will be returned, or \a *picture will be set to
* \c NULL if there was no such block.
* \c NULL if there was no such block. This function does not
* currently support reading from Ogg FLAC files.
*
* \param filename The path to the FLAC file to read.
* \param picture The address where the returned pointer will be
Expand Down
42 changes: 25 additions & 17 deletions src/test_libFLAC/metadata_manip.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ static FLAC__bool remove_file_(const char *filename)
return true;
}

static FLAC__bool test_level_0_(void)
static FLAC__bool test_level_0_(FLAC__bool is_ogg)
{
FLAC__StreamMetadata streaminfo;
FLAC__StreamMetadata *tags = 0;
Expand All @@ -702,15 +702,15 @@ static FLAC__bool test_level_0_(void)

printf("\n\n++++++ testing level 0 interface\n");

if(!generate_file_(/*include_extras=*/true, /*is_ogg=*/false))
if(!generate_file_(/*include_extras=*/true, is_ogg))
return false;

if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_null_))
if(!test_file_(is_ogg, decoder_metadata_callback_null_))
return false;

printf("testing FLAC__metadata_get_streaminfo()... ");

if(!FLAC__metadata_get_streaminfo(flacfilename(/*is_ogg=*/false), &streaminfo))
if(!FLAC__metadata_get_streaminfo(flacfilename(is_ogg), &streaminfo))
return die_("during FLAC__metadata_get_streaminfo()");

/* check to see if some basic data matches (c.f. generate_file_()) */
Expand All @@ -729,7 +729,7 @@ static FLAC__bool test_level_0_(void)

printf("testing FLAC__metadata_get_tags()... ");

if(!FLAC__metadata_get_tags(flacfilename(/*is_ogg=*/false), &tags))
if(!FLAC__metadata_get_tags(flacfilename(is_ogg), &tags))
return die_("during FLAC__metadata_get_tags()");

/* check to see if some basic data matches (c.f. generate_file_()) */
Expand All @@ -742,7 +742,7 @@ static FLAC__bool test_level_0_(void)

printf("testing FLAC__metadata_get_cuesheet()... ");

if(!FLAC__metadata_get_cuesheet(flacfilename(/*is_ogg=*/false), &cuesheet))
if(!FLAC__metadata_get_cuesheet(flacfilename(is_ogg), &cuesheet))
return die_("during FLAC__metadata_get_cuesheet()");

/* check to see if some basic data matches (c.f. generate_file_()) */
Expand All @@ -752,21 +752,23 @@ static FLAC__bool test_level_0_(void)
printf("OK\n");

FLAC__metadata_object_delete(cuesheet);
if(!is_ogg) {
/* FLAC__metadata_get_picture uses layer 1, which isn't ogg-capable yet */
printf("testing FLAC__metadata_get_picture()... ");

printf("testing FLAC__metadata_get_picture()... ");

if(!FLAC__metadata_get_picture(flacfilename(/*is_ogg=*/false), &picture, /*type=*/(FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(uint32_t)(-1), /*max_height=*/(uint32_t)(-1), /*max_depth=*/(uint32_t)(-1), /*max_colors=*/(uint32_t)(-1)))
return die_("during FLAC__metadata_get_picture()");
if(!FLAC__metadata_get_picture(flacfilename(is_ogg), &picture, /*type=*/(FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(uint32_t)(-1), /*max_height=*/(uint32_t)(-1), /*max_depth=*/(uint32_t)(-1), /*max_colors=*/(uint32_t)(-1)))
return die_("during FLAC__metadata_get_picture()");

/* check to see if some basic data matches (c.f. generate_file_()) */
if(picture->data.picture.type != FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER)
return die_("mismatch in picture->data.picture.type");
/* check to see if some basic data matches (c.f. generate_file_()) */
if(picture->data.picture.type != FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER)
return die_("mismatch in picture->data.picture.type");

printf("OK\n");
printf("OK\n");

FLAC__metadata_object_delete(picture);
FLAC__metadata_object_delete(picture);
}

if(!remove_file_(flacfilename(/*is_ogg=*/false)))
if(!remove_file_(flacfilename(is_ogg)))
return false;

return true;
Expand Down Expand Up @@ -2117,8 +2119,14 @@ FLAC__bool test_metadata_file_manipulation(void)

our_metadata_.num_blocks = 0;

if(!test_level_0_())

if(!test_level_0_(/*is_ogg=*/false))
return false;
if(FLAC_API_SUPPORTS_OGG_FLAC) {
if(!test_level_0_(/*is_ogg=*/true))
return false;
}


if(!test_level_1_())
return false;
Expand Down

0 comments on commit 8c244b8

Please sign in to comment.