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

Fix camera size access. Allows for video on devices that don't have exact matching camera sizes. #8

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -33,8 +33,6 @@ public class MediastreamerAndroidContext {
private native void setDeviceFavoriteSampleRate(int samplerate);
private native void setDeviceFavoriteBufferSize(int bufferSize);
private native void addSoundDeviceDescription(String manufacturer, String model, String platform, int flags, int delay, int recommended_rate);

private static Context mContext;

private MediastreamerAndroidContext() {

Expand All @@ -47,10 +45,6 @@ private static MediastreamerAndroidContext getInstance() {
instance = new MediastreamerAndroidContext();
return instance;
}

public static Context getContext(){
return mContext;
}

public static void addSoundDeviceDesc(String manufacturer, String model, String platform, int flags, int delay, int recommended_rate) {
getInstance().addSoundDeviceDescription(manufacturer, model, platform, flags, delay, recommended_rate);
Expand All @@ -60,15 +54,15 @@ public static void addSoundDeviceDesc(String manufacturer, String model, String
public static void setContext(Object c) {
if (c == null)
return;

mContext = (Context)c;
Context context = (Context)c;
int bufferSize = 64;
int sampleRate = 44100;
MediastreamerAndroidContext mac = getInstance();
// When using the OpenSLES sound card, the system is capable of giving us the best values to use for the buffer size and the sample rate
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
AudioManager audiomanager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
AudioManager audiomanager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
String bufferProperty = audiomanager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
bufferSize = parseInt(bufferProperty, bufferSize);
String sampleRateProperty = audiomanager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
Expand Down
Expand Up @@ -27,6 +27,7 @@ of the License, or (at your option) any later version.

import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
import android.view.SurfaceView;

/**
Expand Down Expand Up @@ -137,7 +138,7 @@ protected static int[] selectNearestResolutionAvailableForCamera(int id, int req
}

AndroidCamera[] cameras = AndroidCameraConfiguration.retrieveCameras();
List<AndroidCamera.Size> supportedSizes = null;
List<Size> supportedSizes = null;
for(AndroidCamera c: cameras) {
if (c.id == id)
supportedSizes = c.resolutions;
Expand All @@ -147,7 +148,7 @@ protected static int[] selectNearestResolutionAvailableForCamera(int id, int req
return null;
}
Log.d("mediastreamer", supportedSizes.size() + " supported resolutions :");
for(AndroidCamera.Size s : supportedSizes) {
for(Size s : supportedSizes) {
Log.d("mediastreamer", "\t" + s.width + "x" + s.height);
}
int r[] = null;
Expand All @@ -157,11 +158,11 @@ protected static int[] selectNearestResolutionAvailableForCamera(int id, int req

try {
// look for nearest size
AndroidCamera.Size result = supportedSizes.get(0); /*by default return first value*/
Size result = supportedSizes.get(0); /*by default return first value*/
int req = rW * rH;
int minDist = Integer.MAX_VALUE;
int useDownscale = 0;
for(AndroidCamera.Size s: supportedSizes) {
for(Size s: supportedSizes) {
int dist = /*Math.abs*/-1*(req - s.width * s.height);
if ( ((s.width >= rW && s.height >= rH) || (s.width >= rH && s.height >= rW)) && dist < minDist) {
minDist = dist;
Expand Down
Expand Up @@ -18,12 +18,14 @@ of the License, or (at your option) any later version.
*/
package org.linphone.mediastream.video.capture.hwconf;

import java.util.ArrayList;
import java.util.List;

import org.linphone.mediastream.Log;
import org.linphone.mediastream.Version;

import android.hardware.Camera.Size;



/**
* Entry point for accessing hardware cameras configuration.
Expand Down Expand Up @@ -58,15 +60,10 @@ private static void initCamerasCache() {
return;

try {
if (Version.sdk() < 9) {
if (Version.sdk() < 9)
camerasCache = AndroidCameraConfiguration.probeCamerasSDK5();
} else {
if (Version.sdk() >= 21) {
camerasCache = AndroidCameraConfiguration.probeCamerasSDK21();
} else {
camerasCache = AndroidCameraConfiguration.probeCamerasSDK9();
}
}
else
camerasCache = AndroidCameraConfiguration.probeCamerasSDK9();
} catch (Exception exc) {
Log.e("Error: cannot retrieve cameras information (busy ?)", exc);
exc.printStackTrace();
Expand All @@ -82,45 +79,21 @@ static AndroidCamera[] probeCamerasSDK9() {
return AndroidCameraConfigurationReader9.probeCameras();
}

static AndroidCamera[] probeCamerasSDK21() {
return AndroidCameraConfigurationReader21.probeCameras();
}

/**
* Default: no front; rear=0; default=rear
* @author Guillaume Beraudo
*
*/
static public class AndroidCamera {
static public class Size{
public final int width;
public final int height;

public Size(int w, int h){
this.width = w;
this.height = h;
}
}

public AndroidCamera(int i, boolean f, List<Size> r, int o) {
public AndroidCamera(int i, boolean f, int o, List<Size> r) {
this.id = i;
this.frontFacing = f;
this.orientation = o;
this.resolutions = r;
}
public AndroidCamera(int i, boolean f, int o, List<android.hardware.Camera.Size> origin) {
this.resolutions = new ArrayList<Size>(origin.size());
for (android.hardware.Camera.Size s : origin) {
this.resolutions.add(new AndroidCamera.Size(s.width,s.height));
}
this.id = i;
this.frontFacing = f;
this.orientation = o;
}
public int id;
public boolean frontFacing; // false => rear facing
public int orientation;
public List<Size> resolutions;

}
}

This file was deleted.