mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-09-19 21:06:42 +00:00
avformat/samidec: UTF-16 support
ff_smil_extract_next_chunk() is still used by RealText.
This commit is contained in:
parent
d658ef18e3
commit
231a514dd3
@ -38,11 +38,12 @@ typedef struct {
|
|||||||
|
|
||||||
static int sami_probe(AVProbeData *p)
|
static int sami_probe(AVProbeData *p)
|
||||||
{
|
{
|
||||||
const unsigned char *ptr = p->buf;
|
char buf[6];
|
||||||
|
FFTextReader tr;
|
||||||
|
ff_text_init_buf(&tr, p->buf, p->buf_size);
|
||||||
|
ff_text_read(&tr, buf, sizeof(buf));
|
||||||
|
|
||||||
if (AV_RB24(ptr) == 0xEFBBBF)
|
return !strncmp(buf, "<SAMI>", 6) ? AVPROBE_SCORE_MAX : 0;
|
||||||
ptr += 3; /* skip UTF-8 BOM */
|
|
||||||
return !strncmp(ptr, "<SAMI>", 6) ? AVPROBE_SCORE_MAX : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sami_read_header(AVFormatContext *s)
|
static int sami_read_header(AVFormatContext *s)
|
||||||
@ -52,6 +53,8 @@ static int sami_read_header(AVFormatContext *s)
|
|||||||
AVBPrint buf, hdr_buf;
|
AVBPrint buf, hdr_buf;
|
||||||
char c = 0;
|
char c = 0;
|
||||||
int res = 0, got_first_sync_point = 0;
|
int res = 0, got_first_sync_point = 0;
|
||||||
|
FFTextReader tr;
|
||||||
|
ff_text_init_avio(&tr, s->pb);
|
||||||
|
|
||||||
if (!st)
|
if (!st)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
@ -62,10 +65,10 @@ static int sami_read_header(AVFormatContext *s)
|
|||||||
av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
|
av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
|
||||||
av_bprint_init(&hdr_buf, 0, AV_BPRINT_SIZE_UNLIMITED);
|
av_bprint_init(&hdr_buf, 0, AV_BPRINT_SIZE_UNLIMITED);
|
||||||
|
|
||||||
while (!avio_feof(s->pb)) {
|
while (!ff_text_eof(&tr)) {
|
||||||
AVPacket *sub;
|
AVPacket *sub;
|
||||||
const int64_t pos = avio_tell(s->pb) - (c != 0);
|
const int64_t pos = ff_text_pos(&tr) - (c != 0);
|
||||||
int is_sync, n = ff_smil_extract_next_chunk(s->pb, &buf, &c);
|
int is_sync, n = ff_smil_extract_next_text_chunk(&tr, &buf, &c);
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -274,20 +274,20 @@ void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q)
|
|||||||
q->nb_subs = q->allocated_size = q->current_sub_idx = 0;
|
q->nb_subs = q->allocated_size = q->current_sub_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c)
|
int ff_smil_extract_next_text_chunk(FFTextReader *tr, AVBPrint *buf, char *c)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char end_chr;
|
char end_chr;
|
||||||
|
|
||||||
if (!*c) // cached char?
|
if (!*c) // cached char?
|
||||||
*c = avio_r8(pb);
|
*c = ff_text_r8(tr);
|
||||||
if (!*c)
|
if (!*c)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
end_chr = *c == '<' ? '>' : '<';
|
end_chr = *c == '<' ? '>' : '<';
|
||||||
do {
|
do {
|
||||||
av_bprint_chars(buf, *c, 1);
|
av_bprint_chars(buf, *c, 1);
|
||||||
*c = avio_r8(pb);
|
*c = ff_text_r8(tr);
|
||||||
i++;
|
i++;
|
||||||
} while (*c != end_chr && *c);
|
} while (*c != end_chr && *c);
|
||||||
if (end_chr == '>') {
|
if (end_chr == '>') {
|
||||||
@ -297,6 +297,15 @@ int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c)
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c)
|
||||||
|
{
|
||||||
|
FFTextReader tr;
|
||||||
|
tr.buf_pos = tr.buf_len = 0;
|
||||||
|
tr.type = 0;
|
||||||
|
tr.pb = pb;
|
||||||
|
return ff_smil_extract_next_text_chunk(&tr, buf, c);
|
||||||
|
}
|
||||||
|
|
||||||
const char *ff_smil_get_attr_ptr(const char *s, const char *attr)
|
const char *ff_smil_get_attr_ptr(const char *s, const char *attr)
|
||||||
{
|
{
|
||||||
int in_quotes = 0;
|
int in_quotes = 0;
|
||||||
|
@ -146,6 +146,11 @@ void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q);
|
|||||||
*/
|
*/
|
||||||
int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c);
|
int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As ff_smil_extract_next_chunk(), but with FFTextReader.
|
||||||
|
*/
|
||||||
|
int ff_smil_extract_next_text_chunk(FFTextReader *tr, AVBPrint *buf, char *c);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMIL helper to point on the value of an attribute in the given tag.
|
* SMIL helper to point on the value of an attribute in the given tag.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user