1 /* GStreamer RTP Manager
2 *
3 * Copyright 2007 Collabora Ltd,
4 * Copyright 2007 Nokia Corporation
5 * @author: Philippe Kalaf <philippe.kalaf@collabora.co.uk>.
6 * Copyright 2007 Wim Taymans <wim.taymans@gmail.com>
7 * Copyright 2015 Kurento (http://kurento.org/)
8 * @author: Miguel París <mparisdiaz@gmail.com>
9 * Copyright 2016 Pexip AS
10 * @author: Havard Graff <havard@pexip.com>
11 * @author: Stian Selnes <stian@pexip.com>
12 * Copyright (C) 2019 Net Insight AB
13 * Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Library General Public
17 * License as published by the Free Software Foundation; either
18 * version 2 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Library General Public License for more details.
24 *
25 * You should have received a copy of the GNU Library General Public
26 * License along with this library; if not, write to the
27 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
28 * Boston, MA 02110-1301, USA.
29 */
30
31 #include <gst/gst.h>
32
33 #ifndef __RTP_TIMER_QUEUE_H__
34 #define __RTP_TIMER_QUEUE_H__
35
36 #define RTP_TYPE_TIMER_QUEUE rtp_timer_queue_get_type()
37 G_DECLARE_FINAL_TYPE (RtpTimerQueue, rtp_timer_queue, RTP_TIMER, QUEUE, GObject);
38
39 /**
40 * RtpTimerType:
41 * @RTP_TIMER_EXPECTED: This is used to track when to emit retranmission
42 * requests. They may be converted into %RTP_TIMER_LOST
43 * timer if the number of retry has been exhausted.
44 * @RTP_TIMER_LOST: This is used to track when a packet is considered lost.
45 * @RTP_TIMER_DEADLINE: This is used to track when the jitterbuffer should
46 * start pushing buffers.
47 * @RTP_TIMER_EOS: This is used to track when end of stream is reached.
48 */
49 typedef enum
50 {
51 RTP_TIMER_EXPECTED,
52 RTP_TIMER_LOST,
53 RTP_TIMER_DEADLINE,
54 RTP_TIMER_EOS
55 } RtpTimerType;
56
57 typedef struct
58 {
59 GList list;
60 gboolean queued;
61
62 guint16 seqnum;
63 RtpTimerType type;
64 GstClockTime timeout;
65 GstClockTimeDiff offset;
66 GstClockTime duration;
67 GstClockTime rtx_base;
68 GstClockTime rtx_last;
69 guint num_rtx_retry;
70 guint num_rtx_received;
71 } RtpTimer;
72
73 void rtp_timer_free (RtpTimer * timer);
74 RtpTimer * rtp_timer_dup (const RtpTimer * timer);
75
rtp_timer_get_next(RtpTimer * timer)76 static inline RtpTimer * rtp_timer_get_next (RtpTimer * timer)
77 {
78 GList *list = (GList *) timer;
79 return (RtpTimer *) list->next;
80 }
81
rtp_timer_get_prev(RtpTimer * timer)82 static inline RtpTimer * rtp_timer_get_prev (RtpTimer * timer)
83 {
84 GList *list = (GList *) timer;
85 return (RtpTimer *) list->prev;
86 }
87
88 RtpTimerQueue * rtp_timer_queue_new (void);
89
90 RtpTimer * rtp_timer_queue_find (RtpTimerQueue * queue, guint seqnum);
91
92 RtpTimer * rtp_timer_queue_peek_earliest (RtpTimerQueue * queue);
93
94 gboolean rtp_timer_queue_insert (RtpTimerQueue * queue, RtpTimer * timer);
95
96 gboolean rtp_timer_queue_reschedule (RtpTimerQueue * queue, RtpTimer * timer);
97
98 void rtp_timer_queue_unschedule (RtpTimerQueue * queue, RtpTimer * timer);
99
100 RtpTimer * rtp_timer_queue_pop_until (RtpTimerQueue * queue, GstClockTime timeout);
101
102 void rtp_timer_queue_remove_until (RtpTimerQueue * queue, GstClockTime timeout);
103
104 void rtp_timer_queue_remove_all (RtpTimerQueue * queue);
105
106 void rtp_timer_queue_set_timer (RtpTimerQueue * queue, RtpTimerType type,
107 guint16 seqnum, GstClockTime timeout,
108 GstClockTime delay, GstClockTime duration,
109 GstClockTimeDiff offset);
110 void rtp_timer_queue_set_expected (RtpTimerQueue * queue, guint16 seqnum,
111 GstClockTime timeout, GstClockTime delay,
112 GstClockTime duration);
113 void rtp_timer_queue_set_lost (RtpTimerQueue * queue, guint16 seqnum,
114 GstClockTime timeout,
115 GstClockTime duration, GstClockTimeDiff offset);
116 void rtp_timer_queue_set_eos (RtpTimerQueue * queue, GstClockTime timeout,
117 GstClockTimeDiff offset);
118 void rtp_timer_queue_set_deadline (RtpTimerQueue * queue, guint16 seqnum,
119 GstClockTime timeout, GstClockTimeDiff offset);
120 void rtp_timer_queue_update_timer (RtpTimerQueue * queue, RtpTimer * timer, guint16 seqnum,
121 GstClockTime timeout, GstClockTime delay,
122 GstClockTimeDiff offset, gboolean reset);
123 guint rtp_timer_queue_length (RtpTimerQueue * queue);
124
125 #endif
126