Skip to content

Commit

Permalink
restore to #30432
Browse files Browse the repository at this point in the history
  • Loading branch information
Piasy committed Oct 15, 2020
1 parent be99ee8 commit 7abfc99
Show file tree
Hide file tree
Showing 338 changed files with 40,702 additions and 14 deletions.
7 changes: 7 additions & 0 deletions BUILD.gn
Expand Up @@ -203,6 +203,13 @@ config("common_inherited_config") {
if (is_ubsan) {
cflags += [ "-fsanitize=float-cast-overflow" ]
}

if (!rtc_use_h265) {
defines += [ "DISABLE_H265" ]
}
if (!rtc_use_recorder) {
defines += [ "DISABLE_RECORDER" ]
}
}

# TODO(bugs.webrtc.org/9693): Remove the possibility to suppress this warning
Expand Down
4 changes: 4 additions & 0 deletions api/audio_codecs/audio_decoder.cc
Expand Up @@ -45,6 +45,10 @@ class OldStyleEncodedFrame final : public AudioDecoder::EncodedAudioFrame {
{static_cast<size_t>(ret), speech_type});
}

AudioEncoder::CodecType CodecType() override { return decoder_->CodecType(); }
int PayloadSize() override { return payload_.size(); }
const uint8_t* PayloadData() override { return payload_.data(); }

private:
AudioDecoder* const decoder_;
const rtc::Buffer payload_;
Expand Down
7 changes: 7 additions & 0 deletions api/audio_codecs/audio_decoder.h
Expand Up @@ -19,6 +19,7 @@

#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/audio_codecs/audio_encoder.h"
#include "rtc_base/buffer.h"
#include "rtc_base/constructor_magic.h"

Expand Down Expand Up @@ -53,6 +54,10 @@ class AudioDecoder {
// Returns true if this packet contains DTX.
virtual bool IsDtxPacket() const;

virtual AudioEncoder::CodecType CodecType() = 0;
virtual int PayloadSize() = 0;
virtual const uint8_t* PayloadData() = 0;

// Decodes this frame of audio and writes the result in |decoded|.
// |decoded| must be large enough to store as many samples as indicated by a
// call to Duration() . On success, returns an absl::optional containing the
Expand Down Expand Up @@ -170,6 +175,8 @@ class AudioDecoder {
// during the lifetime of the decoder.
virtual size_t Channels() const = 0;

virtual AudioEncoder::CodecType CodecType() = 0;

protected:
static SpeechType ConvertSpeechType(int16_t type);

Expand Down
7 changes: 7 additions & 0 deletions api/neteq/neteq.h
Expand Up @@ -30,6 +30,9 @@ namespace webrtc {
class AudioFrame;
class AudioDecoderFactory;
class Clock;
#ifndef DISABLE_RECORDER
class Recorder;
#endif

struct NetEqNetworkStatistics {
uint16_t current_buffer_size_ms; // Current jitter buffer size in ms.
Expand Down Expand Up @@ -329,6 +332,10 @@ class NetEq {
// Returns the length of the audio yet to play in the sync buffer.
// Mainly intended for testing.
virtual int SyncBufferSizeMs() const = 0;

#ifndef DISABLE_RECORDER
virtual void InjectRecorder(Recorder* recorder) = 0;
#endif
};

} // namespace webrtc
Expand Down
3 changes: 3 additions & 0 deletions api/peer_connection_interface.h
Expand Up @@ -1125,6 +1125,9 @@ class RTC_EXPORT PeerConnectionInterface : public rtc::RefCountInterface {
// Stops logging the RtcEventLog.
virtual void StopRtcEventLog() = 0;

virtual int32_t StartRecorder(int32_t dir, std::string path) = 0;
virtual int32_t StopRecorder(int32_t dir) = 0;

// Terminates all media, closes the transports, and in general releases any
// resources used by the PeerConnection. This is an irreversible operation.
//
Expand Down
2 changes: 2 additions & 0 deletions api/peer_connection_proxy.h
Expand Up @@ -137,6 +137,8 @@ PROXY_METHOD2(bool,
int64_t)
PROXY_METHOD1(bool, StartRtcEventLog, std::unique_ptr<RtcEventLogOutput>)
PROXY_METHOD0(void, StopRtcEventLog)
PROXY_METHOD2(int32_t, StartRecorder, int32_t, std::string)
PROXY_METHOD1(int32_t, StopRecorder, int32_t)
PROXY_METHOD0(void, Close)
END_PROXY_MAP()

Expand Down
1 change: 1 addition & 0 deletions api/video/builtin_video_bitrate_allocator_factory.cc
Expand Up @@ -41,6 +41,7 @@ class BuiltinVideoBitrateAllocatorFactory
case kVideoCodecVP9:
rate_allocator.reset(new SvcRateAllocator(codec));
break;
// TODO: add an allocator here for H.265
default:
rate_allocator.reset(new DefaultVideoBitrateAllocator(codec));
}
Expand Down
3 changes: 3 additions & 0 deletions api/video/video_codec_type.h
Expand Up @@ -22,6 +22,9 @@ enum VideoCodecType {
kVideoCodecVP9,
kVideoCodecAV1,
kVideoCodecH264,
#ifndef DISABLE_H265
kVideoCodecH265,
#endif
kVideoCodecMultiplex,
};

Expand Down
34 changes: 34 additions & 0 deletions api/video_codecs/video_codec.cc
Expand Up @@ -25,6 +25,9 @@ constexpr char kPayloadNameVp9[] = "VP9";
// frozen.
constexpr char kPayloadNameAv1[] = "AV1X";
constexpr char kPayloadNameH264[] = "H264";
#ifndef DISABLE_H265
constexpr char kPayloadNameH265[] = "H265";
#endif
constexpr char kPayloadNameGeneric[] = "Generic";
constexpr char kPayloadNameMultiplex[] = "Multiplex";
} // namespace
Expand Down Expand Up @@ -56,6 +59,17 @@ bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
numberOfTemporalLayers == other.numberOfTemporalLayers);
}

