Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: examples/dart/camera_video/lib/main.dart

Issue 1375733004: -Add a mojo service to get video frames from the camera through an android service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: remove stale files. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This example makes use of mojo:camera which is available only when
6 // running on Android. It repeatedly captures camera video frame images
7 // and displays it in a mojo view.
8 //
9 // Example usage:
10 // pub get
11 // pub run sky_tools build
12 // pub run sky_tools run_mojo --mojo-path=../../.. --android
13
14 import 'dart:sky';
15 import 'dart:typed_data';
16
17 import 'package:mojo_services/mojo/camera.mojom.dart';
18 import 'package:sky/services.dart';
19
20 Image image = null;
21 final CameraVideoServiceProxy cameraRoll = new CameraVideoServiceProxy.unbound() ;
22
23 Picture paint(Rect paintBounds) {
24 PictureRecorder recorder = new PictureRecorder();
25 if (image != null) {
26 Canvas canvas = new Canvas(recorder, paintBounds);
27 canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
28 canvas.scale(0.3, 0.3);
29 Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0);
30 canvas.drawImage(image, new Point(-image.width / 2.0, -image.height / 2.0), paint);
31 }
32 return recorder.endRecording();
33 }
34
35 Scene composite(Picture picture, Rect paintBounds) {
36 final double devicePixelRatio = view.devicePixelRatio;
37 Rect sceneBounds = new Rect.fromLTWH(
38 0.0, 0.0, view.width * devicePixelRatio, view.height * devicePixelRatio);
39 Float32List deviceTransform = new Float32List(16)
40 ..[0] = devicePixelRatio
41 ..[5] = devicePixelRatio
42 ..[10] = 1.0
43 ..[15] = 1.0;
44 SceneBuilder sceneBuilder = new SceneBuilder(sceneBounds)
45 ..pushTransform(deviceTransform)
46 ..addPicture(Offset.zero, picture, paintBounds)
47 ..pop();
48 return sceneBuilder.build();
49 }
50
51 void beginFrame(double timeStamp) {
52 Rect paintBounds = new Rect.fromLTWH(0.0, 0.0, view.width, view.height);
53 Picture picture = paint(paintBounds);
54 Scene scene = composite(picture, paintBounds);
55 view.scene = scene;
56 }
57
58 void drawNextPhoto() {
59 var future = cameraRoll.ptr.getVideoFrames();
60 future.then((response) {
61 if (response.content == null) {
62 drawNextPhoto();
63 return;
64 }
65 new ImageDecoder(response.content.handle.h, (frame) {
66 if (frame != null) {
67 image = frame;
68 view.scheduleFrame();
69 drawNextPhoto();
70 }
71 });
72 });
73 }
74
75 void main() {
76 view.setFrameCallback(beginFrame);
77 embedder.connectToService("mojo:camera", cameraRoll);
78 drawNextPhoto();
79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698