Skip to content

Commit

Permalink
improve containerFomat default
Browse files Browse the repository at this point in the history
  • Loading branch information
mazyu36 committed Feb 12, 2025
1 parent bd045de commit 12393ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
11 changes: 6 additions & 5 deletions packages/@aws-cdk/aws-ivs-alpha/lib/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ export interface ChannelProps {
/**
* Indicates which content-packaging format is used (MPEG-TS or fMP4).
*
* If `multitrackInputConfiguration` is specified containerFormat is required and must be set to ContainerFormat.FRAGMENTED_MP4.
* Otherwise, containerFormat may be set to ContainerFormat.TS or ContainerFormat.FRAGMENTED_MP4.
* If `multitrackInputConfiguration` is specified, only fMP4 can be used.
* Otherwise, `containerFormat` may be set to `ContainerFormat.TS` or `ContainerFormat.FRAGMENTED_MP4`.
*
* @default undefined - IVS default setting is MPEG-TS
* @default - `ContainerFormat.FRAGMENTED_MP4` is automatically set when the `multitrackInputConfiguration` is specified. If not specified, it remains undefined and uses the IVS default setting (TS).
*/
readonly containerFormat?: ContainerFormat;

Expand Down Expand Up @@ -318,7 +318,7 @@ export class Channel extends ChannelBase {
throw new Error(`\`multitrackInputConfiguration\` is only supported for \`ChannelType.STANDARD\`, got: ${props.type}.`);
}

if (props.containerFormat !== ContainerFormat.FRAGMENTED_MP4) {
if (props.containerFormat !== undefined && props.containerFormat !== ContainerFormat.FRAGMENTED_MP4) {
throw new Error(`\`containerFormat\` must be set to \`ContainerFormat.FRAGMENTED_MP4\` when \`multitrackInputConfiguration\` is specified, got: ${props.containerFormat}.`);
}
}
Expand All @@ -331,7 +331,8 @@ export class Channel extends ChannelBase {
type: props.type,
preset,
recordingConfigurationArn: props.recordingConfiguration?.recordingConfigurationArn,
containerFormat: props.containerFormat,
containerFormat: props.containerFormat ??
(props.multitrackInputConfiguration ? ContainerFormat.FRAGMENTED_MP4 : undefined),
multitrackInputConfiguration: props.multitrackInputConfiguration ?
{
enabled: true,
Expand Down
32 changes: 26 additions & 6 deletions packages/@aws-cdk/aws-ivs-alpha/test/ivs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ test.each([true, false])('channel with insecureIngest set to %s.', (insecureInge
});
});

test.each([ivs.ContainerFormat.FRAGMENTED_MP4, ivs.ContainerFormat.TS])('channel with containerFormat set to %s.', (containerFormat) => {
test.each([ivs.ContainerFormat.FRAGMENTED_MP4, ivs.ContainerFormat.TS])('channel when containerFormat is set to %s.', (containerFormat) => {
new ivs.Channel(stack, 'Channel', {
type: ivs.ChannelType.STANDARD,
containerFormat,
Expand All @@ -228,7 +228,7 @@ test.each([
[ivs.MaximumResolution.FULL_HD, ivs.Policy.ALLOW],
[ivs.MaximumResolution.HD, ivs.Policy.REQUIRE],
[ivs.MaximumResolution.SD, ivs.Policy.ALLOW],
])('channel with multitrackInputConfiguration, maximumResolution: %s, policy: %s.', (maximumResolution, policy) => {
])('create channel when multitrackInputConfiguration is specified, maximumResolution: %s, policy: %s.', (maximumResolution, policy) => {
new ivs.Channel(stack, 'Channel', {
type: ivs.ChannelType.STANDARD,
containerFormat: ivs.ContainerFormat.FRAGMENTED_MP4,
Expand All @@ -249,11 +249,31 @@ test.each([
});
});

test('create channel when multitrackInputConfiguration is specified without containerFormat', () => {
new ivs.Channel(stack, 'Channel', {
type: ivs.ChannelType.STANDARD,
multitrackInputConfiguration: {
maximumResolution: ivs.MaximumResolution.HD,
policy: ivs.Policy.ALLOW,
},
});

Template.fromStack(stack).hasResourceProperties('AWS::IVS::Channel', {
Type: 'STANDARD',
ContainerFormat: 'FRAGMENTED_MP4',
MultitrackInputConfiguration: {
Enabled: true,
MaximumResolution: ivs.MaximumResolution.HD,
Policy: ivs.Policy.ALLOW,
},
});
});

test.each([
ivs.ChannelType.ADVANCED_HD,
ivs.ChannelType.ADVANCED_SD,
ivs.ChannelType.BASIC,
])('throws an error when `type` is %s with `multitrackInputConfiguration`', (type) => {
])('throws an error when `multitrackInputConfiguration` is specified with %s ', (type) => {
expect(() => new ivs.Channel(stack, 'Channel', {
type,
containerFormat: ivs.ContainerFormat.FRAGMENTED_MP4,
Expand All @@ -264,13 +284,13 @@ test.each([
})).toThrow(`\`multitrackInputConfiguration\` is only supported for \`ChannelType.STANDARD\`, got: ${type}.`);
});

test.each([undefined, ivs.ContainerFormat.TS])('throws an error when `containerFormat` is %s with `multitrackInputConfiguration`', (containerFormat) => {
test('throws an error when `multitrackInputConfiguration` is specified with `ContainerFormat.TS`', () => {
expect(() => new ivs.Channel(stack, 'Channel', {
type: ivs.ChannelType.STANDARD,
containerFormat,
containerFormat: ivs.ContainerFormat.TS,
multitrackInputConfiguration: {
maximumResolution: ivs.MaximumResolution.SD,
policy: ivs.Policy.ALLOW,
},
})).toThrow(`\`containerFormat\` must be set to \`ContainerFormat.FRAGMENTED_MP4\` when \`multitrackInputConfiguration\` is specified, got: ${containerFormat}.`);
})).toThrow(`\`containerFormat\` must be set to \`ContainerFormat.FRAGMENTED_MP4\` when \`multitrackInputConfiguration\` is specified, got: ${ivs.ContainerFormat.TS}.`);
});

0 comments on commit 12393ae

Please sign in to comment.