Mercurial > mplayer.hg
comparison libmpdemux/realrtsp/rtsp.c @ 15585:281d155fb37f
ported all network streams to the new API
author | nicodvb |
---|---|
date | Sun, 29 May 2005 12:54:00 +0000 |
parents | 56541efe420b |
children | 941b1a71351f |
comparison
equal
deleted
inserted
replaced
15584:b5f111039c16 | 15585:281d155fb37f |
---|---|
47 #include <sys/time.h> | 47 #include <sys/time.h> |
48 #include <sys/types.h> | 48 #include <sys/types.h> |
49 #include <inttypes.h> | 49 #include <inttypes.h> |
50 | 50 |
51 #include "rtsp.h" | 51 #include "rtsp.h" |
52 #include "../stream.h" | |
53 #include "../demuxer.h" | |
54 #include "rtsp_session.h" | |
52 | 55 |
53 /* | 56 /* |
54 #define LOG | 57 #define LOG |
55 */ | 58 */ |
56 | 59 |
57 #define BUF_SIZE 4096 | 60 #define BUF_SIZE 4096 |
58 #define HEADER_SIZE 1024 | 61 #define HEADER_SIZE 1024 |
59 #define MAX_FIELDS 256 | 62 #define MAX_FIELDS 256 |
60 | 63 |
64 extern int network_bandwidth; | |
61 struct rtsp_s { | 65 struct rtsp_s { |
62 | 66 |
63 int s; | 67 int s; |
64 | 68 |
65 char *host; | 69 char *host; |
837 free(*answer); | 841 free(*answer); |
838 *answer=NULL; | 842 *answer=NULL; |
839 answer++; | 843 answer++; |
840 } | 844 } |
841 } | 845 } |
846 | |
847 static int realrtsp_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) { | |
848 return rtsp_session_read(stream_ctrl->data, buffer, size); | |
849 } | |
850 | |
851 | |
852 static int realrtsp_streaming_start( stream_t *stream ) { | |
853 int fd; | |
854 rtsp_session_t *rtsp; | |
855 char *mrl; | |
856 char *file; | |
857 int port; | |
858 int redirected, temp; | |
859 if( stream==NULL ) return -1; | |
860 | |
861 temp = 5; // counter so we don't get caught in infinite redirections (you never know) | |
862 | |
863 do { | |
864 redirected = 0; | |
865 | |
866 fd = connect2Server( stream->streaming_ctrl->url->hostname, | |
867 port = (stream->streaming_ctrl->url->port ? stream->streaming_ctrl->url->port : 554),1 ); | |
868 if(fd<0 && !stream->streaming_ctrl->url->port) | |
869 fd = connect2Server(stream->streaming_ctrl->url->hostname, port = 7070, 1); | |
870 if(fd<0) return -1; | |
871 | |
872 file = stream->streaming_ctrl->url->file; | |
873 if (file[0] == '/') | |
874 file++; | |
875 mrl = malloc(sizeof(char)*(strlen(stream->streaming_ctrl->url->hostname)+strlen(file)+16)); | |
876 sprintf(mrl,"rtsp://%s:%i/%s",stream->streaming_ctrl->url->hostname,port,file); | |
877 rtsp = rtsp_session_start(fd,&mrl, file, stream->streaming_ctrl->url->hostname, port, &redirected); | |
878 | |
879 if( redirected == 1) { | |
880 url_free(stream->streaming_ctrl->url); | |
881 stream->streaming_ctrl->url = url_new(mrl); | |
882 closesocket(fd); | |
883 } | |
884 | |
885 free(mrl); | |
886 temp--; | |
887 } while( (redirected != 0) && (temp > 0) ); | |
888 | |
889 if(!rtsp) return -1; | |
890 | |
891 stream->fd=fd; | |
892 stream->streaming_ctrl->data=rtsp; | |
893 | |
894 stream->streaming_ctrl->streaming_read = realrtsp_streaming_read; | |
895 //stream->streaming_ctrl->streaming_seek = nop_streaming_seek; | |
896 stream->streaming_ctrl->prebuffer_size = 128*1024; // 8 KBytes | |
897 stream->streaming_ctrl->buffering = 1; | |
898 stream->streaming_ctrl->status = streaming_playing_e; | |
899 return 0; | |
900 } | |
901 | |
902 | |
903 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { | |
904 URL_t *url; | |
905 | |
906 mp_msg(MSGT_OPEN, MSGL_INFO, "STREAM_RTSP, URL: %s\n", stream->url); | |
907 stream->streaming_ctrl = streaming_ctrl_new(); | |
908 if( stream->streaming_ctrl==NULL ) | |
909 return STREAM_ERROR; | |
910 | |
911 stream->streaming_ctrl->bandwidth = network_bandwidth; | |
912 url = url_new(stream->url); | |
913 stream->streaming_ctrl->url = check4proxies(url); | |
914 //url_free(url); | |
915 | |
916 stream->fd = -1; | |
917 if(realrtsp_streaming_start( stream ) < 0) { | |
918 streaming_ctrl_free(stream->streaming_ctrl); | |
919 stream->streaming_ctrl = NULL; | |
920 return STREAM_UNSUPORTED; | |
921 } | |
922 | |
923 fixup_network_stream_cache(stream); | |
924 stream->type = STREAMTYPE_STREAM; | |
925 return STREAM_OK; | |
926 } | |
927 | |
928 | |
929 stream_info_t stream_info_rtsp = { | |
930 "RealNetworks rtsp streaming", | |
931 "realrtsp", | |
932 "Roberto Togni, xine team", | |
933 "ported from xine", | |
934 open_s, | |
935 {"rtsp", NULL}, | |
936 NULL, | |
937 0 // Urls are an option string | |
938 }; |