Skip to content

Commit

Permalink
Catch StreamNotOpenedErrors on the handle_start_analysis_error
Browse files Browse the repository at this point in the history
  • Loading branch information
apockill authored Oct 28, 2021
1 parent 23b47af commit 082cfd0
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 181 deletions.
2 changes: 1 addition & 1 deletion brainframe_qt/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.29.0"
__version__ = "0.30.0"
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def _display_ip_camera_help(self):

def _handle_send_stream_conf_error(self, exc: BaseException) -> None:

message_title = self.tr("Error Opening Stream")
message_title = self.tr("Error Configuring Stream")

if isinstance(exc, bf_errors.DuplicateStreamSourceError):
message_desc = self.tr("Stream source already open")
Expand All @@ -658,24 +658,13 @@ def _handle_send_stream_conf_error(self, exc: BaseException) -> None:
f"{message_info}<br><br>" \
f"{error_text}<b>{exc.kind}</b>"

elif isinstance(exc, bf_errors.StreamNotOpenedError):
message_desc = self.tr("Error encountered while opening stream")
error_text = self.tr("Error: ")
message = f"<b>{message_desc}</b>" \
f"<br><br>" \
f"{exc}<br><br>" \
f"{exc.description}<br><br>" \
f"{error_text}<b>{exc.kind}</b>"

elif isinstance(exc, bf_errors.BaseAPIError):
message_desc = self.tr("Error encountered while opening stream")
message_info1 = self.tr("Is stream already open?")
message_info2 = self.tr("Is this a valid stream source?")
message_desc = self.tr("Error encountered with the stream's configuration.")
message_info = self.tr("Is this a valid stream source?")
error_text = self.tr("Error: ")
message = f"<b>{message_desc}</b>" \
f"<br><br>" \
f"{message_info1}<br>" \
f"{message_info2}<br><br>" \
f"{message_info}<br><br>" \
f"{error_text}<b>{exc.kind}</b>"

else:
Expand All @@ -691,6 +680,25 @@ def _handle_start_analysis_error(
self, stream_conf: bf_codecs.StreamConfiguration,
exc: BaseException) \
-> None:
# Delete the buggy stream configuration
api.delete_stream_configuration(stream_conf.id)

source_hints = {
bf_codecs.StreamConfiguration.ConnType.WEBCAM: self.tr(
"Valid camera IDs can be found by running 'sudo ls /dev | grep video'"
),
bf_codecs.StreamConfiguration.ConnType.IP_CAMERA: self.tr(
"There is a problem with the camera url."
),
bf_codecs.StreamConfiguration.ConnType.FILE: self.tr(
"Is the video file a supported format?"
),
}

message_title = self.tr("Error Connecting to Stream")
message_desc = self.tr("Error encountered while opening stream")
error_text = self.tr("Error: ")

if isinstance(exc, bf_errors.AnalysisLimitExceededError):
# Delete the stream configuration, since you almost never want to
# have a stream that can't have analysis running
Expand All @@ -699,20 +707,32 @@ def _handle_start_analysis_error(
.start()

message_title = self.tr("Active Stream Limit Exceeded")
message_desc = self.tr(
message = self.tr(
"You have exceeded the number of active streams available to "
"you under the terms of your license. Consider deleting "
"another stream or contacting Aotu to increase your "
"active stream limit.")

BrainFrameMessage.warning(
parent=self,
title=message_title,
warning=message_desc).exec()
elif isinstance(exc, bf_errors.StreamNotOpenedError):
message = f"<b>{message_desc}</b>" \
f"<br><br>" \
f"{source_hints[stream_conf.connection_type]}<br><br>" \
f"{exc}<br><br>" \
f"{error_text}<b>{exc.kind}</b>"

elif isinstance(exc, bf_errors.BaseAPIError):
message = f"<b>{message_desc}</b>" \
f"<br><br>" \
f"{source_hints[stream_conf.connection_type]}<br><br>" \
f"{error_text}<b>{exc.kind}</b>"
else:
raise exc

BrainFrameMessage.warning(
parent=self,
title=message_title,
warning=message).open()

def _handle_missing_file_error(self, filepath: Path) -> None:
message_title = self.tr("Error uploading file")
message_info = self.tr("No such file: {filepath}") \
Expand Down
51 changes: 38 additions & 13 deletions brainframe_qt/ui/resources/i18n/brainframe_zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ Please recheck the entered server address.</source>
<context>
<name>StreamConfiguration</name>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="650"/>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="296"/>
<source>Error Opening Stream</source>
<translation>打开视频流时出错</translation>
</message>
Expand All @@ -1241,42 +1241,37 @@ Please recheck the entered server address.</source>
<translation>您已经打开了视频流源。</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="674"/>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="700"/>
<source>Error: </source>
<translation>错误: </translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="671"/>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="699"/>
<source>Error encountered while opening stream</source>
<translation>打开视频流时出错</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="672"/>
<source>Is stream already open?</source>
<translation>视频流是否已打开?</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="673"/>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="663"/>
<source>Is this a valid stream source?</source>
<translation>这是一个有效的视频流源吗?</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="701"/>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="709"/>
<source>Active Stream Limit Exceeded</source>
<translation>视频流数量超过上限</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="702"/>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="710"/>
<source>You have exceeded the number of active streams available to you under the terms of your license. Consider deleting another stream or contacting Aotu to increase your active stream limit.</source>
<translation>您已经超出了许可条款下可供使用的最大视频流数量,请考虑删除其他视频流或与Aotu联系以增加最大视频流限制。</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="717"/>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="737"/>
<source>Error uploading file</source>
<translation>上传文件时发生错误</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="718"/>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="738"/>
<source>No such file: {filepath}</source>
<translation>没有这样的文件:{filepath}</translation>
</message>
Expand Down Expand Up @@ -1305,6 +1300,36 @@ Please recheck the entered server address.</source>
<source>Standard RTSP format:&lt;br&gt;{rtsp_format}</source>
<translation>标准RTSP格式:&lt;br&gt;{rtsp_format}</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="662"/>
<source>Error encountered with the stream&apos;s configuration.</source>
<translation>视频流发生错误</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="687"/>
<source>Valid camera IDs can be found by running &apos;sudo ls /dev | grep video&apos;</source>
<translation>可以执行这个命令获得有效的摄像头ID &apos;sudo ls /dev | grep video&apos;</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="690"/>
<source>There is a problem with the camera url.</source>
<translation>摄像头URL有问题</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="693"/>
<source>Is the video file a supported format?</source>
<translation>这个视频文件的格式是可以支持的吗?</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="698"/>
<source>Error Connecting to Stream</source>
<translation>连接视频流发生错误</translation>
</message>
<message>
<location filename="../../main_window/activities/stream_configuration/stream_configuration.py" line="650"/>
<source>Error Configuring Stream</source>
<translation>配置视频流发生错误</translation>
</message>
</context>
<context>
<name>StreamConfigurationUI</name>
Expand Down
Loading

0 comments on commit 082cfd0

Please sign in to comment.