Right now if replica receives current frame and then deactivated before
replicator is advanced to next frame, logic which deceides when to
advance to the next frame gets broken (assertion on StreamReplicator.cpp:265
triggers and frame advances early).
This patch fixes this by decrementing fNumDeliveriesMadeSoFar when
deactivating replicas that received current frame (and hence
fNumDeliveriesMadeSoFar
was incremented because of that). This also eliminates need in
fDeliveryInProgress.
---
liveMedia/StreamReplicator.cpp | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
--
Stas Tsymbalov
TrueConf LLC
http://trueconf.com/
diff --git a/liveMedia/StreamReplicator.cpp b/liveMedia/StreamReplicator.cpp
index bbd569a..de7c79c 100644
--- a/liveMedia/StreamReplicator.cpp
+++ b/liveMedia/StreamReplicator.cpp
@@ -38,7 +38,6 @@ private:
private:
StreamReplicator& fOurReplicator;
int fFrameIndex; // 0 or 1, depending upon which frame we're currently requesting; could also be -1 if we've stopped playing
- Boolean fDeliveryInProgress;
// Replicas that are currently awaiting data are kept in a (singly-linked) list:
StreamReplica* fNext;
@@ -106,10 +105,19 @@ void StreamReplicator::getNextFrame(StreamReplica* replica) {
void StreamReplicator::deactivateStreamReplica(StreamReplica* replicaBeingDeactivated) {
// Assert: fNumActiveReplicas > 0
if (fNumReplicas == 0) fprintf(stderr, "StreamReplicator::deactivateStreamReplica() Internal Error!\n"); // should not happen
+
+ // Do not deactivate inactive replicas
+ if (replicaBeingDeactivated->fFrameIndex == -1)
+ return;
--fNumActiveReplicas;
- if (replicaBeingDeactivated->fDeliveryInProgress) --fNumDeliveriesMadeSoFar;
- // hack in case we're called while in the middle of a frame delivery to us
+ // Check if replica has received current frame, if so we should 'forget' about delivery made to it.
+ // Because recently activated replicas get same frame index as replicator, and after delivering to
+ // master replica all frame indices are guarantied to be the same this condition if sufficient.
+ if (replicaBeingDeactivated->fFrameIndex != fFrameIndex)
+ --fNumDeliveriesMadeSoFar;
+
+ replicaBeingDeactivated->fFrameIndex = -1;
// Check whether the replica being deactivated is the 'master' replica, or is enqueued awaiting a frame:
if (replicaBeingDeactivated == fMasterReplica) {
@@ -183,10 +191,7 @@ void StreamReplicator::deactivateStreamReplica(StreamReplica* replicaBeingDeacti
}
void StreamReplicator::removeStreamReplica(StreamReplica* replicaBeingRemoved) {
- // Handle the replica that's being removed the same way that we would if it were merely being deactivated:
- if (replicaBeingRemoved->fFrameIndex != -1) { // i.e., we haven't already done this
- deactivateStreamReplica(replicaBeingRemoved);
- }
+ deactivateStreamReplica(replicaBeingRemoved);
// Assert: fNumReplicas > 0
if (fNumReplicas == 0) fprintf(stderr, "StreamReplicator::removeStreamReplica() Internal Error!\n"); // should not happen
@@ -250,8 +255,6 @@ void StreamReplicator::deliverReceivedFrame() {
fReplicasAwaitingCurrentFrame = replica->fNext;
replica->fNext = NULL;
- replica->fDeliveryInProgress = True;
-
// Assert: fMasterReplica != NULL
if (fMasterReplica == NULL) fprintf(stderr, "StreamReplicator::deliverReceivedFrame() Internal Error 1!\n"); // shouldn't happen
StreamReplica::copyReceivedFrame(replica, fMasterReplica);
@@ -263,8 +266,6 @@ void StreamReplicator::deliverReceivedFrame() {
// Complete delivery to this replica:
FramedSource::afterGetting(replica);
-
- replica->fDeliveryInProgress = False;
}
if (fNumDeliveriesMadeSoFar == fNumActiveReplicas - 1 && fMasterReplica != NULL) {
@@ -302,7 +303,7 @@ void StreamReplicator::deliverReceivedFrame() {
StreamReplica::StreamReplica(StreamReplicator& ourReplicator)
: FramedSource(ourReplicator.envir()),
fOurReplicator(ourReplicator),
- fFrameIndex(-1/*we haven't started playing yet*/), fDeliveryInProgress(False), fNext(NULL) {
+ fFrameIndex(-1/*we haven't started playing yet*/), fNext(NULL) {
}
StreamReplica::~StreamReplica() {
@@ -314,10 +315,7 @@ void StreamReplica::doGetNextFrame() {
}
void StreamReplica::doStopGettingFrames() {
- if (fFrameIndex != -1) { // we had been activated
- fFrameIndex = -1; // When we start reading again, this will tell the replicator that we were previously inactive.
- fOurReplicator.deactivateStreamReplica(this);
- }
+ fOurReplicator.deactivateStreamReplica(this);
}
void StreamReplica::copyReceivedFrame(StreamReplica* toReplica, StreamReplica* fromReplica) {
_______________________________________________
live-devel mailing list
[email protected]
http://lists.live555.com/mailman/listinfo/live-devel