comparison libmpdemux/http.c @ 16070:d56d00a47568

Multiple unsv/scast bug fixes. * use recv instead of read for MinGW compatibility * detect EOF more reliably * use ultravox only for unsv:// instead of trying autodetection
author reimar
date Sat, 23 Jul 2005 15:29:51 +0000
parents c5a629a2f33c
children 095e980cf7c0
comparison
equal deleted inserted replaced
16069:63d7e6bf5ee0 16070:d56d00a47568
55 cp_len = len; 55 cp_len = len;
56 memcpy(buffer, &sc->buffer[sc->buffer_pos], cp_len); 56 memcpy(buffer, &sc->buffer[sc->buffer_pos], cp_len);
57 sc->buffer_pos += cp_len; 57 sc->buffer_pos += cp_len;
58 pos += cp_len; 58 pos += cp_len;
59 while (pos < len) { 59 while (pos < len) {
60 int ret = read(fd, &buffer[pos], len - pos); 60 int ret = recv(fd, &buffer[pos], len - pos, 0);
61 if (ret <= 0) 61 if (ret <= 0)
62 break; 62 break;
63 pos += ret; 63 pos += ret;
64 } 64 }
65 return pos; 65 return pos;
71 * \param sc streaming_ctrl_t whose buffer is consumed before reading from fd 71 * \param sc streaming_ctrl_t whose buffer is consumed before reading from fd
72 * \return number of real data before next metadata block starts or 0 on error 72 * \return number of real data before next metadata block starts or 0 on error
73 */ 73 */
74 static unsigned uvox_meta_read(int fd, streaming_ctrl_t *sc) { 74 static unsigned uvox_meta_read(int fd, streaming_ctrl_t *sc) {
75 unsigned metaint; 75 unsigned metaint;
76 unsigned char info[6]; 76 unsigned char info[6] = {0, 0, 0, 0, 0, 0};
77 int info_read;
77 do { 78 do {
78 my_read(fd, info, 1, sc); 79 info_read = my_read(fd, info, 1, sc);
79 if (info[0] == 0x00) 80 if (info[0] == 0x00)
80 my_read(fd, info, 6, sc); 81 info_read = my_read(fd, info, 6, sc);
81 else 82 else
82 my_read(fd, &info[1], 5, sc); 83 info_read += my_read(fd, &info[1], 5, sc);
84 if (info_read != 6) // read error or eof
85 return 0;
83 // sync byte and reserved flags 86 // sync byte and reserved flags
84 if (info[0] != 0x5a || (info[1] & 0xfc) != 0x00) { 87 if (info[0] != 0x5a || (info[1] & 0xfc) != 0x00) {
85 mp_msg(MSGT_DEMUXER, MSGL_ERR, "Invalid or unknown uvox metadata\n"); 88 mp_msg(MSGT_DEMUXER, MSGL_ERR, "Invalid or unknown uvox metadata\n");
86 return 0; 89 return 0;
87 } 90 }
139 if (ret != block) // read problems or eof 142 if (ret != block) // read problems or eof
140 size = done; 143 size = done;
141 144
142 while (done < size) { // now comes the metadata 145 while (done < size) { // now comes the metadata
143 if (sd->is_ultravox) 146 if (sd->is_ultravox)
147 {
144 sd->metaint = uvox_meta_read(fd, sc); 148 sd->metaint = uvox_meta_read(fd, sc);
149 if (!sd->metaint)
150 size = done;
151 }
145 else 152 else
146 scast_meta_read(fd, sc); // read and display metadata 153 scast_meta_read(fd, sc); // read and display metadata
147 sd->metapos = 0; 154 sd->metapos = 0;
148 block = size - done; 155 block = size - done;
149 if (block > sd->metaint) 156 if (block > sd->metaint)
160 static int scast_streaming_start(stream_t *stream) { 167 static int scast_streaming_start(stream_t *stream) {
161 int metaint; 168 int metaint;
162 int fromhdr; 169 int fromhdr;
163 scast_data_t *scast_data; 170 scast_data_t *scast_data;
164 HTTP_header_t *http_hdr = stream->streaming_ctrl->data; 171 HTTP_header_t *http_hdr = stream->streaming_ctrl->data;
165 int is_ultravox = http_hdr && strcasecmp(http_hdr->protocol, "ICY") != 0; 172 int is_ultravox = strcasecmp(stream->streaming_ctrl->url->protocol, "unsv") == 0;
166 if (!stream || stream->fd < 0 || !http_hdr) 173 if (!stream || stream->fd < 0 || !http_hdr)
167 return -1; 174 return -1;
168 if (is_ultravox) 175 if (is_ultravox)
169 metaint = 0; 176 metaint = 0;
170 else { 177 else {
834 841
835 static int fixup_open(stream_t *stream,int seekable) { 842 static int fixup_open(stream_t *stream,int seekable) {
836 HTTP_header_t *http_hdr = stream->streaming_ctrl->data; 843 HTTP_header_t *http_hdr = stream->streaming_ctrl->data;
837 int is_icy = http_hdr && strcasecmp(http_hdr->protocol, "ICY") == 0; 844 int is_icy = http_hdr && strcasecmp(http_hdr->protocol, "ICY") == 0;
838 char *content_type = http_get_field( http_hdr, "Content-Type" ); 845 char *content_type = http_get_field( http_hdr, "Content-Type" );
839 int is_ultravox = http_hdr && content_type && 846 int is_ultravox = strcasecmp(stream->streaming_ctrl->url->protocol, "unsv") == 0;
840 strcasecmp(content_type, "misc/ultravox") == 0;
841 847
842 stream->type = STREAMTYPE_STREAM; 848 stream->type = STREAMTYPE_STREAM;
843 if(!is_icy && !is_ultravox && seekable) 849 if(!is_icy && !is_ultravox && seekable)
844 { 850 {
845 stream->flags |= STREAM_SEEK; 851 stream->flags |= STREAM_SEEK;