Mercurial > pt1.oyama
comparison src/http.c @ 166:726fe10d9e4a
Code refactoring.
Change channel shuld be done in http_open().
Delete unnecessary code, variables.
| author | Naoya OYAMA <naoya.oyama@gmail.com> |
|---|---|
| date | Tue, 02 Oct 2012 21:57:40 +0900 |
| parents | 5d010d0ff6a1 |
| children | 27e5f99f8991 |
comparison
equal
deleted
inserted
replaced
| 165:3ffef0e5b80a | 166:726fe10d9e4a |
|---|---|
| 20 * with this program; if not, write to the Free Software Foundation, | 20 * with this program; if not, write to the Free Software Foundation, |
| 21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include <sys/types.h> | 24 #include <sys/types.h> |
| 25 #include <sys/msg.h> | |
| 25 #include <sys/stat.h> | 26 #include <sys/stat.h> |
| 26 #include <fcntl.h> | 27 #include <fcntl.h> |
| 27 #include <errno.h> | 28 #include <errno.h> |
| 28 #include <stdio.h> | 29 #include <stdio.h> |
| 29 #include <stdlib.h> | 30 #include <stdlib.h> |
| 44 #include "presentation.h" | 45 #include "presentation.h" |
| 45 #include "osdep.h" | 46 #include "osdep.h" |
| 46 #include "mime.h" | 47 #include "mime.h" |
| 47 #include "recpt1.h" | 48 #include "recpt1.h" |
| 48 #include "tssplitter_lite.h" | 49 #include "tssplitter_lite.h" |
| 50 #include "pt1_common.h" | |
| 49 | 51 |
| 50 #define PROTOCOL_TYPE_PRE_SZ 11 /* for the str length of "http-get:*:" */ | 52 #define PROTOCOL_TYPE_PRE_SZ 11 /* for the str length of "http-get:*:" */ |
| 51 #define PROTOCOL_TYPE_SUFF_SZ 2 /* for the str length of ":*" */ | 53 #define PROTOCOL_TYPE_SUFF_SZ 2 /* for the str length of ":*" */ |
| 52 | 54 |
| 53 extern thread_data tdata; | 55 extern thread_data tdata; |
| 107 log_verbose ("http_get_info, filename : %s\n", filename); | 109 log_verbose ("http_get_info, filename : %s\n", filename); |
| 108 | 110 |
| 109 upnp_id = atoi (strrchr (filename, '/') + 1); | 111 upnp_id = atoi (strrchr (filename, '/') + 1); |
| 110 entry = upnp_get_entry (ut, upnp_id); | 112 entry = upnp_get_entry (ut, upnp_id); |
| 111 | 113 |
| 112 if (ut->nr_channel == 0) { | 114 for (i=0; i < ut->channel_list->nr_channel; i++) { |
| 113 if (!strcmp (filename, STREAM_LOCATION)) { | 115 if (!strcmp(filename, ut->channel_list->channel_info[i]->sid)) { |
| 114 log_verbose ("http_get_info, stream location found.\n"); | 116 log_verbose ("http_get_info, stream location found [%s].\n", filename); |
| 115 info->is_readable = 1; | 117 info->is_readable = 1; |
| 116 info->file_length = get_streaming_length(); | 118 info->file_length = get_streaming_length(); |
| 117 info->last_modified = time(NULL); | 119 info->last_modified = time(NULL); |
| 118 info->is_directory = 0; | 120 info->is_directory = 0; |
| 119 info->content_type = ixmlCloneDOMString ("video/mpeg"); | 121 info->content_type = ixmlCloneDOMString ("video/mpeg"); |
| 120 return 0; | 122 return 0; |
| 121 } | 123 } |
| 122 } else { | |
| 123 for (i=0; i < ut->nr_channel; i++) { | |
| 124 if (!strcmp(filename, ut->location_name[i])) { | |
| 125 log_verbose ("http_get_info, stream location found [%s].\n", filename); | |
| 126 info->is_readable = 1; | |
| 127 info->file_length = get_streaming_length(); | |
| 128 info->last_modified = time(NULL); | |
| 129 info->is_directory = 0; | |
| 130 info->content_type = ixmlCloneDOMString ("video/mpeg"); | |
| 131 return 0; | |
| 132 } | |
| 133 } | |
| 134 } | 124 } |
| 135 if (!strcmp (filename, CDS_LOCATION)) | 125 if (!strcmp (filename, CDS_LOCATION)) |
| 136 { | 126 { |
| 137 set_info_file (info, CDS_DESCRIPTION_LEN, SERVICE_CONTENT_TYPE); | 127 set_info_file (info, CDS_DESCRIPTION_LEN, SERVICE_CONTENT_TYPE); |
| 138 return 0; | 128 return 0; |
| 340 struct upnp_entry_t *entry = NULL; | 330 struct upnp_entry_t *entry = NULL; |
| 341 struct web_file_t *file; | 331 struct web_file_t *file; |
| 342 int i, fd, upnp_id = 0; | 332 int i, fd, upnp_id = 0; |
| 343 extern thread_data *gp_tdata; | 333 extern thread_data *gp_tdata; |
| 344 thread_data *tdata = gp_tdata; | 334 thread_data *tdata = gp_tdata; |
| 345 int channel_length = 0; | 335 pt1_message_buf mbuf; |
| 336 int msqid; | |
| 337 int msgflg = IPC_CREAT | 0666; | |
| 346 | 338 |
| 347 if (!filename) | 339 if (!filename) |
| 348 return NULL; | 340 return NULL; |
| 349 | 341 |
| 350 if (mode != UPNP_READ) | 342 if (mode != UPNP_READ) |
| 376 * 1. http_open() $B$G$O(B entry $B$,%9%H%j!<%`:F@8MQ$N$b$N$G$"$k>l9g$K!"(B | 368 * 1. http_open() $B$G$O(B entry $B$,%9%H%j!<%`:F@8MQ$N$b$N$G$"$k>l9g$K!"(B |
| 377 * get_file_stream()$B$r8F$S=P$7%O%s%I%i$rJV5Q$9$k(B | 369 * get_file_stream()$B$r8F$S=P$7%O%s%I%i$rJV5Q$9$k(B |
| 378 */ | 370 */ |
| 379 for (i=0; i < ut->channel_list->nr_channel; i++) { | 371 for (i=0; i < ut->channel_list->nr_channel; i++) { |
| 380 if (atoi(entry->fullpath) == ut->channel_list->channel_info[i]->id) { | 372 if (atoi(entry->fullpath) == ut->channel_list->channel_info[i]->id) { |
| 381 ut->sid = ut->channel_list->channel_info[i]->sid; | 373 if ((msqid = msgget((key_t)getpid(), msgflg)) < 0) { |
| 382 ut->tp = ut->channel_list->channel_info[i]->tp; | 374 // $B%(%i!<;~$O%A%c%s%M%kJQ99%j%/%(%9%H$O$J$+$C$?$3$H$K$9$k(B |
| 383 return get_file_stream (ut->sid, tdata); | 375 fprintf(stderr, "msgget error.\n"); |
| 376 } | |
| 377 mbuf.mtype = 1; | |
| 378 snprintf(mbuf.mtext, sizeof(mbuf.mtext), | |
| 379 "ch=%s t=%d e=%d i=%s", | |
| 380 ut->channel_list->channel_info[i]->tp, | |
| 381 0, | |
| 382 0, | |
| 383 ut->channel_list->channel_info[i]->sid); | |
| 384 if (msgsnd(msqid, &mbuf, strlen(mbuf.mtext)+1, IPC_NOWAIT) < 0) { | |
| 385 fprintf(stderr, "msgsend error.\n"); | |
| 386 } | |
| 387 return get_file_stream (ut->channel_list->channel_info[i]->sid, tdata); | |
| 384 } | 388 } |
| 385 } | 389 } |
| 386 | 390 |
| 387 fd = open (entry->fullpath, O_RDONLY | O_NONBLOCK | O_SYNC | O_NDELAY); | 391 fd = open (entry->fullpath, O_RDONLY | O_NONBLOCK | O_SYNC | O_NDELAY); |
| 388 if (fd < 0) | 392 if (fd < 0) |
