集成短视频功能

serial
BlueMatthew 1 year ago
parent b7fbec6d12
commit 1bede89a8c

@ -186,7 +186,7 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
mRegisterHeartbeatMid = env->GetMethodID(classService, "registerHeartbeatTimer", "(I)V");
mUpdateTimeMid = env->GetMethodID(classService, "updateTime", "(J)Z");
mUpdateCaptureScheduleMid = env->GetMethodID(classService, "updateCaptureSchedule", "(J)Z");
mStartRecordingMid = env->GetMethodID(classService, "startRecording", "(IJIIII)V");
mStartRecordingMid = env->GetMethodID(classService, "startRecording", "(IJIIIII)V");
mRequestWakelockMid = env->GetMethodID(classService, "requestWakelock", "(Ljava/lang/String;J)V");
mReleaseWakelockMid = env->GetMethodID(classService, "releaseWakelock", "(Ljava/lang/String;)V");
@ -848,7 +848,8 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
ALOGE("Failed to get JNI Env");
return false;
}
env->CallVoidMethod(m_javaService, mStartRecordingMid, mPhotoInfo.cameraId, (unsigned long)mPhotoInfo.photoId, mPhotoInfo.duration, mPhotoInfo.width, mPhotoInfo.height, mPhotoInfo.duration);
int orientation = mPhotoInfo.orientation == 0 ? -1 : (mPhotoInfo.orientation - 1) * 90;
env->CallVoidMethod(m_javaService, mStartRecordingMid, mPhotoInfo.cameraId, (unsigned long)mPhotoInfo.photoId, mPhotoInfo.duration, mPhotoInfo.width, mPhotoInfo.height, mPhotoInfo.duration, orientation);
if (didAttachThread)
{

@ -476,7 +476,7 @@ public class MicroPhotoService extends Service {
registerPhotoTimer(getApplicationContext(), scheduleTime, scheduleTime, timeout, schedules);
}
public void startRecording(int cameraId, long videoId, int duration, int width, int height, int quality) {
public void startRecording(int cameraId, long videoId, int duration, int width, int height, int quality, int orientation) {
Context context = getApplicationContext();
Intent intent = new Intent(this, VideoActivity.class);
@ -486,6 +486,7 @@ public class MicroPhotoService extends Service {
intent.putExtra("width", width);
intent.putExtra("height", height);
intent.putExtra("quality", quality);
intent.putExtra("orientation", orientation);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

@ -16,28 +16,12 @@ public class VideoActivity extends AppCompatActivity {
setContentView(R.layout.activity_video);
if (null == savedInstanceState) {
Bundle bundle = new Bundle();
Intent intent = getIntent();
int duration = intent.getIntExtra("duration", 0);
if (intent.hasExtra("cameraId")) {
bundle.putInt("cameraId", intent.getIntExtra("cameraId", 0));
}
if (intent.hasExtra("videoId")) {
bundle.putLong("videoId", intent.getLongExtra("videoId", 0));
}
bundle.putInt("duration", duration);
String act = intent.getStringExtra("action");
if (act != null) {
bundle.putString("action", act);
}
bundle.putInt("width", intent.getIntExtra("width", 0));
bundle.putInt("height", intent.getIntExtra("height", 0));
Intent intent = getIntent();
Fragment fragment = VideoFragment.newInstance();
fragment.setArguments(bundle);
Bundle bundle = intent.getExtras();
if (bundle != null) {
fragment.setArguments(bundle);
}
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, fragment)
.commit();

@ -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));

Loading…
Cancel
Save