Skip to content

Commit

Permalink
avformat/subtitles: Deduplicate subtitles' read_(packet|seek|close)
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Rheinhardt <[email protected]>
  • Loading branch information
mkver committed Jul 18, 2021
1 parent ef1302d commit ea5bdc8
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 360 deletions.
27 changes: 3 additions & 24 deletions libavformat/assdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ static int ass_probe(const AVProbeData *p)
return 0;
}

static int ass_read_close(AVFormatContext *s)
{
ASSContext *ass = s->priv_data;
ff_subtitles_queue_clean(&ass->q);
return 0;
}

static int read_dialogue(ASSContext *ass, AVBPrint *dst, const uint8_t *p,
int64_t *start, int *duration)
{
Expand Down Expand Up @@ -166,28 +159,14 @@ static int ass_read_header(AVFormatContext *s)
return res;
}

static int ass_read_packet(AVFormatContext *s, AVPacket *pkt)
{
ASSContext *ass = s->priv_data;
return ff_subtitles_queue_read_packet(&ass->q, pkt);
}

static int ass_read_seek(AVFormatContext *s, int stream_index,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
ASSContext *ass = s->priv_data;
return ff_subtitles_queue_seek(&ass->q, s, stream_index,
min_ts, ts, max_ts, flags);
}

const AVInputFormat ff_ass_demuxer = {
.name = "ass",
.long_name = NULL_IF_CONFIG_SMALL("SSA (SubStation Alpha) subtitle"),
.flags_internal = FF_FMT_INIT_CLEANUP,
.priv_data_size = sizeof(ASSContext),
.read_probe = ass_probe,
.read_header = ass_read_header,
.read_packet = ass_read_packet,
.read_close = ass_read_close,
.read_seek2 = ass_read_seek,
.read_packet = ff_subtitles_read_packet,
.read_close = ff_subtitles_read_close,
.read_seek2 = ff_subtitles_read_seek,
};
29 changes: 4 additions & 25 deletions libavformat/jacosubdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
#include "libavutil/intreadwrite.h"

typedef struct {
FFDemuxSubtitlesQueue q;
int shift;
unsigned timeres;
FFDemuxSubtitlesQueue q;
} JACOsubContext;

static int timed_line(const char *ptr)
Expand Down Expand Up @@ -93,13 +93,6 @@ static int get_jss_cmd(char k)
return -1;
}

static int jacosub_read_close(AVFormatContext *s)
{
JACOsubContext *jacosub = s->priv_data;
ff_subtitles_queue_clean(&jacosub->q);
return 0;
}

static const char *read_ts(JACOsubContext *jacosub, const char *buf,
int64_t *start, int64_t *duration)
{
Expand Down Expand Up @@ -258,28 +251,14 @@ static int jacosub_read_header(AVFormatContext *s)
return 0;
}

static int jacosub_read_packet(AVFormatContext *s, AVPacket *pkt)
{
JACOsubContext *jacosub = s->priv_data;
return ff_subtitles_queue_read_packet(&jacosub->q, pkt);
}

static int jacosub_read_seek(AVFormatContext *s, int stream_index,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
JACOsubContext *jacosub = s->priv_data;
return ff_subtitles_queue_seek(&jacosub->q, s, stream_index,
min_ts, ts, max_ts, flags);
}

const AVInputFormat ff_jacosub_demuxer = {
.name = "jacosub",
.long_name = NULL_IF_CONFIG_SMALL("JACOsub subtitle format"),
.priv_data_size = sizeof(JACOsubContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = jacosub_probe,
.read_header = jacosub_read_header,
.read_packet = jacosub_read_packet,
.read_seek2 = jacosub_read_seek,
.read_close = jacosub_read_close,
.read_packet = ff_subtitles_read_packet,
.read_seek2 = ff_subtitles_read_seek,
.read_close = ff_subtitles_read_close,
};
27 changes: 3 additions & 24 deletions libavformat/lrcdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,35 +218,14 @@ static int lrc_read_header(AVFormatContext *s)
return 0;
}

static int lrc_read_packet(AVFormatContext *s, AVPacket *pkt)
{
LRCContext *lrc = s->priv_data;
return ff_subtitles_queue_read_packet(&lrc->q, pkt);
}

static int lrc_read_seek(AVFormatContext *s, int stream_index,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
LRCContext *lrc = s->priv_data;
return ff_subtitles_queue_seek(&lrc->q, s, stream_index,
min_ts, ts, max_ts, flags);
}

