Nog een poging...
This commit is contained in:
		
							parent
							
								
									4ad85c9aac
								
							
						
					
					
						commit
						4776cd08d7
					
				
					 1 changed files with 55 additions and 59 deletions
				
			
		|  | @ -71,7 +71,7 @@ int main(){ | ||||||
|   int retval; |   int retval; | ||||||
|   int poller = epoll_create(1); |   int poller = epoll_create(1); | ||||||
|   struct epoll_event ev; |   struct epoll_event ev; | ||||||
|   ev.events = EPOLLIN | EPOLLOUT; |   ev.events = EPOLLIN; | ||||||
|   ev.data.fd = fileno(CONN); |   ev.data.fd = fileno(CONN); | ||||||
|   epoll_ctl(poller, EPOLL_CTL_ADD, fileno(CONN), &ev); |   epoll_ctl(poller, EPOLL_CTL_ADD, fileno(CONN), &ev); | ||||||
|   struct epoll_event events[1]; |   struct epoll_event events[1]; | ||||||
|  | @ -82,68 +82,64 @@ int main(){ | ||||||
|   while (!ferror(CONN) && !feof(CONN)){ |   while (!ferror(CONN) && !feof(CONN)){ | ||||||
|     //only parse input if available or not yet init'ed
 |     //only parse input if available or not yet init'ed
 | ||||||
|     //rightnow = getNowMS();
 |     //rightnow = getNowMS();
 | ||||||
|     retval = epoll_wait(poller, events, 1, 1000); |     retval = epoll_wait(poller, events, 1, 100); | ||||||
|     if (retval){ |     if (retval > 0){ | ||||||
|       if (events[0].events & EPOLLIN){ |       parseChunk(); | ||||||
|         parseChunk(); |       fflush(CONN); | ||||||
|         fflush(CONN); |     } | ||||||
|       } |     if (ready4data){ | ||||||
|       if (events[0].events & EPOLLOUT){ |       if (!inited){ | ||||||
|         if (ready4data){ |         //we are ready, connect the socket!
 | ||||||
|           if (!inited){ |         if (!ss.connect(streamname.c_str())){ | ||||||
|             //we are ready, connect the socket!
 |           #ifdef DEBUG | ||||||
|             if (!ss.connect(streamname.c_str())){ |           fprintf(stderr, "Could not connect to server!\n"); | ||||||
|               #ifdef DEBUG |           #endif | ||||||
|               fprintf(stderr, "Could not connect to server!\n"); |           return 0; | ||||||
|               #endif |  | ||||||
|               return 0; |  | ||||||
|             } |  | ||||||
|             FLV_Readheader(ss);//read the header, we don't want it
 |  | ||||||
|             #ifdef DEBUG |  | ||||||
|             fprintf(stderr, "Header read, starting to send video data...\n"); |  | ||||||
|             #endif |  | ||||||
|             inited = true; |  | ||||||
|           } |  | ||||||
|           //only send data if previous data has been ACK'ed...
 |  | ||||||
|           if (snd_cnt - snd_window_at < snd_window_size){ |  | ||||||
|             if (FLV_GetPacket(ss)){//able to read a full packet?
 |  | ||||||
|               ts = FLVbuffer[7] * 256*256*256; |  | ||||||
|               ts += FLVbuffer[4] * 256*256; |  | ||||||
|               ts += FLVbuffer[5] * 256; |  | ||||||
|               ts += FLVbuffer[6]; |  | ||||||
|               if (ts != 0){ |  | ||||||
|                 if (fts == 0){fts = ts;ftst = getNowMS();} |  | ||||||
|                 ts -= fts; |  | ||||||
|                 FLVbuffer[7] = ts / (256*256*256); |  | ||||||
|                 FLVbuffer[4] = ts / (256*256); |  | ||||||
|                 FLVbuffer[5] = ts / 256; |  | ||||||
|                 FLVbuffer[6] = ts % 256; |  | ||||||
|                 ts += ftst; |  | ||||||
|               }else{ |  | ||||||
|                 ftst = getNowMS(); |  | ||||||
|                 FLVbuffer[7] = ftst / (256*256*256); |  | ||||||
|                 FLVbuffer[4] = ftst / (256*256); |  | ||||||
|                 FLVbuffer[5] = ftst / 256; |  | ||||||
|                 FLVbuffer[6] = ftst % 256; |  | ||||||
|               } |  | ||||||
|               SendMedia((unsigned char)FLVbuffer[0], (unsigned char *)FLVbuffer+11, FLV_len-15, ts); |  | ||||||
|               FLV_Dump();//dump packet and get ready for next
 |  | ||||||
|             } |  | ||||||
|             if ((SWBerr != SWBaseSocket::ok) && (SWBerr != SWBaseSocket::notReady)){ |  | ||||||
|               #ifdef DEBUG |  | ||||||
|               fprintf(stderr, "No more data! :-(  (%s)\n", SWBerr.get_error().c_str()); |  | ||||||
|               #endif |  | ||||||
|               return 0;//no more input possible! Fail immediately.
 |  | ||||||
|             } |  | ||||||
|           } |  | ||||||
|         } |         } | ||||||
|         //send ACK if we received a whole window
 |         FLV_Readheader(ss);//read the header, we don't want it
 | ||||||
|         if (rec_cnt - rec_window_at > rec_window_size){ |         #ifdef DEBUG | ||||||
|           rec_window_at = rec_cnt; |         fprintf(stderr, "Header read, starting to send video data...\n"); | ||||||
|           SendCTL(3, rec_cnt);//send ack (msg 3)
 |         #endif | ||||||
|  |         inited = true; | ||||||
|  |       } | ||||||
|  |       //only send data if previous data has been ACK'ed...
 | ||||||
|  |       if (snd_cnt - snd_window_at < snd_window_size){ | ||||||
|  |         if (FLV_GetPacket(ss)){//able to read a full packet?
 | ||||||
|  |           ts = FLVbuffer[7] * 256*256*256; | ||||||
|  |           ts += FLVbuffer[4] * 256*256; | ||||||
|  |           ts += FLVbuffer[5] * 256; | ||||||
|  |           ts += FLVbuffer[6]; | ||||||
|  |           if (ts != 0){ | ||||||
|  |             if (fts == 0){fts = ts;ftst = getNowMS();} | ||||||
|  |             ts -= fts; | ||||||
|  |             FLVbuffer[7] = ts / (256*256*256); | ||||||
|  |             FLVbuffer[4] = ts / (256*256); | ||||||
|  |             FLVbuffer[5] = ts / 256; | ||||||
|  |             FLVbuffer[6] = ts % 256; | ||||||
|  |             ts += ftst; | ||||||
|  |           }else{ | ||||||
|  |             ftst = getNowMS(); | ||||||
|  |             FLVbuffer[7] = ftst / (256*256*256); | ||||||
|  |             FLVbuffer[4] = ftst / (256*256); | ||||||
|  |             FLVbuffer[5] = ftst / 256; | ||||||
|  |             FLVbuffer[6] = ftst % 256; | ||||||
|  |           } | ||||||
|  |           SendMedia((unsigned char)FLVbuffer[0], (unsigned char *)FLVbuffer+11, FLV_len-15, ts); | ||||||
|  |           FLV_Dump();//dump packet and get ready for next
 | ||||||
|  |         } | ||||||
|  |         if ((SWBerr != SWBaseSocket::ok) && (SWBerr != SWBaseSocket::notReady)){ | ||||||
|  |           #ifdef DEBUG | ||||||
|  |           fprintf(stderr, "No more data! :-(  (%s)\n", SWBerr.get_error().c_str()); | ||||||
|  |           #endif | ||||||
|  |           return 0;//no more input possible! Fail immediately.
 | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |     //send ACK if we received a whole window
 | ||||||
|  |     if (rec_cnt - rec_window_at > rec_window_size){ | ||||||
|  |       rec_window_at = rec_cnt; | ||||||
|  |       SendCTL(3, rec_cnt);//send ack (msg 3)
 | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|   #ifdef DEBUG |   #ifdef DEBUG | ||||||
|   fprintf(stderr, "User disconnected.\n"); |   fprintf(stderr, "User disconnected.\n"); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Thulinma
						Thulinma