Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/VideoToolbox/videocodecfactory.mm

Issue 2977213002: Reland of Injectable Obj-C video codecs (Closed)
Patch Set: Add checks to make sure destroy is called Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10 #include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/videocodecfactory.h"
11
12 #include "webrtc/common_video/h264/profile_level_id.h"
13 #include "webrtc/media/base/codec.h"
14 #include "webrtc/rtc_base/logging.h"
15 #include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.h"
16 #include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.h"
17 #include "webrtc/system_wrappers/include/field_trial.h"
18
19 namespace webrtc {
20
21 namespace {
22 const char kHighProfileExperiment[] = "WebRTC-H264HighProfile";
23
24 bool IsHighProfileEnabled() {
25 return field_trial::IsEnabled(kHighProfileExperiment);
26 }
27 }
28
29 // VideoToolboxVideoEncoderFactory
30
31 VideoToolboxVideoEncoderFactory::VideoToolboxVideoEncoderFactory() {}
32
33 VideoToolboxVideoEncoderFactory::~VideoToolboxVideoEncoderFactory() {}
34
35 VideoEncoder* VideoToolboxVideoEncoderFactory::CreateVideoEncoder(
36 const cricket::VideoCodec& codec) {
37 if (FindMatchingCodec(supported_codecs_, codec)) {
38 LOG(LS_INFO) << "Creating HW encoder for " << codec.name;
39 return new H264VideoToolboxEncoder(codec);
40 }
41 LOG(LS_INFO) << "No HW encoder found for codec " << codec.name;
42 return nullptr;
43 }
44
45 void VideoToolboxVideoEncoderFactory::DestroyVideoEncoder(VideoEncoder* encoder) {
46 delete encoder;
47 encoder = nullptr;
48 }
49
50 const std::vector<cricket::VideoCodec>& VideoToolboxVideoEncoderFactory::support ed_codecs() const {
51 supported_codecs_.clear();
52
53 // TODO(magjed): Enumerate actual level instead of using hardcoded level 3.1.
54 // Level 3.1 is 1280x720@30fps which is enough for now.
55 const H264::Level level = H264::kLevel3_1;
56
57 if (IsHighProfileEnabled()) {
58 cricket::VideoCodec constrained_high(cricket::kH264CodecName);
59 const H264::ProfileLevelId constrained_high_profile(H264::kProfileConstraine dHigh, level);
60 constrained_high.SetParam(cricket::kH264FmtpProfileLevelId,
61 *H264::ProfileLevelIdToString(constrained_high_pro file));
62 constrained_high.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1");
63 constrained_high.SetParam(cricket::kH264FmtpPacketizationMode, "1");
64 supported_codecs_.push_back(constrained_high);
65 }
66
67 cricket::VideoCodec constrained_baseline(cricket::kH264CodecName);
68 const H264::ProfileLevelId constrained_baseline_profile(H264::kProfileConstrai nedBaseline, level);
69 constrained_baseline.SetParam(cricket::kH264FmtpProfileLevelId,
70 *H264::ProfileLevelIdToString(constrained_baseli ne_profile));
71 constrained_baseline.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1");
72 constrained_baseline.SetParam(cricket::kH264FmtpPacketizationMode, "1");
73 supported_codecs_.push_back(constrained_baseline);
74
75 return supported_codecs_;
76 }
77
78 // VideoToolboxVideoDecoderFactory
79
80 VideoToolboxVideoDecoderFactory::VideoToolboxVideoDecoderFactory() {
81 supported_codecs_.push_back(cricket::VideoCodec("H264"));
82 }
83
84 VideoToolboxVideoDecoderFactory::~VideoToolboxVideoDecoderFactory() {}
85
86 VideoDecoder* VideoToolboxVideoDecoderFactory::CreateVideoDecoder(VideoCodecType type) {
87 const rtc::Optional<const char*> codec_name = CodecTypeToPayloadName(type);
88 if (!codec_name) {
89 LOG(LS_ERROR) << "Invalid codec type: " << type;
90 return nullptr;
91 }
92 const cricket::VideoCodec codec(*codec_name);
93 if (FindMatchingCodec(supported_codecs_, codec)) {
94 LOG(LS_INFO) << "Creating HW decoder for " << codec.name;
95 return new H264VideoToolboxDecoder();
96 }
97 LOG(LS_INFO) << "No HW decoder found for codec " << codec.name;
98 return nullptr;
99 }
100
101 void VideoToolboxVideoDecoderFactory::DestroyVideoDecoder(VideoDecoder* decoder) {
102 delete decoder;
103 decoder = nullptr;
104 }
105
106 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698