Skip to content

Commit

Permalink
Update ts-sdk types (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrtqKr authored Jan 9, 2025
1 parent 2853a93 commit 47e6061
Show file tree
Hide file tree
Showing 12 changed files with 681 additions and 471 deletions.
1 change: 1 addition & 0 deletions ts/@live-compositor/core/src/api/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function intoMp4RegisterInput(input: Inputs.RegisterMp4Input): RegisterInputRequ
loop: input.loop,
required: input.required,
offset_ms: input.offsetMs,
video_decoder: input.videoDecoder,
};
}

Expand Down
47 changes: 44 additions & 3 deletions ts/@live-compositor/core/src/api/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
RegisterRtpOutput,
RegisterMp4Output,
RegisterCanvasOutput,
RegisterWhipOutput,
_liveCompositorInternals,
} from 'live-compositor';
import { inputRefIntoRawId } from './input.js';
Expand All @@ -27,7 +28,8 @@ export type OutputCanvasVideoOptions = {
export type RegisterOutput =
| ({ type: 'rtp_stream' } & RegisterRtpOutput)
| ({ type: 'mp4' } & RegisterMp4Output)
| ({ type: 'canvas' } & RegisterCanvasOutput);
| ({ type: 'canvas' } & RegisterCanvasOutput)
| ({ type: 'whip' } & RegisterWhipOutput);

export function intoRegisterOutput(
output: RegisterOutput,
Expand All @@ -39,6 +41,8 @@ export function intoRegisterOutput(
return intoRegisterMp4Output(output, initial);
} else if (output.type === 'canvas') {
return intoRegisterCanvasOutput(output, initial);
} else if (output.type === 'whip') {
return intoRegisterWhipOutput(output, initial);
} else {
throw new Error(`Unknown output type ${(output as any).type}`);
}
Expand Down Expand Up @@ -84,8 +88,22 @@ function intoRegisterCanvasOutput(
};
}

function intoRegisterWhipOutput(
output: Outputs.RegisterWhipOutput,
initial: { video?: Api.Video; audio?: Api.Audio }
): RegisterOutputRequest {
return {
type: 'whip',
endpoint_url: output.endpointUrl,
bearer_token: output.bearerToken,

video: output.video && initial.video && intoOutputVideoOptions(output.video, initial.video),
audio: output.audio && initial.audio && intoOutputWhipAudioOptions(output.audio, initial.audio),
};
}

function intoOutputVideoOptions(
video: Outputs.RtpVideoOptions | Outputs.Mp4VideoOptions,
video: Outputs.RtpVideoOptions | Outputs.Mp4VideoOptions | Outputs.WhipVideoOptions,
initial: Api.Video
): Api.OutputVideoOptions {
return {
Expand All @@ -97,7 +115,10 @@ function intoOutputVideoOptions(
}

function intoVideoEncoderOptions(
encoder: Outputs.RtpVideoEncoderOptions | Outputs.Mp4VideoEncoderOptions
encoder:
| Outputs.RtpVideoEncoderOptions
| Outputs.Mp4VideoEncoderOptions
| Outputs.WhipVideoEncoderOptions
): Api.VideoEncoderOptions {
return {
type: 'ffmpeg_h264',
Expand Down Expand Up @@ -128,6 +149,17 @@ function intoOutputMp4AudioOptions(
};
}

function intoOutputWhipAudioOptions(
audio: Outputs.WhipAudioOptions,
initial: Api.Audio
): Api.OutputWhipAudioOptions {
return {
send_eos_when: audio.sendEosWhen && intoOutputEosCondition(audio.sendEosWhen),
encoder: intoWhipAudioEncoderOptions(audio.encoder),
initial,
};
}

function intoRtpAudioEncoderOptions(
encoder: Outputs.RtpAudioEncoderOptions
): Api.RtpAudioEncoderOptions {
Expand All @@ -147,6 +179,15 @@ function intoMp4AudioEncoderOptions(
};
}

function intoWhipAudioEncoderOptions(
encoder: Outputs.WhipAudioEncoderOptions
): Api.WhipAudioEncoderOptions {
return {
type: 'opus',
channels: encoder.channels,
};
}

export function intoAudioInputsConfiguration(
inputs: _liveCompositorInternals.AudioConfig
): Api.Audio {
Expand Down
Loading

0 comments on commit 47e6061

Please sign in to comment.