Link to home
Start Free TrialLog in
Avatar of bachra04
bachra04Flag for Canada

asked on

buffering algorithm

Hi Experts,
I have been struggling for days now how to solve this problem  and couldn't get it right.
Here is the problem:
I receive startPlay command | stopPlay command from the User Interface layer
every command contains a code so e.g.
at 10.33 I receive startPlay (#1)
after 100 ms I receive stopPlay()
I calculate the duration = diff between start time and stop time and send that to network using some protocol.
Then I receive second command and third command etc...
in order to have those commands working at the network side, the duration should be at least 85 ms and the spacing between command e.g command1 and command2 needs to be 45 ms.
There is some delay at the UI layer ( that I cannot control), so sometimes I receive the start command and stop command too short (less than 85 ms), sometimes the gap between command1 and command 2 is less than 45 sec.
I tried to write a buffering algorithm to solve that delay so I can raise the duration to 85 ms if it is less than that and same for the time between stopping first command and starting  the next one.
As of yet I could n't get it working right and came here to seek your advice how to approach this problem.
I thought about having two queues one for the start command and one for the stop command
and a Timer when it kicks check the first queue and run the command then after some time check the second queue and run the stop command but I'm still not clear how to solve it right.
I'm pretty sure this kind of problems was already solved.
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bachra04

ASKER

Now I just need to code it in C/C++ with pthread.