Tweaked buffer/player timings to prevent delays, almost-working smooth support.
This commit is contained in:
		
							parent
							
								
									4d3a500e66
								
							
						
					
					
						commit
						25c7f6f93d
					
				
					 3 changed files with 45 additions and 7 deletions
				
			
		|  | @ -212,7 +212,10 @@ namespace Buffer { | ||||||
|     } |     } | ||||||
|     while (buffer_running){ |     while (buffer_running){ | ||||||
|       if (thisStream->getIPInput().connected()){ |       if (thisStream->getIPInput().connected()){ | ||||||
|         connected = true; |         if (!connected){ | ||||||
|  |           connected = true; | ||||||
|  |           thisStream->getIPInput().setBlocking(false); | ||||||
|  |         } | ||||||
|         if (thisStream->getIPInput().spool()){ |         if (thisStream->getIPInput().spool()){ | ||||||
|           while (true){ |           while (true){ | ||||||
|             thisStream->getWriteLock(); |             thisStream->getWriteLock(); | ||||||
|  | @ -225,12 +228,12 @@ namespace Buffer { | ||||||
|               thisStream->dropWriteLock(true); |               thisStream->dropWriteLock(true); | ||||||
|             }else{ |             }else{ | ||||||
|               thisStream->dropWriteLock(false); |               thisStream->dropWriteLock(false); | ||||||
|               Util::sleep(25); //10ms wait
 |               //Util::sleep(10); //10ms wait
 | ||||||
|               break; |               break; | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|         }else{ |         //}else{
 | ||||||
|           Util::sleep(1000); //10ms wait
 |           //Util::sleep(500); //500ms wait
 | ||||||
|         } |         } | ||||||
|       }else{ |       }else{ | ||||||
|         if (connected){ |         if (connected){ | ||||||
|  |  | ||||||
|  | @ -239,8 +239,8 @@ int main(int argc, char** argv){ | ||||||
|       if (lastTime == 0){ |       if (lastTime == 0){ | ||||||
|         lastTime = now - source.getJSON()["time"].asInt(); |         lastTime = now - source.getJSON()["time"].asInt(); | ||||||
|       } |       } | ||||||
|       if (playing == -1 && playUntil == 0 && source.getJSON()["time"].asInt() > now - lastTime + 1000){ |       if (playing == -1 && playUntil == 0 && source.getJSON()["time"].asInt() > now - lastTime + 7500){ | ||||||
|         Util::sleep(source.getJSON()["time"].asInt() - (now - lastTime)); |         Util::sleep(source.getJSON()["time"].asInt() - (now - lastTime + 5000)); | ||||||
|       } |       } | ||||||
|       if ( playUntil && playUntil < source.getJSON()["time"].asInt()){ |       if ( playUntil && playUntil < source.getJSON()["time"].asInt()){ | ||||||
|         playing = 0; |         playing = 0; | ||||||
|  |  | ||||||
|  | @ -296,8 +296,43 @@ namespace Connector_HTTP { | ||||||
|                 } |                 } | ||||||
|               } |               } | ||||||
|             } |             } | ||||||
|  |              | ||||||
|  |             long long mstime = 0; | ||||||
|  |             long long mslen = 0; | ||||||
|  |             if (myRef.isMember("keys")){ | ||||||
|  |               for (JSON::ArrIter it = myRef["keys"].ArrBegin(); it != myRef["keys"].ArrEnd(); it++){ | ||||||
|  |                 if ((*it)["time"].asInt() >= (requestedTime / 10000)){ | ||||||
|  |                   mstime = (*it)["time"].asInt(); | ||||||
|  |                   mslen = (*it)["len"].asInt(); | ||||||
|  |                   if (Strm.metadata.isMember("live")){ | ||||||
|  |                     if (it == myRef["keys"].ArrEnd() - 2){ | ||||||
|  |                       HTTP_S.Clean(); | ||||||
|  |                       HTTP_S.SetBody("Proxy, re-request this in a second or two.\n"); | ||||||
|  |                       conn.SendNow(HTTP_S.BuildResponse("208", "Ask again later")); | ||||||
|  |                       HTTP_R.Clean(); //clean for any possible next requests
 | ||||||
|  |                       std::cout << "Fragment after fragment @ " << (requestedTime / 10000) << " not available yet" << std::endl; | ||||||
|  |                     } | ||||||
|  |                   } | ||||||
|  |                   break; | ||||||
|  |                 } | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  |             if (HTTP_R.url == "/"){continue;}//Don't continue, but continue instead.
 | ||||||
|  |             if (Strm.metadata.isMember("live")){ | ||||||
|  |               if (mstime == 0 && (requestedTime / 10000) > 1){ | ||||||
|  |                 HTTP_S.Clean(); | ||||||
|  |                 HTTP_S.SetBody("The requested fragment is no longer kept in memory on the server and cannot be served.\n"); | ||||||
|  |                 conn.SendNow(HTTP_S.BuildResponse("412", "Fragment out of range")); | ||||||
|  |                 HTTP_R.Clean(); //clean for any possible next requests
 | ||||||
|  |                 std::cout << "Fragment @ " << (requestedTime / 10000) << " too old" << std::endl; | ||||||
|  |                 continue; | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  |              | ||||||
|  |              | ||||||
|             sstream << "t " << myRef["trackid"].asInt() << "\n"; |             sstream << "t " << myRef["trackid"].asInt() << "\n"; | ||||||
|             sstream << "s " << (requestedTime / 10000) << "\no \n"; |             sstream << "s " << (requestedTime / 10000) << "\np " << (mstime + mslen) <<"\n"; | ||||||
|  |             std::cout << "Sending: " << sstream.str() << std::endl; | ||||||
|             ss.SendNow(sstream.str().c_str()); |             ss.SendNow(sstream.str().c_str()); | ||||||
| 
 | 
 | ||||||
|             HTTP_S.Clean(); |             HTTP_S.Clean(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Thulinma
						Thulinma