#ifndef DISABLE_H265
bool VideoCodecH265::operator==(const VideoCodecH265& other) const {
return (frameDroppingOn == other.frameDroppingOn &&
keyFrameInterval == other.keyFrameInterval &&
vpsLen == other.vpsLen && spsLen == other.spsLen &&
ppsLen == other.ppsLen &&
(spsLen == 0 || memcmp(spsData, other.spsData, spsLen) == 0) &&
(ppsLen == 0 || memcmp(ppsData, other.ppsData, ppsLen) == 0));
}
#endif

bool SpatialLayer::operator==(const SpatialLayer& other) const {
return (width == other.width && height == other.height &&
maxFramerate == other.maxFramerate &&
Expand Down Expand Up @@ -115,6 +129,18 @@ const VideoCodecH264& VideoCodec::H264() const {
return codec_specific_.H264;
}

#ifndef DISABLE_H265
VideoCodecH265* VideoCodec::H265() {
RTC_DCHECK_EQ(codecType, kVideoCodecH265);
return &codec_specific_.H265;
}

const VideoCodecH265& VideoCodec::H265() const {
RTC_DCHECK_EQ(codecType, kVideoCodecH265);
return codec_specific_.H265;
}
#endif

const char* CodecTypeToPayloadString(VideoCodecType type) {
switch (type) {
case kVideoCodecVP8:
Expand All @@ -125,6 +151,10 @@ const char* CodecTypeToPayloadString(VideoCodecType type) {
return kPayloadNameAv1;
case kVideoCodecH264:
return kPayloadNameH264;
#ifndef DISABLE_H265
case kVideoCodecH265:
return kPayloadNameH265;
#endif
case kVideoCodecMultiplex:
return kPayloadNameMultiplex;
case kVideoCodecGeneric:
Expand All @@ -141,6 +171,10 @@ VideoCodecType PayloadStringToCodecType(const std::string& name) {
return kVideoCodecAV1;
if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
return kVideoCodecH264;
#ifndef DISABLE_H265
if (absl::EqualsIgnoreCase(name, kPayloadNameH265))
return kVideoCodecH265;
#endif
if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
return kVideoCodecMultiplex;
return kVideoCodecGeneric;
Expand Down
24 changes: 24 additions & 0 deletions api/video_codecs/video_codec.h
Expand Up @@ -84,6 +84,23 @@ struct VideoCodecH264 {
uint8_t numberOfTemporalLayers;
};

#ifndef DISABLE_H265
struct VideoCodecH265 {
bool operator==(const VideoCodecH265& other) const;
bool operator!=(const VideoCodecH265& other) const {
return !(*this == other);
}
bool frameDroppingOn;
int keyFrameInterval;
const uint8_t* vpsData;
size_t vpsLen;
const uint8_t* spsData;
size_t spsLen;
const uint8_t* ppsData;
size_t ppsLen;
};
#endif

// Translates from name of codec to codec type and vice versa.
RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type);
RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name);
Expand All @@ -92,6 +109,9 @@ union VideoCodecUnion {
VideoCodecVP8 VP8;
VideoCodecVP9 VP9;
VideoCodecH264 H264;
#ifndef DISABLE_H265
VideoCodecH265 H265;
#endif
};

enum class VideoCodecMode { kRealtimeVideo, kScreensharing };
Expand Down Expand Up @@ -159,6 +179,10 @@ class RTC_EXPORT VideoCodec {
const VideoCodecVP9& VP9() const;
VideoCodecH264* H264();
const VideoCodecH264& H264() const;
#ifndef DISABLE_H265
VideoCodecH265* H265();
const VideoCodecH265& H265() const;
#endif

private:
// TODO(hta): Consider replacing the union with a pointer type.
Expand Down
17 changes: 17 additions & 0 deletions api/video_codecs/video_encoder.cc
Expand Up @@ -59,6 +59,23 @@ VideoCodecH264 VideoEncoder::GetDefaultH264Settings() {
return h264_settings;
}

#ifndef DISABLE_H265
VideoCodecH265 VideoEncoder::GetDefaultH265Settings() {
VideoCodecH265 h265_settings;
memset(&h265_settings, 0, sizeof(h265_settings));

// h265_settings.profile = kProfileBase;
h265_settings.frameDroppingOn = true;
h265_settings.keyFrameInterval = 3000;
h265_settings.spsData = nullptr;
h265_settings.spsLen = 0;
h265_settings.ppsData = nullptr;
h265_settings.ppsLen = 0;

return h265_settings;
}
#endif

VideoEncoder::ScalingSettings::ScalingSettings() = default;

VideoEncoder::ScalingSettings::ScalingSettings(KOff) : ScalingSettings() {}
Expand Down
3 changes: 3 additions & 0 deletions api/video_codecs/video_encoder.h
Expand Up @@ -315,6 +315,9 @@ class RTC_EXPORT VideoEncoder {
static VideoCodecVP8 GetDefaultVp8Settings();
static VideoCodecVP9 GetDefaultVp9Settings();
static VideoCodecH264 GetDefaultH264Settings();
#ifndef DISABLE_H265
static VideoCodecH265 GetDefaultH265Settings();
#endif

virtual ~VideoEncoder() {}

Expand Down
22 changes: 22 additions & 0 deletions api/video_codecs/video_encoder_config.cc
Expand Up @@ -93,6 +93,10 @@ void VideoEncoderConfig::EncoderSpecificSettings::FillEncoderSpecificSettings(
FillVideoCodecVp8(codec->VP8());
} else if (codec->codecType == kVideoCodecVP9) {
FillVideoCodecVp9(codec->VP9());
#ifndef DISABLE_H265
} else if (codec->codecType == kVideoCodecH265) {
FillVideoCodecH265(codec->H265());
#endif
} else {
RTC_NOTREACHED() << "Encoder specifics set/used for unknown codec type.";
}
Expand All @@ -103,6 +107,13 @@ void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH264(
RTC_NOTREACHED();
}

#ifndef DISABLE_H265
void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH265(
VideoCodecH265* h265_settings) const {
RTC_NOTREACHED();
}
#endif

void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp8(
VideoCodecVP8* vp8_settings) const {
RTC_NOTREACHED();
Expand All @@ -122,6 +133,17 @@ void VideoEncoderConfig::H264EncoderSpecificSettings::FillVideoCodecH264(
*h264_settings = specifics_;
}

#ifndef DISABLE_H265
VideoEncoderConfig::H265EncoderSpecificSettings::H265EncoderSpecificSettings(
const VideoCodecH265& specifics)
: specifics_(specifics) {}

void VideoEncoderConfig::H265EncoderSpecificSettings::FillVideoCodecH265(
VideoCodecH265* h265_settings) const {
*h265_settings = specifics_;
}
#endif

VideoEncoderConfig::Vp8EncoderSpecificSettings::Vp8EncoderSpecificSettings(
const VideoCodecVP8& specifics)
: specifics_(specifics) {}
Expand Down
14 changes: 14 additions & 0 deletions api/video_codecs/video_encoder_config.h
Expand Up @@ -84,6 +84,9 @@ class VideoEncoderConfig {
virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const;
virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const;
virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const;
#ifndef DISABLE_H265
virtual void FillVideoCodecH265(VideoCodecH265* h265_settings) const;
#endif

private:
~EncoderSpecificSettings() override {}
Expand All @@ -99,6 +102,17 @@ class VideoEncoderConfig {
VideoCodecH264 specifics_;
};

#ifndef DISABLE_H265
class H265EncoderSpecificSettings : public EncoderSpecificSettings {
public:
explicit H265EncoderSpecificSettings(const VideoCodecH265& specifics);
void FillVideoCodecH265(VideoCodecH265* h265_settings) const override;

private:
VideoCodecH265 specifics_;
};
#endif

class Vp8EncoderSpecificSettings : public EncoderSpecificSettings {
public:
explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics);
Expand Down
6 changes: 6 additions & 0 deletions audio/audio_receive_stream.cc
Expand Up @@ -276,6 +276,12 @@ std::vector<RtpSource> AudioReceiveStream::GetSources() const {
return source_tracker_.GetSources();
}

#ifndef DISABLE_RECORDER
void AudioReceiveStream::InjectRecorder(Recorder* recorder) {
channel_receive_->InjectRecorder(recorder);
}
#endif

AudioMixer::Source::AudioFrameInfo AudioReceiveStream::GetAudioFrameWithInfo(
int sample_rate_hz,
AudioFrame* audio_frame) {
Expand Down
4 changes: 4 additions & 0 deletions audio/audio_receive_stream.h
Expand Up @@ -74,6 +74,10 @@ class AudioReceiveStream final : public webrtc::AudioReceiveStream,
int GetBaseMinimumPlayoutDelayMs() const override;
std::vector<webrtc::RtpSource> GetSources() const override;

#ifndef DISABLE_RECORDER
void InjectRecorder(Recorder* recorder) override;
#endif

// TODO(nisse): We don't formally implement RtpPacketSinkInterface, and this
// method shouldn't be needed. But it's currently used by the
// AudioReceiveStreamTest.ReceiveRtpPacket unittest. Figure out if that test
Expand Down
6 changes: 6 additions & 0 deletions audio/audio_send_stream.cc
Expand Up @@ -470,6 +470,12 @@ webrtc::AudioSendStream::Stats AudioSendStream::GetStats(
return stats;
}

#ifndef DISABLE_RECORDER
void AudioSendStream::InjectRecorder(Recorder* recorder) {
channel_send_->InjectRecorder(recorder);
}
#endif

void AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
// TODO(solenberg): Tests call this function on a network thread, libjingle
// calls on the worker thread. We should move towards always using a network
Expand Down
4 changes: 4 additions & 0 deletions audio/audio_send_stream.h
Expand Up @@ -93,6 +93,10 @@ class AudioSendStream final : public webrtc::AudioSendStream,
webrtc::AudioSendStream::Stats GetStats(
bool has_remote_tracks) const override;

#ifndef DISABLE_RECORDER
void InjectRecorder(Recorder* recorder) override;
#endif

void DeliverRtcp(const uint8_t* packet, size_t length);

// Implements BitrateAllocatorObserver.
Expand Down

0 comments on commit 7abfc99

Please sign in to comment.