File: session.c

package info (click to toggle)
rat 4.2.22-2.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,896 kB
  • ctags: 3,717
  • sloc: ansic: 36,542; tcl: 2,740; sh: 2,675; makefile: 295
file content (207 lines) | stat: -rw-r--r-- 6,661 bytes parent folder | download | duplicates (5)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
 * FILE:    session.c 
 * PROGRAM: RAT
 * AUTHORS: Vicky Hardman + Isidor Kouvelas + Colin Perkins + Orion Hodson
 *
 * Copyright (c) 1995-2001 University College London
 * All rights reserved.
 */
 
#ifndef HIDE_SOURCE_STRINGS
static const char cvsid[] = 
	"$Id: session.c,v 1.159 2001/01/08 20:30:07 ucaccsp Exp $";
#endif /* HIDE_SOURCE_STRINGS */

#include "config_unix.h"
#include "config_win32.h"
#include "debug.h"
#include "memory.h"
#include "version.h"
#include "session.h"
#include "repair.h"
#include "codec_types.h"
#include "codec.h"
#include "channel_types.h"
#include "channel.h"
#include "converter.h"
#include "parameters.h"
#include "audio.h"
#include "pdb.h"
#include "rtp.h"
#include "source.h"
#include "channel_types.h"
#include "channel.h"
#include "sndfile.h"
#include "tonegen.h"
#include "voxlet.h"

#define PCKT_QUEUE_RTP_LEN  24
#define PCKT_QUEUE_RTCP_LEN 12

/* sanity_check_payloads checks for overlapping payload maps between
 * channel coders and codecs.  Necessary because I don't trust myself
 * to not overlap payloads, and other people should not have to worry
 * about it either. [oth] 
 */

static int
sanity_check_payloads(void)
{
        uint32_t i, j, n_codecs, n_channels;
        codec_id_t cid;
        const codec_format_t *cf  = NULL;
        const cc_details_t   *ccd = NULL;
        cc_id_t    ccid;

        u_char pt;

        n_codecs = codec_get_number_of_codecs();
        n_channels = channel_get_coder_count();
        for(i = 0; i < n_codecs; i++) {
                cid = codec_get_codec_number(i);
                cf  = codec_get_format(cid);
                pt  = codec_get_payload(cid);
                if (pt != CODEC_PAYLOAD_DYNAMIC) {
                        ccid = channel_coder_get_by_payload(pt);
                        for(j = 0; j < n_channels; j++) {
                                ccd = channel_get_coder_details(j);
                                if (ccd == channel_get_null_coder()) {
                                        continue;
                                }
                                if (ccd->descriptor == ccid) {
                                        debug_msg("clash with %s %s payload (%d)\n", cf->long_name, ccd->name, pt);
                                        return FALSE;
                                }
                        }
                } else {
                        /* codec is not mapped into codec space so ignore */
                }
        }
        return TRUE;
}

