fftools/ffmpeg_dec: move InputStream.prev_sub to Decoder

It does not need to be visible outside of decoding code.
This commit is contained in:
Anton Khirnov 2023-06-14 16:16:50 +02:00
parent a45b9d35b9
commit e89a6d1089
3 changed files with 18 additions and 13 deletions

View File

@ -359,10 +359,6 @@ typedef struct InputStream {
int autorotate; int autorotate;
int fix_sub_duration; int fix_sub_duration;
struct { /* previous decoded subtitle and related variables */
int got_output;
AVSubtitle subtitle;
} prev_sub;
struct sub2video { struct sub2video {
int w, h; int w, h;

View File

@ -47,6 +47,12 @@ struct Decoder {
int64_t last_filter_in_rescale_delta; int64_t last_filter_in_rescale_delta;
int last_frame_sample_rate; int last_frame_sample_rate;
/* previous decoded subtitle and related variables */
struct {
int got_output;
AVSubtitle subtitle;
} prev_sub;
pthread_t thread; pthread_t thread;
/** /**
* Queue for sending coded packets from the main thread to * Queue for sending coded packets from the main thread to
@ -102,6 +108,8 @@ void dec_free(Decoder **pdec)
av_frame_free(&dec->frame); av_frame_free(&dec->frame);
av_packet_free(&dec->pkt); av_packet_free(&dec->pkt);
avsubtitle_free(&dec->prev_sub.subtitle);
av_freep(pdec); av_freep(pdec);
} }
@ -378,24 +386,25 @@ static void sub2video_flush(InputStream *ist)
static int process_subtitle(InputStream *ist, AVSubtitle *subtitle) static int process_subtitle(InputStream *ist, AVSubtitle *subtitle)
{ {
Decoder *d = ist->decoder;
int got_output = 1; int got_output = 1;
int ret = 0; int ret = 0;
if (ist->fix_sub_duration) { if (ist->fix_sub_duration) {
int end = 1; int end = 1;
if (ist->prev_sub.got_output) { if (d->prev_sub.got_output) {
end = av_rescale(subtitle->pts - ist->prev_sub.subtitle.pts, end = av_rescale(subtitle->pts - d->prev_sub.subtitle.pts,
1000, AV_TIME_BASE); 1000, AV_TIME_BASE);
if (end < ist->prev_sub.subtitle.end_display_time) { if (end < d->prev_sub.subtitle.end_display_time) {
av_log(NULL, AV_LOG_DEBUG, av_log(NULL, AV_LOG_DEBUG,
"Subtitle duration reduced from %"PRId32" to %d%s\n", "Subtitle duration reduced from %"PRId32" to %d%s\n",
ist->prev_sub.subtitle.end_display_time, end, d->prev_sub.subtitle.end_display_time, end,
end <= 0 ? ", dropping it" : ""); end <= 0 ? ", dropping it" : "");
ist->prev_sub.subtitle.end_display_time = end; d->prev_sub.subtitle.end_display_time = end;
} }
} }
FFSWAP(int, got_output, ist->prev_sub.got_output); FFSWAP(int, got_output, d->prev_sub.got_output);
FFSWAP(AVSubtitle, *subtitle, ist->prev_sub.subtitle); FFSWAP(AVSubtitle, *subtitle, d->prev_sub.subtitle);
if (end <= 0) if (end <= 0)
goto out; goto out;
} }
@ -430,8 +439,9 @@ out:
int fix_sub_duration_heartbeat(InputStream *ist, int64_t signal_pts) int fix_sub_duration_heartbeat(InputStream *ist, int64_t signal_pts)
{ {
Decoder *d = ist->decoder;
int ret = AVERROR_BUG; int ret = AVERROR_BUG;
AVSubtitle *prev_subtitle = &ist->prev_sub.subtitle; AVSubtitle *prev_subtitle = &d->prev_sub.subtitle;
AVSubtitle subtitle; AVSubtitle subtitle;
if (!ist->fix_sub_duration || !prev_subtitle->num_rects || if (!ist->fix_sub_duration || !prev_subtitle->num_rects ||

View File

@ -816,7 +816,6 @@ static void ist_free(InputStream **pist)
dec_free(&ist->decoder); dec_free(&ist->decoder);
av_dict_free(&ist->decoder_opts); av_dict_free(&ist->decoder_opts);
avsubtitle_free(&ist->prev_sub.subtitle);
av_freep(&ist->filters); av_freep(&ist->filters);
av_freep(&ist->outputs); av_freep(&ist->outputs);
av_freep(&ist->hwaccel_device); av_freep(&ist->hwaccel_device);