static int lrc_read_close(AVFormatContext *s)
{
LRCContext *lrc = s->priv_data;
ff_subtitles_queue_clean(&lrc->q);
return 0;
}

const AVInputFormat ff_lrc_demuxer = {
.name = "lrc",
.long_name = NULL_IF_CONFIG_SMALL("LRC lyrics"),
.priv_data_size = sizeof (LRCContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = lrc_probe,
.read_header = lrc_read_header,
.read_packet = lrc_read_packet,
.read_close = lrc_read_close,
.read_seek2 = lrc_read_seek
.read_packet = ff_subtitles_read_packet,
.read_close = ff_subtitles_read_close,
.read_seek2 = ff_subtitles_read_seek
};
27 changes: 3 additions & 24 deletions libavformat/mccdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,36 +200,15 @@ static int mcc_read_header(AVFormatContext *s)
return ret;
}

static int mcc_read_packet(AVFormatContext *s, AVPacket *pkt)
{
MCCContext *mcc = s->priv_data;
return ff_subtitles_queue_read_packet(&mcc->q, pkt);
}

static int mcc_read_seek(AVFormatContext *s, int stream_index,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
MCCContext *mcc = s->priv_data;
return ff_subtitles_queue_seek(&mcc->q, s, stream_index,
min_ts, ts, max_ts, flags);
}

static int mcc_read_close(AVFormatContext *s)
{
MCCContext *mcc = s->priv_data;
ff_subtitles_queue_clean(&mcc->q);
return 0;
}

const AVInputFormat ff_mcc_demuxer = {
.name = "mcc",
.long_name = NULL_IF_CONFIG_SMALL("MacCaption"),
.priv_data_size = sizeof(MCCContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = mcc_probe,
.read_header = mcc_read_header,
.read_packet = mcc_read_packet,
.read_seek2 = mcc_read_seek,
.read_close = mcc_read_close,
.extensions = "mcc",
.read_packet = ff_subtitles_read_packet,
.read_seek2 = ff_subtitles_read_seek,
.read_close = ff_subtitles_read_close,
};
27 changes: 3 additions & 24 deletions libavformat/mpl2dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,36 +122,15 @@ static int mpl2_read_header(AVFormatContext *s)
return 0;
}

static int mpl2_read_packet(AVFormatContext *s, AVPacket *pkt)
{
MPL2Context *mpl2 = s->priv_data;
return ff_subtitles_queue_read_packet(&mpl2->q, pkt);
}

static int mpl2_read_seek(AVFormatContext *s, int stream_index,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
MPL2Context *mpl2 = s->priv_data;
return ff_subtitles_queue_seek(&mpl2->q, s, stream_index,
min_ts, ts, max_ts, flags);
}

static int mpl2_read_close(AVFormatContext *s)
{
MPL2Context *mpl2 = s->priv_data;
ff_subtitles_queue_clean(&mpl2->q);
return 0;
}

const AVInputFormat ff_mpl2_demuxer = {
.name = "mpl2",
.long_name = NULL_IF_CONFIG_SMALL("MPL2 subtitles"),
.priv_data_size = sizeof(MPL2Context),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = mpl2_probe,
.read_header = mpl2_read_header,
.read_packet = mpl2_read_packet,
.read_seek2 = mpl2_read_seek,
.read_close = mpl2_read_close,
.extensions = "txt,mpl2",
.read_packet = ff_subtitles_read_packet,
.read_seek2 = ff_subtitles_read_seek,
.read_close = ff_subtitles_read_close,
};
27 changes: 3 additions & 24 deletions libavformat/mpsubdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,36 +169,15 @@ static int mpsub_read_header(AVFormatContext *s)
return res;
}

static int mpsub_read_packet(AVFormatContext *s, AVPacket *pkt)
{
MPSubContext *mpsub = s->priv_data;
return ff_subtitles_queue_read_packet(&mpsub->q, pkt);
}

static int mpsub_read_seek(AVFormatContext *s, int stream_index,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
MPSubContext *mpsub = s->priv_data;
return ff_subtitles_queue_seek(&mpsub->q, s, stream_index,
min_ts, ts, max_ts, flags);
}

static int mpsub_read_close(AVFormatContext *s)
{
MPSubContext *mpsub = s->priv_data;
ff_subtitles_queue_clean(&mpsub->q);
return 0;
}

