1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 17:12:36 +00:00

demux: use bstr arguments for demuxer_add_attachment() and demuxer_add_chapter()

This commit is contained in:
Anton Khirnov 2010-05-19 12:44:37 +02:00 committed by Uoti Urpala
parent 9f508dab97
commit bc072fb7dc
4 changed files with 25 additions and 29 deletions

View File

@ -28,6 +28,7 @@
#include "options.h"
#include "mp_msg.h"
#include "av_opts.h"
#include "bstr.h"
#include "stream/stream.h"
#include "aviprint.h"
@ -449,9 +450,10 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) {
}
case CODEC_TYPE_ATTACHMENT:{
if (st->codec->codec_id == CODEC_ID_TTF)
demuxer_add_attachment(demuxer, st->filename, INT_MAX,
"application/x-truetype-font", INT_MAX,
codec->extradata, codec->extradata_size);
demuxer_add_attachment(demuxer, BSTR(st->filename),
BSTR("application/x-truetype-font"),
(struct bstr){codec->extradata,
codec->extradata_size});
break;
}
default:
@ -547,7 +549,7 @@ static demuxer_t* demux_open_lavf(demuxer_t *demuxer){
uint64_t start = av_rescale_q(c->start, c->time_base, (AVRational){1,1000});
uint64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,1000});
t = av_metadata_get(c->metadata, "title", NULL, 0);
demuxer_add_chapter(demuxer, t ? t->value : NULL, INT_MAX, start, end);
demuxer_add_chapter(demuxer, t ? BSTR(t->value) : BSTR(NULL), start, end);
}
for(i=0; i<avfc->nb_streams; i++)

View File

@ -865,8 +865,7 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer)
BSTR_P(name));
if (idx == selected_edition){
demuxer_add_chapter(demuxer, name.start, name.len,
chapter.start, chapter.end);
demuxer_add_chapter(demuxer, name, chapter.start, chapter.end);
if (editions[idx].edition_flag_ordered) {
chapter.name = talloc_strndup(m_chapters, name.start,
name.len);
@ -915,12 +914,9 @@ static int demux_mkv_read_attachments(demuxer_t *demuxer)
}
struct bstr name = attachment->file_name;
struct bstr mime = attachment->file_mime_type;
char *data = attachment->file_data.start;
int data_size = attachment->file_data.len;
demuxer_add_attachment(demuxer, name.start, name.len, mime.start,
mime.len, data, data_size);
mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Attachment: %.*s, %.*s, %u bytes\n",
BSTR_P(name), BSTR_P(mime), data_size);
demuxer_add_attachment(demuxer, name, mime, attachment->file_data);
mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Attachment: %.*s, %.*s, %zu bytes\n",
BSTR_P(name), BSTR_P(mime), attachment->file_data.len);
}
out:

View File

@ -1429,9 +1429,8 @@ int demuxer_switch_video(demuxer_t *demuxer, int index)
return index;
}
int demuxer_add_attachment(demuxer_t *demuxer, const char *name,
int name_maxlen, const char *type, int type_maxlen,
const void *data, size_t size)
int demuxer_add_attachment(demuxer_t *demuxer, struct bstr name,
struct bstr type, struct bstr data)
{
if (!(demuxer->num_attachments % 32))
demuxer->attachments = talloc_realloc(demuxer, demuxer->attachments,
@ -1440,16 +1439,16 @@ int demuxer_add_attachment(demuxer_t *demuxer, const char *name,
struct demux_attachment *att =
demuxer->attachments + demuxer->num_attachments;
att->name = talloc_strndup(demuxer->attachments, name, name_maxlen);
att->type = talloc_strndup(demuxer->attachments, type, type_maxlen);
att->data = talloc_size(demuxer->attachments, size);
memcpy(att->data, data, size);
att->data_size = size;
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;
return demuxer->num_attachments++;
}
int demuxer_add_chapter(demuxer_t *demuxer, const char *name, int name_maxlen,
int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
uint64_t start, uint64_t end)
{
if (!(demuxer->num_chapters % 32))
@ -1459,16 +1458,16 @@ int demuxer_add_chapter(demuxer_t *demuxer, const char *name, int name_maxlen,
demuxer->chapters[demuxer->num_chapters].start = start;
demuxer->chapters[demuxer->num_chapters].end = end;
demuxer->chapters[demuxer->num_chapters].name = name ?
talloc_strndup(demuxer->chapters, name, name_maxlen) :
demuxer->chapters[demuxer->num_chapters].name = name.len ?
talloc_strndup(demuxer->chapters, name.start, name.len) :
talloc_strdup(demuxer->chapters, mp_gtext("unknown"));
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTER_ID=%d\n", demuxer->num_chapters);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTER_%d_START=%"PRIu64"\n", demuxer->num_chapters, start);
if (end)
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTER_%d_END=%"PRIu64"\n", demuxer->num_chapters, end);
if (name)
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTER_%d_NAME=%.*s\n", demuxer->num_chapters, name_maxlen, name);
if (name.start)
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTER_%d_NAME=%.*s\n", demuxer->num_chapters, BSTR_P(name));
return demuxer->num_chapters++;
}

View File

@ -445,10 +445,9 @@ int demuxer_type_by_filename(char* filename);
void demuxer_help(void);
int get_demuxer_type_from_name(char *demuxer_name, int *force);
int demuxer_add_attachment(demuxer_t *demuxer, const char *name,
int name_maxlen, const char *type, int type_maxlen,
const void *data, size_t size);
int demuxer_add_chapter(demuxer_t *demuxer, const char *name, int name_maxlen,
int demuxer_add_attachment(demuxer_t *demuxer, struct bstr name,
struct bstr type, struct bstr data);
int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
uint64_t start, uint64_t end);
int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, double *seek_pts,
char **chapter_name);