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

Add frame_rate to flutter sdk #261

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion lib/src/components/camera/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ class CameraService extends CameraServiceBase {
Future<GetPropertiesResponse> getProperties(ServiceCall call, GetPropertiesRequest request) async {
final camera = _fromManager(request.name);
final properties = await camera.properties();
return GetPropertiesResponse()
final response = GetPropertiesResponse()
..supportsPcd = properties.supportsPcd
..intrinsicParameters = properties.intrinsicParameters
..distortionParameters = properties.distortionParameters;
if (properties.frameRate != 0) {
response.frameRate = properties.frameRate;
}
return response;
}

@override
Expand Down
72 changes: 66 additions & 6 deletions test/unit_test/components/camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class FakeCamera extends Camera {

@override
String name;
bool setFrameRate;

FakeCamera(this.name);
FakeCamera(this.name, {this.setFrameRate = false});

@override
Future<Map<String, dynamic>> doCommand(Map<String, dynamic> command) async {
Expand All @@ -40,20 +41,26 @@ class FakeCamera extends Camera {

@override
Future<CameraProperties> properties() async {
return CameraProperties()
final properties = CameraProperties()
..supportsPcd = true
..intrinsicParameters = (IntrinsicParameters()..widthPx = 10)
..distortionParameters = (DistortionParameters()..model = 'test');
if (setFrameRate) {
properties.frameRate = 10.0;
}
return properties;
}
}

void main() {
group('Camera Tests', () {
const String name = 'camera';
late FakeCamera camera;
late FakeCamera frameRateCamera;

setUp(() {
camera = FakeCamera(name);
frameRateCamera = FakeCamera(name, setFrameRate: true);
});

test('image', () async {
Expand All @@ -76,10 +83,18 @@ void main() {
expect(actualPcd.raw, [0, 0, 0]);
});

test('properties', () async {
test('properties without frame rate', () async {
final actual = await camera.properties();
expect(actual.distortionParameters.model, 'test');
expect(actual.intrinsicParameters.widthPx, 10);
expect(actual.frameRate, 0);
});

test('properties with frame rate', () async {
final actual = await frameRateCamera.properties();
expect(actual.distortionParameters.model, 'test');
expect(actual.intrinsicParameters.widthPx, 10);
expect(actual.frameRate, 10.0);
});

test('doCommand', () async {
Expand All @@ -97,7 +112,7 @@ void main() {
const String name = 'camera';

setUp(() async {
camera = FakeCamera(name);
camera = FakeCamera(name, setFrameRate: false);
final port = generateTestingPortFromName(name);
final manager = ResourceManager();
manager.register(Camera.getResourceName(name), camera);
Expand Down Expand Up @@ -148,11 +163,12 @@ void main() {
expect(actualPcd.pointCloud, [0, 0, 0]);
});

test('properties', () async {
test('properties without frameRate', () async {
final client = CameraServiceClient(channel);
final actual = await client.getProperties(GetPropertiesRequest()..name = name);
expect(actual.distortionParameters.model, 'test');
expect(actual.intrinsicParameters.widthPx, 10);
expect(actual.frameRate, 0);
});

test('doCommand', () async {
Expand Down Expand Up @@ -187,11 +203,12 @@ void main() {
expect(actualPcd.raw, [0, 0, 0]);
});

test('properties', () async {
test('properties without frame rate', () async {
final client = CameraClient(name, channel);
final actual = await client.properties();
expect(actual.distortionParameters.model, 'test');
expect(actual.intrinsicParameters.widthPx, 10);
expect(actual.frameRate, 0.0);
});

test('doCommand', () async {
Expand All @@ -202,4 +219,47 @@ void main() {
});
});
});

group('Camera RPC Tests with frame rate', () {
late ClientChannel channel;
late FakeCamera camera;
late CameraService service;
late Server server;
const String name = 'camera';

setUp(() async {
camera = FakeCamera(name, setFrameRate: true);
final port = generateTestingPortFromName(name);
final manager = ResourceManager();
manager.register(Camera.getResourceName(name), camera);
service = CameraService(manager);
channel = ClientChannel('localhost', port: port, options: const ChannelOptions(credentials: ChannelCredentials.insecure()));
server = Server.create(services: [service]);
await server.serve(port: port);
});

tearDown(() async {
await channel.shutdown();
await server.shutdown();
});

group('Camera Service Tests', () {
test('properties with frameRate', () async {
final client = CameraServiceClient(channel);
final actual = await client.getProperties(GetPropertiesRequest()..name = name);
expect(actual.distortionParameters.model, 'test');
expect(actual.intrinsicParameters.widthPx, 10);
expect(actual.frameRate, 10.0);
});
});
group('Camera Client Tests', () {
test('properties with frameRate', () async {
final client = CameraClient(name, channel);
final actual = await client.properties();
expect(actual.distortionParameters.model, 'test');
expect(actual.intrinsicParameters.widthPx, 10);
expect(actual.frameRate, 10.0);
});
});
});
}
Loading