Skip to content

Commit

Permalink
Match framerate in DefaultVideoFrameProcessorPipeline with input stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Shi Su committed Dec 20, 2024
1 parent 9a5de7b commit 1d7e425
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

### Fixed
- Match framerate in `DefaultVideoFrameProcessorPipeline` with input stream

## [3.26.0] - 2024-10-07

Expand Down
6 changes: 3 additions & 3 deletions docs/classes/defaultvideoframeprocessorpipeline.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ <h3>processors</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/videoframeprocessorpipeline.html">VideoFrameProcessorPipeline</a>.<a href="../interfaces/videoframeprocessorpipeline.html#processors">processors</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts#L193">src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts:193</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts#L194">src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts:194</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -251,7 +251,7 @@ <h4 class="tsd-returns-title">Returns <a href="../interfaces/videoframeprocessor
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/videoframeprocessorpipeline.html">VideoFrameProcessorPipeline</a>.<a href="../interfaces/videoframeprocessorpipeline.html#processors">processors</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts#L189">src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts:189</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts#L190">src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts:190</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -380,7 +380,7 @@ <h3>process</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts#L197">src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts:197</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts#L198">src/videoframeprocessor/DefaultVideoFrameProcessorPipeline.ts:198</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export default class DefaultVideoFrameProcessorPipeline implements VideoFramePro
this.inputVideoStream = inputMediaStream;
const settings = this.inputVideoStream.getVideoTracks()[0].getSettings();
this.logger.info(`processing pipeline input stream settings ${JSON.stringify(settings)}`);
this.framerate = settings.frameRate;
this.canvasOutput.width = settings.width;
this.canvasOutput.height = settings.height;
this.videoInput.addEventListener('loadedmetadata', this.process);
Expand Down
10 changes: 10 additions & 0 deletions test/dommock/DOMMockBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import UserMediaState from './UserMediaState';

export interface StoppableMediaStreamTrack extends MediaStreamTrack {
streamDeviceID: string | undefined;
framerate: number;

// This stops the track _and dispatches 'ended'_.
// https://stackoverflow.com/a/55960232
Expand All @@ -30,6 +31,9 @@ export interface StoppableMediaStreamTrack extends MediaStreamTrack {

// Tracks know their source device ID. This lets us fake it in tests.
setStreamDeviceID(id: string | undefined): void;

// Tracks know their framerate as a setting, this lets us fake it in tests.
setFramerate(framerate: number): void;
}

// eslint-disable-next-line
Expand Down Expand Up @@ -287,6 +291,7 @@ export default class DOMMockBuilder {
readyState: MediaStreamTrackState = 'live';

streamDeviceID = mockBehavior.mediaStreamTrackSettings?.deviceId || uuidv1();
framerate = 15;

readonly id: string;
readonly kind: string = '';
Expand Down Expand Up @@ -364,6 +369,10 @@ export default class DOMMockBuilder {
this.streamDeviceID = id;
}

setFramerate(framerate: number): void {
this.framerate = framerate;
}

// This stops the track _and dispatches 'ended'_.
// https://stackoverflow.com/a/55960232
externalStop(): void {
Expand Down Expand Up @@ -397,6 +406,7 @@ export default class DOMMockBuilder {
height: mockBehavior.mediaStreamTrackSettings.height,
facingMode: mockBehavior.mediaStreamTrackSettings.facingMode,
groupId: mockBehavior.mediaStreamTrackSettings.groupId,
frameRate: this.framerate,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import VideoFrameProcessor from '../../src/videoframeprocessor/VideoFrameProcess
import VideoFrameProcessorPipelineObserver from '../../src/videoframeprocessor/VideoFrameProcessorPipelineObserver';
import VideoFrameProcessorTimer from '../../src/videoframeprocessor/VideoFrameProcessorTimer';
import DOMMockBehavior from '../dommock/DOMMockBehavior';
import DOMMockBuilder from '../dommock/DOMMockBuilder';
import DOMMockBuilder, { StoppableMediaStreamTrack } from '../dommock/DOMMockBuilder';

/**
* [[MockVideoFrameProcessorTimer]] uses just `setTimeout` to avoid the complexity of
Expand All @@ -40,7 +40,7 @@ describe('DefaultVideoFrameProcessorPipeline', () => {
let domMockBehavior: DOMMockBehavior;
let domMockBuilder: DOMMockBuilder;
let mockVideoStream: MediaStream;
let mockVideoTrack: MediaStreamTrack;
let mockVideoTrack: StoppableMediaStreamTrack;
let proc: VideoFrameProcessor;
const mockTimer = new MockVideoFrameProcessorTimer();

Expand Down Expand Up @@ -73,8 +73,11 @@ describe('DefaultVideoFrameProcessorPipeline', () => {
mockVideoStream = new MediaStream();
// @ts-ignore
mockVideoStream.id = mockStreamId;
// @ts-ignore
mockVideoTrack = new MediaStreamTrack('attach-media-input-task-video-track-id', 'video');
mockVideoTrack = new MediaStreamTrack(
// @ts-ignore
'attach-media-input-task-video-track-id',
'video'
) as StoppableMediaStreamTrack;
mockVideoStream.addTrack(mockVideoTrack);
proc = new NoOpVideoFrameProcessor();
pipe = new DefaultVideoFrameProcessorPipeline(logger, [proc], mockTimer);
Expand Down
6 changes: 3 additions & 3 deletions test/videoframeprocessor/DefaultVideoTransformDevice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import VideoFxProcessor from '../../src/videofx/VideoFxProcessor';
import MockEngineWorker from '../../test/videofx/MockEngineWorker';
import MockFxLib from '../../test/videofx/MockFxLib';
import DOMMockBehavior from '../dommock/DOMMockBehavior';
import DOMMockBuilder from '../dommock/DOMMockBuilder';
import DOMMockBuilder, { StoppableMediaStreamTrack } from '../dommock/DOMMockBuilder';

describe('DefaultVideoTransformDevice', () => {
const assert: Chai.AssertStatic = chai.assert;
Expand All @@ -31,7 +31,7 @@ describe('DefaultVideoTransformDevice', () => {
let domMockBehavior: DOMMockBehavior;
let domMockBuilder: DOMMockBuilder;
let mockVideoStream: MediaStream;
let mockVideoTrack: MediaStreamTrack;
let mockVideoTrack: StoppableMediaStreamTrack;

class MockObserver implements DefaultVideoTransformDeviceObserver {
processingDidStart = sinon.stub();
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('DefaultVideoTransformDevice', () => {
// @ts-ignore
mockVideoStream.id = 'sample';
// @ts-ignore
mockVideoTrack = new MediaStreamTrack('test', 'video');
mockVideoTrack = new MediaStreamTrack('test', 'video') as StoppableMediaStreamTrack;
mockVideoStream.addTrack(mockVideoTrack);
});

Expand Down

0 comments on commit 1d7e425

Please sign in to comment.