OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #import <Foundation/Foundation.h> |
| 12 #import <OCMock/OCMock.h> |
| 13 |
| 14 #include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_fact
ory.h" |
| 15 |
| 16 #import "WebRTC/RTCVideoCodec.h" |
| 17 #import "WebRTC/RTCVideoCodecFactory.h" |
| 18 #include "webrtc/modules/include/module_common_types.h" |
| 19 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 20 #include "webrtc/modules/video_coding/include/video_error_codes.h" |
| 21 #include "webrtc/rtc_base/gunit.h" |
| 22 |
| 23 id<RTCVideoDecoderFactory> CreateDecoderFactoryReturning(int return_code) { |
| 24 id decoderMock = OCMProtocolMock(@protocol(RTCVideoDecoder)); |
| 25 OCMStub([decoderMock startDecodeWithSettings:[OCMArg any] numberOfCores:1]) |
| 26 .andReturn(return_code); |
| 27 OCMStub([decoderMock decode:[OCMArg any] |
| 28 missingFrames:NO |
| 29 fragmentationHeader:[OCMArg any] |
| 30 codecSpecificInfo:[OCMArg any] |
| 31 renderTimeMs:0]) |
| 32 .andReturn(return_code); |
| 33 OCMStub([decoderMock releaseDecoder]).andReturn(return_code); |
| 34 |
| 35 id decoderFactoryMock = OCMProtocolMock(@protocol(RTCVideoDecoderFactory)); |
| 36 RTCVideoCodecInfo *supported = |
| 37 [[RTCVideoCodecInfo alloc] initWithPayload:0 name:@"H264" parameters:@{}]; |
| 38 OCMStub([decoderFactoryMock supportedCodecs]).andReturn(@[ supported ]); |
| 39 OCMStub([decoderFactoryMock createDecoder:[OCMArg any]]).andReturn(decoderMock
); |
| 40 return decoderFactoryMock; |
| 41 } |
| 42 |
| 43 id<RTCVideoDecoderFactory> CreateOKDecoderFactory() { |
| 44 return CreateDecoderFactoryReturning(WEBRTC_VIDEO_CODEC_OK); |
| 45 } |
| 46 |
| 47 id<RTCVideoDecoderFactory> CreateErrorDecoderFactory() { |
| 48 return CreateDecoderFactoryReturning(WEBRTC_VIDEO_CODEC_ERROR); |
| 49 } |
| 50 |
| 51 webrtc::VideoDecoder *GetObjCDecoder(id<RTCVideoDecoderFactory> factory) { |
| 52 webrtc::ObjCVideoDecoderFactory decoder_factory(factory); |
| 53 return decoder_factory.CreateVideoDecoder(webrtc::kVideoCodecH264); |
| 54 } |
| 55 |
| 56 #pragma mark - |
| 57 |
| 58 TEST(ObjCVideoDecoderFactoryTest, InitDecodeReturnsOKOnSuccess) { |
| 59 webrtc::VideoDecoder *decoder = GetObjCDecoder(CreateOKDecoderFactory()); |
| 60 |
| 61 auto settings = new webrtc::VideoCodec(); |
| 62 EXPECT_EQ(decoder->InitDecode(settings, 1), WEBRTC_VIDEO_CODEC_OK); |
| 63 } |
| 64 |
| 65 TEST(ObjCVideoDecoderFactoryTest, InitDecodeReturnsErrorOnFail) { |
| 66 webrtc::VideoDecoder *decoder = GetObjCDecoder(CreateErrorDecoderFactory()); |
| 67 |
| 68 auto settings = new webrtc::VideoCodec(); |
| 69 EXPECT_EQ(decoder->InitDecode(settings, 1), WEBRTC_VIDEO_CODEC_ERROR); |
| 70 } |
| 71 |
| 72 TEST(ObjCVideoDecoderFactoryTest, DecodeReturnsOKOnSuccess) { |
| 73 webrtc::VideoDecoder *decoder = GetObjCDecoder(CreateOKDecoderFactory()); |
| 74 |
| 75 webrtc::EncodedImage encoded_image; |
| 76 webrtc::RTPFragmentationHeader header; |
| 77 webrtc::CodecSpecificInfo info; |
| 78 info.codecType = webrtc::kVideoCodecH264; |
| 79 |
| 80 EXPECT_EQ(decoder->Decode(encoded_image, false, &header, &info, 0), WEBRTC_VID
EO_CODEC_OK); |
| 81 } |
| 82 |
| 83 TEST(ObjCVideoDecoderFactoryTest, DecodeReturnsErrorOnFail) { |
| 84 webrtc::VideoDecoder *decoder = GetObjCDecoder(CreateErrorDecoderFactory()); |
| 85 |
| 86 webrtc::EncodedImage encoded_image; |
| 87 webrtc::RTPFragmentationHeader header; |
| 88 webrtc::CodecSpecificInfo info; |
| 89 info.codecType = webrtc::kVideoCodecH264; |
| 90 |
| 91 EXPECT_EQ(decoder->Decode(encoded_image, false, &header, &info, 0), WEBRTC_VID
EO_CODEC_ERROR); |
| 92 } |
| 93 |
| 94 TEST(ObjCVideoDecoderFactoryTest, ReleaseDecodeReturnsOKOnSuccess) { |
| 95 webrtc::VideoDecoder *decoder = GetObjCDecoder(CreateOKDecoderFactory()); |
| 96 |
| 97 EXPECT_EQ(decoder->Release(), WEBRTC_VIDEO_CODEC_OK); |
| 98 } |
| 99 |
| 100 TEST(ObjCVideoDecoderFactoryTest, ReleaseDecodeReturnsErrorOnFail) { |
| 101 webrtc::VideoDecoder *decoder = GetObjCDecoder(CreateErrorDecoderFactory()); |
| 102 |
| 103 EXPECT_EQ(decoder->Release(), WEBRTC_VIDEO_CODEC_ERROR); |
| 104 } |
OLD | NEW |