webrtc_m130/webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.cc
magjed f823ededce Negotiate H264 profiles in SDP
This CL will start to distinguish H264 profiles during SDP negotiation.
We currently don't look at the H264 profile at all and assume they are
all Constrained Baseline Level 3.1. This CL will start to check profiles
for equality when matching, and will generate the correct answer H264
level.

Each local supported H264 profile needs to be listed explicitly in the
list of local supported codecs, even if they are redundant. For example,
Baseline profile should be listed explicitly even though another profile
that is a superset of Baseline is also listed. The reason for this is to
simplify the code and avoid profile intersection during matching. So
VideoCodec::Matches will check for profile equality, and not check if
one codec is a subset of the other. This also leads to the nice property
that VideoCodec::Matches is symmetric, i.e. iif a.Matches(b) then
b.Matches(a).

BUG=webrtc:6337
TBR=tkchin@webrtc.org

Review-Url: https://codereview.webrtc.org/2483173002
Cr-Commit-Position: refs/heads/master@{#15051}
2016-11-12 17:53:08 +00:00

104 lines
3.1 KiB
C++

/*
* Copyright 2015 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 "webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.h"
#include "webrtc/base/logging.h"
#include "webrtc/media/base/codec.h"
#if defined(WEBRTC_IOS)
#include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h"
#include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h"
#endif
// TODO(kthelgason): delete this when CreateVideoDecoder takes
// a cricket::VideoCodec instead of webrtc::VideoCodecType.
static const char* NameFromCodecType(webrtc::VideoCodecType type) {
switch (type) {
case webrtc::kVideoCodecVP8:
return cricket::kVp8CodecName;
case webrtc::kVideoCodecVP9:
return cricket::kVp9CodecName;
case webrtc::kVideoCodecH264:
return cricket::kH264CodecName;
default:
return "Unknown codec";
}
}
namespace webrtc {
// VideoToolboxVideoEncoderFactory
VideoToolboxVideoEncoderFactory::VideoToolboxVideoEncoderFactory() {
// Hardware H264 encoding only supported on iOS for now.
#if defined(WEBRTC_IOS)
supported_codecs_.push_back(cricket::VideoCodec(cricket::kH264CodecName));
#endif
}
VideoToolboxVideoEncoderFactory::~VideoToolboxVideoEncoderFactory() {}
VideoEncoder* VideoToolboxVideoEncoderFactory::CreateVideoEncoder(
const cricket::VideoCodec& codec) {
#if defined(WEBRTC_IOS)
if (FindMatchingCodec(supported_codecs_, codec)) {
LOG(LS_INFO) << "Creating HW encoder for " << codec.name;
return new H264VideoToolboxEncoder();
}
#endif
LOG(LS_INFO) << "No HW encoder found for codec " << codec.name;
return nullptr;
}
void VideoToolboxVideoEncoderFactory::DestroyVideoEncoder(
VideoEncoder* encoder) {
#if defined(WEBRTC_IOS)
delete encoder;
encoder = nullptr;
#endif
}
const std::vector<cricket::VideoCodec>&
VideoToolboxVideoEncoderFactory::supported_codecs() const {
return supported_codecs_;
}
// VideoToolboxVideoDecoderFactory
VideoToolboxVideoDecoderFactory::VideoToolboxVideoDecoderFactory() {
#if defined(WEBRTC_IOS)
supported_codecs_.push_back(cricket::VideoCodec("H264"));
#endif
}
VideoToolboxVideoDecoderFactory::~VideoToolboxVideoDecoderFactory() {}
VideoDecoder* VideoToolboxVideoDecoderFactory::CreateVideoDecoder(
VideoCodecType type) {
const auto codec = cricket::VideoCodec(NameFromCodecType(type));
#if defined(WEBRTC_IOS)
if (FindMatchingCodec(supported_codecs_, codec)) {
LOG(LS_INFO) << "Creating HW decoder for " << codec.name;
return new H264VideoToolboxDecoder();
}
#endif
LOG(LS_INFO) << "No HW decoder found for codec " << codec.name;
return nullptr;
}
void VideoToolboxVideoDecoderFactory::DestroyVideoDecoder(
VideoDecoder* decoder) {
#if defined(WEBRTC_IOS)
delete decoder;
decoder = nullptr;
#endif
}
} // namespace webrtc