Skip to content

Commit

Permalink
Merge pull request #6944 from video-dev/task/transmuxer-types-and-ts-…
Browse files Browse the repository at this point in the history
…light-enhancements

Exclude AC3 and HEVC remuxing from light build
  • Loading branch information
robwalch authored Jan 8, 2025
2 parents e346300 + 2a30887 commit 1dee99c
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 105 deletions.
12 changes: 6 additions & 6 deletions src/demux/audio/base-audio-demuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { dummyTrack } from '../dummy-demuxed-track';
import type { RationalTimestamp } from '../../utils/timescale-conversion';

class BaseAudioDemuxer implements Demuxer {
protected _audioTrack!: DemuxedAudioTrack;
protected _id3Track!: DemuxedMetadataTrack;
protected _audioTrack?: DemuxedAudioTrack;
protected _id3Track?: DemuxedMetadataTrack;
protected frameIndex: number = 0;
protected cachedData: Uint8Array | null = null;
protected basePTS: number | null = null;
Expand Down Expand Up @@ -74,8 +74,8 @@ class BaseAudioDemuxer implements Demuxer {
let id3Data: Uint8Array | undefined = getId3Data(data, 0);
let offset = id3Data ? id3Data.length : 0;
let lastDataIndex;
const track = this._audioTrack;
const id3Track = this._id3Track;
const track = this._audioTrack as DemuxedAudioTrack;
const id3Track = this._id3Track as DemuxedMetadataTrack;
const timestamp = id3Data ? getId3Timestamp(id3Data) : undefined;
const length = data.length;

Expand Down Expand Up @@ -167,9 +167,9 @@ class BaseAudioDemuxer implements Demuxer {
}

return {
audioTrack: this._audioTrack,
audioTrack: this._audioTrack as DemuxedAudioTrack,
videoTrack: dummyTrack() as DemuxedVideoTrackBase,
id3Track: this._id3Track,
id3Track: this._id3Track as DemuxedMetadataTrack,
textTrack: dummyTrack() as DemuxedUserdataTrack,
};
}
Expand Down
5 changes: 2 additions & 3 deletions src/demux/tsdemuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,8 @@ function parsePMT(
audioPid: -1,
videoPid: -1,
id3Pid: -1,
segmentVideoCodec: 'avc',
segmentAudioCodec: 'aac',
segmentVideoCodec: 'avc' as 'avc' | 'hevc',
segmentAudioCodec: 'aac' as 'aac' | 'ac3' | 'mp3',
};
const sectionLength = ((data[offset + 1] & 0x0f) << 8) | data[offset + 2];
const tableEnd = offset + 3 + sectionLength - 4;
Expand Down Expand Up @@ -822,7 +822,6 @@ function parsePMT(
// logger.log('AVC PID:' + pid);
if (result.videoPid === -1) {
result.videoPid = pid;
result.segmentVideoCodec = 'avc';
}

break;
Expand Down
24 changes: 12 additions & 12 deletions src/demux/video/hevc-video-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,7 @@ class HevcVideoParser extends BaseVideoParser {
track.params[prop] = config.params[prop];
}
}
if (
(!track.vps && !track.sps.length) ||
(track.vps && track.vps[0] === this.initVPS)
) {
track.sps.push(unit.data);
}
this.pushParameterSet(track.sps, unit.data, track.vps);
if (!VideoSample) {
VideoSample = this.VideoSample = this.createVideoSample(
true,
Expand All @@ -185,12 +180,7 @@ class HevcVideoParser extends BaseVideoParser {
track.params[prop] = config[prop];
}
}
if (
(!track.vps && !track.pps.length) ||
(track.vps && track.vps[0] === this.initVPS)
) {
track.pps.push(unit.data);
}
this.pushParameterSet(track.pps, unit.data, track.vps);
}
break;

Expand Down Expand Up @@ -227,6 +217,16 @@ class HevcVideoParser extends BaseVideoParser {
}
}

private pushParameterSet(
parameterSets: Uint8Array[],
data: Uint8Array,
vps: Uint8Array[] | undefined,
) {
if ((vps && vps[0] === this.initVPS) || (!vps && !parameterSets.length)) {
parameterSets.push(data);
}
}

protected getNALuType(data: Uint8Array, offset: number): number {
return (data[offset] & 0x7e) >>> 1;
}
Expand Down
Loading

0 comments on commit 1dee99c

Please sign in to comment.