|
|
|
@ -161,6 +161,8 @@ public class VideoFragment extends Fragment implements View.OnClickListener, Med
|
|
|
|
|
*/
|
|
|
|
|
private Size mVideoSize;
|
|
|
|
|
|
|
|
|
|
private int mOrientation = -1;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* MediaRecorder
|
|
|
|
|
*/
|
|
|
|
@ -280,12 +282,21 @@ public class VideoFragment extends Fragment implements View.OnClickListener, Med
|
|
|
|
|
* @param choices The list of available sizes
|
|
|
|
|
* @return The video size
|
|
|
|
|
*/
|
|
|
|
|
private static Size chooseVideoSize(Size[] choices) {
|
|
|
|
|
for (Size size : choices) {
|
|
|
|
|
if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 1080) {
|
|
|
|
|
return size;
|
|
|
|
|
private static Size chooseVideoSize(Size[] choices, Size expectedSize) {
|
|
|
|
|
if (expectedSize == null || expectedSize.getWidth() <= 0 || expectedSize.getHeight() <= 0) {
|
|
|
|
|
for (Size size : choices) {
|
|
|
|
|
if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 1080) {
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (Size size : choices) {
|
|
|
|
|
if (size.equals(expectedSize)) {
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.e(TAG, "Couldn't find any suitable video size");
|
|
|
|
|
return choices[choices.length - 1];
|
|
|
|
|
}
|
|
|
|
@ -342,6 +353,12 @@ public class VideoFragment extends Fragment implements View.OnClickListener, Med
|
|
|
|
|
mCameraId = Integer.toString(argument.getInt("CameraId", 0));
|
|
|
|
|
mVideoId = argument.getLong("videoId", 0);
|
|
|
|
|
mDuration = argument.getInt("duration", 0);
|
|
|
|
|
int width = argument.getInt("width", 0);
|
|
|
|
|
int height = argument.getInt("height", 0);
|
|
|
|
|
mOrientation = argument.getInt("orientation", -1);
|
|
|
|
|
if (width > 0 && height > 0) {
|
|
|
|
|
mVideoSize = new Size(width, height);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "Recv recording request CameraId=" + mCameraId + " videoId=" + Long.toString(mVideoId));
|
|
|
|
@ -484,7 +501,7 @@ public class VideoFragment extends Fragment implements View.OnClickListener, Med
|
|
|
|
|
if (map == null) {
|
|
|
|
|
throw new RuntimeException("Cannot get available preview/video sizes");
|
|
|
|
|
}
|
|
|
|
|
mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class));
|
|
|
|
|
mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class), mVideoSize);
|
|
|
|
|
mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
|
|
|
|
|
width, height, mVideoSize);
|
|
|
|
|
|
|
|
|
@ -627,19 +644,14 @@ public class VideoFragment extends Fragment implements View.OnClickListener, Med
|
|
|
|
|
if (null == activity) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
|
|
|
|
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
|
|
|
|
|
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
|
|
|
|
|
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
|
|
|
|
|
if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) {
|
|
|
|
|
mNextVideoAbsolutePath = getVideoFilePath(getActivity());
|
|
|
|
|
}
|
|
|
|
|
mMediaRecorder.setOutputFile(mNextVideoAbsolutePath);
|
|
|
|
|
mMediaRecorder.setVideoEncodingBitRate(10000000);
|
|
|
|
|
mMediaRecorder.setVideoEncodingBitRate(1024 * 1024 * 8);
|
|
|
|
|
mMediaRecorder.setVideoFrameRate(30);
|
|
|
|
|
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
|
|
|
|
|
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
|
|
|
|
@ -647,10 +659,16 @@ public class VideoFragment extends Fragment implements View.OnClickListener, Med
|
|
|
|
|
if (mDuration > 0) {
|
|
|
|
|
mMediaRecorder.setMaxDuration(mDuration * 1000);
|
|
|
|
|
}
|
|
|
|
|
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
|
|
|
|
|
int orientationAdjustment = 0;
|
|
|
|
|
if (mOrientation != -1) {
|
|
|
|
|
orientationAdjustment = mOrientation / 90;
|
|
|
|
|
}
|
|
|
|
|
int rotation = (activity.getWindowManager().getDefaultDisplay().getRotation() + orientationAdjustment) % 4;
|
|
|
|
|
int orientationHint = 0;
|
|
|
|
|
switch (mSensorOrientation) {
|
|
|
|
|
case SENSOR_ORIENTATION_DEFAULT_DEGREES:
|
|
|
|
|
mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
|
|
|
|
|
orientationHint = DEFAULT_ORIENTATIONS.get(rotation);
|
|
|
|
|
mMediaRecorder.setOrientationHint(orientationHint);
|
|
|
|
|
break;
|
|
|
|
|
case SENSOR_ORIENTATION_INVERSE_DEGREES:
|
|
|
|
|
mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
|
|
|
|
|