Skip to content

Rtp-stream的两个问题 #316

Description

@Canees
  1. Pipeline error: FFmpegError: Failed to configure filter graph: Function not implemented
    出现这个错误是因为源码使用了-1,在硬编码中-1是不可用
       old:
          const targetWidth = this.options.video.width ?? -1;
          const targetHeight = this.options.video.height ?? -1;
        
       new:
            // 在RKMPP 硬件缩放器(scale_rkrga)期望使用 drm_prime 硬件帧,因此需要转换一下
            if (needsScale && this.hardwareContext?.deviceType === AV_HWDEVICE_TYPE_RKMPP) {
              filterChain.custom('hwupload');
            }
          const targetWidth = this.options.video.width ?? currentWidth;
          const targetHeight = this.options.video.height ?? currentHeight;
    
  2. 在rtp-stream.ts 中使用RtpPacket.deSerialize 会增加性能开销
       old:
           import { isRtcp, RtpPacket } from 'werift';
       new:
            // 直接修改 buffer 的固定头字段,避免完整反序列化/序列化
            // RTP 固定头: 字节 2-3 = seqnum (uint16 BE), 字节 4-7 = timestamp (uint32 BE)
            buffer.writeUInt16BE(sequenceNumber, 2);          // ②③ 替换序列号并递增
            sequenceNumber = (sequenceNumber + 1) & 0xffff;
            timestampOffset ??= (timestampBase - buffer.readUInt32BE(4)) >>> 0; // ④ 首次计算偏移
            buffer.writeUInt32BE((buffer.readUInt32BE(4) + timestampOffset) >>> 0, 4); // ⑤ 应用偏移
    
  3. 移除werift库,只提供rtp的出口即可(方便使用其他高性能库,werift库也优秀)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions