From 488eb98616b41d85b03a96fa5b4a0ed12b944c69 Mon Sep 17 00:00:00 2001 From: Peter Hanspers Date: Fri, 8 Jun 2018 14:49:51 +0200 Subject: [PATCH] Setting resolution alignment to 4 on iOS. Bug: webrtc:9381 Change-Id: I6fb6cc6ffa197ca581462e308a857ac38e10b9a1 Reviewed-on: https://webrtc-review.googlesource.com/82162 Reviewed-by: Anders Carlsson Commit-Queue: Peter Hanspers Cr-Commit-Position: refs/heads/master@{#23553} --- .../Native/src/objc_video_track_source.mm | 3 +- .../UnitTests/ObjCVideoTrackSource_xctest.mm | 45 +++++++++++++++---- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/sdk/objc/Framework/Native/src/objc_video_track_source.mm b/sdk/objc/Framework/Native/src/objc_video_track_source.mm index d3942dfd39..b430efa763 100644 --- a/sdk/objc/Framework/Native/src/objc_video_track_source.mm +++ b/sdk/objc/Framework/Native/src/objc_video_track_source.mm @@ -32,7 +32,8 @@ namespace webrtc { -ObjCVideoTrackSource::ObjCVideoTrackSource() {} +ObjCVideoTrackSource::ObjCVideoTrackSource() : + AdaptedVideoTrackSource(/* required resolution alignment */ 4) {} ObjCVideoTrackSource::ObjCVideoTrackSource(RTCObjCVideoSourceAdapter *adapter) : adapter_(adapter) { adapter_.objCVideoTrackSource = this; diff --git a/sdk/objc/Framework/UnitTests/ObjCVideoTrackSource_xctest.mm b/sdk/objc/Framework/UnitTests/ObjCVideoTrackSource_xctest.mm index d2ed398525..7d111c8b12 100644 --- a/sdk/objc/Framework/UnitTests/ObjCVideoTrackSource_xctest.mm +++ b/sdk/objc/Framework/UnitTests/ObjCVideoTrackSource_xctest.mm @@ -81,6 +81,35 @@ class ObjCCallbackVideoSink : public rtc::VideoSinkInterface CVBufferRelease(pixelBufferRef); } +- (void)testOnCapturedFrameAdaptsFrameWithAlignment { + // Requesting to adapt 1280x720 to 912x514 gives 639x360 without alignment. The 639 causes issues + // with some hardware encoders (e.g. HEVC) so in this test we verify that the alignment is set and + // respected. + + CVPixelBufferRef pixelBufferRef = NULL; + CVPixelBufferCreate( + NULL, 720, 1280, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, NULL, &pixelBufferRef); + + RTCCVPixelBuffer *buffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBufferRef]; + + RTCVideoFrame *frame = + [[RTCVideoFrame alloc] initWithBuffer:buffer rotation:RTCVideoRotation_0 timeStampNs:0]; + + cricket::FakeVideoRenderer *video_renderer = new cricket::FakeVideoRenderer(); + const rtc::VideoSinkWants video_sink_wants; + rtc::VideoSourceInterface *video_source_interface = _video_source; + video_source_interface->AddOrUpdateSink(video_renderer, video_sink_wants); + + _video_source->OnOutputFormatRequest(912, 514, 30); + _video_source->OnCapturedFrame(frame); + + XCTAssertEqual(video_renderer->num_rendered_frames(), 1); + XCTAssertEqual(video_renderer->width(), 360); + XCTAssertEqual(video_renderer->height(), 640); + + CVBufferRelease(pixelBufferRef); +} + - (void)testOnCapturedFrameWithoutAdaptation { CVPixelBufferRef pixelBufferRef = NULL; CVPixelBufferCreate( @@ -197,14 +226,14 @@ class ObjCCallbackVideoSink : public rtc::VideoSinkInterface XCTestExpectation *callbackExpectation = [self expectationWithDescription:@"videoSinkCallback"]; ObjCCallbackVideoSink callback_video_sink(^void(RTCVideoFrame *outputFrame) { - XCTAssertEqual(outputFrame.width, 297); - XCTAssertEqual(outputFrame.height, 525); + XCTAssertEqual(outputFrame.width, 300); + XCTAssertEqual(outputFrame.height, 516); RTCCVPixelBuffer *outputBuffer = outputFrame.buffer; - XCTAssertEqual(outputBuffer.cropX, 152); - XCTAssertEqual(outputBuffer.cropY, 0); - XCTAssertEqual(outputBuffer.cropWidth, 396); - XCTAssertEqual(outputBuffer.cropHeight, 700); + XCTAssertEqual(outputBuffer.cropX, 150); + XCTAssertEqual(outputBuffer.cropY, 6); + XCTAssertEqual(outputBuffer.cropWidth, 400); + XCTAssertEqual(outputBuffer.cropHeight, 688); XCTAssertEqual(buffer.pixelBuffer, outputBuffer.pixelBuffer); [callbackExpectation fulfill]; @@ -280,13 +309,13 @@ class ObjCCallbackVideoSink : public rtc::VideoSinkInterface XCTestExpectation *callbackExpectation = [self expectationWithDescription:@"videoSinkCallback"]; ObjCCallbackVideoSink callback_video_sink(^void(RTCVideoFrame *outputFrame) { XCTAssertEqual(outputFrame.width, 300); - XCTAssertEqual(outputFrame.height, 533); + XCTAssertEqual(outputFrame.height, 536); RTCCVPixelBuffer *outputBuffer = outputFrame.buffer; XCTAssertEqual(outputBuffer.cropX, 40); XCTAssertEqual(outputBuffer.cropY, 52); XCTAssertEqual(outputBuffer.cropWidth, 300); - XCTAssertEqual(outputBuffer.cropHeight, 533); + XCTAssertEqual(outputBuffer.cropHeight, 536); XCTAssertEqual(buffer.pixelBuffer, outputBuffer.pixelBuffer); [callbackExpectation fulfill];