Paraslash Audio Streaming | |
About News Download Documentation Development |
Public API of the mp4 parser. More...
Data Structures | |
struct | mp4_callback |
Callbacks provided by the user of the mp4 parsing API. More... | |
struct | mp4_tag |
Specifies one metadata tag. More... | |
struct | mp4_metadata |
An array of name/value pairs. More... | |
Functions | |
int | mp4_set_sample_position (struct mp4 *f, uint32_t sample) |
Reposition the read/write file offset. More... | |
int | mp4_open (const struct mp4_callback *cb, struct mp4 **result) |
Read the audio track and the metadata of an mp4 file. More... | |
void | mp4_close (struct mp4 *f) |
Deallocate all resources associated with an mp4 file handle. More... | |
int | mp4_get_sample_size (const struct mp4 *f, uint32_t sample, uint32_t *result) |
Look up and return the size of the given sample in the stsz table. More... | |
uint16_t | mp4_get_sample_rate (const struct mp4 *f) |
Return the sample rate stored in the stsd atom. More... | |
uint16_t | mp4_get_channel_count (const struct mp4 *f) |
Return the number of channels of the audio track. More... | |
uint32_t | mp4_num_samples (const struct mp4 *f) |
Return the number of samples of the audio track. More... | |
uint64_t | mp4_get_duration (const struct mp4 *f) |
Compute the duration of an mp4 file. More... | |
int | mp4_open_meta (const struct mp4_callback *cb, struct mp4 **result) |
Open an mp4 file in metadata-only mode. More... | |
struct mp4_metadata * | mp4_get_meta (struct mp4 *f) |
Return the metadata of an mp4 file. More... | |
int | mp4_update_meta (struct mp4 *f) |
Write back the modified metadata items to the mp4 file. More... | |
__malloc char * | mp4_get_tag_value (const struct mp4 *f, const char *item) |
Return the value of the given tag item. More... | |
Public API of the mp4 parser.
int mp4_set_sample_position | ( | struct mp4 * | f, |
uint32_t | sample | ||
) |
Reposition the read/write file offset.
f | See mp4_close(). |
sample | The number of the sample to reposition to. |
The given sample number must be within range, i.e., strictly less than the value returned by mp4_num_samples().
References ERRNO_TO_PARA_ERROR.
int mp4_open | ( | const struct mp4_callback * | cb, |
struct mp4 ** | result | ||
) |
Read the audio track and the metadata of an mp4 file.
cb | Only the ->read() and ->seek() methods need to be supplied. |
result | Initialized to a non-NULL pointer iff the function succeeds. |
This detects and parses the first audio track and the metadata information of the mp4 file. Various error checks are performed after the mp4 atoms have been parsed successfully.
This function does not modify the file. However, if the caller intents to update the metadata later, the ->write() and ->truncate() methods must be supplied in the callback structure.
void mp4_close | ( | struct mp4 * | f | ) |
Deallocate all resources associated with an mp4 file handle.
f | File handle returned by mp4_open() or mp4_open_meta(). |
This frees the metadata items and various tables which were allocated when the file was opened. The given file handle must not be NULL.
int mp4_get_sample_size | ( | const struct mp4 * | f, |
uint32_t | sample, | ||
uint32_t * | result | ||
) |
Look up and return the size of the given sample in the stsz table.
f | See mp4_close(). |
sample | The sample number of interest. |
result | Sample size is returned here. |
For the sample argument the restriction mentioned in the documentation of mp4_set_sample_position() applies as well.
References ERRNO_TO_PARA_ERROR.
uint16_t mp4_get_sample_rate | ( | const struct mp4 * | f | ) |
Return the sample rate stored in the stsd atom.
f | See mp4_close(). |
The sample rate is a property of the audio track of the mp4 file and is thus independent of the sample number.
uint16_t mp4_get_channel_count | ( | const struct mp4 * | f | ) |
Return the number of channels of the audio track.
f | See mp4_close(). |
uint32_t mp4_num_samples | ( | const struct mp4 * | f | ) |
Return the number of samples of the audio track.
f | See mp4_close(). |
uint64_t mp4_get_duration | ( | const struct mp4 * | f | ) |
Compute the duration of an mp4 file.
f | See mp4_close(). |
int mp4_open_meta | ( | const struct mp4_callback * | cb, |
struct mp4 ** | result | ||
) |
Open an mp4 file in metadata-only mode.
cb | See mp4_open(). |
result | See mp4_open(). |
This is similar to mp4_open() but is cheaper because it only parses the metadata of the mp4 file. The only functions that can subsequently be called with the file handle returned here are mp4_get_meta() and mp4_update_meta().
struct mp4_metadata* mp4_get_meta | ( | struct mp4 * | f | ) |
Return the metadata of an mp4 file.
f | See mp4_close(). |
The caller is allowed to add, delete or modify the entries of the returned structure with the intention to pass the modified version to mp4_update_meta().
int mp4_update_meta | ( | struct mp4 * | f | ) |
Write back the modified metadata items to the mp4 file.
This is the only public function which modifies the contents of an mp4 file. This is achieved by calling the ->write() and ->truncate() methods of the callback structure passed to mp4_open() or mp4_open_meta().
f | See mp4_close(). |
The modified metadata structure does not need to be supplied to this function because it is part of the mp4 structure.
__malloc char* mp4_get_tag_value | ( | const struct mp4 * | f, |
const char * | item | ||
) |
Return the value of the given tag item.
f | See mp4_close(). |
item | "artist", "title", "album", "comment", or "date". |
References mp4_tag::item, and para_strdup().