Skip to content

Commit 2ed3ba2

Browse files
committed
"code till remote control ui fix, sync file saving with prefix"
1 parent 80a9253 commit 2ed3ba2

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

app/src/main/java/com/googleresearch/capturesync/MainActivity.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ public MediaRecorder getMediaRecorder() {
185185
// High level camera controls.
186186
private CameraController cameraController;
187187
private CameraCaptureSession captureSession;
188+
private String sessionPrefixText = "";
188189

189190
/**
190191
* Manages SoftwareSync setup/teardown. Since softwaresync should only run when the camera is
@@ -365,8 +366,8 @@ private void handleWebSocketMsg(@NotNull WsMessageContext wsMessageContext){
365366

366367
switch(command){
367368
case "START_REC":
368-
Log.i(TAG,"handling the message in START");
369-
369+
Log.i(TAG,"handling the message in START, Session_Prefix :" + infoParts[1]);
370+
this.sessionPrefixText = infoParts[1];
370371
btn.callOnClick();
371372
this.isVideoRecording = true;
372373
//startVideo(false);
@@ -540,12 +541,13 @@ private void setLeaderClientControls(boolean isLeader) {
540541

541542

542543
} else {
543-
startVideo(false);
544+
545+
startVideo(false, this.sessionPrefixText);
544546
((SoftwareSyncLeader) softwareSyncController.softwareSync)
545547
.broadcastRpc(
546548
SoftwareSyncController.METHOD_START_RECORDING,
547-
"0");
548-
Log.i(TAG, "Starting recording ÖÖ :");
549+
this.sessionPrefixText);
550+
Log.i(TAG, "Starting recording " + this.sessionPrefixText);
549551
}
550552

551553
/* if (cameraController.getOutputSurfaces().isEmpty()) {
@@ -1034,7 +1036,7 @@ private void startPreview() {
10341036
* Create directory and return file
10351037
* returning video file
10361038
*/
1037-
private String getOutputMediaFilePath() throws IOException {
1039+
private String getOutputMediaFilePath(String prefixText) throws IOException {
10381040
// // External sdcard file location
10391041
// File mediaStorageDir = new File(Environment.getExternalStorageDirectory(),
10401042
// "MROB_VID");
@@ -1053,25 +1055,26 @@ private String getOutputMediaFilePath() throws IOException {
10531055
lastTimeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
10541056
Locale.getDefault()).format(new Date());
10551057
String mediaFile;
1056-
mediaFile = dir.toString() + File.separator + "VID_" + lastTimeStamp + ".mp4";
1058+
//mediaFile = dir.toString() + File.separator + "VID_" + lastTimeStamp + ".mp4";
1059+
mediaFile = dir.toString() + File.separator + prefixText +"_"+ lastTimeStamp + ".mp4";
10571060
return mediaFile;
10581061

10591062
}
10601063

10611064
private void createRecorderSurface() throws IOException {
10621065
surface = MediaCodec.createPersistentInputSurface();
10631066

1064-
MediaRecorder recorder = setUpMediaRecorder(surface, false);
1067+
MediaRecorder recorder = setUpMediaRecorder(surface, false, "");
10651068
recorder.prepare();
10661069
recorder.release();
10671070
deleteUnusedVideo();
10681071
}
10691072

1070-
private MediaRecorder setUpMediaRecorder(Surface surface) throws IOException {
1071-
return setUpMediaRecorder(surface, true);
1073+
private MediaRecorder setUpMediaRecorder(Surface surface, String prefixText) throws IOException {
1074+
return setUpMediaRecorder(surface, true, prefixText);
10721075
}
10731076

1074-
private MediaRecorder setUpMediaRecorder(Surface surface, boolean specifyOutput) throws IOException {
1077+
private MediaRecorder setUpMediaRecorder(Surface surface, boolean specifyOutput, String prefixText) throws IOException {
10751078
MediaRecorder recorder = new MediaRecorder();
10761079
recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
10771080
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
@@ -1082,7 +1085,7 @@ private MediaRecorder setUpMediaRecorder(Surface surface, boolean specifyOutput)
10821085
* set output file in media recorder
10831086
*/
10841087

1085-
lastVideoPath = getOutputMediaFilePath();
1088+
lastVideoPath = getOutputMediaFilePath(prefixText);
10861089
recorder.setOutputFile(lastVideoPath);
10871090

10881091
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_1080P);
@@ -1108,16 +1111,16 @@ public boolean isVideoRecording() {
11081111
return isVideoRecording;
11091112
}
11101113

1111-
public void startVideo(boolean wantAutoExp) {
1114+
public void startVideo(boolean wantAutoExp, String prefixText) {
11121115
Log.d(TAG, "Starting video.");
11131116
//Toast.makeText(this, "Started recording video", Toast.LENGTH_LONG).show();
11141117

11151118
isVideoRecording = true;
11161119
try {
11171120

11181121
Log.d(TAG, "Starting video after toast.");
1119-
mediaRecorder = setUpMediaRecorder(surface);
1120-
String filename = lastTimeStamp + ".csv";
1122+
mediaRecorder = setUpMediaRecorder(surface, prefixText);
1123+
String filename = prefixText+"_"+lastTimeStamp + ".csv";
11211124
// Creates frame timestamps logger
11221125
try {
11231126
mLogger = new CSVLogger(SUBDIR_NAME, filename, this);

app/src/main/java/com/googleresearch/capturesync/RemoteFileUpload.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected Boolean doInBackground(String ... selectedFilePaths) {
3333

3434
try {
3535
FileInputStream fis = new FileInputStream(new File(selectedFilePaths[0]));
36-
36+
System.out.println("FILE_PATH: " + selectedFilePaths[0]);
3737
URL url = new URL(urlServer);
3838
conn = (HttpURLConnection) url.openConnection();
3939
conn.setChunkedStreamingMode(maxBufferSize);

app/src/main/java/com/googleresearch/capturesync/SoftwareSyncController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,16 @@ private void setupSoftwareSync() {
192192
clientRpcs.put(
193193
METHOD_START_RECORDING,
194194
payload -> {
195-
Log.v(TAG, "Starting video");
195+
Log.v(TAG, "Starting video client");
196196
context.runOnUiThread(
197-
() -> context.startVideo(false)
197+
() -> context.startVideo(false, payload)
198198
);
199199
});
200200

201201
clientRpcs.put(
202202
METHOD_STOP_RECORDING,
203203
payload -> {
204-
Log.v(TAG, "Stopping video");
204+
Log.v(TAG, "Stopping video client");
205205
context.runOnUiThread(
206206
context::stopVideo
207207
);

remote_control/remote_control.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ def __init__(self, MainWindow ) -> None:
2323
def startBtn(self):
2424
self.label.setText('Recording Started')
2525
self.label.adjustSize()
26-
self.ws.send("START_REC")
26+
session_prefix = self.download_prefix_text.toPlainText()
27+
self.ws.send("START_REC@@"+session_prefix)
2728

2829
def stopBtn(self):
2930
self.label.setText('Recording Stopped')
3031
self.ws.send("STOP_REC")
3132
def statusBtn(self):
3233
self.ws.send("STATUS")
3334
message = self.ws.recv()
34-
self.label.setText(message)
35+
self.status_label.setPlainText(message)
36+
def clearStatusBtn(self):
37+
self.status_label.setPlainText("")
3538
def downloadBtn(self):
3639
endpoint = self.api_input.toPlainText()
3740
download_prefix = self.download_prefix_text.toPlainText()
@@ -53,34 +56,39 @@ def setupUi(self, MainWindow):
5356
self.label.setFont(font)
5457
self.label.setObjectName("label")
5558
self.start_btn = QtWidgets.QPushButton(self.centralwidget)
56-
self.start_btn.setGeometry(QtCore.QRect(130, 90, 161, 61))
59+
self.start_btn.setGeometry(QtCore.QRect(130, 120, 161, 61))
5760
self.start_btn.setFont(font)
5861
self.start_btn.setObjectName("pushButton")
5962
self.start_btn.clicked.connect(self.startBtn)
6063
self.stop_btn = QtWidgets.QPushButton(self.centralwidget)
61-
self.stop_btn.setGeometry(QtCore.QRect(430, 90, 161, 61))
64+
self.stop_btn.setGeometry(QtCore.QRect(430, 120, 161, 61))
6265
self.stop_btn.setFont(font)
6366
self.stop_btn.setObjectName("pushButton_2")
6467
self.stop_btn.clicked.connect(self.stopBtn)
6568
self.status_btn = QtWidgets.QPushButton(self.centralwidget)
66-
self.status_btn.setGeometry(QtCore.QRect(280, 300, 161, 61))
69+
self.status_btn.setGeometry(QtCore.QRect(280, 200, 161, 61))
6770
self.status_btn.setFont(font)
6871
self.status_btn.setObjectName("pushButton_3")
6972
self.status_btn.clicked.connect(self.statusBtn)
7073
self.api_input = QtWidgets.QTextEdit(self.centralwidget)
71-
self.api_input.setGeometry(QtCore.QRect(143, 390, 451, 31))
74+
self.api_input.setGeometry(QtCore.QRect(143, 450, 451, 31))
7275
self.api_input.setObjectName("textEdit")
7376
self.download_prefix_text = QtWidgets.QTextEdit(self.centralwidget)
74-
self.download_prefix_text.setGeometry(QtCore.QRect(280, 430, 161, 31))
77+
self.download_prefix_text.setGeometry(QtCore.QRect(280, 80, 161, 31))
7578
self.download_prefix_text.setObjectName("prefix_text")
7679
self.download_btn = QtWidgets.QPushButton(self.centralwidget)
77-
self.download_btn.setGeometry(QtCore.QRect(280, 500, 161, 61))
80+
self.download_btn.setGeometry(QtCore.QRect(280, 380, 161, 61))
7881
self.download_btn.setFont(font)
7982
self.download_btn.setObjectName("pushButton_4")
8083
self.download_btn.clicked.connect(self.downloadBtn)
8184
self.status_label = QtWidgets.QPlainTextEdit(self.centralwidget)
82-
self.status_label.setGeometry(QtCore.QRect(173, 180, 381, 91))
85+
self.status_label.setGeometry(QtCore.QRect(173, 280, 381, 91))
8386
self.status_label.setObjectName("plainTextEdit")
87+
self.status_clear_btn = QtWidgets.QPushButton(self.centralwidget)
88+
self.status_clear_btn.setGeometry(QtCore.QRect(560, 341, 31, 31))
89+
self.status_clear_btn.setFont(font)
90+
self.status_clear_btn.setObjectName("pushButton_5")
91+
self.status_clear_btn.clicked.connect(self.clearStatusBtn)
8492
MainWindow.setCentralWidget(self.centralwidget)
8593
self.menubar = QtWidgets.QMenuBar(MainWindow)
8694
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
@@ -100,8 +108,10 @@ def retranslateUi(self, MainWindow):
100108
self.start_btn.setText(_translate("MainWindow", "Start"))
101109
self.stop_btn.setText(_translate("MainWindow", "Stop"))
102110
self.status_btn.setText(_translate("MainWindow", "Status"))
111+
self.status_clear_btn.setText(_translate("MainWindow", "X"))
112+
self.status_clear_btn.setStyleSheet('QPushButton {;color: red;}')
103113
self.api_input.setPlaceholderText(_translate("MainWindow", "Please enter the api endpoint where you want the files to be uploaded "))
104-
self.download_prefix_text.setPlaceholderText(_translate("MainWindow", "Session PREFIX for download "))
114+
self.download_prefix_text.setPlaceholderText(_translate("MainWindow", " Enter Session Prefix"))
105115
self.download_btn.setText(_translate("MainWindow", "Download"))
106116
self.status_label.setPlaceholderText(_translate("MainWindow", "No status "))
107117

0 commit comments

Comments
 (0)