Slide 1

Slide 1 text

Camera API で 何か FxOSコードリーディングミートアップ#11 2014/11/15

Slide 2

Slide 2 text

自己紹介 ひらとり ● @flatbirdH ● FxOS コードリーディング ● html5j Webプラットフォー ム部 (スタッフ)

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

なぜ Camera API?

Slide 5

Slide 5 text

Firefox OS 2.0 から Privileged API に!

Slide 6

Slide 6 text

アプリの権限 web (通常) ● ホスト型アプリ。 ● または、特権なしパッケージ型アプリ。 privileged (特権) ● パッケージ型アプリのみ。 ● Marketplace での審査が必要。 certified (認定) ● プレインストールアプリ(パッケージ型)。 ● 一般開発者は使えない。 権限によって使える API が異なる。

Slide 7

Slide 7 text

昔見たときのパーミッション FxOS 1.1 くらい? web alarms, fmradio, geolocation, storage, desktop- notification privileged browser, contacts, systemXHR, tcp-socket, device- storage:music, device-storage:videos, device-storage: pictures, device-storage:sdcard certified backgroundservice, bluetooth, camera, mobileconnection, power, settings, sms, systemclock, telephony, webapps-manage, wifi-manage

Slide 8

Slide 8 text

FxOS 1.1 くらい? web alarms, fmradio, geolocation, storage, desktop- notification privileged browser, contacts, systemXHR, tcp-socket, device- storage:music, device-storage:videos, device-storage: pictures, device-storage:sdcard certified backgroundservice, bluetooth, camera, mobileconnection, power, settings, sms, systemclock, telephony, webapps-manage, wifi-manage カメラも使えないのか、、、という衝撃 昔見たときのパーミッション

Slide 9

Slide 9 text

関西Firefox OS勉強会 3rd GIG

Slide 10

Slide 10 text

関西Firefox OS勉強会 3rd GIG

Slide 11

Slide 11 text

関東Firefox OS勉強会 7th

Slide 12

Slide 12 text

関東Firefox OS勉強会 7th

Slide 13

Slide 13 text

Privileged になった! 感慨深い。。。

Slide 14

Slide 14 text

Camera API を使わずカメラを使う ● 写真が欲しい場合 ○ Web Activities ● リアルタイムのカメラ画像 (ビデオスト リーム) が欲しい場合 ○ getUserMedia() ○ Firefox OS 1.4 以降 "video-capture" が 使えるように

Slide 15

Slide 15 text

Web Activities var activity = new MozActivity({ // Ask for the "pick" activity name: "pick", // Provide the data required by the filters of the activity data: { type: "image/jpeg" } }); activity.onsuccess = function() { var blob = this.result.blob; var img = document.querySelector('img'); img.src = window.URL.createObjectURL(blob); }; activity.onerror = function() { console.log(this.error); };

Slide 16

Slide 16 text

getUserMedia "permissions": { "video-capture": { "description": "Required to capture audio via getUserMedia" } }

Slide 17

Slide 17 text

getUserMedia navigator.getUserMedia = (navigator.getUserMedia || navigator.mozGetUserMedia); navigator.getUserMedia( // constraints { video: true, audio: false }, // successCallback function(stream) { var video = document.querySelector('video'); video.src = window.URL.createObjectURL(stream); video.play(); }, // errorCallback function(err) { console.log("The following error occured: " + err); } );

Slide 18

Slide 18 text

Camera API は どんなとき使うの?

Slide 19

Slide 19 text

Camera API を使う時 カメラアプリを作る時 Note: Except if you are implementing a replacement for the default Camera application, you shouldn't use this API. Instead, if you want to use the camera in your device, you should use the Web Activities API. https://developer.mozilla.org/docs/Web/API/Camera_API

Slide 20

Slide 20 text

Camera API で出来ること ● 写真撮影 … takePicture() ● プレビュー … getPreviewStream() ● 動画撮影 … startRecording() ● フォーカス … autoFocus(), focusAreas, etc. ● ズーム … zoom ● ホワイトバランス … whiteBalanceMode ● シーン … sceneMode ● フラッシュ … flashMode ● エフェクト … effect

Slide 21

Slide 21 text

Camera API の使い方

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

http://www.slideshare.net/chikoski/20141030-html5jfirefox-osdeviceapi/

Slide 24

Slide 24 text

http://www.slideshare.net/chikoski/20141030-html5jfirefox-osdeviceapi/

Slide 25

Slide 25 text

今日のコレはやんなくても よかったんじゃ...?

Slide 26

Slide 26 text

なので、 清水さんのスライドを 使わせていただきます

Slide 27

Slide 27 text

http://www.slideshare.net/chikoski/20141030-html5jfirefox-osdeviceapi/ “type”: “privileged”

Slide 28

Slide 28 text

http://www.slideshare.net/chikoski/20141030-html5jfirefox-osdeviceapi/ CameraControl [“back”, “front”] CameraManager

Slide 29

Slide 29 text

CameraControl ● 写真撮影 … takePicture() ● プレビュー … getPreviewStream() ● 動画撮影 … startRecording() ● フォーカス … autoFocus(), focusAreas, etc. ● ズーム … zoom ● ホワイトバランス … whiteBalanceMode ● シーン … sceneMode ● フラッシュ … flashMode ● エフェクト … effect

Slide 30

Slide 30 text

http://www.slideshare.net/chikoski/20141030-html5jfirefox-osdeviceapi/

Slide 31

Slide 31 text

http://www.slideshare.net/chikoski/20141030-html5jfirefox-osdeviceapi/

Slide 32

Slide 32 text

http://www.slideshare.net/chikoski/20141030-html5jfirefox-osdeviceapi/

Slide 33

Slide 33 text

http://www.slideshare.net/chikoski/20141030-html5jfirefox-osdeviceapi/

Slide 34

Slide 34 text

http://www.slideshare.net/chikoski/20141030-html5jfirefox-osdeviceapi/

Slide 35

Slide 35 text

Flame の CameraCapabilities “back” カメラ(=メインカメラ)

Slide 36

Slide 36 text

previewSizes: {"height":720,"width":1280},{"height":480,"width":864},{"height": 480,"width":800},{"height":432,"width":768},{"height":480,"width":720},{"height": 480,"width":640},{"height":432,"width":576},{"height":320,"width":480},{"height": 288,"width":384},{"height":288,"width":352},{"height":240,"width":320},{"height": 160,"width":240},{"height":144,"width":176},{"height":176,"width":144} pictureSizes: {"height":1944,"width":2592},{"height":1536,"width":2048},{"height": 1080,"width":1920},{"height":1200,"width":1600},{"height":768,"width":1280}, {"height":720,"width":1280},{"height":768,"width":1024},{"height":600,"width": 800},{"height":480,"width":800},{"height":480,"width":720},{"height":480,"width": 640},{"height":288,"width":352},{"height":240,"width":320},{"height":144,"width": 176} thumbnailSizes: {"height":480,"width":640},{"height":288,"width":512},{"height": 288,"width":480},{"height":154,"width":256},{"height":288,"width":432},{"height": 240,"width":320},{"height":144,"width":176},{"height":0,"width":0} videoSizes: {"height":720,"width":1280},{"height":480,"width":864},{"height":480," width":800},{"height":480,"width":720},{"height":480,"width":640},{"height":320," width":480},{"height":288,"width":352},{"height":240,"width":320},{"height":144," width":176}

Slide 37

Slide 37 text

fileFormats: "jpeg","bayer-mipi-10bggr","bayer-ideal-qcom-10bggr","bayer-qcom- 10bggr","yuv422sp" whiteBalanceModes: "auto","incandescent","fluorescent","warm-fluorescent"," daylight","cloudy-daylight","twilight","shade" sceneModes: "auto","asd","landscape","snow","beach","sunset","night","portrait"," backlight","sports","steadyphoto","flowers","candlelight","fireworks","party","night- portrait","theatre","action","AR","hdr" effects: "none","mono","negative","solarize","sepia","posterize","whiteboard"," blackboard","aqua" flashModes: "off","auto","on","torch" focusModes: "auto","infinity","macro","continuous-video","continuous-picture"

Slide 38

Slide 38 text

zoomRatios: 1,1.02,1.04,1.07,1.09,1.12,1.14,1.17,1.2,1.23,1.25,1.28,1.31,1.35,1.38,1.41,1.44,1.48,1.51,1. 55,1.58,1.62,1.66,1.7,1.74,1.78,1.82,1.86,1.9,1.95,2,2.04,2.09,2.14,2.19,2.24,2.29,2.35,2 .4,2.46,2.51,2.57,2.63,2.7,2.76,2.82,2.89,2.96,3.03,3.1,3.17,3.24,3.32,3.4,3.48,3.56,3.6 4,3.73,3.81,3.9,4,4.09,4.18,4.28,4.38,4.48,4.59,4.7,4.81,4.92,5.03,5.15,5.27,5.4,5.52,5. 65,5.78,5.92,6.06 maxFocusAreas: 1 maxMeteringAreas: 5 maxDetectedFaces: 5 minExposureCompensation: -2.0000039935112 maxExposureCompensation: 2.0000039935112 exposureCompensationStep: 0.16666699945926666

Slide 39

Slide 39 text

recorderProfiles: low:{"format":"3gp","video":{"codec":"h264","bitrate":192000,"framerate":30," width":176,"height":144},"audio":{"codec":"amrnb","bitrate":12200,"samplerate": 8000,"channels":1}}, high:{"format":"mp4","video":{"codec":"h264","bitrate":14000000,"framerate":30," width":1280,"height":720},"audio":{"codec":"aac","bitrate":156000,"samplerate": 48000,"channels":2}}, qcif:{"format":"3gp","video":{"codec":"h264","bitrate":192000,"framerate":30," width":176,"height":144},"audio":{"codec":"amrnb","bitrate":12200,"samplerate": 8000,"channels":1}}, cif:{"format":"3gp","video":{"codec":"h264","bitrate":720000,"framerate":30," width":352,"height":288},"audio":{"codec":"amrnb","bitrate":12200,"samplerate": 8000,"channels":1}}, 480p:{"format":"mp4","video":{"codec":"h264","bitrate":2000000,"framerate":30," width":720,"height":480},"audio":{"codec":"aac","bitrate":156000,"samplerate": 48000,"channels":2}}, 720p:{"format":"mp4","video":{"codec":"h264","bitrate":14000000,"framerate":30," width":1280,"height":720},"audio":{"codec":"aac","bitrate":156000,"samplerate": 48000,"channels":2}}, isoModes: "auto","hjr","100","200","400","800","1600"

Slide 40

Slide 40 text

Flame の CameraCapabilities “back” カメラ vs “front” カメラ

Slide 41

Slide 41 text

back front previewSizes 最大 720x1280 最大 480x640 pictureSizes 最大 1194x2592 最大 1200x1600 videoSizes 最大 720x1280 最大 480x640 fileFormats jpeg,bayer-mipi-10bggr,bayer-ideal-qcom-10bggr, bayer-qcom-10bggr,yuv422sp jpeg,yuv422sp sceneModes auto,asd,landscape,snow,beach,sunset,night, portrait,backlight,sports,steadyphoto,flowers, candlelight,fireworks,party,night-portrait,theatre, action,AR,hdr なし effects none,mono,negative,solarize,sepia,posterize, whiteboard,blackboard,aqua なし flashModes off,auto,on,torch なし focusModes auto,infinity,macro,continuous-video,continuous- picture fixed maxFocusAreas 1 0 recorderProfiles low(3gp),high(mp4),qcif(3gp),cif(3gp),480p (mp4),720p(mp4) low(3gp),qcif(3gp), cif(3gp)

Slide 42

Slide 42 text

おまけ

Slide 43

Slide 43 text

おまけ1 mozCamera? mozCameras? ● MDN のドキュメントは mozCamera と書いてあ るけど実際に取れるのは mozCameras ● mozCameras のほうには mozCamera に変 わったのでそっちを見ろと書いてある。 https://developer.mozilla.org/en-US/docs/Web/API/Navigator.mozCameras

Slide 44

Slide 44 text

WebIDL 見ても mozCameras http://mxr.mozilla.org/mozilla-b2g34_v2_1/source/dom/webidl/Navigator. webidl#280

Slide 45

Slide 45 text

おまけ2 フラッシュライトはできるのか? Bug 968119 - Need a privileged (not certified) API for accessing the camera's flash https://bugzilla.mozilla.org/show_bug.cgi?id=968119

Slide 46

Slide 46 text

できた var mode = flashON ? 'torch' : 'off'; var capabilities = mainCamera.capabilities; if (capabilities.flashModes.indexOf(mode) > -1) { mainCamera.flashMode = mode; console.log('flashMode=' + mainCamera.flashMode); }

Slide 47

Slide 47 text

おまけ3 Open Web Board につないだ Web カメラはどう見える?

Slide 48

Slide 48 text

おまけ3 Open Web Board につないだ Web カメラはどう見える? 近日公開

Slide 49

Slide 49 text

最後に

Slide 50

Slide 50 text

http://www.adventar.org/calendars/411

Slide 51

Slide 51 text

Thank you!