[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[517] mplayerxp/libmpstream
Brought to you by:
olov
From: <nic...@us...> - 2012-12-07 16:04:06
|
Revision: 517 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=517&view=rev Author: nickols_k Date: 2012-12-07 16:03:55 +0000 (Fri, 07 Dec 2012) Log Message: ----------- more or less accuracies in return codes Modified Paths: -------------- mplayerxp/libmpstream/asf_mmst_streaming.cpp mplayerxp/libmpstream/asf_streaming.cpp mplayerxp/libmpstream/asf_streaming.h mplayerxp/libmpstream/network.cpp mplayerxp/libmpstream/network.h mplayerxp/libmpstream/s_network.cpp mplayerxp/libmpstream/s_rtsp.cpp mplayerxp/libmpstream/s_udp.cpp Modified: mplayerxp/libmpstream/asf_mmst_streaming.cpp =================================================================== --- mplayerxp/libmpstream/asf_mmst_streaming.cpp 2012-12-07 14:29:41 UTC (rev 516) +++ mplayerxp/libmpstream/asf_mmst_streaming.cpp 2012-12-07 16:03:55 UTC (rev 517) @@ -490,169 +490,161 @@ return -1; } -int asf_mmst_networking_start(Tcp& tcp, networking_t *networking) +MPXP_Rc asf_mmst_networking_start(Tcp& tcp, networking_t *networking) { - char str[1024]; - unsigned char data[BUF_SIZE]; - uint8_t asf_header[HDR_BUF_SIZE]; - int asf_header_len; - int len, i, packet_length; - char *path, *unescpath; - URL_t *url1 = networking->url; + char str[1024]; + uint8_t data[BUF_SIZE]; + uint8_t asf_header[HDR_BUF_SIZE]; + int asf_header_len; + int len, i, packet_length; + char* path, *unescpath; + URL_t* url1 = networking->url; - tcp.close(); + tcp.close(); - /* parse url */ - path = strchr(url1->file,'/') + 1; + /* parse url */ + path = strchr(url1->file,'/') + 1; - /* mmst filename are not url_escaped by MS MediaPlayer and are expected as - * "plain text" by the server, so need to decode it here - */ - unescpath=new char [strlen(path)+1]; - if (!unescpath) { + /* mmst filename are not url_escaped by MS MediaPlayer and are expected as + * "plain text" by the server, so need to decode it here + */ + unescpath=new char [strlen(path)+1]; + if (!unescpath) { MSG_FATAL("Memory allocation failed!\n"); - return -1; - } - url2string(unescpath,path); - path=unescpath; + return MPXP_False; + } + url2string(unescpath,path); + path=unescpath; - if( url1->port==0 ) { - url1->port=1755; - } - tcp.open(networking->libinput, url1->hostname, url1->port, Tcp::IP4); - if( !tcp.established()) { - delete path; - return -1; - } - MSG_INFO ("connected\n"); + if( url1->port==0 ) url1->port=1755; + tcp.open(networking->libinput, url1->hostname, url1->port, Tcp::IP4); + if( !tcp.established()) { + delete path; + return MPXP_False; + } + MSG_INFO ("connected\n"); - seq_num=0; + seq_num=0; - /* - * Send the initial connect info including player version no. Client GUID (random) and the host address being connected to. - * This command is sent at the very start of protocol initiation. It sends local information to the serve - * cmd 1 0x01 - * */ + /* + * Send the initial connect info including player version no. Client GUID (random) and the host address being connected to. + * This command is sent at the very start of protocol initiation. It sends local information to the serve + * cmd 1 0x01 + * */ - /* prepare for the url encoding conversion */ + /* prepare for the url encoding conversion */ #ifdef USE_ICONV #ifdef USE_LANGINFO - url_conv = iconv_open("UTF-16LE",nl_langinfo(CODESET)); + url_conv = iconv_open("UTF-16LE",nl_langinfo(CODESET)); #else - url_conv = iconv_open("UTF-16LE", NULL); + url_conv = iconv_open("UTF-16LE", NULL); #endif #endif - snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname); - string_utf16 (data, str, strlen(str)); + snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname); + string_utf16 (data, str, strlen(str)); // send_command(s, commandno ....) - send_command (tcp, 1, 0, 0x0004000b, strlen(str) * 2+2, data); + send_command (tcp, 1, 0, 0x0004000b, strlen(str) * 2+2, data); - len = tcp.read (data, BUF_SIZE); + len = tcp.read (data, BUF_SIZE); - /*This sends details of the local machine IP address to a Funnel system at the server. - * Also, the TCP or UDP transport selection is sent. - * - * here 192.168.0.129 is local ip address TCP/UDP states the tronsport we r using - * and 1037 is the local TCP or UDP socket number - * cmd 2 0x02 - * */ + /*This sends details of the local machine IP address to a Funnel system at the server. + * Also, the TCP or UDP transport selection is sent. + * + * here 192.168.0.129 is local ip address TCP/UDP states the tronsport we r using + * and 1037 is the local TCP or UDP socket number + * cmd 2 0x02 + * */ - string_utf16 (&data[8], "\002\000\\\\192.168.0.1\\TCP\\1037", 24); - memset (data, 0, 8); - send_command (tcp, 2, 0, 0, 24*2+10, data); + string_utf16 (&data[8], "\002\000\\\\192.168.0.1\\TCP\\1037", 24); + memset (data, 0, 8); + send_command (tcp, 2, 0, 0, 24*2+10, data); - len = tcp.read(data, BUF_SIZE); + len = tcp.read(data, BUF_SIZE); - /* This command sends file path (at server) and file name request to the server. - * 0x5 */ + /* This command sends file path (at server) and file name request to the server. + * 0x5 */ - string_utf16 (&data[8], path, strlen(path)); - memset (data, 0, 8); - send_command (tcp, 5, 0, 0, strlen(path)*2+10, data); - delete path; + string_utf16 (&data[8], path, strlen(path)); + memset (data, 0, 8); + send_command (tcp, 5, 0, 0, strlen(path)*2+10, data); + delete path; - get_answer (tcp); + get_answer (tcp); - /* The ASF header chunk request. Includes ?session' variable for pre header value. - * After this command is sent, - * the server replies with 0x11 command and then the header chunk with header data follows. - * 0x15 */ + /* The ASF header chunk request. Includes ?session' variable for pre header value. + * After this command is sent, + * the server replies with 0x11 command and then the header chunk with header data follows. + * 0x15 */ - memset (data, 0, 40); - data[32] = 2; + memset (data, 0, 40); + data[32] = 2; - send_command (tcp, 0x15, 1, 0, 40, data); + send_command (tcp, 0x15, 1, 0, 40, data); - num_stream_ids = 0; - /* get_headers(s, asf_header); */ + num_stream_ids = 0; + /* get_headers(s, asf_header); */ - asf_header_len = get_header (tcp, asf_header, networking); + asf_header_len = get_header (tcp, asf_header, networking); // printf("---------------------------------- asf_header %d\n",asf_header); - if (asf_header_len==0) { //error reading header - tcp.close(); - return -1; - } - packet_length = interp_header (asf_header, asf_header_len); + if (asf_header_len==0) { //error reading header + tcp.close(); + return MPXP_False; + } + packet_length = interp_header (asf_header, asf_header_len); + /* + * This command is the media stream MBR selector. Switches are always 6 bytes in length. + * After all switch elements, data ends with bytes [00 00] 00 20 ac 40 [02]. + * Where: + * [00 00] shows 0x61 0x00 (on the first 33 sent) or 0xff 0xff for ASF files, and with no ending data for WMV files. + * It is not yet understood what all this means. + * And the last [02] byte is probably the header ?session' value. + * + * 0x33 */ - /* - * This command is the media stream MBR selector. Switches are always 6 bytes in length. - * After all switch elements, data ends with bytes [00 00] 00 20 ac 40 [02]. - * Where: - * [00 00] shows 0x61 0x00 (on the first 33 sent) or 0xff 0xff for ASF files, and with no ending data for WMV files. - * It is not yet understood what all this means. - * And the last [02] byte is probably the header ?session' value. - * - * 0x33 */ + memset (data, 0, 40); - memset (data, 0, 40); + if (mp_conf.audio_id > 0) { + data[2] = 0xFF; + data[3] = 0xFF; + data[4] = mp_conf.audio_id; + send_command(tcp, 0x33, num_stream_ids, 0xFFFF | mp_conf.audio_id << 16, 8, data); + } else { + for (i=1; i<num_stream_ids; i++) { + data [ (i-1) * 6 + 2 ] = 0xFF; + data [ (i-1) * 6 + 3 ] = 0xFF; + data [ (i-1) * 6 + 4 ] = stream_ids[i]; + data [ (i-1) * 6 + 5 ] = 0x00; + } + send_command (tcp, 0x33, num_stream_ids, 0xFFFF | stream_ids[0] << 16, (num_stream_ids-1)*6+2 , data); + } - if (mp_conf.audio_id > 0) { - data[2] = 0xFF; - data[3] = 0xFF; - data[4] = mp_conf.audio_id; - send_command(tcp, 0x33, num_stream_ids, 0xFFFF | mp_conf.audio_id << 16, 8, data); - } else { - for (i=1; i<num_stream_ids; i++) { - data [ (i-1) * 6 + 2 ] = 0xFF; - data [ (i-1) * 6 + 3 ] = 0xFF; - data [ (i-1) * 6 + 4 ] = stream_ids[i]; - data [ (i-1) * 6 + 5 ] = 0x00; - } + get_answer (tcp); - send_command (tcp, 0x33, num_stream_ids, 0xFFFF | stream_ids[0] << 16, (num_stream_ids-1)*6+2 , data); - } + /* Start sending file from packet xx. + * This command is also used for resume downloads or requesting a lost packet. + * Also used for seeking by sending a play point value which seeks to the media time point. + * Includes ?session' value in pre header and the maximum media stream time. + * 0x07 */ - get_answer (tcp); + memset (data, 0, 40); - /* Start sending file from packet xx. - * This command is also used for resume downloads or requesting a lost packet. - * Also used for seeking by sending a play point value which seeks to the media time point. - * Includes ?session' value in pre header and the maximum media stream time. - * 0x07 */ + for (i=8; i<16; i++) data[i] = 0xFF; + data[20] = 0x04; - memset (data, 0, 40); + send_command (tcp, 0x07, 1, 0xFFFF | stream_ids[0] << 16, 24, data); - for (i=8; i<16; i++) - data[i] = 0xFF; + networking->networking_read = asf_mmst_networking_read; + networking->networking_seek = asf_mmst_networking_seek; + networking->buffering = 1; + networking->status = networking_playing_e; - data[20] = 0x04; + packet_length1 = packet_length; + MSG_V("mmst packet_length = %d\n",packet_length); - send_command (tcp, 0x07, 1, 0xFFFF | stream_ids[0] << 16, 24, data); - - networking->networking_read = asf_mmst_networking_read; - networking->networking_seek = asf_mmst_networking_seek; - networking->buffering = 1; - networking->status = networking_playing_e; - - packet_length1 = packet_length; - MSG_V("mmst packet_length = %d\n",packet_length); - #ifdef USE_ICONV - if (url_conv != (iconv_t)(-1)) - iconv_close(url_conv); + if (url_conv != (iconv_t)(-1)) iconv_close(url_conv); #endif - - return 0; + return MPXP_Ok; } Modified: mplayerxp/libmpstream/asf_streaming.cpp =================================================================== --- mplayerxp/libmpstream/asf_streaming.cpp 2012-12-07 14:29:41 UTC (rev 516) +++ mplayerxp/libmpstream/asf_streaming.cpp 2012-12-07 16:03:55 UTC (rev 517) @@ -51,7 +51,7 @@ // WMP sequence is MMSU then MMST and then HTTP. // In MPlayer case since HTTP support is more reliable, // we are doing HTTP first then we try MMST if HTTP fail. -static int asf_http_networking_start(Tcp& fd, networking_t *networking ); +static MPXP_Rc asf_http_networking_start(Tcp& fd, networking_t *networking ); /* ASF networking support several network protocol. @@ -73,17 +73,17 @@ In MPlayer case since HTTP support is more reliable, we are doing HTTP first then we try MMST if HTTP fail. */ -int asf_networking_start(Tcp& tcp, networking_t *networking) { +MPXP_Rc asf_networking_start(Tcp& tcp, networking_t *networking) { char *proto = networking->url->protocol; int port = networking->url->port; - int rc; + MPXP_Rc rc; // Is protocol even valid mms,mmsu,mmst,http,http_proxy? if (!(!strncasecmp(proto, "mmst", 4) || !strncasecmp(proto, "mmsu", 4) || !strncasecmp(proto, "http_proxy", 10) || !strncasecmp(proto, "mms", 3) || !strncasecmp(proto, "http", 4))) { MSG_ERR("Unknown protocol: %s\n", proto ); - return -1; + return MPXP_False; } // Is protocol mms or mmsu? @@ -92,7 +92,7 @@ //fd = asf_mmsu_networking_start( stream ); //mmsu support is not implemented yet - using this code MSG_V(" ===> ASF/UDP failed\n"); - return -1; + return MPXP_False; } //Is protocol mms or mmst? @@ -100,9 +100,9 @@ MSG_V("Trying ASF/TCP...\n"); rc = asf_mmst_networking_start(tcp,networking); networking->url->port = port; - if( rc>-1 ) return 0; + if( rc==MPXP_Ok ) return MPXP_Ok; MSG_V(" ===> ASF/TCP failed\n"); - if( rc==-2 ) return -1; + return MPXP_False; } //Is protocol http, http_proxy, or mms? @@ -111,12 +111,12 @@ MSG_V("Trying ASF/HTTP...\n"); rc = asf_http_networking_start(tcp,networking); networking->url->port = port; - if( rc>-1 ) return 0; + if( rc==MPXP_Ok ) return MPXP_Ok; MSG_V(" ===> ASF/HTTP failed\n"); - if( rc==-2 ) return -1; + return MPXP_False; } //everything failed - return -1; + return MPXP_False; } static int @@ -184,256 +184,235 @@ return best; } -static int +static MPXP_Rc asf_networking_parse_header(Tcp& tcp, networking_t* networking) { - ASF_header_t asfh; - ASF_stream_chunck_t chunk; - asf_http_networking_t* asf_ctrl = (asf_http_networking_t*) networking->data; - char* buffer=NULL, *chunk_buffer=NULL; - int i,r,size,pos = 0; - int start; - int buffer_size = 0; - int chunk_size2read = 0; - int bw = networking->bandwidth; - int *v_rates = NULL, *a_rates = NULL; - int v_rate = 0, a_rate = 0, a_idx = -1, v_idx = -1; + ASF_header_t asfh; + ASF_stream_chunck_t chunk; + asf_http_networking_t* asf_ctrl = (asf_http_networking_t*) networking->data; + char* buffer=NULL, *chunk_buffer=NULL; + int i,r,size,pos = 0; + int start; + int buffer_size = 0; + int chunk_size2read = 0; + int bw = networking->bandwidth; + int *v_rates = NULL, *a_rates = NULL; + int v_rate = 0, a_rate = 0, a_idx = -1, v_idx = -1; - if(asf_ctrl == NULL) return -1; + if(asf_ctrl == NULL) return MPXP_False; - // The ASF header can be in several network chunks. For example if the content description - // is big, the ASF header will be split in 2 network chunk. - // So we need to retrieve all the chunk before starting to parse the header. - do { - for( r=0; r < (int)sizeof(ASF_stream_chunck_t) ; ) { - i = nop_networking_read(tcp,((char*)&chunk)+r,sizeof(ASF_stream_chunck_t) - r,networking); - if(i <= 0) return -1; - r += i; - } - // Endian handling of the stream chunk - le2me_ASF_stream_chunck_t(&chunk); - size = asf_networking( &chunk, &r) - sizeof(ASF_stream_chunck_t); - if(r) MSG_WARN("Warning : drop header ????\n"); - if(size < 0){ - MSG_ERR("Error while parsing chunk header\n"); - return -1; - } - if (chunk.type != ASF_STREAMING_HEADER) { + // The ASF header can be in several network chunks. For example if the content description + // is big, the ASF header will be split in 2 network chunk. + // So we need to retrieve all the chunk before starting to parse the header. + do { + for( r=0; r < (int)sizeof(ASF_stream_chunck_t) ; ) { + i = nop_networking_read(tcp,((char*)&chunk)+r,sizeof(ASF_stream_chunck_t) - r,networking); + if(i <= 0) return MPXP_False; + r += i; + } + // Endian handling of the stream chunk + le2me_ASF_stream_chunck_t(&chunk); + size = asf_networking( &chunk, &r) - sizeof(ASF_stream_chunck_t); + if(r) MSG_WARN("Warning : drop header ????\n"); + if(size < 0){ + MSG_ERR("Error while parsing chunk header\n"); + return MPXP_False; + } + if (chunk.type != ASF_STREAMING_HEADER) { MSG_ERR("Don't got a header as first chunk !!!!\n"); - return -1; - } - - // audit: do not overflow buffer_size - if (size > std::numeric_limits<size_t>::max() - buffer_size) return -1; - buffer = (char*) mp_malloc(size+buffer_size); - if(buffer == NULL) { + return MPXP_False; + } + // audit: do not overflow buffer_size + if (size > std::numeric_limits<size_t>::max() - buffer_size) return MPXP_False; + buffer = (char*) mp_malloc(size+buffer_size); + if(buffer == NULL) { MSG_FATAL("Error can't allocate %d bytes buffer\n",size+buffer_size); - return -1; - } - if( chunk_buffer!=NULL ) { - memcpy( buffer, chunk_buffer, buffer_size ); - delete chunk_buffer ; - } - chunk_buffer = buffer; - buffer += buffer_size; - buffer_size += size; + return MPXP_False; + } + if( chunk_buffer!=NULL ) { + memcpy( buffer, chunk_buffer, buffer_size ); + delete chunk_buffer ; + } + chunk_buffer = buffer; + buffer += buffer_size; + buffer_size += size; - for(r = 0; r < size;) { + for(r = 0; r < size;) { i = nop_networking_read(tcp,buffer+r,size-r,networking); if(i < 0) { - MSG_ERR("Error while reading network stream\n"); - return -1; + MSG_ERR("Error while reading network stream\n"); + return MPXP_False; } r += i; - } + } - if( chunk_size2read==0 ) { - if(size < (int)sizeof(asfh)) { - MSG_ERR("Error chunk is too small\n"); - return -1; - } else MSG_DBG2("Got chunk\n"); - memcpy(&asfh,buffer,sizeof(asfh)); - le2me_ASF_header_t(&asfh); - chunk_size2read = asfh.objh.size; - MSG_DBG2("Size 2 read=%d\n", chunk_size2read); - } - } while( buffer_size<chunk_size2read); - buffer = chunk_buffer; - size = buffer_size; + if( chunk_size2read==0 ) { + if(size < (int)sizeof(asfh)) { + MSG_ERR("Error chunk is too small\n"); + return MPXP_False; + } else MSG_DBG2("Got chunk\n"); + memcpy(&asfh,buffer,sizeof(asfh)); + le2me_ASF_header_t(&asfh); + chunk_size2read = asfh.objh.size; + MSG_DBG2("Size 2 read=%d\n", chunk_size2read); + } + } while( buffer_size<chunk_size2read); + buffer = chunk_buffer; + size = buffer_size; - if(asfh.cno > 256) { - MSG_ERR("Error sub chunks number is invalid\n"); - return -1; - } + if(asfh.cno > 256) { + MSG_ERR("Error sub chunks number is invalid\n"); + return MPXP_False; + } - start = sizeof(asfh); + start = sizeof(asfh); - pos = find_asf_guid(buffer, asf_file_header_guid, start, size); - if (pos >= 0) { - ASF_file_header_t *fileh = (ASF_file_header_t *) &buffer[pos]; - pos += sizeof(ASF_file_header_t); - if (pos > size) goto len_err_out; - le2me_ASF_file_header_t(fileh); -/* - if(fileh.packetsize != fileh.packetsize2) { - printf("Error packetsize check don't match\n"); - return -1; - } -*/ - asf_ctrl->packet_size = fileh->max_packet_size; - // before playing. - // preroll: time in ms to bufferize before playing - networking->prebuffer_size = (unsigned int)(((double)fileh->preroll/1000.0)*((double)fileh->max_bitrate/8.0)); - } + pos = find_asf_guid(buffer, asf_file_header_guid, start, size); + if (pos >= 0) { + ASF_file_header_t *fileh = (ASF_file_header_t *) &buffer[pos]; + pos += sizeof(ASF_file_header_t); + if (pos > size) goto len_err_out; + le2me_ASF_file_header_t(fileh); + asf_ctrl->packet_size = fileh->max_packet_size; + // before playing. + // preroll: time in ms to bufferize before playing + networking->prebuffer_size = (unsigned int)(((double)fileh->preroll/1000.0)*((double)fileh->max_bitrate/8.0)); + } - pos = start; - while ((pos = find_asf_guid(buffer, asf_stream_header_guid, pos, size)) >= 0) - { - ASF_stream_header_t *streamh = (ASF_stream_header_t *)&buffer[pos]; - pos += sizeof(ASF_stream_header_t); - if (pos > size) goto len_err_out; - le2me_ASF_stream_header_t(streamh); - switch(ASF_LOAD_GUID_PREFIX(streamh->type)) { - case 0xF8699E40 : // audio stream - if(asf_ctrl->audio_streams == NULL){ - asf_ctrl->audio_streams = (int*)mp_malloc(sizeof(int)); - asf_ctrl->n_audio = 1; - } else { - asf_ctrl->n_audio++; - asf_ctrl->audio_streams = (int*)mp_realloc(asf_ctrl->audio_streams, - asf_ctrl->n_audio*sizeof(int)); - } - asf_ctrl->audio_streams[asf_ctrl->n_audio-1] = streamh->stream_no; - break; - case 0xBC19EFC0 : // video stream - if(asf_ctrl->video_streams == NULL){ - asf_ctrl->video_streams = (int*)mp_malloc(sizeof(int)); - asf_ctrl->n_video = 1; - } else { - asf_ctrl->n_video++; - asf_ctrl->video_streams = (int*)mp_realloc(asf_ctrl->video_streams, + pos = start; + while ((pos = find_asf_guid(buffer, asf_stream_header_guid, pos, size)) >= 0) { + ASF_stream_header_t *streamh = (ASF_stream_header_t *)&buffer[pos]; + pos += sizeof(ASF_stream_header_t); + if (pos > size) goto len_err_out; + le2me_ASF_stream_header_t(streamh); + switch(ASF_LOAD_GUID_PREFIX(streamh->type)) { + case 0xF8699E40 : // audio stream + if(asf_ctrl->audio_streams == NULL){ + asf_ctrl->audio_streams = (int*)mp_malloc(sizeof(int)); + asf_ctrl->n_audio = 1; + } else { + asf_ctrl->n_audio++; + asf_ctrl->audio_streams = (int*)mp_realloc(asf_ctrl->audio_streams, + asf_ctrl->n_audio*sizeof(int)); + } + asf_ctrl->audio_streams[asf_ctrl->n_audio-1] = streamh->stream_no; + break; + case 0xBC19EFC0 : // video stream + if(asf_ctrl->video_streams == NULL){ + asf_ctrl->video_streams = (int*)mp_malloc(sizeof(int)); + asf_ctrl->n_video = 1; + } else { + asf_ctrl->n_video++; + asf_ctrl->video_streams = (int*)mp_realloc(asf_ctrl->video_streams, asf_ctrl->n_video*sizeof(int)); + } + asf_ctrl->video_streams[asf_ctrl->n_video-1] = streamh->stream_no; + break; } - asf_ctrl->video_streams[asf_ctrl->n_video-1] = streamh->stream_no; - break; - } - } + } - // always allocate to avoid lots of ifs later - v_rates =new(zeromem) int [asf_ctrl->n_video]; - a_rates =new(zeromem) int [asf_ctrl->n_audio]; + // always allocate to avoid lots of ifs later + v_rates =new(zeromem) int [asf_ctrl->n_video]; + a_rates =new(zeromem) int [asf_ctrl->n_audio]; - pos = find_asf_guid(buffer, asf_stream_group_guid, start, size); - if (pos >= 0) { - // stream bitrate properties object + pos = find_asf_guid(buffer, asf_stream_group_guid, start, size); + if (pos >= 0) { + // stream bitrate properties object int stream_count; char *ptr = &buffer[pos]; MSG_V("Stream bitrate properties object\n"); - stream_count = le2me_16(*(uint16_t*)ptr); - ptr += sizeof(uint16_t); - if (ptr > &buffer[size]) goto len_err_out; - MSG_V(" stream count=[0x%x][%u]\n", - stream_count, stream_count ); - for( i=0 ; i<stream_count ; i++ ) { - uint32_t rate; - int id; - int j; - id = le2me_16(*(uint16_t*)ptr); - ptr += sizeof(uint16_t); - if (ptr > &buffer[size]) goto len_err_out; - memcpy(&rate, ptr, sizeof(uint32_t));// workaround unaligment bug on sparc - ptr += sizeof(uint32_t); - if (ptr > &buffer[size]) goto len_err_out; - rate = le2me_32(rate); - MSG_V( - " stream id=[0x%x][%u]\n", id, id); - MSG_V( - " max bitrate=[0x%x][%u]\n", rate, rate); - for (j = 0; j < asf_ctrl->n_video; j++) { - if (id == asf_ctrl->video_streams[j]) { - MSG_V(" is video stream\n"); - v_rates[j] = rate; - break; - } - } - for (j = 0; j < asf_ctrl->n_audio; j++) { - if (id == asf_ctrl->audio_streams[j]) { - MSG_V( " is audio stream\n"); - a_rates[j] = rate; - break; - } - } + stream_count = le2me_16(*(uint16_t*)ptr); + ptr += sizeof(uint16_t); + if (ptr > &buffer[size]) goto len_err_out; + MSG_V(" stream count=[0x%x][%u]\n",stream_count, stream_count ); + for( i=0 ; i<stream_count ; i++ ) { + uint32_t rate; + int id; + int j; + id = le2me_16(*(uint16_t*)ptr); + ptr += sizeof(uint16_t); + if (ptr > &buffer[size]) goto len_err_out; + memcpy(&rate, ptr, sizeof(uint32_t));// workaround unaligment bug on sparc + ptr += sizeof(uint32_t); + if (ptr > &buffer[size]) goto len_err_out; + rate = le2me_32(rate); + MSG_V(" stream id=[0x%x][%u]\n", id, id); + MSG_V(" max bitrate=[0x%x][%u]\n", rate, rate); + for (j = 0; j < asf_ctrl->n_video; j++) { + if (id == asf_ctrl->video_streams[j]) { + MSG_V(" is video stream\n"); + v_rates[j] = rate; + break; } - } - delete buffer; + } + for (j = 0; j < asf_ctrl->n_audio; j++) { + if (id == asf_ctrl->audio_streams[j]) { + MSG_V( " is audio stream\n"); + a_rates[j] = rate; + break; + } + } + } + } + delete buffer; - // automatic stream selection based on bandwidth - if (bw == 0) bw = INT_MAX; - MSG_V( "Max bandwidth set to %d\n", bw); + // automatic stream selection based on bandwidth + if (bw == 0) bw = INT_MAX; + MSG_V( "Max bandwidth set to %d\n", bw); - if (asf_ctrl->n_audio) { - // find lowest-bitrate audio stream - a_rate = a_rates[0]; - a_idx = 0; - for (i = 0; i < asf_ctrl->n_audio; i++) { - if (a_rates[i] < a_rate) { - a_rate = a_rates[i]; - a_idx = i; - } + if (asf_ctrl->n_audio) { + // find lowest-bitrate audio stream + a_rate = a_rates[0]; + a_idx = 0; + for (i = 0; i < asf_ctrl->n_audio; i++) { + if (a_rates[i] < a_rate) { + a_rate = a_rates[i]; + a_idx = i; + } + } + if (max_idx(asf_ctrl->n_video, v_rates, bw - a_rate) < 0) { + // both audio and video are not possible, try video only next + a_idx = -1; + a_rate = 0; + } } - if (max_idx(asf_ctrl->n_video, v_rates, bw - a_rate) < 0) { - // both audio and video are not possible, try video only next - a_idx = -1; - a_rate = 0; - } - } - // find best video stream - v_idx = max_idx(asf_ctrl->n_video, v_rates, bw - a_rate); - if (v_idx >= 0) - v_rate = v_rates[v_idx]; + // find best video stream + v_idx = max_idx(asf_ctrl->n_video, v_rates, bw - a_rate); + if (v_idx >= 0) v_rate = v_rates[v_idx]; + // find best audio stream + a_idx = max_idx(asf_ctrl->n_audio, a_rates, bw - v_rate); - // find best audio stream - a_idx = max_idx(asf_ctrl->n_audio, a_rates, bw - v_rate); + delete v_rates; + delete a_rates; - delete v_rates; - delete a_rates; + if (a_idx < 0 && v_idx < 0) { + MSG_FATAL( "bandwidth too small, file cannot be played!\n"); + return MPXP_False; + } - if (a_idx < 0 && v_idx < 0) { - MSG_FATAL( "bandwidth too small, " - "file cannot be played!\n"); - return -1; - } - - if (mp_conf.audio_id > 0) // a audio stream was forced - asf_ctrl->audio_id = mp_conf.audio_id; - else if (a_idx >= 0) - asf_ctrl->audio_id = asf_ctrl->audio_streams[a_idx]; - else if (asf_ctrl->n_audio) { - MSG_WARN( "bandwidth too small, " - "deselected audio stream\n"); - mp_conf.audio_id = -2; - } + if (mp_conf.audio_id > 0) asf_ctrl->audio_id = mp_conf.audio_id; + else if (a_idx >= 0) asf_ctrl->audio_id = asf_ctrl->audio_streams[a_idx]; + else if (asf_ctrl->n_audio) { + MSG_WARN( "bandwidth too small, deselected audio stream\n"); + mp_conf.audio_id = -2; + } - if (mp_conf.video_id > 0) // a video stream was forced - asf_ctrl->video_id = mp_conf.video_id; - else if (v_idx >= 0) - asf_ctrl->video_id = asf_ctrl->video_streams[v_idx]; - else if (asf_ctrl->n_video) { - MSG_WARN( "bandwidth too small, " - "deselected video stream\n"); - mp_conf.video_id = -2; - } + if (mp_conf.video_id > 0) asf_ctrl->video_id = mp_conf.video_id; + else if (v_idx >= 0) asf_ctrl->video_id = asf_ctrl->video_streams[v_idx]; + else if (asf_ctrl->n_video) { + MSG_WARN( "bandwidth too small, deselected video stream\n"); + mp_conf.video_id = -2; + } + return MPXP_Ok; - return 1; - len_err_out: - MSG_FATAL( "Invalid length in ASF header!\n"); - if (buffer) delete buffer; - if (v_rates) delete v_rates; - if (a_rates) delete a_rates; - return -1; + MSG_FATAL( "Invalid length in ASF header!\n"); + if (buffer) delete buffer; + if (v_rates) delete v_rates; + if (a_rates) delete a_rates; + return MPXP_False; } static int @@ -741,131 +720,129 @@ return 0; } -static int asf_http_networking_start(Tcp& tcp, networking_t *networking) { - HTTP_header_t *http_hdr=NULL; - URL_t *url = networking->url; - asf_http_networking_t *asf_http_ctrl; - char buffer[BUFFER_SIZE]; - int i, ret; - int done; - int auth_retry = 0; +static MPXP_Rc asf_http_networking_start(Tcp& tcp, networking_t *networking) { + HTTP_header_t *http_hdr=NULL; + URL_t *url = networking->url; + asf_http_networking_t *asf_http_ctrl; + char buffer[BUFFER_SIZE]; + int i, ret; + int done; + int auth_retry = 0; - asf_http_ctrl = new(zeromem) asf_http_networking_t; - if( asf_http_ctrl==NULL ) { - MSG_FATAL("Memory allocation failed\n"); - return -1; + asf_http_ctrl = new(zeromem) asf_http_networking_t; + if( asf_http_ctrl==NULL ) { + MSG_FATAL("Memory allocation failed\n"); + return MPXP_False; + } + asf_http_ctrl->networking_type = ASF_Unknown_e; + asf_http_ctrl->request = 1; + asf_http_ctrl->audio_streams = asf_http_ctrl->video_streams = NULL; + asf_http_ctrl->n_audio = asf_http_ctrl->n_video = 0; + networking->data = (any_t*)asf_http_ctrl; + + do { + done = 1; + tcp.close(); + + if( !strcasecmp( url->protocol, "http_proxy" ) ) { + if( url->port==0 ) url->port = 8080; + } else { + if( url->port==0 ) url->port = 80; } - asf_http_ctrl->networking_type = ASF_Unknown_e; - asf_http_ctrl->request = 1; - asf_http_ctrl->audio_streams = asf_http_ctrl->video_streams = NULL; - asf_http_ctrl->n_audio = asf_http_ctrl->n_video = 0; - networking->data = (any_t*)asf_http_ctrl; + tcp.open(networking->libinput, url->hostname, url->port, Tcp::IP4); + if( !tcp.established()) return MPXP_False; + http_hdr = asf_http_request( networking ); + MSG_DBG2("Request [%s]\n", http_hdr->buffer ); + for(i=0; i < (int)http_hdr->buffer_size ; ) { + int r = tcp.write((uint8_t*)(http_hdr->buffer+i), http_hdr->buffer_size-i); + if(r<0) { + MSG_ERR("Socket write error : %s\n",strerror(errno)); + return MPXP_False; + } + i += r; + } + http_free( http_hdr ); + http_hdr = http_new_header(); do { - done = 1; - tcp.close(); - - if( !strcasecmp( url->protocol, "http_proxy" ) ) { - if( url->port==0 ) url->port = 8080; - } else { - if( url->port==0 ) url->port = 80; + i = tcp.read((uint8_t*)buffer, BUFFER_SIZE); + if( i<=0 ) { + perror("read"); + http_free( http_hdr ); + return MPXP_False; + } + http_response_append( http_hdr, buffer, i ); + } while( !http_is_header_entire( http_hdr ) ); + if( mp_conf.verbose>0 ) { + http_hdr->buffer[http_hdr->buffer_size]='\0'; + MSG_DBG2("Response [%s]\n", http_hdr->buffer ); + } + ret = asf_http_parse_response(asf_http_ctrl, http_hdr); + if( ret<0 ) { + MSG_ERR("Failed to parse header\n"); + http_free( http_hdr ); + return MPXP_False; + } + switch( asf_http_ctrl->networking_type ) { + case ASF_Live_e: + case ASF_Prerecorded_e: + case ASF_PlainText_e: + if( http_hdr->body_size>0 ) { + if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { + http_free( http_hdr ); + return MPXP_False; + } } - tcp.open(networking->libinput, url->hostname, url->port, Tcp::IP4); - if( !tcp.established()) return 0; - - http_hdr = asf_http_request( networking ); - MSG_DBG2("Request [%s]\n", http_hdr->buffer ); - for(i=0; i < (int)http_hdr->buffer_size ; ) { - int r = tcp.write((uint8_t*)(http_hdr->buffer+i), http_hdr->buffer_size-i); - if(r <0) { - MSG_ERR("Socket write error : %s\n",strerror(errno)); - return -1; + if( asf_http_ctrl->request==1 ) { + if( asf_http_ctrl->networking_type!=ASF_PlainText_e ) { + // First request, we only got the ASF header. + ret = asf_networking_parse_header(tcp,networking); + if(ret < 0) return MPXP_False; + if(asf_http_ctrl->n_audio == 0 && asf_http_ctrl->n_video == 0) { + MSG_ERR("No stream found\n"); + return MPXP_False; } - i += r; + asf_http_ctrl->request++; + done = 0; + } else done = 1; } - http_free( http_hdr ); - http_hdr = http_new_header(); - do { - i = tcp.read((uint8_t*)buffer, BUFFER_SIZE); - if( i<=0 ) { - perror("read"); - http_free( http_hdr ); - return -1; - } - http_response_append( http_hdr, buffer, i ); - } while( !http_is_header_entire( http_hdr ) ); - if( mp_conf.verbose>0 ) { - http_hdr->buffer[http_hdr->buffer_size]='\0'; - MSG_DBG2("Response [%s]\n", http_hdr->buffer ); - } - ret = asf_http_parse_response(asf_http_ctrl, http_hdr); - if( ret<0 ) { - MSG_ERR("Failed to parse header\n"); + break; + case ASF_Redirector_e: + if( http_hdr->body_size>0 ) { + if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { http_free( http_hdr ); - return -1; + return MPXP_False; + } } - switch( asf_http_ctrl->networking_type ) { - case ASF_Live_e: - case ASF_Prerecorded_e: - case ASF_PlainText_e: - if( http_hdr->body_size>0 ) { - if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { - http_free( http_hdr ); - return -1; - } - } - if( asf_http_ctrl->request==1 ) { - if( asf_http_ctrl->networking_type!=ASF_PlainText_e ) { - // First request, we only got the ASF header. - ret = asf_networking_parse_header(tcp,networking); - if(ret < 0) return -1; - if(asf_http_ctrl->n_audio == 0 && asf_http_ctrl->n_video == 0) { - MSG_ERR("No stream found\n"); - return -1; - } - asf_http_ctrl->request++; - done = 0; - } else { - done = 1; - } - } - break; - case ASF_Redirector_e: - if( http_hdr->body_size>0 ) { - if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { - http_free( http_hdr ); - return -1; - } - } -// type |= STREAMTYPE_TEXT; - done = 1; - break; - case ASF_Authenticate_e: - if( http_authenticate( http_hdr, url, &auth_retry)<0 ) return -1; - asf_http_ctrl->networking_type = ASF_Unknown_e; - done = 0; - break; - case ASF_Unknown_e: - default: - MSG_ERR("Unknown ASF networking type\n"); - tcp.close(); - http_free( http_hdr ); - return -1; - } - // Check if we got a redirect. - } while(!done); - - if( asf_http_ctrl->networking_type==ASF_PlainText_e || asf_http_ctrl->networking_type==ASF_Redirector_e ) { - networking->networking_read = nop_networking_read; - networking->networking_seek = nop_networking_seek; - } else { - networking->networking_read = asf_http_networking_read; - networking->networking_seek = asf_http_networking_seek; - networking->buffering = 1; +// type |= STREAMTYPE_TEXT; + done = 1; + break; + case ASF_Authenticate_e: + if( http_authenticate( http_hdr, url, &auth_retry)<0 ) return MPXP_False; + asf_http_ctrl->networking_type = ASF_Unknown_e; + done = 0; + break; + case ASF_Unknown_e: + default: + MSG_ERR("Unknown ASF networking type\n"); + tcp.close(); + http_free( http_hdr ); + return MPXP_False; } - networking->status = networking_playing_e; + // Check if we got a redirect. + } while(!done); - http_free( http_hdr ); - return 0; + if( asf_http_ctrl->networking_type==ASF_PlainText_e || asf_http_ctrl->networking_type==ASF_Redirector_e ) { + networking->networking_read = nop_networking_read; + networking->networking_seek = nop_networking_seek; + } else { + networking->networking_read = asf_http_networking_read; + networking->networking_seek = asf_http_networking_seek; + networking->buffering = 1; + } + networking->status = networking_playing_e; + + http_free( http_hdr ); + return MPXP_Ok; } Modified: mplayerxp/libmpstream/asf_streaming.h =================================================================== --- mplayerxp/libmpstream/asf_streaming.h 2012-12-07 14:29:41 UTC (rev 516) +++ mplayerxp/libmpstream/asf_streaming.h 2012-12-07 16:03:55 UTC (rev 517) @@ -5,7 +5,7 @@ namespace mpxp { class Tcp; } -extern int asf_networking_start(Tcp& fd, networking_t *networking); -extern int asf_mmst_networking_start(Tcp& fd, networking_t *networking); +extern MPXP_Rc asf_networking_start(Tcp& fd, networking_t *networking); +extern MPXP_Rc asf_mmst_networking_start(Tcp& fd, networking_t *networking); #endif Modified: mplayerxp/libmpstream/network.cpp =================================================================== --- mplayerxp/libmpstream/network.cpp 2012-12-07 14:29:41 UTC (rev 516) +++ mplayerxp/libmpstream/network.cpp 2012-12-07 16:03:55 UTC (rev 517) @@ -362,13 +362,12 @@ // By using the protocol, the extension of the file or the content-type // we might be able to guess the networking type. -int autodetectProtocol(networking_t *networking, Tcp& tcp) { +static MPXP_Rc autodetectProtocol(networking_t *networking, Tcp& tcp) { HTTP_header_t *http_hdr=NULL; unsigned int i; - int fd=-1; int redirect; int auth_retry=0; - int seekable=0; + MPXP_Rc seekable=MPXP_False; char *extension; char *content_type; char *next_url; @@ -394,7 +393,7 @@ MSG_ERR("You must enter a port number for RTP streams!\n"); goto err_out; } - return 0; + return MPXP_Ok; } #endif // HTTP based protocol @@ -411,7 +410,7 @@ if( http_hdr!=NULL && http_hdr->status_code==200 ) { char *accept_ranges; if( (accept_ranges = http_get_field(http_hdr,"Accept-Ranges")) != NULL ) - seekable = strncmp(accept_ranges,"bytes",5)==0; + seekable = strncmp(accept_ranges,"bytes",5)==0?MPXP_Ok:MPXP_False; } // Check if the response is an ICY status_code reason_phrase if( !strcasecmp(http_hdr->protocol, "ICY") ) { @@ -431,7 +430,7 @@ MSG_INFO("Public : %s\n", atoi(field_data)?"yes":"no"); field_data = NULL; if( (field_data = http_get_field(http_hdr, "icy-br")) != NULL ) MSG_INFO("Bitrate: %skbit/s\n", field_data); field_data = NULL; - return 0; + return MPXP_Ok; } case 400: // Server Full MSG_ERR("Error: ICY-Server is full, skipping!\n"); @@ -457,7 +456,7 @@ // Look if we can use the Content-Type content_type = http_get_field( http_hdr, "Content-Type" ); if( content_type!=NULL ) { - char *content_length = NULL; + const char *content_length = NULL; MSG_V("Content-Type: [%s]\n", content_type ); if( (content_length = http_get_field(http_hdr, "Content-Length")) != NULL) MSG_V("Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length")); @@ -470,7 +469,7 @@ } // Not found in the mime type table, don't fail, // we should try raw HTTP - return 0; + return MPXP_Ok; // Redirect case 301: // Permanently case 302: // Temporarily @@ -500,18 +499,16 @@ } } while( redirect ); err_out: - if (fd > 0) closesocket( fd ); - fd = -1; http_free( http_hdr ); http_hdr = NULL; - return -1; + return MPXP_False; } int networking_bufferize( networking_t *networking,unsigned char *buffer, int size) { //printf("networking_bufferize\n"); - networking->buffer = (char*)mp_malloc(size); + networking->buffer = new char [size]; if( networking->buffer==NULL ) { MSG_FATAL(MSGTR_OutOfMemory); return -1; @@ -561,18 +558,17 @@ return -1; } -int -nop_networking_start(Tcp& tcp,networking_t* networking ) { +MPXP_Rc nop_networking_start(Tcp& tcp,networking_t* networking ) { HTTP_header_t *http_hdr = NULL; char *next_url=NULL; URL_t *rd_url=NULL; - int ret; + MPXP_Rc ret; if( !tcp.established() ) { tcp = *http_send_request(networking->libinput, networking->url,0); - if( !tcp.established() ) return -1; + if( !tcp.established() ) return MPXP_False; http_hdr = http_read_response(tcp); - if( http_hdr==NULL ) return -1; + if( http_hdr==NULL ) return MPXP_False; switch( http_hdr->status_code ) { case 200: // OK @@ -581,14 +577,14 @@ if( http_hdr->body_size>0 ) { if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { http_free( http_hdr ); - return -1; + return MPXP_False; } } break; // Redirect case 301: // Permanently case 302: // Temporarily - ret=-1; + ret=MPXP_False; next_url = http_get_field( http_hdr, "Location" ); if (next_url != NULL) @@ -611,7 +607,7 @@ default: MSG_ERR("Server return %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase ); tcp.close(); - return -1; + return MPXP_False; break; } } else { @@ -620,7 +616,7 @@ if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { http_free( http_hdr ); networking->data = NULL; - return -1; + return MPXP_False; } } } @@ -635,7 +631,7 @@ networking->prebuffer_size = 64*1024; // KBytes networking->buffering = 1; networking->status = networking_playing_e; - return 0; + return MPXP_Ok; } void fixup_network_stream_cache(networking_t *networking) { @@ -656,16 +652,15 @@ return pnm_read(reinterpret_cast<pnm_t*>(stream_ctrl->data), buffer, size); } - -int pnm_networking_start(Tcp& tcp,networking_t *networking ) { +MPXP_Rc pnm_networking_start(Tcp& tcp,networking_t *networking ) { pnm_t *pnm; tcp.open(networking->libinput, networking->url->hostname, networking->url->port ? networking->url->port : 7070); - if(!tcp.established()) return -1; + if(!tcp.established()) return MPXP_False; pnm = pnm_connect(tcp,networking->url->file); - if(!pnm) return -2; + if(!pnm) return MPXP_NA; networking->data=pnm; @@ -673,7 +668,7 @@ networking->prebuffer_size = 8*1024; // 8 KBytes networking->buffering = 1; networking->status = networking_playing_e; - return 0; + return MPXP_Ok; } #ifdef HAVE_RTSP_SESSION_H @@ -682,15 +677,13 @@ return rtsp_session_read(stream_ctrl->data, buffer, size); } - -int -realrtsp_networking_start( net_fd_t* fd, networking_t *stream ) { +MPXP_Rc realrtsp_networking_start( net_fd_t* fd, networking_t *stream ) { rtsp_session_t *rtsp; char *mrl; char *file; int port; int redirected, temp; - if( stream==NULL ) return -1; + if( stream==NULL ) return MPXP_False; temp = 5; // counter so we don't get caught in infinite redirections (you never know) @@ -700,7 +693,7 @@ *fd = tcp_connect2Server( networking->url->hostname, port, 1); if(*fd<0 && !networking->url->port) *fd = tcp_connect2Server( networking->url->hostname,port = 7070, 1 ); - if(*fd<0) return -1; + if(*fd<0) return MPXP_False; file = networking->url->file; if (file[0] == '/') file++; @@ -719,7 +712,7 @@ } while( (redirected != 0) && (temp > 0) ); - if(!rtsp) return -1; + if(!rtsp) return MPXP_False; networking->data=rtsp; @@ -727,7 +720,7 @@ networking->prebuffer_size = 128*1024; // 8 KBytes networking->buffering = 1; networking->status = networking_playing_e; - return 0; + return MPXP_Ok; } #endif // HAVE_RTSP_SESSION_H @@ -740,13 +733,12 @@ return read_rtp_from_server(tcp, buffer, size ); } -static int -rtp_networking_start(Tcp& tcp,networking_t* networking, int raw_udp ) { +static MPXP_Rc rtp_networking_start(Tcp& tcp,networking_t* networking, int raw_udp ) { if( !tcp.established() ) { Udp* udp(new(zeromem) Udp(networking->url)); tcp = udp->socket(); - if( !tcp.established()) return -1; + if( !tcp.established()) return MPXP_False; } if(raw_udp) @@ -758,19 +750,19 @@ networking->prebuffer_size = 64*1024; // KBytes networking->buffering = 0; networking->status = networking_playing_e; - return 0; + return MPXP_Ok; } #endif -int networking_start(Tcp& tcp,networking_t* networking, URL_t *url) { - int ret; +MPXP_Rc networking_start(Tcp& tcp,networking_t* networking, URL_t *url) { + MPXP_Rc rc; networking->url = check4proxies( url ); - ret = autodetectProtocol( networking, tcp); + rc = autodetectProtocol( networking, tcp); - if( ret<0 ) return -1; - ret = -1; + if( rc!=MPXP_Ok ) return MPXP_False; + rc = MPXP_False; // Get the bandwidth available networking->bandwidth = network_bandwidth; @@ -778,37 +770,36 @@ // For RTP streams, we usually don't know the stream type until we open it. if( !strcasecmp( networking->url->protocol, "rtp")) { if(tcp.established()) tcp.close(); - ret = rtp_networking_start(tcp, networking, 0); + rc = rtp_networking_start(tcp, networking, 0); } else if( !strcasecmp( networking->url->protocol, "pnm")) { tcp.close(); - ret = pnm_networking_start(tcp, networking); - if (ret == -1) { + rc = pnm_networking_start(tcp, networking); + if (rc == MPXP_False) { MSG_INFO("Can't connect with pnm, retrying with http.\n"); - return -1; + return MPXP_False; } } #ifdef HAVE_RTSP_SESSION_H else if( !strcasecmp( networking->url->protocol, "rtsp")) { - *fd = -1; - if ((ret = realrtsp_networking_start( tcp, networking )) < 0) { + if ((rc = realrtsp_networking_start( tcp, networking )) < 0) { MSG_INFO("Not a Realmedia rtsp url. Trying standard rtsp protocol.\n"); #ifdef STREAMING_LIVE_DOT_COM - ret = rtsp_networking_start( tcp, networking ); - if( ret<0 ) MSG_ERR("rtsp_networking_start failed\n"); - return ret; + rc = rtsp_networking_start( tcp, networking ); + if(rc==MPXP_FAlse ) MSG_ERR("rtsp_networking_start failed\n"); + return rc; #else MSG_ERR("RTSP support requires the \"LIVE.COM Streaming Media\" libraries!\n"); - return -1; + return MPXP_False; #endif } } #endif else if(!strcasecmp( networking->url->protocol, "udp")) { tcp.close(); - ret = rtp_networking_start(tcp, networking, 1); - if(ret<0) { + rc = rtp_networking_start(tcp, networking, 1); + if(rc==MPXP_False) { MSG_ERR("rtp_networking_start(udp) failed\n"); - return -1; + return MPXP_False; } } else { // Send the appropriate HTTP request @@ -816,25 +807,24 @@ // ASF raw stream is encapsulated. // It can also be a playlist (redirector) // so we need to pass demuxer_type too - ret = asf_networking_start(tcp,networking); - if( ret<0 ) { + rc = asf_networking_start(tcp,networking); + if( rc==MPXP_False ) { //sometimes a file is just on a webserver and it is not streamed. //try loading them default method as last resort for http protocol if ( !strcasecmp(networking->url->protocol, "http") ) { MSG_STATUS("Trying default networking for http protocol\n "); //reset stream tcp.close(); - ret=nop_networking_start(tcp,networking); + rc=nop_networking_start(tcp,networking); } - if (ret<0) { + if (rc==MPXP_False) { MSG_ERR("asf_networking_start failed\n"); MSG_STATUS("Check if this is a playlist which requires -playlist option\nExample: mplayer -playlist <url>\n"); } } } - if( ret<0 ) { - free_networking( networking ); - } else if( networking->buffering ) { + if( rc==MPXP_False ) ; + else if( networking->buffering ) { if(mp_conf.s_cache_size<0) { // cache option not set, will use our computed value. // buffer in KBytes, *5 because the prefill is 20% of the buffer. @@ -843,7 +833,7 @@ } MSG_INFO("Cache size set to %d KBytes\n", mp_conf.s_cache_size); } - return ret; + return rc; } int Modified: mplayerxp/libmpstream/network.h =================================================================== --- mplayerxp/libmpstream/network.h 2012-12-07 14:29:41 UTC (rev 516) +++ mplayerxp/libmpstream/network.h 2012-12-07 16:03:55 UTC (rev 517) @@ -51,7 +51,7 @@ }; extern void fixup_network_stream_cache(networking_t *s); -extern int networking_start(Tcp& fd,networking_t *n, URL_t *url); +extern MPXP_Rc networking_start(Tcp& fd,networking_t *n, URL_t *url); extern int networking_bufferize(networking_t *networking,unsigned char *buffer, int size); extern networking_t *new_networking(libinput_t* libinput); extern void free_networking( networking_t *networking ); Modified: mplayerxp/libmpstream/s_network.cpp =================================================================== --- mplayerxp/libmpstream/s_network.cpp 2012-12-07 14:29:41 UTC (rev 516) +++ mplayerxp/libmpstream/s_network.cpp 2012-12-07 16:03:55 UTC (rev 517) @@ -56,7 +56,7 @@ url = url_new(filename); if(url) { networking=new_networking(libinput); - if(networking_start(tcp,networking,url)<0){ + if(networking_start(tcp,networking,url)!=MPXP_Ok){ MSG_ERR(MSGTR_UnableOpenURL, filename); url_free(url); url=NULL; Modified: mplayerxp/libmpstream/s_rtsp.cpp =================================================================== --- mplayerxp/libmpstream/s_rtsp.cpp 2012-12-07 14:29:41 UTC (rev 516) +++ mplayerxp/libmpstream/s_rtsp.cpp 2012-12-07 16:03:55 UTC (rev 517) @@ -42,7 +42,7 @@ virtual off_t size() const; virtual off_t sector_size() const; private: - int start (); + MPXP_Rc start (); networking_t* networking; Tcp tcp; @@ -77,9 +77,10 @@ rtsp_session_end (rtsp); url_free(networking->url); free_networking(networking); + networking=NULL; } -int Rtsp_Stream_Interface::start() +MPXP_Rc Rtsp_Stream_Interface::start() { rtsp_session_t *rtsp; char *mrl; @@ -100,7 +101,7 @@ if (!tcp.established() && !networking->url->port) tcp.open(networking->libinput,networking->url->hostname, port = 7070); - if (!tcp.established()) return -1; + if (!tcp.established()) return MPXP_False; file = networking->url->file; if (file[0] == '/') file++; @@ -123,7 +124,7 @@ temp--; } while ((redirected != 0) && (temp > 0)); - if (!rtsp) return -1; + if (!rtsp) return MPXP_False; networking->data = rtsp; @@ -131,7 +132,7 @@ networking->buffering = 1; networking->status = networking_playing_e; - return 0; + return MPXP_Ok; } extern int network_bandwidth; @@ -152,7 +153,7 @@ tcp.close(); index_mode = -1; /* prevent most RTSP streams from locking due to -idx */ - if (start() < 0) { + if (start() != MPXP_Ok) { free_networking(networking); networking = NULL; return MPXP_False; Modified: mplayerxp/libmpstream/s_udp.cpp =================================================================== --- mplayerxp/libmpstream/s_udp.cpp 2012-12-07 14:29:41 UTC (rev 516) +++ mplayerxp/libmpstream/s_udp.cpp 2012-12-07 16:03:55 UTC (rev 517) @@ -41,7 +41,7 @@ virtual off_t size() const; virtual off_t sector_size() const; private: - int start (); + MPXP_Rc start (); networking_t* networking; Udp udp; @@ -70,13 +70,14 @@ { url_free(networking->url); free_networking(networking); + networking=NULL; } -int Udp_Stream_Interface::start () +MPXP_Rc Udp_Stream_Interface::start () { if (!udp.established()) { udp.open(networking->url); - if (!udp.established()) return -1; + if (!udp.established()) return MPXP_False; } tcp=udp.socket(); networking->networking_read = nop_networking_read; @@ -84,7 +85,7 @@ networking->prebuffer_size = 64 * 1024; /* 64 KBytes */ networking->buffering = 0; networking->status = networking_playing_e; - return 0; + return MPXP_Ok; } extern int network_bandwidth; @@ -105,7 +106,7 @@ networking = NULL; return MPXP_False; } - if (start () < 0) { + if (start () !=MPXP_Ok) { MSG_ERR("udp_networking_start failed\n"); free_networking (networking); networking = NULL; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |