summaryrefslogtreecommitdiff
path: root/mcast/netcv2dvbip/streamer.c
blob: 640338672bcad487a7286905999bedd39e312534 (plain)
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
#include "defs.h"

#include <stdio.h>

#include "misc.h"
#include "igmp.h"
#include "streamer.h"
#include "stream.h"

#define MULTICAST_PRIV_MIN (0xEFFF0000)
#define MULTICAST_PRIV_MAX (0xEFFF1000)

cStreamer::cStreamer()
{
	m_IgmpMain = NULL;
	m_bindaddr = 0;
	m_portnum = 0;
	m_table = 0;
}

void cStreamer::SetBindIf(iface_t bindif)
{
	m_bindaddr = bindif.ipaddr;
	m_bindif = bindif;
}

void cStreamer::SetStreamPort(int portnum)
{
        m_portnum = portnum;
}

void cStreamer::SetTable(int table)
{
        m_table = table;
}

void cStreamer::Run()
{
	if ( m_IgmpMain == NULL )
	{
		m_IgmpMain = new cIgmpMain(this, m_bindif, m_table);
		m_IgmpMain->StartListener();
	}
	return;
}

void cStreamer::Stop()
{
	if ( m_IgmpMain )
	{
		m_IgmpMain->Destruct();
		delete m_IgmpMain;
		m_IgmpMain = NULL;
	}
	return;
}

void cStreamer::SetNumGroups(int numgroups)
{
	m_numgroups = numgroups;
}

bool cStreamer::IsGroupinRange(in_addr_t groupaddr)
{
        in_addr_t g = htonl(groupaddr);
        if ( (g > MULTICAST_PRIV_MIN) && (g <= MULTICAST_PRIV_MIN+m_numgroups) 
		&&(g <= MULTICAST_PRIV_MAX) )
        {
                return true;
        }
        return false;
}

void cStreamer::StartMulticast(cMulticastGroup* Group)
{
        in_addr group;
        group.s_addr = Group->group;
        unsigned long channel = htonl(Group->group) - MULTICAST_PRIV_MIN;

        printf("START Channel %d on Multicast Group: %s\n", 
		(unsigned short) channel, inet_ntoa(group));
        if (Group->stream == NULL)
        {
                Group->stream = new cStream(channel,  Group->group, m_portnum);
                Group->stream->StartStream(m_bindaddr);
        }
}

void cStreamer::StopMulticast(cMulticastGroup* Group)
{
        in_addr group;
        group.s_addr = Group->group;

        printf("STOP Multicast Group: %s\n", inet_ntoa(group));
        if (Group->stream)
        {
                Group->stream->StopStream();
                delete Group->stream;
                Group->stream = NULL;
        }
}