Reland "Move class VideoCodec from common_types.h to its own api header file."

This is a reland of efc71e565e9b36bcdfb4571f59e34bbd8fabd0cd

Differs from the original cl by not widening the type of
VideoCodec::width and VideoCodec::height.

Original change's description:
> 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}

Bug: webrtc:7660
Change-Id: I7cf74a85a61ea2b831e6f32b3b3e17514ebefec8
Reviewed-on: https://webrtc-review.googlesource.com/82140
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23569}
This commit is contained in:
Niels Möller
2018-06-08 14:03:44 +02:00
committed by Commit Bot
parent c17ca5354a
commit a46bd4b9c7
17 changed files with 162 additions and 155 deletions

View File

@ -383,9 +383,8 @@ rtc_source_set("typedefs") {
]
}
rtc_static_library("webrtc_common") {
rtc_source_set("webrtc_common") {
sources = [
"common_types.cc",
"common_types.h",
]
deps = [

View File

@ -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",

View File

@ -8,11 +8,12 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "common_types.h" // NOLINT(build/include)
#include "api/video_codecs/video_codec.h"
#include <string.h>
#include <algorithm>
#include <limits>
#include <string>
#include <type_traits>
#include "rtc_base/checks.h"

View File

@ -11,13 +11,156 @@
#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;
// TODO(nisse): Change to int, for consistency.
uint16_t width;
uint16_t 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_

View File

@ -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:

View File

@ -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"

View File

@ -325,55 +325,6 @@ enum class VideoType {
kBGRA,
};
// 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;
};
// TODO(magjed): Move this and other H264 related classes out to their own file.
namespace H264 {
@ -387,22 +338,6 @@ enum Profile {
} // namespace H264
// 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;
};
// Video codec types
enum VideoCodecType {
// There are various memset(..., 0, ...) calls in the code that rely on
@ -427,12 +362,6 @@ enum VideoCodecType {
const char* CodecTypeToPayloadString(VideoCodecType type);
VideoCodecType PayloadStringToCodecType(const std::string& name);
union VideoCodecUnion {
VideoCodecVP8 VP8;
VideoCodecVP9 VP9;
VideoCodecH264 H264;
};
struct SpatialLayer {
bool operator==(const SpatialLayer& other) const;
bool operator!=(const SpatialLayer& other) const { return !(*this == other); }
@ -451,72 +380,6 @@ struct SpatialLayer {
// settings such as resolution.
typedef SpatialLayer SimulcastStream;
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;
unsigned short width;
unsigned short 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_;
};
// TODO(sprang): Remove this when downstream projects have been updated.
using BitrateAllocation = VideoBitrateAllocation;

View File

@ -198,6 +198,7 @@ rtc_static_library("rtp_rtcp") {
"../../api:transport_api",
"../../api/audio_codecs:audio_codecs_api",
"../../api/video:video_bitrate_allocation",
"../../api/video_codecs:video_codecs_api",
"../../common_video",
"../../logging:rtc_event_audio",
"../../logging:rtc_event_log_api",
@ -411,6 +412,7 @@ if (rtc_include_tests) {
"../../api:transport_api",
"../../api/video:video_bitrate_allocation",
"../../api/video:video_frame",
"../../api/video_codecs:video_codecs_api",
"../../call:rtp_receiver",
"../../common_video:common_video",
"../../logging:mocks",

View File

@ -16,13 +16,12 @@
#include "api/audio_codecs/audio_format.h"
#include "api/optional.h"
#include "api/video_codecs/video_codec.h"
#include "modules/rtp_rtcp/source/rtp_utility.h"
#include "rtc_base/criticalsection.h"
namespace webrtc {
class VideoCodec;
class RTPPayloadRegistry {
public:
RTPPayloadRegistry();

View File

@ -12,7 +12,6 @@
#include <algorithm>
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/codecs/audio_format_conversion.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"

View File

@ -12,7 +12,7 @@
#include <memory>
#include <set>
#include "common_types.h" // NOLINT(build/include)
#include "api/video_codecs/video_codec.h"
#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "modules/rtp_rtcp/source/rtcp_packet.h"

View File

@ -14,7 +14,7 @@
#include <memory>
#include <vector>
#include "common_types.h" // NOLINT(build/include)
#include "api/video_codecs/video_codec.h"
#include "modules/rtp_rtcp/include/rtp_payload_registry.h"
#include "modules/rtp_rtcp/include/rtp_rtcp.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"

View File

@ -456,6 +456,7 @@ rtc_static_library("webrtc_vp9_helpers") {
deps = [
":video_codec_interface",
"../..:webrtc_common",
"../../api/video_codecs:video_codecs_api",
"../../common_video",
"../../rtc_base:checks",
]

View File

@ -15,8 +15,7 @@
#include <vector>
#include <memory>
#include "common_types.h" // NOLINT(build/include)
#include "typedefs.h" // NOLINT(build/include)
#include "api/video_codecs/video_codec.h"
#define VP8_TS_MAX_PERIODICITY 16
#define VP8_TS_MAX_LAYERS 5

View File

@ -15,7 +15,7 @@
#include <vector>
#include "common_types.h" // NOLINT(build/include)
#include "api/video_codecs/video_codec.h"
#include "common_video/include/video_bitrate_allocator.h"
namespace webrtc {

View File

@ -23,6 +23,7 @@
#include "api/fec_controller.h"
#include "api/video/video_frame.h"
#include "api/video_codecs/video_codec.h"
#include "modules/include/module.h"
#include "modules/include/module_common_types.h"
#include "modules/video_coding/include/video_coding_defines.h"

View File

@ -11,7 +11,7 @@
#ifndef MODULES_VIDEO_CODING_UTILITY_DEFAULT_VIDEO_BITRATE_ALLOCATOR_H_
#define MODULES_VIDEO_CODING_UTILITY_DEFAULT_VIDEO_BITRATE_ALLOCATOR_H_
#include "common_types.h" // NOLINT(build/include)
#include "api/video_codecs/video_codec.h"
#include "common_video/include/video_bitrate_allocator.h"
namespace webrtc {