static rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidth) { sdpplin_t *desc; rmff_header_t *header; char *buf; int len, i; int max_bit_rate=0; int avg_bit_rate=0; int max_packet_size=0; int avg_packet_size=0; int duration=0; if (!data) return NULL; desc=sdpplin_parse(data); if (!desc) return NULL; buf = xbuffer_init(2048); header=calloc(1,sizeof(rmff_header_t)); header->fileheader=rmff_new_fileheader(4+desc->stream_count); header->cont=rmff_new_cont( desc->title, desc->author, desc->copyright, desc->abstract); header->data=rmff_new_dataheader(0,0); header->streams=calloc(1,sizeof(rmff_mdpr_t*)*(desc->stream_count+1)); #ifdef LOG printf("number of streams: %u\n", desc->stream_count); #endif for (i=0; i<desc->stream_count; i++) { int j=0; int n; char b[64]; int rulematches[MAX_RULEMATCHES]; if (!desc->stream[i]) continue; #ifdef LOG printf("calling asmrp_match with:\n%s\n%u\n", desc->stream[i]->asm_rule_book, bandwidth); #endif n=asmrp_match(desc->stream[i]->asm_rule_book, bandwidth, rulematches); for (j=0; j<n; j++) { #ifdef LOG printf("asmrp rule match: %u for stream %u\n", rulematches[j], desc->stream[i]->stream_id); #endif sprintf(b,"stream=%u;rule=%u,", desc->stream[i]->stream_id, rulematches[j]); *stream_rules = xbuffer_strcat(*stream_rules, b); } if (!desc->stream[i]->mlti_data) { len = 0; buf = xbuffer_free(buf); } else len=select_mlti_data(desc->stream[i]->mlti_data, desc->stream[i]->mlti_data_size, rulematches[0], &buf); header->streams[i]=rmff_new_mdpr( desc->stream[i]->stream_id, desc->stream[i]->max_bit_rate, desc->stream[i]->avg_bit_rate, desc->stream[i]->max_packet_size, desc->stream[i]->avg_packet_size, desc->stream[i]->start_time, desc->stream[i]->preroll, desc->stream[i]->duration, desc->stream[i]->stream_name, desc->stream[i]->mime_type, len, buf); duration=FFMAX(duration,desc->stream[i]->duration); max_bit_rate+=desc->stream[i]->max_bit_rate; avg_bit_rate+=desc->stream[i]->avg_bit_rate; max_packet_size=FFMAX(max_packet_size, desc->stream[i]->max_packet_size); if (avg_packet_size) avg_packet_size=(avg_packet_size + desc->stream[i]->avg_packet_size) / 2; else avg_packet_size=desc->stream[i]->avg_packet_size; } if (*stream_rules && strlen(*stream_rules) && (*stream_rules)[strlen(*stream_rules)-1] == ',') (*stream_rules)[strlen(*stream_rules)-1]=0; /* delete last ',' in stream_rules */ header->prop=rmff_new_prop( max_bit_rate, avg_bit_rate, max_packet_size, avg_packet_size, 0, duration, 0, 0, 0, desc->stream_count, desc->flags); rmff_fix_header(header); buf = xbuffer_free(buf); sdpplin_free(desc); return header; }
/* * parse sdp(stream description) lines. * * subscribe is "Subscribe: " which is send with SET_PARAMETER request. * */ struct rmff_header_t *real_parse_sdp(char *data,char **subscribe,int bw) { struct sdpreal_t *desc; struct list_h *p; struct rmff_header_t *rmff_header; uint8_t *buf; int *matched; /* array of matched rules. malloced in find_asmrule_match */ int matched_rules; int i,j; int mlti_data_len; int subscribe_len = BUFSIZE_1K; char subbuf[32]; int duration =0; int max_bit_rate = 0; int avg_bit_rate = 0; int max_packet_size = 0; int avg_packet_size = 0; desc = sdpreal_parse(data); rmff_header = new_rmff_header_t(); rmff_header->fileheader = new_rmff_fileheader(4 + desc->stream_count); rmff_header->cont = new_rmff_cont(desc->title,desc->author, desc->copyright,desc->abstract); rmff_header->data = new_rmff_dataheader(0,0); rmff_header->streams = (rmff_mdpr_t**)xmalloc(sizeof(struct rmff_mdpr_t*) * (desc->stream_count + 1)); display(MSDL_VER,"number of streams: %u\n",desc->stream_count); *subscribe = (char *)xmalloc(subscribe_len); strcpy(*subscribe,"Subscribe: "); for(i = 0,p = desc->streams; i < desc->stream_count; i++,p = p->next) { struct sdpreal_stream_t *stream = (sdpreal_stream_t *)p->p; /* Subscribe: stream=0;rule=16,stream=0;rule=17 */ matched_rules = find_asmrule_match(stream->asm_rule_book, &matched,bw); if((strlen(*subscribe) + 32 * matched_rules) > subscribe_len) { /* subscribe should be longer */ subscribe_len = (subscribe_len * 2 > strlen(*subscribe) + 32 * matched_rules) ? subscribe_len * 2 : strlen(*subscribe) + 32 * matched_rules; *subscribe = (char *)xrealloc(*subscribe,subscribe_len); } for(j = 0; j < matched_rules ; j++) { snprintf(subbuf,sizeof(subbuf),"stream=%u;rule=%u,",i,matched[j]); strcat(*subscribe,subbuf); } buf = NULL; if(!stream->mlti_data) { mlti_data_len = 0; } else { /* buf is malloc()ed inside select_mlti_data */ mlti_data_len = select_mlti_data(stream->mlti_data, stream->mlti_data_size, matched[0],&buf); } rmff_header->streams[i] = new_rmff_mdpr(stream->stream_id, stream->max_bit_rate, stream->avg_bit_rate, stream->max_packet_size, stream->avg_packet_size, stream->start_time, stream->preroll, stream->duration, stream->stream_name, stream->mime_type, mlti_data_len, buf); duration = (duration > stream->duration) ? duration : stream->duration; max_bit_rate += stream->max_bit_rate; avg_bit_rate += stream->avg_bit_rate; max_packet_size = (max_packet_size > stream->max_packet_size) ? max_packet_size : stream->max_packet_size; if(avg_packet_size) { avg_packet_size = (avg_packet_size + stream->avg_packet_size) / 2; } else { avg_packet_size = stream->avg_packet_size; } if(matched) { free(matched); matched = NULL; } if(buf) { free(buf); buf = NULL; } } if((*subscribe)[strlen(*subscribe) -1 ] == ',') { (*subscribe)[strlen(*subscribe) -1 ] = '\0'; /* delete last comma */ } rmff_header->prop = new_rmff_prop(max_bit_rate, avg_bit_rate, max_packet_size, avg_packet_size, 0, duration, 0,0,0, desc->stream_count, desc->flags); rmff_fix_header(rmff_header); free_sdpreal_t(desc); rmff_print_header(rmff_header); return rmff_header; }