webrtc/api/test/mock_video_encoder.h
Erik Språng 157b7814b9 Remove deprecated SetRates/SetRateAllocation from VideoEncoder.
This CL removes two deprecated methods from the VideoEncoder interface:
* int32_t SetRates(uint32_t, uint32_t);
* int32_t SetRateAllocation(const VideoBitrateAllocation&, uint32_t);

These are no longer used, instead the new version must be implemented:
  void SetRates(const RateControlParameters&) = 0;

Migrating is straight forward. For the old SetRates, simple replace:
  int32_t MyEncoder::SetRates(uint32_t bitrate, uint32_t framerate) {
with
  void MyEncoder::SetRates(const RateControlParameters& parameters) {
    uint32_t bitrate = parameters.bitrate.get_sum_kbps();
    uint32_t framerate =
      static_cast<uint32_t>(parameters.framerate_fps + 0.5);

For SetRateAllocation, replace:
  int32_t MyEncoder::SetRateAllocation(
      const VideoBitrateAllocation& allocation,
      uint32_t framerate) {
with
  void MyEncoder::SetRates(const RateControlParameters& parameters) {
    const VideoBitrateAllocation& allocation = parameters.bitrate;
    uint32_t framerate =
      static_cast<uint32_t>(parameters.framerate_fps + 0.5);

Two more things to note:
1. The new method is void. Previously the only use of the return value
   in production code was to log a more or less generic error message.
   Instead, log the actual error from the encoder when it happens,
   then just return.

2. The new method is pure virtual; it must be overriden even in test.

This CL is intended to be landed two weeks after creation, on Thursday
May 9th 2019.

Bug: webrtc:10481
Change-Id: I61349571a280bd40cd100ca9f93c4aa7748ed30d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/134214
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27926}
2019-05-13 11:42:59 +00:00

53 lines
1.8 KiB
C++

/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef API_TEST_MOCK_VIDEO_ENCODER_H_
#define API_TEST_MOCK_VIDEO_ENCODER_H_
#include <vector>
#include "api/video_codecs/video_encoder.h"
#include "test/gmock.h"
namespace webrtc {
class MockEncodedImageCallback : public EncodedImageCallback {
public:
MockEncodedImageCallback();
~MockEncodedImageCallback();
MOCK_METHOD3(OnEncodedImage,
Result(const EncodedImage& encodedImage,
const CodecSpecificInfo* codecSpecificInfo,
const RTPFragmentationHeader* fragmentation));
};
class MockVideoEncoder : public VideoEncoder {
public:
MockVideoEncoder();
~MockVideoEncoder();
MOCK_CONST_METHOD2(Version, int32_t(int8_t* version, int32_t length));
MOCK_METHOD3(InitEncode,
int32_t(const VideoCodec* codecSettings,
int32_t numberOfCores,
size_t maxPayloadSize));
MOCK_METHOD2(Encode,
int32_t(const VideoFrame& inputImage,
const std::vector<VideoFrameType>* frame_types));
MOCK_METHOD1(RegisterEncodeCompleteCallback,
int32_t(EncodedImageCallback* callback));
MOCK_METHOD0(Release, int32_t());
MOCK_METHOD0(Reset, int32_t());
MOCK_METHOD1(SetRates, void(const RateControlParameters& parameters));
MOCK_CONST_METHOD0(GetEncoderInfo, EncoderInfo(void));
};
} // namespace webrtc
#endif // API_TEST_MOCK_VIDEO_ENCODER_H_