Revision becc0c84

View differences:

conf/janus.cfg.sample.in
39 39
;								  in any of the available transports.
40 40
;server_name = MyJanusInstance	; Public name of this Janus instance
41 41
;								  as it will appear in an info request
42
;recordings_tmp_ext = tmp	; The extension for recordings, in Janus, is
43
;							.mjr, a custom format we devised ourselves.
44
;							By default, we save to .mjr directly. If you'd
45
;							rather the recording filename have a temporary
46
;							extension while it's being saved, and only
47
;							have the .mjr extension when the recording
48
;							is over (e.g., to automatically trigger some
49
;							external scripts), then uncomment and set the
50
;							recordings_tmp_ext property to the extension
51
;							to add to the base (e.g., tmp --> .mjr.tmp).
42 52

  
43 53

  
44 54
; Certificate and key to use for DTLS.
janus.c
33 33
#include "debug.h"
34 34
#include "rtcp.h"
35 35
#include "auth.h"
36
#include "record.h"
36 37
#include "events.h"
37 38

  
38 39

  
......
3494 3495
	item = janus_config_get_item_drilldown(config, "general", "token_auth");
3495 3496
	janus_auth_init(item && item->value && janus_is_true(item->value));
3496 3497

  
3498
	/* Initialize the recorder code */
3499
	item = janus_config_get_item_drilldown(config, "general", "recordings_tmp_ext");
3500
	if(item && item->value) {
3501
		janus_recorder_init(TRUE, item->value);
3502
	} else {
3503
		janus_recorder_init(FALSE, NULL);
3504
	}
3505

  
3497 3506
	/* Setup ICE stuff (e.g., checking if the provided STUN server is correct) */
3498 3507
	char *stun_server = NULL, *turn_server = NULL;
3499 3508
	uint16_t stun_port = 0, turn_port = 0;
......
4173 4182
		g_hash_table_destroy(eventhandlers_so);
4174 4183
	}
4175 4184

  
4185
	janus_recorder_deinit();
4186

  
4176 4187
	JANUS_PRINT("Bye!\n");
4177 4188

  
4178 4189
	exit(0);
record.c
36 36
/* Frame header in the structured recording */
37 37
static const char *frame_header = "MEETECHO";
38 38

  
39
/* Whether the filenames should have a temporary extension, while saving, or not (default=false) */
40
static gboolean rec_tempname = FALSE;
41
/* Extension to add in case tempnames is true (default="tmp" --> ".tmp") */
42
static char *rec_tempext = NULL;
43

  
44
void janus_recorder_init(gboolean tempnames, const char *extension) {
45
	JANUS_LOG(LOG_INFO, "Initializing recorder code\n");
46
	if(tempnames) {
47
		rec_tempname = TRUE;
48
		if(extension == NULL) {
49
			rec_tempext = g_strdup("tmp");
50
			JANUS_LOG(LOG_INFO, "  -- No extension provided, using default one (tmp)");
51
		} else {
52
			rec_tempext = g_strdup(extension);
53
			JANUS_LOG(LOG_INFO, "  -- Using temporary extension .%s", rec_tempext);
54
		}
55
	}
56
}
57

  
58
void janus_recorder_deinit(void) {
59
	rec_tempname = FALSE;
60
	g_free(rec_tempext);
61
}
62

  
39 63

  
40 64
janus_recorder *janus_recorder_create(const char *dir, const char *codec, const char *filename) {
41 65
	janus_recorder_medium type = JANUS_RECORDER_AUDIO;
......
101 125
	memset(newname, 0, 1024);
102 126
	if(filename == NULL) {
103 127
		/* Choose a random username */
104
		g_snprintf(newname, 1024, "janus-recording-%"SCNu32".mjr", janus_random_uint32());
128
		if(!rec_tempname) {
129
			/* Use .mjr as an extension right away */
130
			g_snprintf(newname, 1024, "janus-recording-%"SCNu32".mjr", janus_random_uint32());
131
		} else {
132
			/* Append the temporary extension to .mjr, we'll rename when closing */
133
			g_snprintf(newname, 1024, "janus-recording-%"SCNu32".mjr.%s", janus_random_uint32(), rec_tempext);
134
		}
105 135
	} else {
106 136
		/* Just append the extension */
107
		g_snprintf(newname, 1024, "%s.mjr", filename);
137
		if(!rec_tempname) {
138
			/* Use .mjr as an extension right away */
139
			g_snprintf(newname, 1024, "%s.mjr", filename);
140
		} else {
141
			/* Append the temporary extension to .mjr, we'll rename when closing */
142
			g_snprintf(newname, 1024, "%s.mjr.%s", filename, rec_tempext);
143
		}
108 144
	}
109 145
	/* Try opening the file now */
110 146
	if(dir == NULL) {
......
208 244
		fseek(recorder->file, 0L, SEEK_SET);
209 245
		JANUS_LOG(LOG_INFO, "File is %zu bytes: %s\n", fsize, recorder->filename);
210 246
	}
247
	if(rec_tempname) {
248
		/* We need to rename the file, to remove the temporary extension */
249
		char newname[1024];
250
		memset(newname, 0, 1024);
251
		g_snprintf(newname, strlen(recorder->filename)-strlen(rec_tempext), "%s", recorder->filename);
252
		if(rename(recorder->filename, newname) != 0) {
253
			JANUS_LOG(LOG_ERR, "Error renaming %s to %s...\n", recorder->filename, newname);
254
		} else {
255
			JANUS_LOG(LOG_INFO, "Recording renamed: %s\n", newname);
256
			g_free(recorder->filename);
257
			recorder->filename = g_strdup(newname);
258
		}
259
	}
211 260
	janus_mutex_unlock_nodebug(&recorder->mutex);
212 261
	return 0;
213 262
}
record.h
56 56
	janus_mutex mutex;
57 57
} janus_recorder;
58 58

  
59
/*! \brief Initialize the recorder code
60
 * @param[in] tempnames Whether the filenames should have a temporary extension, while saving, or not
61
 * @param[in] extension Extension to add in case tempnames is true */
62
void janus_recorder_init(gboolean tempnames, const char *extension);
63
/*! \brief De-initialize the recorder code */
64
void janus_recorder_deinit(void);
59 65

  
60 66
/*! \brief Create a new recorder
61 67
 * \note If no target directory is provided, the current directory will be used. If no filename

Also available in: Unified diff