aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Anton Khirnov <wyskas@gmail.com>2010-05-19 12:44:37 +0200
committerGravatar Uoti Urpala <uau@glyph.nonexistent.invalid>2010-05-22 06:40:28 +0300
commitbc072fb7dc314710aa8c822b400efa3072b8c6ad (patch)
tree3c6ca55fa7931d08f98f5ef518eb05178b0fe10a
parent9f508dab976b0e4cf43da8b9ef31de357ef76d2f (diff)
demux: use bstr arguments for demuxer_add_attachment() and demuxer_add_chapter()
-rw-r--r--libmpdemux/demux_lavf.c10
-rw-r--r--libmpdemux/demux_mkv.c12
-rw-r--r--libmpdemux/demuxer.c25
-rw-r--r--libmpdemux/demuxer.h7
4 files changed, 25 insertions, 29 deletions
diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c
index 2cdacff30c..2e8495c1c4 100644
--- a/libmpdemux/demux_lavf.c
+++ b/libmpdemux/demux_lavf.c
@@ -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++)
diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c
index 0a63df400e..9a5c5eceb2 100644
--- a/libmpdemux/demux_mkv.c
+++ b/libmpdemux/demux_mkv.c
@@ -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:
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c
index 93565e62d2..1930cf3488 100644
--- a/libmpdemux/demuxer.c
+++ b/libmpdemux/demuxer.c
@@ -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++;
}
diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h
index 7a702a3139..1a1f189b55 100644
--- a/libmpdemux/demuxer.h
+++ b/libmpdemux/demuxer.h
@@ -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);