Move class VideoCodec from common_types.h to its own api header file.
Bug: webrtc:7660 Change-Id: I91f19bfc2565461328f30081f8383e136419aefb Reviewed-on: https://webrtc-review.googlesource.com/79881 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23544}
This commit is contained in:
@ -17,6 +17,7 @@ rtc_source_set("video_codecs_api") {
|
||||
sources = [
|
||||
"sdp_video_format.cc",
|
||||
"sdp_video_format.h",
|
||||
"video_codec.cc",
|
||||
"video_codec.h",
|
||||
"video_decoder.cc",
|
||||
"video_decoder.h",
|
||||
|
||||
161
api/video_codecs/video_codec.cc
Normal file
161
api/video_codecs/video_codec.cc
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "api/video_codecs/video_codec.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
#include "rtc_base/stringutils.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
VideoCodec::VideoCodec()
|
||||
: codecType(kVideoCodecUnknown),
|
||||
plType(0),
|
||||
width(0),
|
||||
height(0),
|
||||
startBitrate(0),
|
||||
maxBitrate(0),
|
||||
minBitrate(0),
|
||||
targetBitrate(0),
|
||||
maxFramerate(0),
|
||||
active(true),
|
||||
qpMax(0),
|
||||
numberOfSimulcastStreams(0),
|
||||
simulcastStream(),
|
||||
spatialLayers(),
|
||||
mode(kRealtimeVideo),
|
||||
expect_encode_from_texture(false),
|
||||
timing_frame_thresholds({0, 0}),
|
||||
codec_specific_() {}
|
||||
|
||||
VideoCodecVP8* VideoCodec::VP8() {
|
||||
RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
|
||||
return &codec_specific_.VP8;
|
||||
}
|
||||
|
||||
const VideoCodecVP8& VideoCodec::VP8() const {
|
||||
RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
|
||||
return codec_specific_.VP8;
|
||||
}
|
||||
|
||||
VideoCodecVP9* VideoCodec::VP9() {
|
||||
RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
|
||||
return &codec_specific_.VP9;
|
||||
}
|
||||
|
||||
const VideoCodecVP9& VideoCodec::VP9() const {
|
||||
RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
|
||||
return codec_specific_.VP9;
|
||||
}
|
||||
|
||||
VideoCodecH264* VideoCodec::H264() {
|
||||
RTC_DCHECK_EQ(codecType, kVideoCodecH264);
|
||||
return &codec_specific_.H264;
|
||||
}
|
||||
|
||||
const VideoCodecH264& VideoCodec::H264() const {
|
||||
RTC_DCHECK_EQ(codecType, kVideoCodecH264);
|
||||
return codec_specific_.H264;
|
||||
}
|
||||
|
||||
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";
|
||||
static const char* kPayloadNameMultiplex = "Multiplex";
|
||||
|
||||
static bool CodecNamesEq(const char* name1, const char* name2) {
|
||||
return _stricmp(name1, name2) == 0;
|
||||
}
|
||||
|
||||
const char* CodecTypeToPayloadString(VideoCodecType type) {
|
||||
switch (type) {
|
||||
case kVideoCodecVP8:
|
||||
return kPayloadNameVp8;
|
||||
case kVideoCodecVP9:
|
||||
return kPayloadNameVp9;
|
||||
case kVideoCodecH264:
|
||||
return kPayloadNameH264;
|
||||
case kVideoCodecI420:
|
||||
return kPayloadNameI420;
|
||||
// Other codecs default to generic.
|
||||
case kVideoCodecMultiplex:
|
||||
case kVideoCodecGeneric:
|
||||
case kVideoCodecUnknown:
|
||||
return kPayloadNameGeneric;
|
||||
}
|
||||
return kPayloadNameGeneric;
|
||||
}
|
||||
|
||||
VideoCodecType PayloadStringToCodecType(const std::string& name) {
|
||||
if (CodecNamesEq(name.c_str(), kPayloadNameVp8))
|
||||
return kVideoCodecVP8;
|
||||
if (CodecNamesEq(name.c_str(), kPayloadNameVp9))
|
||||
return kVideoCodecVP9;
|
||||
if (CodecNamesEq(name.c_str(), kPayloadNameH264))
|
||||
return kVideoCodecH264;
|
||||
if (CodecNamesEq(name.c_str(), kPayloadNameI420))
|
||||
return kVideoCodecI420;
|
||||
if (CodecNamesEq(name.c_str(), kPayloadNameMultiplex))
|
||||
return kVideoCodecMultiplex;
|
||||
return kVideoCodecGeneric;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -11,13 +11,155 @@
|
||||
#ifndef API_VIDEO_CODECS_VIDEO_CODEC_H_
|
||||
#define API_VIDEO_CODECS_VIDEO_CODEC_H_
|
||||
|
||||
// TODO(bugs.webrtc.org/7660): This is an initial place holder file. Downstream
|
||||
// users of VideoCodec must be updated to include this file, before contents can
|
||||
// be moved out of common_types.h.
|
||||
#include <string>
|
||||
|
||||
#include "common_types.h" // NOLINT(build/include)
|
||||
|
||||
// The VideoCodec class represents an old defacto-api, which we're migrating
|
||||
namespace webrtc {
|
||||
|
||||
// The VideoCodec class represents an old defacto-apis, which we're migrating
|
||||
// away from slowly.
|
||||
|
||||
// Video codec
|
||||
enum VideoCodecComplexity {
|
||||
kComplexityNormal = 0,
|
||||
kComplexityHigh = 1,
|
||||
kComplexityHigher = 2,
|
||||
kComplexityMax = 3
|
||||
};
|
||||
|
||||
// VP8 specific
|
||||
struct VideoCodecVP8 {
|
||||
bool operator==(const VideoCodecVP8& other) const;
|
||||
bool operator!=(const VideoCodecVP8& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
VideoCodecComplexity complexity;
|
||||
unsigned char numberOfTemporalLayers;
|
||||
bool denoisingOn;
|
||||
bool automaticResizeOn;
|
||||
bool frameDroppingOn;
|
||||
int keyFrameInterval;
|
||||
};
|
||||
|
||||
enum class InterLayerPredMode {
|
||||
kOn, // Allow inter-layer prediction for all frames.
|
||||
// Frame of low spatial layer can be used for
|
||||
// prediction of next spatial layer frame.
|
||||
kOff, // Encoder produces independent spatial layers.
|
||||
kOnKeyPic // Allow inter-layer prediction only for frames
|
||||
// within key picture.
|
||||
};
|
||||
|
||||
// VP9 specific.
|
||||
struct VideoCodecVP9 {
|
||||
bool operator==(const VideoCodecVP9& other) const;
|
||||
bool operator!=(const VideoCodecVP9& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
VideoCodecComplexity complexity;
|
||||
unsigned char numberOfTemporalLayers;
|
||||
bool denoisingOn;
|
||||
bool frameDroppingOn;
|
||||
int keyFrameInterval;
|
||||
bool adaptiveQpMode;
|
||||
bool automaticResizeOn;
|
||||
unsigned char numberOfSpatialLayers;
|
||||
bool flexibleMode;
|
||||
InterLayerPredMode interLayerPred;
|
||||
};
|
||||
|
||||
// H264 specific.
|
||||
struct VideoCodecH264 {
|
||||
bool operator==(const VideoCodecH264& other) const;
|
||||
bool operator!=(const VideoCodecH264& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
bool frameDroppingOn;
|
||||
int keyFrameInterval;
|
||||
// These are NULL/0 if not externally negotiated.
|
||||
const uint8_t* spsData;
|
||||
size_t spsLen;
|
||||
const uint8_t* ppsData;
|
||||
size_t ppsLen;
|
||||
H264::Profile profile;
|
||||
};
|
||||
|
||||
// Translates from name of codec to codec type and vice versa.
|
||||
const char* CodecTypeToPayloadString(VideoCodecType type);
|
||||
VideoCodecType PayloadStringToCodecType(const std::string& name);
|
||||
|
||||
union VideoCodecUnion {
|
||||
VideoCodecVP8 VP8;
|
||||
VideoCodecVP9 VP9;
|
||||
VideoCodecH264 H264;
|
||||
};
|
||||
|
||||
enum VideoCodecMode { kRealtimeVideo, kScreensharing };
|
||||
|
||||
// Common video codec properties
|
||||
class VideoCodec {
|
||||
public:
|
||||
VideoCodec();
|
||||
|
||||
// Public variables. TODO(hta): Make them private with accessors.
|
||||
VideoCodecType codecType;
|
||||
unsigned char plType;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
|
||||
unsigned int startBitrate; // kilobits/sec.
|
||||
unsigned int maxBitrate; // kilobits/sec.
|
||||
unsigned int minBitrate; // kilobits/sec.
|
||||
unsigned int targetBitrate; // kilobits/sec.
|
||||
|
||||
uint32_t maxFramerate;
|
||||
|
||||
// This enables/disables encoding and sending when there aren't multiple
|
||||
// simulcast streams,by allocating 0 bitrate if inactive.
|
||||
bool active;
|
||||
|
||||
unsigned int qpMax;
|
||||
unsigned char numberOfSimulcastStreams;
|
||||
SimulcastStream simulcastStream[kMaxSimulcastStreams];
|
||||
SpatialLayer spatialLayers[kMaxSpatialLayers];
|
||||
|
||||
VideoCodecMode mode;
|
||||
bool expect_encode_from_texture;
|
||||
|
||||
// Timing frames configuration. There is delay of delay_ms between two
|
||||
// consequent timing frames, excluding outliers. Frame is always made a
|
||||
// timing frame if it's at least outlier_ratio in percent of "ideal" average
|
||||
// frame given bitrate and framerate, i.e. if it's bigger than
|
||||
// |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
|
||||
// frames will not be sent too often usually. Yet large frames will always
|
||||
// have timing information for debug purposes because they are more likely to
|
||||
// cause extra delays.
|
||||
struct TimingFrameTriggerThresholds {
|
||||
int64_t delay_ms;
|
||||
uint16_t outlier_ratio_percent;
|
||||
} timing_frame_thresholds;
|
||||
|
||||
bool operator==(const VideoCodec& other) const = delete;
|
||||
bool operator!=(const VideoCodec& other) const = delete;
|
||||
|
||||
// Accessors for codec specific information.
|
||||
// There is a const version of each that returns a reference,
|
||||
// and a non-const version that returns a pointer, in order
|
||||
// to allow modification of the parameters.
|
||||
VideoCodecVP8* VP8();
|
||||
const VideoCodecVP8& VP8() const;
|
||||
VideoCodecVP9* VP9();
|
||||
const VideoCodecVP9& VP9() const;
|
||||
VideoCodecH264* H264();
|
||||
const VideoCodecH264& H264() const;
|
||||
|
||||
private:
|
||||
// TODO(hta): Consider replacing the union with a pointer type.
|
||||
// This will allow removing the VideoCodec* types from this file.
|
||||
VideoCodecUnion codec_specific_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // API_VIDEO_CODECS_VIDEO_CODEC_H_
|
||||
|
||||
@ -27,7 +27,6 @@ namespace webrtc {
|
||||
class RTPFragmentationHeader;
|
||||
// TODO(pbos): Expose these through a public (root) header or change these APIs.
|
||||
struct CodecSpecificInfo;
|
||||
class VideoCodec;
|
||||
|
||||
class EncodedImageCallback {
|
||||
public:
|
||||
|
||||
@ -15,8 +15,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "api/optional.h"
|
||||
#include "api/video_codecs/video_codec.h"
|
||||
#include "api/video_codecs/sdp_video_format.h"
|
||||
#include "common_types.h" // NOLINT(build/include)
|
||||
#include "rtc_base/refcount.h"
|
||||
#include "rtc_base/scoped_ref_ptr.h"
|
||||
|
||||
@ -28,8 +28,8 @@ struct VideoStream {
|
||||
VideoStream(const VideoStream& other);
|
||||
std::string ToString() const;
|
||||
|
||||
size_t width;
|
||||
size_t height;
|
||||
int width;
|
||||
int height;
|
||||
int max_framerate;
|
||||
|
||||
int min_bitrate_bps;
|
||||
|
||||
Reference in New Issue
Block a user