Anders Carlsson | 79ce820 | 2018-06-01 12:51:09 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018 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 | */ |
| 11 | |
| 12 | #import "WebRTC/RTCVideoCodecH264.h" |
| 13 | |
| 14 | #include "media/base/h264_profile_level_id.h" |
| 15 | |
| 16 | @interface RTCH264ProfileLevelId () |
| 17 | |
| 18 | @property(nonatomic, assign) RTCH264Profile profile; |
| 19 | @property(nonatomic, assign) RTCH264Level level; |
| 20 | @property(nonatomic, strong) NSString *hexString; |
| 21 | |
| 22 | @end |
| 23 | |
| 24 | @implementation RTCH264ProfileLevelId |
| 25 | |
| 26 | @synthesize profile = _profile; |
| 27 | @synthesize level = _level; |
| 28 | @synthesize hexString = _hexString; |
| 29 | |
| 30 | - (instancetype)initWithHexString:(NSString *)hexString { |
| 31 | if (self = [super init]) { |
| 32 | self.hexString = hexString; |
| 33 | |
| 34 | rtc::Optional<webrtc::H264::ProfileLevelId> profile_level_id = |
| 35 | webrtc::H264::ParseProfileLevelId([hexString cStringUsingEncoding:NSUTF8StringEncoding]); |
| 36 | if (profile_level_id.has_value()) { |
| 37 | self.profile = static_cast<RTCH264Profile>(profile_level_id->profile); |
| 38 | self.level = static_cast<RTCH264Level>(profile_level_id->level); |
| 39 | } |
| 40 | } |
| 41 | return self; |
| 42 | } |
| 43 | |
| 44 | - (instancetype)initWithProfile:(RTCH264Profile)profile level:(RTCH264Level)level { |
| 45 | if (self = [super init]) { |
| 46 | self.profile = profile; |
| 47 | self.level = level; |
| 48 | |
| 49 | rtc::Optional<std::string> hex_string = |
| 50 | webrtc::H264::ProfileLevelIdToString(webrtc::H264::ProfileLevelId( |
| 51 | static_cast<webrtc::H264::Profile>(profile), static_cast<webrtc::H264::Level>(level))); |
| 52 | self.hexString = |
| 53 | [NSString stringWithCString:hex_string.value_or("").c_str() encoding:NSUTF8StringEncoding]; |
| 54 | } |
| 55 | return self; |
| 56 | } |
| 57 | |
| 58 | @end |