Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new encoder factory for UWP MF encoder #37

Open
wants to merge 4 commits into
base: releases/m71
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 41 additions & 29 deletions third_party/winuwp_h264/winuwp_h264_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,10 @@
#include "third_party/winuwp_h264/H264Decoder/H264Decoder.h"
#include "media/engine/webrtcvideoencoderfactory.h"
#include "media/engine/webrtcvideodecoderfactory.h"

#include "rtc_base/logging.h"

namespace webrtc {

WinUWPH264EncoderFactory::WinUWPH264EncoderFactory() {
codecList_ =
std::vector<cricket::VideoCodec> {
cricket::VideoCodec("H264")
};
}

webrtc::VideoEncoder* WinUWPH264EncoderFactory::CreateVideoEncoder(
const cricket::VideoCodec& codec) {
if (codec.name == "H264") {
return new WinUWPH264EncoderImpl();
} else {
return nullptr;
}
}

const std::vector<cricket::VideoCodec>&
WinUWPH264EncoderFactory::supported_codecs() const {
return codecList_;
}

void WinUWPH264EncoderFactory::DestroyVideoEncoder(
webrtc::VideoEncoder* encoder) {
encoder->Release();
delete encoder;
}


webrtc::VideoDecoder* WinUWPH264DecoderFactory::CreateVideoDecoder(
webrtc::VideoCodecType type) {
if (type == kVideoCodecH264) {
Expand All @@ -61,5 +33,45 @@ namespace webrtc {
delete decoder;
}

std::vector<SdpVideoFormat> WinUWPH264EncoderFactory::GetSupportedFormats()
const {
std::vector<SdpVideoFormat> formats = {
SdpVideoFormat(cricket::kH264CodecName,
{
//copy-pasted from h264.cc
{cricket::kH264FmtpProfileLevelId, "42100b"},
{cricket::kH264FmtpLevelAsymmetryAllowed, "1"},
{cricket::kH264FmtpPacketizationMode, "0"}
}),
SdpVideoFormat(cricket::kH264CodecName,
{
{cricket::kH264FmtpProfileLevelId, "42100b"},
{cricket::kH264FmtpLevelAsymmetryAllowed, "1"},
{cricket::kH264FmtpPacketizationMode, "1"}
})
};
return formats;
}

VideoEncoderFactory::CodecInfo WinUWPH264EncoderFactory::QueryVideoEncoder(
const SdpVideoFormat& format) const {
CodecInfo info;
info.is_hardware_accelerated = true;
info.has_internal_source = false;

return info;
}

std::unique_ptr<VideoEncoder> WinUWPH264EncoderFactory::CreateVideoEncoder(
const SdpVideoFormat& format) {
if (cricket::CodecNamesEq(format.name, cricket::kH264CodecName)) {
return std::make_unique<WinUWPH264EncoderImpl>();
}

RTC_LOG(LS_ERROR) << "Trying to create encoder of unsupported format "
<< format.name;
return nullptr;
}

} // namespace webrtc

17 changes: 6 additions & 11 deletions third_party/winuwp_h264/winuwp_h264_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,18 @@
#include "media/engine/webrtcvideoencoderfactory.h"
#include "media/engine/webrtcvideodecoderfactory.h"
#include "media/base/codec.h"
#include "api/video_codecs/video_encoder_factory.h"

namespace webrtc {

class WinUWPH264EncoderFactory : public cricket::WebRtcVideoEncoderFactory {
class WinUWPH264EncoderFactory : public VideoEncoderFactory {
public:
WinUWPH264EncoderFactory();
std::vector<SdpVideoFormat> GetSupportedFormats() const override;

webrtc::VideoEncoder* CreateVideoEncoder(const cricket::VideoCodec& codec)
override;

const std::vector<cricket::VideoCodec>& supported_codecs()
const override;

void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override;
CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const override;

private:
std::vector<cricket::VideoCodec> codecList_;
std::unique_ptr<VideoEncoder> CreateVideoEncoder(
const SdpVideoFormat& format) override;
};

class WinUWPH264DecoderFactory : public cricket::WebRtcVideoDecoderFactory {
Expand Down