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

Internal bug, should not have happened 在同时编码与解码的时候 #45

Closed
Coloryr opened this issue Mar 25, 2024 · 3 comments
Closed
Labels
question Further information is requested

Comments

@Coloryr
Copy link

Coloryr commented Mar 25, 2024

System.ApplicationException: Internal bug, should not have happened
   at IPHost.Desktop.FFmpegHelper.ThrowExceptionIfError(Int32 error) in E:\code\IPHost\IPHost.Desktop\FFmpegHelper.cs:line 76
   at IPHost.Desktop.VideoDecoder.<.ctor>b__28_0() in E:\code\IPHost\IPHost.Desktop\VideoDecoder.cs:line 192
Aborted
if (packs.TryDequeue(out var packet))
{
    var data = (byte*)ffmpeg.av_malloc((ulong)packet.Size);
    Marshal.Copy(packet.Data, 0, (IntPtr)data, packet.Size);

    ffmpeg.av_packet_from_data(_pPacket, data, packet.Size)
        .ThrowExceptionIfError();

    ffmpeg.avcodec_send_packet(_videoCodecContext, _pPacket)
        .ThrowExceptionIfError();

    //ffmpeg.av_packet_unref(_pPacket);
    ffmpeg.av_free(data);

    error = ffmpeg.avcodec_receive_frame(_videoCodecContext, _videoFrame);
    if (error == 0)
    {
        AVFrame frame = *_videoFrame;

        if (_videoCodecContext->hw_device_ctx != null)
        {
            ffmpeg.av_hwframe_transfer_data(_receivedFrame, _videoFrame, 0)
                .ThrowExceptionIfError();
            frame = *_receivedFrame;
            if (first_frame)
            {
                first_frame = false;
            }
        }

        if (vfc == null)
        {
            var sourceSize = FrameSize;
            var sourcePixelFormat = HWDeviceType == AVHWDeviceType.AV_HWDEVICE_TYPE_NONE
            ? _videoCodecContext->pix_fmt
                     : DecodeHelper.GetHWPixelFormat(HWDeviceType);
            var destinationSize = sourceSize;
            var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGRA;
            vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat);
        }

        var convertedFrame = vfc.Convert(frame);
        IPHostApi.SetVideoPtr(_uuid, convertedFrame.width, convertedFrame.height, (IntPtr)convertedFrame.data[0]);

        start_time = ffmpeg.av_gettime() - ffmpeg.av_rescale_q(_videoFrame->pts, TimeBase, ffmpeg.av_make_q(1, ffmpeg.AV_TIME_BASE));
    }
    else if (error != -11)
    {
        error.ThrowExceptionIfError();
    }
}
else
{
    Thread.Sleep(1);
}
@Coloryr
Copy link
Author

Coloryr commented Mar 25, 2024

如果只是单一编码或者解码没这个问题,而且这个问题是概率发生
问题发生在avcodec_receive_frame

@nyanmisaka
Copy link
Owner

Not reproducible via FFmpeg CLI transcoding. More information is needed to locate which line in FFmpeg is throwing this error AVERROR_BUG. There's indeed one in rkmppdec.c but it is used as an assertion.

@nyanmisaka nyanmisaka added the question Further information is requested label Mar 25, 2024
@nyanmisaka
Copy link
Owner

The problem cannot be reproduced through the CLI. My guess is that in the downstream application, the encoder takes up too many slots in the decoder buffer pool and the decoder is stuck.

@nyanmisaka nyanmisaka closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants