Add stream stop message

This commit is contained in:
QuantumEntangledAndy committed 2022-06-21 11:04:27 +07:00
1 parent 83ea1b4edd
commit 4bfb9738cb
3 files changed
+79 -2

No files matched your search

+2
View File
@@ -10,6 +10,8 @@ pub const MSG_ID_LOGIN: u32 = 1;
pub const MSG_ID_LOGOUT: u32 = 2;
/// Video and Audio Streams messages have this ID
pub const MSG_ID_VIDEO: u32 = 3;
/// Video and Audio Streams messages have this ID when a stop is requested
pub const MSG_ID_VIDEO_STOP: u32 = 4;
/// TalkAbility messages have this ID
pub const MSG_ID_TALKABILITY: u32 = 10;
/// TalkReset messages have this ID
@@ -14,8 +14,8 @@ use std::thread::JoinHandle;
use std::time::{Duration, Instant};
/// A shareable connection to a camera. Handles serialization of messages. To send/receive, call
/// .[subscribe()] with a message ID. You can use the BcSubscription to send or receive only
/// messages with that ID; each incoming message is routed to its appropriate subscriber.
/// .[subscribe()] with a message number. You can use the BcSubscription to send or receive only
/// messages with that number; each incoming message is routed to its appropriate subscriber.
///
/// There can be only one subscriber per kind of message at a time.
pub struct BcConnection {
+75
View File
@@ -123,4 +123,79 @@ impl BcCamera {
data_outs.write(bc_media)?;
}
}
/// Stop a camera from sending more stream data.
pub fn stop_video(&self, stream: Stream) -> Result<()> {
let connection = self
.connection
.as_ref()
.expect("Must be connected to stop video");
let msg_num = self.new_message_num();
let sub_video = connection.subscribe(msg_num)?;
// On an E1 and swann cameras:
// - mainStream always has a value of 0
// - subStream always has a value of 1
// - There is no externStram
// On a B800:
// - mainStream is 0
// - subStream is 0
// - externStream is 0
let stream_code = match stream {
Stream::Main => 0,
Stream::Sub => 1,
Stream::Extern => 0,
};
// Theses are the numbers used with the offical client
// On an E1 and swann cameras:
// - mainStream always has a value of 0
// - subStream always has a value of 1
// - There is no externStram
// On a B800:
// - mainStream is 0
// - subStream is 256
// - externStram is 1024
let handle = match stream {
Stream::Main => 0,
Stream::Sub => 256,
Stream::Extern => 1024,
};
let stream_name = match stream {
Stream::Main => "mainStream",
Stream::Sub => "subStream",
Stream::Extern => "externStream",
}
.to_string();
let stop_video = Bc::new_from_xml(
BcMeta {
msg_id: MSG_ID_VIDEO_STOP,
channel_id: self.channel_id,
msg_num,
stream_type: stream_code,
response_code: 0,
class: 0x6414, // IDK why
},
BcXml {
preview: Some(Preview {
version: xml_ver(),
channel_id: self.channel_id,
handle,
stream_type: stream_name,
}),
..Default::default()
},
);
sub_video.send(stop_video)?;
let reply = sub_video.rx.recv_timeout(crate::RX_TIMEOUT)?;
if reply.meta.response_code != 200 {
return Err(super::Error::CameraServiceUnavaliable);
}
Ok(())
}
}