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