summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2010-01-25 15:59:53 +0200
committerUoti Urpala <uau@glyph.nonexistent.invalid>2010-01-25 15:59:53 +0200
commite28e4a1b157bd0e9620fcff956d713a9921f506c (patch)
treed92e54e1e25feb84e692396cf234478f403e5738 /stream
parent560acfd0407c757e17bf72b490687d4947b05675 (diff)
parent213092c8dcfc925d8d54cf320b60cf298a870696 (diff)
downloadmpv-e28e4a1b157bd0e9620fcff956d713a9921f506c.tar.bz2
mpv-e28e4a1b157bd0e9620fcff956d713a9921f506c.tar.xz
Merge svn changes up to r30419
Diffstat (limited to 'stream')
-rw-r--r--stream/cache2.c39
-rw-r--r--stream/http.c11
-rw-r--r--stream/stream.c2
-rw-r--r--stream/stream_ftp.c7
4 files changed, 42 insertions, 17 deletions
diff --git a/stream/cache2.c b/stream/cache2.c
index 4c9bdf8aec..70ba5d1c5a 100644
--- a/stream/cache2.c
+++ b/stream/cache2.c
@@ -15,6 +15,7 @@
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
+#include <errno.h>
#include "osdep/shmem.h"
#include "osdep/timer.h"
@@ -280,22 +281,27 @@ static cache_vars_t* cache_init(int size,int sector){
void cache_uninit(stream_t *s) {
cache_vars_t* c = s->cache_data;
- if(!s->cache_pid) return;
+ if(s->cache_pid) {
#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__)
- cache_do_control(s, -2, NULL);
+ cache_do_control(s, -2, NULL);
#else
- kill(s->cache_pid,SIGKILL);
- waitpid(s->cache_pid,NULL,0);
+ kill(s->cache_pid,SIGKILL);
+ waitpid(s->cache_pid,NULL,0);
#endif
+ s->cache_pid = 0;
+ }
if(!c) return;
#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__)
free(c->stream);
free(c->buffer);
+ c->buffer = NULL;
free(s->cache_data);
#else
shmem_free(c->buffer,c->buffer_size);
+ c->buffer = NULL;
shmem_free(s->cache_data,sizeof(cache_vars_t));
#endif
+ s->cache_data = NULL;
}
static void exit_sighandler(int x){
@@ -303,8 +309,12 @@ static void exit_sighandler(int x){
exit(0);
}
+/**
+ * \return 1 on success, 0 if the function was interrupted and -1 on error
+ */
int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){
int ss = stream->sector_size ? stream->sector_size : STREAM_BUFFER_SIZE;
+ int res = -1;
cache_vars_t* s;
if (stream->flags & STREAM_NON_CACHEABLE) {
@@ -313,7 +323,7 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){
}
s=cache_init(size,ss);
- if(s == NULL) return 0;
+ if(s == NULL) return -1;
stream->cache_data=s;
s->stream=stream; // callback
s->seek_limit=seek_limit;
@@ -330,6 +340,8 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){
#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__)
if((stream->cache_pid=fork())){
+ if ((pid_t)stream->cache_pid == -1)
+ stream->cache_pid = 0;
#else
{
stream_t* stream2=malloc(sizeof(stream_t));
@@ -347,6 +359,11 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){
}
#endif
#endif
+ if (!stream->cache_pid) {
+ mp_msg(MSGT_CACHE, MSGL_ERR,
+ "Starting cache process/thread failed: %s.\n", strerror(errno));
+ goto err_out;
+ }
// wait until cache is filled at least prefill_init %
mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %"PRId64" [%"PRId64"] %"PRId64" pre:%d eof:%d \n",
(int64_t)s->min_filepos,(int64_t)s->read_filepos,(int64_t)s->max_filepos,min,s->eof);
@@ -356,11 +373,17 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){
(int64_t)s->max_filepos-s->read_filepos
);
if(s->eof) break; // file is smaller than prefill size
- if(stream_check_interrupt(PREFILL_SLEEP_TIME))
- return 0;
+ if(stream_check_interrupt(PREFILL_SLEEP_TIME)) {
+ res = 0;
+ goto err_out;
+ }
}
mp_msg(MSGT_CACHE,MSGL_STATUS,"\n");
return 1; // parent exits
+
+err_out:
+ cache_uninit(stream);
+ return res;
}
#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__)
@@ -386,6 +409,8 @@ static void ThreadProc( void *s ){
#ifdef PTHREAD_CACHE
return NULL;
#endif
+ // make sure forked code never leaves this function
+ exit(0);
}
int cache_stream_fill_buffer(stream_t *s){
diff --git a/stream/http.c b/stream/http.c
index 117c531e4c..f993fee179 100644
--- a/stream/http.c
+++ b/stream/http.c
@@ -743,6 +743,7 @@ static int http_streaming_start(stream_t *stream, int* file_format) {
int auth_retry=0;
int seekable=0;
char *content_type;
+ const char *content_length;
char *next_url;
URL_t *url = stream->streaming_ctrl->url;
@@ -816,15 +817,15 @@ static int http_streaming_start(stream_t *stream, int* file_format) {
// Assume standard http if not ICY
switch( http_hdr->status_code ) {
case 200: // OK
+ content_length = http_get_field(http_hdr, "Content-Length");
+ if (content_length) {
+ mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", content_length);
+ stream->end_pos = atoll(content_length);
+ }
// 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;
mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", content_type );
- if( (content_length = http_get_field(http_hdr, "Content-Length")) != NULL) {
- mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length"));
- stream->end_pos = atoi(content_length);
- }
// Check in the mime type table for a demuxer type
i = 0;
while(mime_type_table[i].mime_type != NULL) {
diff --git a/stream/stream.c b/stream/stream.c
index c964a7c447..76d4306b82 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -435,9 +435,7 @@ stream_t* new_stream(int fd,int type){
void free_stream(stream_t *s){
// printf("\n*** free_stream() called ***\n");
#ifdef CONFIG_STREAM_CACHE
- if(s->cache_pid) {
cache_uninit(s);
- }
#endif
if(s->close) s->close(s);
if(s->fd>0){
diff --git a/stream/stream_ftp.c b/stream/stream_ftp.c
index 9ccd27a46a..e21e512989 100644
--- a/stream/stream_ftp.c
+++ b/stream/stream_ftp.c
@@ -244,7 +244,7 @@ static int FtpOpenPort(struct stream_priv_s* p) {
return fd;
}
-static int FtpOpenData(stream_t* s,size_t newpos) {
+static int FtpOpenData(stream_t* s,off_t newpos) {
struct stream_priv_s* p = s->priv;
int resp;
char str[256],rsp_txt[256];
@@ -369,7 +369,8 @@ static void close_f(stream_t *s) {
static int open_f(stream_t *stream,int mode, void* opts, int* file_format) {
- int len = 0,resp;
+ int resp;
+ int64_t len = 0;
struct stream_priv_s* p = (struct stream_priv_s*)opts;
char str[256],rsp_txt[256];
@@ -438,7 +439,7 @@ static int open_f(stream_t *stream,int mode, void* opts, int* file_format) {
mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command '%s' failed: %s\n",str,rsp_txt);
} else {
int dummy;
- sscanf(rsp_txt,"%d %d",&dummy,&len);
+ sscanf(rsp_txt,"%d %"SCNd64,&dummy,&len);
}
if(len > 0) {