Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrews54757 committed Aug 6, 2024
1 parent 4b58a84 commit 58cc70e
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 33 deletions.
19 changes: 6 additions & 13 deletions chrome/player/modules/dash2mp4/dash2mp4.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,23 @@ export class DASH2MP4 extends EventEmitter {
constructor(registerCancel) {
super();
this.converter = null;
if (registerCancel) {
registerCancel(() => {
this.cancel();
});
}
this.registerCancel = registerCancel;
}

cancel() {
this.cancelled = true;
if (this.converter) {
this.converter.cancel();
}
}

async convert(videoMimeType, videoDuration, videoInitSegment, audioMimeType, audioDuration, audioInitSegment, zippedFragments) {
try {
this.converter = new MP4Merger();
this.converter = new MP4Merger(this.registerCancel);
this.converter.on('progress', (progress) => {
this.emit('progress', progress);
});
return await this.converter.convert(videoDuration, videoInitSegment, audioDuration, audioInitSegment, zippedFragments);
} catch (e) {
if (e.message === 'Cancelled') {
throw e;
}
const {Reencoder} = await import('../reencoder/reencoder.mjs');
this.converter = new Reencoder();
this.converter = new Reencoder(this.registerCancel);
this.converter.on('progress', (progress) => {
this.emit('progress', progress);
});
Expand Down
2 changes: 1 addition & 1 deletion chrome/player/modules/dash2mp4/mp4merger.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export class MP4Merger extends EventEmitter {
if (this.cancelled) {
this.destroy();
this.blobManager.close();
return null;
throw new Error('Cancelled');
}
if (zippedFragments[i].track === 0) {
await this.pushFragment(this.videoTrack, zippedFragments[i]);
Expand Down
2 changes: 1 addition & 1 deletion chrome/player/modules/hls2mp4/hls2mp4.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export class HLS2MP4 extends EventEmitter {
if (this.cancelled) {
this.destroy();
this.blobManager.close();
return null;
throw new Error('Cancelled');
}
if (zippedFragments[i].track === 0) {
await this.pushFragment(zippedFragments[i]);
Expand Down
2 changes: 1 addition & 1 deletion chrome/player/modules/reencoder/reencoder.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export class Reencoder extends EventEmitter {
if (this.cancelled) {
this.destroy();
this.blobManager.close();
return null;
throw new Error('Cancelled');
}
if (zippedFragments[i].track === 0) {
await this.pushFragment(zippedFragments[i], this.videoDemuxer);
Expand Down
1 change: 0 additions & 1 deletion chrome/player/players/dash/DashPlayer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ export default class DashPlayer extends EventEmitter {
return {
extension: 'mp4',
blob: blob,
cancelled: dash2mp4.cancelled,
};
} catch (e) {
zippedFragments.forEach((data) => {
Expand Down
1 change: 0 additions & 1 deletion chrome/player/players/hls/HLSPlayer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ export default class HLSPlayer extends EventEmitter {
return {
extension: 'mp4',
blob: blob,
cancelled: mp4merger.cancelled,
};
} else {
if (levelInitData || audioLevelInitData) {
Expand Down
9 changes: 1 addition & 8 deletions chrome/player/players/mp4/MP4Player.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -742,14 +742,7 @@ export default class MP4Player extends EventEmitter {
frag.removeReference(ReferenceTypes.SAVER);
}
writer.abort();
if (e.message !== 'Cancelled') {
throw e;
}
return {
extension: 'mp4',
blob: null,
cancelled: true,
};
throw e;
}
}

Expand Down
14 changes: 7 additions & 7 deletions chrome/player/ui/SaveManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,13 @@ export class SaveManager {
this.downloadCancel = null;
DOMElements.saveNotifBanner.style.display = 'none';

if (confirm(Localize.getMessage('player_savevideo_failed_ask_archive'))) {
this.dumpBuffer(name);
if (e.message === 'Cancelled') {
console.error(e);
this.setStatusMessage('save-video', Localize.getMessage('player_savevideo_cancelled'), 'info', 2000);
} else {
if (confirm(Localize.getMessage('player_savevideo_failed_ask_archive'))) {
this.dumpBuffer(name);
}
}
return;
}
Expand All @@ -176,11 +181,6 @@ export class SaveManager {
this.downloadURL = null;
}

if (!result || result.cancelled) {
this.setStatusMessage('save-video', Localize.getMessage('player_savevideo_cancelled'), 'info', 2000);
return;
}

this.setStatusMessage('save-video', Localize.getMessage('player_savevideo_complete'), 'info', 2000);

if (!canStream) {
Expand Down

0 comments on commit 58cc70e

Please sign in to comment.