V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
befovy
V2EX  ›  Flutter

请教 Flutter ios 外接纹理, copyPixelBuffer 只被调用了一次

  •  
  •   befovy ·
    befovy · Jul 10, 2019 · 11205 views
    This topic created in 2490 days ago, the information mentioned may be changed or developed.

    尝试用 flutter 做一个视频应用,anroid 端成功接入了 surfaceTexture 可以显示视频。

    但是在 iOS 端外接纹理时, 实现 FlutterTexture

    并使用了 FlutterTextureRegistry registerTexture 成功注册。

    但是视频没有显示出来,调试发现 copyPixelBuffer 只被调用了一次,在这一次调用中,由于视频还没有准备好,所以返回了空。

    但是后续 copyPixelBuffer 不被调用了, 是什么原因,有 V 友了解吗? 是否和第一次调用返回 nil 有关系?

    4 replies    2020-02-18 11:16:01 +08:00
    befovy
        1
    befovy  
    OP
       Jul 11, 2019
    我自己来回答一下吧。

    ```objc
    @protocol FlutterTextureRegistry <NSObject>
    - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture;
    - (void)textureFrameAvailable:(int64_t)textureId;
    - (void)unregisterTexture:(int64_t)textureId;
    @end
    ```

    每次有新的图像准备好之后, 调用 `textureFrameAvailable` 告诉 flutter, 应该更新显示了。
    然后 flutter 就会调用 `copyPixelBuffer` 获取 pixelbuffer 并显示。

    另外需要注意 copyPixelBuffer 返回的 pixelbuffer 需要是 BGRA32 格式的才行,这一点文档中也没提到,真是个坑
    zinwalin
        2
    zinwalin  
       Jan 9, 2020
    性能怎样?
    zinwalin
        3
    zinwalin  
       Jan 9, 2020
    有没有 demo 可以分享下, 谢谢。
    befovy
        4
    befovy  
    OP
       Feb 18, 2020
    @zinwalin demo 的话可以看我的项目 befovy/fijkplayer
    播放视频性能可以,但没有做严格的性能对比分析
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2307 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 01:20 · PVG 09:20 · LAX 18:20 · JFK 21:20
    ♥ Do have faith in what you're doing.