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

ClosedWriteChannelException: The channel was closed #1601

Open
noho501 opened this issue Oct 12, 2024 · 24 comments
Open

ClosedWriteChannelException: The channel was closed #1601

noho501 opened this issue Oct 12, 2024 · 24 comments
Assignees
Labels

Comments

@noho501
Copy link

noho501 commented Oct 12, 2024

Hi @pedroSG94 ,

We are encountering an issue during screen broadcasting on Facebook, where an error appears after about a minute. This problem only occurs on Facebook; streaming to YouTube works fine. This error didn’t appear before, but it has started showing up recently, possibly after a recent update.

Branch: Master
Screen broadcast settings: 720x1280, 30fps, bitrate: 500*1000
Platform: Facebook

I’ve attached the full log. Could you please provide any suggestions to help resolve this issue?
OPPO-CPH2473-Android-14_2024-10-12_093032.txt.txt

@pedroSG94
Copy link
Owner

pedroSG94 commented Oct 12, 2024

Hello,

According with the logs, the videoinfo is setted multiple times doing that video packet is reset and maybe produce this error. To avoid it I did a fix for it:
#1602

  implementation 'com.github.pedroSG94.RootEncoder:library:c62693873d'

@pedroSG94
Copy link
Owner

I was able to reproduce the error. I'm working on it

@pedroSG94 pedroSG94 self-assigned this Oct 13, 2024
@pedroSG94 pedroSG94 added the bug label Oct 13, 2024
@noho501
Copy link
Author

noho501 commented Oct 13, 2024

Thank you so much. I am looking forward to your good news.

@pedroSG94
Copy link
Owner

For now, I detected that this is a bug in Ktor library because using java.io socket it is working fine.

@pedroSG94
Copy link
Owner

Fixed here:
546ef08

The problem was related with the soTimeout using a tls socket. I think it is a bug in the ktor library but I was able to solve it using withtimeout in read/write methods manually

@noho501
Copy link
Author

noho501 commented Oct 13, 2024

Thank you so much, I will test it and let you know

@noho501
Copy link
Author

noho501 commented Oct 14, 2024

Thank you for the fix. However, another issue still seems unresolved. I am trying to stream using the local file I attached, but after a second, it stops. Please check the log.

Log:
OPPO-CPH2473-Android-14_2024-10-14_151002.txt

The video used for streaming:
https://drive.google.com/file/d/1ncjueHqJ8mIUdl7vSlsQ_7moYSP79mw8/view?usp=sharing

Thanks.

@pedroSG94
Copy link
Owner

Hello,

I don't understand that logs. It is a json
About the error, are you able to reproduce it using other device?

@noho501
Copy link
Author

noho501 commented Oct 14, 2024

Hi,

Please see the new attached log. Yes, I can reproduce the issue on other devices (Android 12 & 14). It's the same error with this video (some videos still work): Video link.

OPPO-CPH2473-Android-14_2024-10-14_1545.txt

@pedroSG94
Copy link
Owner

Ok, I was able to reproduce the error.

The audio is working but the video decoder stopped

@pedroSG94
Copy link
Owner

Hello,

I was debugging the error with that file and seems that MediaExtractor class of Android is not working properly with that file. Only can extract 3 video frames producing that the video freeze.

For now, I'm looking an alternative to MediaExtractor or a way to fix it.

@noho501
Copy link
Author

noho501 commented Oct 14, 2024

Thank you for your confirmation. I am looking forward to your good news.

@pedroSG94
Copy link
Owner

pedroSG94 commented Oct 17, 2024

After multiple tests I can confirm that it is not a bug in the library code, it is a bug in the MediaExtractor class. MediaExtractor is not able to extract video frames from that video for some reason (audio is working). If you re encode the video using ffmpeg it is wofking fine so it is not a problem in the video config.

The only solution will be implement a new extractor without MediaExtractor class but the only viable alternative is use the extractor of ExoPlayer project. The problem is that ExoPlayer need min API version 19 but this project have min API version 16 so I have plan to do a full refactor to decoders that will allow change the extractor allowing set a extractor based on ExoPlayer and add that extractor to extra-sources module which use min API 21.

