kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | #import "WebRTC/RTCVideoCodec.h" |
| 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 13 | #include "modules/include/module_common_types.h" |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 14 | |
| 15 | @implementation RTCRtpFragmentationHeader |
| 16 | |
| 17 | @synthesize fragmentationOffset = _fragmentationOffset; |
| 18 | @synthesize fragmentationLength = _fragmentationLength; |
| 19 | @synthesize fragmentationTimeDiff = _fragmentationTimeDiff; |
| 20 | @synthesize fragmentationPlType = _fragmentationPlType; |
| 21 | |
magjed | 8eab09c | 2017-07-31 02:56:35 -0700 | [diff] [blame] | 22 | - (instancetype)initWithNativeFragmentationHeader: |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 23 | (const webrtc::RTPFragmentationHeader *)fragmentationHeader { |
| 24 | if (self = [super init]) { |
| 25 | if (fragmentationHeader) { |
| 26 | int count = fragmentationHeader->fragmentationVectorSize; |
| 27 | NSMutableArray *offsets = [NSMutableArray array]; |
| 28 | NSMutableArray *lengths = [NSMutableArray array]; |
| 29 | NSMutableArray *timeDiffs = [NSMutableArray array]; |
| 30 | NSMutableArray *plTypes = [NSMutableArray array]; |
| 31 | for (int i = 0; i < count; ++i) { |
| 32 | [offsets addObject:@(fragmentationHeader->fragmentationOffset[i])]; |
| 33 | [lengths addObject:@(fragmentationHeader->fragmentationLength[i])]; |
| 34 | [timeDiffs addObject:@(fragmentationHeader->fragmentationTimeDiff[i])]; |
| 35 | [plTypes addObject:@(fragmentationHeader->fragmentationPlType[i])]; |
| 36 | } |
| 37 | _fragmentationOffset = [offsets copy]; |
| 38 | _fragmentationLength = [lengths copy]; |
| 39 | _fragmentationTimeDiff = [timeDiffs copy]; |
| 40 | _fragmentationPlType = [plTypes copy]; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return self; |
| 45 | } |
| 46 | |
magjed | 8eab09c | 2017-07-31 02:56:35 -0700 | [diff] [blame] | 47 | - (std::unique_ptr<webrtc::RTPFragmentationHeader>)createNativeFragmentationHeader { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 48 | auto fragmentationHeader = |
| 49 | std::unique_ptr<webrtc::RTPFragmentationHeader>(new webrtc::RTPFragmentationHeader); |
| 50 | fragmentationHeader->VerifyAndAllocateFragmentationHeader(_fragmentationOffset.count); |
| 51 | for (NSUInteger i = 0; i < _fragmentationOffset.count; ++i) { |
| 52 | fragmentationHeader->fragmentationOffset[i] = (size_t)_fragmentationOffset[i].unsignedIntValue; |
| 53 | fragmentationHeader->fragmentationLength[i] = (size_t)_fragmentationLength[i].unsignedIntValue; |
| 54 | fragmentationHeader->fragmentationTimeDiff[i] = |
| 55 | (uint16_t)_fragmentationOffset[i].unsignedIntValue; |
| 56 | fragmentationHeader->fragmentationPlType[i] = (uint8_t)_fragmentationOffset[i].unsignedIntValue; |
| 57 | } |
| 58 | |
| 59 | return fragmentationHeader; |
| 60 | } |
| 61 | |
| 62 | @end |