Code Monkey home page Code Monkey logo

Comments (7)

melchor629 avatar melchor629 commented on June 2, 2024

Hi, thanks for raising the issue. Let's see...

When you use one of StreamEncoder, FileEncoder, StreamDecoder or FileDecoder, the encoder/decoder is initialised when the first write/read is requested from the stream (they are all node.js streams). Talking about StreamEncoder, the encoder is initialised inside the _transform method:

res = await this._enc.initStreamAsync(this._writeFlac.bind(this), null, null, null);

It is done before doing any encoder call, and according to node.js documentation, the stream is paused until I call callback (which is done when something fails, or after sending the data to be processed by flac). So, theorically only one _transform method is running at the same time.

Well there is also the _flush method, that is called by node when you (for example) call flacEncoder.end(). This method, according to the docs, is called when there is no more data to read (so after _transform has been called and all their callbacks called back). In the _flush method is where the encoder is de-initialised, but because the stream is being closed, it should not be a problem.

With that facts, you got the Encoder has not been initialised yet error for some reason I cannot imagine currently. So if you are able to provide some stack traces or logs, would be helpful.

Something I never had is some debug logs for the library, so maybe today is a good day to add them to track this kind of weird issues (I will provide more information when I have this done).

Once again, thanks, and glad to hear you like the project :)

from node-flac-bindings.

jbaudanza avatar jbaudanza commented on June 2, 2024

Ah ok. I think I see what's happening. My client is closing the connection before sending any PCM data, so _write is never being called. It looks like this:

  1. Client opens connection
    StreamEncoder() is created
    stream is passed to S3 Uploader to start streaming to S3. (not sure if this is relevant)
  2. Client immediately closes connection without sending audio data
    flacEncoder.end() raises 'Encoder has not been initialized yet' error.

Thank you for your help!

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 2, 2024

Mmmm that makes a lot of sense in fact! That's a good point.

I will create a fix for this, so if for some reason, the user does not provide any data (like in your case), send an empty flac file or something like this.

from node-flac-bindings.

jbaudanza avatar jbaudanza commented on June 2, 2024

Yeah, I actually think you could argue this is not a bug. I can see two possible "fixes" in this case:

  • Encoder's readable stream never emits any data.
  • Encoder throws an error on end, but it says something more descriptive like, "Encoder never received any data to encode".

I think both behaviors would be reasonable.

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 2, 2024

Finally implemented the "no data emitted" fix for this ce03102. Also added tests to cover this scenarios for StreamEncoder, FileEncoder and StreamDecoder (did not see any way to replicate this in FileDecoder).

Should not error anymore when calling .end() without writing anything to the stream :)

Thanks for everything, really helped to improve the library. Closing the issue for now. If you see the same error after the release, feel free to reopen it. I will publish a new version later this weekend.

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 2, 2024

Hi again, I published a new version of the package 2.5.0 with this fix. Just to let you know :)

from node-flac-bindings.

jbaudanza avatar jbaudanza commented on June 2, 2024

Thank you so much. I will deploy it and let you know if I encounter and more issues

from node-flac-bindings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.