1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-03 12:47:49 +00:00

Move all subtitle parsing from mkv demuxer to update_subtitles().

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@25683 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
eugeni 2008-01-11 21:45:17 +00:00
parent d9d27bb8c4
commit bdb6a07d2a
2 changed files with 25 additions and 30 deletions

View File

@ -2702,8 +2702,6 @@ handle_subtitles(demuxer_t *demuxer, mkv_track_t *track, char *block,
int64_t size, uint64_t block_duration, uint64_t timecode)
{
demux_packet_t *dp;
char *ptr1;
int i;
if (block_duration == 0)
{
@ -2712,28 +2710,9 @@ handle_subtitles(demuxer_t *demuxer, mkv_track_t *track, char *block,
return;
}
#ifdef USE_ASS
if (ass_enabled && track->subtitle_type == MATROSKA_SUBTYPE_SSA) {
ass_process_chunk(track->sh_sub->ass_track, block, size, (long long)timecode, (long long)block_duration);
return;
}
#endif
ptr1 = block;
if (track->subtitle_type == MATROSKA_SUBTYPE_SSA)
{
/* Find text section. */
for (i=0; i < 8 && *ptr1 != '\0'; ptr1++)
if (*ptr1 == ',')
i++;
if (*ptr1 == '\0') /* Broken line? */
return;
}
sub_utf8 = 1;
size -= ptr1 - block;
dp = new_demux_packet(size);
memcpy(dp->buffer, ptr1, size);
memcpy(dp->buffer, block, size);
dp->pts = timecode / 1000.0f;
dp->endpts = (timecode + block_duration) / 1000.0f;
ds_add_packet(demuxer->sub, dp);

View File

@ -28,11 +28,6 @@ void update_subtitles(sh_video_t *sh_video, demux_stream_t *d_dvdsub, int reset)
int len;
char type = d_dvdsub->sh ? ((sh_sub_t *)d_dvdsub->sh)->type : 'v';
static subtitle subs;
if (dvdsub_id >= 0 && type == 'a')
#ifdef USE_ASS
if (!ass_enabled)
#endif
type = 't';
if (reset) {
sub_clear_text(&subs, MP_NOPTS_VALUE);
if (vo_sub) {
@ -104,7 +99,7 @@ void update_subtitles(sh_video_t *sh_video, demux_stream_t *d_dvdsub, int reset)
if (spudec_changed(vo_spudec))
vo_osd_changed(OSDTYPE_SPU);
} else if (dvdsub_id >= 0 && type == 't') {
} else if (dvdsub_id >= 0 && (type == 't' || type == 'a')) {
double curpts = sh_video->pts + sub_delay;
double endpts;
vo_sub = &subs;
@ -115,7 +110,16 @@ void update_subtitles(sh_video_t *sh_video, demux_stream_t *d_dvdsub, int reset)
endpts = d_dvdsub->first->endpts;
len = ds_get_packet_sub(d_dvdsub, &packet);
#ifdef USE_ASS
if (ass_enabled) {
if (type == 'a' && ass_enabled) { // ssa/ass subs with libass
sh_sub_t* sh = d_dvdsub->sh;
ass_track = sh ? sh->ass_track : NULL;
if (ass_track)
ass_process_chunk(ass_track, packet, len,
(long long)(pts*1000 + 0.5),
(long long)((endpts-pts)*1000 + 0.5));
continue;
}
if (type == 't' && ass_enabled) { // plaintext subs with libass
static ass_track_t *global_ass_track = NULL;
if (!global_ass_track) global_ass_track = ass_default_track(ass_library);
ass_track = global_ass_track;
@ -128,11 +132,23 @@ void update_subtitles(sh_video_t *sh_video, demux_stream_t *d_dvdsub, int reset)
subs.end = endpts * 100;
ass_process_subtitle(ass_track, &subs);
}
} else
continue;
}
#endif
if (pts != MP_NOPTS_VALUE) {
if (endpts == MP_NOPTS_VALUE)
sub_clear_text(&subs, MP_NOPTS_VALUE);
if (type == 'a') { // ssa/ass subs without libass => convert to plaintext
int i;
unsigned char* p = packet;
for (i=0; i < 8 && *p != '\0'; p++)
if (*p == ',')
i++;
if (*p == '\0') /* Broken line? */
continue;
len -= p - packet;
packet = p;
}
sub_add_text(&subs, packet, len, endpts);
vo_osd_changed(OSDTYPE_SUBTITLE);
}