Skip to content

Commit

Permalink
feat: parse EXT-X-SKIP tags and attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Oct 20, 2023
1 parent fdf9ead commit 493e967
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/web-media-box/src/hls-parser/consts/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export const EXT_X_PROGRAM_DATE_TIME = 'EXT-X-PROGRAM-DATE-TIME';
export const EXT_X_BITRATE = 'EXT-X-BITRATE';
export const EXT_X_PART = 'EXT-X-PART';
export const EXT_X_MEDIA = 'EXT_X_MEDIA';
export const EXT_X_SKIP = 'EXT-X-SKIP';
3 changes: 3 additions & 0 deletions packages/web-media-box/src/hls-parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
EXT_X_PART,
EXT_X_PROGRAM_DATE_TIME,
EXT_X_MEDIA,
EXT_X_SKIP,
} from './consts/tags.ts';
import type {
CustomTagMap,
Expand Down Expand Up @@ -65,6 +66,7 @@ import {
ExtXMap,
ExtXPart,
ExtXMedia,
ExtXSkip,
} from './tags/tagWithAttributesProcessors.ts';

const defaultSegment: Segment = {
Expand Down Expand Up @@ -142,6 +144,7 @@ class Parser {
[EXT_X_MAP]: new ExtXMap(this.warnCallback),
[EXT_X_PART]: new ExtXPart(this.warnCallback),
[EXT_X_MEDIA]: new ExtXMedia(this.warnCallback),
[EXT_X_SKIP]: new ExtXSkip(this.warnCallback),
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ParsedPlaylist, PartialSegment, Segment, Rendition, RenditionType, RenditionGroups, GroupId } from '../types/parsedPlaylist';
import { TagProcessor } from './base.ts';
import { missingRequiredAttributeWarn } from '../utils/warn.ts';
import { EXT_X_PART_INF, EXT_X_SERVER_CONTROL, EXT_X_START, EXT_X_KEY, EXT_X_MAP, EXT_X_PART, EXT_X_MEDIA } from '../consts/tags.ts';
import { EXT_X_PART_INF, EXT_X_SERVER_CONTROL, EXT_X_START, EXT_X_KEY, EXT_X_MAP, EXT_X_PART, EXT_X_MEDIA, EXT_X_SKIP } from '../consts/tags.ts';
import { parseBoolean } from '../utils/parse.ts';

export abstract class TagWithAttributesProcessor extends TagProcessor {
Expand Down Expand Up @@ -240,3 +240,18 @@ export class ExtXMedia extends TagWithAttributesProcessor {
playlist.renditionGroups[renditionTypeKey][rendition.groupId] = [rendition];
}
}

export class ExtXSkip extends TagWithAttributesProcessor {
private static readonly SKIPPED_SEGMENTS = 'SKIPPED-SEGMENTS';
private static readonly RECENTLY_REMOVED_DATERANGES = 'RECENTLY-REMOVED-DATERANGES';

protected requiredAttributes = new Set([ExtXSkip.SKIPPED_SEGMENTS]);
protected readonly tag = EXT_X_SKIP;

protected safeProcess(tagAttributes: Record<string, string>, playlist: ParsedPlaylist): void {
playlist.skip = {
skippedSegments: Number(tagAttributes[ExtXSkip.SKIPPED_SEGMENTS]),
recentlyRemovedDateranges: tagAttributes[ExtXSkip.RECENTLY_REMOVED_DATERANGES].split('\t')
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export interface RenditionGroups {
closedCaptions: Record<GroupId, RenditionGroup>;
}

export interface Skip {
skippedSegments: number;
recentlyRemovedDateranges?: Array<string>;
}

export type PlaylistType = 'EVENT' | 'VOD';

export interface ParsedPlaylist {
Expand Down Expand Up @@ -117,4 +122,6 @@ export interface ParsedPlaylist {
renditionGroups: RenditionGroups;
// Used to persist EXT_X_BITRATE across segments
currentBitrate?: number;
// https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.5.2
skip?: Skip
}

0 comments on commit 493e967

Please sign in to comment.