Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
d9ac8d29
Commit
d9ac8d29
authored
12 years ago
by
Clément Bœsch
Browse files
Options
Downloads
Patches
Plain Diff
lavf: move srtdec:read_chunk() to subtitles utils.
This function can be useful for various other subtitles formats.
parent
67286fa9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
libavformat/srtdec.c
+1
-47
1 addition, 47 deletions
libavformat/srtdec.c
libavformat/subtitles.c
+46
-0
46 additions, 0 deletions
libavformat/subtitles.c
libavformat/subtitles.h
+15
-0
15 additions, 0 deletions
libavformat/subtitles.h
with
62 additions
and
47 deletions
libavformat/srtdec.c
+
1
−
47
View file @
d9ac8d29
...
...
@@ -71,52 +71,6 @@ static int64_t get_pts(const char **buf, int *duration,
return
AV_NOPTS_VALUE
;
}
static
inline
int
is_eol
(
char
c
)
{
return
c
==
'\r'
||
c
==
'\n'
;
}
static
void
read_chunk
(
AVIOContext
*
pb
,
AVBPrint
*
buf
)
{
char
eol_buf
[
5
];
int
n
=
0
,
i
=
0
,
nb_eol
=
0
;
av_bprint_clear
(
buf
);
for
(;;)
{
char
c
=
avio_r8
(
pb
);
if
(
!
c
)
break
;
/* ignore all initial line breaks */
if
(
n
==
0
&&
is_eol
(
c
))
continue
;
/* line break buffering: we don't want to add the trailing \r\n */
if
(
is_eol
(
c
))
{
nb_eol
+=
c
==
'\n'
;
if
(
nb_eol
==
2
)
break
;
eol_buf
[
i
++
]
=
c
;
if
(
i
==
sizeof
(
eol_buf
)
-
1
)
break
;
continue
;
}
/* only one line break followed by data: we flush the line breaks
* buffer */
if
(
i
)
{
eol_buf
[
i
]
=
0
;
av_bprintf
(
buf
,
"%s"
,
eol_buf
);
i
=
nb_eol
=
0
;
}
av_bprint_chars
(
buf
,
c
,
1
);
n
++
;
}
}
static
int
srt_read_header
(
AVFormatContext
*
s
)
{
SRTContext
*
srt
=
s
->
priv_data
;
...
...
@@ -133,7 +87,7 @@ static int srt_read_header(AVFormatContext *s)
av_bprint_init
(
&
buf
,
0
,
AV_BPRINT_SIZE_UNLIMITED
);
while
(
!
url_feof
(
s
->
pb
))
{
read_chunk
(
s
->
pb
,
&
buf
);
ff_subtitles_
read_chunk
(
s
->
pb
,
&
buf
);
if
(
buf
.
len
)
{
int64_t
pos
=
avio_tell
(
s
->
pb
);
...
...
This diff is collapsed.
Click to expand it.
libavformat/subtitles.c
+
46
−
0
View file @
d9ac8d29
...
...
@@ -192,3 +192,49 @@ const char *ff_smil_get_attr_ptr(const char *s, const char *attr)
}
return
NULL
;
}
static
inline
int
is_eol
(
char
c
)
{
return
c
==
'\r'
||
c
==
'\n'
;
}
void
ff_subtitles_read_chunk
(
AVIOContext
*
pb
,
AVBPrint
*
buf
)
{
char
eol_buf
[
5
];
int
n
=
0
,
i
=
0
,
nb_eol
=
0
;
av_bprint_clear
(
buf
);
for
(;;)
{
char
c
=
avio_r8
(
pb
);
if
(
!
c
)
break
;
/* ignore all initial line breaks */
if
(
n
==
0
&&
is_eol
(
c
))
continue
;
/* line break buffering: we don't want to add the trailing \r\n */
if
(
is_eol
(
c
))
{
nb_eol
+=
c
==
'\n'
;
if
(
nb_eol
==
2
)
break
;
eol_buf
[
i
++
]
=
c
;
if
(
i
==
sizeof
(
eol_buf
)
-
1
)
break
;
continue
;
}
/* only one line break followed by data: we flush the line breaks
* buffer */
if
(
i
)
{
eol_buf
[
i
]
=
0
;
av_bprintf
(
buf
,
"%s"
,
eol_buf
);
i
=
nb_eol
=
0
;
}
av_bprint_chars
(
buf
,
c
,
1
);
n
++
;
}
}
This diff is collapsed.
Click to expand it.
libavformat/subtitles.h
+
15
−
0
View file @
d9ac8d29
...
...
@@ -81,4 +81,19 @@ int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c);
*/
const
char
*
ff_smil_get_attr_ptr
(
const
char
*
s
,
const
char
*
attr
);
/**
* @brief Read a subtitles chunk.
*
* A chunk is defined by a multiline "event", ending with a second line break.
* The trailing line breaks are trimmed. CLRF are supported.
* Example: "foo\r\nbar\r\n\r\nnext" will print "foo\r\nbar" into buf, and pb
* will focus on the 'n' of the "next" string.
*
* @param pb I/O context
* @param buf an initialized buf where the chunk is written
*
* @note buf is cleared before writing into it.
*/
void
ff_subtitles_read_chunk
(
AVIOContext
*
pb
,
AVBPrint
*
buf
);
#endif
/* AVFORMAT_SUBTITLES_H */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment