Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Dvb/TSStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class TSStream extends EventEmitter
*/
private $channels;

/**
* @var Exiting
* Indicating exit process started. This process depends on termination delay.
*/
private $exiting = false;
private $exited = false;

/**
Expand Down Expand Up @@ -276,6 +281,7 @@ public function _handleExit()

$this->emit('exit');
$this->removeAllListeners();
$this->exiting = false;
}

/**
Expand Down Expand Up @@ -430,6 +436,15 @@ public function removeClient(WritableStreamInterface $client)
$this->autoKillIfKillable();
}

/**
* Return the exiting status
* @return bool
*/
public function isExiting()
{
return $this->exiting;
}

/**
* Terminate process forcefully
*/
Expand All @@ -438,6 +453,7 @@ public function terminate()
if ($this->exited) {
return;
}
$this->exiting = true;
$this->logger->debug("Terminate process " . $this->process->getCommand());
if (!$this->process->terminate(SIGKILL)) {
throw new \RuntimeException("Unable to signal process");
Expand Down Expand Up @@ -495,4 +511,4 @@ public function releaseEpgGrabbing()
$this->epgGrabbing = false;
$this->autoKillIfKillable();
}
}
}
18 changes: 17 additions & 1 deletion src/Dvb/TSStreamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ public function getTsStream(int $channelServiceId): ExtendedPromiseInterface
});
}
$this->doCreateTsStream($channelDescriptor);
} else {
$curStream = $this->streamsByChannelFrequency[$channelFrequency];
// in the case exit process in ongoing, we need to wait it ends before creating a new TsStream
if ($curStream->isExiting()) {
$this->logger->debug("getTsStream() while isExiting() == true");
$exitPromise = new Promise(function (callable $exitResolver) use ($curStream) {
$curStream->on('exit', function () use ($exitResolver) {
$this->logger->debug("on exit executed");
return $exitResolver();
});
});
return $exitPromise->then(function () use ($resolver, $channelDescriptor, $channelFrequency) {
$this->logger->debug("doCreateTsStream delayed after on exit");
return $resolver($this->doCreateTsStream($channelDescriptor));
});
}
}
return $resolver($this->streamsByChannelFrequency[$channelFrequency]);
});
Expand Down Expand Up @@ -141,4 +157,4 @@ public function terminateTsStream()
}
return null;
}
}
}