Skip to content

Commit 0cfcde3

Browse files
Merge pull request #31 from MobileRoboticsSkoltech/blinking_flash
Flash logging
2 parents d7df21d + 7653f8b commit 0cfcde3

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This project is based on [Open Camera](https://opencamera.org.uk/) — a popul
3232
- ```{VIDEO_NAME}_accel.csv```, data format: ```X-data, Y-data, Z-data, timestamp (ns)```
3333
- ```{VIDEO_NAME}_magnetic.csv```, data format: ```X-data, Y-data, Z-data, timestamp (ns)```
3434
- ```{VIDEO_NAME}_timestamps.csv```, data format: ```timestamp (ns)```
35+
- ```{VIDEO_NAME}_flash.csv```, data format: ```timestamp (ns)``` (timestamps of when the flash fired)
3536

3637
### Remote recording
3738

app/src/main/java/net/sourceforge/opencamera/ExtendedAppInterface.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.util.Log;
88

99
import net.sourceforge.opencamera.cameracontroller.YuvImageUtils;
10+
import net.sourceforge.opencamera.sensorlogging.FlashController;
1011
import net.sourceforge.opencamera.sensorlogging.RawSensorInfo;
1112
import net.sourceforge.opencamera.sensorlogging.VideoFrameInfo;
1213
import net.sourceforge.opencamera.sensorlogging.VideoPhaseInfo;
@@ -26,6 +27,12 @@ public class ExtendedAppInterface extends MyApplicationInterface {
2627
private static final int SENSOR_FREQ_DEFAULT_PREF = 0;
2728

2829
private final RawSensorInfo mRawSensorInfo;
30+
31+
public FlashController getFlashController() {
32+
return mFlashController;
33+
}
34+
35+
private final FlashController mFlashController;
2936
private final SharedPreferences mSharedPreferences;
3037
private final MainActivity mMainActivity;
3138
private final YuvImageUtils mYuvUtils;
@@ -40,6 +47,8 @@ public VideoFrameInfo setupFrameInfo() throws IOException {
4047
super(mainActivity, savedInstanceState);
4148
mRawSensorInfo = mainActivity.getRawSensorInfoManager();
4249
mMainActivity = mainActivity;
50+
mFlashController = new FlashController(mainActivity);
51+
4352
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mainActivity);
4453
// We create it only once here (not during the video) as it is a costly operation
4554
// (instantiates RenderScript object)
@@ -152,6 +161,16 @@ public void startingVideo() {
152161
mMainActivity.getPreview().showToast(null, "Requested IMU recording but no sensors were enabled");
153162
mMainActivity.getPreview().stopVideo(false);
154163
}
164+
165+
if (getVideoFlashPref()) {
166+
try {
167+
mFlashController.startRecording(mLastVideoDate);
168+
} catch (IOException e) {
169+
Log.e(TAG, "Failed to start flash controller");
170+
e.printStackTrace();
171+
}
172+
}
173+
155174
super.startingVideo();
156175
}
157176

@@ -168,6 +187,10 @@ public void stoppingVideo() {
168187
mMainActivity.getPreview().showToast("Stopping video with IMU recording...", true);
169188
}
170189

190+
if (mFlashController.isRecording()) {
191+
mFlashController.stopRecording();
192+
}
193+
171194
super.stoppingVideo();
172195
}
173196

app/src/main/java/net/sourceforge/opencamera/preview/Preview.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5145,6 +5145,7 @@ private void flashVideo() {
51455145
// turn on torch
51465146
cancelAutoFocus();
51475147
camera_controller.setFlashValue("flash_torch");
5148+
applicationInterface.getFlashController().onFlashFired();
51485149
try {
51495150
Thread.sleep(100);
51505151
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package net.sourceforge.opencamera.sensorlogging;
2+
3+
import android.os.SystemClock;
4+
import android.util.Log;
5+
6+
import net.sourceforge.opencamera.MainActivity;
7+
import net.sourceforge.opencamera.StorageUtils;
8+
import net.sourceforge.opencamera.StorageUtilsWrapper;
9+
10+
import java.io.BufferedWriter;
11+
import java.io.File;
12+
import java.io.IOException;
13+
import java.io.PrintWriter;
14+
import java.util.Date;
15+
16+
public class FlashController {
17+
private final static String TAG = "FlashController";
18+
private final static String TIMESTAMP_FILE_SUFFIX = "_flash";
19+
private BufferedWriter mFlashBufferedWriter;
20+
private final MainActivity mContext;
21+
22+
public boolean isRecording() {
23+
return mIsRecording;
24+
}
25+
26+
private volatile boolean mIsRecording;
27+
28+
29+
public FlashController(MainActivity context) {
30+
mContext = context;
31+
}
32+
33+
public void startRecording(Date currentVideoDate) throws IOException {
34+
StorageUtilsWrapper storageUtils = mContext.getStorageUtils();
35+
36+
File frameTimestampFile = storageUtils.createOutputCaptureInfo(
37+
StorageUtils.MEDIA_TYPE_RAW_SENSOR_INFO, "csv", TIMESTAMP_FILE_SUFFIX, currentVideoDate
38+
);
39+
mFlashBufferedWriter = new BufferedWriter(
40+
new PrintWriter(frameTimestampFile)
41+
);
42+
mIsRecording = true;
43+
}
44+
45+
public void onFlashFired() {
46+
if (isRecording() && mFlashBufferedWriter != null) {
47+
long timestamp = SystemClock.elapsedRealtimeNanos();
48+
try {
49+
mFlashBufferedWriter
50+
.append(Long.toString(timestamp))
51+
.append("\n");
52+
} catch (IOException e) {
53+
Log.d(TAG, "Failed to write flash timestamp");
54+
}
55+
}
56+
}
57+
58+
public void stopRecording() {
59+
mIsRecording = false;
60+
try {
61+
if (mFlashBufferedWriter != null) {
62+
Log.d(TAG, "Before writer close()");
63+
mFlashBufferedWriter.flush();
64+
mFlashBufferedWriter.close();
65+
mFlashBufferedWriter = null;
66+
Log.d(TAG, "After writer close()");
67+
}
68+
} catch (IOException e) {
69+
Log.d(TAG, "Exception occurred when attempting to close mFlashBufferedWriter");
70+
e.printStackTrace();
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)