I will do this new feature for version 2.5.3 because this is a big change and I want avoid change more code in this version.

@pedroSG94
Copy link
Owner

Other alternative is use MediaPlayer class to get video frames and MediaExtractor for audio but I'm not sure if this solution is a good idea.

What do you think about it?. I tested this but it produce others limitations

@noho501
Copy link
Author

noho501 commented Oct 18, 2024

Thank you for confirming. I also believe that using ExoPlayer is the best solution. I will wait for version 2.5.3 and test it once it's available.

@noho501
Copy link
Author

noho501 commented Oct 30, 2024

Hi @pedroSG94 ,

After updating to version 2.5.4, the problem persists, and there are additional issues. The audio is distorted and plays slowly.

Here is the link to the video I streamed: YouTube Live Video.

Here is the original video: Original Video.

Additionally, this video cannot be streamed; it says it is not supported:

Best regards,

@pedroSG94
Copy link
Owner

pedroSG94 commented Oct 30, 2024

Hello,

Thank you for the report. I will check it.

I'm developing an Extractor using Exoplayer extractor instead of MediaExtractor from Android but it is not ready yet so all should be working like in the version 2.5.2 (the video that freeze is not working yet video2)

I will check the new issues maybe related with the new decoder implementation and fix it. For now, use version 2.5.2

@pedroSG94
Copy link
Owner

pedroSG94 commented Oct 31, 2024

Hello,

I checked the first file but the error related with slowly audio is present in previous versions before the change so It is not a problem only in the last version but maybe it is fixeable (still checking it).

About the not supported error, it is because I added an additional check in the decoder that force the video used to have duration that I think is the problem because the video is freeze. If the duration can't be extracted, the video extraction fail in prepareVideo before start decoding to avoid reproduce video that will be invalid and freeze.

I will check the first video but the second and third video should be fixed using the new extractor instead the current extractor. I think that report a fail is better than let the user reproduce it and produce a freeze.

@pedroSG94
Copy link
Owner

I discovered the reason about the first video fail.

When you extract audio info from the first video using MediaExtractor or even with MediaMetadataRetriever the samplerate is 24000 but the real samplerate is 48000. This produce the slowly audio effect because the encoder is configured based on the decoder extracted value. If you hardcode the samplerate value all is working fine.

This seem that it is not a problem in the decoder code but more a problem in MediaExtractor class of Android. I'm looking if I can find a way to fix it

@pedroSG94
Copy link
Owner

I added a commit that implement a Media3Extractor using the exoplayer project dependency that improve a bit this problem but still produce problems:
dcf669a

@noho501
Copy link
Author

noho501 commented Nov 1, 2024

Thank you! I’ll test it and report back to you.

@pedroSG94
Copy link
Owner

This new Extractor solve the problem with the first file but still have few problems using the second and third file (mostly with the second file).
Remember that you need change the extractor for video or audio using:

    genericFromFile.setAudioExtractor(Media3Extractor(this))
    genericFromFile.setVideoExtractor(Media3Extractor(this))

@noho501
Copy link
Author

noho501 commented Nov 5, 2024

Hi @pedroSG94,

I am using the following dependencies:

implementation 'com.github.pedroSG94.RootEncoder:library:2.5.4'
implementation ('com.github.pedroSG94.RootEncoder:extra-sources:2.5.4') {
    exclude module: 'UVCAndroid'
}

When I implement version 2.5.4 and try to import import com.pedro.extrasources.extractor.Media3Extractor, I receive the error: Unresolved reference: extractor.

Do you know how to resolve this issue?

Thank you!

@pedroSG94
Copy link
Owner

pedroSG94 commented Nov 5, 2024

Hello,

It isn't in the last release. Use this for now:

  implementation 'com.github.pedroSG94.RootEncoder:library:73b7c9d43e'
  implementation 'com.github.pedroSG94.RootEncoder:extra-sources:73b7c9d43e'

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

No branches or pull requests

2 participants