Skip to content

Commit

Permalink
little fix in getPreviewSize method camera api1
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Aug 10, 2017
1 parent 182e169 commit 094b08f
Showing 1 changed file with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import android.graphics.ImageFormat;
import android.hardware.Camera;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.opengl.GLES20;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.util.Size;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import com.pedro.encoder.video.FormatVideoEncoder;
import java.io.IOException;
import java.util.List;
import javax.microedition.khronos.egl.EGL10;
Expand Down Expand Up @@ -225,12 +231,45 @@ public List<Camera.Size> getPreviewSize() {
camera.release();
camera = null;
}
for (Camera.Size size : previewSizes) {
Log.i(TAG, size.width + "X" + size.height);
//discard preview more high than encoder support
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
Size maxSize = getMaxEncoderSizeSupported();
if(maxSize != null) {
for (Camera.Size size : previewSizes) {
if (size.width > maxSize.getWidth() || size.height > maxSize.getHeight()){
Log.i(TAG, size.width + "X" + size.height + ", not supported for encoder");
previewSizes.remove(size);
}
}
}
}
return previewSizes;
}

/**
* @return max size that h264 device encoder can record. null if encoder not found
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private Size getMaxEncoderSizeSupported() {
String mime = "video/avc";
int count = MediaCodecList.getCodecCount();
for (int i = 0; i < count; i++) {
MediaCodecInfo mci = MediaCodecList.getCodecInfoAt(i);
if (!mci.isEncoder()) {
continue;
}
String[] types = mci.getSupportedTypes();
for (String type : types) {
if (type.equalsIgnoreCase(mime)) {
MediaCodecInfo.CodecCapabilities codecCapabilities = mci.getCapabilitiesForType(mime);
return new Size(codecCapabilities.getVideoCapabilities().getSupportedWidths().getUpper(),
codecCapabilities.getVideoCapabilities().getSupportedHeights().getUpper());
}
}
}
return null;
}

public void setEffect(EffectManager effect) {
if (camera != null) {
Camera.Parameters parameters = camera.getParameters();
Expand Down

0 comments on commit 094b08f

Please sign in to comment.