scanner: More adaptive frame upload
This commit is contained in:
parent
4f6f97a784
commit
3010ee3657
@ -48,6 +48,9 @@ Page({
|
||||
frame_upload_seq_num: 0,
|
||||
qrarc_class: "sm",
|
||||
qrmarkers_class: "hidden",
|
||||
frame_upload_in_flight: 0,
|
||||
frame_upload_time_cost: 0,
|
||||
frame_upload_interval_ms: 2000,
|
||||
},
|
||||
|
||||
make_hint_text(r) {
|
||||
@ -365,15 +368,18 @@ Page({
|
||||
}
|
||||
},
|
||||
handle_image_data_url(data_url) {
|
||||
return;
|
||||
const now = Date.now();
|
||||
const interval_ms = 2000;
|
||||
if (now - this.data.last_frame_upload_time < interval_ms) {
|
||||
if (
|
||||
now - this.data.last_frame_upload_time < this.data.frame_upload_interval_ms ||
|
||||
this.data.frame_upload_in_flight > 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
var begin = Date.now();
|
||||
this.setData({
|
||||
last_frame_upload_time: now,
|
||||
frame_upload_seq_num: this.data.frame_upload_seq_num + 1,
|
||||
frame_upload_in_flight: this.data.frame_upload_in_flight + 1,
|
||||
});
|
||||
var seq_num = this.data.frame_upload_seq_num.toString().padStart(3, '0');
|
||||
var fd = {
|
||||
@ -383,16 +389,27 @@ Page({
|
||||
image_data_url: data_url,
|
||||
}
|
||||
wx.request({
|
||||
url: getApp().globalData.server_url + '/api/v1/camera-frame/',
|
||||
url: "https://research.themblem.com/event/camera-frame",
|
||||
method: "POST",
|
||||
data: fd,
|
||||
data: JSON.stringify(fd),
|
||||
header: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
success: (res) => {
|
||||
this.setData({
|
||||
frame_uploaded: this.data.frame_uploaded + 1,
|
||||
frame_upload_in_flight: this.data.frame_upload_in_flight - 1,
|
||||
frame_upload_time_cost: Date.now() - begin,
|
||||
frame_upload_interval_ms: this.data.frame_upload_interval_ms * 2,
|
||||
});
|
||||
},
|
||||
fail: (e) => {
|
||||
this.log("frame upload failed", e);
|
||||
this.setData({
|
||||
frame_upload_in_flight: this.data.frame_upload_in_flight - 1,
|
||||
frame_upload_time_cost: Date.now() - begin,
|
||||
frame_upload_interval_ms: this.data.frame_upload_interval_ms * 2,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<view>model: {{ phone_model }}</view>
|
||||
<view>zoom: {{ zoom }}</view>
|
||||
<view>sensitivity: {{ camera_sensitivity }}</view>
|
||||
<view>frame uploaded: {{ frame_uploaded }}</view>
|
||||
<view>frame uploaded: {{ frame_uploaded }} (upload cost {{ frame_upload_time_cost }}ms)</view>
|
||||
<view>max zoom: {{ max_zoom }}</view>
|
||||
<view>result: {{ result }}</view>
|
||||
</view>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user