File indexing completed on 2025-01-19 03:57:06
0001 /********************************************************* 0002 * Copyright (C) 2020, Val Doroshchuk <valbok@gmail.com> * 0003 * * 0004 * This file is part of QtAVPlayer. * 0005 * Free Qt Media Player based on FFmpeg. * 0006 *********************************************************/ 0007 0008 #include "qavsubtitleframe.h" 0009 #include "qavstreamframe_p.h" 0010 #include <QDebug> 0011 0012 extern "C" { 0013 #include "libavcodec/avcodec.h" 0014 #include "libavformat/avformat.h" 0015 } 0016 0017 QT_BEGIN_NAMESPACE 0018 0019 class QAVSubtitleFramePrivate : public QAVStreamFramePrivate 0020 { 0021 public: 0022 QSharedPointer<AVSubtitle> subtitle; 0023 0024 double pts() const override; 0025 double duration() const override; 0026 }; 0027 0028 static void subtitle_free(AVSubtitle *subtitle) 0029 { 0030 avsubtitle_free(subtitle); 0031 } 0032 0033 QAVSubtitleFrame::QAVSubtitleFrame() 0034 : QAVStreamFrame(*new QAVSubtitleFramePrivate) 0035 { 0036 Q_D(QAVSubtitleFrame); 0037 d->subtitle.reset(new AVSubtitle, subtitle_free); 0038 memset(d->subtitle.data(), 0, sizeof(*d->subtitle.data())); 0039 } 0040 0041 QAVSubtitleFrame::~QAVSubtitleFrame() 0042 { 0043 } 0044 0045 QAVSubtitleFrame::QAVSubtitleFrame(const QAVSubtitleFrame &other) 0046 : QAVSubtitleFrame() 0047 { 0048 operator=(other); 0049 } 0050 0051 QAVSubtitleFrame &QAVSubtitleFrame::operator=(const QAVSubtitleFrame &other) 0052 { 0053 Q_D(QAVSubtitleFrame); 0054 QAVStreamFrame::operator=(other); 0055 d->subtitle = static_cast<QAVSubtitleFramePrivate *>(other.d_ptr.get())->subtitle; 0056 0057 return *this; 0058 } 0059 0060 AVSubtitle *QAVSubtitleFrame::subtitle() const 0061 { 0062 Q_D(const QAVSubtitleFrame); 0063 return d->subtitle.data(); 0064 } 0065 0066 double QAVSubtitleFramePrivate::pts() const 0067 { 0068 if (!subtitle) 0069 return NAN; 0070 AVRational tb; 0071 tb.num = 1; 0072 tb.den = AV_TIME_BASE; 0073 return subtitle->pts == AV_NOPTS_VALUE ? NAN : subtitle->pts * av_q2d(tb); 0074 } 0075 0076 double QAVSubtitleFramePrivate::duration() const 0077 { 0078 if (!subtitle) 0079 return 0.0; 0080 return (subtitle->end_display_time - subtitle->start_display_time) / 1000.0; 0081 } 0082 0083 QT_END_NAMESPACE