void
session_init(session_t *sp, int index, int mode)
{
	codec_id_t                 cid;
        const codec_format_t      *cf   = NULL;
        const converter_details_t *conv = NULL;
        const cc_details_t        *ccd  = NULL;
        uint8_t                    i;

	memset(sp, 0, sizeof(session_t));

	codec_init();
        sanity_check_payloads();
        vu_table_init();

	cid = codec_get_by_name("DVI-8K-Mono");
        assert(cid);
        cf  = codec_get_format(cid);
	sp->cur_ts                      = ts_map32(8000,0);
        sp->encodings[0]		= codec_get_payload(cid);           	/* user chosen encoding for primary */
	sp->num_encodings		= 1;                                	/* Number of encodings applied */

        ccd = channel_get_null_coder();
        channel_encoder_create(ccd->descriptor, &sp->channel_coder);

        conv                            = converter_get_details(0);
        sp->converter                   = conv->id;
	sp->other_session		= NULL;				/* Completed in main_engine.c if we're a transoder */
	sp->id				= index;
	sp->mode         		= mode;	
        sp->rtp_session_count           = 0;
	for (i = 0; i < MAX_LAYERS; i++) {
		sp->rx_rtp_port[i] = sp->tx_rtp_port[i] = sp->rx_rtcp_port[i] = sp->tx_rtcp_port[i] = PORT_UNINIT;
                sp->rtp_session[i] = NULL;
	}
	sp->rx_rtp_port[0] 		= 5004; /* Default ports per:             */
	sp->tx_rtp_port[0] 		= 5004; /* draft-ietf-avt-profile-new-00  */
        sp->rx_rtcp_port[0]   		= 5005;
        sp->tx_rtcp_port[0]   		= 5005;
	sp->ttl				= 16;
        sp->filter_loopback             = TRUE;
	sp->playing_audio		= TRUE;
	sp->lecture			= FALSE;
	sp->auto_lecture		= 0;
 	sp->receive_audit_required	= FALSE;
	sp->silence_detection		= SILENCE_DETECTION_OFF;
	sp->sync_on			= FALSE;
	sp->agc_on			= FALSE;
        sp->ui_on                       = FALSE;
	sp->meter			= TRUE;					/* Powermeter operation */
	sp->in_file 			= NULL;
	sp->out_file  			= NULL;
	sp->local_file_player		= NULL;
	sp->mbus_engine_addr		= NULL;
	sp->mbus_engine			= NULL;
	sp->mbus_ui_addr		= NULL;
	sp->mbus_video_addr		= xstrdup("(media:video module:engine)");
	sp->min_playout			= 0;
	sp->max_playout			= 1000;
        sp->last_depart_ts              = 0;
	sp->loopback_gain		= 0;
	sp->layers                      = 1;
	sp->ui_activated		= FALSE;
	sp->encrkey			= NULL;
	sp->logger                      = NULL;
	sp->mbus_waiting		= FALSE;
	sp->mbus_waiting_token		= NULL;
	sp->mbus_go 			= FALSE;
	sp->mbus_go_token		= NULL;
	sp->magic			= 0xcafebabe;				/* Magic number for debugging */

        source_list_create(&sp->active_sources);

	sp->title = "Untitled session";
	strncpy(sp->asc_address[0], "127.0.0.3", MAXHOSTNAMELEN);	/* Yeuch! This value should never be used! */
}

void
session_exit(session_t *sp)
{
        codec_exit();
        if (sp->local_file_player) {
                voxlet_destroy(&sp->local_file_player);
        }
	if (sp->tone_generator) {
		tonegen_destroy(&sp->tone_generator);
	}
        if (sp->in_file_converter) {
                converter_destroy(&sp->in_file_converter);
        }
	if (sp->in_file  != NULL) {
                snd_read_close (&sp->in_file);
        }
	if (sp->out_file != NULL) {
                snd_write_close(&sp->out_file);
        }
	if (sp->pdb != NULL) {
		pdb_destroy(&sp->pdb);
	}
        channel_encoder_destroy(&sp->channel_coder);
        source_list_destroy(&sp->active_sources);
	xfree(sp->mbus_engine_addr);
	xfree(sp->mbus_video_addr);
	xfree(sp->mbus_ui_addr);
	xfree(sp);
}

void
session_validate(session_t *sp)
{
	/* Sanity check the session... the more checks we can add here the better, */
	/* they're done once round the main loop and we can add calls to this at   */
	/* any point we think our data structures are being corrupted. For speed,  */
	/* we only check the magic number if we've not been built with debugging.  */
	assert(sp != NULL);
	assert(sp->magic == 0xcafebabe);
#ifdef DEBUG
	assert((sp->ttl >= 0) && (sp->ttl <= 255));
	assert((sp->tx_rtp_port[0] % 2) == 0);
	assert((sp->rx_rtp_port[0] % 2) == 0);
	assert((sp->tx_rtcp_port[0] % 2) == 1);
	assert((sp->rx_rtcp_port[0] % 2) == 1);
#endif
}