-
Notifications
You must be signed in to change notification settings - Fork 26
/
janus-gateway-live.patch
145 lines (137 loc) · 5.99 KB
/
janus-gateway-live.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
diff --git a/Makefile.am b/Makefile.am
index 85d6bee6..1249f8f4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -104,6 +104,8 @@ janus_SOURCES = \
mutex.h \
record.c \
record.h \
+ live.c \
+ live.h \
refcount.h \
rtcp.c \
rtcp.h \
@@ -141,12 +143,16 @@ janus_CFLAGS = \
-DEVENTDIR=\"$(eventdir)\" \
-DCONFDIR=\"$(confdir)\" \
$(BORINGSSL_CFLAGS) \
+ $(POST_PROCESSING_CFLAGS) \
+ $(OPUS_CFLAGS) \
$(NULL)
janus_LDADD = \
$(BORINGSSL_LIBS) \
$(JANUS_LIBS) \
$(JANUS_MANUAL_LIBS) \
+ $(POST_PROCESSING_LIBS) \
+ $(OPUS_LIBS) \
$(NULL)
dist_man1_MANS = janus.1
diff --git a/conf/janus.plugin.recordplay.jcfg.sample.in b/conf/janus.plugin.recordplay.jcfg.sample.in
index a15d1b6c..77d30232 100644
--- a/conf/janus.plugin.recordplay.jcfg.sample.in
+++ b/conf/janus.plugin.recordplay.jcfg.sample.in
@@ -2,6 +2,7 @@
# events = true|false, whether events should be sent to event handlers
general: {
+ rtmp = "rtmp://localhost:1935/qixi"
path = "@recordingsdir@"
#events = false
}
diff --git a/plugins/janus_recordplay.c b/plugins/janus_recordplay.c
index 1c0e4507..73a8abbf 100644
--- a/plugins/janus_recordplay.c
+++ b/plugins/janus_recordplay.c
@@ -265,6 +265,7 @@
#include "../config.h"
#include "../mutex.h"
#include "../record.h"
+#include "../live.h"
#include "../sdp-utils.h"
#include "../rtp.h"
#include "../rtcp.h"
@@ -412,6 +413,7 @@ typedef struct janus_recordplay_session {
janus_recordplay_recording *recording;
janus_recorder *arc; /* Audio recorder */
janus_recorder *vrc; /* Video recorder */
+ janus_live_pub *pub; /* live pub */
janus_mutex rec_mutex; /* Mutex to protect the recorders from race conditions */
janus_recordplay_frame_packet *aframes; /* Audio frames (for playout) */
janus_recordplay_frame_packet *vframes; /* Video frames (for playout) */
@@ -466,6 +468,7 @@ static void janus_recordplay_recording_free(const janus_refcount *recording_ref)
static char *recordings_path = NULL;
+static char *rtmp_path = NULL;
void janus_recordplay_update_recordings_list(void);
static void *janus_recordplay_playout_thread(void *data);
@@ -704,6 +707,9 @@ int janus_recordplay_init(janus_callbacks *callback, const char *config_path) {
janus_config_item *path = janus_config_get(config, config_general, janus_config_type_item, "path");
if(path && path->value)
recordings_path = g_strdup(path->value);
+ janus_config_item *rtmp = janus_config_get(config, config_general, janus_config_type_item, "rtmp");
+ if(rtmp && rtmp->value)
+ rtmp_path = g_strdup(rtmp->value);
janus_config_item *events = janus_config_get(config, config_general, janus_config_type_item, "events");
if(events != NULL && events->value != NULL)
notify_events = janus_is_true(events->value);
@@ -996,6 +1002,7 @@ struct janus_plugin_result *janus_recordplay_handle_message(janus_plugin_session
json_t *video_keyframe_interval= json_object_get(root, "video-keyframe-interval");
if(video_keyframe_interval) {
session->video_keyframe_interval = json_integer_value(video_keyframe_interval);
+ session->video_keyframe_interval = 1000;
JANUS_LOG(LOG_VERB, "Video keyframe interval has been set to %u\n", session->video_keyframe_interval);
}
response = json_object();
@@ -1120,6 +1127,7 @@ void janus_recordplay_send_rtcp_feedback(janus_plugin_session *handle, int video
gint64 interval = (gint64)(session->video_keyframe_interval / 1000) * G_USEC_PER_SEC;
if(elapsed >= interval) {
+ JANUS_LOG(LOG_INFO, "send pli and fir\n");
/* Send both a FIR and a PLI, just to be sure */
janus_rtcp_fir((char *)&rtcpbuf, 20, &session->video_fir_seq);
gateway->relay_rtcp(handle, video, rtcpbuf, 20);
@@ -1173,6 +1181,7 @@ void janus_recordplay_incoming_rtp(janus_plugin_session *handle, int video, char
session->rec_vssrc = g_random_int();
header->ssrc = htonl(session->rec_vssrc);
janus_recorder_save_frame(session->vrc, buf, len);
+ janus_live_pub_save_frame(session->pub, buf, len, TRUE, 1);
/* Restore header or core statistics will be messed up */
header->ssrc = htonl(ssrc);
header->timestamp = htonl(timestamp);
@@ -1180,6 +1189,7 @@ void janus_recordplay_incoming_rtp(janus_plugin_session *handle, int video, char
} else {
/* Save the frame if we're recording */
janus_recorder_save_frame(video ? session->vrc : session->arc, buf, len);
+ janus_live_pub_save_frame(session->pub, buf, len, video, 1);
}
janus_recordplay_send_rtcp_feedback(handle, video, buf, len);
@@ -1264,6 +1274,13 @@ static void janus_recordplay_hangup_media_internal(janus_plugin_session *handle)
JANUS_LOG(LOG_INFO, "Closed video recording %s\n", rc->filename ? rc->filename : "??");
janus_recorder_destroy(rc);
}
+ if(session->pub) {
+ janus_live_pub *pub = session->pub;
+ session->pub = NULL;
+ janus_live_pub_close(pub);
+ JANUS_LOG(LOG_INFO, "Closed rtmp living %s\n", pub->url ? pub->url : "??");
+ janus_live_pub_destroy(pub);
+ }
janus_mutex_unlock(&session->rec_mutex);
if(session->recorder) {
if(session->recording) {
@@ -1479,6 +1496,7 @@ static void *janus_recordplay_handler(void *data) {
/* Check which codec we should record for audio and/or video */
const char *acodec = NULL, *vcodec = NULL;
janus_sdp_find_preferred_codecs(offer, &acodec, &vcodec);
+ vcodec = "h264";
rec->acodec = janus_audiocodec_from_name(acodec);
rec->vcodec = janus_videocodec_from_name(vcodec);
/* We found preferred codecs: let's just make sure the direction is what we need */
@@ -1533,6 +1551,10 @@ static void *janus_recordplay_handler(void *data) {
rec->vrc_file = g_strdup(filename);
session->vrc = janus_recorder_create(recordings_path, janus_videocodec_name(rec->vcodec), rec->vrc_file);
}
+ char rtmpurl[1024];
+ rtmpurl[0] = '\0';
+ g_snprintf(rtmpurl, 1024, "%s/%"SCNu64"", rtmp_path, rec->id);
+ session->pub = janus_live_pub_create(rtmpurl, janus_audiocodec_name(rec->acodec), janus_audiocodec_name(rec->vcodec));
session->recorder = TRUE;
session->recording = rec;
session->sdp_version = 1; /* This needs to be increased when it changes */