Skip to content

Commit 9ef3a7f

Browse files
committed
FPS correctly detected in landscape
1 parent 029528e commit 9ef3a7f

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

app/src/main/java/poly/darkdepths/strongbox/CameraFragment.java

+43-17
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class CameraFragment extends Fragment {
7373
private byte[] audioData;
7474
private AudioRecord audioRecord;
7575
private int mFramesTotal = 0;
76-
private int mFPS = 15;
76+
private int mFPS = -1;
7777
private long lastTime = 0;
7878
private boolean mPreCompressFrames = true;
7979
private OutputStream outputStreamAudio;
@@ -84,6 +84,8 @@ public class CameraFragment extends Fragment {
8484
private long startTime = 0;
8585
private Boolean portrait = false;
8686
private Cursor cursor = null;
87+
private int benchmarkFPS = -1;
88+
private Boolean benchmarking = false;
8789

8890
/**
8991
* Returns a new instance of this fragment for the given section
@@ -106,6 +108,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
106108
View rootView = inflater.inflate(R.layout.fragment_camera, container, false);
107109
setUpVideoButton(rootView);
108110
setUpGalleryButton(rootView);
111+
109112
return rootView;
110113
}
111114

@@ -121,8 +124,11 @@ public void onResume(){
121124
if (!vfs.isMounted())
122125
vfs.mount(appState.getDbFile(), securestore.getKey().getEncoded());
123126

127+
int currentOrientation = getResources().getConfiguration().orientation;
128+
portrait = (currentOrientation == Configuration.ORIENTATION_PORTRAIT);
129+
124130
prepareForVideoRecording();
125-
hookCallback();
131+
new Thread(new benchmark()).start();
126132
}
127133

128134
@Override
@@ -224,12 +230,10 @@ public void onPreviewFrame(byte[] data, Camera camera) {
224230
if (mPreCompressFrames) {
225231
if (portrait)
226232
{
227-
dataResult = rotateYUV420Degree90(data,mLastHeight,mLastWidth);
233+
dataResult = rotateYUV420Degree90(dataResult,mLastHeight,mLastWidth);
228234
}
229-
YuvImage yuv = new YuvImage(dataResult, mPreviewFormat,
230-
mLastWidth, mLastHeight, null);
231-
byte[] temp = halveYUV420(yuv.getYuvData(), mLastWidth, mLastHeight);
232-
yuv = new YuvImage(temp, mPreviewFormat, mLastWidth/2, mLastHeight/2, null);
235+
byte[] temp = halveYUV420(dataResult, mLastWidth, mLastHeight);
236+
YuvImage yuv = new YuvImage(temp, mPreviewFormat, mLastWidth/2, mLastHeight/2, null);
233237
ByteArrayOutputStream out = new ByteArrayOutputStream();
234238
yuv.compressToJpeg(new Rect(0, 0, mLastWidth/2, mLastHeight/2),
235239
MediaConstants.sJpegQuality, out);
@@ -252,8 +256,14 @@ public void onPreviewFrame(byte[] data, Camera camera) {
252256
frameCounter++;
253257

254258
if((System.currentTimeMillis() - start) >= 1000) {
255-
Log.d("Framecounter", "FPS: " + frameCounter);
256-
mFPS = frameCounter;
259+
if (benchmarking) {
260+
mFPS = frameCounter;
261+
benchmarkFPS = frameCounter;
262+
Log.d("Framecounter", "New Benchmark FPS: " + benchmarkFPS);
263+
} else {
264+
Log.d("Recorder", "Recording FPS is: " + frameCounter);
265+
}
266+
257267
frameCounter = 0;
258268
start = System.currentTimeMillis();
259269
}
@@ -360,7 +370,7 @@ private void startRecording ()
360370

361371
boolean withEmbeddedAudio = false;
362372

363-
Encoder encoder = new Encoder(fileOut,mFPS,withEmbeddedAudio);
373+
Encoder encoder = new Encoder(fileOut,benchmarkFPS,withEmbeddedAudio);
364374
encoder.start();
365375
//start capture
366376
startAudioRecording();
@@ -409,14 +419,7 @@ public void run ()
409419
}
410420

411421
muxer.finish();
412-
413422
fos.close();
414-
415-
//setResult(Activity.RESULT_OK, new Intent().putExtra(MediaStore.EXTRA_OUTPUT, fileOut.getAbsolutePath()));
416-
417-
//if (isRequest)
418-
// getActivity().finish();
419-
420423
} catch (Exception e) {
421424
Log.e(TAG, "IO", e);
422425
}
@@ -616,6 +619,29 @@ public void onClick(View v) {
616619
);
617620
}
618621

622+
public class benchmark implements Runnable {
623+
@Override
624+
public void run(){
625+
if (benchmarkFPS == -1) {
626+
benchmarking = true;
627+
try {
628+
Thread.sleep(1000);
629+
} catch (Exception e) {
630+
Log.d("Benchmark", "Trouble sleeping. Try Ativan?");
631+
}
632+
hookCallback();
633+
try {
634+
Thread.sleep(2500);
635+
} catch (Exception e) {
636+
Log.d("Benchmark", "Trouble sleeping. Try Ativan?");
637+
}
638+
if (mCamera != null)
639+
mCamera.setPreviewCallback(null);
640+
benchmarking = false;
641+
}
642+
}
643+
}
644+
619645
private void setUpGalleryButton(final View view) {
620646
final ImageButton galleryButton = (ImageButton)view.findViewById(R.id.galleryButton);
621647
galleryButton.setOnClickListener(

0 commit comments

Comments
 (0)