MythTV master
textsubtitleparser.h
Go to the documentation of this file.
1// -*- Mode: c++ -*-
7#ifndef TEXT_SUBTITLE_PARSER_H
8#define TEXT_SUBTITLE_PARSER_H
9
10extern "C" {
11#include <libavcodec/avcodec.h>
12#include <libavformat/avformat.h>
13}
14
15// C++ headers
16#include <cstdint>
17#include <vector>
18
19// Qt headers
20#include <QObject>
21#include <QMutexLocker>
22#include <QStringList>
23#include <QDateTime>
24
26{
27 public:
28 text_subtitle_t(long start_, long end_) : m_start(start_), m_end(end_) {}
29 text_subtitle_t() = default;
32
33 public:
34 uint64_t m_start {0};
35 uint64_t m_end {0};
36 QStringList m_textLines;
37};
38
39using TextSubtitleList = std::vector<text_subtitle_t>;
40
41class TextSubtitles : public QObject
42{
43 Q_OBJECT
44
45 signals:
47
48 public:
49 ~TextSubtitles() override;
50
51 void SetFilename(const QString &fileName) {
52 QMutexLocker locker(&m_lock);
53 m_fileName = fileName;
54 }
55
56 void SetLastLoaded(void);
57 void SetByteCount(off_t count) {
58 QMutexLocker locker(&m_lock);
59 m_byteCount = count;
60 }
61 off_t GetByteCount(void) const { return m_byteCount; }
62 void SetInProgress(bool isInProgress) {
63 QMutexLocker locker(&m_lock);
64 m_isInProgress = isInProgress;
65 }
66 void SetHasSubtitles(bool hasSubs) { m_hasSubtitles = hasSubs; }
67 bool GetHasSubtitles() const { return m_hasSubtitles; }
68
69 void Lock(void) { m_lock.lock(); }
70 void Unlock(void) { m_lock.unlock(); }
71
72 private:
73 QString m_fileName;
74 QDateTime m_lastLoaded;
76 // Note: m_isInProgress is overly conservative because it doesn't
77 // change from true to false after a recording completes.
78 bool m_isInProgress {false};
79 bool m_hasSubtitles {false};
80 QRecursiveMutex m_lock;
81};
82
83class SubtitleReader;
85
87{
88 public:
89 TextSubtitleParser(SubtitleReader *parent, QString fileName, TextSubtitles *target);
91 void LoadSubtitles(bool inBackground);
92 int decode(AVPacket *pkt);
93 QByteArray GetSubHeader();
94 void SeekFrame(int64_t ts, int flags);
95 int ReadNextSubtitle(void);
96
97 private:
98 static int read_packet(void *opaque, uint8_t *buf, int buf_size);
99 static int64_t seek_packet(void *opaque, int64_t offset, int whence);
100
104 QString m_fileName;
105
106 AVFormatContext *m_fmtCtx {nullptr};
107 AVCodecContext *m_decCtx {nullptr};
108 AVStream *m_stream {nullptr};
109 AVPacket *m_pkt {nullptr};
110};
111
112#endif
static int64_t seek_packet(void *opaque, int64_t offset, int whence)
Seek in the file buffer.
SubtitleReader * m_parent
TextSubtitleParser(SubtitleReader *parent, QString fileName, TextSubtitles *target)
TextSubtitles * m_target
AVFormatContext * m_fmtCtx
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Read data from the file buffer into the avio context buffer.
void LoadSubtitles(bool inBackground)
void SeekFrame(int64_t ts, int flags)
AVCodecContext * m_decCtx
int decode(AVPacket *pkt)
int ReadNextSubtitle(void)
Read the next subtitle in the AV stream.
SubtitleLoadHelper * m_loadHelper
void SetHasSubtitles(bool hasSubs)
off_t GetByteCount(void) const
void SetByteCount(off_t count)
QDateTime m_lastLoaded
void TextSubtitlesUpdated()
bool GetHasSubtitles() const
void SetFilename(const QString &fileName)
void SetLastLoaded(void)
~TextSubtitles() override
void SetInProgress(bool isInProgress)
QRecursiveMutex m_lock
TextSubtitles Copyright (c) 2006 by Pekka Jääskeläinen Distributed as part of MythTV under GPL v2 and...
text_subtitle_t & operator=(const text_subtitle_t &)=default
uint64_t m_start
Starting time in msec or starting frame.
text_subtitle_t()=default
uint64_t m_end
Ending time in msec or ending frame.
text_subtitle_t(const text_subtitle_t &)=default
text_subtitle_t(long start_, long end_)
QStringList m_textLines
#define off_t
std::vector< text_subtitle_t > TextSubtitleList