Paraslash Audio Streaming | |
About News Download Documentation Development |
Paraslash's internal mp4 parser. More...
#include <regex.h>
#include "para.h"
#include "error.h"
#include "portable_io.h"
#include "string.h"
#include "mp4.h"
Macros | |
#define | ATOM_ITEM(_name, a, b, c, d) ATOM_ ## _name, |
atom_items More... | |
#define | ATOM_VALUE(a, b, c, d) ((a << 24) + (b << 16) + (c << 8) + d) |
A cpp version of read_u32_be(). More... | |
#define | ATOM_ITEM(_name, a, b, c, d) {.name = # _name, .val = ATOM_VALUE(a, b, c, d)}, |
atom_items More... | |
#define | TAG_LEN(_len) (24 + (_len)) |
Total length of an on-disk metadata tag. More... | |
Enumerations | |
enum | audio_track_state { ATS_INITIAL, ATS_SEEN_MP4A, ATS_TRACK_CHANGE } |
The three states of the mp4 parser. More... | |
enum | atom { ATOM_ITEMS } |
The enumeration of interesting atoms. More... | |
Functions | |
void | mp4_close (struct mp4 *f) |
Deallocate all resources associated with an mp4 file handle. More... | |
int | mp4_open (const struct mp4_callback *cb, struct mp4 **result) |
Read the audio track and the metadata of an mp4 file. More... | |
uint64_t | mp4_get_duration (const struct mp4 *f) |
Compute the duration of an mp4 file. More... | |
int | mp4_set_sample_position (struct mp4 *f, uint32_t sample) |
Reposition the read/write file offset. 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... | |
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... | |
Paraslash's internal mp4 parser.
#define ATOM_ITEM | ( | _name, | |
a, | |||
b, | |||
c, | |||
d | |||
) | ATOM_ ## _name, |
atom_items
For the C enumeration we concatenate ATOM_ with the first argument.
#define ATOM_VALUE | ( | a, | |
b, | |||
c, | |||
d | |||
) | ((a << 24) + (b << 16) + (c << 8) + d) |
A cpp version of read_u32_be().
#define ATOM_ITEM | ( | _name, | |
a, | |||
b, | |||
c, | |||
d | |||
) | {.name = # _name, .val = ATOM_VALUE(a, b, c, d)}, |
atom_items
For the C enumeration we concatenate ATOM_ with the first argument.
#define TAG_LEN | ( | _len | ) | (24 + (_len)) |
Total length of an on-disk metadata tag.
enum audio_track_state |
The three states of the mp4 parser.
The parser only loads the audio specific values and tables when it is in the second state.
Enumerator | |
---|---|
ATS_INITIAL | We haven't encountered an mp4a atom so far. |
ATS_SEEN_MP4A | We have seen an mp4a atom but no subsequent trak atom yet. |
ATS_TRACK_CHANGE | A trak atom was seen after the mp4a atom. |
enum atom |
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_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.
uint64_t mp4_get_duration | ( | const struct mp4 * | f | ) |
Compute the duration of an mp4 file.
f | See mp4_close(). |
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_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(). |
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().