Changeset 255564 in webkit


Ignore:
Timestamp:
Feb 3, 2020 8:38:29 AM (4 years ago)
Author:
youenn@apple.com
Message:

Make sure RTCVideoEncoderH264 generate a keyframe even if the frame that was supposed to be a key frame was dropped
https://bugs.webkit.org/show_bug.cgi?id=207108

Reviewed by Eric Carlson.

Add a parameter telling whether a frame to be encoded should be a key frame.
In encoder callback, if the frame is expected to be a key frame, set a flag to force the next frame to be a key frame.
This ensures that keyframe sending is not delayed in case encoding is dropping or failing to encode frames.

  • Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm:

(-[RTCVideoEncoderH264 initWithCodecInfo:]):
(-[RTCVideoEncoderH264 encode:codecSpecificInfo:frameTypes:]):
(-[RTCVideoEncoderH264 frameWasEncoded:flags:sampleBuffer:codecSpecificInfo:width:height:renderTimeMs:timestamp:rotation:isKeyFrameRequired:]):

Location:
trunk/Source/ThirdParty/libwebrtc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/ThirdParty/libwebrtc/ChangeLog

    r254815 r255564  
     12020-02-03  youenn fablet  <youenn@apple.com>
     2
     3        Make sure RTCVideoEncoderH264 generate a keyframe even if the frame that was supposed to be a key frame was dropped
     4        https://bugs.webkit.org/show_bug.cgi?id=207108
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add a parameter telling whether a frame to be encoded should be a key frame.
     9        In encoder callback, if the frame is expected to be a key frame, set a flag to force the next frame to be a key frame.
     10        This ensures that keyframe sending is not delayed in case encoding is dropping or failing to encode frames.
     11
     12        * Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm:
     13        (-[RTCVideoEncoderH264 initWithCodecInfo:]):
     14        (-[RTCVideoEncoderH264 encode:codecSpecificInfo:frameTypes:]):
     15        (-[RTCVideoEncoderH264 frameWasEncoded:flags:sampleBuffer:codecSpecificInfo:width:height:renderTimeMs:timestamp:rotation:isKeyFrameRequired:]):
     16
    1172020-01-20  youenn fablet  <youenn@apple.com>
    218
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm

    r252472 r255564  
    8787           renderTimeMs:(int64_t)renderTimeMs
    8888              timestamp:(uint32_t)timestamp
    89                rotation:(RTCVideoRotation)rotation;
     89               rotation:(RTCVideoRotation)rotation
     90     isKeyFrameRequired:(bool)isKeyFrameRequired;
    9091
    9192@end
     
    113114                       int64_t rtms,
    114115                       uint32_t ts,
    115                        RTCVideoRotation r)
    116       : encoder(e), width(w), height(h), render_time_ms(rtms), timestamp(ts), rotation(r) {
     116                       RTCVideoRotation r,
     117                       bool isKeyFrameRequired)
     118      : encoder(e), width(w), height(h), render_time_ms(rtms), timestamp(ts), rotation(r), isKeyFrameRequired(isKeyFrameRequired) {
    117119    if (csi) {
    118120      codecSpecificInfo = csi;
     
    129131  uint32_t timestamp;
    130132  RTCVideoRotation rotation;
     133  bool isKeyFrameRequired;
    131134};
    132135
     
    207210                            renderTimeMs:encodeParams->render_time_ms
    208211                               timestamp:encodeParams->timestamp
    209                                 rotation:encodeParams->rotation];
     212                                rotation:encodeParams->rotation
     213                      isKeyFrameRequired:encodeParams->isKeyFrameRequired];
    210214}
    211215
     
    371375  std::vector<uint8_t> _frameScaleBuffer;
    372376  bool _disableEncoding;
     377  bool _isKeyFrameRequired;
    373378}
    374379
     
    401406    RTC_CHECK([codecInfo.name isEqualToString:kRTCVideoCodecH264Name]);
    402407  }
     408  _isKeyFrameRequired = false;
     409
    403410  return self;
    404411}
     
    451458    return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
    452459  }
    453   BOOL isKeyframeRequired = NO;
     460  BOOL isKeyframeRequired = _isKeyFrameRequired;
     461  _isKeyFrameRequired = false;
    454462
    455463  // Get a pixel buffer from the pool and copy frame data over.
     
    514522    for (NSNumber *frameType in frameTypes) {
    515523      if ((RTCFrameType)frameType.intValue == RTCFrameTypeVideoFrameKey) {
     524        RTC_LOG(LS_INFO) << "keyframe requested";
    516525        isKeyframeRequired = YES;
    517526        break;
     
    535544                                              frame.timeStampNs / rtc::kNumNanosecsPerMillisec,
    536545                                              frame.timeStamp,
    537                                               frame.rotation));
     546                                              frame.rotation,
     547                                              isKeyframeRequired));
    538548  encodeParams->codecSpecificInfo.packetizationMode = _packetizationMode;
    539549
     
    948958           renderTimeMs:(int64_t)renderTimeMs
    949959              timestamp:(uint32_t)timestamp
    950                rotation:(RTCVideoRotation)rotation {
     960               rotation:(RTCVideoRotation)rotation
     961     isKeyFrameRequired:(bool)isKeyFrameRequired {
    951962  if (status != noErr) {
    952963    RTC_LOG(LS_ERROR) << "H264 encode failed with code: " << status;
     964    if (isKeyFrameRequired)
     965      _isKeyFrameRequired = true;
    953966    return;
    954967  }
    955968  if (infoFlags & kVTEncodeInfo_FrameDropped) {
     969    if (isKeyFrameRequired)
     970      _isKeyFrameRequired = true;
    956971    RTC_LOG(LS_INFO) << "H264 encode dropped frame.";
    957972    return;
    958973  }
     974  _isKeyFrameRequired = false;
    959975
    960976  BOOL isKeyframe = NO;
     
    10051021  if (!res) {
    10061022    RTC_LOG(LS_ERROR) << "Encode callback failed";
     1023    if (isKeyFrameRequired)
     1024      _isKeyFrameRequired = true;
    10071025    return;
    10081026  }
Note: See TracChangeset for help on using the changeset viewer.