demux: get rid of some bstr things

Change the demuxer_add_attachment() and demuxer_add_chapter() signatures
to take char* instead of bstr, and everything which depends on it.
This commit is contained in:
wm4 2015-06-24 14:18:51 +02:00
parent ae2873f72e
commit fcd589b123
8 changed files with 36 additions and 38 deletions

View File

@ -90,17 +90,17 @@ static bool eat_char(struct bstr *data, char ch)
}
}
static struct bstr read_quoted(struct bstr *data)
static char *read_quoted(void *talloc_ctx, struct bstr *data)
{
*data = bstr_lstrip(*data);
if (!eat_char(data, '"'))
return (struct bstr) {0};
return NULL;
int end = bstrchr(*data, '"');
if (end < 0)
return (struct bstr) {0};
return NULL;
struct bstr res = bstr_splice(*data, 0, end);
*data = bstr_cut(*data, end + 1);
return res;
return bstrto0(talloc_ctx, res);
}
// Read a 2 digit unsigned decimal integer.
@ -163,7 +163,7 @@ struct cue_file *mp_parse_cue(struct bstr data)
data = skip_utf8_bom(data);
struct bstr filename = {0};
char *filename = NULL;
// Global metadata, and copied into new tracks.
struct cue_track proto_track = {0};
struct cue_track *cur_track = &proto_track;
@ -182,7 +182,7 @@ struct cue_file *mp_parse_cue(struct bstr data)
break;
}
case CUE_TITLE:
cur_track->title = read_quoted(&param);
cur_track->title = read_quoted(f, &param);
break;
case CUE_INDEX: {
int type = read_int_2(&param);
@ -197,7 +197,7 @@ struct cue_file *mp_parse_cue(struct bstr data)
}
case CUE_FILE:
// NOTE: FILE comes before TRACK, so don't use cur_track->filename
filename = read_quoted(&param);
filename = read_quoted(f, &param);
break;
}
}

View File

@ -30,9 +30,9 @@ struct cue_file {
struct cue_track {
double pregap_start; // corresponds to INDEX 00
double start; // corresponds to INDEX 01
struct bstr filename;
char *filename;
int source;
struct bstr title;
char *title;
};
bool mp_probe_cue(struct bstr data);

View File

@ -1217,21 +1217,19 @@ bool demux_stream_is_selected(struct sh_stream *stream)
return r;
}
int demuxer_add_attachment(demuxer_t *demuxer, struct bstr name,
struct bstr type, struct bstr data)
int demuxer_add_attachment(demuxer_t *demuxer, char *name, char *type,
void *data, size_t data_size)
{
if (!(demuxer->num_attachments % 32))
demuxer->attachments = talloc_realloc(demuxer, demuxer->attachments,
struct demux_attachment,
demuxer->num_attachments + 32);
struct demux_attachment *att =
demuxer->attachments + demuxer->num_attachments;
att->name = talloc_strndup(demuxer->attachments, name.start, name.len);
att->type = talloc_strndup(demuxer->attachments, type.start, type.len);
att->data = talloc_size(demuxer->attachments, data.len);
memcpy(att->data, data.start, data.len);
att->data_size = data.len;
struct demux_attachment *att = &demuxer->attachments[demuxer->num_attachments];
att->name = talloc_strdup(demuxer->attachments, name);
att->type = talloc_strdup(demuxer->attachments, type);
att->data = talloc_memdup(demuxer->attachments, data, data_size);
att->data_size = data_size;
return demuxer->num_attachments++;
}
@ -1254,17 +1252,17 @@ static void demuxer_sort_chapters(demuxer_t *demuxer)
sizeof(struct demux_chapter), chapter_compare);
}
int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
int demuxer_add_chapter(demuxer_t *demuxer, char *name,
double pts, uint64_t demuxer_id)
{
struct demux_chapter new = {
.original_index = demuxer->num_chapters,
.pts = pts,
.name = name.len ? bstrdup0(demuxer, name) : NULL,
.name = talloc_strdup(demuxer, name),
.metadata = talloc_zero(demuxer, struct mp_tags),
.demuxer_id = demuxer_id,
};
mp_tags_set_bstr(new.metadata, bstr0("TITLE"), name);
mp_tags_set_str(new.metadata, "TITLE", name);
MP_TARRAY_APPEND(demuxer, demuxer->chapters, demuxer->num_chapters, new);
return demuxer->num_chapters - 1;
}

View File

@ -284,9 +284,9 @@ void demux_set_stream_autoselect(struct demuxer *demuxer, bool autoselect);
void demuxer_help(struct mp_log *log);
int demuxer_add_attachment(struct demuxer *demuxer, struct bstr name,
struct bstr type, struct bstr data);
int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
int demuxer_add_attachment(struct demuxer *demuxer, char *name,
char *type, void *data, size_t data_size);
int demuxer_add_chapter(demuxer_t *demuxer, char *name,
double pts, uint64_t demuxer_id);
double demuxer_get_time_length(struct demuxer *demuxer);

