Merge branch 'matroska'
[mplayer/kovensky.git] / stream / stream_live555.c
blobc3b61de5d41d976118dd137b76b3b756bac06e87
2 #include "config.h"
4 #include <unistd.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
9 #include "stream.h"
10 #include "network.h"
11 #include "libmpdemux/demuxer.h"
12 #include "help_mp.h"
14 extern int network_bandwidth;
16 static int _rtsp_streaming_seek(int fd, off_t pos, streaming_ctrl_t* streaming_ctrl) {
17 return -1; // For now, we don't handle RTSP stream seeking
20 static int rtsp_streaming_start(stream_t* stream) {
21 stream->streaming_ctrl->streaming_seek = _rtsp_streaming_seek;
22 return 0;
26 static int open_live_rtsp_sip(stream_t *stream,int mode, void* opts, int* file_format) {
27 URL_t *url;
29 stream->streaming_ctrl = streaming_ctrl_new();
30 if( stream->streaming_ctrl==NULL ) {
31 return STREAM_ERROR;
33 stream->streaming_ctrl->bandwidth = network_bandwidth;
34 url = url_new(stream->url);
35 stream->streaming_ctrl->url = check4proxies(url);
36 //url_free(url);
38 mp_msg(MSGT_OPEN, MSGL_INFO, "STREAM_LIVE555, URL: %s\n", stream->url);
40 if(rtsp_streaming_start(stream) < 0) {
41 mp_msg(MSGT_NETWORK,MSGL_ERR,"rtsp_streaming_start failed\n");
42 goto fail;
45 *file_format = DEMUXER_TYPE_RTP;
46 stream->type = STREAMTYPE_STREAM;
47 stream->flags = STREAM_NON_CACHEABLE;
48 return STREAM_OK;
50 fail:
51 streaming_ctrl_free( stream->streaming_ctrl );
52 stream->streaming_ctrl = NULL;
53 return STREAM_ERROR;
56 static int open_live_sdp(stream_t *stream,int mode, void* opts, int* file_format) {
57 int f;
58 char *filename = stream->url;
59 off_t len;
60 char* sdpDescription;
61 ssize_t numBytesRead;
63 if(strncmp("sdp://",filename,6) == 0) {
64 filename += 6;
65 #if defined(__CYGWIN__) || defined(__MINGW32__)
66 f = open(filename,O_RDONLY|O_BINARY);
67 #else
68 f = open(filename,O_RDONLY);
69 #endif
70 if(f < 0) {
71 mp_tmsg(MSGT_OPEN,MSGL_ERR,"File not found: '%s'\n",filename);
72 return STREAM_ERROR;
75 len=lseek(f,0,SEEK_END);
76 lseek(f,0,SEEK_SET);
77 if(len == -1)
78 return STREAM_ERROR;
79 if(len > SIZE_MAX - 1)
80 return STREAM_ERROR;
82 sdpDescription = malloc(len+1);
83 if(sdpDescription == NULL) return STREAM_ERROR;
84 numBytesRead = read(f, sdpDescription, len);
85 if(numBytesRead != len) {
86 free(sdpDescription);
87 return STREAM_ERROR;
89 sdpDescription[len] = '\0'; // to be safe
90 stream->priv = sdpDescription;
92 stream->type = STREAMTYPE_SDP;
93 *file_format = DEMUXER_TYPE_RTP;
94 return STREAM_OK;
96 return STREAM_UNSUPPORTED;
100 const stream_info_t stream_info_rtsp_sip = {
101 "standard RTSP and SIP",
102 "RTSP and SIP",
103 "Ross Finlayson",
104 "Uses LIVE555 Streaming Media library.",
105 open_live_rtsp_sip,
106 {"rtsp", "sip", NULL },
107 NULL,
108 0 // Urls are an option string
111 const stream_info_t stream_info_sdp = {
112 "SDP stream descriptor",
113 "SDP",
114 "Ross Finlayson",
115 "Uses LIVE555 Streaming Media library.",
116 open_live_sdp,
117 {"sdp", NULL },
118 NULL,
119 0 // Urls are an option string