@@ -73,7 +73,7 @@ public class CameraFragment extends Fragment {
73
73
private byte [] audioData ;
74
74
private AudioRecord audioRecord ;
75
75
private int mFramesTotal = 0 ;
76
- private int mFPS = 15 ;
76
+ private int mFPS = - 1 ;
77
77
private long lastTime = 0 ;
78
78
private boolean mPreCompressFrames = true ;
79
79
private OutputStream outputStreamAudio ;
@@ -84,6 +84,8 @@ public class CameraFragment extends Fragment {
84
84
private long startTime = 0 ;
85
85
private Boolean portrait = false ;
86
86
private Cursor cursor = null ;
87
+ private int benchmarkFPS = -1 ;
88
+ private Boolean benchmarking = false ;
87
89
88
90
/**
89
91
* Returns a new instance of this fragment for the given section
@@ -106,6 +108,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
106
108
View rootView = inflater .inflate (R .layout .fragment_camera , container , false );
107
109
setUpVideoButton (rootView );
108
110
setUpGalleryButton (rootView );
111
+
109
112
return rootView ;
110
113
}
111
114
@@ -121,8 +124,11 @@ public void onResume(){
121
124
if (!vfs .isMounted ())
122
125
vfs .mount (appState .getDbFile (), securestore .getKey ().getEncoded ());
123
126
127
+ int currentOrientation = getResources ().getConfiguration ().orientation ;
128
+ portrait = (currentOrientation == Configuration .ORIENTATION_PORTRAIT );
129
+
124
130
prepareForVideoRecording ();
125
- hookCallback ();
131
+ new Thread ( new benchmark ()). start ();
126
132
}
127
133
128
134
@ Override
@@ -224,12 +230,10 @@ public void onPreviewFrame(byte[] data, Camera camera) {
224
230
if (mPreCompressFrames ) {
225
231
if (portrait )
226
232
{
227
- dataResult = rotateYUV420Degree90 (data ,mLastHeight ,mLastWidth );
233
+ dataResult = rotateYUV420Degree90 (dataResult ,mLastHeight ,mLastWidth );
228
234
}
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 );
233
237
ByteArrayOutputStream out = new ByteArrayOutputStream ();
234
238
yuv .compressToJpeg (new Rect (0 , 0 , mLastWidth /2 , mLastHeight /2 ),
235
239
MediaConstants .sJpegQuality , out );
@@ -252,8 +256,14 @@ public void onPreviewFrame(byte[] data, Camera camera) {
252
256
frameCounter ++;
253
257
254
258
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
+
257
267
frameCounter = 0 ;
258
268
start = System .currentTimeMillis ();
259
269
}
@@ -360,7 +370,7 @@ private void startRecording ()
360
370
361
371
boolean withEmbeddedAudio = false ;
362
372
363
- Encoder encoder = new Encoder (fileOut ,mFPS ,withEmbeddedAudio );
373
+ Encoder encoder = new Encoder (fileOut ,benchmarkFPS ,withEmbeddedAudio );
364
374
encoder .start ();
365
375
//start capture
366
376
startAudioRecording ();
@@ -409,14 +419,7 @@ public void run ()
409
419
}
410
420
411
421
muxer .finish ();
412
-
413
422
fos .close ();
414
-
415
- //setResult(Activity.RESULT_OK, new Intent().putExtra(MediaStore.EXTRA_OUTPUT, fileOut.getAbsolutePath()));
416
-
417
- //if (isRequest)
418
- // getActivity().finish();
419
-
420
423
} catch (Exception e ) {
421
424
Log .e (TAG , "IO" , e );
422
425
}
@@ -616,6 +619,29 @@ public void onClick(View v) {
616
619
);
617
620
}
618
621
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
+
619
645
private void setUpGalleryButton (final View view ) {
620
646
final ImageButton galleryButton = (ImageButton )view .findViewById (R .id .galleryButton );
621
647
galleryButton .setOnClickListener (
0 commit comments