Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #180: fix ts stream with opus audio payload. #190

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 47 additions & 38 deletions src/demux/ts-demuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1557,45 +1557,54 @@ class TSDemuxer extends BaseDemuxer {
}

let sample_pts_ms = base_pts_ms;
let last_sample_pts_ms: number;

for (let offset = 0; offset < data.length; ) {
ref_sample_duration = 20;

const opus_pending_trim_start = (data[offset + 1] & 0x10) !== 0;
const trim_end = (data[offset + 1] & 0x08) !== 0;
let index = offset + 2;
let size = 0;

while (data[index] === 0xFF) {
size += 255;
index += 1;
}
size += data[index];
index += 1;
index += opus_pending_trim_start ? 2 : 0;
index += trim_end ? 2 : 0;

last_sample_pts_ms = sample_pts_ms;
let sample_pts_ms_int = Math.floor(sample_pts_ms);
let sample = data.slice(index, index + size)

let opus_sample = {
unit: sample,
length: sample.byteLength,
pts: sample_pts_ms_int,
dts: sample_pts_ms_int
};
this.audio_track_.samples.push(opus_sample);
this.audio_track_.length += sample.byteLength;

sample_pts_ms += ref_sample_duration;
offset = index + size;
}
// let last_sample_pts_ms: number;
let sample_pts_ms_int = Math.floor(sample_pts_ms);
let opus_sample = {
unit: data,
length: data.byteLength,
pts: sample_pts_ms_int,
dts: sample_pts_ms_int
};
this.audio_track_.samples.push(opus_sample);
this.audio_track_.length += data.byteLength;

if (last_sample_pts_ms) {
this.audio_last_sample_pts_ = last_sample_pts_ms;
}
// for (let offset = 0; offset < data.length; ) {
// ref_sample_duration = 20;

// const opus_pending_trim_start = (data[offset + 1] & 0x10) !== 0;
// const trim_end = (data[offset + 1] & 0x08) !== 0;
// let index = offset + 2;
// let size = 0;

// while (data[index] === 0xFF) {
// size += 255;
// index += 1;
// }
// size += data[index];
// index += 1;
// index += opus_pending_trim_start ? 2 : 0;
// index += trim_end ? 2 : 0;

// last_sample_pts_ms = sample_pts_ms;
// let sample_pts_ms_int = Math.floor(sample_pts_ms);
// let sample = data.slice(index, index + size)

// let opus_sample = {
// unit: sample,
// length: sample.byteLength,
// pts: sample_pts_ms_int,
// dts: sample_pts_ms_int
// };
// this.audio_track_.samples.push(opus_sample);
// this.audio_track_.length += sample.byteLength;

// sample_pts_ms += ref_sample_duration;
// offset = index + size;
// }

// if (last_sample_pts_ms) {
// this.audio_last_sample_pts_ = last_sample_pts_ms;
// }
}

private parseMP3Payload(data: Uint8Array, pts: number) {
Expand Down