Skip to content

Commit

Permalink
Add dropAllAnimations feature
Browse files Browse the repository at this point in the history
Original implementation by JustAMan, mostly in the following
three commits sans unrelated changes. Backported by Oneric.
jellyfin@d3bc472
jellyfin@a66e797
jellyfin@971a997

The commits have also been adjusted to apply on top of current upstream
master, to use the animations detection from the previous commit instead
of the faulty original logic and the scanned_events variable was added.
Also added documentation which was missing in the original commits.

Co-authored-by: Oneric <[email protected]>
  • Loading branch information
JustAMan and TheOneric committed May 7, 2022
1 parent f4804f9 commit 5b42203
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ When creating an instance of SubtitleOctopus, you can set the following options:
- `maxRenderHeight`: The maximum rendering height of the subtitles canvas.
Beyond this subtitles will be upscaled by the browser.
(Default: `0` - no limit)
- `dropAllAnimations`: If set to true, attempt to discard all animated tags.
Enabling this may severly mangle complex subtitles and
should only be considered as an last ditch effort of uncertain success
for hardware otherwise incapable of displaing anything.
Will not reliably work with manually edited or allocated events.
(Default: `false` - do nothing)

### Rendering Modes
#### JS Blending
Expand Down
25 changes: 25 additions & 0 deletions src/SubtitleOctopus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ class SubtitleOctopus {
private:
ReusableBuffer2D m_blend;
RenderBlendResult m_blendResult;
bool drop_animations;
int scanned_events; // next unscanned event index
public:
ASS_Library* ass_library;
ASS_Renderer* ass_renderer;
Expand All @@ -252,12 +254,33 @@ class SubtitleOctopus {
track = NULL;
canvas_w = 0;
canvas_h = 0;
drop_animations = false;
scanned_events = 0;
}

void setLogLevel(int level) {
log_level = level;
}

void setDropAnimations(int value) {
drop_animations = !!value;
if (drop_animations)
scanAnimations(scanned_events);
}

/*
* \brief Scan events starting at index i for animations
* and discard animated tags when found.
* Note that once animated tags were dropped they cannot be restored.
* Updates the class member scanned_events to last scanned index.
*/
void scanAnimations(int i) {
for (; i < track->n_events; i++) {
_is_event_animated(track->events + i, drop_animations);
}
scanned_events = i;
}

void initLibrary(int frame_w, int frame_h) {
ass_library = ass_library_init();
if (!ass_library) {
Expand Down Expand Up @@ -287,6 +310,7 @@ class SubtitleOctopus {
fprintf(stderr, "jso: Failed to start a track\n");
exit(4);
}
scanAnimations(0);
}

void createTrackMem(char *buf, unsigned long bufsize) {
Expand All @@ -296,6 +320,7 @@ class SubtitleOctopus {
fprintf(stderr, "jso: Failed to start a track\n");
exit(4);
}
scanAnimations(0);
}

void removeTrack() {
Expand Down
1 change: 1 addition & 0 deletions src/SubtitleOctopus.idl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ interface SubtitleOctopus {
attribute ASS_Renderer ass_renderer;
attribute ASS_Library ass_library;
void setLogLevel(long level);
void setDropAnimations(long value);
void initLibrary(long frame_w, long frame_h);
void createTrack(DOMString subfile);
void createTrackMem(DOMString buf, unsigned long bufsize);
Expand Down
2 changes: 2 additions & 0 deletions src/post-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ self.nextIsRaf = false;
self.lastCurrentTimeReceivedAt = Date.now();
self.targetFps = 24;
self.libassMemoryLimit = 0; // in MiB
self.dropAllAnimations = false;

self.width = 0;
self.height = 0;
Expand Down Expand Up @@ -565,6 +566,7 @@ function onMessageFromMainEmscriptenThread(message) {
self.targetFps = message.data.targetFps || self.targetFps;
self.libassMemoryLimit = message.data.libassMemoryLimit || self.libassMemoryLimit;
self.libassGlyphLimit = message.data.libassGlyphLimit || 0;
self.dropAllAnimations = !!message.data.dropAllAnimations || self.dropAllAnimations;
removeRunDependency('worker-init');
postMessage({
target: "ready",
Expand Down
1 change: 1 addition & 0 deletions src/pre-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Module['onRuntimeInitialized'] = function () {
self.blendH = Module._malloc(4);

self.octObj.initLibrary(screen.width, screen.height);
self.octObj.setDropAnimations(self.dropAllAnimations);
self.octObj.createTrack("/sub.ass");
self.ass_track = self.octObj.track;
self.ass_library = self.octObj.ass_library;
Expand Down
4 changes: 3 additions & 1 deletion src/subtitles-octopus.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var SubtitlesOctopus = function (options) {
self.prescaleFactor = options.prescaleFactor || 1.0;
self.prescaleHeightLimit = options.prescaleHeightLimit || 1080;
self.maxRenderHeight = options.maxRenderHeight || 0; // 0 - no limit
self.dropAllAnimations = options.dropAllAnimations || false; // attempt to remove all animations as a last ditch effort for displaying on weak hardware; may severly mangle subtitles if enabled
self.isOurCanvas = false; // (internal) we created canvas and manage it
self.video = options.video; // HTML video element (optional if canvas specified)
self.canvasParent = null; // (internal) HTML canvas parent element
Expand Down Expand Up @@ -113,7 +114,8 @@ var SubtitlesOctopus = function (options) {
debug: self.debug,
targetFps: self.targetFps,
libassMemoryLimit: self.libassMemoryLimit,
libassGlyphLimit: self.libassGlyphLimit
libassGlyphLimit: self.libassGlyphLimit,
dropAllAnimations: self.dropAllAnimations
});
};

Expand Down

0 comments on commit 5b42203

Please sign in to comment.