View File

@ -80,14 +80,14 @@ static bool try_open(struct timeline *tl, char *filename)
return false;
}
static bool open_source(struct timeline *tl, struct bstr filename)
static bool open_source(struct timeline *tl, char *filename)
{
void *ctx = talloc_new(NULL);
bool res = false;
struct bstr dirname = mp_dirname(tl->demuxer->filename);
struct bstr base_filename = bstr0(mp_basename(bstrdup0(ctx, filename)));
struct bstr base_filename = bstr0(mp_basename(filename));
if (!base_filename.len) {
MP_WARN(tl, "CUE: Invalid audio filename in .cue file!\n");
} else {
@ -173,21 +173,21 @@ static void build_timeline(struct timeline *tl)
// CUE files usually use either separate files for every single track, or
// only one file for all tracks.
struct bstr *files = 0;
char **files = 0;
size_t file_count = 0;
for (size_t n = 0; n < track_count; n++) {
struct cue_track *track = &tracks[n];
track->source = -1;
for (size_t file = 0; file < file_count; file++) {
if (bstrcmp(files[file], track->filename) == 0) {
if (strcmp(files[file], track->filename) == 0) {
track->source = file;
break;
}
}
if (track->source == -1) {
file_count++;
files = talloc_realloc(ctx, files, struct bstr, file_count);
files = talloc_realloc(ctx, files, char *, file_count);
files[file_count - 1] = track->filename;
track->source = file_count - 1;
}
@ -229,7 +229,7 @@ static void build_timeline(struct timeline *tl)
chapters[i] = (struct demux_chapter) {
.pts = timeline[i].start,
// might want to include other metadata here
.name = bstrdup0(chapters, tracks[i].title),
.name = talloc_strdup(chapters, tracks[i].title),
};
starttime += duration;
}

View File

@ -282,7 +282,7 @@ static void add_stream_chapters(struct demuxer *demuxer)
double p = n;
if (stream_control(demuxer->stream, STREAM_CTRL_GET_CHAPTER_TIME, &p) < 1)
continue;
demuxer_add_chapter(demuxer, bstr0(""), p, 0);
demuxer_add_chapter(demuxer, "", p, 0);
}
}
@ -301,7 +301,7 @@ static int d_open(demuxer_t *demuxer, enum demux_check check)
char *t = NULL;
stream_control(demuxer->stream, STREAM_CTRL_GET_DISC_NAME, &t);
if (t) {
mp_tags_set_bstr(demuxer->metadata, bstr0("TITLE"), bstr0(t));
mp_tags_set_str(demuxer->metadata, "TITLE", t);
talloc_free(t);
}

View File

@ -618,9 +618,8 @@ static void handle_stream(demuxer_t *demuxer, int i)
AVDictionaryEntry *mt = av_dict_get(st->metadata, "mimetype", NULL, 0);
char *mimetype = mt ? mt->value : NULL;
if (mimetype) {
demuxer_add_attachment(demuxer, bstr0(filename), bstr0(mimetype),
(struct bstr){codec->extradata,
codec->extradata_size});
demuxer_add_attachment(demuxer, filename, mimetype,
codec->extradata, codec->extradata_size);
}
break;
}
@ -808,7 +807,7 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check)
for (i = 0; i < avfc->nb_chapters; i++) {
AVChapter *c = avfc->chapters[i];
t = av_dict_get(c->metadata, "title", NULL, 0);
int index = demuxer_add_chapter(demuxer, t ? bstr0(t->value) : bstr0(""),
int index = demuxer_add_chapter(demuxer, t ? t : "",
c->start * av_q2d(c->time_base), i);
mp_tags_copy_from_av_dictionary(demuxer->chapters[index].metadata, c->metadata);
}

View File

@ -894,7 +894,7 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer)
name);
if (idx == selected_edition) {
demuxer_add_chapter(demuxer, bstr0(name), chapter.start / 1e9,
demuxer_add_chapter(demuxer, name, chapter.start / 1e9,
ca->chapter_uid);
}
if (m_chapters) {
@ -996,7 +996,8 @@ static int demux_mkv_read_attachments(demuxer_t *demuxer)
}
char *name = attachment->file_name;
char *mime = attachment->file_mime_type;
demuxer_add_attachment(demuxer, bstr0(name), bstr0(mime), attachment->file_data);
demuxer_add_attachment(demuxer, name, mime, attachment->file_data.start,
attachment->file_data.len);
MP_VERBOSE(demuxer, "Attachment: %s, %s, %zu bytes\n",
name, mime, attachment->file_data.len);
}