# HG changeset patch # User Naoya OYAMA # Date 1286110537 -32400 # Node ID 5dcaf3785ebe061d5cf8fbad11e29e214c63c20d # Parent e413158cae1344635c89ceb93f934c3728269362 fix process terminate problem. add dynamic Content-Length header. diff -r e413158cae13 -r 5dcaf3785ebe src/http.c --- 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; //ファイルサイズ(残録画時間xビットレート) - file->detail.stream.len = file->detail.stream.len - (file->detail.stream.len % LENGTH_PACKET); + file->detail.stream.len = get_streaming_length(); //ファイルサイズ(残録画時間xビットレート) 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はやっつけ仕事過ぎる気がします +#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; +} diff -r e413158cae13 -r 5dcaf3785ebe src/metadata.c --- 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 diff -r e413158cae13 -r 5dcaf3785ebe src/recpt1.c --- 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 から dequeue する // dequeue したデータは 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); diff -r e413158cae13 -r 5dcaf3785ebe src/ushare.c --- 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; } + diff -r e413158cae13 -r 5dcaf3785ebe src/ushare.h --- a/src/ushare.h Sun Oct 03 11:35:19 2010 +0900 +++ b/src/ushare.h Sun Oct 03 21:55:37 2010 +0900 @@ -132,5 +132,7 @@ inline void display_headers (void); void * dlna_startup(void *p); +void UPnPBreak (int s __attribute__ ((unused))); + #endif /* _USHARE_H_ */