Merge svn changes up to r30475
[mplayer/glamo.git] / stream / stream_live555.c
blobacf616acd4b41162423c8eccfc74ecb31df85bf8
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "config.h"
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
26 #include "stream.h"
27 #include "network.h"
28 #include "libmpdemux/demuxer.h"
29 #include "help_mp.h"
31 extern int network_bandwidth;
33 static int _rtsp_streaming_seek(int fd, off_t pos, streaming_ctrl_t* streaming_ctrl) {
34 return -1; // For now, we don't handle RTSP stream seeking
37 static int rtsp_streaming_start(stream_t* stream) {
38 stream->streaming_ctrl->streaming_seek = _rtsp_streaming_seek;
39 return 0;
43 static int open_live_rtsp_sip(stream_t *stream,int mode, void* opts, int* file_format) {
44 URL_t *url;
46 stream->streaming_ctrl = streaming_ctrl_new();
47 if( stream->streaming_ctrl==NULL ) {
48 return STREAM_ERROR;
50 stream->streaming_ctrl->bandwidth = network_bandwidth;
51 url = url_new(stream->url);
52 stream->streaming_ctrl->url = check4proxies(url);
53 //url_free(url);
55 mp_msg(MSGT_OPEN, MSGL_INFO, "STREAM_LIVE555, URL: %s\n", stream->url);
57 if(rtsp_streaming_start(stream) < 0) {
58 mp_msg(MSGT_NETWORK,MSGL_ERR,"rtsp_streaming_start failed\n");
59 goto fail;
62 *file_format = DEMUXER_TYPE_RTP;
63 stream->type = STREAMTYPE_STREAM;
64 stream->flags = STREAM_NON_CACHEABLE;
65 return STREAM_OK;
67 fail:
68 streaming_ctrl_free( stream->streaming_ctrl );
69 stream->streaming_ctrl = NULL;
70 return STREAM_ERROR;
73 static int open_live_sdp(stream_t *stream,int mode, void* opts, int* file_format) {
74 int f;
75 char *filename = stream->url;
76 off_t len;
77 char* sdpDescription;
78 ssize_t numBytesRead;
80 if(strncmp("sdp://",filename,6) == 0) {
81 filename += 6;
82 #if defined(__CYGWIN__) || defined(__MINGW32__)
83 f = open(filename,O_RDONLY|O_BINARY);
84 #else
85 f = open(filename,O_RDONLY);
86 #endif
87 if(f < 0) {
88 mp_tmsg(MSGT_OPEN,MSGL_ERR,"File not found: '%s'\n",filename);
89 return STREAM_ERROR;
92 len=lseek(f,0,SEEK_END);
93 lseek(f,0,SEEK_SET);
94 if(len == -1)
95 return STREAM_ERROR;
96 if(len > SIZE_MAX - 1)
97 return STREAM_ERROR;
99 sdpDescription = malloc(len+1);
100 if(sdpDescription == NULL) return STREAM_ERROR;
101 numBytesRead = read(f, sdpDescription, len);
102 if(numBytesRead != len) {
103 free(sdpDescription);
104 return STREAM_ERROR;
106 sdpDescription[len] = '\0'; // to be safe
107 stream->priv = sdpDescription;
109 stream->type = STREAMTYPE_SDP;
110 *file_format = DEMUXER_TYPE_RTP;
111 return STREAM_OK;
113 return STREAM_UNSUPPORTED;
117 const stream_info_t stream_info_rtsp_sip = {
118 "standard RTSP and SIP",
119 "RTSP and SIP",
120 "Ross Finlayson",
121 "Uses LIVE555 Streaming Media library.",
122 open_live_rtsp_sip,
123 {"rtsp", "sip", NULL },
124 NULL,
125 0 // Urls are an option string
128 const stream_info_t stream_info_sdp = {
129 "SDP stream descriptor",
130 "SDP",
131 "Ross Finlayson",
132 "Uses LIVE555 Streaming Media library.",
133 open_live_sdp,
134 {"sdp", NULL },
135 NULL,
136 0 // Urls are an option string