File indexing completed on 2024-06-16 04:38:30

0001 /*
0002     SPDX-FileCopyrightText: 2003 Fabrice Bellard
0003     SPDX-FileCopyrightText: 2020-2022 Mladen Milinkovic <max@smoothware.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "subtitledecoder.h"
0009 
0010 #include "videoplayer/backend/ffplayer.h"
0011 
0012 using namespace SubtitleComposer;
0013 
0014 SubtitleDecoder::SubtitleDecoder(QObject *parent)
0015     : Decoder(parent)
0016 {
0017 
0018 }
0019 
0020 void
0021 SubtitleDecoder::run()
0022 {
0023     for(;;) {
0024         Frame *sp = m_frameQueue->peekWritable();
0025         if(!sp)
0026             break;
0027 
0028         int gotSubtitle = decodeFrame(nullptr, &sp->sub);
0029         if(gotSubtitle < 0)
0030             break;
0031 
0032         double pts = 0;
0033 
0034         if(gotSubtitle && sp->sub.format == 0) {
0035             if(sp->sub.pts != AV_NOPTS_VALUE)
0036                 pts = sp->sub.pts / (double)AV_TIME_BASE;
0037             sp->pts = pts;
0038             sp->serial = pktSerial();
0039             sp->width = width();
0040             sp->height = height();
0041             sp->uploaded = false;
0042 
0043             // now we can update the picture count
0044             m_frameQueue->push();
0045         } else if(gotSubtitle) {
0046             avsubtitle_free(&sp->sub);
0047         }
0048     }
0049 }