mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-25 04:11:44 +00:00
100l: Cannot return a pointer to space that I frequently realloc (rmff_add_track). Changed rmff_file_t->tracks from rmff_track_t * to rmff_track_t **. Docs update. Added #defines for file and frame flags.
This commit is contained in:
parent
a4abb1de79
commit
938bdcce90
@ -120,6 +120,16 @@ extern "C" {
|
|||||||
|
|
||||||
#include "mb_file_io.h"
|
#include "mb_file_io.h"
|
||||||
|
|
||||||
|
/** \brief The stream may be saved to disc. Can be set in the
|
||||||
|
\link ::rmff_prop_t PROP header\endlink. */
|
||||||
|
#define RMFF_FILE_FLAG_SAVE_ENABLED 0x0001
|
||||||
|
/** \brief Allows the client to use extra buffering. Can be set in the
|
||||||
|
\link ::rmff_prop_t PROP header\endlink. */
|
||||||
|
#define RMFF_FILE_FLAG_PERFECT_PLAY 0x0002
|
||||||
|
/** \brief The stream is being generated by a live broadcast. Can be set in the
|
||||||
|
\link ::rmff_prop_t PROP header\endlink. */
|
||||||
|
#define RMFF_FILE_FLAG_LIVE_BROADCAST 0x0004
|
||||||
|
|
||||||
/** \brief The global PROP file header.
|
/** \brief The global PROP file header.
|
||||||
|
|
||||||
This header is mandatory for a RealMedia file. It contains statistical
|
This header is mandatory for a RealMedia file. It contains statistical
|
||||||
@ -273,6 +283,13 @@ typedef struct rmff_index_entry_t {
|
|||||||
uint32_t packet_number;
|
uint32_t packet_number;
|
||||||
} rmff_index_entry_t;
|
} rmff_index_entry_t;
|
||||||
|
|
||||||
|
/** \brief The packet is being delivered reliably. Can be set in the
|
||||||
|
::rmff_frame_t#flags member. */
|
||||||
|
#define RMFF_FRAME_FLAG_RELIABLE 0x01
|
||||||
|
/** \brief The frame is a key frame. Can be set in the ::rmff_frame_t#flags
|
||||||
|
member. */
|
||||||
|
#define RMFF_FRAME_FLAG_KEYFRAME 0x02
|
||||||
|
|
||||||
/** A frame or packet of media data.
|
/** A frame or packet of media data.
|
||||||
|
|
||||||
A new frame can be obtained with ::rmff_allocate_frame or read from a file
|
A new frame can be obtained with ::rmff_allocate_frame or read from a file
|
||||||
@ -341,7 +358,7 @@ typedef struct rmff_file_t {
|
|||||||
uint32_t num_packets_in_chunk;
|
uint32_t num_packets_in_chunk;
|
||||||
uint32_t num_packets_read;
|
uint32_t num_packets_read;
|
||||||
|
|
||||||
rmff_track_t *tracks;
|
rmff_track_t **tracks;
|
||||||
int num_tracks;
|
int num_tracks;
|
||||||
|
|
||||||
void *app_data;
|
void *app_data;
|
||||||
@ -502,6 +519,8 @@ rmff_track_t *rmff_add_track(rmff_file_t *file, int create_index);
|
|||||||
values, especially the \c uknown fields. Should be used after
|
values, especially the \c uknown fields. Should be used after
|
||||||
::rmff_add_track.
|
::rmff_add_track.
|
||||||
|
|
||||||
|
\note This function has not been implemented yet.
|
||||||
|
|
||||||
\param props A pointer to the structure whose values should be set.
|
\param props A pointer to the structure whose values should be set.
|
||||||
|
|
||||||
\see rmff_set_std_audio_v5_values(real_audio_v5_props_t*),
|
\see rmff_set_std_audio_v5_values(real_audio_v5_props_t*),
|
||||||
@ -515,6 +534,8 @@ void rmff_set_std_audio_v4_values(real_audio_v4_props_t *props);
|
|||||||
values, especially the \c uknown fields. Should be used after
|
values, especially the \c uknown fields. Should be used after
|
||||||
::rmff_add_track.
|
::rmff_add_track.
|
||||||
|
|
||||||
|
\note This function has not been implemented yet.
|
||||||
|
|
||||||
\param props A pointer to the structure whose values should be set.
|
\param props A pointer to the structure whose values should be set.
|
||||||
|
|
||||||
\see rmff_set_std_audio_v4_values(real_audio_v5_props_t*),
|
\see rmff_set_std_audio_v4_values(real_audio_v5_props_t*),
|
||||||
@ -528,6 +549,8 @@ void rmff_set_std_audio_v5_values(real_audio_v5_props_t *props);
|
|||||||
values, especially the \c uknown fields. Should be used after
|
values, especially the \c uknown fields. Should be used after
|
||||||
::rmff_add_track.
|
::rmff_add_track.
|
||||||
|
|
||||||
|
\note This function has not been implemented yet.
|
||||||
|
|
||||||
\param props A pointer to the structure whose values should be set.
|
\param props A pointer to the structure whose values should be set.
|
||||||
|
|
||||||
\see rmff_set_std_audio_v4_values(real_audio_v4_props_t*),
|
\see rmff_set_std_audio_v4_values(real_audio_v4_props_t*),
|
||||||
|
@ -363,7 +363,9 @@ open_file_for_writing(const char *path,
|
|||||||
file->internal = safecalloc(sizeof(rmff_file_internal_t));
|
file->internal = safecalloc(sizeof(rmff_file_internal_t));
|
||||||
|
|
||||||
/* save allowed & perfect play */
|
/* save allowed & perfect play */
|
||||||
rmff_put_uint16_be(&file->prop_header.flags, 1 | 2);
|
rmff_put_uint16_be(&file->prop_header.flags,
|
||||||
|
RMFF_FILE_FLAG_SAVE_ENABLED |
|
||||||
|
RMFF_FILE_FLAG_PERFECT_PLAY);
|
||||||
|
|
||||||
clear_error();
|
clear_error();
|
||||||
return file;
|
return file;
|
||||||
@ -407,8 +409,10 @@ rmff_close_file(rmff_file_t *file) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
safefree(file->name);
|
safefree(file->name);
|
||||||
for (i = 0; i < file->num_tracks; i++)
|
for (i = 0; i < file->num_tracks; i++) {
|
||||||
rmff_free_track_data(&file->tracks[i]);
|
rmff_free_track_data(file->tracks[i]);
|
||||||
|
safefree(file->tracks[i]);
|
||||||
|
}
|
||||||
safefree(file->tracks);
|
safefree(file->tracks);
|
||||||
safefree(file->cont_header.title);
|
safefree(file->cont_header.title);
|
||||||
safefree(file->cont_header.author);
|
safefree(file->cont_header.author);
|
||||||
@ -496,7 +500,7 @@ rmff_read_headers(rmff_file_t *file) {
|
|||||||
rmff_prop_t *prop;
|
rmff_prop_t *prop;
|
||||||
rmff_cont_t *cont;
|
rmff_cont_t *cont;
|
||||||
rmff_mdpr_t *mdpr;
|
rmff_mdpr_t *mdpr;
|
||||||
rmff_track_t track;
|
rmff_track_t *track;
|
||||||
real_video_props_t *rvp;
|
real_video_props_t *rvp;
|
||||||
real_audio_v4_props_t *ra4p;
|
real_audio_v4_props_t *ra4p;
|
||||||
rmff_file_internal_t *fint;
|
rmff_file_internal_t *fint;
|
||||||
@ -576,11 +580,11 @@ rmff_read_headers(rmff_file_t *file) {
|
|||||||
file->cont_header_present = 1;
|
file->cont_header_present = 1;
|
||||||
|
|
||||||
} else if (object_id == rmffFOURCC('M', 'D', 'P', 'R')) {
|
} else if (object_id == rmffFOURCC('M', 'D', 'P', 'R')) {
|
||||||
memset(&track, 0, sizeof(rmff_track_t));
|
track = (rmff_track_t *)safecalloc(sizeof(rmff_track_t));
|
||||||
track.file = (struct rmff_file_t *)file;
|
track->file = (struct rmff_file_t *)file;
|
||||||
mdpr = &track.mdpr_header;
|
mdpr = &track->mdpr_header;
|
||||||
read_uint16_be_to(&mdpr->id);
|
read_uint16_be_to(&mdpr->id);
|
||||||
track.id = rmff_get_uint16_be(&mdpr->id);
|
track->id = rmff_get_uint16_be(&mdpr->id);
|
||||||
read_uint32_be_to(&mdpr->max_bit_rate);
|
read_uint32_be_to(&mdpr->max_bit_rate);
|
||||||
read_uint32_be_to(&mdpr->avg_bit_rate);
|
read_uint32_be_to(&mdpr->avg_bit_rate);
|
||||||
read_uint32_be_to(&mdpr->max_packet_size);
|
read_uint32_be_to(&mdpr->max_packet_size);
|
||||||
@ -609,21 +613,21 @@ rmff_read_headers(rmff_file_t *file) {
|
|||||||
ra4p = (real_audio_v4_props_t *)mdpr->type_specific_data;
|
ra4p = (real_audio_v4_props_t *)mdpr->type_specific_data;
|
||||||
if ((size >= sizeof(real_video_props_t)) &&
|
if ((size >= sizeof(real_video_props_t)) &&
|
||||||
(get_fourcc(&rvp->fourcc1) == rmffFOURCC('V', 'I', 'D', 'O')))
|
(get_fourcc(&rvp->fourcc1) == rmffFOURCC('V', 'I', 'D', 'O')))
|
||||||
track.type = RMFF_TRACK_TYPE_VIDEO;
|
track->type = RMFF_TRACK_TYPE_VIDEO;
|
||||||
else if ((size >= sizeof(real_audio_v4_props_t)) &&
|
else if ((size >= sizeof(real_audio_v4_props_t)) &&
|
||||||
(get_fourcc(&ra4p->fourcc1) ==
|
(get_fourcc(&ra4p->fourcc1) ==
|
||||||
rmffFOURCC('.', 'r', 'a', 0xfd))) {
|
rmffFOURCC('.', 'r', 'a', 0xfd))) {
|
||||||
track.type = RMFF_TRACK_TYPE_AUDIO;
|
track->type = RMFF_TRACK_TYPE_AUDIO;
|
||||||
if ((rmff_get_uint16_be(&ra4p->version1) == 5) &&
|
if ((rmff_get_uint16_be(&ra4p->version1) == 5) &&
|
||||||
(size < sizeof(real_audio_v5_props_t)))
|
(size < sizeof(real_audio_v5_props_t)))
|
||||||
return set_error(RMFF_ERR_DATA, "RealAudio v5 data indicated but "
|
return set_error(RMFF_ERR_DATA, "RealAudio v5 data indicated but "
|
||||||
"data too small", RMFF_ERR_DATA);
|
"data too small", RMFF_ERR_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
track.internal = safecalloc(sizeof(rmff_track_internal_t));
|
track->internal = safecalloc(sizeof(rmff_track_internal_t));
|
||||||
file->tracks =
|
file->tracks =
|
||||||
(rmff_track_t *)saferealloc(file->tracks, (file->num_tracks + 1) *
|
(rmff_track_t **)saferealloc(file->tracks, (file->num_tracks + 1) *
|
||||||
sizeof(rmff_track_t));
|
sizeof(rmff_track_t *));
|
||||||
file->tracks[file->num_tracks] = track;
|
file->tracks[file->num_tracks] = track;
|
||||||
file->num_tracks++;
|
file->num_tracks++;
|
||||||
|
|
||||||
@ -799,7 +803,7 @@ rmff_set_track_data(rmff_track_t *track,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rmff_set_track_specific_data(rmff_track_t *track,
|
rmff_set_type_specific_data(rmff_track_t *track,
|
||||||
const unsigned char *data,
|
const unsigned char *data,
|
||||||
uint32_t size) {
|
uint32_t size) {
|
||||||
if (track == NULL)
|
if (track == NULL)
|
||||||
@ -815,7 +819,7 @@ rmff_set_track_specific_data(rmff_track_t *track,
|
|||||||
rmff_track_t *
|
rmff_track_t *
|
||||||
rmff_add_track(rmff_file_t *file,
|
rmff_add_track(rmff_file_t *file,
|
||||||
int create_index) {
|
int create_index) {
|
||||||
rmff_track_t track;
|
rmff_track_t *track;
|
||||||
rmff_track_internal_t *tint;
|
rmff_track_internal_t *tint;
|
||||||
int i, id, found;
|
int i, id, found;
|
||||||
|
|
||||||
@ -826,27 +830,27 @@ rmff_add_track(rmff_file_t *file,
|
|||||||
do {
|
do {
|
||||||
found = 0;
|
found = 0;
|
||||||
for (i = 0; i < file->num_tracks; i++)
|
for (i = 0; i < file->num_tracks; i++)
|
||||||
if (file->tracks[i].id == id) {
|
if (file->tracks[i]->id == id) {
|
||||||
found = 1;
|
found = 1;
|
||||||
id++;
|
id++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (found);
|
} while (found);
|
||||||
|
|
||||||
memset(&track, 0, sizeof(rmff_track_t));
|
track = (rmff_track_t *)safecalloc(sizeof(rmff_track_t));
|
||||||
track.id = id;
|
track->id = id;
|
||||||
track.file = file;
|
track->file = file;
|
||||||
tint = (rmff_track_internal_t *)safecalloc(sizeof(rmff_track_internal_t));
|
tint = (rmff_track_internal_t *)safecalloc(sizeof(rmff_track_internal_t));
|
||||||
tint->index_this = create_index;
|
tint->index_this = create_index;
|
||||||
track.internal = tint;
|
track->internal = tint;
|
||||||
|
|
||||||
file->tracks =
|
file->tracks =
|
||||||
(rmff_track_t *)saferealloc(file->tracks, (file->num_tracks + 1) *
|
(rmff_track_t **)saferealloc(file->tracks, (file->num_tracks + 1) *
|
||||||
sizeof(rmff_track_t));
|
sizeof(rmff_track_t *));
|
||||||
file->tracks[file->num_tracks] = track;
|
file->tracks[file->num_tracks] = track;
|
||||||
file->num_tracks++;
|
file->num_tracks++;
|
||||||
|
|
||||||
return &file->tracks[file->num_tracks - 1];
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1075,7 +1079,7 @@ rmff_write_headers(rmff_file_t *file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < file->num_tracks; i++) {
|
for (i = 0; i < file->num_tracks; i++) {
|
||||||
bw = write_mdpr_header(&file->tracks[i]);
|
bw = write_mdpr_header(file->tracks[i]);
|
||||||
if (bw < RMFF_ERR_OK)
|
if (bw < RMFF_ERR_OK)
|
||||||
return bw;
|
return bw;
|
||||||
}
|
}
|
||||||
@ -1119,7 +1123,7 @@ rmff_fix_headers(rmff_file_t *file) {
|
|||||||
rmff_put_uint16_be(&prop->num_streams, file->num_tracks);
|
rmff_put_uint16_be(&prop->num_streams, file->num_tracks);
|
||||||
|
|
||||||
for (i = 0; i < file->num_tracks; i++) {
|
for (i = 0; i < file->num_tracks; i++) {
|
||||||
track = &file->tracks[i];
|
track = file->tracks[i];
|
||||||
mdpr = &track->mdpr_header;
|
mdpr = &track->mdpr_header;
|
||||||
tint = (rmff_track_internal_t *)track->internal;
|
tint = (rmff_track_internal_t *)track->internal;
|
||||||
|
|
||||||
@ -1238,8 +1242,8 @@ rmff_find_track_with_id(rmff_file_t *file,
|
|||||||
if (file == 0)
|
if (file == 0)
|
||||||
return (rmff_track_t *)set_error(RMFF_ERR_PARAMETERS, NULL, 0);
|
return (rmff_track_t *)set_error(RMFF_ERR_PARAMETERS, NULL, 0);
|
||||||
for (i = 0; i < file->num_tracks; i++)
|
for (i = 0; i < file->num_tracks; i++)
|
||||||
if (file->tracks[i].id == id)
|
if (file->tracks[i]->id == id)
|
||||||
return &file->tracks[i];
|
return file->tracks[i];
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1262,7 +1266,7 @@ rmff_write_index(rmff_file_t *file) {
|
|||||||
|
|
||||||
fint->num_index_chunks = 0;
|
fint->num_index_chunks = 0;
|
||||||
for (i = 0; i < file->num_tracks; i++)
|
for (i = 0; i < file->num_tracks; i++)
|
||||||
if (file->tracks[i].num_index_entries > 0)
|
if (file->tracks[i]->num_index_entries > 0)
|
||||||
fint->num_index_chunks++;
|
fint->num_index_chunks++;
|
||||||
|
|
||||||
if (fint->num_index_chunks == 0)
|
if (fint->num_index_chunks == 0)
|
||||||
@ -1271,7 +1275,7 @@ rmff_write_index(rmff_file_t *file) {
|
|||||||
io->seek(fh, 0, SEEK_END);
|
io->seek(fh, 0, SEEK_END);
|
||||||
|
|
||||||
for (i = 0; i < file->num_tracks; i++) {
|
for (i = 0; i < file->num_tracks; i++) {
|
||||||
track = &file->tracks[i];
|
track = file->tracks[i];
|
||||||
tint = (rmff_track_internal_t *)track->internal;
|
tint = (rmff_track_internal_t *)track->internal;
|
||||||
if (track->num_index_entries > 0) {
|
if (track->num_index_entries > 0) {
|
||||||
pos = io->tell(fh);
|
pos = io->tell(fh);
|
||||||
|
Loading…
Reference in New Issue
Block a user