Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
c20bdd8d
Commit
c20bdd8d
authored
Sep 10, 2015
by
Francois Cartegnie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
demux: subtitle: dont break non-seekable streams
parent
e35efa48
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
15 deletions
+67
-15
modules/demux/Makefile.am
modules/demux/Makefile.am
+3
-2
modules/demux/subtitle.c
modules/demux/subtitle.c
+17
-8
modules/demux/subtitle_helper.h
modules/demux/subtitle_helper.h
+44
-0
modules/demux/vobsub.c
modules/demux/vobsub.c
+3
-5
No files found.
modules/demux/Makefile.am
View file @
c20bdd8d
...
...
@@ -56,7 +56,7 @@ demux_LTLIBRARIES += libaiff_plugin.la
libmjpeg_plugin_la_SOURCES
=
demux/mjpeg.c demux/mxpeg_helper.h
demux_LTLIBRARIES
+=
libmjpeg_plugin.la
libsubtitle_plugin_la_SOURCES
=
demux/subtitle.c
libsubtitle_plugin_la_SOURCES
=
demux/subtitle.c
demux/subtitle_helper.h
libsubtitle_plugin_la_LIBADD
=
$(LIBM)
demux_LTLIBRARIES
+=
libsubtitle_plugin.la
...
...
@@ -64,7 +64,8 @@ libty_plugin_la_SOURCES = demux/ty.c codec/cc.h
demux_LTLIBRARIES
+=
libty_plugin.la
libvobsub_plugin_la_SOURCES
=
demux/vobsub.c demux/vobsub.h
\
demux/mpeg/ps.h demux/mpeg/pes.h
demux/mpeg/ps.h demux/mpeg/pes.h
\
demux/subtitle_helper.h
demux_LTLIBRARIES
+=
libvobsub_plugin.la
libvoc_plugin_la_SOURCES
=
demux/voc.c
...
...
modules/demux/subtitle.c
View file @
c20bdd8d
...
...
@@ -38,10 +38,13 @@
#include <ctype.h>
#include <math.h>
#include <assert.h>
#include <vlc_demux.h>
#include <vlc_charset.h>
#include "subtitle_helper.h"
/*****************************************************************************
* Module descriptor
*****************************************************************************/
...
...
@@ -299,6 +302,11 @@ static int Open ( vlc_object_t *p_this )
}
free
(
psz_type
);
#ifndef NDEBUG
const
uint64_t
i_start_pos
=
stream_Tell
(
p_demux
->
s
);
#endif
uint64_t
i_read_offset
=
0
;
/* Detect Unicode while skipping the UTF-8 Byte Order Mark */
bool
unicode
=
false
;
const
uint8_t
*
p_data
;
...
...
@@ -306,7 +314,7 @@ static int Open ( vlc_object_t *p_this )
&&
!
memcmp
(
p_data
,
"
\xEF\xBB\xBF
"
,
3
)
)
{
unicode
=
true
;
stream_Seek
(
p_demux
->
s
,
3
)
;
/* skip BOM */
i_read_offset
=
3
;
/* skip BOM */
msg_Dbg
(
p_demux
,
"detected Unicode Byte Order Mark"
);
}
...
...
@@ -322,7 +330,7 @@ static int Open ( vlc_object_t *p_this )
int
i_dummy
;
char
p_dummy
;
if
(
(
s
=
stream_ReadLine
(
p_demux
->
s
)
)
==
NULL
)
if
(
(
s
=
peek_Readline
(
p_demux
->
s
,
&
i_read_offset
)
)
==
NULL
)
break
;
if
(
strcasestr
(
s
,
"<SAMI>"
)
)
...
...
@@ -474,17 +482,15 @@ static int Open ( vlc_object_t *p_this )
}
free
(
s
);
/* It will nearly always work even for non seekable stream thanks the
* caching system, and if it fails we lose just a few sub */
if
(
stream_Seek
(
p_demux
->
s
,
unicode
?
3
:
0
)
)
msg_Warn
(
p_demux
,
"failed to rewind"
);
}
/* Quit on unknown subtitles */
if
(
p_sys
->
i_type
==
SUB_TYPE_UNKNOWN
)
{
stream_Seek
(
p_demux
->
s
,
0
);
#ifndef NDEBUG
/* Ensure it will work with non seekable streams */
assert
(
i_start_pos
==
stream_Tell
(
p_demux
->
s
)
);
#endif
msg_Warn
(
p_demux
,
"failed to recognize subtitle type"
);
free
(
p_sys
);
return
VLC_EGENERIC
;
...
...
@@ -503,6 +509,9 @@ static int Open ( vlc_object_t *p_this )
msg_Dbg
(
p_demux
,
"loading all subtitles..."
);
if
(
unicode
)
/* skip BOM */
stream_Seek
(
p_demux
->
s
,
3
);
/* Load the whole file */
TextLoad
(
&
p_sys
->
txt
,
p_demux
->
s
);
...
...
modules/demux/subtitle_helper.h
0 → 100644
View file @
c20bdd8d
/*****************************************************************************
* subtitle.h: subtitle helper functions
*****************************************************************************
* Copyright (C) 2015 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
inline
static
char
*
peek_Readline
(
stream_t
*
p_demuxstream
,
uint64_t
*
pi_offset
)
{
uint8_t
*
p_peek
;
ssize_t
i_peek
=
stream_Peek
(
p_demuxstream
,
(
const
uint8_t
**
)
&
p_peek
,
*
pi_offset
+
2048
);
if
(
i_peek
<=
0
)
return
NULL
;
const
uint64_t
i_bufsize
=
(
uint64_t
)
i_peek
-
*
pi_offset
;
char
*
psz_line
=
NULL
;
/* Create a stream memory from that offset */
stream_t
*
p_memorystream
=
stream_MemoryNew
(
p_demuxstream
,
&
p_peek
[
*
pi_offset
],
i_bufsize
,
true
);
if
(
p_memorystream
)
{
psz_line
=
stream_ReadLine
(
p_memorystream
);
*
pi_offset
+=
stream_Tell
(
p_memorystream
);
stream_Delete
(
p_memorystream
);
}
return
psz_line
;
}
modules/demux/vobsub.c
View file @
c20bdd8d
...
...
@@ -39,6 +39,7 @@
#include "mpeg/pes.h"
#include "mpeg/ps.h"
#include "vobsub.h"
#include "subtitle_helper.h"
/*****************************************************************************
* Module descriptor
...
...
@@ -122,17 +123,14 @@ static int Open ( vlc_object_t *p_this )
demux_sys_t
*
p_sys
;
char
*
psz_vobname
,
*
s
;
int
i_len
;
uint64_t
i_read_offset
=
0
;
if
(
(
s
=
stream_ReadLine
(
p_demux
->
s
)
)
!=
NULL
)
if
(
(
s
=
peek_Readline
(
p_demux
->
s
,
&
i_read_offset
)
)
!=
NULL
)
{
if
(
!
strcasestr
(
s
,
"# VobSub index file"
)
)
{
msg_Dbg
(
p_demux
,
"this doesn't seem to be a vobsub file"
);
free
(
s
);
if
(
stream_Seek
(
p_demux
->
s
,
0
)
)
{
msg_Warn
(
p_demux
,
"failed to rewind"
);
}
return
VLC_EGENERIC
;
}
free
(
s
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment