SlideShare a Scribd company logo
Camera2 API: Overview
Shift (Suhyun Park)
Android Camera API existed
since version 1.0 (API 1)
* only ‘major’ feature added in
Camera2 API (android.hardware.camera2)
- Introduced in Lollipop 5.0 (API 21) / Nov. 12, 2014: almost 4 years ago
- New devices can use both Camera2 API (android.hardware.camera2) and
deprecated Camera API (android.hardware.camera)
- To reduce confusion, we’ll call the deprecated one as ‘Camera1’
What Camera2 can do while Camera1 can’t
- Accessing to 3+ cameras
(hopefully at once, for P 9.0 (API
28) or higher)
- DSLR-like manual controls (ISO,
exposure time, lens focus
distance, white balance, etc.)
© LGE
© LGE
What Camera2 can do while Camera1 can’t
- Burst mode
- RAW support
- etc.
© Google
Example use of Camera2
- Portrait mode
Open 2 cameras
simultaneously, outfocus
one of them and process
image
© Google
… but do they?
Vendors
They don’t really care about
Camera2
Vendors
… or they care so much about Camera2 that they don’t care about the
deprecated one
Fragmentation
- Some vendors even has their own
SDKs (it’s usable on other
vendors’ devices, hopefully)
© Samsung
So is it worth using?
- Camera1 is deprecated
- Camera2 has some serious professional features for a camera app, and it’s
generally way faster compared to Camera1 when implemented right
- API 21+ (>87%, as of July 2018) can benefit from it
- But we have to make 2 logics (for devices not fully supporting and/or
acting strange on Camera2)
Dealing with it
: Technical Aspect
© Google
© Google
The pipeline
- It takes a whole new
pipeline (“completely
reworked” according to
Google)
- Everything is asynchronous
© Google
The pipeline
CameraManager
- is a system service
- is used to query available
cameras and features
- is a starting point of
Camera2
© Google
The pipeline
CameraCharacteristics
- is a map of the camera’s
characteristics
- Used like this:
characteristics[CameraChar
acteristics.LENS_FACING]
© Google
The pipeline
CameraCharacteristics
- is NOT equivalent to
Camera1’s properties
© Google
The pipeline
CameraDevice
- is the camera device
- unlike Camera1, it is got
asynchronously using
CameraManager and a
callback
© Google
The pipeline
CaptureRequest
- is used to control camera
parameters, and request for
preview or image capture
© Google
The pipeline
CameraCaptureSession
- is used to send requests
and receive results from/to
the hardware
© Google
© Google
The pipeline
Notice this? we can specify
multiple surface outputs! - this
was not possible in Camera1
© Google
The pipeline
But the aspect ratio has to be
same across all sizes
(at least to support Galaxy
devices)
The pipeline
Example CaptureRequest for camera previewing
// Preview request is built with builder pattern
previewRequestBuilder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW) ?: return
// We can set multiple targets, i.e. show multiple previews
previewRequestBuilder.addTarget(Surface(imageTexture))
// Setting camera preferences
previewRequestBuilder[CaptureRequest.CONTROL_AF_MODE] = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
previewRequestBuilder[CaptureRequest.FLASH_MODE] = CaptureRequest.FLASH_MODE_OFF
previewRequest = previewRequestBuilder.build()
// Sending a PreviewRequest to current camera session
// The session will handle given PreviewRequest appropriately
captureSession?.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler)
The pipeline
Notice the backgroundHandler?
the API manages all the background stuff for us
// Preview request is built with builder pattern
previewRequestBuilder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW) ?: return
// We can set multiple targets, i.e. show multiple previews
previewRequestBuilder.addTarget(Surface(imageTexture))
// Setting camera preferences
previewRequestBuilder[CaptureRequest.CONTROL_AF_MODE] = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
previewRequestBuilder[CaptureRequest.FLASH_MODE] = CaptureRequest.FLASH_MODE_OFF
previewRequest = previewRequestBuilder.build()
// Sending a PreviewRequest to current camera session
// The session will handle given PreviewRequest appropriately
captureSession?.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler)
Find the Difference
: Differences Between Camera1 and 2
Setting Up Preview / Connecting to Surface
camera = Camera.open(id) // This is the camera val callback = object: CameraDevice.StateCallback() {
override fun onOpened(camera: CameraDevice?) {
cameraDevice = camera // This is the cameraDevice
}
...
}
cameraManager.openCamera(id, callback, backgroundHandler)
Straightforward, is blocking current thread Gets device by callback, does its job by backgroundHandler
Setting Up Preview / Connecting to Surface
(camera ?: return).let {
it.setPreviewTexture(imageTexture)
// or you can do
// it.setPreviewDisplay(surfaceHolder)
it.startPreview()
}
val surface = Surface(imageTexture)
previewRequestBuilder = cameraDevice!!
.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
previewRequestBuilder.addTarget(surface)
cameraDevice!!.createCaptureSession(
listOf(surface, imageReader!!.surface),
object : CameraCaptureSession.StateCallback() {
override fun onConfigured(
session: CameraCaptureSession?) {
captureSession = session // This is the session
previewRequest = previewRequestBuilder.build()
captureSession?
.setRepeatingRequest(previewRequest, captureCallback,
backgroundHandler)
}
...
}
}, backgroundHandler)
Again, straightforward, is blocking current thread.
We have to manually set preview size to match
the surface’s size.
Gets session by callback, and we can start preview by calling
setRepeatingRequest.
Preview size is automatically chosen by the API to match the surface size.
Properties vs. CameraCharacteristics
Properties (Camera1)
- Mixed mutable/immutable properties
- things like previewSize are mutable;
things like supportedPreviewSizes are not
- You CAN call camera.setProperties() to
update camera settings
- You NEED to open a camera to use this
CameraCharacteristics (Camera2)
- Immutable properties only
- like the name says, you can only get the
characteristics of a CameraDevice
- You CAN’T update camera settings with
this class; it’s used only for checking
device features
- You DON’T NEED to open a camera
Querying Features
camera!!.parameters!!.supportedFlashModes cameraManager
.getCameraCharacteristics(cameraId)
.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)
Can query features by accessing
Camera.Parameters
Need to open camera before querying
Can query features by CameraCharacteristics, using cameraId (not
cameraDevice) so no need to open cameraDevice
Setting Parameters
camera!!.parameters = camera!!.parameters.apply {
flashMode = Camera.Parameters.FLASH_MODE_ON
zoom = 125 // Sets zoom to x1.25, if supported
}
previewRequestBuilder[CaptureRequest.LENS_FOCUS_DISTANCE] = 9.50f
previewRequestBuilder[CaptureRequest.SENSOR_EXPOSURE_TIME] = 1000000000L / 30
previewRequest = previewRequestBuilder.build()
captureSession?.stopRepeating()
captureSession?.setRepeatingRequest(previewRequest, captureCallback,
backgroundHandler)
Sets parameters directly
When given unsupported values, it’ll throw an
error
Sets parameters by builder pattern
When given unsupported values, it’ll try its best to fit into supported values,
by rounding or clamping, etc
Setting Parameters
camera!!.parameters = camera!!.parameters.apply {
flashMode = Camera.Parameters.FLASH_MODE_ON
zoom = 125 // Sets zoom to x1.25, if supported
}
private fun <T> setPreviewOptions(
vararg options: Pair<CaptureRequest.Key<in T>, T>,
postProcess: () -> Unit = {}) {
for (option in options) {
previewRequestBuilder[option.first] = option.second
}
postProcess()
previewRequest = previewRequestBuilder.build()
captureSession?.stopRepeating()
captureSession?.setRepeatingRequest(
previewRequest, captureCallback, backgroundHandler)
}
...
setPreivewOptions(
CaptureRequest.LENS_FOCUS_DISTANCE to 9.50f,
CaptureRequest.SENSOR_EXPOSURE_TIME to 1000000000L / 30
)
Sets parameters directly
When given unsupported values, it’ll throw an
error
We can make an extension function to simplify this
Setting Parameters
camera!!.parameters = camera!!.parameters.apply {
flashMode = Camera.Parameters.FLASH_MODE_ON
zoom = 125 // Sets zoom to x1.25, if supported
}
It can be rather frustrating because only some
specific values are supported by the camera, so if I
request x1.25, the app will likely to crash on
Galaxy S9+
But Camera2 handles similar cases appropriately -
like what would we expect
Example supported zoom ratios (by Samsung Galaxy S9+ Camera)
Check out my Camera1-based OSP here :
https://github.com/shiftpsh/sensor-tester/releases
Setting parameters in Camera1 vs. 2
Camera1
- Parameters are global
- If we want to make a change, then it’s
changed globally. But since image
processing takes time, the API waits until
last image finishes processing and finally
change the settings
Camera2
- Parameters are set per request
- Image processing stages gets parameters
per request - the API don’t have to care
about the last image or whatsoever,
resulting improved frame rates
Setting parameters in Camera1
1234567
processing stages
request
params A
params B
current params: A
result
Setting parameters in Camera1
1234567
processing stages
request
params A
params B
If we change settings... It get mixed
current params: B
result
Setting parameters in Camera1
1222223
processing stages
request
params A
params B
current params: A
So Camera1 does this way … one by one
result
Setting parameters in Camera2
1 / A2 / A3 / A4 / B5 / B6 / B7 / B
processing stages
request
params A
params B
But in Camera2, parameters are baked into the requests
result
Setting parameters in Camera1 vs. 2
Camera1
Camera2
result
… resulting much higher speed
© Google
© Google
Taking Pictures
camera!!.takePicture(null, null) { bytes, _ ->
process(bytes)
}
imageReader = ImageReader.newInstance(largestSize.width, largestSize.height,
ImageFormat.JPEG, 2)
val onImageAvailableListener = ImageReader.OnImageAvailableListener { reader ->
process(image)
}
imageReader!!.setOnImageAvailableListener(
onImageAvailableListener, backgroundHandler)
val captureBuilder = cameraDevice!!
.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE)
captureBuilder.addTarget(imageReader!!.surface)
...
val captureCallback = object : CameraCaptureSession.CaptureCallback() {
override fun onCaptureCompleted(...) {...}
}
captureSession?.stopRepeating()
captureSession?.abortCaptures()
captureSession?.capture(
captureBuilder.build(), captureCallback, backgroundHandler)
One of the few functions that uses a callback.
Returns a ByteArray - RGB format
It uses an imageReader to capture image. Also uses a callback.
Returns an Image - YUV format (typically)
Implementing it in existing apps
API may be different but the flow is same
Open Camera Connect to Surface
Start Preview /
Repeating Request
Apply Filter, etc..
Capture Image
Close Camera
Speed comparison
Device Camera1 Camera2 Improvement
Google Pixel 2 (9) 87.7ms 35.1ms 150%
Samsung Galaxy S9+ (8.0) 71.7ms 27.9ms 157%
LG G7 ThinQ (8.0) 37.3ms 11.5ms 224%
Opening the camera
* Averaged result of 10 runs
Speed comparison
Device Camera1 Camera2 Improvement
Google Pixel 2 (9) 810.3ms 406.2ms 99%
Samsung Galaxy S9+ (8.0) 477.2ms 351.1ms 36%
LG G7 ThinQ (8.0) 616.4ms 382.9ms 61%
Taking a single full resolution picture
* Averaged result of 10 runs, right after callback
Migration Strategy
- Not all devices work well with Camera2, even if its API level ≥ 21
- It’s up to vendors - if they wrote good enough HAL(hardware abstraction
layer) for Camera2 then it’ll work well, otherwise not
Migration Strategy
- We can test some devices if they supports
Camera2 well and make a whitelist
- Or we can ask our users to opt-in, like
putting an option to enable advanced
camera in ‘experimental’ section like many
other apps do
Q&A

More Related Content

What's hot

모바일 게임 테스트 자동화 (Appium 확장)
모바일 게임 테스트 자동화 (Appium 확장)모바일 게임 테스트 자동화 (Appium 확장)
모바일 게임 테스트 자동화 (Appium 확장)
Jongwon Kim
 
[1023 박민수] 깊이_버퍼_그림자_1
[1023 박민수] 깊이_버퍼_그림자_1[1023 박민수] 깊이_버퍼_그림자_1
[1023 박민수] 깊이_버퍼_그림자_1MoonLightMS
 
Firebase on Android: The Big Picture
Firebase on Android: The Big PictureFirebase on Android: The Big Picture
Firebase on Android: The Big Picture
Sriyank Siddhartha
 
Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019
Unity Technologies
 
개발이 테스트를 만났을 때(Shift left testing)
개발이 테스트를 만났을 때(Shift left testing)개발이 테스트를 만났을 때(Shift left testing)
개발이 테스트를 만났을 때(Shift left testing)
SangIn Choung
 
Opencv
OpencvOpencv
Opencv
Procheta Nag
 
Android camera basics
Android camera basicsAndroid camera basics
Android camera basics
Choulhyouc Lee
 
IndirectDraw with unity
IndirectDraw with unityIndirectDraw with unity
IndirectDraw with unity
Jung Suk Ko
 
영웅의 군단의 테크니컬 아트 - 황재철, 유나이트 코리아 2014
영웅의 군단의 테크니컬 아트 - 황재철, 유나이트 코리아 2014영웅의 군단의 테크니컬 아트 - 황재철, 유나이트 코리아 2014
영웅의 군단의 테크니컬 아트 - 황재철, 유나이트 코리아 2014
NDOORS
 
OpenCV presentation series- part 1
OpenCV presentation series- part 1OpenCV presentation series- part 1
OpenCV presentation series- part 1
Sairam Adithya
 
Understaing Android EGL
Understaing Android EGLUnderstaing Android EGL
Understaing Android EGL
Suhan Lee
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glchangehee lee
 
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
현철 조
 
Exoplayer 2
Exoplayer  2Exoplayer  2
Exoplayer 2
TSE-JU LIN(Louis)
 
Unity3D Programming
Unity3D ProgrammingUnity3D Programming
Unity3D Programming
Michael Ivanov
 
Unreal Engine (For Creating Games) Presentation
Unreal Engine (For Creating Games) PresentationUnreal Engine (For Creating Games) Presentation
Unreal Engine (For Creating Games) Presentation
Nitin Sharma
 
katalon studio 툴을 이용한 GUI 테스트 자동화 가이드
katalon studio 툴을 이용한 GUI 테스트 자동화 가이드katalon studio 툴을 이용한 GUI 테스트 자동화 가이드
katalon studio 툴을 이용한 GUI 테스트 자동화 가이드
SangIn Choung
 
Getting started with Ray Tracing in Unity 2019.3 - Unite Copenhagen 2019
Getting started with Ray Tracing in Unity 2019.3 - Unite Copenhagen 2019Getting started with Ray Tracing in Unity 2019.3 - Unite Copenhagen 2019
Getting started with Ray Tracing in Unity 2019.3 - Unite Copenhagen 2019
Unity Technologies
 
유니티의 툰셰이딩을 사용한 3D 애니메이션 표현
유니티의 툰셰이딩을 사용한 3D 애니메이션 표현유니티의 툰셰이딩을 사용한 3D 애니메이션 표현
유니티의 툰셰이딩을 사용한 3D 애니메이션 표현
MinGeun Park
 
NDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdf
NDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdfNDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdf
NDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdf
Jongwon Kim
 

What's hot (20)

모바일 게임 테스트 자동화 (Appium 확장)
모바일 게임 테스트 자동화 (Appium 확장)모바일 게임 테스트 자동화 (Appium 확장)
모바일 게임 테스트 자동화 (Appium 확장)
 
[1023 박민수] 깊이_버퍼_그림자_1
[1023 박민수] 깊이_버퍼_그림자_1[1023 박민수] 깊이_버퍼_그림자_1
[1023 박민수] 깊이_버퍼_그림자_1
 
Firebase on Android: The Big Picture
Firebase on Android: The Big PictureFirebase on Android: The Big Picture
Firebase on Android: The Big Picture
 
Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019
 
개발이 테스트를 만났을 때(Shift left testing)
개발이 테스트를 만났을 때(Shift left testing)개발이 테스트를 만났을 때(Shift left testing)
개발이 테스트를 만났을 때(Shift left testing)
 
Opencv
OpencvOpencv
Opencv
 
Android camera basics
Android camera basicsAndroid camera basics
Android camera basics
 
IndirectDraw with unity
IndirectDraw with unityIndirectDraw with unity
IndirectDraw with unity
 
영웅의 군단의 테크니컬 아트 - 황재철, 유나이트 코리아 2014
영웅의 군단의 테크니컬 아트 - 황재철, 유나이트 코리아 2014영웅의 군단의 테크니컬 아트 - 황재철, 유나이트 코리아 2014
영웅의 군단의 테크니컬 아트 - 황재철, 유나이트 코리아 2014
 
OpenCV presentation series- part 1
OpenCV presentation series- part 1OpenCV presentation series- part 1
OpenCV presentation series- part 1
 
Understaing Android EGL
Understaing Android EGLUnderstaing Android EGL
Understaing Android EGL
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_gl
 
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
[NDC17] Unreal.js - 자바스크립트로 쉽고 빠른 UE4 개발하기
 
Exoplayer 2
Exoplayer  2Exoplayer  2
Exoplayer 2
 
Unity3D Programming
Unity3D ProgrammingUnity3D Programming
Unity3D Programming
 
Unreal Engine (For Creating Games) Presentation
Unreal Engine (For Creating Games) PresentationUnreal Engine (For Creating Games) Presentation
Unreal Engine (For Creating Games) Presentation
 
katalon studio 툴을 이용한 GUI 테스트 자동화 가이드
katalon studio 툴을 이용한 GUI 테스트 자동화 가이드katalon studio 툴을 이용한 GUI 테스트 자동화 가이드
katalon studio 툴을 이용한 GUI 테스트 자동화 가이드
 
Getting started with Ray Tracing in Unity 2019.3 - Unite Copenhagen 2019
Getting started with Ray Tracing in Unity 2019.3 - Unite Copenhagen 2019Getting started with Ray Tracing in Unity 2019.3 - Unite Copenhagen 2019
Getting started with Ray Tracing in Unity 2019.3 - Unite Copenhagen 2019
 
유니티의 툰셰이딩을 사용한 3D 애니메이션 표현
유니티의 툰셰이딩을 사용한 3D 애니메이션 표현유니티의 툰셰이딩을 사용한 3D 애니메이션 표현
유니티의 툰셰이딩을 사용한 3D 애니메이션 표현
 
NDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdf
NDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdfNDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdf
NDC21_게임테스트자동화5년의기록_NCSOFT_김종원.pdf
 

Similar to Camera2 API: Overview

Droidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera ApplicationsDroidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera Applications
Huyen Dao
 
Droidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera ApplicationsDroidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera Applications
Huyen Tue Dao
 
Camera
CameraCamera
Android RuntimePermissionsExtended
Android RuntimePermissionsExtendedAndroid RuntimePermissionsExtended
Android RuntimePermissionsExtended
Nebojša Vukšić
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blink
InnovationM
 
Building a Native Camera Access Library - Part IV - Transcript.pdf
Building a Native Camera Access Library - Part IV - Transcript.pdfBuilding a Native Camera Access Library - Part IV - Transcript.pdf
Building a Native Camera Access Library - Part IV - Transcript.pdf
ShaiAlmog1
 
How to create a camera2
How to create a camera2How to create a camera2
How to create a camera2
Booch Lin
 
Exploring CameraX from JetPack
Exploring CameraX from JetPackExploring CameraX from JetPack
Exploring CameraX from JetPack
Hassan Abid
 
Introduction of Android Camera1
Introduction of Android Camera1Introduction of Android Camera1
Introduction of Android Camera1
Booch Lin
 
Android camera2
Android camera2Android camera2
Android camera2
Takuma Lee
 
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
How React Native, Appium and me made each other shine @Frontmania 16-11-2018How React Native, Appium and me made each other shine @Frontmania 16-11-2018
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
Wim Selles
 
Building a Native Camera Access Library - Part V - Transcript.pdf
Building a Native Camera Access Library - Part V - Transcript.pdfBuilding a Native Camera Access Library - Part V - Transcript.pdf
Building a Native Camera Access Library - Part V - Transcript.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XLIII - Transcript.pdf
Creating a Facebook Clone - Part XLIII - Transcript.pdfCreating a Facebook Clone - Part XLIII - Transcript.pdf
Creating a Facebook Clone - Part XLIII - Transcript.pdf
ShaiAlmog1
 
Building a Native Camera Access Library - Part II - Transcript.pdf
Building a Native Camera Access Library - Part II - Transcript.pdfBuilding a Native Camera Access Library - Part II - Transcript.pdf
Building a Native Camera Access Library - Part II - Transcript.pdf
ShaiAlmog1
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.js
Josh Staples
 
QXCameraKit
QXCameraKitQXCameraKit
QXCameraKit
Hirakawa Akira
 
Android Lab Test : Using the camera preview (english)
Android Lab Test : Using the camera preview (english)Android Lab Test : Using the camera preview (english)
Android Lab Test : Using the camera preview (english)
Bruno Delb
 
Mopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKitMopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKit
anistar sung
 
Google Fit, Android Wear & Xamarin
Google Fit, Android Wear & XamarinGoogle Fit, Android Wear & Xamarin
Google Fit, Android Wear & Xamarin
Peter Friese
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
OdessaJS Conf
 

Similar to Camera2 API: Overview (20)

Droidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera ApplicationsDroidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera Applications
 
Droidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera ApplicationsDroidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera Applications
 
Camera
CameraCamera
Camera
 
Android RuntimePermissionsExtended
Android RuntimePermissionsExtendedAndroid RuntimePermissionsExtended
Android RuntimePermissionsExtended
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blink
 
Building a Native Camera Access Library - Part IV - Transcript.pdf
Building a Native Camera Access Library - Part IV - Transcript.pdfBuilding a Native Camera Access Library - Part IV - Transcript.pdf
Building a Native Camera Access Library - Part IV - Transcript.pdf
 
How to create a camera2
How to create a camera2How to create a camera2
How to create a camera2
 
Exploring CameraX from JetPack
Exploring CameraX from JetPackExploring CameraX from JetPack
Exploring CameraX from JetPack
 
Introduction of Android Camera1
Introduction of Android Camera1Introduction of Android Camera1
Introduction of Android Camera1
 
Android camera2
Android camera2Android camera2
Android camera2
 
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
How React Native, Appium and me made each other shine @Frontmania 16-11-2018How React Native, Appium and me made each other shine @Frontmania 16-11-2018
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
 
Building a Native Camera Access Library - Part V - Transcript.pdf
Building a Native Camera Access Library - Part V - Transcript.pdfBuilding a Native Camera Access Library - Part V - Transcript.pdf
Building a Native Camera Access Library - Part V - Transcript.pdf
 
Creating a Facebook Clone - Part XLIII - Transcript.pdf
Creating a Facebook Clone - Part XLIII - Transcript.pdfCreating a Facebook Clone - Part XLIII - Transcript.pdf
Creating a Facebook Clone - Part XLIII - Transcript.pdf
 
Building a Native Camera Access Library - Part II - Transcript.pdf
Building a Native Camera Access Library - Part II - Transcript.pdfBuilding a Native Camera Access Library - Part II - Transcript.pdf
Building a Native Camera Access Library - Part II - Transcript.pdf
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.js
 
QXCameraKit
QXCameraKitQXCameraKit
QXCameraKit
 
Android Lab Test : Using the camera preview (english)
Android Lab Test : Using the camera preview (english)Android Lab Test : Using the camera preview (english)
Android Lab Test : Using the camera preview (english)
 
Mopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKitMopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKit
 
Google Fit, Android Wear & Xamarin
Google Fit, Android Wear & XamarinGoogle Fit, Android Wear & Xamarin
Google Fit, Android Wear & Xamarin
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
 

More from Suhyun Park

코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)
코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)
코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)
Suhyun Park
 
정수론적 알고리즘 - Sogang ICPC Team, 2020 Winter
정수론적 알고리즘 - Sogang ICPC Team, 2020 Winter정수론적 알고리즘 - Sogang ICPC Team, 2020 Winter
정수론적 알고리즘 - Sogang ICPC Team, 2020 Winter
Suhyun Park
 
게임 필승법과 Sprague–Grundy 정리 - Sogang ICPC Team, 2020 Winter
게임 필승법과 Sprague–Grundy 정리 - Sogang ICPC Team, 2020 Winter게임 필승법과 Sprague–Grundy 정리 - Sogang ICPC Team, 2020 Winter
게임 필승법과 Sprague–Grundy 정리 - Sogang ICPC Team, 2020 Winter
Suhyun Park
 
퍼시스턴트 세그먼트 트리 - Sogang ICPC Team, 2020 Winter
퍼시스턴트 세그먼트 트리 - Sogang ICPC Team, 2020 Winter퍼시스턴트 세그먼트 트리 - Sogang ICPC Team, 2020 Winter
퍼시스턴트 세그먼트 트리 - Sogang ICPC Team, 2020 Winter
Suhyun Park
 
세그먼트 트리 느리게 업데이트하기 - Sogang ICPC Team, 2020 Winter
세그먼트 트리 느리게 업데이트하기 - Sogang ICPC Team, 2020 Winter세그먼트 트리 느리게 업데이트하기 - Sogang ICPC Team, 2020 Winter
세그먼트 트리 느리게 업데이트하기 - Sogang ICPC Team, 2020 Winter
Suhyun Park
 
Persistent Segment Tree - Sogang ICPC Team, 2019
Persistent Segment Tree - Sogang ICPC Team, 2019Persistent Segment Tree - Sogang ICPC Team, 2019
Persistent Segment Tree - Sogang ICPC Team, 2019
Suhyun Park
 
Heavy-Light Decomposition - Sogang ICPC Team, 2019
Heavy-Light Decomposition - Sogang ICPC Team, 2019Heavy-Light Decomposition - Sogang ICPC Team, 2019
Heavy-Light Decomposition - Sogang ICPC Team, 2019
Suhyun Park
 
Fast Fourier Transform - Sogang ICPC Team, 2019
Fast Fourier Transform - Sogang ICPC Team, 2019Fast Fourier Transform - Sogang ICPC Team, 2019
Fast Fourier Transform - Sogang ICPC Team, 2019
Suhyun Park
 
Centroid Decomposition - Sogang ICPC Team, 2019
Centroid Decomposition - Sogang ICPC Team, 2019Centroid Decomposition - Sogang ICPC Team, 2019
Centroid Decomposition - Sogang ICPC Team, 2019
Suhyun Park
 
Lazy Propagation on Segment Trees - Sogang ICPC Team, 2019
Lazy Propagation on Segment Trees - Sogang ICPC Team, 2019Lazy Propagation on Segment Trees - Sogang ICPC Team, 2019
Lazy Propagation on Segment Trees - Sogang ICPC Team, 2019
Suhyun Park
 

More from Suhyun Park (10)

코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)
코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)
코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)
 
정수론적 알고리즘 - Sogang ICPC Team, 2020 Winter
정수론적 알고리즘 - Sogang ICPC Team, 2020 Winter정수론적 알고리즘 - Sogang ICPC Team, 2020 Winter
정수론적 알고리즘 - Sogang ICPC Team, 2020 Winter
 
게임 필승법과 Sprague–Grundy 정리 - Sogang ICPC Team, 2020 Winter
게임 필승법과 Sprague–Grundy 정리 - Sogang ICPC Team, 2020 Winter게임 필승법과 Sprague–Grundy 정리 - Sogang ICPC Team, 2020 Winter
게임 필승법과 Sprague–Grundy 정리 - Sogang ICPC Team, 2020 Winter
 
퍼시스턴트 세그먼트 트리 - Sogang ICPC Team, 2020 Winter
퍼시스턴트 세그먼트 트리 - Sogang ICPC Team, 2020 Winter퍼시스턴트 세그먼트 트리 - Sogang ICPC Team, 2020 Winter
퍼시스턴트 세그먼트 트리 - Sogang ICPC Team, 2020 Winter
 
세그먼트 트리 느리게 업데이트하기 - Sogang ICPC Team, 2020 Winter
세그먼트 트리 느리게 업데이트하기 - Sogang ICPC Team, 2020 Winter세그먼트 트리 느리게 업데이트하기 - Sogang ICPC Team, 2020 Winter
세그먼트 트리 느리게 업데이트하기 - Sogang ICPC Team, 2020 Winter
 
Persistent Segment Tree - Sogang ICPC Team, 2019
Persistent Segment Tree - Sogang ICPC Team, 2019Persistent Segment Tree - Sogang ICPC Team, 2019
Persistent Segment Tree - Sogang ICPC Team, 2019
 
Heavy-Light Decomposition - Sogang ICPC Team, 2019
Heavy-Light Decomposition - Sogang ICPC Team, 2019Heavy-Light Decomposition - Sogang ICPC Team, 2019
Heavy-Light Decomposition - Sogang ICPC Team, 2019
 
Fast Fourier Transform - Sogang ICPC Team, 2019
Fast Fourier Transform - Sogang ICPC Team, 2019Fast Fourier Transform - Sogang ICPC Team, 2019
Fast Fourier Transform - Sogang ICPC Team, 2019
 
Centroid Decomposition - Sogang ICPC Team, 2019
Centroid Decomposition - Sogang ICPC Team, 2019Centroid Decomposition - Sogang ICPC Team, 2019
Centroid Decomposition - Sogang ICPC Team, 2019
 
Lazy Propagation on Segment Trees - Sogang ICPC Team, 2019
Lazy Propagation on Segment Trees - Sogang ICPC Team, 2019Lazy Propagation on Segment Trees - Sogang ICPC Team, 2019
Lazy Propagation on Segment Trees - Sogang ICPC Team, 2019
 

Recently uploaded

GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
Google
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 

Recently uploaded (20)

GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 

Camera2 API: Overview

  • 2. Android Camera API existed since version 1.0 (API 1)
  • 3.
  • 4. * only ‘major’ feature added in
  • 5. Camera2 API (android.hardware.camera2) - Introduced in Lollipop 5.0 (API 21) / Nov. 12, 2014: almost 4 years ago - New devices can use both Camera2 API (android.hardware.camera2) and deprecated Camera API (android.hardware.camera) - To reduce confusion, we’ll call the deprecated one as ‘Camera1’
  • 6. What Camera2 can do while Camera1 can’t - Accessing to 3+ cameras (hopefully at once, for P 9.0 (API 28) or higher) - DSLR-like manual controls (ISO, exposure time, lens focus distance, white balance, etc.) © LGE © LGE
  • 7.
  • 8. What Camera2 can do while Camera1 can’t - Burst mode - RAW support - etc. © Google
  • 9. Example use of Camera2 - Portrait mode Open 2 cameras simultaneously, outfocus one of them and process image © Google
  • 10. … but do they?
  • 11. Vendors They don’t really care about Camera2
  • 12. Vendors … or they care so much about Camera2 that they don’t care about the deprecated one
  • 13. Fragmentation - Some vendors even has their own SDKs (it’s usable on other vendors’ devices, hopefully) © Samsung
  • 14.
  • 15. So is it worth using? - Camera1 is deprecated - Camera2 has some serious professional features for a camera app, and it’s generally way faster compared to Camera1 when implemented right - API 21+ (>87%, as of July 2018) can benefit from it - But we have to make 2 logics (for devices not fully supporting and/or acting strange on Camera2)
  • 16. Dealing with it : Technical Aspect
  • 19. The pipeline - It takes a whole new pipeline (“completely reworked” according to Google) - Everything is asynchronous © Google
  • 20. The pipeline CameraManager - is a system service - is used to query available cameras and features - is a starting point of Camera2 © Google
  • 21. The pipeline CameraCharacteristics - is a map of the camera’s characteristics - Used like this: characteristics[CameraChar acteristics.LENS_FACING] © Google
  • 22. The pipeline CameraCharacteristics - is NOT equivalent to Camera1’s properties © Google
  • 23. The pipeline CameraDevice - is the camera device - unlike Camera1, it is got asynchronously using CameraManager and a callback © Google
  • 24. The pipeline CaptureRequest - is used to control camera parameters, and request for preview or image capture © Google
  • 25. The pipeline CameraCaptureSession - is used to send requests and receive results from/to the hardware © Google
  • 27. The pipeline Notice this? we can specify multiple surface outputs! - this was not possible in Camera1 © Google
  • 28. The pipeline But the aspect ratio has to be same across all sizes (at least to support Galaxy devices)
  • 29. The pipeline Example CaptureRequest for camera previewing // Preview request is built with builder pattern previewRequestBuilder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW) ?: return // We can set multiple targets, i.e. show multiple previews previewRequestBuilder.addTarget(Surface(imageTexture)) // Setting camera preferences previewRequestBuilder[CaptureRequest.CONTROL_AF_MODE] = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE previewRequestBuilder[CaptureRequest.FLASH_MODE] = CaptureRequest.FLASH_MODE_OFF previewRequest = previewRequestBuilder.build() // Sending a PreviewRequest to current camera session // The session will handle given PreviewRequest appropriately captureSession?.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler)
  • 30. The pipeline Notice the backgroundHandler? the API manages all the background stuff for us // Preview request is built with builder pattern previewRequestBuilder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW) ?: return // We can set multiple targets, i.e. show multiple previews previewRequestBuilder.addTarget(Surface(imageTexture)) // Setting camera preferences previewRequestBuilder[CaptureRequest.CONTROL_AF_MODE] = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE previewRequestBuilder[CaptureRequest.FLASH_MODE] = CaptureRequest.FLASH_MODE_OFF previewRequest = previewRequestBuilder.build() // Sending a PreviewRequest to current camera session // The session will handle given PreviewRequest appropriately captureSession?.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler)
  • 31. Find the Difference : Differences Between Camera1 and 2
  • 32. Setting Up Preview / Connecting to Surface camera = Camera.open(id) // This is the camera val callback = object: CameraDevice.StateCallback() { override fun onOpened(camera: CameraDevice?) { cameraDevice = camera // This is the cameraDevice } ... } cameraManager.openCamera(id, callback, backgroundHandler) Straightforward, is blocking current thread Gets device by callback, does its job by backgroundHandler
  • 33. Setting Up Preview / Connecting to Surface (camera ?: return).let { it.setPreviewTexture(imageTexture) // or you can do // it.setPreviewDisplay(surfaceHolder) it.startPreview() } val surface = Surface(imageTexture) previewRequestBuilder = cameraDevice!! .createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW) previewRequestBuilder.addTarget(surface) cameraDevice!!.createCaptureSession( listOf(surface, imageReader!!.surface), object : CameraCaptureSession.StateCallback() { override fun onConfigured( session: CameraCaptureSession?) { captureSession = session // This is the session previewRequest = previewRequestBuilder.build() captureSession? .setRepeatingRequest(previewRequest, captureCallback, backgroundHandler) } ... } }, backgroundHandler) Again, straightforward, is blocking current thread. We have to manually set preview size to match the surface’s size. Gets session by callback, and we can start preview by calling setRepeatingRequest. Preview size is automatically chosen by the API to match the surface size.
  • 34. Properties vs. CameraCharacteristics Properties (Camera1) - Mixed mutable/immutable properties - things like previewSize are mutable; things like supportedPreviewSizes are not - You CAN call camera.setProperties() to update camera settings - You NEED to open a camera to use this CameraCharacteristics (Camera2) - Immutable properties only - like the name says, you can only get the characteristics of a CameraDevice - You CAN’T update camera settings with this class; it’s used only for checking device features - You DON’T NEED to open a camera
  • 35. Querying Features camera!!.parameters!!.supportedFlashModes cameraManager .getCameraCharacteristics(cameraId) .get(CameraCharacteristics.FLASH_INFO_AVAILABLE) Can query features by accessing Camera.Parameters Need to open camera before querying Can query features by CameraCharacteristics, using cameraId (not cameraDevice) so no need to open cameraDevice
  • 36. Setting Parameters camera!!.parameters = camera!!.parameters.apply { flashMode = Camera.Parameters.FLASH_MODE_ON zoom = 125 // Sets zoom to x1.25, if supported } previewRequestBuilder[CaptureRequest.LENS_FOCUS_DISTANCE] = 9.50f previewRequestBuilder[CaptureRequest.SENSOR_EXPOSURE_TIME] = 1000000000L / 30 previewRequest = previewRequestBuilder.build() captureSession?.stopRepeating() captureSession?.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler) Sets parameters directly When given unsupported values, it’ll throw an error Sets parameters by builder pattern When given unsupported values, it’ll try its best to fit into supported values, by rounding or clamping, etc
  • 37. Setting Parameters camera!!.parameters = camera!!.parameters.apply { flashMode = Camera.Parameters.FLASH_MODE_ON zoom = 125 // Sets zoom to x1.25, if supported } private fun <T> setPreviewOptions( vararg options: Pair<CaptureRequest.Key<in T>, T>, postProcess: () -> Unit = {}) { for (option in options) { previewRequestBuilder[option.first] = option.second } postProcess() previewRequest = previewRequestBuilder.build() captureSession?.stopRepeating() captureSession?.setRepeatingRequest( previewRequest, captureCallback, backgroundHandler) } ... setPreivewOptions( CaptureRequest.LENS_FOCUS_DISTANCE to 9.50f, CaptureRequest.SENSOR_EXPOSURE_TIME to 1000000000L / 30 ) Sets parameters directly When given unsupported values, it’ll throw an error We can make an extension function to simplify this
  • 38. Setting Parameters camera!!.parameters = camera!!.parameters.apply { flashMode = Camera.Parameters.FLASH_MODE_ON zoom = 125 // Sets zoom to x1.25, if supported } It can be rather frustrating because only some specific values are supported by the camera, so if I request x1.25, the app will likely to crash on Galaxy S9+ But Camera2 handles similar cases appropriately - like what would we expect Example supported zoom ratios (by Samsung Galaxy S9+ Camera) Check out my Camera1-based OSP here : https://github.com/shiftpsh/sensor-tester/releases
  • 39. Setting parameters in Camera1 vs. 2 Camera1 - Parameters are global - If we want to make a change, then it’s changed globally. But since image processing takes time, the API waits until last image finishes processing and finally change the settings Camera2 - Parameters are set per request - Image processing stages gets parameters per request - the API don’t have to care about the last image or whatsoever, resulting improved frame rates
  • 40. Setting parameters in Camera1 1234567 processing stages request params A params B current params: A result
  • 41. Setting parameters in Camera1 1234567 processing stages request params A params B If we change settings... It get mixed current params: B result
  • 42. Setting parameters in Camera1 1222223 processing stages request params A params B current params: A So Camera1 does this way … one by one result
  • 43. Setting parameters in Camera2 1 / A2 / A3 / A4 / B5 / B6 / B7 / B processing stages request params A params B But in Camera2, parameters are baked into the requests result
  • 44. Setting parameters in Camera1 vs. 2 Camera1 Camera2 result … resulting much higher speed
  • 47. Taking Pictures camera!!.takePicture(null, null) { bytes, _ -> process(bytes) } imageReader = ImageReader.newInstance(largestSize.width, largestSize.height, ImageFormat.JPEG, 2) val onImageAvailableListener = ImageReader.OnImageAvailableListener { reader -> process(image) } imageReader!!.setOnImageAvailableListener( onImageAvailableListener, backgroundHandler) val captureBuilder = cameraDevice!! .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE) captureBuilder.addTarget(imageReader!!.surface) ... val captureCallback = object : CameraCaptureSession.CaptureCallback() { override fun onCaptureCompleted(...) {...} } captureSession?.stopRepeating() captureSession?.abortCaptures() captureSession?.capture( captureBuilder.build(), captureCallback, backgroundHandler) One of the few functions that uses a callback. Returns a ByteArray - RGB format It uses an imageReader to capture image. Also uses a callback. Returns an Image - YUV format (typically)
  • 48. Implementing it in existing apps
  • 49. API may be different but the flow is same Open Camera Connect to Surface Start Preview / Repeating Request Apply Filter, etc.. Capture Image Close Camera
  • 50. Speed comparison Device Camera1 Camera2 Improvement Google Pixel 2 (9) 87.7ms 35.1ms 150% Samsung Galaxy S9+ (8.0) 71.7ms 27.9ms 157% LG G7 ThinQ (8.0) 37.3ms 11.5ms 224% Opening the camera * Averaged result of 10 runs
  • 51. Speed comparison Device Camera1 Camera2 Improvement Google Pixel 2 (9) 810.3ms 406.2ms 99% Samsung Galaxy S9+ (8.0) 477.2ms 351.1ms 36% LG G7 ThinQ (8.0) 616.4ms 382.9ms 61% Taking a single full resolution picture * Averaged result of 10 runs, right after callback
  • 52. Migration Strategy - Not all devices work well with Camera2, even if its API level ≥ 21 - It’s up to vendors - if they wrote good enough HAL(hardware abstraction layer) for Camera2 then it’ll work well, otherwise not
  • 53. Migration Strategy - We can test some devices if they supports Camera2 well and make a whitelist - Or we can ask our users to opt-in, like putting an option to enable advanced camera in ‘experimental’ section like many other apps do
  • 54. Q&A