| Index: third_party/openh264/testing/h264_codec_tester.cc
|
| diff --git a/third_party/openh264/testing/h264_codec_tester.cc b/third_party/openh264/testing/h264_codec_tester.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cdf9d8152cd1692e4055a9594cf6310d665e3cce
|
| --- /dev/null
|
| +++ b/third_party/openh264/testing/h264_codec_tester.cc
|
| @@ -0,0 +1,112 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "third_party/openh264/testing/h264_codec_tester.h"
|
| +
|
| +using namespace webrtc;
|
| +
|
| +namespace openh264 {
|
| +
|
| +H264CodecTester::H264CodecTester() : last_encoded_image_(nullptr),
|
| + last_decoded_image_(nullptr) {
|
| +}
|
| +
|
| +H264CodecTester::~H264CodecTester() {
|
| + encoder_.Release();
|
| + decoder_.Release();
|
| +}
|
| +
|
| +bool H264CodecTester::Init(unsigned short width, unsigned short height) {
|
| + const int32_t number_of_cores = 1;
|
| + const size_t max_payload_size = 0;
|
| +
|
| + // Codec settings...
|
| + VideoCodec codec;
|
| + memset(&codec, 0, sizeof(codec));
|
| +
|
| + codec.codecType = kVideoCodecH264;
|
| + strncpy(codec.plName, "H264", 5);
|
| + codec.plType = 120;
|
| +
|
| + codec.width = width;
|
| + codec.height = height;
|
| +
|
| + codec.minBitrate = 300;
|
| + codec.maxBitrate = 600;
|
| + codec.targetBitrate = 450;
|
| + codec.startBitrate = codec.minBitrate;
|
| + codec.maxFramerate = 30;
|
| +
|
| + memset(&codec.codecSpecific.H264, 0, sizeof(codec.codecSpecific.H264));
|
| + codec.codecSpecific.H264.profile = kProfileBase;
|
| + codec.codecSpecific.H264.frameDroppingOn = true;
|
| + codec.codecSpecific.H264.keyFrameInterval = 3000;
|
| + codec.codecSpecific.H264.spsData = nullptr;
|
| + codec.codecSpecific.H264.spsLen = 0;
|
| + codec.codecSpecific.H264.ppsData = nullptr;
|
| + codec.codecSpecific.H264.ppsLen = 0;
|
| +
|
| + codec.qpMax = 56;
|
| + codec.numberOfSimulcastStreams = 1;
|
| + codec.simulcastStream[0].width = codec.width;
|
| + codec.simulcastStream[0].height = codec.height;
|
| + codec.simulcastStream[0].minBitrate = codec.minBitrate;
|
| + codec.simulcastStream[0].maxBitrate = codec.maxBitrate;
|
| + codec.simulcastStream[0].targetBitrate = codec.targetBitrate;
|
| + codec.simulcastStream[0].qpMax = codec.qpMax;
|
| + codec.simulcastStream[0].numberOfTemporalLayers = 1;
|
| +
|
| + codec.mode = kRealtimeVideo;
|
| + codec.extra_options = nullptr;
|
| +
|
| + // Initialize encoder and decoder.
|
| + if (encoder_.InitEncode(&codec, number_of_cores, max_payload_size)
|
| + != WEBRTC_VIDEO_CODEC_OK) {
|
| + encoder_.Release();
|
| + return false;
|
| + }
|
| + if (decoder_.InitDecode(&codec, number_of_cores) != WEBRTC_VIDEO_CODEC_OK) {
|
| + encoder_.Release();
|
| + decoder_.Release();
|
| + return false;
|
| + }
|
| +
|
| + // Register so that Encoded and Decoded will be called.
|
| + encoder_.RegisterEncodeCompleteCallback(this);
|
| + decoder_.RegisterDecodeCompleteCallback(this);
|
| +
|
| + return true;
|
| +}
|
| +
|
| +bool H264CodecTester::Encode(const VideoFrame& frame) {
|
| + last_encoded_image_ = nullptr;
|
| + if (encoder_.Encode(frame, nullptr, nullptr) != WEBRTC_VIDEO_CODEC_OK ||
|
| + !last_encoded_image_) {
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +VideoFrame* H264CodecTester::Decode() {
|
| + last_decoded_image_ = nullptr;
|
| + if (decoder_.Decode(*last_encoded_image_, false, nullptr)
|
| + != WEBRTC_VIDEO_CODEC_OK || !last_decoded_image_) {
|
| + return nullptr;
|
| + }
|
| + return last_decoded_image_;
|
| +}
|
| +
|
| +int32_t H264CodecTester::Encoded(const EncodedImage& encoded_image,
|
| + const CodecSpecificInfo* codec_specific_info,
|
| + const RTPFragmentationHeader* fragmentation) {
|
| + last_encoded_image_ = &encoded_image;
|
| + return WEBRTC_VIDEO_CODEC_OK;
|
| +}
|
| +
|
| +int32_t H264CodecTester::Decoded(VideoFrame& decoded_image) {
|
| + last_decoded_image_ = &decoded_image;
|
| + return WEBRTC_VIDEO_CODEC_OK;
|
| +}
|
| +
|
| +} // namespace openh264
|
|
|