Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onCluster not triggered upon setting streaming mode to true #50

Open
iLulu1012 opened this issue Oct 30, 2024 · 5 comments
Open

onCluster not triggered upon setting streaming mode to true #50

iLulu1012 opened this issue Oct 30, 2024 · 5 comments

Comments

@iLulu1012
Copy link

Hi, I have been trying to use this package for one of my task. Upon playing with the demo-streaming, I realized the onCluster for the stream target does not trigger with streaming set to true on the muxer. The chunked argument also causes issue with monotonicity violation. Is there any insight to how one might be able to realizes the creation of a cluster if streaming is set to false? without having to care for the position argument as the cluster would be pipe immediately to the server. Thanks!

@Vanilagy
Copy link
Owner

Hi, I cannot reproduce the monotonicity violation issue. I switched to chunked: true in the streaming demo, but it does not raise a monotonicity violation. Can you show me the code that produced one on your end?

Regarding the onCluster callback: Thank you for bringing this to my attention. I'll investigate it when I find the time.

@iLulu1012
Copy link
Author

Hi Vanilagy, I actually couldnt reproduce the monotonicity violation issue anymore. Thanks for the response! But yeah it seems like the onCluster issue still exist?

@Vanilagy
Copy link
Owner

Yes, could be, I haven't looked into it yet.

@essemd
Copy link

essemd commented Jan 15, 2025

I reproduced the monotonicity violation with streaming and chunked set to true, with a chunk size of 1MiB or less. Also, skimming through the code it seems that onCluster is not intended to fire when streaming is set to True:

	/** Creates a new Cluster element to contain media chunks. */
	#createNewCluster(timestamp: number) {
		if (this.#currentCluster && !this.#options.streaming) {
			this.#finalizeCurrentCluster();
		}
                ...
	#finalizeCurrentCluster() {
		let clusterSize = this.#writer.pos - this.#writer.dataOffsets.get(this.#currentCluster);
		let endPos = this.#writer.pos;

		// Write the size now that we know it
		this.#writer.seek(this.#writer.offsets.get(this.#currentCluster) + 4);
		this.#writer.writeEBMLVarInt(clusterSize, CLUSTER_SIZE_BYTES);
		this.#writer.seek(endPos);

		if (this.#writer instanceof BaseStreamTargetWriter && this.#writer.target.options.onCluster) {
			let { data, start } = this.#writer.getTrackedWrites();
			this.#writer.target.options.onCluster(data, start, this.#currentClusterTimestamp);
		}
	}

As you can see above, this.#finalizeCurrentCluster is only called when this.#options.streaming is False. And onCluster is called from inside this.#finalizeCurrentCluster.

@Vanilagy
Copy link
Owner

This could be it, yeah. Thanks for finding this. If you want, you can open a PR with the fix.

The monotonicity violation, however, still needs to be investigated. Can you provide some code that reproduces that bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants