diff options
author | Stefan Holst <holstsn@users.sourceforge.net> | 2002-12-24 01:30:21 +0000 |
---|---|---|
committer | Stefan Holst <holstsn@users.sourceforge.net> | 2002-12-24 01:30:21 +0000 |
commit | 375a1697687a45a70f83e400bd113028846813a1 (patch) | |
tree | 4a7039f72a0209b61aeeeacf0e66e477938936f6 /src | |
parent | efc8ab88d8211aa84c7131f7e5c9c2ce0c4ef079 (diff) | |
download | xine-lib-375a1697687a45a70f83e400bd113028846813a1.tar.gz xine-lib-375a1697687a45a70f83e400bd113028846813a1.tar.bz2 |
a cleaner implementation of sdp/sdpplin added, small fixes
CVS patchset: 3663
CVS date: 2002/12/24 01:30:21
Diffstat (limited to 'src')
-rw-r--r-- | src/input/libreal/Makefile.am | 8 | ||||
-rw-r--r-- | src/input/libreal/real.c | 414 | ||||
-rw-r--r-- | src/input/libreal/real.h | 6 | ||||
-rw-r--r-- | src/input/libreal/rmff.c | 3 | ||||
-rw-r--r-- | src/input/libreal/sdpplin.c | 311 | ||||
-rw-r--r-- | src/input/libreal/sdpplin.h | 112 |
6 files changed, 516 insertions, 338 deletions
diff --git a/src/input/libreal/Makefile.am b/src/input/libreal/Makefile.am index 6a1cd9167..db63a86ad 100644 --- a/src/input/libreal/Makefile.am +++ b/src/input/libreal/Makefile.am @@ -1,4 +1,4 @@ -REAL_CFLAGS = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE +REAL_CFLAGS = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -I../librtsp AM_CFLAGS = $(REAL_CFLAGS) @ANSI_FLAGS@ @@ -7,14 +7,16 @@ noinst_LTLIBRARIES = libreal.la libreal_la_SOURCES = \ real.c \ asmrp.c \ - rmff.c + rmff.c \ + sdpplin.c libreal_la_LDFLAGS = $(THREAD_LIBS) -avoid-version -module noinst_HEADERS = \ real.h \ asmrp.h \ - rmff.h + rmff.h \ + sdpplin.h debug: @$(MAKE) CFLAGS="$(DEBUG_CFLAGS) $(DVD_CFLAGS)" diff --git a/src/input/libreal/real.c b/src/input/libreal/real.c index 7028343b6..8785571fc 100644 --- a/src/input/libreal/real.c +++ b/src/input/libreal/real.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: real.c,v 1.5 2002/12/22 16:46:27 holstsn Exp $ + * $Id: real.c,v 1.6 2002/12/24 01:30:22 holstsn Exp $ * * special functions for real streams. * adopted from joschkas real tools. @@ -29,6 +29,8 @@ #include "real.h" #include "asmrp.h" +#include "sdpplin.h" +#include <xineutils.h> /* #define LOG @@ -469,356 +471,106 @@ static int select_mlti_data(const char *mlti_chunk, int mlti_size, int selection } /* - * Decodes base64 strings (based upon b64 package) - */ - -static char *b64_decode(const char *in, int *size) -{ - char dtable[256]; /* Encode / decode table */ - int i,j,k; - char *out=malloc(sizeof(char)*strlen(in)); - - for (i = 0; i < 255; i++) { - dtable[i] = 0x80; - } - for (i = 'A'; i <= 'Z'; i++) { - dtable[i] = 0 + (i - 'A'); - } - for (i = 'a'; i <= 'z'; i++) { - dtable[i] = 26 + (i - 'a'); - } - for (i = '0'; i <= '9'; i++) { - dtable[i] = 52 + (i - '0'); - } - dtable['+'] = 62; - dtable['/'] = 63; - dtable['='] = 0; - - k=0; - - /*CONSTANTCONDITION*/ - for (j=0; j<strlen(in); j+=4) - { - char a[4], b[4]; - - for (i = 0; i < 4; i++) { - int c = in[i+j]; - - if (dtable[c] & 0x80) { - printf("Illegal character '%c' in input.\n", c); - exit(1); - } - a[i] = (char) c; - b[i] = (char) dtable[c]; - } - out[k++] = (b[0] << 2) | (b[1] >> 4); - out[k++] = (b[1] << 4) | (b[2] >> 2); - out[k++] = (b[2] << 6) | b[3]; - i = a[2] == '=' ? 1 : (a[3] == '=' ? 2 : 3); - if (i < 3) { - out[k]=0; - *size=k; - return out; - } - } - out[k]=0; - *size=k; - return out; -} - -/* * looking at stream description. */ - -static int sdp_filter(const char *in, const char *filter, char *out) { - - int flen=strlen(filter); - int len=strchr(in,'\n')-in; - if (!strncmp(in,filter,flen)) - { - if(in[flen]=='"') flen++; - if(in[len-1]==13) len--; - if(in[len-1]=='"') len--; - memcpy(out, &in[flen], len-flen); - out[len-flen]=0; - - return len-flen; - } +rmff_header_t *real_parse_sdp(char *data, char *stream_rules, uint32_t bandwidth) { + + sdpplin_t *desc; + rmff_header_t *header; + char buf[2048]; + 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; - return 0; -} -rmff_header_t *real_parse_sdp(const char *data, char *stream_rules, uint32_t bandwidth) { + if (!data) return NULL; - rmff_header_t *h=malloc(sizeof(rmff_header_t)); - rmff_mdpr_t *media=NULL; - char buf[4096]; - int rulematches[16]; - int n; - int len; - int have_audio=0, have_video=0, stream, sr[2]; + desc=sdpplin_parse(data); - stream_rules[0]=0; + if (!desc) return NULL; - h=malloc(sizeof(rmff_header_t)); - h->streams=malloc(sizeof(rmff_mdpr_t*)*3); - h->streams[0]=NULL; - h->streams[1]=NULL; - h->streams[2]=NULL; - h->prop=malloc(sizeof(rmff_prop_t)); - h->streams[0]=malloc(sizeof(rmff_mdpr_t)); - h->streams[1]=malloc(sizeof(rmff_mdpr_t)); - h->cont=malloc(sizeof(rmff_cont_t)); - h->data=malloc(sizeof(rmff_data_t)); - h->fileheader=malloc(sizeof(rmff_fileheader_t)); - h->fileheader->object_id=RMF_TAG; - h->fileheader->size=18; - h->fileheader->object_version=0; - h->fileheader->file_version=0; - h->fileheader->num_headers=6; - - h->prop->object_version=0; - h->streams[0]->object_version=0; - h->streams[1]->object_version=0; - h->cont->object_version=0; - h->data->object_version=0; - - h->prop->object_id=PROP_TAG; - h->streams[0]->object_id=MDPR_TAG; - h->streams[1]->object_id=MDPR_TAG; - h->cont->object_id=CONT_TAG; - h->data->object_id=DATA_TAG; - - h->prop->size=50; - h->data->size=18; - h->data->next_data_header=0; - - h->cont->title=NULL; - h->cont->author=NULL; - h->cont->copyright=NULL; - h->cont->comment=NULL; - - while (*data) { - - if(sdp_filter(data,"m=audio",buf)) - { - media=h->streams[0]; - have_audio=1; - stream=0; - } else if(sdp_filter(data,"m=video",buf)) - { - media=h->streams[1]; - have_video=1; - stream=1; - } else if(sdp_filter(data,"m=",buf)) - { - printf("real: warning: unknown media stream type '%s'\n", buf); - do { - data+=strchr(data,'\n')-data+1; - } while (*data && data[0]!='m'); - continue; - } - - /* cont stuff */ - - len=sdp_filter(data,"a=Title:buffer;",buf); - if (len) h->cont->title=b64_decode(buf,&len); - - len=sdp_filter(data,"a=Author:buffer;",buf); - if (len) h->cont->author=b64_decode(buf,&len); - - len=sdp_filter(data,"a=Copyright:buffer;",buf); - if (len) h->cont->copyright=b64_decode(buf,&len); - - len=sdp_filter(data,"a=Abstract:buffer;",buf); - if (len) h->cont->comment=b64_decode(buf,&len); - - /* prop stuff */ - - len=sdp_filter(data,"a=StreamCount:integer;",buf); - if (len) h->prop->num_streams=atoi(buf); - - len=sdp_filter(data,"a=Flags:integer;",buf); - if (len) h->prop->flags=atoi(buf); - - /* mdpr stuff */ - - if (media) { - - len=sdp_filter(data,"a=control:streamid=",buf); - if (len) media->stream_number=atoi(buf); - - len=sdp_filter(data,"a=MaxBitRate:integer;",buf); - if (len) - { - media->max_bit_rate=atoi(buf); - media->avg_bit_rate=media->max_bit_rate; - } - - len=sdp_filter(data,"a=MaxPacketSize:integer;",buf); - if (len) - { - media->max_packet_size=atoi(buf); - media->avg_packet_size=media->max_packet_size; - } - - len=sdp_filter(data,"a=StartTime:integer;",buf); - if (len) media->start_time=atoi(buf); - - len=sdp_filter(data,"a=Preroll:integer;",buf); - if (len) media->preroll=atoi(buf); - - len=sdp_filter(data,"a=length:npt=",buf); - if (len) media->duration=(uint32_t)(atof(buf)*1000); - - len=sdp_filter(data,"a=StreamName:string;",buf); - if (len) - { - media->stream_name=strdup(buf); - media->stream_name_size=strlen(media->stream_name); - } - len=sdp_filter(data,"a=mimetype:string;",buf); - if (len) - { - media->mime_type=strdup(buf); - media->mime_type_size=strlen(media->mime_type); - } - len=sdp_filter(data,"a=OpaqueData:buffer;",buf); - if (len) - { - media->mlti_data=b64_decode(buf, &(media->mlti_data_size)); + header=xine_xmalloc(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=xine_xmalloc(sizeof(rmff_mdpr_t*)*(desc->stream_count+1)); #ifdef LOG - printf("mlti_data_size: %i\n", media->mlti_data_size); + printf("number of streams: %u\n", desc->stream_count); #endif - } - len=sdp_filter(data,"a=ASMRuleBook:string;",buf); - if (len) - { - int i=0; - char b[64]; + + for (i=0; i<desc->stream_count; i++) { + + int j=0; + int n; + char b[64]; + int rulematches[16]; #ifdef LOG - printf("calling asmrp_match with:\n%s\n%u\n", buf, bandwidth); + printf("calling asmrp_match with:\n%s\n%u\n", desc->stream[i]->asm_rule_book, bandwidth); #endif - n=asmrp_match(buf, bandwidth, rulematches); - sr[stream]=rulematches[0]; - for (i=0; i<n; i++) { + 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[i], stream); + printf("asmrp rule match: %u for stream %u\n", rulematches[j], desc->stream[i]->stream_id); #endif - sprintf(b,"stream=%u;rule=%u,", stream, rulematches[i]); - strcat(stream_rules, b); - } - } + sprintf(b,"stream=%u;rule=%u,", desc->stream[i]->stream_id, rulematches[j]); + strcat(stream_rules, b); } - data+=strchr(data,'\n')-data+1; - } - if (strlen(stream_rules)>0); - stream_rules[strlen(stream_rules)-1]=0; /* delete last , */ - - /* we have to reconstruct some data in prop */ - h->prop->max_bit_rate=0; - h->prop->avg_bit_rate=0; - h->prop->max_packet_size=0; - h->prop->avg_packet_size=0; - h->prop->num_packets=0; - h->prop->duration=0; - h->prop->preroll=0; - h->prop->index_offset=0; - - - - if(have_video) - { - - h->prop->max_bit_rate=h->streams[1]->max_bit_rate; - h->prop->avg_bit_rate=h->streams[1]->avg_bit_rate; - h->prop->max_packet_size=h->streams[1]->max_packet_size; - h->prop->avg_packet_size=h->streams[1]->avg_packet_size; - h->prop->duration=h->streams[1]->duration; - /* h->prop->preroll=h->streams[1]->preroll; */ - - /* select a codec */ - h->streams[1]->type_specific_len=select_mlti_data( - h->streams[1]->mlti_data, h->streams[1]->mlti_data_size, sr[1], buf); - h->streams[1]->type_specific_data=malloc(sizeof(char)*h->streams[1]->type_specific_len); - memcpy(h->streams[1]->type_specific_data, buf, h->streams[1]->type_specific_len); + + len=select_mlti_data(desc->stream[i]->mlti_data, desc->stream[i]->mlti_data_size, rulematches[0], buf); - } else - { - free(h->streams[1]); - h->streams[1]=NULL; - } - if(have_audio) - { - - h->prop->max_bit_rate+=h->streams[0]->max_bit_rate; - h->prop->avg_bit_rate+=h->streams[0]->avg_bit_rate; - h->prop->max_packet_size=MAX(h->prop->max_packet_size, - h->streams[0]->max_packet_size); - if (have_video) - h->prop->avg_packet_size=(h->streams[1]->avg_packet_size - +h->streams[0]->avg_packet_size) / 2; + 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=MAX(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=MAX(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 - h->prop->avg_packet_size=h->streams[0]->avg_packet_size; - h->prop->duration=MAX(h->prop->duration,h->streams[0]->duration); - /* h->prop->preroll=MAX(h->streams[1]->preroll,h->streams[0]->preroll); */ - - /* select a codec */ - h->streams[0]->type_specific_len=select_mlti_data( - h->streams[0]->mlti_data, h->streams[0]->mlti_data_size, sr[0], buf); - h->streams[0]->type_specific_data=malloc(sizeof(char)*h->streams[0]->type_specific_len); - memcpy(h->streams[0]->type_specific_data, buf, h->streams[0]->type_specific_len); - - } else - { - free(h->streams[0]); - h->streams[0]=NULL; + avg_packet_size=desc->stream[i]->avg_packet_size; } - - /* fix sizes */ - - h->cont->title_len=0; - h->cont->author_len=0; - h->cont->copyright_len=0; - h->cont->comment_len=0; - if (h->cont->title) h->cont->title_len=strlen(h->cont->title); - if (h->cont->author) h->cont->author_len=strlen(h->cont->author); - if (h->cont->copyright) h->cont->copyright_len=strlen(h->cont->copyright); - if (h->cont->comment) h->cont->comment_len=strlen(h->cont->comment); - - h->cont->size=18 - +h->cont->title_len - +h->cont->author_len - +h->cont->copyright_len - +h->cont->comment_len; - - if (have_audio) - h->streams[0]->size=12+7*4+6 - +h->streams[0]->stream_name_size - +h->streams[0]->mime_type_size - +h->streams[0]->type_specific_len; - - if (have_video) - h->streams[1]->size=12+7*4+6 - +h->streams[1]->stream_name_size - +h->streams[1]->mime_type_size - +h->streams[1]->type_specific_len; - - /* fix data offset */ - h->prop->data_offset=RMFF_HEADER_SIZE - +h->cont->size - +h->prop->size; - - if (have_video) - h->prop->data_offset+=h->streams[1]->size; - - if (have_audio) - h->prop->data_offset+=h->streams[0]->size; - - return h; + if (stream_rules) + 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); + + return header; } int real_get_rdt_chunk(rtsp_t *rtsp_session, char *buffer) { diff --git a/src/input/libreal/real.h b/src/input/libreal/real.h index 48ab2e82d..6d31dd0fd 100644 --- a/src/input/libreal/real.h +++ b/src/input/libreal/real.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: real.h,v 1.1 2002/12/12 22:14:55 holstsn Exp $ + * $Id: real.h,v 1.2 2002/12/24 01:30:22 holstsn Exp $ * * special functions for real streams. * adopted from joschkas real tools. @@ -28,7 +28,7 @@ #define HAVE_REAL_H #include "rmff.h" -#include "../librtsp/rtsp.h" +#include "rtsp.h" #ifdef __CYGWIN__ #define uint32_t unsigned int @@ -42,7 +42,7 @@ */ void real_calc_response_and_checksum (char *response, char *chksum, char *challenge); int real_get_rdt_chunk(rtsp_t *rtsp_session, char *buffer); -rmff_header_t *real_parse_sdp(const char *data, char *stream_rules, uint32_t bandwidth); +rmff_header_t *real_parse_sdp(char *data, char *stream_rules, uint32_t bandwidth); rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth); #endif diff --git a/src/input/libreal/rmff.c b/src/input/libreal/rmff.c index 2ce5d5717..bbdd398ec 100644 --- a/src/input/libreal/rmff.c +++ b/src/input/libreal/rmff.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: rmff.c,v 1.2 2002/12/15 01:51:36 holstsn Exp $ + * $Id: rmff.c,v 1.3 2002/12/24 01:30:22 holstsn Exp $ * * functions for real media file format * adopted from joschkas real tools @@ -623,6 +623,7 @@ rmff_mdpr_t *rmff_new_mdpr( mdpr->mime_type_size=strlen(mime_type); } mdpr->type_specific_len=type_specific_len; + mdpr->type_specific_data=malloc(sizeof(char)*type_specific_len); memcpy(mdpr->type_specific_data,type_specific_data,type_specific_len); mdpr->mlti_data=NULL; diff --git a/src/input/libreal/sdpplin.c b/src/input/libreal/sdpplin.c new file mode 100644 index 000000000..cd1c49275 --- /dev/null +++ b/src/input/libreal/sdpplin.c @@ -0,0 +1,311 @@ +/* + * Copyright (C) 2002 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * $Id: sdpplin.c,v 1.1 2002/12/24 01:30:22 holstsn Exp $ + * + * sdp/sdpplin parser. + * + */ + +#include "rmff.h" +#include "rtsp.h" +#include "sdpplin.h" +#include <xineutils.h> + +/* +#define LOG +*/ + +/* + * Decodes base64 strings (based upon b64 package) + */ + +static char *b64_decode(const char *in, char *out, int *size) +{ + char dtable[256]; /* Encode / decode table */ + int i,j,k; + + for (i = 0; i < 255; i++) { + dtable[i] = 0x80; + } + for (i = 'A'; i <= 'Z'; i++) { + dtable[i] = 0 + (i - 'A'); + } + for (i = 'a'; i <= 'z'; i++) { + dtable[i] = 26 + (i - 'a'); + } + for (i = '0'; i <= '9'; i++) { + dtable[i] = 52 + (i - '0'); + } + dtable['+'] = 62; + dtable['/'] = 63; + dtable['='] = 0; + + k=0; + + /*CONSTANTCONDITION*/ + for (j=0; j<strlen(in); j+=4) + { + char a[4], b[4]; + + for (i = 0; i < 4; i++) { + int c = in[i+j]; + + if (dtable[c] & 0x80) { + printf("Illegal character '%c' in input.\n", c); + exit(1); + } + a[i] = (char) c; + b[i] = (char) dtable[c]; + } + xine_buffer_ensure_size(out, k+3); + out[k++] = (b[0] << 2) | (b[1] >> 4); + out[k++] = (b[1] << 4) | (b[2] >> 2); + out[k++] = (b[2] << 6) | b[3]; + i = a[2] == '=' ? 1 : (a[3] == '=' ? 2 : 3); + if (i < 3) { + out[k]=0; + *size=k; + return out; + } + } + out[k]=0; + *size=k; + return out; +} + +static char *nl(char *data) { + + return strchr(data,'\n')+1; +} + +static int filter(const char *in, const char *filter, char **out) { + + int flen=strlen(filter); + int len=strchr(in,'\n')-in; + + if (!strncmp(in,filter,flen)) + { + if(in[flen]=='"') flen++; + if(in[len-1]==13) len--; + if(in[len-1]=='"') len--; + xine_buffer_copyin(*out, 0, in+flen, len-flen+1); + (*out)[len-flen]=0; + + return len-flen; + } + + return 0; +} +static sdpplin_stream_t *sdpplin_parse_stream(char **data) { + + sdpplin_stream_t *desc=xine_xmalloc(sizeof(sdpplin_stream_t)); + char *buf=xine_buffer_init(32); + char *decoded=xine_buffer_init(32); + int handled; + + if (filter(*data, "m=", &buf)) { + desc->id = strdup(buf); + } else + { + printf("sdpplin: no m= found.\n"); + free(desc); + xine_buffer_free(buf); + return NULL; + } + *data=nl(*data); + + while (**data && *data[0]!='m') { + + handled=0; + + if(filter(*data,"a=control:streamid=",&buf)) { + desc->stream_id=atoi(buf); + handled=1; + *data=nl(*data); + } + + if(filter(*data,"a=MaxBitRate:integer;",&buf)) { + desc->max_bit_rate=atoi(buf); + if (!desc->avg_bit_rate) + desc->avg_bit_rate=desc->max_bit_rate; + handled=1; + *data=nl(*data); + } + + if(filter(*data,"a=MaxPacketSize:integer;",&buf)) { + desc->max_packet_size=atoi(buf); + if (!desc->avg_packet_size) + desc->avg_packet_size=desc->max_packet_size; + handled=1; + *data=nl(*data); + } + + if(filter(*data,"a=StartTime:integer;",&buf)) { + desc->start_time=atoi(buf); + handled=1; + *data=nl(*data); + } + + if(filter(*data,"a=Preroll:integer;",&buf)) { + desc->preroll=atoi(buf); + handled=1; + *data=nl(*data); + } + + if(filter(*data,"a=length:npt=",&buf)) { + desc->duration=(uint32_t)(atof(buf)*1000); + handled=1; + *data=nl(*data); + } + + if(filter(*data,"a=StreamName:string;",&buf)) { + desc->stream_name=strdup(buf); + desc->stream_name_size=strlen(desc->stream_name); + handled=1; + *data=nl(*data); + } + + if(filter(*data,"a=mimetype:string;",&buf)) { + desc->mime_type=strdup(buf); + desc->mime_type_size=strlen(desc->mime_type); + handled=1; + *data=nl(*data); + } + + if(filter(*data,"a=OpaqueData:buffer;",&buf)) { + decoded = b64_decode(buf, decoded, &(desc->mlti_data_size)); + desc->mlti_data=malloc(sizeof(char)*desc->mlti_data_size); + memcpy(desc->mlti_data, decoded, desc->mlti_data_size); + handled=1; + *data=nl(*data); +#ifdef LOG + printf("mlti_data_size: %i\n", desc->mlti_data_size); +#endif + } + + if(filter(*data,"a=ASMRuleBook:string;",&buf)) { + desc->asm_rule_book=strdup(buf); + handled=1; + *data=nl(*data); + } + + if(!handled) { +#ifdef LOG + int len=strchr(*data,'\n')-(*data); + xine_buffer_copyin(buf, 0, *data, len+1); + buf[len]=0; + printf("libreal: sdpplin: not handled: '%s'\n", buf); +#endif + *data=nl(*data); + } + } + + xine_buffer_free(buf); + xine_buffer_free(decoded); + + return desc; +} + +sdpplin_t *sdpplin_parse(char *data) { + + sdpplin_t *desc=xine_xmalloc(sizeof(sdpplin_t)); + sdpplin_stream_t *stream; + char *buf=xine_buffer_init(32); + char *decoded=xine_buffer_init(32); + int handled; + int len; + + while (*data) { + + handled=0; + + if (filter(data, "m=", &buf)) { + stream=sdpplin_parse_stream(&data); +#ifdef LOG + printf("got data for stream id %u\n", stream->stream_id); +#endif + desc->stream[stream->stream_id]=stream; + continue; + } + + if(filter(data,"a=Title:buffer;",&buf)) { + decoded=b64_decode(buf, decoded, &len); + desc->title=strdup(decoded); + handled=1; + data=nl(data); + } + + if(filter(data,"a=Author:buffer;",&buf)) { + decoded=b64_decode(buf, decoded, &len); + desc->author=strdup(decoded); + handled=1; + data=nl(data); + } + + if(filter(data,"a=Copyright:buffer;",&buf)) { + decoded=b64_decode(buf, decoded, &len); + desc->copyright=strdup(decoded); + handled=1; + data=nl(data); + } + + if(filter(data,"a=Abstract:buffer;",&buf)) { + decoded=b64_decode(buf, decoded, &len); + desc->abstract=strdup(decoded); + handled=1; + data=nl(data); + } + + if(filter(data,"a=StreamCount:integer;",&buf)) { + desc->stream_count=atoi(buf); + desc->stream=malloc(sizeof(sdpplin_stream_t*)*desc->stream_count); + handled=1; + data=nl(data); + } + + if(filter(data,"a=Flags:integer;",&buf)) { + desc->flags=atoi(buf); + handled=1; + data=nl(data); + } + + if(!handled) { +#ifdef LOG + int len=strchr(data,'\n')-data; + xine_buffer_copyin(buf, 0, data, len+1); + buf[len]=0; + printf("libreal: sdpplin: not handled: '%s'\n", buf); +#endif + data=nl(data); + } + } + + xine_buffer_free(buf); + xine_buffer_free(decoded); + + return desc; +} + +void sdpplin_free(sdpplin_t *description) { + + /* TODO: free strings */ + free(description); +} + diff --git a/src/input/libreal/sdpplin.h b/src/input/libreal/sdpplin.h new file mode 100644 index 000000000..bfc017a56 --- /dev/null +++ b/src/input/libreal/sdpplin.h @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2002 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * $Id: sdpplin.h,v 1.1 2002/12/24 01:30:22 holstsn Exp $ + * + * sdp/sdpplin parser. + * + */ + +#ifndef HAVE_SDPPLIN_H +#define HAVE_SDPPLIN_H + +#include "rmff.h" +#include "rtsp.h" + +#ifdef __CYGWIN__ +#define uint32_t unsigned int +#define uint16_t unsigned short int +#define uint8_t unsigned char +#endif + +typedef struct { + + char *id; + char *bandwidth; + + int stream_id; + char *range; + char *length; + char *rtpmap; + char *mimetype; + int min_switch_overlap; + int start_time; + int end_one_rule_end_all; + int avg_bit_rate; + int max_bit_rate; + int avg_packet_size; + int max_packet_size; + int end_time; + int seek_greater_on_switch; + int preroll; + + int duration; + char *stream_name; + int stream_name_size; + char *mime_type; + int mime_type_size; + char *mlti_data; + int mlti_data_size; + int rmff_flags_length; + char *rmff_flags; + int asm_rule_book_length; + char *asm_rule_book; + +} sdpplin_stream_t; + +typedef struct { + + int sdp_version, sdpplin_version; + char *owner; + char *session_name; + char *session_info; + char *uri; + char *email; + char *phone; + char *connection; + char *bandwidth; + + int flags; + int is_real_data_type; + int stream_count; + char *title; + char *author; + char *copyright; + char *keywords; + int asm_rule_book_length; + char *asm_rule_book; + char *abstract; + char *range; + int avg_bit_rate; + int max_bit_rate; + int avg_packet_size; + int max_packet_size; + int preroll; + int duration; + + sdpplin_stream_t **stream; + +} sdpplin_t; + +sdpplin_t *sdpplin_parse(char *data); + +void sdpplin_free(sdpplin_t *description); + +#endif + |