xbmc
DVDSubtitlesLibass.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "SubtitlesStyle.h"
12 #include "threads/CriticalSection.h"
13 #include "utils/ColorUtils.h"
14 
15 #include <memory>
16 
17 #include <ass/ass.h>
18 #include <ass/ass_types.h>
19 
22 static constexpr int ASS_NO_ID = -1;
23 
24 enum ASSSubType
25 {
26  NATIVE = 0,
27  ADAPTED
28 };
29 
31 {
32 public:
35 
40  void Configure();
41 
42  ASS_Image* RenderImage(double pts,
44  bool updateStyle,
45  const std::shared_ptr<struct KODI::SUBTITLES::STYLE::style>& subStyle,
46  int* changes = NULL);
47 
48  ASS_Event* GetEvents();
49 
54  int GetNrOfEvents() const;
55 
61  bool DecodeHeader(char* data, int size);
62 
67  bool DecodeDemuxPkt(const char* data, int size, double start, double duration);
68 
73  bool CreateTrack(char* buf, size_t size);
74 
78  void FlushEvents();
79 
84  int GetPlayResY();
85 
86 protected:
91  bool CreateTrack();
92 
97  bool CreateStyle();
98 
104  void SetSubtitleType(ASSSubType type) { m_subtitleType = type; }
105 
113  int AddEvent(const char* text, double startTime, double stopTime);
114 
123  int AddEvent(const char* text,
124  double startTime,
125  double stopTime,
127 
131  void AppendTextToEvent(int eventId, const char* text);
132 
139  int DeleteEvents(int nEvents, int threshold);
140 
146  void ChangeEventStopTime(int eventId, double stopTime);
147 
148  friend class CSubtitlesAdapter;
149 
150 
151 private:
152  void ConfigureAssOverride(const std::shared_ptr<struct KODI::SUBTITLES::STYLE::style>& subStyle,
153  ASS_Style* style);
154  void ApplyStyle(const std::shared_ptr<struct KODI::SUBTITLES::STYLE::style>& subStyle,
156 
157  ASS_Library* m_library = nullptr;
158  ASS_Track* m_track = nullptr;
159  ASS_Renderer* m_renderer = nullptr;
160  mutable CCriticalSection m_section;
161  ASSSubType m_subtitleType{NATIVE};
162 
163  // current default style ID of the ASS track
164  int m_currentDefaultStyleId{ASS_NO_ID};
165 
166  // default allocated style ID for the kodi user configured subtitle style
167  int m_defaultKodiStyleId{ASS_NO_ID};
168  std::string m_defaultFontFamilyName;
169 };
void AppendTextToEvent(int eventId, const char *text)
Append text to the specified event.
Definition: DVDSubtitlesLibass.cpp:653
bool CreateTrack()
Create a new empty ASS track.
Definition: DVDSubtitlesLibass.cpp:189
bool DecodeDemuxPkt(const char *data, int size, double start, double duration)
Decode ASS/SSA demux packet (depends from DecodeHeader)
Definition: DVDSubtitlesLibass.cpp:174
void SetSubtitleType(ASSSubType type)
Specify whether the subtitles are native (loaded from ASS/SSA file or stream) or adapted (converted f...
Definition: DVDSubtitlesLibass.h:104
int DeleteEvents(int nEvents, int threshold)
Delete old events only if the total number of events reaches the threshold.
Definition: DVDSubtitlesLibass.cpp:721
Definition: SubtitlesStyle.h:114
int GetNrOfEvents() const
Get the number of events (subtitle entries) in the ASS track.
Definition: DVDSubtitlesLibass.cpp:598
int AddEvent(const char *text, double startTime, double stopTime)
Add an ASS event to show a subtitle on a specified time.
Definition: DVDSubtitlesLibass.cpp:606
Definition: SubtitlesAdapter.h:22
void ChangeEventStopTime(int eventId, double stopTime)
Change the stop time of an Event with the specified time.
Definition: DVDSubtitlesLibass.cpp:685
void Configure()
Configure libass. This method groups any configurations that might change throughout the lifecycle of...
Definition: DVDSubtitlesLibass.cpp:82
void FlushEvents()
Flush buffered events.
Definition: DVDSubtitlesLibass.cpp:709
int GetPlayResY()
Get PlayResY value.
Definition: DVDSubtitlesLibass.cpp:539
bool CreateStyle()
Create a new empty ASS style.
Definition: DVDSubtitlesLibass.cpp:217
Definition: SubtitlesStyle.h:106
Definition: DVDSubtitlesLibass.h:30
bool DecodeHeader(char *data, int size)
Decode Header of ASS/SSA, needed to properly decode demux packets with DecodeDemuxPkt.
Definition: DVDSubtitlesLibass.cpp:161