Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: webrtc/sdk/objc/Framework/UnitTests/objc_video_encoder_factory_tests.mm

Issue 2980173002: Revert of Injectable Obj-C video codecs (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/sdk/objc/Framework/UnitTests/objc_video_decoder_factory_tests.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/PeerConnection/objc_video_encoder_fa ctory.h"
15
16 #import "WebRTC/RTCVideoCodec.h"
17 #import "WebRTC/RTCVideoCodecFactory.h"
18 #import "WebRTC/RTCVideoFrameBuffer.h"
19 #include "webrtc/modules/include/module_common_types.h"
20 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
21 #include "webrtc/modules/video_coding/include/video_error_codes.h"
22 #include "webrtc/rtc_base/gunit.h"
23 #include "webrtc/sdk/objc/Framework/Classes/Video/objc_frame_buffer.h"
24
25 id<RTCVideoEncoderFactory> CreateEncoderFactoryReturning(int return_code) {
26 id encoderMock = OCMProtocolMock(@protocol(RTCVideoEncoder));
27 OCMStub([encoderMock initEncodeWithSettings:[OCMArg any] numberOfCores:1]).and Return(return_code);
28 OCMStub([encoderMock encode:[OCMArg any] codecSpecificInfo:[OCMArg any] frameT ypes:[OCMArg any]])
29 .andReturn(return_code);
30 OCMStub([encoderMock releaseEncode]).andReturn(return_code);
31 OCMStub([encoderMock setBitrate:0 framerate:0]).andReturn(return_code == WEBRT C_VIDEO_CODEC_OK);
32
33 id encoderFactoryMock = OCMProtocolMock(@protocol(RTCVideoEncoderFactory));
34 RTCVideoCodecInfo *supported =
35 [[RTCVideoCodecInfo alloc] initWithPayload:0 name:@"H264" parameters:@{}];
36 OCMStub([encoderFactoryMock supportedCodecs]).andReturn(@[ supported ]);
37 OCMStub([encoderFactoryMock createEncoder:[OCMArg any]]).andReturn(encoderMock );
38 return encoderFactoryMock;
39 }
40
41 id<RTCVideoEncoderFactory> CreateOKEncoderFactory() {
42 return CreateEncoderFactoryReturning(WEBRTC_VIDEO_CODEC_OK);
43 }
44
45 id<RTCVideoEncoderFactory> CreateErrorEncoderFactory() {
46 return CreateEncoderFactoryReturning(WEBRTC_VIDEO_CODEC_ERROR);
47 }
48
49 webrtc::VideoEncoder *GetObjCEncoder(id<RTCVideoEncoderFactory> factory) {
50 webrtc::ObjCVideoEncoderFactory encoder_factory(factory);
51 cricket::VideoCodec codec("H264");
52 return encoder_factory.CreateVideoEncoder(codec);
53 }
54
55 #pragma mark -
56
57 TEST(ObjCVideoEncoderFactoryTest, InitEncodeReturnsOKOnSuccess) {
58 webrtc::VideoEncoder *encoder = GetObjCEncoder(CreateOKEncoderFactory());
59
60 auto settings = new webrtc::VideoCodec();
61 EXPECT_EQ(encoder->InitEncode(settings, 1, 0), WEBRTC_VIDEO_CODEC_OK);
62 }
63
64 TEST(ObjCVideoEncoderFactoryTest, InitEncodeReturnsErrorOnFail) {
65 webrtc::VideoEncoder *encoder = GetObjCEncoder(CreateErrorEncoderFactory());
66
67 auto settings = new webrtc::VideoCodec();
68 EXPECT_EQ(encoder->InitEncode(settings, 1, 0), WEBRTC_VIDEO_CODEC_ERROR);
69 }
70
71 TEST(ObjCVideoEncoderFactoryTest, EncodeReturnsOKOnSuccess) {
72 webrtc::VideoEncoder *encoder = GetObjCEncoder(CreateOKEncoderFactory());
73
74 CVPixelBufferRef pixel_buffer;
75 CVPixelBufferCreate(kCFAllocatorDefault, 640, 480, kCVPixelFormatType_32ARGB, nil, &pixel_buffer);
76 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer =
77 new rtc::RefCountedObject<webrtc::ObjCFrameBuffer>(
78 [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixel_buffer]);
79 webrtc::VideoFrame frame(buffer, webrtc::kVideoRotation_0, 0);
80 webrtc::CodecSpecificInfo info;
81 info.codecType = webrtc::kVideoCodecH264;
82 info.codec_name = "H264";
83 std::vector<webrtc::FrameType> frame_types;
84
85 EXPECT_EQ(encoder->Encode(frame, &info, &frame_types), WEBRTC_VIDEO_CODEC_OK);
86 }
87
88 TEST(ObjCVideoEncoderFactoryTest, EncodeReturnsErrorOnFail) {
89 webrtc::VideoEncoder *encoder = GetObjCEncoder(CreateErrorEncoderFactory());
90
91 CVPixelBufferRef pixel_buffer;
92 CVPixelBufferCreate(kCFAllocatorDefault, 640, 480, kCVPixelFormatType_32ARGB, nil, &pixel_buffer);
93 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer =
94 new rtc::RefCountedObject<webrtc::ObjCFrameBuffer>(
95 [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixel_buffer]);
96 webrtc::VideoFrame frame(buffer, webrtc::kVideoRotation_0, 0);
97 webrtc::CodecSpecificInfo info;
98 info.codecType = webrtc::kVideoCodecH264;
99 info.codec_name = "H264";
100 std::vector<webrtc::FrameType> frame_types;
101
102 EXPECT_EQ(encoder->Encode(frame, &info, &frame_types), WEBRTC_VIDEO_CODEC_ERRO R);
103 }
104
105 TEST(ObjCVideoEncoderFactoryTest, ReleaseEncodeReturnsOKOnSuccess) {
106 webrtc::VideoEncoder *encoder = GetObjCEncoder(CreateOKEncoderFactory());
107
108 EXPECT_EQ(encoder->Release(), WEBRTC_VIDEO_CODEC_OK);
109 }
110
111 TEST(ObjCVideoEncoderFactoryTest, ReleaseEncodeReturnsErrorOnFail) {
112 webrtc::VideoEncoder *encoder = GetObjCEncoder(CreateErrorEncoderFactory());
113
114 EXPECT_EQ(encoder->Release(), WEBRTC_VIDEO_CODEC_ERROR);
115 }
116
117 TEST(ObjCVideoEncoderFactoryTest, SetChannelParametersAlwaysReturnsOK) {
118 webrtc::VideoEncoder *encoder = GetObjCEncoder(CreateErrorEncoderFactory());
119
120 EXPECT_EQ(encoder->SetChannelParameters(1, 1), WEBRTC_VIDEO_CODEC_OK);
121 }
122
123 TEST(ObjCVideoEncoderFactoryTest, SetRatesReturnsOKOnSuccess) {
124 webrtc::VideoEncoder *encoder = GetObjCEncoder(CreateOKEncoderFactory());
125
126 EXPECT_EQ(encoder->SetRates(0, 0), WEBRTC_VIDEO_CODEC_OK);
127 }
128
129 TEST(ObjCVideoEncoderFactoryTest, SetRatesReturnsErrorOnFail) {
130 webrtc::VideoEncoder *encoder = GetObjCEncoder(CreateErrorEncoderFactory());
131
132 EXPECT_EQ(encoder->SetRates(0, 0), WEBRTC_VIDEO_CODEC_ERROR);
133 }
OLDNEW
« no previous file with comments | « webrtc/sdk/objc/Framework/UnitTests/objc_video_decoder_factory_tests.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698