#include <winsock.h>
#include "jrtplib_wrapper.h"
#include <stdio.h>
#include <process.h>
#include <Windows.h>
#include <stdint.h>
#define MIN_VALUE 1
#define MAX_VALUE 100
struct net_info
{
char * ip;
int port;
};
struct net_info mcast_info[100] =
{
{ "239.1.1.1",10000},
{ "239.1.1.2",10002},
{ "239.1.1.3",10004},
{ "239.1.1.4",10006},
{ "239.1.1.5",10008},
{ "239.1.1.6",10012},
{ "239.1.1.7",10014},
{ "239.1.1.8",10016},
{ "239.1.1.9",10018},
{ "239.1.1.10",10020},
{ "239.1.1.11",10022},
{ "239.1.1.12",10024},
{ "239.1.1.13",10026},
{ "239.1.1.14",10028},
{ "239.1.1.15",10030},
{ "239.1.1.16",10032},
{ "239.1.1.17",10034},
{ "239.1.1.18",10036},
{ "239.1.1.19",10038},
{ "239.1.1.20",10040},
{ "239.1.1.21",10042},
{ "239.1.1.22",10044},
{ "239.1.1.23",10046},
{ "239.1.1.24",10048},
{ "239.1.1.25",10050},
{ "239.1.1.26",10052},
{ "239.1.1.27",10054},
{ "239.1.1.28",10056},
{ "239.1.1.29",10058},
{ "239.1.1.30",10060},
{ "239.1.1.31",10062},
{ "239.1.1.32",10064},
{ "239.1.1.33",10066},
{ "239.1.1.34",10068},
{ "239.1.1.35",10070},
{ "239.1.1.36",10072},
{ "239.1.1.37",10074},
{ "239.1.1.38",10076},
{ "239.1.1.39",10078},
{ "239.1.1.40",10080},
{ "239.1.1.41",10082},
{ "239.1.1.42",10084},
{ "239.1.1.43",10086},
{ "239.1.1.44",10088},
{ "239.1.1.45",10090},
{ "239.1.1.46",10092},
{ "239.1.1.47",10094},
{ "239.1.1.48",10096},
{ "239.1.1.49",10098},
{ "239.1.1.50",10100},
{ "239.1.1.51",10102},
{ "239.1.1.52",10104},
{ "239.1.1.53",10106},
{ "239.1.1.54",10108},
{ "239.1.1.55",10110},
{ "239.1.1.56",10112},
{ "239.1.1.57",10114},
{ "239.1.1.58",10116},
{ "239.1.1.59",10118},
{ "239.1.1.60",10120},
{ "239.1.1.61",10122},
{ "239.1.1.62",10124},
{ "239.1.1.63",10126},
{ "239.1.1.64",10128},
{ "239.1.1.65",10130},
{ "239.1.1.66",10132},
{ "239.1.1.67",10134},
{ "239.1.1.68",10136},
{ "239.1.1.69",10138},
{ "239.1.1.70",10140},
{ "239.1.1.71",10142},
{ "239.1.1.72",10144},
{ "239.1.1.73",10146},
{ "239.1.1.74",10148},
{ "239.1.1.75",10150},
{ "239.1.1.76",10152},
{ "239.1.1.77",10154},
{ "239.1.1.78",10156},
{ "239.1.1.79",10158},
{ "239.1.1.80",10160},
{ "239.1.1.81",10162},
{ "239.1.1.82",10164},
{ "239.1.1.83",10166},
{ "239.1.1.84",10168},
{ "239.1.1.85",10170},
{ "239.1.1.86",10172},
{ "239.1.1.87",10174},
{ "239.1.1.88",10176},
{ "239.1.1.89",10178},
{ "239.1.1.90",10180},
{ "239.1.1.91",10182},
{ "239.1.1.92",10184},
{ "239.1.1.93",10186},
{ "239.1.1.94",10188},
{ "239.1.1.95",10190},
{ "239.1.1.96",10192},
{ "239.1.1.97",10194},
{ "239.1.1.98",10196},
{ "239.1.1.99",10198},
{ "239.1.1.100",10200}
};
struct stream_header
{
int frame_numb;
int stream_len;
unsigned short width;
unsigned short height;
int frame_flag;
};
static int add_multicast(char* ip, int port);
static void multicast_client_start();
static void multicast_client_stop();
bool initOK = false;
uint8_t* tmp_buffer = NULL;
bool is_IDR = false;
unsigned int __stdcall multicast_client_run(void* pM)
{
struct stream_header* header;
int sum_size;
int rev_size;
int is_qempty;
while(initOK)
{
if(tmp_buffer==NULL)
{
tmp_buffer=(uint8_t*)malloc(1*1024*1024);
if(tmp_buffer==NULL)
{
printf("malloc fail \n");
return 0;
}
}
rev_size = fap_multicast_client_run(tmp_buffer, 1024 * 1024);
if(rev_size == -1)
{
fprintf(stderr, "need to re-init\n");
exit(1);
} else if(rev_size == -2) {
fprintf(stderr, "buffer is too small\n");
continue;
}
header = (struct stream_header*)tmp_buffer;
printf("getdata-width:[%d],getdata-height:[%d],tpye=[%d]\n",header->width,header->height,header->frame_flag);
if(header->frame_flag != 0 && header->frame_flag != 1)
{
printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!data is wrong,please drop it\n");
continue;
}
//g_print("rev_size1:[%d]\n",rev_size);
sum_size = rev_size;
if(sum_size != header->stream_len+sizeof(struct stream_header))
{
fprintf(stderr, "there is data loss,recv %d, require %dplease drop it\n",
rev_size, header->stream_len+sizeof(struct stream_header));
continue;
}
if(header->frame_flag == 1)
{
is_IDR = TRUE;
}
}
return 0;
}
static int add_multicast(char *ip,int port)
{
int status;
status = fap_multicast_client_init(ip,port);
return status;
}
static void multicast_client_start()
{
HANDLE handle = (HANDLE)_beginthreadex(NULL, 0, multicast_client_run, NULL, 0, NULL);
}
static void multicast_client_stop()
{
}
int main()
{
WSADATA dat;
WSAStartup(MAKEWORD(2,2),&dat);
if(add_multicast(mcast_info[40-1].ip,mcast_info[40-1].port)==-1)
{
printf("7+++++++++\n");
}
else
{
printf("init is ok\n");
initOK = true;
}
if(initOK)
{
//client_info.timer_tag=g_timeout_add(50, (GSourceFunc)handle_data, NULL);
multicast_client_start();
getchar();
multicast_client_stop();
}
WSACleanup();
return 0;
}