sheave_core/handlers/rtmp_context.rs
1mod last_chunk;
2
3use std::{
4 collections::HashMap,
5 net::SocketAddr,
6 sync::Arc,
7 time::Duration
8};
9use crate::{
10 handshake::{
11 EncryptionAlgorithm,
12 Handshake
13 },
14 messages::{
15 ChunkSize,
16 WindowAcknowledgementSize,
17 PeerBandwidth,
18 PlayMode,
19 amf::v0::{
20 Number,
21 AmfString,
22 Object,
23 EcmaArray
24 }
25 },
26 flv::Flv
27};
28use super::{
29 ClientType,
30 PublisherStatus,
31 SubscriberStatus
32};
33pub use self::last_chunk::*;
34
35/// RTMP's common contexts.
36///
37/// Many fields are optional by default.
38/// Because these data need for both of client and server but are sent/received later.
39/// Therefore the `default` constructor has been prepared instead of such as `new`.
40///
41/// # Examples
42///
43/// ```rust
44/// use sheave_core::handlers::RtmpContext;
45///
46/// // When you create this struct.
47/// RtmpContext::default();
48/// ```
49#[derive(Debug)]
50pub struct RtmpContext {
51 signed: bool,
52 receiving_chunk_size: ChunkSize,
53 sending_chunk_size: ChunkSize,
54 window_acknowledgement_size: WindowAcknowledgementSize,
55 peer_bandwidth: PeerBandwidth,
56 buffer_length: u32,
57 last_transaction_id: Number,
58 topic_database_url: Option<String>,
59 topic_storage_path: Option<String>,
60 client_addr: Option<SocketAddr>,
61 app: Option<AmfString>,
62 topic_path: Option<AmfString>,
63 tc_url: Option<AmfString>,
64 last_command_name: Option<AmfString>,
65 client_type: Option<ClientType>,
66 publisher_status: Option<PublisherStatus>,
67 subscriber_status: Option<SubscriberStatus>,
68 encryption_algorithm: Option<EncryptionAlgorithm>,
69 client_handshake: Option<Handshake>,
70 server_handshake: Option<Handshake>,
71 command_object: Option<Object>,
72 properties: Option<Object>,
73 information: Option<Object>,
74 message_id: Option<u32>,
75 playlist: Option<EcmaArray>,
76 publishing_name: Option<AmfString>,
77 publishing_type: Option<AmfString>,
78 stream_name: Option<AmfString>,
79 start_time: Option<Duration>,
80 play_mode: Option<PlayMode>,
81 await_duration: Option<Duration>,
82 topic: Option<Flv>,
83 last_received_chunks: HashMap<u16, LastChunk>,
84 last_sent_chunks: HashMap<u16, LastChunk>
85}
86
87impl Default for RtmpContext {
88 fn default() -> Self {
89 Self {
90 signed: bool::default(),
91 receiving_chunk_size: ChunkSize::default(),
92 sending_chunk_size: ChunkSize::default(),
93 window_acknowledgement_size: WindowAcknowledgementSize::default(),
94 peer_bandwidth: PeerBandwidth::default(),
95 buffer_length: 30000,
96 last_transaction_id: Number::default(),
97 topic_database_url: Option::default(),
98 topic_storage_path: Option::default(),
99 client_addr: Option::default(),
100 app: Option::default(),
101 topic_path: Option::default(),
102 tc_url: Option::default(),
103 last_command_name: Option::default(),
104 client_type: Option::default(),
105 publisher_status: Option::default(),
106 subscriber_status: Option::default(),
107 encryption_algorithm: Option::default(),
108 client_handshake: Option::default(),
109 server_handshake: Option::default(),
110 command_object: Option::default(),
111 properties: Option::default(),
112 information: Option::default(),
113 message_id: Option::default(),
114 playlist: Option::default(),
115 publishing_name: Option::default(),
116 publishing_type: Option::default(),
117 stream_name: Option::default(),
118 start_time: Option::default(),
119 play_mode: Option::default(),
120 await_duration: Option::default(),
121 topic: Option::default(),
122 last_received_chunks: HashMap::default(),
123 last_sent_chunks: HashMap::default()
124 }
125 }
126}
127
128impl RtmpContext {
129 #[cfg(windows)]
130 /// The token of directory separator in Windows environment.
131 pub const DIRECTORY_SEPARATOR: &str = "\\";
132 #[cfg(unix)]
133 /// The token of directory separator in Linux/Unix environment.
134 pub const DIRECTORY_SEPARATOR: &str = "/";
135
136 /// Gets a mutable reference via this wrapped by `Arc`.
137 /// Sheave uses this after wrapping into `Arc`.
138 /// Because of making this shareable between every handling steps.
139 pub fn make_weak_mut<'a>(self: &'a Arc<Self>) -> &'a mut Self {
140 unsafe { &mut *(Arc::downgrade(self).as_ptr() as *mut Self) }
141 }
142
143 /// Stores a flag to mean this handshake is signed.
144 pub fn set_signed(&mut self, signed: bool) {
145 self.signed = signed;
146 }
147
148 /// Indicates whether the handshake is signed.
149 pub fn is_signed(&mut self) -> bool {
150 self.signed
151 }
152
153 /// Sets a chunking size which reads from streams.
154 pub fn set_receiving_chunk_size(&mut self, chunk_size: ChunkSize) {
155 self.receiving_chunk_size = chunk_size;
156 }
157
158 /// Gets a chunking size which reads from streams.
159 pub fn get_receiving_chunk_size(&mut self) -> ChunkSize {
160 self.receiving_chunk_size
161 }
162
163 /// Sets a chunking size which writes into streams.
164 pub fn set_sending_chunk_size(&mut self, chunk_size: ChunkSize) {
165 self.sending_chunk_size = chunk_size;
166 }
167
168 /// Gets a chunkign size which writes into stream.
169 pub fn get_sending_chunk_size(&mut self) -> ChunkSize {
170 self.sending_chunk_size
171 }
172
173 /// Sets the window acknowledgement size.
174 pub fn set_window_acknowledgement_size(&mut self, window_acknowledgement_size: WindowAcknowledgementSize) {
175 self.window_acknowledgement_size = window_acknowledgement_size;
176 }
177
178 /// Gets the window acknowledgement size.
179 pub fn get_window_acknowledgement_size(&mut self) -> WindowAcknowledgementSize {
180 self.window_acknowledgement_size
181 }
182
183 /// Sets the peer bandwidth.
184 pub fn set_peer_bandwidth(&mut self, peer_bandwidth: PeerBandwidth) {
185 self.peer_bandwidth = peer_bandwidth;
186 }
187
188 /// Gets the peer bandwidth.
189 pub fn get_peer_bandwidth(&mut self) -> PeerBandwidth {
190 self.peer_bandwidth
191 }
192
193 /// Sets the buffer length.
194 pub fn set_buffer_length(&mut self, buffer_length: u32) {
195 self.buffer_length = buffer_length;
196 }
197
198 /// Gets the buffer length.
199 pub fn get_buffer_length(&mut self) -> u32 {
200 self.buffer_length
201 }
202
203 /// Sets a transaction ID.
204 /// Mainly, this is used by server side contexts.
205 /// Because of servers should echo same transaction ID in its response.
206 pub fn set_transaction_id(&mut self, transaction_id: Number) {
207 self.last_transaction_id = transaction_id;
208 }
209
210 /// Gets a transaction ID sent.
211 pub fn get_transaction_id(&mut self) -> Number {
212 self.last_transaction_id
213 }
214
215 /// Increases current transaction ID.
216 /// Mainly, this is used by client side contexts.
217 /// Because of clients should count which transaction is it now on.
218 pub fn increase_transaction_id(&mut self) {
219 self.last_transaction_id += 1f64;
220 }
221
222 /// Sets the topic database url.
223 pub fn set_topic_database_url(&mut self, topic_database_url: &str) {
224 self.topic_database_url = Some(topic_database_url.into());
225 }
226
227 /// Gets the topic database url.
228 /// Note this can return `None`. e.g. When this field is default as it is.
229 ///
230 /// # Examples
231 ///
232 /// ```rust
233 /// use sheave_core::handlers::RtmpContext;
234 ///
235 /// let mut rtmp_context = RtmpContext::default();
236 /// assert!(rtmp_context.get_topic_database_url().is_none())
237 /// ```
238 pub fn get_topic_database_url(&mut self) -> Option<&String> {
239 self.topic_database_url.as_ref()
240 }
241
242 /// Sets the topic storage path.
243 pub fn set_topic_storage_path(&mut self, topic_storage_path: &str) {
244 self.topic_storage_path = Some(topic_storage_path.into());
245 }
246
247 /// Gets the topic storage path.
248 /// Note this can return `None`. e.g. When this field is default as it is.
249 ///
250 /// # Examples
251 ///
252 /// ```rust
253 /// use sheave_core::handlers::RtmpContext;
254 ///
255 /// let mut rtmp_context = RtmpContext::default();
256 /// assert!(rtmp_context.get_topic_storage_path().is_none())
257 /// ```
258 pub fn get_topic_storage_path(&mut self) -> Option<&String> {
259 self.topic_storage_path.as_ref()
260 }
261
262 /// Sets a client IP address.
263 pub fn set_client_addr(&mut self, client_addr: SocketAddr) {
264 self.client_addr = Some(client_addr);
265 }
266
267 /// Gets a client IP address.
268 /// Note this can return `None`. e.g. When this field is default as it is.
269 ///
270 /// # Examples
271 ///
272 /// ```rust
273 /// use sheave_core::handlers::RtmpContext;
274 ///
275 /// let mut rtmp_context = RtmpContext::default();
276 /// assert!(rtmp_context.get_client_addr().is_none())
277 /// ```
278 pub fn get_client_addr(&mut self) -> Option<SocketAddr> {
279 self.client_addr
280 }
281
282 /// Sets the `app` name.
283 /// This can be contained in a request URI of RTMP.
284 pub fn set_app(&mut self, app: &str) {
285 self.app = Some(AmfString::from(app));
286 }
287
288 /// Gets the `app` name.
289 /// Note this can return `None`. e.g. When this field is default as it is.
290 ///
291 /// # Examples
292 ///
293 /// ```rust
294 /// use sheave_core::handlers::RtmpContext;
295 ///
296 /// let mut rtmp_context = RtmpContext::default();
297 /// assert!(rtmp_context.get_app().is_none())
298 /// ```
299 pub fn get_app(&mut self) -> Option<&AmfString> {
300 self.app.as_ref()
301 }
302
303 /// Sets a `topic_path` (e.g. filename) sent from a client.
304 pub fn set_topic_path(&mut self, topic_path: AmfString) {
305 self.topic_path = Some(topic_path);
306 }
307
308 /// Resets a `topic_path` from this context.
309 /// This is prepared for deleting a `topic_path` when receives the `FCUnpublish` command.
310 pub fn reset_topic_path(&mut self) {
311 self.topic_path = None;
312 }
313
314 /// Gets a `topic_path` (e.g. filename) sent from a client.
315 /// Note this can return `None`. e.g. When this field is default as it is.
316 ///
317 /// # Examples
318 ///
319 /// ```rust
320 /// use sheave_core::handlers::RtmpContext;
321 ///
322 /// let mut rtmp_context = RtmpContext::default();
323 /// assert!(rtmp_context.get_topic_path().is_none())
324 /// ```
325 pub fn get_topic_path(&mut self) -> Option<&AmfString> {
326 self.topic_path.as_ref()
327 }
328
329 /// Sets the `tcUrl`. This is a full URL in the RTMP request like following form.
330 ///
331 /// `rtmp://hostname/[app]/[topic_path]`
332 ///
333 /// Where `app` and `topic_path` can be unspecified.
334 /// Clients specify above URL at the start of RTMP requests.
335 /// Then the server checks `app` and `topic_path` in client-side `Connect` commands (if they are specified).
336 pub fn set_tc_url(&mut self, tc_url: &str) {
337 self.tc_url = Some(AmfString::from(tc_url));
338 }
339
340 /// Gets the `tcUrl`.
341 /// Note this can return `None`. e.g. When this field is default as it is.
342 ///
343 /// # Examples
344 ///
345 /// ```rust
346 /// use sheave_core::handlers::RtmpContext;
347 ///
348 /// let mut rtmp_context = RtmpContext::default();
349 /// assert!(rtmp_context.get_tc_url().is_none())
350 /// ```
351 pub fn get_tc_url(&mut self) -> Option<&AmfString> {
352 self.tc_url.as_ref()
353 }
354
355 /// Sets last command name.
356 pub fn set_command_name(&mut self, command_name: AmfString) {
357 self.last_command_name = Some(command_name);
358 }
359
360 /// Gets last command name.
361 /// Note this can return `None`. e.g. When this field is default as it is.
362 ///
363 /// # Examples
364 ///
365 /// ```rust
366 /// use sheave_core::handlers::RtmpContext;
367 ///
368 /// let mut rtmp_context = RtmpContext::default();
369 /// assert!(rtmp_context.get_command_name().is_none())
370 /// ```
371 pub fn get_command_name(&mut self) -> Option<&AmfString> {
372 self.last_command_name.as_ref()
373 }
374
375 /// Sets that its client is either publisher or subscriber.
376 /// Curently, the server distinguishes this by referring specific field in a command object which a connect command has.
377 /// e.g. "fpad", "capabilities" etc.
378 pub fn set_client_type(&mut self, client_type: ClientType) {
379 self.client_type = Some(client_type);
380 }
381
382 /// Gets the type that its client is which either publisher or subscriber.
383 /// Note this can return `None`. e.g. When this field is default as it is.
384 ///
385 /// # Examples
386 ///
387 /// ```rust
388 /// use sheave_core::handlers::RtmpContext;
389 ///
390 /// let mut rtmp_context = RtmpContext::default();
391 /// assert!(rtmp_context.get_client_type().is_none())
392 /// ```
393 pub fn get_client_type(&mut self) -> Option<ClientType> {
394 self.client_type
395 }
396
397 /// Sets one of publisher's status.
398 pub fn set_publisher_status(&mut self, publisher_status: PublisherStatus) {
399 self.publisher_status = Some(publisher_status);
400 }
401
402 /// Gets one of publisher's status.
403 /// Note this can return `None`. e.g. When this field is default as it is.
404 ///
405 /// # Examples
406 ///
407 /// ```rust
408 /// use sheave_core::handlers::RtmpContext;
409 ///
410 /// let mut rtmp_context = RtmpContext::default();
411 /// assert!(rtmp_context.get_publisher_status().is_none())
412 /// ```
413 pub fn get_publisher_status(&mut self) -> Option<PublisherStatus> {
414 self.publisher_status
415 }
416
417 /// Sets one of subscriber's status.
418 pub fn set_subscriber_status(&mut self, subscriber_status: SubscriberStatus) {
419 self.subscriber_status = Some(subscriber_status);
420 }
421
422 /// Gets one of subscriber's status.
423 /// Note this can return `None`. e.g. When this field is default as it is.
424 ///
425 /// # Examples
426 ///
427 /// ```rust
428 /// use sheave_core::handlers::RtmpContext;
429 ///
430 /// let mut rtmp_context = RtmpContext::default();
431 /// assert!(rtmp_context.get_subscriber_status().is_none())
432 /// ```
433 pub fn get_subscriber_status(&mut self) -> Option<SubscriberStatus> {
434 self.subscriber_status
435 }
436
437 /// Stores the algorithm to encrypt this handshake.
438 pub fn set_encryption_algorithm(&mut self, encryption_algorithm: EncryptionAlgorithm) {
439 self.encryption_algorithm = Some(encryption_algorithm);
440 }
441
442 /// Gets specieifed algorithm to encrypt this handshake.
443 /// Note this can return `None`. e.g. When this field is default as it is.
444 ///
445 /// # Examples
446 ///
447 /// ```rust
448 /// use sheave_core::handlers::RtmpContext;
449 ///
450 /// let mut rtmp_context = RtmpContext::default();
451 /// assert!(rtmp_context.get_encryption_algorithm().is_none())
452 /// ```
453 pub fn get_encryption_algorithm(&mut self) -> Option<EncryptionAlgorithm> {
454 self.encryption_algorithm
455 }
456
457 /// Stores a cleint-side handshake bytes.
458 pub fn set_client_handshake(&mut self, handshake: Handshake) {
459 self.client_handshake = Some(handshake);
460 }
461
462 /// Gets a client-side handshake bytes.
463 /// Note this can return `None`. e.g. When this field is default as it is.
464 ///
465 /// # Examples
466 ///
467 /// ```rust
468 /// use sheave_core::handlers::RtmpContext;
469 ///
470 /// let mut rtmp_context = RtmpContext::default();
471 /// assert!(rtmp_context.get_client_handshake().is_none())
472 /// ```
473 pub fn get_client_handshake(&mut self) -> Option<&Handshake> {
474 self.client_handshake.as_ref()
475 }
476
477 /// Gets a client-side handshake bytes as mutable.
478 /// Note:
479 ///
480 /// * This is currently used for only testing (also intagration tests contained).
481 /// * This can return `None`. e.g. When this field is default as it is.
482 ///
483 /// # Examples
484 ///
485 /// ```rust
486 /// use sheave_core::handlers::RtmpContext;
487 ///
488 /// let mut rtmp_context = RtmpContext::default();
489 /// assert!(rtmp_context.get_client_handshake_mut().is_none())
490 /// ```
491 pub fn get_client_handshake_mut(&mut self) -> Option<&mut Handshake> {
492 self.client_handshake.as_mut()
493 }
494
495 /// Stores a server-side handshake bytes.
496 pub fn set_server_handshake(&mut self, handshake: Handshake) {
497 self.server_handshake = Some(handshake);
498 }
499
500 /// Gets a server-side handshake bytes.
501 /// Note this can return `None`. e.g. When this field is default as it is.
502 ///
503 /// # Examples
504 ///
505 /// ```rust
506 /// use sheave_core::handlers::RtmpContext;
507 ///
508 /// let mut rtmp_context = RtmpContext::default();
509 /// assert!(rtmp_context.get_server_handshake().is_none())
510 /// ```
511 pub fn get_server_handshake(&mut self) -> Option<&Handshake> {
512 self.server_handshake.as_ref()
513 }
514
515 /// Sets a command object sent from a client.
516 pub fn set_command_object(&mut self, command_object: Object) {
517 self.command_object = Some(command_object);
518 }
519
520 /// Gets a command object sent from a client.
521 /// Note this can return `None`. e.g. When this field is default as it is.
522 ///
523 /// # Examples
524 ///
525 /// ```rust
526 /// use sheave_core::handlers::RtmpContext;
527 ///
528 /// let mut rtmp_context = RtmpContext::default();
529 /// assert!(rtmp_context.get_command_object().is_none())
530 /// ```
531 pub fn get_command_object(&mut self) -> Option<&Object> {
532 self.command_object.as_ref()
533 }
534
535 /// Sets a properties object of a server.
536 pub fn set_properties(&mut self, properties: Object) {
537 self.properties = Some(properties);
538 }
539
540 /// Gets a properties object of a server.
541 /// Note this can return `None`. e.g. When this field is dafault as it is.
542 ///
543 /// # Examples
544 ///
545 /// ```rust
546 /// use sheave_core::handlers::RtmpContext;
547 ///
548 /// let mut rtmp_context = RtmpContext::default();
549 /// assert!(rtmp_context.get_properties().is_none())
550 /// ```
551 pub fn get_properties(&mut self) -> Option<&Object> {
552 self.properties.as_ref()
553 }
554
555 /// Sets a information object of a server.
556 pub fn set_information(&mut self, information: Object) {
557 self.information = Some(information);
558 }
559
560 /// Gets a information object of a server.
561 /// Note this can return `None`. e.g. When this field is default as it is.
562 ///
563 /// # Examples
564 ///
565 /// ```rust
566 /// use sheave_core::handlers::RtmpContext;
567 ///
568 /// let mut rtmp_context = RtmpContext::default();
569 /// assert!(rtmp_context.get_information().is_none())
570 /// ```
571 pub fn get_information(&mut self) -> Option<&Object> {
572 self.information.as_ref()
573 }
574
575 /// Sets a message ID of this stream.
576 pub fn set_message_id(&mut self, message_id: u32) {
577 self.message_id = Some(message_id);
578 }
579
580 /// Resets a message ID from this context.
581 /// This is prepared for deleting tne `message_id` when receives the `deleteStream` command.
582 pub fn reset_message_id(&mut self) {
583 self.message_id = None;
584 }
585
586 /// Gets a message ID of this stream.
587 /// Note this can return `None`. e.g. When this field is default as it is.
588 ///
589 /// # Examples
590 ///
591 /// ```rust
592 /// use sheave_core::handlers::RtmpContext;
593 ///
594 /// let mut rtmp_context = RtmpContext::default();
595 /// assert!(rtmp_context.get_message_id().is_none())
596 /// ```
597 pub fn get_message_id(&mut self) -> Option<u32> {
598 self.message_id
599 }
600
601 /// Sets a Playlist.
602 ///
603 /// Currently, this is sent from several client like OBS.
604 pub fn set_playlist(&mut self, playlist: EcmaArray) {
605 self.playlist = Some(playlist);
606 }
607
608 /// Gets a playlist.
609 /// Note this can return `None`. e.g. When this field is default as it is.
610 ///
611 /// # Examples
612 ///
613 /// ```rust
614 /// use sheave_core::handlers::RtmpContext;
615 ///
616 /// let mut rtmp_context = RtmpContext::default();
617 /// assert!(rtmp_context.get_playlist().is_none())
618 /// ```
619 ///
620 /// Currently, this is sent from several client like OBS.
621 pub fn get_playlist(&mut self) -> Option<&EcmaArray> {
622 self.playlist.as_ref()
623 }
624
625 /// Sets a publishing name of this stream.
626 pub fn set_publishing_name(&mut self, publishing_name: AmfString) {
627 self.publishing_name = Some(publishing_name);
628 }
629
630 /// Gets a publishing name of this stream.
631 /// Note this can return `None`. e.g. When this field is default as it is.
632 ///
633 /// # Examples
634 ///
635 /// ```rust
636 /// use sheave_core::handlers::RtmpContext;
637 ///
638 /// let mut rtmp_context = RtmpContext::default();
639 /// assert!(rtmp_context.get_publishing_name().is_none())
640 /// ```
641 pub fn get_publishing_name(&mut self) -> Option<&AmfString> {
642 self.publishing_name.as_ref()
643 }
644
645 /// Sets a publishing type of this stream.
646 pub fn set_publishing_type(&mut self, publishing_type: AmfString) {
647 self.publishing_type = Some(publishing_type);
648 }
649
650 /// Gets a publishing type of this stream.
651 /// Note this can return `None`. e.g. When this field is default as it is.
652 ///
653 /// # Examples
654 ///
655 /// ```rust
656 /// use sheave_core::handlers::RtmpContext;
657 ///
658 /// let mut rtmp_context = RtmpContext::default();
659 /// assert!(rtmp_context.get_publishing_type().is_none())
660 /// ```
661 pub fn get_publishing_type(&mut self) -> Option<&AmfString> {
662 self.publishing_type.as_ref()
663 }
664
665 /// Sets a stream name of this stream.
666 pub fn set_stream_name(&mut self, stream_name: AmfString) {
667 self.stream_name = Some(stream_name);
668 }
669
670 /// Gets a stream name of this stream.
671 /// Note this can return `None`. e.g. When this field is default as it is.
672 ///
673 /// # Examples
674 ///
675 /// ```rust
676 /// use sheave_core::handlers::RtmpContext;
677 ///
678 /// let mut rtmp_context = RtmpContext::default();
679 /// assert!(rtmp_context.get_stream_name().is_none())
680 /// ```
681 pub fn get_stream_name(&mut self) -> Option<&AmfString> {
682 self.stream_name.as_ref()
683 }
684
685 /// Sets a start time of this stream.
686 pub fn set_start_time(&mut self, start_time: Duration) {
687 self.start_time = Some(start_time);
688 }
689
690 /// Gets a start time of this stream.
691 /// Note this can return `None`. e.g. When this field is default as it is.
692 ///
693 /// # Examples
694 ///
695 /// ```rust
696 /// use sheave_core::handlers::RtmpContext;
697 ///
698 /// let mut rtmp_context = RtmpContext::default();
699 /// assert!(rtmp_context.get_start_time().is_none())
700 /// ```
701 pub fn get_start_time(&mut self) -> Option<Duration> {
702 self.start_time
703 }
704
705 /// Sets a play mode of this stream.
706 pub fn set_play_mode(&mut self, play_mode: PlayMode) {
707 self.play_mode = Some(play_mode);
708 }
709
710 /// Gets a play mode of this stream.
711 /// Note this can return `None`. e.g. When this field is default as it is.
712 ///
713 /// # Examples
714 ///
715 /// ```rust
716 /// use sheave_core::handlers::RtmpContext;
717 ///
718 /// let mut rtmp_context = RtmpContext::default();
719 /// assert!(rtmp_context.get_play_mode().is_none())
720 /// ```
721 pub fn get_play_mode(&mut self) -> Option<PlayMode> {
722 self.play_mode
723 }
724
725 /// Sets a duration for awaiting of receiving some message.
726 ///
727 /// Currently, this is used only clients during publishing audio/video data.
728 pub fn set_await_duration(&mut self, await_duration: Duration) {
729 self.await_duration = Some(await_duration);
730 }
731
732 /// Gets a duration for awaiting of receiving some message.
733 ///
734 /// Currently, this is used only clients during publishing audio/video data.
735 pub fn get_await_duration(&mut self) -> Option<Duration> {
736 self.await_duration
737 }
738
739 /// Sets a topic file/device.
740 pub fn set_topic(&mut self, topic: Flv) {
741 self.topic = Some(topic);
742 }
743
744 /// Gets a topic file/device.
745 /// Note this can return `None`. e.g. When this field is default as it is.
746 ///
747 /// # Examples
748 ///
749 /// ```rust
750 /// use sheave_core::handlers::RtmpContext;
751 ///
752 /// let mut rtmp_context = RtmpContext::default();
753 /// assert!(rtmp_context.get_topic().is_none())
754 /// ```
755 pub fn get_topic(&mut self) -> Option<&Flv> {
756 self.topic.as_ref()
757 }
758
759 /// Gets a topic file/device as mutable.
760 /// Note this can return `None`. e.g. When it is the default as is.
761 ///
762 /// # Examples
763 ///
764 /// ```rust
765 /// use sheave_core::handlers::RtmpContext;
766 ///
767 /// let mut rtmp_context = RtmpContext::default();
768 /// assert!(rtmp_context.get_topic_mut().is_none())
769 /// ```
770 pub fn get_topic_mut(&mut self) -> Option<&mut Flv> {
771 self.topic.as_mut()
772 }
773
774 /// Stores a last received chunk.
775 pub fn insert_received_chunk(&mut self, chunk_id: u16, last_chunk: LastChunk) {
776 self.last_received_chunks.insert(chunk_id, last_chunk);
777 }
778
779 /// Loads a last received chunk.
780 /// If no last chunk is stored associated with specified ID, this returns `None`.
781 ///
782 /// # Examples
783 ///
784 /// ```rust
785 /// use sheave_core::{
786 /// handlers::RtmpContext,
787 /// messages::Channel
788 /// };
789 ///
790 /// let mut rtmp_context = RtmpContext::default();
791 /// assert!(rtmp_context.get_last_received_chunk(&Channel::System.into()).is_none())
792 /// ```
793 pub fn get_last_received_chunk(&mut self, chunk_id: &u16) -> Option<&LastChunk> {
794 self.last_received_chunks.get(chunk_id)
795 }
796
797 /// Loads a last received chunk as mutable.
798 /// If no last chunk is stored associated with specified ID, this returns `None`.
799 ///
800 /// # Examples
801 ///
802 /// ```rust
803 /// use sheave_core::{
804 /// handlers::RtmpContext,
805 /// messages::Channel
806 /// };
807 ///
808 /// let mut rtmp_context = RtmpContext::default();
809 /// assert!(rtmp_context.get_last_received_chunk_mut(&Channel::System.into()).is_none())
810 /// ```
811 pub fn get_last_received_chunk_mut(&mut self, chunk_id: &u16) -> Option<&mut LastChunk> {
812 self.last_received_chunks.get_mut(chunk_id)
813 }
814
815 /// Stores a last sent chunk.
816 pub fn insert_sent_chunk(&mut self, chunk_id: u16, last_chunk: LastChunk) {
817 self.last_sent_chunks.insert(chunk_id, last_chunk);
818 }
819
820 /// Loads a last sent chunk.
821 /// If no last chunk is stored associated with specified ID, this returns `None`.
822 ///
823 /// # Examples
824 ///
825 /// ```rust
826 /// use sheave_core::{
827 /// handlers::RtmpContext,
828 /// messages::Channel
829 /// };
830 ///
831 /// let mut rtmp_context = RtmpContext::default();
832 /// assert!(rtmp_context.get_last_sent_chunk(&Channel::System.into()).is_none())
833 /// ```
834 pub fn get_last_sent_chunk(&mut self, chunk_id: &u16) -> Option<&LastChunk> {
835 self.last_sent_chunks.get(chunk_id)
836 }
837
838 /// Loads a last sent chunk as mutable.
839 /// If no last chunk is stored associated with specified ID, this returns `None`.
840 ///
841 /// # Examples
842 ///
843 /// ```rust
844 /// use sheave_core::{
845 /// handlers::RtmpContext,
846 /// messages::Channel
847 /// };
848 ///
849 /// let mut rtmp_context = RtmpContext::default();
850 /// assert!(rtmp_context.get_last_sent_chunk_mut(&Channel::System.into()).is_none())
851 /// ```
852 pub fn get_last_sent_chunk_mut(&mut self, chunk_id: &u16) -> Option<&mut LastChunk> {
853 self.last_sent_chunks.get_mut(chunk_id)
854 }
855}