comparison src/http.c @ 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
comparison
equal deleted inserted replaced
125:e413158cae13 126:5dcaf3785ebe
76 off_t len; 76 off_t len;
77 } stream; 77 } stream;
78 } detail; 78 } detail;
79 }; 79 };
80 80
81 static off_t get_streaming_length (void);
82
81 static inline void 83 static inline void
82 set_info_file (struct File_Info *info, const size_t length, 84 set_info_file (struct File_Info *info, const size_t length,
83 const char *content_type) 85 const char *content_type)
84 { 86 {
85 info->file_length = length; 87 info->file_length = length;
116 ( !strcmp(entry->fullpath, STREAM_LOCATION))) ) { 118 ( !strcmp(entry->fullpath, STREAM_LOCATION))) ) {
117 #endif 119 #endif
118 if (!strcmp (filename, STREAM_LOCATION)) { 120 if (!strcmp (filename, STREAM_LOCATION)) {
119 log_verbose ("http_get_info, stream location found.\n"); 121 log_verbose ("http_get_info, stream location found.\n");
120 info->is_readable = 1; 122 info->is_readable = 1;
121 info->file_length = 100*1024*1024; 123 info->file_length = get_streaming_length();
122 info->file_length = info->file_length - (info->file_length % LENGTH_PACKET);
123 info->last_modified = time(NULL); 124 info->last_modified = time(NULL);
124 info->is_directory = 0; 125 info->is_directory = 0;
125 info->content_type = ixmlCloneDOMString ("video/mpeg"); 126 info->content_type = ixmlCloneDOMString ("video/mpeg");
126 return 0; 127 return 0;
127 } 128 }
188 info->last_modified = st.st_mtime; 189 info->last_modified = st.st_mtime;
189 info->is_directory = S_ISDIR (st.st_mode); 190 info->is_directory = S_ISDIR (st.st_mode);
190 #endif 191 #endif
191 192
192 info->is_readable = 1; 193 info->is_readable = 1;
193 info->file_length = 100*1024*1024; 194 info->file_length = get_streaming_length();
194 info->file_length = info->file_length - (info->file_length % LENGTH_PACKET);
195 info->last_modified = time(NULL); 195 info->last_modified = time(NULL);
196 info->is_directory = 0; 196 info->is_directory = 0;
197 197
198 protocol = 198 protocol =
199 #ifdef HAVE_DLNA 199 #ifdef HAVE_DLNA
314 314
315 file->detail.stream.p_queue = tdata->streamer->stream_session[i]->p_queue; 315 file->detail.stream.p_queue = tdata->streamer->stream_session[i]->p_queue;
316 file->fullpath = strdup (fullpath); 316 file->fullpath = strdup (fullpath);
317 file->pos = 0; 317 file->pos = 0;
318 file->type = FILE_STREAM; 318 file->type = FILE_STREAM;
319 file->detail.stream.len = 100*1024*1024; //$B%U%!%$%k%5%$%:(B($B;DO?2h;~4V(Bx$B%S%C%H%l!<%H(B) 319 file->detail.stream.len = get_streaming_length(); //$B%U%!%$%k%5%$%:(B($B;DO?2h;~4V(Bx$B%S%C%H%l!<%H(B)
320 file->detail.stream.len = file->detail.stream.len - (file->detail.stream.len % LENGTH_PACKET);
321 file->detail.stream.qbuf = stream_dequeue(file->detail.stream.p_queue); 320 file->detail.stream.qbuf = stream_dequeue(file->detail.stream.p_queue);
322 if ( file->detail.stream.qbuf == NULL ) { 321 if ( file->detail.stream.qbuf == NULL ) {
323 log_error ("get_file_stream(): stream_dequeue error.\n"); 322 log_error ("get_file_stream(): stream_dequeue error.\n");
324 return NULL; 323 return NULL;
325 } 324 }
422 file->detail.stream.qbuf = stream_dequeue(file->detail.stream.p_queue); 421 file->detail.stream.qbuf = stream_dequeue(file->detail.stream.p_queue);
423 file->pos = 0; 422 file->pos = 0;
424 } 423 }
425 if ( file->detail.stream.qbuf == NULL ) { 424 if ( file->detail.stream.qbuf == NULL ) {
426 log_verbose ("http_read stream_dequeue error NULL\n"); 425 log_verbose ("http_read stream_dequeue error NULL\n");
427 return -1; 426 return 0;
428 } 427 }
429 len = (size_t) MIN (buflen, file->detail.stream.qbuf->size - file->pos); 428 len = (size_t) MIN (buflen, file->detail.stream.qbuf->size - file->pos);
430 memcpy (buf, file->detail.stream.qbuf->data + file->pos, (size_t) len); 429 memcpy (buf, file->detail.stream.qbuf->data + file->pos, (size_t) len);
431 break; 430 break;
432 default: 431 default:
598 http_read, 597 http_read,
599 http_write, 598 http_write,
600 http_seek, 599 http_seek,
601 http_close 600 http_close
602 }; 601 };
602
603 // TS_BITRATE$B$O$d$C$D$1;E;v2a$.$k5$$,$7$^$9(B
604 #define TS_BITRATE (10*1000*1000/8)
605 static off_t
606 get_streaming_length (void)
607 {
608 off_t length = 0;
609 extern thread_data *gp_tdata;
610 thread_data *tdata = gp_tdata;
611 time_t cur_time;
612
613 time(&cur_time);
614 length = ((tdata->start_time+tdata->recsec) -cur_time) * (off_t)TS_BITRATE;
615 if ( length < 0 ) {
616 length = 0;
617 }
618 length = length - (length % LENGTH_PACKET);
619 return length;
620 }