webrtc_m130/webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.cc
Kári Tristan Helgason cbe7435288 Reland of Add a webrtc{en,de}coderfactory implementation for VideoToolbox (patchset #1 id:1 of https://codereview.webrtc.org/2483273002/ )
Reason for revert:
Fix gyp build

Original issue's description:
> Revert of Add a webrtc{en,de}coderfactory implementation for VideoToolbox (patchset #2 id:20001 of https://codereview.webrtc.org/2463313002/ )
>
> Reason for revert:
> Broke dependent project because the .gn changes weren't accompanied by corresponding .gyp changes.
>
> Original issue's description:
> > Add a webrtc{en,de}coderfactory implementation for VideoToolbox
> >
> > This CL removes the coupling of the VideoToolbox h264 implementation
> > to the generic h264 code. The files have been moved into sdb/obj/Framework
> > and all dependency on them has been removed from the rest of WebRTC.
> > We now add it as an external encoder via a factory supplied to the
> > CreatePeerConnectionFactory call. This also brings the iOS implementation
> > closer to what we do on Android for MediaCodec.
> >
> > BUG=webrtc:6619
> >
> > Committed: https://crrev.com/6a5047dad31f14f53dd9f8bc1ecde19e1dede2e4
> > Cr-Commit-Position: refs/heads/master@{#14953}
>
> TBR=magjed@webrtc.org,stefan@webrtc.org,kthelgason@webrtc.org
> BUG=webrtc:6619
>
> Committed: https://crrev.com/d69ad84420d9c0e1c11450c352f6c92e7c9583f1
> Cr-Commit-Position: refs/heads/master@{#14985}

R=magjed@webrtc.org
TBR=kwiberg@webrtc.org, magjed@webrtc.org, stefan@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:6619

Review URL: https://codereview.webrtc.org/2487723004 .

Cr-Commit-Position: refs/heads/master@{#14992}
2016-11-09 09:43:38 +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 (IsCodecSupported(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 (IsCodecSupported(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