2015-02-26 13:59:22 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-06-08 14:03:44 +02:00
|
|
|
#include "api/video_codecs/video_codec.h"
|
2015-02-26 13:59:22 +00:00
|
|
|
|
|
|
|
|
#include <string.h>
|
2017-06-08 04:19:13 -07:00
|
|
|
#include <algorithm>
|
2017-04-19 02:59:48 -07:00
|
|
|
#include <limits>
|
2018-06-08 14:03:44 +02:00
|
|
|
#include <string>
|
2017-04-19 02:59:48 -07:00
|
|
|
#include <type_traits>
|
2015-02-26 13:59:22 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2018-03-19 18:25:10 +01:00
|
|
|
#include "rtc_base/strings/string_builder.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/stringutils.h"
|
2016-11-22 10:16:57 -08:00
|
|
|
|
2015-02-26 13:59:22 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
|
2018-03-19 13:48:44 +01:00
|
|
|
bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
|
|
|
|
|
return (complexity == other.complexity &&
|
|
|
|
|
numberOfTemporalLayers == other.numberOfTemporalLayers &&
|
|
|
|
|
denoisingOn == other.denoisingOn &&
|
|
|
|
|
automaticResizeOn == other.automaticResizeOn &&
|
|
|
|
|
frameDroppingOn == other.frameDroppingOn &&
|
|
|
|
|
keyFrameInterval == other.keyFrameInterval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
|
|
|
|
|
return (complexity == other.complexity &&
|
|
|
|
|
numberOfTemporalLayers == other.numberOfTemporalLayers &&
|
|
|
|
|
denoisingOn == other.denoisingOn &&
|
|
|
|
|
frameDroppingOn == other.frameDroppingOn &&
|
|
|
|
|
keyFrameInterval == other.keyFrameInterval &&
|
|
|
|
|
adaptiveQpMode == other.adaptiveQpMode &&
|
|
|
|
|
automaticResizeOn == other.automaticResizeOn &&
|
|
|
|
|
numberOfSpatialLayers == other.numberOfSpatialLayers &&
|
|
|
|
|
flexibleMode == other.flexibleMode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
|
|
|
|
|
return (frameDroppingOn == other.frameDroppingOn &&
|
|
|
|
|
keyFrameInterval == other.keyFrameInterval &&
|
|
|
|
|
spsLen == other.spsLen && ppsLen == other.ppsLen &&
|
|
|
|
|
profile == other.profile &&
|
|
|
|
|
(spsLen == 0 || memcmp(spsData, other.spsData, spsLen) == 0) &&
|
|
|
|
|
(ppsLen == 0 || memcmp(ppsData, other.ppsData, ppsLen) == 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SpatialLayer::operator==(const SpatialLayer& other) const {
|
|
|
|
|
return (width == other.width && height == other.height &&
|
|
|
|
|
numberOfTemporalLayers == other.numberOfTemporalLayers &&
|
|
|
|
|
maxBitrate == other.maxBitrate &&
|
|
|
|
|
targetBitrate == other.targetBitrate &&
|
|
|
|
|
minBitrate == other.minBitrate && qpMax == other.qpMax &&
|
|
|
|
|
active == other.active);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-25 09:05:06 -07:00
|
|
|
VideoCodec::VideoCodec()
|
2018-08-16 14:35:26 +02:00
|
|
|
: codecType(kVideoCodecGeneric),
|
2016-10-25 09:05:06 -07:00
|
|
|
plType(0),
|
|
|
|
|
width(0),
|
|
|
|
|
height(0),
|
|
|
|
|
startBitrate(0),
|
|
|
|
|
maxBitrate(0),
|
|
|
|
|
minBitrate(0),
|
|
|
|
|
targetBitrate(0),
|
|
|
|
|
maxFramerate(0),
|
2018-01-17 13:55:14 -08:00
|
|
|
active(true),
|
2016-10-25 09:05:06 -07:00
|
|
|
qpMax(0),
|
|
|
|
|
numberOfSimulcastStreams(0),
|
|
|
|
|
simulcastStream(),
|
|
|
|
|
spatialLayers(),
|
2018-06-13 11:52:16 +02:00
|
|
|
mode(VideoCodecMode::kRealtimeVideo),
|
2016-11-16 16:41:30 +01:00
|
|
|
expect_encode_from_texture(false),
|
2017-06-19 07:18:55 -07:00
|
|
|
timing_frame_thresholds({0, 0}),
|
2016-11-16 23:23:04 -08:00
|
|
|
codec_specific_() {}
|
2016-10-25 09:05:06 -07:00
|
|
|
|
|
|
|
|
VideoCodecVP8* VideoCodec::VP8() {
|
|
|
|
|
RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
|
2016-11-16 23:23:04 -08:00
|
|
|
return &codec_specific_.VP8;
|
2016-10-25 09:05:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const VideoCodecVP8& VideoCodec::VP8() const {
|
|
|
|
|
RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
|
2016-11-16 23:23:04 -08:00
|
|
|
return codec_specific_.VP8;
|
2016-10-25 09:05:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoCodecVP9* VideoCodec::VP9() {
|
|
|
|
|
RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
|
2016-11-16 23:23:04 -08:00
|
|
|
return &codec_specific_.VP9;
|
2016-10-25 09:05:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const VideoCodecVP9& VideoCodec::VP9() const {
|
|
|
|
|
RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
|
2016-11-16 23:23:04 -08:00
|
|
|
return codec_specific_.VP9;
|
2016-10-25 09:05:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoCodecH264* VideoCodec::H264() {
|
|
|
|
|
RTC_DCHECK_EQ(codecType, kVideoCodecH264);
|
2016-11-16 23:23:04 -08:00
|
|
|
return &codec_specific_.H264;
|
2016-10-25 09:05:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const VideoCodecH264& VideoCodec::H264() const {
|
|
|
|
|
RTC_DCHECK_EQ(codecType, kVideoCodecH264);
|
2016-11-16 23:23:04 -08:00
|
|
|
return codec_specific_.H264;
|
2016-10-25 09:05:06 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-16 16:41:30 +01:00
|
|
|
static const char* kPayloadNameVp8 = "VP8";
|
|
|
|
|
static const char* kPayloadNameVp9 = "VP9";
|
|
|
|
|
static const char* kPayloadNameH264 = "H264";
|
|
|
|
|
static const char* kPayloadNameI420 = "I420";
|
|
|
|
|
static const char* kPayloadNameGeneric = "Generic";
|
2018-01-25 13:01:09 -08:00
|
|
|
static const char* kPayloadNameMultiplex = "Multiplex";
|
2016-11-16 16:41:30 +01:00
|
|
|
|
2016-11-22 10:16:57 -08:00
|
|
|
static bool CodecNamesEq(const char* name1, const char* name2) {
|
|
|
|
|
return _stricmp(name1, name2) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 03:52:48 -07:00
|
|
|
const char* CodecTypeToPayloadString(VideoCodecType type) {
|
2016-11-16 16:41:30 +01:00
|
|
|
switch (type) {
|
|
|
|
|
case kVideoCodecVP8:
|
2017-08-24 03:52:48 -07:00
|
|
|
return kPayloadNameVp8;
|
2016-11-16 16:41:30 +01:00
|
|
|
case kVideoCodecVP9:
|
2017-08-24 03:52:48 -07:00
|
|
|
return kPayloadNameVp9;
|
2016-11-16 16:41:30 +01:00
|
|
|
case kVideoCodecH264:
|
2017-08-24 03:52:48 -07:00
|
|
|
return kPayloadNameH264;
|
2016-11-16 16:41:30 +01:00
|
|
|
case kVideoCodecI420:
|
2017-08-24 03:52:48 -07:00
|
|
|
return kPayloadNameI420;
|
2017-12-11 12:21:02 +05:30
|
|
|
// Other codecs default to generic.
|
2018-08-16 14:35:26 +02:00
|
|
|
default:
|
2017-08-24 03:52:48 -07:00
|
|
|
return kPayloadNameGeneric;
|
2016-11-16 16:41:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 03:52:48 -07:00
|
|
|
VideoCodecType PayloadStringToCodecType(const std::string& name) {
|
2016-11-22 10:16:57 -08:00
|
|
|
if (CodecNamesEq(name.c_str(), kPayloadNameVp8))
|
2017-08-24 03:52:48 -07:00
|
|
|
return kVideoCodecVP8;
|
2016-11-22 10:16:57 -08:00
|
|
|
if (CodecNamesEq(name.c_str(), kPayloadNameVp9))
|
2017-08-24 03:52:48 -07:00
|
|
|
return kVideoCodecVP9;
|
2016-11-22 10:16:57 -08:00
|
|
|
if (CodecNamesEq(name.c_str(), kPayloadNameH264))
|
2017-08-24 03:52:48 -07:00
|
|
|
return kVideoCodecH264;
|
2016-11-22 10:16:57 -08:00
|
|
|
if (CodecNamesEq(name.c_str(), kPayloadNameI420))
|
2017-08-24 03:52:48 -07:00
|
|
|
return kVideoCodecI420;
|
2018-01-25 13:01:09 -08:00
|
|
|
if (CodecNamesEq(name.c_str(), kPayloadNameMultiplex))
|
|
|
|
|
return kVideoCodecMultiplex;
|
2017-08-24 03:52:48 -07:00
|
|
|
return kVideoCodecGeneric;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 13:59:22 +00:00
|
|
|
} // namespace webrtc
|