Commit 268ff7ea authored by Jean-Paul Saman's avatar Jean-Paul Saman

Undo coding style fixes to make syncing with Xine code easier

parent 96537a3c
...@@ -247,8 +247,7 @@ static void call_hash (char *key, char *challenge, int len) { ...@@ -247,8 +247,7 @@ static void call_hash (char *key, char *challenge, int len) {
memcpy(key+b+24, challenge+c, len-c); memcpy(key+b+24, challenge+c, len-c);
} }
static void calc_response (char *result, char *field) static void calc_response (char *result, char *field) {
{
char buf1[128]; char buf1[128];
char buf2[128]; char buf2[128];
int i; int i;
...@@ -273,9 +272,7 @@ static void calc_response (char *result, char *field) ...@@ -273,9 +272,7 @@ static void calc_response (char *result, char *field)
memcpy (result, field, 16); memcpy (result, field, 16);
} }
static void calc_response_string (char *result, char *challenge) {
static void calc_response_string (char *result, char *challenge)
{
char field[128]; char field[128];
char zres[20]; char zres[20];
int i; int i;
...@@ -304,8 +301,8 @@ static void calc_response_string (char *result, char *challenge) ...@@ -304,8 +301,8 @@ static void calc_response_string (char *result, char *challenge)
} }
} }
void real_calc_response_and_checksum (char *response, char *chksum, char *challenge) void real_calc_response_and_checksum (char *response, char *chksum, char *challenge) {
{
int ch_len, table_len, resp_len; int ch_len, table_len, resp_len;
int i; int i;
char *ptr; char *ptr;
...@@ -366,8 +363,8 @@ void real_calc_response_and_checksum (char *response, char *chksum, char *challe ...@@ -366,8 +363,8 @@ void real_calc_response_and_checksum (char *response, char *chksum, char *challe
* takes a MLTI-Chunk and a rule number got from match_asm_rule, * takes a MLTI-Chunk and a rule number got from match_asm_rule,
* returns a pointer to selected data and number of bytes in that. * returns a pointer to selected data and number of bytes in that.
*/ */
static int select_mlti_data(const char *mlti_chunk, int mlti_size, int selection, char **out) static int select_mlti_data(const char *mlti_chunk, int mlti_size, int selection, char **out) {
{
int numrules, codec, size; int numrules, codec, size;
int i; int i;
...@@ -423,8 +420,8 @@ static int select_mlti_data(const char *mlti_chunk, int mlti_size, int selection ...@@ -423,8 +420,8 @@ static int select_mlti_data(const char *mlti_chunk, int mlti_size, int selection
* looking at stream description. * looking at stream description.
*/ */
rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidth) rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidth) {
{
sdpplin_t *desc = NULL; sdpplin_t *desc = NULL;
rmff_header_t *header = NULL; rmff_header_t *header = NULL;
char *buf = NULL; char *buf = NULL;
...@@ -462,8 +459,9 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt ...@@ -462,8 +459,9 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt
memset(header->streams, 0, sizeof(rmff_mdpr_t*)*(desc->stream_count+1)); memset(header->streams, 0, sizeof(rmff_mdpr_t*)*(desc->stream_count+1));
lprintf("number of streams: %u\n", desc->stream_count); lprintf("number of streams: %u\n", desc->stream_count);
for (i=0; i<desc->stream_count; i++)
{ for (i=0; i<desc->stream_count; i++) {
int j=0; int j=0;
int n; int n;
char b[64]; char b[64];
...@@ -472,20 +470,17 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt ...@@ -472,20 +470,17 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt
lprintf("calling asmrp_match with:\n%s\n%u\n", desc->stream[i]->asm_rule_book, bandwidth); lprintf("calling asmrp_match with:\n%s\n%u\n", desc->stream[i]->asm_rule_book, bandwidth);
n=asmrp_match(desc->stream[i]->asm_rule_book, bandwidth, rulematches); n=asmrp_match(desc->stream[i]->asm_rule_book, bandwidth, rulematches);
for (j=0; j<n; j++) for (j=0; j<n; j++) {
{
lprintf("asmrp rule match: %u for stream %u\n", rulematches[j], desc->stream[i]->stream_id); lprintf("asmrp rule match: %u for stream %u\n", rulematches[j], desc->stream[i]->stream_id);
sprintf(b,"stream=%u;rule=%u,", desc->stream[i]->stream_id, rulematches[j]); sprintf(b,"stream=%u;rule=%u,", desc->stream[i]->stream_id, rulematches[j]);
strcat(*stream_rules, b); strcat(*stream_rules, b);
} }
if (!desc->stream[i]->mlti_data) if (!desc->stream[i]->mlti_data) {
{
len = 0; len = 0;
if( buf ) free( buf ); if( buf ) free( buf );
buf = NULL; buf = NULL;
} } else
else
len=select_mlti_data(desc->stream[i]->mlti_data, len=select_mlti_data(desc->stream[i]->mlti_data,
desc->stream[i]->mlti_data_size, rulematches[0], &buf); desc->stream[i]->mlti_data_size, rulematches[0], &buf);
...@@ -533,8 +528,7 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt ...@@ -533,8 +528,7 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt
rmff_fix_header(header); rmff_fix_header(header);
if( desc ) if( desc ) {
{
sdpplin_free( desc ); sdpplin_free( desc );
free( desc ); free( desc );
} }
...@@ -542,13 +536,11 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt ...@@ -542,13 +536,11 @@ rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidt
return header; return header;
error: error:
if( desc ) if( desc ) {
{
sdpplin_free( desc ); sdpplin_free( desc );
free( desc ); free( desc );
} }
if( header ) if( header ) {
{
rmff_free_header( header ); rmff_free_header( header );
free( header ); free( header );
} }
...@@ -556,8 +548,8 @@ error: ...@@ -556,8 +548,8 @@ error:
return NULL; return NULL;
} }
int real_get_rdt_chunk_header(rtsp_client_t *rtsp_session, rmff_pheader_t *ph) int real_get_rdt_chunk_header(rtsp_client_t *rtsp_session, rmff_pheader_t *ph) {
{
int n=1; int n=1;
uint8_t header[8]; uint8_t header[8];
int size; int size;
...@@ -566,20 +558,16 @@ int real_get_rdt_chunk_header(rtsp_client_t *rtsp_session, rmff_pheader_t *ph) ...@@ -566,20 +558,16 @@ int real_get_rdt_chunk_header(rtsp_client_t *rtsp_session, rmff_pheader_t *ph)
uint32_t ts; uint32_t ts;
n=rtsp_read_data(rtsp_session, header, 8); n=rtsp_read_data(rtsp_session, header, 8);
if (n<8) if (n<8) return 0;
return 0; if (header[0] != 0x24) {
if (header[0] != 0x24)
{
lprintf("rdt chunk not recognized: got 0x%02x\n", header[0]); lprintf("rdt chunk not recognized: got 0x%02x\n", header[0]);
return 0; return 0;
} }
size=(header[1]<<16)+(header[2]<<8)+(header[3]); size=(header[1]<<16)+(header[2]<<8)+(header[3]);
flags1=header[4]; flags1=header[4];
if ((flags1!=0x40)&&(flags1!=0x42)) if ((flags1!=0x40)&&(flags1!=0x42)) {
{
lprintf("got flags1: 0x%02x\n",flags1); lprintf("got flags1: 0x%02x\n",flags1);
if (header[6]==0x06) if (header[6]==0x06) {
{
lprintf("got end of stream packet\n"); lprintf("got end of stream packet\n");
return 0; return 0;
} }
...@@ -587,19 +575,16 @@ int real_get_rdt_chunk_header(rtsp_client_t *rtsp_session, rmff_pheader_t *ph) ...@@ -587,19 +575,16 @@ int real_get_rdt_chunk_header(rtsp_client_t *rtsp_session, rmff_pheader_t *ph)
header[1]=header[6]; header[1]=header[6];
header[2]=header[7]; header[2]=header[7];
n=rtsp_read_data(rtsp_session, header+3, 5); n=rtsp_read_data(rtsp_session, header+3, 5);
if (n<5) if (n<5) return 0;
return 0;
lprintf("ignoring bytes:\n"); lprintf("ignoring bytes:\n");
n=rtsp_read_data(rtsp_session, header+4, 4); n=rtsp_read_data(rtsp_session, header+4, 4);
if (n<4) if (n<4) return 0;
return 0;
flags1=header[4]; flags1=header[4];
size-=9; size-=9;
} }
unknown1=(header[5]<<16)+(header[6]<<8)+(header[7]); unknown1=(header[5]<<16)+(header[6]<<8)+(header[7]);
n=rtsp_read_data(rtsp_session, header, 6); n=rtsp_read_data(rtsp_session, header, 6);
if (n<6) if (n<6) return 0;
return 0;
ts=BE_32(header); ts=BE_32(header);
#if 0 #if 0
...@@ -618,8 +603,8 @@ int real_get_rdt_chunk_header(rtsp_client_t *rtsp_session, rmff_pheader_t *ph) ...@@ -618,8 +603,8 @@ int real_get_rdt_chunk_header(rtsp_client_t *rtsp_session, rmff_pheader_t *ph)
} }
int real_get_rdt_chunk(rtsp_client_t *rtsp_session, rmff_pheader_t *ph, int real_get_rdt_chunk(rtsp_client_t *rtsp_session, rmff_pheader_t *ph,
unsigned char **buffer) unsigned char **buffer) {
{
int n; int n;
rmff_dump_pheader(ph, *buffer); rmff_dump_pheader(ph, *buffer);
n=rtsp_read_data(rtsp_session, *buffer + 12, ph->length - 12); n=rtsp_read_data(rtsp_session, *buffer + 12, ph->length - 12);
...@@ -628,8 +613,8 @@ int real_get_rdt_chunk(rtsp_client_t *rtsp_session, rmff_pheader_t *ph, ...@@ -628,8 +613,8 @@ int real_get_rdt_chunk(rtsp_client_t *rtsp_session, rmff_pheader_t *ph,
//! maximum size of the rtsp description, must be < INT_MAX //! maximum size of the rtsp description, must be < INT_MAX
#define MAX_DESC_BUF (20 * 1024 * 1024) #define MAX_DESC_BUF (20 * 1024 * 1024)
rmff_header_t *real_setup_and_get_header(rtsp_client_t *rtsp_session, int bandwidth) rmff_header_t *real_setup_and_get_header(rtsp_client_t *rtsp_session, int bandwidth) {
{
char *description=NULL; char *description=NULL;
char *session_id=NULL; char *session_id=NULL;
rmff_header_t *h; rmff_header_t *h;
...@@ -658,8 +643,7 @@ rmff_header_t *real_setup_and_get_header(rtsp_client_t *rtsp_session, int bandw ...@@ -658,8 +643,7 @@ rmff_header_t *real_setup_and_get_header(rtsp_client_t *rtsp_session, int bandw
rtsp_schedule_field(rtsp_session, "Require: com.real.retain-entity-for-setup"); rtsp_schedule_field(rtsp_session, "Require: com.real.retain-entity-for-setup");
status=rtsp_request_describe(rtsp_session,NULL); status=rtsp_request_describe(rtsp_session,NULL);
if ( status<200 || status>299 ) if ( status<200 || status>299 ) {
{
char *alert=rtsp_search_answers(rtsp_session,"Alert"); char *alert=rtsp_search_answers(rtsp_session,"Alert");
if (alert) { if (alert) {
lprintf("real: got message from server:\n%s\n", alert); lprintf("real: got message from server:\n%s\n", alert);
...@@ -712,10 +696,10 @@ rmff_header_t *real_setup_and_get_header(rtsp_client_t *rtsp_session, int bandw ...@@ -712,10 +696,10 @@ rmff_header_t *real_setup_and_get_header(rtsp_client_t *rtsp_session, int bandw
rmff_fix_header(h); rmff_fix_header(h);
#if 0 #if 0
fprintf("Title: %s\nCopyright: %s\nAuthor: %s\nStreams: %i\n", fprintf("Title: %s\nCopyright: %s\nAuthor: %s\nStreams: %i\n",
h->cont->title, h->cont->copyright, h->cont->author, h->prop->num_streams); h->cont->title, h->cont->copyright, h->cont->author, h->prop->num_streams);
#endif #endif
/* setup our streams */ /* setup our streams */
real_calc_response_and_checksum (challenge2, checksum, challenge1); real_calc_response_and_checksum (challenge2, checksum, challenge1);
......
...@@ -183,8 +183,8 @@ static void rmff_dump_cont(rmff_cont_t *cont, char *buffer) { ...@@ -183,8 +183,8 @@ static void rmff_dump_cont(rmff_cont_t *cont, char *buffer) {
cont->object_id=BE_32(&cont->object_id); cont->object_id=BE_32(&cont->object_id);
} }
static void rmff_dump_dataheader(rmff_data_t *data, char *buffer) static void rmff_dump_dataheader(rmff_data_t *data, char *buffer) {
{
if (!data) return; if (!data) return;
data->object_id=BE_32(&data->object_id); data->object_id=BE_32(&data->object_id);
...@@ -247,8 +247,8 @@ void rmff_dump_pheader(rmff_pheader_t *h, char *data) { ...@@ -247,8 +247,8 @@ void rmff_dump_pheader(rmff_pheader_t *h, char *data) {
data[11]=h->flags; data[11]=h->flags;
} }
rmff_fileheader_t *rmff_new_fileheader(uint32_t num_headers) rmff_fileheader_t *rmff_new_fileheader(uint32_t num_headers) {
{
rmff_fileheader_t *fileheader = malloc(sizeof(rmff_fileheader_t)); rmff_fileheader_t *fileheader = malloc(sizeof(rmff_fileheader_t));
if( !fileheader ) return NULL; if( !fileheader ) return NULL;
...@@ -273,8 +273,8 @@ rmff_prop_t *rmff_new_prop ( ...@@ -273,8 +273,8 @@ rmff_prop_t *rmff_new_prop (
uint32_t index_offset, uint32_t index_offset,
uint32_t data_offset, uint32_t data_offset,
uint16_t num_streams, uint16_t num_streams,
uint16_t flags ) uint16_t flags ) {
{
rmff_prop_t *prop = malloc(sizeof(rmff_prop_t)); rmff_prop_t *prop = malloc(sizeof(rmff_prop_t));
if( !prop ) return NULL; if( !prop ) return NULL;
...@@ -309,8 +309,8 @@ rmff_mdpr_t *rmff_new_mdpr( ...@@ -309,8 +309,8 @@ rmff_mdpr_t *rmff_new_mdpr(
const char *stream_name, const char *stream_name,
const char *mime_type, const char *mime_type,
uint32_t type_specific_len, uint32_t type_specific_len,
const char *type_specific_data ) const char *type_specific_data ) {
{
rmff_mdpr_t *mdpr = malloc(sizeof(rmff_mdpr_t)); rmff_mdpr_t *mdpr = malloc(sizeof(rmff_mdpr_t));
if( !mdpr ) return NULL; if( !mdpr ) return NULL;
...@@ -326,22 +326,19 @@ rmff_mdpr_t *rmff_new_mdpr( ...@@ -326,22 +326,19 @@ rmff_mdpr_t *rmff_new_mdpr(
mdpr->preroll=preroll; mdpr->preroll=preroll;
mdpr->duration=duration; mdpr->duration=duration;
mdpr->stream_name_size=0; mdpr->stream_name_size=0;
if (stream_name) if (stream_name) {
{
mdpr->stream_name=strdup(stream_name); mdpr->stream_name=strdup(stream_name);
mdpr->stream_name_size=strlen(stream_name); mdpr->stream_name_size=strlen(stream_name);
} }
mdpr->mime_type_size=0; mdpr->mime_type_size=0;
if (mime_type) if (mime_type) {
{
mdpr->mime_type=strdup(mime_type); mdpr->mime_type=strdup(mime_type);
mdpr->mime_type_size=strlen(mime_type); mdpr->mime_type_size=strlen(mime_type);
} }
mdpr->type_specific_len=type_specific_len; mdpr->type_specific_len=type_specific_len;
mdpr->type_specific_data = malloc(sizeof(char)*type_specific_len); mdpr->type_specific_data = malloc(sizeof(char)*type_specific_len);
if( !mdpr->type_specific_data ) if( !mdpr->type_specific_data ) {
{
if( mdpr->stream_name ) free( mdpr->stream_name ); if( mdpr->stream_name ) free( mdpr->stream_name );
free( mdpr ); free( mdpr );
return NULL; return NULL;
...@@ -352,8 +349,8 @@ rmff_mdpr_t *rmff_new_mdpr( ...@@ -352,8 +349,8 @@ rmff_mdpr_t *rmff_new_mdpr(
return mdpr; return mdpr;
} }
rmff_cont_t *rmff_new_cont(const char *title, const char *author, const char *copyright, const char *comment) rmff_cont_t *rmff_new_cont(const char *title, const char *author, const char *copyright, const char *comment) {
{
rmff_cont_t *cont = malloc(sizeof(rmff_cont_t)); rmff_cont_t *cont = malloc(sizeof(rmff_cont_t));
if( !cont ) return NULL; if( !cont ) return NULL;
...@@ -369,8 +366,7 @@ rmff_cont_t *rmff_new_cont(const char *title, const char *author, const char *co ...@@ -369,8 +366,7 @@ rmff_cont_t *rmff_new_cont(const char *title, const char *author, const char *co
cont->copyright_len=0; cont->copyright_len=0;
cont->comment_len=0; cont->comment_len=0;
if (title) if (title) {
{
cont->title_len=strlen(title); cont->title_len=strlen(title);
cont->title=strdup(title); cont->title=strdup(title);
} }
...@@ -379,13 +375,11 @@ rmff_cont_t *rmff_new_cont(const char *title, const char *author, const char *co ...@@ -379,13 +375,11 @@ rmff_cont_t *rmff_new_cont(const char *title, const char *author, const char *co
cont->author_len=strlen(author); cont->author_len=strlen(author);
cont->author=strdup(author); cont->author=strdup(author);
} }
if (copyright) if (copyright) {
{
cont->copyright_len=strlen(copyright); cont->copyright_len=strlen(copyright);
cont->copyright=strdup(copyright); cont->copyright=strdup(copyright);
} }
if (comment) if (comment) {
{
cont->comment_len=strlen(comment); cont->comment_len=strlen(comment);
cont->comment=strdup(comment); cont->comment=strdup(comment);
} }
...@@ -393,8 +387,7 @@ rmff_cont_t *rmff_new_cont(const char *title, const char *author, const char *co ...@@ -393,8 +387,7 @@ rmff_cont_t *rmff_new_cont(const char *title, const char *author, const char *co
return cont; return cont;
} }
rmff_data_t *rmff_new_dataheader(uint32_t num_packets, uint32_t next_data_header) rmff_data_t *rmff_new_dataheader(uint32_t num_packets, uint32_t next_data_header) {
{
rmff_data_t *data = malloc(sizeof(rmff_data_t)); rmff_data_t *data = malloc(sizeof(rmff_data_t));
if( !data ) return NULL; if( !data ) return NULL;
...@@ -408,31 +401,26 @@ rmff_data_t *rmff_new_dataheader(uint32_t num_packets, uint32_t next_data_header ...@@ -408,31 +401,26 @@ rmff_data_t *rmff_new_dataheader(uint32_t num_packets, uint32_t next_data_header
return data; return data;
} }
void rmff_print_header(rmff_header_t *h) void rmff_print_header(rmff_header_t *h) {
{
rmff_mdpr_t **stream; rmff_mdpr_t **stream;
if(!h) if(!h) {
{
printf("rmff_print_header: NULL given\n"); printf("rmff_print_header: NULL given\n");
return; return;
} }
if(h->fileheader) if(h->fileheader) {
{
printf("\nFILE:\n"); printf("\nFILE:\n");
printf("file version : %d\n", h->fileheader->file_version); printf("file version : %d\n", h->fileheader->file_version);
printf("number of headers : %d\n", h->fileheader->num_headers); printf("number of headers : %d\n", h->fileheader->num_headers);
} }
if(h->cont) if(h->cont) {
{
printf("\nCONTENT:\n"); printf("\nCONTENT:\n");
printf("title : %s\n", h->cont->title); printf("title : %s\n", h->cont->title);
printf("author : %s\n", h->cont->author); printf("author : %s\n", h->cont->author);
printf("copyright : %s\n", h->cont->copyright); printf("copyright : %s\n", h->cont->copyright);
printf("comment : %s\n", h->cont->comment); printf("comment : %s\n", h->cont->comment);
} }
if(h->prop) if(h->prop) {
{
printf("\nSTREAM PROPERTIES:\n"); printf("\nSTREAM PROPERTIES:\n");
printf("bit rate (max/avg) : %i/%i\n", h->prop->max_bit_rate, h->prop->avg_bit_rate); printf("bit rate (max/avg) : %i/%i\n", h->prop->max_bit_rate, h->prop->avg_bit_rate);
printf("packet size (max/avg) : %i/%i bytes\n", h->prop->max_packet_size, h->prop->avg_packet_size); printf("packet size (max/avg) : %i/%i bytes\n", h->prop->max_packet_size, h->prop->avg_packet_size);
...@@ -449,10 +437,8 @@ void rmff_print_header(rmff_header_t *h) ...@@ -449,10 +437,8 @@ void rmff_print_header(rmff_header_t *h)
printf("\n"); printf("\n");
} }
stream=h->streams; stream=h->streams;
if(stream) if(stream) {
{ while (*stream) {
while (*stream)
{
printf("\nSTREAM %i:\n", (*stream)->stream_number); printf("\nSTREAM %i:\n", (*stream)->stream_number);
printf("stream name [mime type] : %s [%s]\n", (*stream)->stream_name, (*stream)->mime_type); printf("stream name [mime type] : %s [%s]\n", (*stream)->stream_name, (*stream)->mime_type);
printf("bit rate (max/avg) : %i/%i\n", (*stream)->max_bit_rate, (*stream)->avg_bit_rate); printf("bit rate (max/avg) : %i/%i\n", (*stream)->max_bit_rate, (*stream)->avg_bit_rate);
...@@ -464,8 +450,7 @@ void rmff_print_header(rmff_header_t *h) ...@@ -464,8 +450,7 @@ void rmff_print_header(rmff_header_t *h)
stream++; stream++;
} }
} }
if(h->data) if(h->data) {
{
printf("\nDATA:\n"); printf("\nDATA:\n");
printf("size : %i\n", h->data->size); printf("size : %i\n", h->data->size);
printf("packets : %i\n", h->data->num_packets); printf("packets : %i\n", h->data->num_packets);
...@@ -473,63 +458,50 @@ void rmff_print_header(rmff_header_t *h) ...@@ -473,63 +458,50 @@ void rmff_print_header(rmff_header_t *h)
} }
} }
void rmff_fix_header(rmff_header_t *h) void rmff_fix_header(rmff_header_t *h) {
{
unsigned int num_headers=0; unsigned int num_headers=0;
unsigned int header_size=0; unsigned int header_size=0;
rmff_mdpr_t **streams; rmff_mdpr_t **streams;
int num_streams=0; int num_streams=0;
if (!h) if (!h) {
{
lprintf("rmff_fix_header: fatal: no header given.\n"); lprintf("rmff_fix_header: fatal: no header given.\n");
return; return;
} }
if (!h->streams) if (!h->streams) {
{
lprintf("rmff_fix_header: warning: no MDPR chunks\n"); lprintf("rmff_fix_header: warning: no MDPR chunks\n");
} } else {
else
{
streams=h->streams; streams=h->streams;
while (*streams) while (*streams) {
{
num_streams++; num_streams++;
num_headers++; num_headers++;
header_size+=(*streams)->size; header_size+=(*streams)->size;
streams++; streams++;
} }
} }
if (h->prop) if (h->prop) {
{ if (h->prop->size != 50) {
if (h->prop->size != 50)
{
lprintf("rmff_fix_header: correcting prop.size from %i to %i\n", h->prop->size, 50); lprintf("rmff_fix_header: correcting prop.size from %i to %i\n", h->prop->size, 50);
h->prop->size=50; h->prop->size=50;
} }
if (h->prop->num_streams != num_streams) if (h->prop->num_streams != num_streams) {
{
lprintf("rmff_fix_header: correcting prop.num_streams from %i to %i\n", h->prop->num_streams, num_streams); lprintf("rmff_fix_header: correcting prop.num_streams from %i to %i\n", h->prop->num_streams, num_streams);
h->prop->num_streams=num_streams; h->prop->num_streams=num_streams;
} }
num_headers++; num_headers++;
header_size+=50; header_size+=50;
} } else lprintf("rmff_fix_header: warning: no PROP chunk.\n");
else lprintf("rmff_fix_header: warning: no PROP chunk.\n");
if (h->cont) if (h->cont) {
{
num_headers++; num_headers++;
header_size+=h->cont->size; header_size+=h->cont->size;
} } else lprintf("rmff_fix_header: warning: no CONT chunk.\n");
else lprintf("rmff_fix_header: warning: no CONT chunk.\n");
if (!h->data) if (!h->data) {
{
lprintf("rmff_fix_header: no DATA chunk, creating one\n"); lprintf("rmff_fix_header: no DATA chunk, creating one\n");
h->data = malloc(sizeof(rmff_data_t)); h->data = malloc(sizeof(rmff_data_t));
if( h->data ) if( h->data ) {
{
memset(h->data, 0, sizeof(rmff_data_t)); memset(h->data, 0, sizeof(rmff_data_t));
h->data->object_id=DATA_TAG; h->data->object_id=DATA_TAG;
h->data->object_version=0; h->data->object_version=0;
...@@ -540,12 +512,10 @@ void rmff_fix_header(rmff_header_t *h) ...@@ -540,12 +512,10 @@ void rmff_fix_header(rmff_header_t *h)
} }
num_headers++; num_headers++;
if (!h->fileheader) if (!h->fileheader) {
{
lprintf("rmff_fix_header: no fileheader, creating one"); lprintf("rmff_fix_header: no fileheader, creating one");
h->fileheader = malloc(sizeof(rmff_fileheader_t)); h->fileheader = malloc(sizeof(rmff_fileheader_t));
if( h->fileheader ) if( h->fileheader ) {
{
memset(h->fileheader, 0, sizeof(rmff_fileheader_t)); memset(h->fileheader, 0, sizeof(rmff_fileheader_t));
h->fileheader->object_id=RMF_TAG; h->fileheader->object_id=RMF_TAG;
h->fileheader->size=34; h->fileheader->size=34;
...@@ -557,26 +527,21 @@ void rmff_fix_header(rmff_header_t *h) ...@@ -557,26 +527,21 @@ void rmff_fix_header(rmff_header_t *h)
header_size+=h->fileheader->size; header_size+=h->fileheader->size;
num_headers++; num_headers++;
if(h->fileheader->num_headers != num_headers) if(h->fileheader->num_headers != num_headers) {
{
lprintf("rmff_fix_header: setting num_headers from %i to %i\n", h->fileheader->num_headers, num_headers); lprintf("rmff_fix_header: setting num_headers from %i to %i\n", h->fileheader->num_headers, num_headers);
h->fileheader->num_headers=num_headers; h->fileheader->num_headers=num_headers;
} }
if(h->prop) if(h->prop) {
{ if (h->prop->data_offset != header_size) {
if (h->prop->data_offset != header_size)
{
lprintf("rmff_fix_header: setting prop.data_offset from %i to %i\n", h->prop->data_offset, header_size); lprintf("rmff_fix_header: setting prop.data_offset from %i to %i\n", h->prop->data_offset, header_size);
h->prop->data_offset=header_size; h->prop->data_offset=header_size;
} }
if (h->prop->num_packets == 0) if (h->prop->num_packets == 0) {
{
int p=(int)(h->prop->avg_bit_rate/8.0*(h->prop->duration/1000.0)/h->prop->avg_packet_size); int p=(int)(h->prop->avg_bit_rate/8.0*(h->prop->duration/1000.0)/h->prop->avg_packet_size);
lprintf("rmff_fix_header: assuming prop.num_packets=%i\n", p); lprintf("rmff_fix_header: assuming prop.num_packets=%i\n", p);
h->prop->num_packets=p; h->prop->num_packets=p;
} }
if (h->data->num_packets == 0) if (h->data->num_packets == 0) {
{
lprintf("rmff_fix_header: assuming data.num_packets=%i\n", h->prop->num_packets); lprintf("rmff_fix_header: assuming data.num_packets=%i\n", h->prop->num_packets);
h->data->num_packets=h->prop->num_packets; h->data->num_packets=h->prop->num_packets;
} }
...@@ -585,8 +550,7 @@ void rmff_fix_header(rmff_header_t *h) ...@@ -585,8 +550,7 @@ void rmff_fix_header(rmff_header_t *h)
} }
} }
int rmff_get_header_size(rmff_header_t *h) int rmff_get_header_size(rmff_header_t *h) {
{
if (!h) return 0; if (!h) return 0;
if (!h->prop) return -1; if (!h->prop) return -1;
return h->prop->data_offset+18; return h->prop->data_offset+18;
...@@ -599,20 +563,17 @@ void rmff_free_header(rmff_header_t *h) ...@@ -599,20 +563,17 @@ void rmff_free_header(rmff_header_t *h)
if (h->fileheader) free(h->fileheader); if (h->fileheader) free(h->fileheader);
if (h->prop) free(h->prop); if (h->prop) free(h->prop);
if (h->data) free(h->data); if (h->data) free(h->data);
if (h->cont) if (h->cont) {
{
free(h->cont->title); free(h->cont->title);
free(h->cont->author); free(h->cont->author);
free(h->cont->copyright); free(h->cont->copyright);
free(h->cont->comment); free(h->cont->comment);
free(h->cont); free(h->cont);
} }
if (h->streams) if (h->streams) {
{
rmff_mdpr_t **s=h->streams; rmff_mdpr_t **s=h->streams;
while(*s) while(*s) {
{
free((*s)->stream_name); free((*s)->stream_name);
free((*s)->mime_type); free((*s)->mime_type);
free((*s)->type_specific_data); free((*s)->type_specific_data);
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* Decodes base64 strings (based upon b64 package) * Decodes base64 strings (based upon b64 package)
*/ */
static char *b64_decode(const char *in, char *out, int *size) static char *b64_decode(const char *in, char *out, int *size) {
{
char dtable[256]; /* Encode / decode table */ char dtable[256]; /* Encode / decode table */
int i,k; int i,k;
unsigned int j; unsigned int j;
...@@ -53,16 +53,13 @@ static char *b64_decode(const char *in, char *out, int *size) ...@@ -53,16 +53,13 @@ static char *b64_decode(const char *in, char *out, int *size)
k=0; k=0;
/*CONSTANTCONDITION*/ /*CONSTANTCONDITION*/
for (j=0; j<strlen(in); j+=4) for (j=0; j<strlen(in); j+=4) {
{
char a[4], b[4]; char a[4], b[4];
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++) {
{
int c = in[i+j]; int c = in[i+j];
if (dtable[c] & 0x80) if (dtable[c] & 0x80) {
{
printf("Illegal character '%c' in input.\n", c); printf("Illegal character '%c' in input.\n", c);
exit(1); exit(1);
} }
...@@ -74,8 +71,7 @@ static char *b64_decode(const char *in, char *out, int *size) ...@@ -74,8 +71,7 @@ static char *b64_decode(const char *in, char *out, int *size)
out[k++] = (b[1] << 4) | (b[2] >> 2); out[k++] = (b[1] << 4) | (b[2] >> 2);
out[k++] = (b[2] << 6) | b[3]; out[k++] = (b[2] << 6) | b[3];
i = a[2] == '=' ? 1 : (a[3] == '=' ? 2 : 3); i = a[2] == '=' ? 1 : (a[3] == '=' ? 2 : 3);
if (i < 3) if (i < 3) {
{
out[k]=0; out[k]=0;
*size=k; *size=k;
return out; return out;
...@@ -86,23 +82,21 @@ static char *b64_decode(const char *in, char *out, int *size) ...@@ -86,23 +82,21 @@ static char *b64_decode(const char *in, char *out, int *size)
return out; return out;
} }
static char *nl(char *data) static char *nl(char *data) {
{
char *nlptr = (data) ? strchr(data,'\n') : NULL; char *nlptr = (data) ? strchr(data,'\n') : NULL;
return (nlptr) ? nlptr + 1 : NULL; return (nlptr) ? nlptr + 1 : NULL;
} }
static int filter(const char *in, const char *filter, char **out) static int filter(const char *in, const char *filter, char **out) {
{
int flen=strlen(filter); int flen=strlen(filter);
int len; int len;
if (!in) if (!in) return 0;
return 0;
len = (strchr(in,'\n')) ? strchr(in,'\n')-in : strlen(in); len = (strchr(in,'\n')) ? strchr(in,'\n')-in : strlen(in);
if (!strncmp(in,filter,flen)) if (!strncmp(in,filter,flen)) {
{
if(in[flen]=='"') flen++; if(in[flen]=='"') flen++;
if(in[len-1]==13) len--; if(in[len-1]==13) len--;
if(in[len-1]=='"') len--; if(in[len-1]=='"') len--;
...@@ -113,8 +107,8 @@ static int filter(const char *in, const char *filter, char **out) ...@@ -113,8 +107,8 @@ static int filter(const char *in, const char *filter, char **out)
return 0; return 0;
} }
static sdpplin_stream_t *sdpplin_parse_stream(char **data) static sdpplin_stream_t *sdpplin_parse_stream(char **data) {
{
sdpplin_stream_t *desc = malloc(sizeof(sdpplin_stream_t)); sdpplin_stream_t *desc = malloc(sizeof(sdpplin_stream_t));
char *buf = malloc(32000); char *buf = malloc(32000);
char *decoded = malloc(32000); char *decoded = malloc(32000);
...@@ -126,77 +120,64 @@ static sdpplin_stream_t *sdpplin_parse_stream(char **data) ...@@ -126,77 +120,64 @@ static sdpplin_stream_t *sdpplin_parse_stream(char **data)
if( !buf ) goto error; if( !buf ) goto error;
if( !decoded ) goto error; if( !decoded ) goto error;
if (filter(*data, "m=", &buf)) if (filter(*data, "m=", &buf)) {
{
desc->id = strdup(buf); desc->id = strdup(buf);
} } else {
else
{
lprintf("sdpplin: no m= found.\n"); lprintf("sdpplin: no m= found.\n");
goto error; goto error;
} }
*data=nl(*data); *data=nl(*data);
while (*data && **data && *data[0]!='m') while (*data && **data && *data[0]!='m') {
{
handled=0; handled=0;
if(filter(*data,"a=control:streamid=",&buf)) if(filter(*data,"a=control:streamid=",&buf)) {
{
desc->stream_id=atoi(buf); desc->stream_id=atoi(buf);
handled=1; handled=1;
*data=nl(*data); *data=nl(*data);
} }
if(filter(*data,"a=MaxBitRate:integer;",&buf)) if(filter(*data,"a=MaxBitRate:integer;",&buf)) {
{
desc->max_bit_rate=atoi(buf); desc->max_bit_rate=atoi(buf);
if (!desc->avg_bit_rate) if (!desc->avg_bit_rate)
desc->avg_bit_rate=desc->max_bit_rate; desc->avg_bit_rate=desc->max_bit_rate;
handled=1; handled=1;
*data=nl(*data); *data=nl(*data);
} }
if(filter(*data,"a=MaxPacketSize:integer;",&buf)) if(filter(*data,"a=MaxPacketSize:integer;",&buf)) {
{
desc->max_packet_size=atoi(buf); desc->max_packet_size=atoi(buf);
if (!desc->avg_packet_size) if (!desc->avg_packet_size)
desc->avg_packet_size=desc->max_packet_size; desc->avg_packet_size=desc->max_packet_size;
handled=1; handled=1;
*data=nl(*data); *data=nl(*data);
} }
if(filter(*data,"a=StartTime:integer;",&buf)) if(filter(*data,"a=StartTime:integer;",&buf)) {
{
desc->start_time=atoi(buf); desc->start_time=atoi(buf);
handled=1; handled=1;
*data=nl(*data); *data=nl(*data);
} }
if(filter(*data,"a=Preroll:integer;",&buf)) if(filter(*data,"a=Preroll:integer;",&buf)) {
{
desc->preroll=atoi(buf); desc->preroll=atoi(buf);
handled=1; handled=1;
*data=nl(*data); *data=nl(*data);
} }
if(filter(*data,"a=length:npt=",&buf)) if(filter(*data,"a=length:npt=",&buf)) {
{
desc->duration=(uint32_t)(atof(buf)*1000); desc->duration=(uint32_t)(atof(buf)*1000);
handled=1; handled=1;
*data=nl(*data); *data=nl(*data);
} }
if(filter(*data,"a=StreamName:string;",&buf)) if(filter(*data,"a=StreamName:string;",&buf)) {
{
desc->stream_name=strdup(buf); desc->stream_name=strdup(buf);
desc->stream_name_size=strlen(desc->stream_name); desc->stream_name_size=strlen(desc->stream_name);
handled=1; handled=1;
*data=nl(*data); *data=nl(*data);
} }
if(filter(*data,"a=mimetype:string;",&buf)) if(filter(*data,"a=mimetype:string;",&buf)) {
{
desc->mime_type=strdup(buf); desc->mime_type=strdup(buf);
desc->mime_type_size=strlen(desc->mime_type); desc->mime_type_size=strlen(desc->mime_type);
handled=1; handled=1;
*data=nl(*data); *data=nl(*data);
} }
if(filter(*data,"a=OpaqueData:buffer;",&buf)) if(filter(*data,"a=OpaqueData:buffer;",&buf)) {
{
decoded = b64_decode(buf, decoded, &(desc->mlti_data_size)); decoded = b64_decode(buf, decoded, &(desc->mlti_data_size));
desc->mlti_data = malloc(sizeof(char)*desc->mlti_data_size); desc->mlti_data = malloc(sizeof(char)*desc->mlti_data_size);
memcpy(desc->mlti_data, decoded, desc->mlti_data_size); memcpy(desc->mlti_data, decoded, desc->mlti_data_size);
...@@ -204,15 +185,13 @@ static sdpplin_stream_t *sdpplin_parse_stream(char **data) ...@@ -204,15 +185,13 @@ static sdpplin_stream_t *sdpplin_parse_stream(char **data)
*data=nl(*data); *data=nl(*data);
lprintf("mlti_data_size: %i\n", desc->mlti_data_size); lprintf("mlti_data_size: %i\n", desc->mlti_data_size);
} }
if(filter(*data,"a=ASMRuleBook:string;",&buf)) if(filter(*data,"a=ASMRuleBook:string;",&buf)) {
{
desc->asm_rule_book=strdup(buf); desc->asm_rule_book=strdup(buf);
handled=1; handled=1;
*data=nl(*data); *data=nl(*data);
} }
if(!handled) if(!handled) {
{
#ifdef LOG #ifdef LOG
int len=strchr(*data,'\n')-(*data); int len=strchr(*data,'\n')-(*data);
memcpy(buf, *data, len+1); memcpy(buf, *data, len+1);
...@@ -233,8 +212,8 @@ error: ...@@ -233,8 +212,8 @@ error:
return NULL; return NULL;
} }
sdpplin_t *sdpplin_parse(char *data) sdpplin_t *sdpplin_parse(char *data) {
{
sdpplin_t *desc = malloc(sizeof(sdpplin_t)); sdpplin_t *desc = malloc(sizeof(sdpplin_t));
sdpplin_stream_t *stream; sdpplin_stream_t *stream;
char *buf=malloc(3200); char *buf=malloc(3200);
...@@ -243,74 +222,63 @@ sdpplin_t *sdpplin_parse(char *data) ...@@ -243,74 +222,63 @@ sdpplin_t *sdpplin_parse(char *data)
int len; int len;
if( !desc ) return NULL; if( !desc ) return NULL;
if( !buf ) if( !buf ) {
{
free( desc ); free( desc );
return NULL; return NULL;
} }
if( !decoded ) if( !decoded ) {
{
free( buf ); free( buf );
free( desc ); free( desc );
return NULL; return NULL;
} }
memset(desc, 0, sizeof(sdpplin_t)); memset(desc, 0, sizeof(sdpplin_t));
while (data && *data) while (data && *data) {
{
handled=0; handled=0;
if (filter(data, "m=", &buf)) if (filter(data, "m=", &buf)) {
{
stream=sdpplin_parse_stream(&data); stream=sdpplin_parse_stream(&data);
lprintf("got data for stream id %u\n", stream->stream_id); lprintf("got data for stream id %u\n", stream->stream_id);
desc->stream[stream->stream_id]=stream; desc->stream[stream->stream_id]=stream;
continue; continue;
} }
if(filter(data,"a=Title:buffer;",&buf)) if(filter(data,"a=Title:buffer;",&buf)) {
{
decoded=b64_decode(buf, decoded, &len); decoded=b64_decode(buf, decoded, &len);
desc->title=strdup(decoded); desc->title=strdup(decoded);
handled=1; handled=1;
data=nl(data); data=nl(data);
} }
if(filter(data,"a=Author:buffer;",&buf)) if(filter(data,"a=Author:buffer;",&buf)) {
{
decoded=b64_decode(buf, decoded, &len); decoded=b64_decode(buf, decoded, &len);
desc->author=strdup(decoded); desc->author=strdup(decoded);
handled=1; handled=1;
data=nl(data); data=nl(data);
} }
if(filter(data,"a=Copyright:buffer;",&buf)) if(filter(data,"a=Copyright:buffer;",&buf)) {
{
decoded=b64_decode(buf, decoded, &len); decoded=b64_decode(buf, decoded, &len);
desc->copyright=strdup(decoded); desc->copyright=strdup(decoded);
handled=1; handled=1;
data=nl(data); data=nl(data);
} }
if(filter(data,"a=Abstract:buffer;",&buf)) if(filter(data,"a=Abstract:buffer;",&buf)) {
{
decoded=b64_decode(buf, decoded, &len); decoded=b64_decode(buf, decoded, &len);
desc->abstract=strdup(decoded); desc->abstract=strdup(decoded);
handled=1; handled=1;
data=nl(data); data=nl(data);
} }
if(filter(data,"a=StreamCount:integer;",&buf)) if(filter(data,"a=StreamCount:integer;",&buf)) {
{
desc->stream_count=atoi(buf); desc->stream_count=atoi(buf);
desc->stream = malloc(sizeof(sdpplin_stream_t*)*desc->stream_count); desc->stream = malloc(sizeof(sdpplin_stream_t*)*desc->stream_count);
handled=1; handled=1;
data=nl(data); data=nl(data);
} }
if(filter(data,"a=Flags:integer;",&buf)) if(filter(data,"a=Flags:integer;",&buf)) {
{
desc->flags=atoi(buf); desc->flags=atoi(buf);
handled=1; handled=1;
data=nl(data); data=nl(data);
} }
if(!handled) if(!handled) {
{
#ifdef LOG #ifdef LOG
int len=strchr(data,'\n')-data; int len=strchr(data,'\n')-data;
memcpy(buf, data, len+1); memcpy(buf, data, len+1);
...@@ -326,16 +294,14 @@ sdpplin_t *sdpplin_parse(char *data) ...@@ -326,16 +294,14 @@ sdpplin_t *sdpplin_parse(char *data)
return desc; return desc;
} }
void sdpplin_free(sdpplin_t *description) void sdpplin_free(sdpplin_t *description) {
{
int i; int i;
if( !description ) return; if( !description ) return;
for( i=0; i<description->stream_count; i++ ) for( i=0; i<description->stream_count; i++ ) {
{ if( description->stream[i] ) {
if( description->stream[i] )
{
if( description->stream[i]->id ) free( description->stream[i]->id ); if( description->stream[i]->id ) free( description->stream[i]->id );
if( description->stream[i]->bandwidth ) free( description->stream[i]->bandwidth ); if( description->stream[i]->bandwidth ) free( description->stream[i]->bandwidth );
if( description->stream[i]->range ) free( description->stream[i]->range ); if( description->stream[i]->range ) free( description->stream[i]->range );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment