Skip to content

Commit 50e5461

Browse files
committed
"File server logging, stable video, multiple files upload working"
1 parent 31d1afd commit 50e5461

File tree

6 files changed

+104
-111
lines changed

6 files changed

+104
-111
lines changed

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
import android.os.Handler;
2727
import android.util.Log;
2828
import android.util.Pair;
29-
import android.widget.Toast;
30-
31-
import androidx.annotation.NonNull;
32-
33-
import java.io.File;
3429
import java.util.ArrayList;
3530
import java.util.LinkedList;
3631
import java.util.List;
@@ -390,25 +385,25 @@ public void onCaptureCompleted(
390385
}
391386
}
392387

393-
@Override
394-
public void onCaptureSequenceCompleted(@NonNull CameraCaptureSession session, int sequenceId, long frameNumber) {
395-
super.onCaptureSequenceCompleted(session, sequenceId, frameNumber);
396-
if (context.getLastVideoSeqId() != null && sequenceId == context.getLastVideoSeqId() && context.getLogger() != null) {
397-
context.getMediaRecorder().stop();
398-
399-
if (context.isVideoRecording()) {
400-
context.setVideoRecording(false);
401-
} else {
402-
// MediaRecorder created an empty video on preview, should perform a cleanup
403-
context.deleteUnusedVideo();
404-
}
405-
406-
context.getMediaRecorder().reset();
407-
408-
context.getLogger().close();
409-
context.setLogger(null);
410-
}
411-
}
388+
// @Override
389+
// public void onCaptureSequenceCompleted(@NonNull CameraCaptureSession session, int sequenceId, long frameNumber) {
390+
// super.onCaptureSequenceCompleted(session, sequenceId, frameNumber);
391+
// if (context.getLastVideoSeqId() != null && sequenceId == context.getLastVideoSeqId() && context.getLogger() != null) {
392+
// context.getMediaRecorder().stop();
393+
//
394+
// if (context.isVideoRecording()) {
395+
// context.setVideoRecording(false);
396+
// } else {
397+
// // MediaRecorder created an empty video on preview, should perform a cleanup
398+
// context.deleteUnusedVideo();
399+
// }
400+
//
401+
// context.getMediaRecorder().reset();
402+
//
403+
// context.getLogger().close();
404+
// context.setLogger(null);
405+
// }
406+
// }
412407
};
413408
}
414409

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

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ public int getCurSequence() {
131131
return curSequence;
132132
}
133133

134-
public void setLogger(CSVLogger mLogger) {
135-
this.mLogger = mLogger;
136-
}
134+
// public void setLogger(CSVLogger mLogger) {
135+
// this.mLogger = mLogger;
136+
// }
137137

