summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-06-04 00:29:29 +0200
committerwm4 <wm4@nowhere>2013-06-04 00:29:44 +0200
commit92ae48db0f91fbfcfbb1722fa81c922808f62d5a (patch)
treee32fe21b5f8c11ada7788768a76e2d9f7d061c66 /demux
parentdaf8ed831b4ae63cf0931cc3d6727956137f865f (diff)
parentc1ac97b99b3e80bbf84ed540178dd6689ead0b87 (diff)
downloadmpv-92ae48db0f91fbfcfbb1722fa81c922808f62d5a.tar.bz2
mpv-92ae48db0f91fbfcfbb1722fa81c922808f62d5a.tar.xz
Merge branch 'sub_mess'
This branch heavily refactors the subtitle code (both loading and rendering), and adds support for a few new formats through FFmpeg. We don't remove any of the old code yet. There are still some subtleties related to subreader.c to be resolved: code page detection & conversion, timing post-processing, UTF-16 subtitle support, support for the -subfps option. Also, SRT reading and loading ASS via libass should be turned into proper demuxers. (SRT is needed because Libav's is gravely broken, and we want ASS loading via libass to cover full libass format support. Both should be demuxers which are probed _before_ libavformat, so that all subtitles can be loaded through the demuxer infrastructure, and libavformat subtitles don't need to be treated in a special way.)
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c37
-rw-r--r--demux/demux.h9
-rw-r--r--demux/demux_lavf.c7
-rw-r--r--demux/demux_mpg.c2
-rw-r--r--demux/demux_sub.c38
-rw-r--r--demux/stheader.h5
6 files changed, 75 insertions, 23 deletions
diff --git a/demux/demux.c b/demux/demux.c
index ed74540a7d..5de6b84745 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -66,6 +66,7 @@ extern const demuxer_desc_t demuxer_desc_mpeg_es;
extern const demuxer_desc_t demuxer_desc_mpeg4_es;
extern const demuxer_desc_t demuxer_desc_h264_es;
extern const demuxer_desc_t demuxer_desc_mpeg_ts;
+extern const demuxer_desc_t demuxer_desc_sub;
/* Please do not add any new demuxers here. If you want to implement a new
* demuxer, add it to libavformat, except for wrappers around external
@@ -95,6 +96,8 @@ const demuxer_desc_t *const demuxer_list[] = {
&demuxer_desc_mpeg_ts,
// auto-probe last, because it checks file-extensions only
&demuxer_desc_mf,
+ // no auto-probe
+ &demuxer_desc_sub,
/* Please do not add any new demuxers here. If you want to implement a new
* demuxer, add it to libavformat, except for wrappers around external
* libraries and demuxers requiring binary support. */
@@ -217,8 +220,8 @@ static const demuxer_desc_t *get_demuxer_desc_from_type(int file_format)
}
-demuxer_t *new_demuxer(struct MPOpts *opts, stream_t *stream, int type,
- int a_id, int v_id, int s_id, char *filename)
+static demuxer_t *new_demuxer(struct MPOpts *opts, stream_t *stream, int type,
+ int a_id, int v_id, int s_id, char *filename)
{
struct demuxer *d = talloc_zero(NULL, struct demuxer);
d->stream = stream;
@@ -248,6 +251,18 @@ demuxer_t *new_demuxer(struct MPOpts *opts, stream_t *stream, int type,
return d;
}
+// for demux_sub.c
+demuxer_t *new_sub_pseudo_demuxer(struct MPOpts *opts)
+{
+ struct stream *s = open_stream("null://", NULL, NULL);
+ assert(s);
+ struct demuxer *d = new_demuxer(opts, s, DEMUXER_TYPE_SUB,
+ -1, -1, -1, NULL);
+ new_sh_stream(d, STREAM_SUB);
+ talloc_steal(d, s);
+ return d;
+}
+
static struct sh_stream *new_sh_stream_id(demuxer_t *demuxer,
enum stream_type type,
int stream_index,
@@ -786,20 +801,20 @@ int ds_get_packet_pts(demux_stream_t *ds, unsigned char **start, double *pts)
return len;
}
-int ds_get_packet_sub(demux_stream_t *ds, unsigned char **start)
+struct demux_packet *ds_get_packet_sub(demux_stream_t *ds)
{
- int len;
if (ds->buffer_pos >= ds->buffer_size) {
- *start = NULL;
if (!ds->packs)
- return -1; // no sub
+ return NULL; // no sub
if (!ds_fill_buffer(ds))
- return -1; // EOF
+ return NULL; // EOF
}
- len = ds->buffer_size - ds->buffer_pos;
- *start = &ds->buffer[ds->buffer_pos];
- ds->buffer_pos += len;
- return len;
+ if (ds->buffer_pos < ds->buffer_size) {
+ ds->current->buffer += ds->buffer_pos;
+ ds->buffer_size -= ds->buffer_pos;
+ }
+ ds->buffer_pos = ds->buffer_size;
+ return ds->current;
}
struct demux_packet *ds_get_packet2(struct demux_stream *ds, bool repeat_last)
diff --git a/demux/demux.h b/demux/demux.h
index 886252fa85..9ec6d0c6f0 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -77,6 +77,7 @@ enum demuxer_type {
DEMUXER_TYPE_END,
DEMUXER_TYPE_PLAYLIST,
+ DEMUXER_TYPE_SUB,
};
enum timestamp_type {
@@ -304,9 +305,9 @@ static inline void *realloc_struct(void *ptr, size_t nmemb, size_t size)
return realloc(ptr, nmemb * size);
}
-struct demuxer *new_demuxer(struct MPOpts *opts, struct stream *stream,
- int type, int a_id, int v_id, int s_id,
- char *filename);
+demuxer_t *new_sub_pseudo_demuxer(struct MPOpts *opts);
+
+
void free_demuxer(struct demuxer *demuxer);
void demuxer_add_packet(demuxer_t *demuxer, struct sh_stream *stream,
@@ -343,7 +344,7 @@ void ds_free_packs(struct demux_stream *ds);
int ds_get_packet(struct demux_stream *ds, unsigned char **start);
int ds_get_packet_pts(struct demux_stream *ds, unsigned char **start,
double *pts);
-int ds_get_packet_sub(struct demux_stream *ds, unsigned char **start);
+struct demux_packet *ds_get_packet_sub(demux_stream_t *ds);
struct demux_packet *ds_get_packet2(struct demux_stream *ds, bool repeat_last);
double ds_get_next_pts(struct demux_stream *ds);
int ds_parse(struct demux_stream *sh, uint8_t **buffer, int *len, double pts,
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index a978bc9cee..a482f736c6 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -671,11 +671,8 @@ static int demux_lavf_fill_buffer(demuxer_t *demux, demux_stream_t *dsds)
if (ts != AV_NOPTS_VALUE) {
dp->pts = ts * av_q2d(st->time_base);
priv->last_pts = dp->pts * AV_TIME_BASE;
- // always set duration for subtitles, even if AV_PKT_FLAG_KEY isn't set,
- // otherwise they will stay on screen to long if e.g. ASS is demuxed
- // from mkv
- if ((stream->type == STREAM_SUB || (pkt->flags & AV_PKT_FLAG_KEY)) &&
- pkt->convergence_duration > 0)
+ dp->duration = pkt->duration * av_q2d(st->time_base);
+ if (pkt->convergence_duration > 0)
dp->duration = pkt->convergence_duration * av_q2d(st->time_base);
}
dp->pos = demux->filepos;
diff --git a/demux/demux_mpg.c b/demux/demux_mpg.c
index b30fb8e6e1..d47b3afd86 100644
--- a/demux/demux_mpg.c
+++ b/demux/demux_mpg.c
@@ -523,7 +523,7 @@ static int demux_mpg_read_packet(demuxer_t *demux,int id){
if(!demux->s_streams[aid]){
sh_sub_t *sh = new_sh_sub(demux, aid);
- if (sh) sh->gsh->codec = "dvd_subtitle";
+ if (sh) sh->gsh->codec = "dvd_subtitle_mpg";
mp_msg(MSGT_DEMUX,MSGL_V,"==> Found subtitle: %d\n",aid);
}
diff --git a/demux/demux_sub.c b/demux/demux_sub.c
new file mode 100644
index 0000000000..ab99091215
--- /dev/null
+++ b/demux/demux_sub.c
@@ -0,0 +1,38 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Note: not a real demuxer. The frontend has its own code to open subtitle
+// code, and then creates a new dummy demuxer with new_sub_demuxer().
+// But eventually, all subtitles should be opened this way, and this
+// file can be removed.
+
+#include "demux.h"
+
+static int dummy_fill_buffer(struct demuxer *demuxer, struct demux_stream *ds)
+{
+ return 0;
+}
+
+const struct demuxer_desc demuxer_desc_sub = {
+ .info = "External subtitles pseudo demuxer",
+ .name = "sub",
+ .shortdesc = "sub",
+ .author = "",
+ .comment = "",
+ .type = DEMUXER_TYPE_SUB,
+ .fill_buffer = dummy_fill_buffer,
+};
diff --git a/demux/stheader.h b/demux/stheader.h
index 433dc7ef71..421dfaf857 100644
--- a/demux/stheader.h
+++ b/demux/stheader.h
@@ -161,10 +161,11 @@ typedef struct sh_video {
typedef struct sh_sub {
SH_COMMON
- bool active; // after track switch decoder may stay initialized, not active
unsigned char *extradata; // extra header data passed from demuxer
int extradata_len;
- const struct sd_functions *sd_driver;
+ struct ass_track *track; // loaded by libass
+ struct sub_data *sub_data; // loaded by subreader.c
+ struct dec_sub *dec_sub; // decoder context
} sh_sub_t;
// demuxer.c: