Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-client-android
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-client-android
Commits
ee4ea3fd
Commit
ee4ea3fd
authored
Dec 20, 2018
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
camera: add target fps selection algorithm
Change-Id: I43a1f1c86e6a161a22a52a26c195a2a7fff5da31
parent
f3c059a5
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ring-android/app/src/main/java/cx/ring/services/CameraServiceCamera2.java
+34
-23
34 additions, 23 deletions
.../src/main/java/cx/ring/services/CameraServiceCamera2.java
with
34 additions
and
23 deletions
ring-android/app/src/main/java/cx/ring/services/CameraServiceCamera2.java
+
34
−
23
View file @
ee4ea3fd
...
@@ -66,6 +66,8 @@ import cx.ring.views.AutoFitTextureView;
...
@@ -66,6 +66,8 @@ import cx.ring.views.AutoFitTextureView;
class
CameraServiceCamera2
extends
CameraService
{
class
CameraServiceCamera2
extends
CameraService
{
private
static
final
String
TAG
=
CameraServiceCamera2
.
class
.
getName
();
private
static
final
String
TAG
=
CameraServiceCamera2
.
class
.
getName
();
private
static
final
boolean
USE_HARDWARE_ENCODER
=
false
;
private
static
final
boolean
USE_HARDWARE_ENCODER
=
false
;
private
static
final
int
FPS_MAX
=
30
;
private
static
final
int
FPS_TARGET
=
30
;
private
final
HandlerThread
t
=
new
HandlerThread
(
"videoHandler"
);
private
final
HandlerThread
t
=
new
HandlerThread
(
"videoHandler"
);
...
@@ -219,9 +221,7 @@ class CameraServiceCamera2 extends CameraService {
...
@@ -219,9 +221,7 @@ class CameraServiceCamera2 extends CameraService {
}
}
private
static
Size
chooseOptimalSize
(
Size
[]
choices
,
int
textureViewWidth
,
private
static
Size
chooseOptimalSize
(
Size
[]
choices
,
int
textureViewWidth
,
int
textureViewHeight
,
int
maxWidth
,
int
maxHeight
,
Size
aspectRatio
)
{
int
textureViewHeight
,
int
maxWidth
,
int
maxHeight
,
Size
aspectRatio
)
{
// Collect the supported resolutions that are at least as big as the preview Surface
// Collect the supported resolutions that are at least as big as the preview Surface
List
<
Size
>
bigEnough
=
new
ArrayList
<>();
List
<
Size
>
bigEnough
=
new
ArrayList
<>();
// Collect the supported resolutions that are smaller than the preview Surface
// Collect the supported resolutions that are smaller than the preview Surface
...
@@ -252,6 +252,25 @@ class CameraServiceCamera2 extends CameraService {
...
@@ -252,6 +252,25 @@ class CameraServiceCamera2 extends CameraService {
}
}
}
}
private
static
Range
<
Integer
>
chooseOptimalFpsRange
(
Range
<
Integer
>[]
ranges
)
{
Range
<
Integer
>
range
=
null
;
if
(
ranges
!=
null
)
{
for
(
Range
<
Integer
>
r
:
ranges
)
{
if
(
r
.
getUpper
()
>
FPS_MAX
)
continue
;
if
(
range
!=
null
)
{
int
d
=
Math
.
abs
(
r
.
getUpper
()
-
FPS_TARGET
)
-
Math
.
abs
(
range
.
getUpper
()
-
FPS_TARGET
);
if
(
d
>
0
)
continue
;
if
(
d
==
0
&&
r
.
getLower
()
>
range
.
getLower
())
continue
;
}
range
=
r
;
}
}
return
range
==
null
?
new
Range
<>(
0
,
FPS_TARGET
)
:
range
;
}
@Override
@Override
public
void
openCamera
(
Context
context
,
VideoParams
videoParams
,
Object
surface
,
CameraListener
listener
)
{
public
void
openCamera
(
Context
context
,
VideoParams
videoParams
,
Object
surface
,
CameraListener
listener
)
{
CameraDevice
camera
=
previewCamera
;
CameraDevice
camera
=
previewCamera
;
...
@@ -266,27 +285,22 @@ class CameraServiceCamera2 extends CameraService {
...
@@ -266,27 +285,22 @@ class CameraServiceCamera2 extends CameraService {
Handler
handler
=
new
Handler
(
t
.
getLooper
());
Handler
handler
=
new
Handler
(
t
.
getLooper
());
try
{
try
{
CameraCharacteristics
cc
=
manager
.
getCameraCharacteristics
(
videoParams
.
id
);
CameraCharacteristics
cc
=
manager
.
getCameraCharacteristics
(
videoParams
.
id
);
final
Range
<
Integer
>
fpsRange
=
chooseOptimalFpsRange
(
cc
.
get
(
CameraCharacteristics
.
CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES
));
Log
.
w
(
TAG
,
"fpsRange: "
+
fpsRange
);
StreamConfigurationMap
streamConfigs
=
cc
.
get
(
CameraCharacteristics
.
SCALER_STREAM_CONFIGURATION_MAP
);
StreamConfigurationMap
streamConfigs
=
cc
.
get
(
CameraCharacteristics
.
SCALER_STREAM_CONFIGURATION_MAP
);
cc
.
get
(
CameraCharacteristics
.
CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES
);
Size
[]
sizes
=
streamConfigs
.
getOutputSizes
(
SurfaceHolder
.
class
);
Size
[]
sizes
=
streamConfigs
.
getOutputSizes
(
SurfaceHolder
.
class
);
for
(
Size
s
:
sizes
)
for
(
Size
s
:
sizes
)
Log
.
w
(
TAG
,
"supportedSize: "
+
s
);
Log
.
w
(
TAG
,
"supportedSize: "
+
s
);
AutoFitTextureView
view
=
(
AutoFitTextureView
)
surface
;
AutoFitTextureView
view
=
(
AutoFitTextureView
)
surface
;
boolean
flip
=
videoParams
.
rotation
%
180
!=
0
;
boolean
flip
=
videoParams
.
rotation
%
180
!=
0
;
Size
previewSize
=
chooseOptimalSize
(
sizes
,
final
Size
previewSize
=
chooseOptimalSize
(
sizes
,
flip
?
view
.
getHeight
()
:
view
.
getWidth
(),
flip
?
view
.
getWidth
()
:
view
.
getHeight
(),
flip
?
view
.
getHeight
()
:
view
.
getWidth
(),
flip
?
view
.
getWidth
()
:
view
.
getHeight
(),
videoParams
.
width
,
videoParams
.
height
,
videoParams
.
width
,
videoParams
.
height
,
new
Size
(
videoParams
.
width
,
videoParams
.
height
));
new
Size
(
videoParams
.
width
,
videoParams
.
height
));
//videoParams.
Log
.
e
(
TAG
,
"openCamera "
+
videoParams
.
width
+
"x"
+
videoParams
.
height
+
" flip:"
+
flip
);
Log
.
e
(
TAG
,
"openCamera "
+
videoParams
.
rotWidth
+
"x"
+
videoParams
.
rotHeight
);
Log
.
e
(
TAG
,
"openCamera view "
+
view
.
getWidth
()
+
"x"
+
view
.
getHeight
());
Log
.
e
(
TAG
,
"openCamera previewSize "
+
previewSize
.
getWidth
()
+
"x"
+
previewSize
.
getHeight
());
//view.setAspectRatio(flip ? videoParams.height : videoParams.width, flip ? videoParams.width : videoParams.height);
//view.setAspectRatio(videoParams.height, videoParams.width);
int
orientation
=
context
.
getResources
().
getConfiguration
().
orientation
;
int
orientation
=
context
.
getResources
().
getConfiguration
().
orientation
;
if
(
orientation
==
Configuration
.
ORIENTATION_LANDSCAPE
)
{
if
(
orientation
==
Configuration
.
ORIENTATION_LANDSCAPE
)
{
view
.
setAspectRatio
(
view
.
setAspectRatio
(
...
@@ -297,10 +311,7 @@ class CameraServiceCamera2 extends CameraService {
...
@@ -297,10 +311,7 @@ class CameraServiceCamera2 extends CameraService {
}
}
SurfaceTexture
texture
=
view
.
getSurfaceTexture
();
SurfaceTexture
texture
=
view
.
getSurfaceTexture
();
//texture.setDefaultBufferSize(flip ? previewSize.getHeight() : previewSize.getWidth(), flip ? previewSize.getWidth() : previewSize.getHeight());
Surface
s
=
new
Surface
(
texture
);
Surface
s
=
new
Surface
(
texture
);
//s.setFixedSize(flip ? videoParams.height : videoParams.width, flip ? videoParams.width : videoParams.height);
Pair
<
MediaCodec
,
Surface
>
codec
=
USE_HARDWARE_ENCODER
?
openCameraWithEncoder
(
videoParams
,
MediaFormat
.
MIMETYPE_VIDEO_VP8
)
:
null
;
Pair
<
MediaCodec
,
Surface
>
codec
=
USE_HARDWARE_ENCODER
?
openCameraWithEncoder
(
videoParams
,
MediaFormat
.
MIMETYPE_VIDEO_VP8
)
:
null
;
...
@@ -336,7 +347,7 @@ class CameraServiceCamera2 extends CameraService {
...
@@ -336,7 +347,7 @@ class CameraServiceCamera2 extends CameraService {
}
}
builder
.
set
(
CaptureRequest
.
CONTROL_AF_MODE
,
CaptureRequest
.
CONTROL_AF_MODE_CONTINUOUS_VIDEO
);
builder
.
set
(
CaptureRequest
.
CONTROL_AF_MODE
,
CaptureRequest
.
CONTROL_AF_MODE_CONTINUOUS_VIDEO
);
builder
.
set
(
CaptureRequest
.
CONTROL_AE_MODE
,
CaptureRequest
.
CONTROL_AE_MODE_ON
);
builder
.
set
(
CaptureRequest
.
CONTROL_AE_MODE
,
CaptureRequest
.
CONTROL_AE_MODE_ON
);
builder
.
set
(
CaptureRequest
.
CONTROL_AE_TARGET_FPS_RANGE
,
new
Range
<>(
0
,
24
)
);
builder
.
set
(
CaptureRequest
.
CONTROL_AE_TARGET_FPS_RANGE
,
fps
Range
);
builder
.
set
(
CaptureRequest
.
CONTROL_AWB_MODE
,
CaptureRequest
.
CONTROL_AWB_MODE_AUTO
);
builder
.
set
(
CaptureRequest
.
CONTROL_AWB_MODE
,
CaptureRequest
.
CONTROL_AWB_MODE_AUTO
);
final
CaptureRequest
request
=
builder
.
build
();
final
CaptureRequest
request
=
builder
.
build
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment