2001-02-24 20:28:24 +00:00
|
|
|
|
2001-08-01 09:14:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-07-31 23:18:16 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2003-04-02 16:52:00 +00:00
|
|
|
#ifndef __MINGW32__
|
2001-04-22 16:56:20 +00:00
|
|
|
#include <sys/ioctl.h>
|
2002-07-26 04:04:51 +00:00
|
|
|
#include <sys/wait.h>
|
2003-04-02 16:52:00 +00:00
|
|
|
#endif
|
2001-07-31 23:18:16 +00:00
|
|
|
#include <fcntl.h>
|
2001-10-20 23:51:02 +00:00
|
|
|
#include <signal.h>
|
2003-04-02 16:25:07 +00:00
|
|
|
#include <strings.h>
|
2001-04-22 16:56:20 +00:00
|
|
|
|
2001-08-01 09:14:02 +00:00
|
|
|
#include "config.h"
|
2003-06-11 16:48:09 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_WINSOCK2
|
|
|
|
#define closesocket close
|
|
|
|
#else
|
|
|
|
#include <winsock2.h>
|
|
|
|
#endif
|
|
|
|
|
2001-09-26 21:35:14 +00:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "osdep/shmem.h"
|
2001-07-31 23:18:16 +00:00
|
|
|
|
2001-04-22 16:56:20 +00:00
|
|
|
#include "stream.h"
|
2006-08-04 17:01:29 +00:00
|
|
|
#include "libmpdemux/demuxer.h"
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "m_option.h"
|
|
|
|
#include "m_struct.h"
|
2003-04-02 16:25:07 +00:00
|
|
|
|
2006-09-12 16:24:23 +00:00
|
|
|
#include "cache2.h"
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2003-01-05 23:51:05 +00:00
|
|
|
//#include "vcd_read_bincue.h"
|
2003-01-04 20:11:06 +00:00
|
|
|
|
2003-04-09 07:31:11 +00:00
|
|
|
#ifdef HAVE_VCD
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_vcd;
|
2003-04-09 07:31:11 +00:00
|
|
|
#endif
|
2003-04-03 12:00:50 +00:00
|
|
|
#ifdef HAVE_CDDA
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_cdda;
|
2003-04-03 12:00:50 +00:00
|
|
|
#endif
|
2003-05-17 12:24:01 +00:00
|
|
|
#ifdef MPLAYER_NETWORK
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_netstream;
|
|
|
|
extern const stream_info_t stream_info_pnm;
|
|
|
|
extern const stream_info_t stream_info_asf;
|
|
|
|
extern const stream_info_t stream_info_rtsp;
|
|
|
|
extern const stream_info_t stream_info_rtp;
|
|
|
|
extern const stream_info_t stream_info_udp;
|
|
|
|
extern const stream_info_t stream_info_http1;
|
|
|
|
extern const stream_info_t stream_info_http2;
|
2003-04-06 16:36:17 +00:00
|
|
|
#endif
|
2003-08-11 00:02:46 +00:00
|
|
|
#ifdef HAS_DVBIN_SUPPORT
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_dvb;
|
2003-08-11 00:02:46 +00:00
|
|
|
#endif
|
2006-07-31 18:36:29 +00:00
|
|
|
#ifdef USE_TV
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_tv;
|
2006-07-31 18:36:29 +00:00
|
|
|
#endif
|
2006-08-28 17:05:18 +00:00
|
|
|
#ifdef USE_RADIO
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_radio;
|
2006-08-28 17:05:18 +00:00
|
|
|
#endif
|
2006-07-10 21:32:19 +00:00
|
|
|
#ifdef HAVE_PVR
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_pvr;
|
2006-07-10 21:32:19 +00:00
|
|
|
#endif
|
2003-08-15 19:13:23 +00:00
|
|
|
#ifdef HAVE_FTP
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_ftp;
|
2003-08-15 19:13:23 +00:00
|
|
|
#endif
|
2005-02-27 04:25:12 +00:00
|
|
|
#ifdef HAVE_VSTREAM
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_vstream;
|
2005-02-27 04:25:12 +00:00
|
|
|
#endif
|
2005-05-19 19:50:39 +00:00
|
|
|
#ifdef USE_DVDNAV
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_dvdnav;
|
2005-05-19 19:50:39 +00:00
|
|
|
#endif
|
2005-05-19 20:58:11 +00:00
|
|
|
#ifdef LIBSMBCLIENT
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_smb;
|
2005-05-19 20:58:11 +00:00
|
|
|
#endif
|
2005-09-23 22:35:04 +00:00
|
|
|
#ifdef STREAMING_LIVE555
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_sdp;
|
|
|
|
extern const stream_info_t stream_info_rtsp_sip;
|
2005-10-14 12:41:15 +00:00
|
|
|
#endif
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_cue;
|
|
|
|
extern const stream_info_t stream_info_null;
|
|
|
|
extern const stream_info_t stream_info_mf;
|
|
|
|
extern const stream_info_t stream_info_file;
|
2006-11-03 22:03:58 +00:00
|
|
|
#ifdef USE_DVDREAD
|
2007-12-02 13:22:53 +00:00
|
|
|
extern const stream_info_t stream_info_ifo;
|
|
|
|
extern const stream_info_t stream_info_dvd;
|
2005-12-14 21:52:41 +00:00
|
|
|
#endif
|
2003-04-02 16:25:07 +00:00
|
|
|
|
2007-12-02 13:07:35 +00:00
|
|
|
static const stream_info_t* const auto_open_streams[] = {
|
2003-04-09 07:31:11 +00:00
|
|
|
#ifdef HAVE_VCD
|
|
|
|
&stream_info_vcd,
|
|
|
|
#endif
|
2003-04-03 12:00:50 +00:00
|
|
|
#ifdef HAVE_CDDA
|
2003-04-02 19:29:26 +00:00
|
|
|
&stream_info_cdda,
|
2003-04-06 16:36:17 +00:00
|
|
|
#endif
|
2003-05-17 12:24:01 +00:00
|
|
|
#ifdef MPLAYER_NETWORK
|
2003-04-06 16:36:17 +00:00
|
|
|
&stream_info_netstream,
|
2005-05-29 12:54:00 +00:00
|
|
|
&stream_info_http1,
|
|
|
|
&stream_info_asf,
|
|
|
|
&stream_info_pnm,
|
|
|
|
&stream_info_rtsp,
|
2005-09-23 22:35:04 +00:00
|
|
|
#ifdef STREAMING_LIVE555
|
2005-05-29 12:54:00 +00:00
|
|
|
&stream_info_sdp,
|
|
|
|
&stream_info_rtsp_sip,
|
|
|
|
#endif
|
2006-08-04 18:32:36 +00:00
|
|
|
&stream_info_rtp,
|
|
|
|
&stream_info_udp,
|
2005-05-29 12:54:00 +00:00
|
|
|
&stream_info_http2,
|
2003-04-03 12:00:50 +00:00
|
|
|
#endif
|
2003-08-11 00:02:46 +00:00
|
|
|
#ifdef HAS_DVBIN_SUPPORT
|
|
|
|
&stream_info_dvb,
|
|
|
|
#endif
|
2006-07-31 18:36:29 +00:00
|
|
|
#ifdef USE_TV
|
|
|
|
&stream_info_tv,
|
|
|
|
#endif
|
2006-08-28 17:05:18 +00:00
|
|
|
#ifdef USE_RADIO
|
|
|
|
&stream_info_radio,
|
|
|
|
#endif
|
2006-07-10 21:32:19 +00:00
|
|
|
#ifdef HAVE_PVR
|
|
|
|
&stream_info_pvr,
|
|
|
|
#endif
|
2003-08-15 19:13:23 +00:00
|
|
|
#ifdef HAVE_FTP
|
|
|
|
&stream_info_ftp,
|
2005-02-27 04:25:12 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_VSTREAM
|
|
|
|
&stream_info_vstream,
|
2005-05-19 20:58:11 +00:00
|
|
|
#endif
|
|
|
|
#ifdef LIBSMBCLIENT
|
|
|
|
&stream_info_smb,
|
2003-08-15 19:13:23 +00:00
|
|
|
#endif
|
2005-05-15 07:38:42 +00:00
|
|
|
&stream_info_cue,
|
2006-11-03 22:03:58 +00:00
|
|
|
#ifdef USE_DVDREAD
|
2007-12-02 13:13:02 +00:00
|
|
|
&stream_info_ifo,
|
2005-05-19 19:50:39 +00:00
|
|
|
&stream_info_dvd,
|
2005-12-14 21:52:41 +00:00
|
|
|
#endif
|
2005-05-19 19:50:39 +00:00
|
|
|
#ifdef USE_DVDNAV
|
2006-06-14 21:58:17 +00:00
|
|
|
&stream_info_dvdnav,
|
2005-05-19 19:50:39 +00:00
|
|
|
#endif
|
|
|
|
|
2003-04-10 10:59:12 +00:00
|
|
|
&stream_info_null,
|
2006-08-03 19:43:02 +00:00
|
|
|
&stream_info_mf,
|
2003-04-02 16:25:07 +00:00
|
|
|
&stream_info_file,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2007-12-01 16:31:49 +00:00
|
|
|
stream_t* open_stream_plugin(const stream_info_t* sinfo,char* filename,int mode,
|
2007-11-26 00:41:21 +00:00
|
|
|
char** options, int* file_format, int* ret,
|
|
|
|
char** redirected_url) {
|
2003-04-02 16:25:07 +00:00
|
|
|
void* arg = NULL;
|
|
|
|
stream_t* s;
|
|
|
|
m_struct_t* desc = (m_struct_t*)sinfo->opts;
|
|
|
|
|
|
|
|
// Parse options
|
|
|
|
if(desc) {
|
|
|
|
arg = m_struct_alloc(desc);
|
|
|
|
if(sinfo->opts_url) {
|
|
|
|
m_option_t url_opt =
|
|
|
|
{ "stream url", arg , CONF_TYPE_CUSTOM_URL, 0, 0 ,0, sinfo->opts };
|
|
|
|
if(m_option_parse(&url_opt,"stream url",filename,arg,M_CONFIG_FILE) < 0) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR, "URL parsing failed on url %s\n",filename);
|
|
|
|
m_struct_free(desc,arg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(options) {
|
|
|
|
int i;
|
|
|
|
for(i = 0 ; options[i] != NULL ; i += 2) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_DBG2, "Set stream arg %s=%s\n",
|
|
|
|
options[i],options[i+1]);
|
|
|
|
if(!m_struct_set(desc,arg,options[i],options[i+1]))
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_WARN, "Failed to set stream option %s=%s\n",
|
|
|
|
options[i],options[i+1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = new_stream(-2,-2);
|
|
|
|
s->url=strdup(filename);
|
|
|
|
s->flags |= mode;
|
|
|
|
*ret = sinfo->open(s,mode,arg,file_format);
|
|
|
|
if((*ret) != STREAM_OK) {
|
2007-11-26 00:41:21 +00:00
|
|
|
#ifdef MPLAYER_NETWORK
|
|
|
|
if (*ret == STREAM_REDIRECTED && redirected_url) {
|
|
|
|
if (s->streaming_ctrl && s->streaming_ctrl->url
|
|
|
|
&& s->streaming_ctrl->url->url)
|
|
|
|
*redirected_url = strdup(s->streaming_ctrl->url->url);
|
|
|
|
else
|
|
|
|
*redirected_url = NULL;
|
|
|
|
}
|
|
|
|
streaming_ctrl_free(s->streaming_ctrl);
|
|
|
|
#endif
|
2003-04-02 16:25:07 +00:00
|
|
|
free(s->url);
|
|
|
|
free(s);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(s->type <= -2)
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_WARN, "Warning streams need a type !!!!\n");
|
|
|
|
if(s->flags & STREAM_SEEK && !s->seek)
|
|
|
|
s->flags &= ~STREAM_SEEK;
|
|
|
|
if(s->seek && !(s->flags & STREAM_SEEK))
|
2003-04-06 16:36:17 +00:00
|
|
|
s->flags |= STREAM_SEEK;
|
2003-04-02 16:25:07 +00:00
|
|
|
|
2006-12-18 20:56:24 +00:00
|
|
|
s->mode = mode;
|
2003-04-02 16:25:07 +00:00
|
|
|
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_V, "STREAM: [%s] %s\n",sinfo->name,filename);
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_V, "STREAM: Description: %s\n",sinfo->info);
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_V, "STREAM: Author: %s\n", sinfo->author);
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_V, "STREAM: Comment: %s\n", sinfo->comment);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stream_t* open_stream_full(char* filename,int mode, char** options, int* file_format) {
|
|
|
|
int i,j,l,r;
|
2007-12-01 16:31:49 +00:00
|
|
|
const stream_info_t* sinfo;
|
2003-04-02 16:25:07 +00:00
|
|
|
stream_t* s;
|
2007-11-26 00:41:21 +00:00
|
|
|
char *redirected_url = NULL;
|
2003-04-02 16:25:07 +00:00
|
|
|
|
|
|
|
for(i = 0 ; auto_open_streams[i] ; i++) {
|
|
|
|
sinfo = auto_open_streams[i];
|
|
|
|
if(!sinfo->protocols) {
|
2003-08-31 18:51:05 +00:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_WARN, "Stream type %s has protocols == NULL, it's a bug\n", sinfo->name);
|
2003-04-02 16:25:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for(j = 0 ; sinfo->protocols[j] ; j++) {
|
|
|
|
l = strlen(sinfo->protocols[j]);
|
|
|
|
// l == 0 => Don't do protocol matching (ie network and filenames)
|
2006-12-05 18:30:48 +00:00
|
|
|
if((l == 0 && !strstr(filename, "://")) ||
|
2007-12-19 01:28:00 +00:00
|
|
|
((strncasecmp(sinfo->protocols[j],filename,l) == 0) &&
|
2003-04-02 16:25:07 +00:00
|
|
|
(strncmp("://",filename+l,3) == 0))) {
|
|
|
|
*file_format = DEMUXER_TYPE_UNKNOWN;
|
2007-11-26 00:41:21 +00:00
|
|
|
s = open_stream_plugin(sinfo,filename,mode,options,file_format,&r,
|
|
|
|
&redirected_url);
|
2003-04-02 16:25:07 +00:00
|
|
|
if(s) return s;
|
2007-11-26 00:41:21 +00:00
|
|
|
if(r == STREAM_REDIRECTED && redirected_url) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_V, "[%s] open %s redirected to %s\n",
|
|
|
|
sinfo->info, filename, redirected_url);
|
|
|
|
s = open_stream_full(redirected_url, mode, options, file_format);
|
|
|
|
free(redirected_url);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
else if(r != STREAM_UNSUPPORTED) {
|
2005-10-18 11:11:25 +00:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR, MSGTR_FailedToOpen,filename);
|
2003-04-02 16:25:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR, "No stream found to handle url %s\n",filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-12-18 20:56:24 +00:00
|
|
|
stream_t* open_output_stream(char* filename,char** options) {
|
|
|
|
int file_format; //unused
|
|
|
|
if(!filename) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,"open_output_stream(), NULL filename, report this bug\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return open_stream_full(filename,STREAM_WRITE,options,&file_format);
|
|
|
|
}
|
|
|
|
|
2001-04-22 16:56:20 +00:00
|
|
|
//=================== STREAMER =========================
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
int stream_fill_buffer(stream_t *s){
|
|
|
|
int len;
|
2003-04-07 20:44:06 +00:00
|
|
|
if (/*s->fd == NULL ||*/ s->eof) { s->buf_pos = s->buf_len = 0; return 0; }
|
2001-02-24 20:28:24 +00:00
|
|
|
switch(s->type){
|
2001-05-03 23:32:56 +00:00
|
|
|
case STREAMTYPE_STREAM:
|
2003-05-17 12:24:01 +00:00
|
|
|
#ifdef MPLAYER_NETWORK
|
2007-11-08 23:07:19 +00:00
|
|
|
if( s->streaming_ctrl!=NULL && s->streaming_ctrl->streaming_read ) {
|
2001-11-20 22:22:21 +00:00
|
|
|
len=s->streaming_ctrl->streaming_read(s->fd,s->buffer,STREAM_BUFFER_SIZE, s->streaming_ctrl);break;
|
|
|
|
} else {
|
|
|
|
len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break;
|
|
|
|
}
|
|
|
|
#else
|
2001-02-24 20:28:24 +00:00
|
|
|
len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break;
|
|
|
|
#endif
|
2002-03-16 14:32:03 +00:00
|
|
|
case STREAMTYPE_DS:
|
|
|
|
len = demux_read_data((demux_stream_t*)s->priv,s->buffer,STREAM_BUFFER_SIZE);
|
|
|
|
break;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
2003-04-02 16:25:07 +00:00
|
|
|
default:
|
|
|
|
len= s->fill_buffer ? s->fill_buffer(s,s->buffer,STREAM_BUFFER_SIZE) : 0;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; }
|
|
|
|
s->buf_pos=0;
|
|
|
|
s->buf_len=len;
|
|
|
|
s->pos+=len;
|
|
|
|
// printf("[%d]",len);fflush(stdout);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2006-12-18 20:56:24 +00:00
|
|
|
int stream_write_buffer(stream_t *s, unsigned char *buf, int len) {
|
|
|
|
int rd;
|
|
|
|
if(!s->write_buffer)
|
|
|
|
return -1;
|
|
|
|
rd = s->write_buffer(s, buf, len);
|
|
|
|
if(rd < 0)
|
|
|
|
return -1;
|
|
|
|
s->pos += rd;
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
|
2001-07-31 23:18:16 +00:00
|
|
|
int stream_seek_long(stream_t *s,off_t pos){
|
2002-07-26 04:04:51 +00:00
|
|
|
off_t newpos=0;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2006-03-24 08:12:03 +00:00
|
|
|
// if( mp_msg_test(MSGT_STREAM,MSGL_DBG3) ) printf("seek_long to 0x%X\n",(unsigned int)pos);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
s->buf_pos=s->buf_len=0;
|
|
|
|
|
2006-12-18 20:56:24 +00:00
|
|
|
if(s->mode == STREAM_WRITE) {
|
|
|
|
if(!s->seek || !s->seek(s,pos))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-02-28 23:40:39 +00:00
|
|
|
if(s->sector_size)
|
|
|
|
newpos = (pos/s->sector_size)*s->sector_size;
|
|
|
|
else
|
|
|
|
newpos = pos&(~((off_t)STREAM_BUFFER_SIZE-1));
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_STREAM,MSGL_DBG3) ){
|
2006-04-22 05:12:10 +00:00
|
|
|
mp_msg(MSGT_STREAM,MSGL_DBG3, "s->pos=%"PRIX64" newpos=%"PRIX64" new_bufpos=%"PRIX64" buflen=%X \n",
|
2005-10-13 18:33:56 +00:00
|
|
|
(int64_t)s->pos,(int64_t)newpos,(int64_t)pos,s->buf_len);
|
2001-10-02 21:45:41 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
pos-=newpos;
|
|
|
|
|
|
|
|
if(newpos==0 || newpos!=s->pos){
|
|
|
|
switch(s->type){
|
2001-05-03 23:32:56 +00:00
|
|
|
case STREAMTYPE_STREAM:
|
|
|
|
//s->pos=newpos; // real seek
|
2001-11-20 22:22:21 +00:00
|
|
|
// Some streaming protocol allow to seek backward and forward
|
|
|
|
// A function call that return -1 can tell that the protocol
|
|
|
|
// doesn't support seeking.
|
2003-05-17 12:24:01 +00:00
|
|
|
#ifdef MPLAYER_NETWORK
|
2004-02-17 12:30:45 +00:00
|
|
|
if(s->seek) { // new stream seek is much cleaner than streaming_ctrl one
|
|
|
|
if(!s->seek(s,newpos)) {
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR, "Seek failed\n");
|
2004-03-13 16:10:02 +00:00
|
|
|
return 0;
|
2004-02-17 12:30:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-01-12 20:16:28 +00:00
|
|
|
if( s->streaming_ctrl!=NULL && s->streaming_ctrl->streaming_seek ) {
|
2001-11-20 22:22:21 +00:00
|
|
|
if( s->streaming_ctrl->streaming_seek( s->fd, pos, s->streaming_ctrl )<0 ) {
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_INFO,"Stream not seekable!\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2001-05-03 23:32:56 +00:00
|
|
|
if(newpos<s->pos){
|
2001-09-26 21:35:14 +00:00
|
|
|
mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n");
|
2001-05-03 23:32:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
while(s->pos<newpos){
|
|
|
|
if(stream_fill_buffer(s)<=0) break; // EOF
|
|
|
|
}
|
2001-11-20 22:22:21 +00:00
|
|
|
#endif
|
2001-05-03 23:32:56 +00:00
|
|
|
break;
|
2002-09-15 20:51:55 +00:00
|
|
|
default:
|
2003-04-02 16:25:07 +00:00
|
|
|
// This should at the beginning as soon as all streams are converted
|
|
|
|
if(!s->seek)
|
|
|
|
return 0;
|
|
|
|
// Now seek
|
|
|
|
if(!s->seek(s,newpos)) {
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR, "Seek failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
// putchar('.');fflush(stdout);
|
|
|
|
//} else {
|
|
|
|
// putchar('%');fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2006-03-16 14:24:22 +00:00
|
|
|
while(stream_fill_buffer(s) > 0 && pos >= 0) {
|
|
|
|
if(pos<=s->buf_len){
|
2001-02-24 20:28:24 +00:00
|
|
|
s->buf_pos=pos; // byte position in sector
|
|
|
|
return 1;
|
|
|
|
}
|
2006-03-16 14:24:22 +00:00
|
|
|
pos -= s->buf_len;
|
|
|
|
}
|
2001-09-26 21:35:14 +00:00
|
|
|
|
2001-09-27 20:36:53 +00:00
|
|
|
// if(pos==s->buf_len) printf("XXX Seek to last byte of file -> EOF\n");
|
|
|
|
|
2005-10-13 18:33:56 +00:00
|
|
|
mp_msg(MSGT_STREAM,MSGL_V,"stream_seek: WARNING! Can't seek to 0x%"PRIX64" !\n",(int64_t)(pos+newpos));
|
2001-02-24 20:28:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void stream_reset(stream_t *s){
|
|
|
|
if(s->eof){
|
|
|
|
s->pos=0; //ftell(f);
|
|
|
|
// s->buf_pos=s->buf_len=0;
|
|
|
|
s->eof=0;
|
|
|
|
}
|
2003-04-06 16:36:17 +00:00
|
|
|
if(s->control) s->control(s,STREAM_CTRL_RESET,NULL);
|
2001-02-24 20:28:24 +00:00
|
|
|
//stream_seek(s,0);
|
|
|
|
}
|
|
|
|
|
2006-03-01 21:56:30 +00:00
|
|
|
int stream_control(stream_t *s, int cmd, void *arg){
|
2007-08-28 22:38:45 +00:00
|
|
|
if(!s->control) return STREAM_UNSUPPORTED;
|
2006-02-27 21:06:47 +00:00
|
|
|
return s->control(s, cmd, arg);
|
|
|
|
}
|
|
|
|
|
2001-10-10 00:47:17 +00:00
|
|
|
stream_t* new_memory_stream(unsigned char* data,int len){
|
2006-06-04 22:41:27 +00:00
|
|
|
stream_t *s;
|
|
|
|
|
|
|
|
if(len < 0)
|
|
|
|
return NULL;
|
|
|
|
s=malloc(sizeof(stream_t)+len);
|
2002-08-04 13:35:25 +00:00
|
|
|
memset(s,0,sizeof(stream_t));
|
2001-10-10 00:47:17 +00:00
|
|
|
s->fd=-1;
|
|
|
|
s->type=STREAMTYPE_MEMORY;
|
|
|
|
s->buf_pos=0; s->buf_len=len;
|
|
|
|
s->start_pos=0; s->end_pos=len;
|
|
|
|
stream_reset(s);
|
|
|
|
s->pos=len;
|
|
|
|
memcpy(s->buffer,data,len);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
stream_t* new_stream(int fd,int type){
|
|
|
|
stream_t *s=malloc(sizeof(stream_t));
|
2001-12-03 17:14:36 +00:00
|
|
|
if(s==NULL) return NULL;
|
|
|
|
memset(s,0,sizeof(stream_t));
|
2003-06-11 16:48:09 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_WINSOCK2
|
|
|
|
{
|
|
|
|
WSADATA wsdata;
|
|
|
|
int temp = WSAStartup(0x0202, &wsdata); // there might be a better place for this (-> later)
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_V,"WINSOCK2 init: %i\n", temp);
|
|
|
|
}
|
|
|
|
#endif
|
2001-12-03 17:14:36 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
s->fd=fd;
|
|
|
|
s->type=type;
|
2001-03-21 03:20:17 +00:00
|
|
|
s->buf_pos=s->buf_len=0;
|
2001-04-23 21:25:09 +00:00
|
|
|
s->start_pos=s->end_pos=0;
|
2001-08-22 23:54:38 +00:00
|
|
|
s->priv=NULL;
|
2002-09-15 19:47:49 +00:00
|
|
|
s->url=NULL;
|
2001-10-20 23:51:02 +00:00
|
|
|
s->cache_pid=0;
|
2001-02-24 20:28:24 +00:00
|
|
|
stream_reset(s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_stream(stream_t *s){
|
2002-05-20 03:25:26 +00:00
|
|
|
// printf("\n*** free_stream() called ***\n");
|
2003-04-02 16:52:00 +00:00
|
|
|
#ifdef USE_STREAM_CACHE
|
2002-02-28 13:50:09 +00:00
|
|
|
if(s->cache_pid) {
|
2003-04-12 13:53:33 +00:00
|
|
|
cache_uninit(s);
|
2002-02-28 13:50:09 +00:00
|
|
|
}
|
2003-04-02 16:52:00 +00:00
|
|
|
#endif
|
2005-05-19 20:58:11 +00:00
|
|
|
if(s->close) s->close(s);
|
2005-05-12 22:07:11 +00:00
|
|
|
if(s->fd>0){
|
|
|
|
/* on unix we define closesocket to close
|
|
|
|
on windows however we have to distinguish between
|
|
|
|
network socket and file */
|
|
|
|
if(s->url && strstr(s->url,"://"))
|
|
|
|
closesocket(s->fd);
|
|
|
|
else close(s->fd);
|
|
|
|
}
|
2003-06-11 16:48:09 +00:00
|
|
|
#ifdef HAVE_WINSOCK2
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_V,"WINSOCK2 uninit\n");
|
|
|
|
WSACleanup(); // there might be a better place for this (-> later)
|
|
|
|
#endif
|
2003-04-02 16:25:07 +00:00
|
|
|
// Disabled atm, i don't like that. s->priv can be anything after all
|
|
|
|
// streams should destroy their priv on close
|
|
|
|
//if(s->priv) free(s->priv);
|
|
|
|
if(s->url) free(s->url);
|
2001-02-24 20:28:24 +00:00
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
|
2002-03-16 14:32:03 +00:00
|
|
|
stream_t* new_ds_stream(demux_stream_t *ds) {
|
|
|
|
stream_t* s = new_stream(-1,STREAMTYPE_DS);
|
|
|
|
s->priv = ds;
|
|
|
|
return s;
|
|
|
|
}
|