Changeset 626d8bea9aeafbef8933bf7ea1cf64b9078a3fea
- Timestamp:
- 25/02/03 18:17:43 (6 years ago)
- git-parent:
- Files:
-
- include/httpd.h (modified) (2 diffs)
- include/stream_output.h (modified) (3 diffs)
- modules/access_output/http.c (modified) (7 diffs)
- modules/misc/httpd.c (modified) (19 diffs)
- modules/mux/ogg.c (modified) (3 diffs)
- src/stream_output/stream_output.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
include/httpd.h
r84aaa85 r626d8be 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001-2003 VideoLAN 5 * $Id: httpd.h,v 1. 1 2003/02/23 19:05:22fenrir Exp $5 * $Id: httpd.h,v 1.2 2003/02/25 17:17:43 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 58 58 httpd_stream_t *, 59 59 uint8_t *, int ); 60 int (*pf_header_stream) ( httpd_t *, 61 httpd_stream_t *, 62 uint8_t *, int ); 60 63 void (*pf_unregister_stream) ( httpd_t *, httpd_stream_t * ); 61 64 }; include/stream_output.h
r7def704 r626d8be 3 3 ***************************************************************************** 4 4 * Copyright (C) 2002 VideoLAN 5 * $Id: stream_output.h,v 1. 7 2003/02/24 11:00:54fenrir Exp $5 * $Id: stream_output.h,v 1.8 2003/02/25 17:17:43 fenrir Exp $ 6 6 * 7 7 * Authors: Christophe Massiot <massiot@via.ecp.fr> … … 37 37 * 38 38 */ 39 #define SOUT_BUFFER_FLAGS_HEADER 0x0001 39 40 struct sout_buffer_t 40 41 { … … 51 52 mtime_t i_pts; 52 53 54 uint32_t i_flags; 53 55 int i_bitrate; 54 56 modules/access_output/http.c
r84aaa85 r626d8be 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001-2003 VideoLAN 5 * $Id: http.c,v 1. 1 2003/02/23 19:05:22fenrir Exp $5 * $Id: http.c,v 1.2 2003/02/25 17:17:43 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 67 67 /* stream */ 68 68 httpd_stream_t *p_httpd_stream; 69 70 /* gather header from stream */ 71 int i_header_allocated; 72 int i_header_size; 73 uint8_t *p_header; 74 vlc_bool_t b_header_complete; 69 75 }; 70 76 77 static struct 78 { 79 char *psz_ext; 80 char *psz_mime; 81 } http_mime[] = 82 { 83 { ".avi", "video/avi" }, 84 { ".asf", "video/x-ms-asf" }, 85 { ".m1a", "audio/mpeg" }, 86 { ".m2a", "audio/mpeg" }, 87 { ".m1v", "video/mpeg" }, 88 { ".m2v", "video/mpeg" }, 89 { ".mp2", "audio/mpeg" }, 90 { ".mp3", "audio/mpeg" }, 91 { ".mpa", "audio/mpeg" }, 92 { ".mpg", "video/mpeg" }, 93 { ".mpeg", "video/mpeg" }, 94 { ".mpe", "video/mpeg" }, 95 { ".mov", "video/quicktime" }, 96 { ".moov", "video/quicktime" }, 97 { ".ogg", "application/ogg" }, 98 { ".ogm", "application/ogg" }, 99 { ".wav", "audio/wav" }, 100 { NULL, NULL } 101 }; 102 103 static char *GetMime( char *psz_name ) 104 { 105 char *psz_ext; 106 107 psz_ext = strrchr( psz_name, '.' ); 108 if( psz_ext ) 109 { 110 int i; 111 112 for( i = 0; http_mime[i].psz_ext != NULL ; i++ ) 113 { 114 if( !strcmp( http_mime[i].psz_ext, psz_ext ) ) 115 { 116 return( http_mime[i].psz_mime ); 117 } 118 } 119 } 120 return( "application/octet-stream" ); 121 } 71 122 /***************************************************************************** 72 123 * Open: open the file … … 166 217 p_sys->p_httpd_stream = 167 218 p_sys->p_httpd->pf_register_stream( p_sys->p_httpd, 168 psz_file_name, "application/x-octet_stream", 219 psz_file_name, 220 GetMime( psz_file_name ), 169 221 NULL, NULL ); 170 222 … … 182 234 } 183 235 236 p_sys->i_header_allocated = 1024; 237 p_sys->i_header_size = 0; 238 p_sys->p_header = malloc( p_sys->i_header_allocated ); 239 p_sys->b_header_complete = VLC_FALSE; 240 184 241 p_access->pf_write = Write; 185 242 p_access->pf_seek = Seek; … … 201 258 httpd_Release( p_sys->p_httpd ); 202 259 260 FREE( p_sys->p_header ); 261 203 262 msg_Info( p_access, "Close" ); 204 263 … … 218 277 sout_buffer_t *p_next; 219 278 279 if( p_buffer->i_flags & SOUT_BUFFER_FLAGS_HEADER ) 280 { 281 /* gather header */ 282 if( p_sys->b_header_complete ) 283 { 284 /* free previously gathered header */ 285 p_sys->i_header_size = 0; 286 p_sys->b_header_complete = VLC_FALSE; 287 } 288 if( p_buffer->i_size + p_sys->i_header_size > p_sys->i_header_allocated ) 289 { 290 p_sys->i_header_allocated = p_buffer->i_size + p_sys->i_header_size + 1024; 291 p_sys->p_header = realloc( p_sys->p_header, p_sys->i_header_allocated ); 292 } 293 memcpy( &p_sys->p_header[p_sys->i_header_size], 294 p_buffer->p_buffer, 295 p_buffer->i_size ); 296 p_sys->i_header_size += p_buffer->i_size; 297 } 298 else if( !p_sys->b_header_complete ) 299 { 300 p_sys->b_header_complete = VLC_TRUE; 301 302 p_sys->p_httpd->pf_header_stream( p_sys->p_httpd, 303 p_sys->p_httpd_stream, 304 p_sys->p_header, p_sys->i_header_size ); 305 } 306 /* send data */ 220 307 i_err = p_sys->p_httpd->pf_send_stream( p_sys->p_httpd, p_sys->p_httpd_stream, 221 308 p_buffer->p_buffer, p_buffer->i_size ); … … 230 317 } 231 318 } 319 232 320 if( i_err < 0 ) 233 321 { modules/misc/httpd.c
r3755de8 r626d8be 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001-2003 VideoLAN 5 * $Id: httpd.c,v 1. 2 2003/02/24 11:14:16 gbazinExp $5 * $Id: httpd.c,v 1.3 2003/02/25 17:17:43 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 97 97 * Prototypes 98 98 *****************************************************************************/ 99 static httpd_host_t *RegisterHost ( httpd_t *, char *, int );100 static void UnregisterHost ( httpd_t *, httpd_host_t * );101 102 static httpd_file_t *RegisterFile ( httpd_t *,103 char *psz_file, char *psz_mime,104 char *psz_user, char *psz_password,105 httpd_file_callback pf_fill,106 httpd_file_callback_args_t *p_args );107 static void UnregisterFile ( httpd_t *, httpd_file_t * );99 static httpd_host_t *RegisterHost ( httpd_t *, char *, int ); 100 static void UnregisterHost ( httpd_t *, httpd_host_t * ); 101 102 static httpd_file_t *RegisterFile ( httpd_t *, 103 char *psz_file, char *psz_mime, 104 char *psz_user, char *psz_password, 105 httpd_file_callback pf_fill, 106 httpd_file_callback_args_t *p_args ); 107 static void UnregisterFile ( httpd_t *, httpd_file_t * ); 108 108 109 109 //#define httpd_stream_t httpd_file_t 110 static httpd_stream_t *RegisterStream ( httpd_t *,110 static httpd_stream_t *RegisterStream ( httpd_t *, 111 111 char *psz_file, char *psz_mime, 112 112 char *psz_user, char *psz_password ); 113 static int SendStream( httpd_t *, httpd_stream_t *, uint8_t *, int ); 113 static int SendStream ( httpd_t *, httpd_stream_t *, uint8_t *, int ); 114 static int HeaderStream ( httpd_t *, httpd_stream_t *, uint8_t *, int ); 114 115 static void UnregisterStream( httpd_t *, httpd_stream_t* ); 115 116 … … 152 153 153 154 /* private */ 154 int i_buffer_size; /* buffer size */ 155 uint8_t *p_buffer; /* buffer */ 156 int i_buffer; /* reading pointer */ 157 int i_buffer_valid; /* valid data from 0 */ 158 155 156 /* circular buffer for stream only */ 157 int i_buffer_size; /* buffer size, can't be reallocated smaller */ 158 uint8_t *p_buffer; /* buffer */ 159 int64_t i_buffer_pos; /* absolute position from begining */ 160 int i_buffer_last_pos; /* a new connection will start with that */ 161 162 /* data to be send at connection time (if any) */ 163 int i_header_size; 164 uint8_t *p_header; 159 165 }; 160 166 … … 182 188 httpd_file_t *p_file; 183 189 190 /* used while sending header and file */ 184 191 int i_buffer_size; 185 192 uint8_t *p_buffer; 186 int i_buffer; /* private */ 193 int i_buffer; /* private */ 194 195 /* used for stream */ 196 int64_t i_stream_pos; /* absolute pos in stream */ 187 197 } httpd_connection_t; 188 198 … … 265 275 p_httpd->pf_unregister_file = UnregisterFile; 266 276 p_httpd->pf_register_stream = RegisterStream; 277 p_httpd->pf_header_stream = HeaderStream; 267 278 p_httpd->pf_send_stream = SendStream; 268 279 p_httpd->pf_unregister_stream=UnregisterStream; … … 634 645 } 635 646 636 p_file->b_stream = VLC_FALSE; 637 p_file->p_sys = p_args; 638 p_file->pf_fill = pf_fill; 639 640 p_file->i_buffer_size = 0; 641 p_file->i_buffer_valid = 0; 642 p_file->i_buffer = 0; 643 p_file->p_buffer = NULL; 647 p_file->b_stream = VLC_FALSE; 648 p_file->p_sys = p_args; 649 p_file->pf_fill = pf_fill; 650 651 p_file->i_buffer_size = 0; 652 p_file->i_buffer_last_pos = 0; 653 p_file->i_buffer_pos = 0; 654 p_file->p_buffer = NULL; 655 656 p_file->i_header_size = 0; 657 p_file->p_header = NULL; 644 658 645 659 __RegisterFile( p_httpt, p_file ); … … 678 692 { 679 693 vlc_mutex_unlock( &p_httpt->file_lock ); 680 msg_Err( p_httpt, "%s already registere t", psz_file );694 msg_Err( p_httpt, "%s already registered", psz_file ); 681 695 return NULL; 682 696 } … … 702 716 p_stream->p_sys = NULL; 703 717 p_stream->pf_fill = NULL; 704 p_stream->i_buffer_size = 1024*1024; 705 p_stream->i_buffer_valid = 0; 706 p_stream->i_buffer = 0; 718 719 p_stream->i_buffer_size = 1024*1024*10; 720 p_stream->i_buffer_pos = 0; 721 p_stream->i_buffer_last_pos = 0; 707 722 p_stream->p_buffer = malloc( p_stream->i_buffer_size ); 723 724 p_stream->i_header_size = 0; 725 p_stream->p_header = NULL; 708 726 709 727 __RegisterFile( p_httpt, p_stream ); … … 769 787 } 770 788 FREE( p_file->p_buffer ); 789 FREE( p_file->p_header ); 771 790 772 791 FREE( p_file ); … … 807 826 static int _SendStream( httpd_sys_t *p_httpt, httpd_stream_t *p_stream, uint8_t *p_data, int i_data ) 808 827 { 809 if( i_data <= 0 ) 828 int i_count; 829 int i_pos; 830 831 if( i_data <= 0 || p_data == NULL ) 810 832 { 811 833 return( VLC_SUCCESS ); 812 834 } 835 //fprintf( stderr, "## i_data=%d pos=%lld\n", i_data, p_stream->i_buffer_pos ); 813 836 814 837 vlc_mutex_lock( &p_httpt->file_lock ); 815 if( p_stream->i_buffer_size < p_stream->i_buffer_valid + i_data ) 816 { 817 /* not enough room */ 818 if( p_stream->i_buffer < p_stream->i_buffer_valid ) 819 { 820 memmove( p_stream->p_buffer, 821 p_stream->p_buffer + p_stream->i_buffer, 822 p_stream->i_buffer_valid - p_stream->i_buffer ); 823 } 824 p_stream->i_buffer_valid -= p_stream->i_buffer; 825 826 p_stream->i_buffer = 0; 827 } 828 i_data = __MIN( i_data, p_stream->i_buffer_size - p_stream->i_buffer_valid ); 829 memcpy( p_stream->p_buffer + p_stream->i_buffer_valid, p_data, i_data ); 830 p_stream->i_buffer_valid += i_data; 831 838 839 /* save this pointer (to be used by new connection) */ 840 p_stream->i_buffer_last_pos = p_stream->i_buffer_pos; 841 842 i_pos = p_stream->i_buffer_pos % p_stream->i_buffer_size; 843 i_count = i_data; 844 while( i_count > 0) 845 { 846 int i_copy; 847 848 i_copy = __MIN( i_data, p_stream->i_buffer_size - i_pos ); 849 850 memcpy( &p_stream->p_buffer[i_pos], 851 p_data, 852 i_copy ); 853 854 i_pos = ( i_pos + i_copy ) % p_stream->i_buffer_size; 855 i_count -= i_copy; 856 p_data += i_copy; 857 } 858 859 p_stream->i_buffer_pos += i_data; 832 860 vlc_mutex_unlock( &p_httpt->file_lock ); 833 861 … … 837 865 { 838 866 return( _SendStream( p_httpd->p_sys, p_stream, p_data, i_data ) ); 867 } 868 869 static int HeaderStream( httpd_t *p_httpd, httpd_stream_t *p_stream, uint8_t *p_data, int i_data ) 870 { 871 httpd_sys_t *p_httpt = p_httpd->p_sys; 872 873 vlc_mutex_lock( &p_httpt->file_lock ); 874 875 FREE( p_stream->p_header ); 876 if( p_data == NULL || i_data <= 0 ) 877 { 878 p_stream->i_header_size = 0; 879 } 880 else 881 { 882 p_stream->i_header_size = i_data; 883 p_stream->p_header = malloc( i_data ); 884 memcpy( p_stream->p_header, 885 p_data, 886 i_data ); 887 } 888 vlc_mutex_unlock( &p_httpt->file_lock ); 889 890 return( VLC_SUCCESS ); 839 891 } 840 892 … … 1013 1065 p_con->p_buffer = malloc( p_con->i_buffer_size ); 1014 1066 1067 p_con->i_stream_pos = 0; // updated by httpd_thread */ 1015 1068 p_con->p_next = NULL; 1016 1069 … … 1311 1364 p_con->i_state = HTTPD_CONNECTION_SENDING_HEADER; 1312 1365 1366 /* we send stream header with this one */ 1367 if( p_con->i_http_error == 200 && p_con->p_file->b_stream ) 1368 { 1369 p_con->i_buffer_size = 4096 + p_con->p_file->i_header_size; 1370 } 1371 1313 1372 p_con->i_buffer_size = 4096; 1314 1373 p_con->i_buffer = 0; … … 1323 1382 p += sprintf( p, "\r\n" ); 1324 1383 1325 p_con->i_buffer_size = strlen( p_con->p_buffer ) + 1; 1384 p_con->i_buffer_size = strlen( p_con->p_buffer );// + 1; 1385 1386 if( p_con->i_http_error == 200 && p_con->p_file->b_stream && p_con->p_file->i_header_size > 0 ) 1387 { 1388 /* add stream header */ 1389 memcpy( &p_con->p_buffer[p_con->i_buffer_size], 1390 p_con->p_file->p_header, 1391 p_con->p_file->i_header_size ); 1392 p_con->i_buffer_size += p_con->p_file->i_header_size; 1393 } 1326 1394 1327 1395 //msg_Dbg( p_httpt, "answer=\n%s", p_con->p_buffer ); 1328 1396 } 1329 #define HTTPD_STREAM_PACKET 1 3001397 #define HTTPD_STREAM_PACKET 10000 1330 1398 static void httpd_Thread( httpd_sys_t *p_httpt ) 1331 1399 { … … 1478 1546 { 1479 1547 p_con->i_state = HTTPD_CONNECTION_SENDING_STREAM; 1548 p_con->i_stream_pos = p_con->p_file->i_buffer_last_pos; 1480 1549 } 1481 1550 p_con = p_con->p_next; … … 1502 1571 else if( p_con->i_state == HTTPD_CONNECTION_SENDING_STREAM ) 1503 1572 { 1504 httpd_ file_t *p_file= p_con->p_file;1505 int i_ len;1506 1507 //msg_Dbg( p_httpt, "buffer=%d buffer_size=%d", p_file->i_buffer, p_file->i_buffer_size ); 1508 if( p_ file->i_buffer < p_file->i_buffer_valid)1573 httpd_stream_t *p_stream = p_con->p_file; 1574 int i_send; 1575 int i_write; 1576 1577 if( p_con->i_stream_pos < p_stream->i_buffer_pos ) 1509 1578 { 1510 int i_write; 1511 /* write data */ 1512 i_write = __MIN( p_file->i_buffer_valid - p_file->i_buffer, HTTPD_STREAM_PACKET ); 1513 i_len = send( p_con->fd, p_file->p_buffer + p_file->i_buffer, i_write, 0 ); 1514 1515 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR )|| 1516 ( i_len == 0 ) ) 1579 int i_pos; 1580 /* check if this p_con aren't to late */ 1581 if( p_con->i_stream_pos + p_stream->i_buffer_size < p_stream->i_buffer_pos ) 1582 { 1583 fprintf(stderr, "fixing i_stream_pos (old=%lld i_buffer_pos=%lld\n", p_con->i_stream_pos, p_stream->i_buffer_pos ); 1584 p_con->i_stream_pos = p_stream->i_buffer_last_pos; 1585 } 1586 1587 i_pos = p_con->i_stream_pos % p_stream->i_buffer_size; 1588 /* size until end of buffer */ 1589 i_write = p_stream->i_buffer_size - i_pos; 1590 /* is it more than valid data */ 1591 if( i_write >= p_stream->i_buffer_pos - p_con->i_stream_pos ) 1592 { 1593 i_write = p_stream->i_buffer_pos - p_con->i_stream_pos; 1594 } 1595 /* limit to HTTPD_STREAM_PACKET */ 1596 if( i_write > HTTPD_STREAM_PACKET ) 1597 { 1598 i_write = HTTPD_STREAM_PACKET; 1599 } 1600 i_send = send( p_con->fd, &p_stream->p_buffer[i_pos], i_write, 0 ); 1601 1602 if( ( i_send < 0 && errno != EAGAIN && errno != EINTR )|| ( i_send == 0 ) ) 1517 1603 { 1518 1604 httpd_connection_t *p_next = p_con->p_next; … … 1520 1606 httpd_ConnnectionClose( p_httpt, p_con ); 1521 1607 p_con = p_next; 1608 continue; 1522 1609 } 1523 else 1610 else if( i_send > 0 ) 1524 1611 { 1525 p_con = p_con->p_next;1612 p_con->i_stream_pos += i_send; 1526 1613 } 1527 1614 } 1528 else 1529 { 1530 p_con = p_con->p_next; 1531 } 1615 p_con = p_con->p_next; 1532 1616 continue; /* just for clarity */ 1533 1617 } … … 1539 1623 } /* for over connection */ 1540 1624 1541 1625 #if 0 1542 1626 b_wait = VLC_TRUE; 1543 1627 /* update position for stream based file */ … … 1555 1639 } 1556 1640 } 1641 #endif 1557 1642 vlc_mutex_unlock( &p_httpt->file_lock ); 1558 if( b_wait ) msleep( 100 );1643 /*if( b_wait )*/ msleep( 10 ); 1559 1644 } 1560 1645 msg_Info( p_httpt, "httpd stopped" ); modules/mux/ogg.c
rc11203a r626d8be 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001, 2002 VideoLAN 5 * $Id: ogg.c,v 1. 1 2003/02/24 23:27:20fenrir Exp $5 * $Id: ogg.c,v 1.2 2003/02/25 17:17:43 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 328 328 329 329 p_og = OggStreamFlush( p_sout, &p_stream->os, 0 ); 330 OggSetDate( p_og, p_stream->i_dts, p_stream->i_length ); 331 332 sout_AccessOutWrite( p_sout->p_access, p_og ); 330 if( p_og ) 331 { 332 OggSetDate( p_og, p_stream->i_dts, p_stream->i_length ); 333 334 sout_AccessOutWrite( p_sout->p_access, p_og ); 335 } 333 336 334 337 ogg_stream_clear( &p_stream->os ); … … 510 513 } 511 514 515 /* set HEADER flag */ 516 for( p_og = p_hdr; p_og != NULL; p_og = p_og->p_next ) 517 { 518 p_og->i_flags |= SOUT_BUFFER_FLAGS_HEADER; 519 } 512 520 return( p_hdr ); 513 521 } src/stream_output/stream_output.c
r75292af r626d8be 3 3 ***************************************************************************** 4 4 * Copyright (C) 2002 VideoLAN 5 * $Id: stream_output.c,v 1.1 5 2003/02/24 23:28:18fenrir Exp $5 * $Id: stream_output.c,v 1.16 2003/02/25 17:17:43 fenrir Exp $ 6 6 * 7 7 * Authors: Christophe Massiot <massiot@via.ecp.fr> … … 635 635 p_buffer->i_buffer_size = i_size; 636 636 637 p_buffer->i_size = i_size;638 p_buffer->i_length = 0;639 p_buffer->i_dts = 0;640 p_buffer->i_pts = 0;637 p_buffer->i_size = i_size; 638 p_buffer->i_length = 0; 639 p_buffer->i_dts = 0; 640 p_buffer->i_pts = 0; 641 641 p_buffer->i_bitrate = 0; 642 p_buffer->i_flags = 0x0000; 642 643 p_buffer->p_next = NULL; 643 644 … … 716 717 p_dup->i_pts = p_buffer->i_pts; 717 718 p_dup->i_length = p_buffer->i_length; 719 p_dup->i_flags = p_buffer->i_flags; 718 720 p_sout->p_vlc->pf_memcpy( p_dup->p_buffer, p_buffer->p_buffer, p_buffer->i_size ); 719 721
