Mercurial > pt1.oyama
changeset 126:5dcaf3785ebe
fix process terminate problem.
add dynamic Content-Length header.
author | Naoya OYAMA <naoya.oyama@gmail.com> |
---|---|
date | Sun, 03 Oct 2010 21:55:37 +0900 |
parents | e413158cae13 |
children | 5a380559a61e |
files | src/http.c src/metadata.c src/recpt1.c src/ushare.c src/ushare.h |
diffstat | 5 files changed, 37 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/http.c Sun Oct 03 11:35:19 2010 +0900 +++ b/src/http.c Sun Oct 03 21:55:37 2010 +0900 @@ -78,6 +78,8 @@ } detail; }; +static off_t get_streaming_length (void); + static inline void set_info_file (struct File_Info *info, const size_t length, const char *content_type) @@ -118,8 +120,7 @@ if (!strcmp (filename, STREAM_LOCATION)) { log_verbose ("http_get_info, stream location found.\n"); info->is_readable = 1; - info->file_length = 100*1024*1024; - info->file_length = info->file_length - (info->file_length % LENGTH_PACKET); + info->file_length = get_streaming_length(); info->last_modified = time(NULL); info->is_directory = 0; info->content_type = ixmlCloneDOMString ("video/mpeg"); @@ -190,8 +191,7 @@ #endif info->is_readable = 1; - info->file_length = 100*1024*1024; - info->file_length = info->file_length - (info->file_length % LENGTH_PACKET); + info->file_length = get_streaming_length(); info->last_modified = time(NULL); info->is_directory = 0; @@ -316,8 +316,7 @@ file->fullpath = strdup (fullpath); file->pos = 0; file->type = FILE_STREAM; - file->detail.stream.len = 100*1024*1024; //$B%U%!%$%k%5%$%:(B($B;DO?2h;~4V(Bx$B%S%C%H%l!<%H(B) - file->detail.stream.len = file->detail.stream.len - (file->detail.stream.len % LENGTH_PACKET); + file->detail.stream.len = get_streaming_length(); //$B%U%!%$%k%5%$%:(B($B;DO?2h;~4V(Bx$B%S%C%H%l!<%H(B) file->detail.stream.qbuf = stream_dequeue(file->detail.stream.p_queue); if ( file->detail.stream.qbuf == NULL ) { log_error ("get_file_stream(): stream_dequeue error.\n"); @@ -424,7 +423,7 @@ } if ( file->detail.stream.qbuf == NULL ) { log_verbose ("http_read stream_dequeue error NULL\n"); - return -1; + return 0; } len = (size_t) MIN (buflen, file->detail.stream.qbuf->size - file->pos); memcpy (buf, file->detail.stream.qbuf->data + file->pos, (size_t) len); @@ -600,3 +599,22 @@ http_seek, http_close }; + +// TS_BITRATE$B$O$d$C$D$1;E;v2a$.$k5$$,$7$^$9(B +#define TS_BITRATE (10*1000*1000/8) +static off_t +get_streaming_length (void) +{ + off_t length = 0; + extern thread_data *gp_tdata; + thread_data *tdata = gp_tdata; + time_t cur_time; + + time(&cur_time); + length = ((tdata->start_time+tdata->recsec) -cur_time) * (off_t)TS_BITRATE; + if ( length < 0 ) { + length = 0; + } + length = length - (length % LENGTH_PACKET); + return length; +}
--- a/src/metadata.c Sun Oct 03 11:35:19 2010 +0900 +++ b/src/metadata.c Sun Oct 03 21:55:37 2010 +0900 @@ -565,6 +565,7 @@ struct upnp_entry_t *entry = ut->root_entry; st.st_size = 100*1024*1024; metadata_add_file (ut, ut->root_entry, STREAM_LOCATION, STREAM_FILE_NAME, &st); + ut->contentlist = NULL; //metadata_add_container (ut, ut->root_entry, "/web/"); #if 0
--- a/src/recpt1.c Sun Oct 03 11:35:19 2010 +0900 +++ b/src/recpt1.c Sun Oct 03 21:55:37 2010 +0900 @@ -674,6 +674,8 @@ //fprintf (stderr, "stream_func(): start.\n"); while(1) { + if(f_exit) + break; // 3.1 tdata->stream_queue $B$+$i(B dequeue $B$9$k(B // dequeue $B$7$?%G!<%?$O(B ARIB_STD_B25_BUFFER qbuf = stream_dequeue(p_queue); @@ -871,11 +873,15 @@ void cleanup(thread_data *tdata) { + int use_dlna = TRUE; /* stop recording */ ioctl(tdata->tfd, STOP_REC, 0); /* xxx need mutex? */ f_exit = TRUE; + if ( use_dlna ) { + UPnPBreak(0); + } pthread_cond_signal(&tdata->queue->cond_avail); pthread_cond_signal(&tdata->queue->cond_used);
--- a/src/ushare.c Sun Oct 03 11:35:19 2010 +0900 +++ b/src/ushare.c Sun Oct 03 21:55:37 2010 +0900 @@ -641,7 +641,8 @@ return (init_upnp (ut)); } -static void +//static void +void UPnPBreak (int s __attribute__ ((unused))) { ushare_signal_exit (); @@ -890,13 +891,10 @@ build_metadata_list (ut); - log_verbose ("uShare mutex lock.\n"); /* Let main sleep until it's time to die... */ pthread_mutex_lock (&ut->termination_mutex); - log_verbose ("uShare cond wait.\n"); pthread_cond_wait (&ut->termination_cond, &ut->termination_mutex); pthread_mutex_unlock (&ut->termination_mutex); - log_verbose ("uShare finish.\n"); if (ut->use_telnet) ctrl_telnet_stop (); @@ -905,7 +903,7 @@ ushare_free (ut); finish_iconv (); - log_verbose ("dlna_start() finish\n"); /* it should never be executed */ return NULL; } +