138138
public CSVLogger getLogger() {
139139
return mLogger;
@@ -150,9 +150,9 @@ public CSVLogger getLogger() {
150150
// Phase config file to use for phase alignment, configs are located in the raw folder.
151151
private final int phaseConfigFile = R.raw.default_phaseconfig;
152152

153-
public MediaRecorder getMediaRecorder() {
154-
return mediaRecorder;
155-
}
153+
// public MediaRecorder getMediaRecorder() {
154+
// return mediaRecorder;
155+
// }
156156

157157
private MediaRecorder mediaRecorder = new MediaRecorder();
158158
private boolean isVideoRecording = false;
@@ -534,7 +534,7 @@ private void setLeaderClientControls(boolean isLeader) {
534534
SoftwareSyncController.METHOD_STOP_RECORDING,
535535
"0");
536536
Log.i(TAG, "Stopping recording ÖÖ :");
537-
537+
startPreview();
538538

539539
} else {
540540

@@ -691,7 +691,7 @@ private PhaseConfig loadPhaseConfigFile() throws JSONException {
691691
}
692692

693693
private void closeCamera() {
694-
stopPreview();
694+
// stopPreview();
695695
captureSession = null;
696696
surface.release();
697697
if (cameraController != null) {
@@ -1024,7 +1024,7 @@ private void startPreview(boolean wantAutoExp) {
10241024
}
10251025
}
10261026

1027-
private void startPreview() {
1027+
public void startPreview() {
10281028
startPreview(false);
10291029
}
10301030

@@ -1086,7 +1086,9 @@ private MediaRecorder setUpMediaRecorder(Surface surface, boolean specifyOutput,
10861086

10871087
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_1080P);
10881088
recorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
1089-
recorder.setVideoEncodingBitRate(profile.videoBitRate);
1089+
recorder.setVideoEncodingBitRate(8000000);
1090+
recorder.setVideoFrameRate(30);
1091+
Log.d(TAG, profile.videoBitRate + " Bitrate");
10901092

10911093
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
10921094
// int rotation = getWindowManager().getDefaultDisplay().getRotation();
@@ -1099,13 +1101,13 @@ private MediaRecorder setUpMediaRecorder(Surface surface, boolean specifyOutput,
10991101
return recorder;
11001102
}
11011103

1102-
public void setVideoRecording(boolean videoRecording) {
1103-
isVideoRecording = videoRecording;
1104-
}
1105-
1106-
public boolean isVideoRecording() {
1107-
return isVideoRecording;
1108-
}
1104+
// public void setVideoRecording(boolean videoRecording) {
1105+
// isVideoRecording = videoRecording;
1106+
// }
1107+
//
1108+
// public boolean isVideoRecording() {
1109+
// return isVideoRecording;
1110+
// }
11091111

11101112
public void sendFilesToServer(String payload){
11111113
try {
@@ -1118,30 +1120,42 @@ public void sendFilesToServer(String payload){
11181120
File path = new File(videoFilePath);
11191121
File list[] = path.listFiles();
11201122
Map<String,String> postRequestDataMap = new HashMap<>();
1123+
List<Map<String, String>> dataFileList = new ArrayList<Map<String, String>>();
11211124
String filename = "FileNotFound";
1125+
Boolean fileFoundFlag = Boolean.FALSE;
11221126
for(int i=0; i< list.length; i++){
11231127
filename = list[i].getName();
11241128
if(filename.startsWith(payloadParams[1])){
11251129
postRequestDataMap.put("VIDEO_FILE_PATH", videoFilePath + filename);
1126-
break;
1130+
postRequestDataMap.put("CSV_FILE_PATH", csvFilePath + filename.split("\\.")[0] + ".csv" );
1131+
postRequestDataMap.put("CLIENT_ID", clientID);
1132+
postRequestDataMap.put("API_ENDPOINT", payloadParams[0]);
1133+
postRequestDataMap.put("SESSION_PREFIX", payloadParams[1]);
1134+
//new UploadFileToServer().execute(postRequestDataMap);
1135+
Map<String, String> myTempCopyMap = new HashMap<String, String>(postRequestDataMap);
1136+
dataFileList.add(myTempCopyMap);
1137+
postRequestDataMap.clear();
1138+
fileFoundFlag = Boolean.TRUE;
11271139
}
11281140

11291141
}
1130-
if(filename != "FileNotFound"){
1131-
postRequestDataMap.put("CSV_FILE_PATH", csvFilePath + filename.split("\\.")[0] + ".csv" );
1132-
postRequestDataMap.put("CLIENT_ID", clientID);
1133-
postRequestDataMap.put("API_ENDPOINT", payloadParams[0]);
1134-
postRequestDataMap.put("SESSION_PREFIX", payloadParams[1]);
1135-
1136-
new UploadFileToServer().execute(postRequestDataMap);
1137-
}else{
1142+
if(fileFoundFlag==Boolean.FALSE){
1143+
//find a way to show this on the app with a msg
11381144
throw new FileNotFoundException();
1145+
}else{
1146+
new UploadFileToServer().execute(dataFileList);
1147+
//
1148+
// Map<String, String> myMap ;
1149+
// for (int j=0; j<myFileList.size(); j++)
1150+
// {
1151+
// myMap = myFileList.get(j);
1152+
// String val1 = myMap.get("VIDEO_FILE_PATH");
1153+
// String val2 = myMap.get("CSV_FILE_PATH");
1154+
// Log.d(TAG, "VIDEO_FILE_PATH :" + val1 + " CSV_FILE_PATH:"+val2);
1155+
// }
1156+
11391157
}
1140-
for (String name: postRequestDataMap.keySet()) {
1141-
String key = name;
1142-
String value = postRequestDataMap.get(name);
1143-
System.out.println(key + ":" + value);
1144-
}
1158+
11451159

11461160
}catch (Exception e){
11471161
e.printStackTrace();
@@ -1195,7 +1209,11 @@ public void stopVideo() {
11951209
// Switch to preview again
11961210

11971211
//Toast.makeText(this, "Stopped recording video", Toast.LENGTH_LONG).show();
1198-
startPreview();
1212+
1213+
isVideoRecording = false;
1214+
mediaRecorder.stop();
1215+
mLogger.close();
1216+
mLogger = null;
11991217
}
12001218

12011219
private void stopPreview() {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ private void setupSoftwareSync() {
204204
payload -> {
205205
Log.v(TAG, "Stopping video client");
206206
context.runOnUiThread(
207-
context::stopVideo
207+
()->{
208+
context.stopVideo();
209+
context.startPreview();
210+
}
208211
);
209212
});
210213
clientRpcs.put(

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

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
import java.io.IOException;
2222
import java.nio.charset.Charset;
2323
import java.util.ArrayList;
24+
import java.util.List;
2425
import java.util.Map;
2526
import java.net.Proxy.Type.*;
2627

2728
import android.os.AsyncTask;
2829

2930

3031

31-
public class UploadFileToServer extends AsyncTask<Map<String, String>, Integer, String> {
32+
public class UploadFileToServer extends AsyncTask<List<Map<String, String>>, Integer, String> {
3233
@Override
3334
protected void onPreExecute() {
3435
// setting progress bar to zero
@@ -41,12 +42,12 @@ protected void onProgressUpdate(Integer... progress) {
4142
}
4243

4344
@Override
44-
protected String doInBackground(Map<String, String>... postRequestDataMap) {
45+
protected String doInBackground(List<Map<String, String>>... postRequestDataMap) {
4546
return uploadFile(postRequestDataMap[0]);
4647
}
4748

4849
@SuppressWarnings("deprecation")
49-
private String uploadFile(Map<String, String> postRequestDataMap) {
50+
private String uploadFile(List<Map<String, String>> postRequestDataList) {
5051
String responseString = "All Good";
5152
HttpResponse httpResponse;
5253
ArrayList<NameValuePair> postParameters;
@@ -59,38 +60,28 @@ private String uploadFile(Map<String, String> postRequestDataMap) {
5960
// if(postRequestDataMap.get("API_ENDPOINT") != ""){
6061
// endpoint = postRequestDataMap.get("API_ENDPOINT");
6162
// }
63+
Map<String, String> postRequestDataMap ;
64+
for (int j=0; j<postRequestDataList.size(); j++){
65+
postRequestDataMap = postRequestDataList.get(j);
66+
final HttpPost httpPost = new HttpPost(endpoint);
67+
final File video_file = new File(postRequestDataMap.get("VIDEO_FILE_PATH"));
68+
final File csv_file = new File(postRequestDataMap.get("CSV_FILE_PATH"));
69+
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
70+
builder.setMode(HttpMultipartMode.LEGACY);
71+
builder.addPart("file", new FileBody(video_file));
72+
builder.addPart("csv_file", new FileBody(csv_file));
73+
builder.addTextBody("client_id", postRequestDataMap.get("CLIENT_ID"));
74+
builder.addTextBody("session_prefix", postRequestDataMap.get("SESSION_PREFIX"));
75+
76+
HttpEntity entity = builder.build();
77+
httpPost.setEntity(entity);
78+
httpResponse = httpClient.execute(httpPost);
79+
statusCode = httpResponse.getCode();
80+
System.out.println("Response Status:" + statusCode);
81+
System.out.println("FILE UPLOADED");
82+
83+
}
6284

63-
final HttpPost httpPost = new HttpPost(endpoint);
64-
final File video_file = new File(postRequestDataMap.get("VIDEO_FILE_PATH"));
65-
final File csv_file = new File(postRequestDataMap.get("CSV_FILE_PATH"));
66-
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
67-
builder.setMode(HttpMultipartMode.LEGACY);
68-
builder.addPart("file", new FileBody(video_file));
69-
builder.addPart("csv_file", new FileBody(csv_file));
70-
builder.addTextBody("client_id", postRequestDataMap.get("CLIENT_ID"));
71-
builder.addTextBody("session_prefix", postRequestDataMap.get("SESSION_PREFIX"));
72-
73-
// JSONObject jsonObj = new JSONObject();
74-
// try{
75-
// jsonObj.put("client_id", postRequestDataMap.get("CLIENT_ID"));
76-
// jsonObj.put("session_prefix", postRequestDataMap.get("SESSION_PREFIX"));
77-
// }catch(Exception e){
78-
// e.printStackTrace();
79-
// }
80-
//
81-
//// Create the POST object and add the parameters
82-
// StringEntity sentity = new StringEntity(jsonObj.toString(), ContentType.APPLICATION_JSON, "UTF-8", false);
83-
//
84-
//// postParameters = new ArrayList<NameValuePair>();
85-
//// postParameters.add(new BasicNameValuePair("client_id", postRequestDataMap.get("CLIENT_ID")));
86-
//// postParameters.add(new BasicNameValuePair("session_prefix",postRequestDataMap.get("SESSION_PREFIX") ));
87-
// httpPost.setEntity(sentity);
88-
HttpEntity entity = builder.build();
89-
httpPost.setEntity(entity);
90-
httpResponse = httpClient.execute(httpPost);
91-
statusCode = httpResponse.getCode();
92-
System.out.println("Response Status:" + statusCode);
93-
System.out.println("FILE UPLOADED");
9485

9586
} catch (IOException e) {
9687
e.printStackTrace();

fileserver/file_server.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,31 @@ def upload_file():
3434
resp.status_code = 400
3535
return resp
3636

37-
print(request.files)
38-
print(request.form)
3937

38+
session_prefix, client_id = request.form.get("session_prefix"), request.form.get("client_id")
39+
print("Request to upload received from CLIENT:" + client_id +" for session " + session_prefix )
4040

4141
files = request.files.getlist('file')
4242
files.extend(request.files.getlist('csv_file'))
4343
errors = {}
4444
success = False
4545

4646
# create a directory based on session and client id
47-
session_prefix, client_id = request.form.get("session_prefix"), request.form.get("client_id")
4847
directory_path = os.path.join(app.config['UPLOAD_FOLDER'],session_prefix + "/" + client_id + "/")
49-
print(directory_path)
5048
if not os.path.exists(directory_path):
5149
os.makedirs(directory_path)
52-
# import pdb;pdb.set_trace()
50+
5351
for file in files:
5452
if file and allowed_file(file.filename):
5553
filename = secure_filename(file.filename)
54+
print("received file: " + filename + " from CLIENT:" + client_id +" for session " + session_prefix )
5655
file.save(os.path.join(directory_path, filename))
5756
success = True
5857
else:
5958
errors[file.filename] = 'File type is not allowed'
60-
resp = jsonify({'message' : 'Files successfully uploaded'})
59+
resp = jsonify({'message' : 'Files successfully downloaded'})
6160
resp.status_code = 201
6261
return resp
63-
# if success and errors:
64-
# errors['message'] = 'File(s) successfully uploaded'
65-
# resp = jsonify(errors)
66-
# resp.status_code = 500
67-
# return resp
68-
# if success:
69-
# resp = jsonify({'message' : 'Files successfully uploaded'})
70-
# resp.status_code = 201
71-
# return resp
72-
# else:
73-
# resp = jsonify(errors)
74-
# resp.status_code = 500
75-
# return resp
7662

7763
if __name__ == '__main__':
7864
app.run(host='0.0.0.0', port=5000,debug=True)

remote_control/remote_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def setupUi(self, MainWindow):
7878
self.api_input.setGeometry(QtCore.QRect(143, 450, 451, 31))
7979
self.api_input.setObjectName("textEdit")
8080
self.download_prefix_text = QtWidgets.QTextEdit(self.centralwidget)
81-
self.download_prefix_text.setGeometry(QtCore.QRect(280, 80, 161, 31))
81+
self.download_prefix_text.setGeometry(QtCore.QRect(180, 80, 380, 31))
8282
self.download_prefix_text.setObjectName("prefix_text")
8383
self.download_btn = QtWidgets.QPushButton(self.centralwidget)
8484
self.download_btn.setGeometry(QtCore.QRect(280, 380, 161, 61))

0 commit comments

Comments
 (0)