libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

flac_extractor.c File Reference

plugin to support FLAC files More...

#include "platform.h"
#include "extractor.h"
#include <FLAC/all.h>
Include dependency graph for flac_extractor.c:

Go to the source code of this file.

Data Structures

struct  Matches
 

Macros

#define FLAC_HEADER   "fLaC"
 
#define ADD(t, s)
 

Functions

static FLAC__StreamDecoderReadStatus flac_read (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
 
static FLAC__StreamDecoderSeekStatus flac_seek (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
 
static FLAC__StreamDecoderTellStatus flac_tell (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
 
static FLAC__StreamDecoderLengthStatus flac_length (const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
 
static FLAC__bool flac_eof (const FLAC__StreamDecoder *decoder, void *client_data)
 
static FLAC__StreamDecoderWriteStatus flac_write (const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 *const buffer[], void *client_data)
 
static char * xstrndup (const char *s, size_t n)
 
static void check (const char *type, unsigned int type_length, const char *value, unsigned int value_length, struct EXTRACTOR_ExtractContext *ec)
 
static void flac_metadata (const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
 
static void flac_error (const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
 
void EXTRACTOR_flac_extract_method (struct EXTRACTOR_ExtractContext *ec)
 

Variables

static struct Matches tmap []
 

Detailed Description

plugin to support FLAC files

Author
Christian Grothoff

Definition in file flac_extractor.c.

Macro Definition Documentation

◆ ADD

#define ADD (   t,
 
)
Value:
do { ec->proc (ec->cls, "flac", t, EXTRACTOR_METAFORMAT_UTF8, \
"text/plain", s, strlen (s) + 1); } while (0)
@ EXTRACTOR_METAFORMAT_UTF8
Definition: extractor.h:102

Give meta data to extractor.

Parameters
ttype of the meta data
smeta data value in utf8 format

Definition at line 233 of file flac_extractor.c.

◆ FLAC_HEADER

#define FLAC_HEADER   "fLaC"

Bytes each FLAC file must begin with (not used, but we might choose to add this back in the future to improve performance for non-ogg files).

Definition at line 36 of file flac_extractor.c.

Function Documentation

◆ check()

static void check ( const char *  type,
unsigned int  type_length,
const char *  value,
unsigned int  value_length,
struct EXTRACTOR_ExtractContext ec 
)
static

Check if a mapping exists for the given meta data value and if so give the result to LE.

Parameters
typetype of the meta data according to FLAC
type_lengthnumber of bytes in 'type'
valuemeta data as UTF8 string (non 0-terminated)
value_lengthnumber of bytes in value
ecextractor context

Definition at line 269 of file flac_extractor.c.

References ADD, NULL, Matches::text, tmap, type, and xstrndup().

Referenced by flac_metadata().

◆ EXTRACTOR_flac_extract_method()

void EXTRACTOR_flac_extract_method ( struct EXTRACTOR_ExtractContext ec)

Main entry method for the 'audio/flac' extraction plugin.

Parameters
ecextraction context provided to the plugin

Definition at line 441 of file flac_extractor.c.

References flac_eof(), flac_error(), flac_length(), flac_metadata(), flac_read(), flac_seek(), flac_tell(), flac_write(), and NULL.

◆ flac_eof()

static FLAC__bool flac_eof ( const FLAC__StreamDecoder *  decoder,
void *  client_data 
)
static

Tell FLAC if we are at the end of the file.

Parameters
decoderunused
absolute_byte_offsetlocation to store the current offset
client_datathe 'struct EXTRACTOR_ExtractContext'
Returns
true at EOF, false if not

Definition at line 149 of file flac_extractor.c.

References EXTRACTOR_ExtractContext::cls, EXTRACTOR_ExtractContext::get_size, and EXTRACTOR_ExtractContext::seek.

Referenced by EXTRACTOR_flac_extract_method().

◆ flac_error()

static void flac_error ( const FLAC__StreamDecoder *  decoder,
FLAC__StreamDecoderErrorStatus  status,
void *  client_data 
)
static

Function called whenever FLAC decoder has trouble. Does nothing.

Parameters
decoderthe decoder handle
statustype of the error
client_dataour 'struct EXTRACTOR_ExtractContext'

Definition at line 427 of file flac_extractor.c.

Referenced by EXTRACTOR_flac_extract_method().

◆ flac_length()

static FLAC__StreamDecoderLengthStatus flac_length ( const FLAC__StreamDecoder *  decoder,
FLAC__uint64 *  stream_length,
void *  client_data 
)
static

Tell FLAC the size of the file.

Parameters
decoderunused
stream_lengthwhere to store the file size
client_datathe 'struct EXTRACTOR_ExtractContext'
Returns
true at EOF, false if not

Definition at line 129 of file flac_extractor.c.

References EXTRACTOR_ExtractContext::cls, and EXTRACTOR_ExtractContext::get_size.

Referenced by EXTRACTOR_flac_extract_method().

◆ flac_metadata()

static void flac_metadata ( const FLAC__StreamDecoder *  decoder,
const FLAC__StreamMetadata *  metadata,
void *  client_data 
)
static

◆ flac_read()

static FLAC__StreamDecoderReadStatus flac_read ( const FLAC__StreamDecoder *  decoder,
FLAC__byte  buffer[],
size_t *  bytes,
void *  client_data 
)
static

Custom read function for flac.

Parameters
decoderunused
bufferwhere to write the data
byteshow many bytes to read, set to how many bytes were read
client_dataour 'struct EXTRACTOR_ExtractContxt*'
Returns
status code (error, end-of-file or success)

Definition at line 49 of file flac_extractor.c.

References buffer, EXTRACTOR_ExtractContext::cls, NULL, and EXTRACTOR_ExtractContext::read.

Referenced by EXTRACTOR_flac_extract_method().

◆ flac_seek()

static FLAC__StreamDecoderSeekStatus flac_seek ( const FLAC__StreamDecoder *  decoder,
FLAC__uint64  absolute_byte_offset,
void *  client_data 
)
static

Seek to a particular position in the file.

Parameters
decoderunused
absolute_byte_offsetwhere to seek
client_datathe 'struct EXTRACTOR_ExtractContext'
Returns
status code (error or success)

Definition at line 85 of file flac_extractor.c.

References EXTRACTOR_ExtractContext::cls, and EXTRACTOR_ExtractContext::seek.

Referenced by EXTRACTOR_flac_extract_method().

◆ flac_tell()

static FLAC__StreamDecoderTellStatus flac_tell ( const FLAC__StreamDecoder *  decoder,
FLAC__uint64 *  absolute_byte_offset,
void *  client_data 
)
static

Tell FLAC about our current position in the file.

Parameters
decoderunused
absolute_byte_offsetlocation to store the current offset
client_datathe 'struct EXTRACTOR_ExtractContext'
Returns
status code (error or success)

Definition at line 107 of file flac_extractor.c.

References EXTRACTOR_ExtractContext::cls, and EXTRACTOR_ExtractContext::seek.

Referenced by EXTRACTOR_flac_extract_method().

◆ flac_write()

static FLAC__StreamDecoderWriteStatus flac_write ( const FLAC__StreamDecoder *  decoder,
const FLAC__Frame *  frame,
const FLAC__int32 *const  buffer[],
void *  client_data 
)
static

FLAC wants to write. Always succeeds but does nothing.

Parameters
decoderunused
frameunused
bufferunused
client_datathe 'struct EXTRACTOR_ExtractContext'
Returns
always claims success

Definition at line 177 of file flac_extractor.c.

Referenced by EXTRACTOR_flac_extract_method().

◆ xstrndup()

static char* xstrndup ( const char *  s,
size_t  n 
)
static

Create 0-terminated version of n-character string.

Parameters
sinput string (non 0-terminated)
nnumber of bytes in 's'
Returns
NULL on error, otherwise 0-terminated version of 's'

Definition at line 245 of file flac_extractor.c.

References NULL.

Referenced by check().

Variable Documentation

◆ tmap

struct Matches tmap[]
static
Initial value:
= {
{NULL, 0}
}
#define NULL
Definition: getopt1.c:60
@ EXTRACTOR_METATYPE_SONG_VERSION
Definition: extractor.h:285
@ EXTRACTOR_METATYPE_GENRE
Definition: extractor.h:280
@ EXTRACTOR_METATYPE_TRACK_NUMBER
Definition: extractor.h:281
@ EXTRACTOR_METATYPE_TITLE
Definition: extractor.h:134
@ EXTRACTOR_METATYPE_ARTIST
Definition: extractor.h:279
@ EXTRACTOR_METATYPE_PERFORMER
Definition: extractor.h:283
@ EXTRACTOR_METATYPE_ISRC
Definition: extractor.h:163
@ EXTRACTOR_METATYPE_CREATION_DATE
Definition: extractor.h:196
@ EXTRACTOR_METATYPE_LICENSE
Definition: extractor.h:226
@ EXTRACTOR_METATYPE_COPYRIGHT
Definition: extractor.h:183
@ EXTRACTOR_METATYPE_ORGANIZATION
Definition: extractor.h:327
@ EXTRACTOR_METATYPE_ALBUM
Definition: extractor.h:278
@ EXTRACTOR_METATYPE_LOCATION_SUBLOCATION
Definition: extractor.h:176
@ EXTRACTOR_METATYPE_CONTACT_INFORMATION
Definition: extractor.h:284
@ EXTRACTOR_METATYPE_DESCRIPTION
Definition: extractor.h:182

Mapping of FLAC meta data description texts to LE types. NULL-terminated.

Definition at line 177 of file flac_extractor.c.

Referenced by check().