const AVInputFormat ff_mpsub_demuxer = {
.name = "mpsub",
.long_name = NULL_IF_CONFIG_SMALL("MPlayer subtitles"),
.priv_data_size = sizeof(MPSubContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = mpsub_probe,
.read_header = mpsub_read_header,
.read_packet = mpsub_read_packet,
.read_seek2 = mpsub_read_seek,
.read_close = mpsub_read_close,
.extensions = "sub",
.read_packet = ff_subtitles_read_packet,
.read_seek2 = ff_subtitles_read_seek,
.read_close = ff_subtitles_read_close,
};
27 changes: 3 additions & 24 deletions libavformat/pjsdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,15 @@ static int pjs_read_header(AVFormatContext *s)
return 0;
}

static int pjs_read_packet(AVFormatContext *s, AVPacket *pkt)
{
PJSContext *pjs = s->priv_data;
return ff_subtitles_queue_read_packet(&pjs->q, pkt);
}

static int pjs_read_seek(AVFormatContext *s, int stream_index,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
PJSContext *pjs = s->priv_data;
return ff_subtitles_queue_seek(&pjs->q, s, stream_index,
min_ts, ts, max_ts, flags);
}

static int pjs_read_close(AVFormatContext *s)
{
PJSContext *pjs = s->priv_data;
ff_subtitles_queue_clean(&pjs->q);
return 0;
}

const AVInputFormat ff_pjs_demuxer = {
.name = "pjs",
.long_name = NULL_IF_CONFIG_SMALL("PJS (Phoenix Japanimation Society) subtitles"),
.priv_data_size = sizeof(PJSContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = pjs_probe,
.read_header = pjs_read_header,
.read_packet = pjs_read_packet,
.read_seek2 = pjs_read_seek,
.read_close = pjs_read_close,
.extensions = "pjs",
.read_packet = ff_subtitles_read_packet,
.read_seek2 = ff_subtitles_read_seek,
.read_close = ff_subtitles_read_close,
};
27 changes: 3 additions & 24 deletions libavformat/realtextdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,36 +127,15 @@ static int realtext_read_header(AVFormatContext *s)
return res;
}

static int realtext_read_packet(AVFormatContext *s, AVPacket *pkt)
{
RealTextContext *rt = s->priv_data;
return ff_subtitles_queue_read_packet(&rt->q, pkt);
}

static int realtext_read_seek(AVFormatContext *s, int stream_index,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
RealTextContext *rt = s->priv_data;
return ff_subtitles_queue_seek(&rt->q, s, stream_index,
min_ts, ts, max_ts, flags);
}

static int realtext_read_close(AVFormatContext *s)
{
RealTextContext *rt = s->priv_data;
ff_subtitles_queue_clean(&rt->q);
return 0;
}

const AVInputFormat ff_realtext_demuxer = {
.name = "realtext",
.long_name = NULL_IF_CONFIG_SMALL("RealText subtitle format"),
.priv_data_size = sizeof(RealTextContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = realtext_probe,
.read_header = realtext_read_header,
.read_packet = realtext_read_packet,
.read_seek2 = realtext_read_seek,
.read_close = realtext_read_close,
.extensions = "rt",
.read_packet = ff_subtitles_read_packet,
.read_seek2 = ff_subtitles_read_seek,
.read_close = ff_subtitles_read_close,
};
27 changes: 3 additions & 24 deletions libavformat/samidec.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,36 +119,15 @@ static int sami_read_header(AVFormatContext *s)
return res;
}

static int sami_read_packet(AVFormatContext *s, AVPacket *pkt)
{
SAMIContext *sami = s->priv_data;
return ff_subtitles_queue_read_packet(&sami->q, pkt);
}

static int sami_read_seek(AVFormatContext *s, int stream_index,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
SAMIContext *sami = s->priv_data;
return ff_subtitles_queue_seek(&sami->q, s, stream_index,
min_ts, ts, max_ts, flags);
}

static int sami_read_close(AVFormatContext *s)
{
SAMIContext *sami = s->priv_data;
ff_subtitles_queue_clean(&sami->q);
return 0;
}

const AVInputFormat ff_sami_demuxer = {
.name = "sami",
.long_name = NULL_IF_CONFIG_SMALL("SAMI subtitle format"),
.priv_data_size = sizeof(SAMIContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = sami_probe,
.read_header = sami_read_header,
.read_packet = sami_read_packet,
.read_seek2 = sami_read_seek,
.read_close = sami_read_close,
.extensions = "smi,sami",
.read_packet = ff_subtitles_read_packet,
.read_seek2 = ff_subtitles_read_seek,
.read_close = ff_subtitles_read_close,
};
Loading

0 comments on commit ea5bdc8

Please sign in to comment.