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 "RTCRtpFragmentationHeader+Private.h" 12 13#include "modules/include/module_common_types.h" 14 15@implementation RTC_OBJC_TYPE (RTCRtpFragmentationHeader) 16(Private) 17 18 - (instancetype)initWithNativeFragmentationHeader 19 : (const webrtc::RTPFragmentationHeader *)fragmentationHeader { 20 if (self = [super init]) { 21 if (fragmentationHeader) { 22 int count = fragmentationHeader->fragmentationVectorSize; 23 NSMutableArray *offsets = [NSMutableArray array]; 24 NSMutableArray *lengths = [NSMutableArray array]; 25 NSMutableArray *timeDiffs = [NSMutableArray array]; 26 NSMutableArray *plTypes = [NSMutableArray array]; 27 for (int i = 0; i < count; ++i) { 28 [offsets addObject:@(fragmentationHeader->fragmentationOffset[i])]; 29 [lengths addObject:@(fragmentationHeader->fragmentationLength[i])]; 30 [timeDiffs addObject:@(0)]; 31 [plTypes addObject:@(0)]; 32 } 33 self.fragmentationOffset = [offsets copy]; 34 self.fragmentationLength = [lengths copy]; 35 self.fragmentationTimeDiff = [timeDiffs copy]; 36 self.fragmentationPlType = [plTypes copy]; 37 } 38 } 39 40 return self; 41} 42 43- (std::unique_ptr<webrtc::RTPFragmentationHeader>)createNativeFragmentationHeader { 44 auto fragmentationHeader = 45 std::unique_ptr<webrtc::RTPFragmentationHeader>(new webrtc::RTPFragmentationHeader); 46 fragmentationHeader->VerifyAndAllocateFragmentationHeader(self.fragmentationOffset.count); 47 for (NSUInteger i = 0; i < self.fragmentationOffset.count; ++i) { 48 fragmentationHeader->fragmentationOffset[i] = (size_t)self.fragmentationOffset[i].unsignedIntValue; 49 fragmentationHeader->fragmentationLength[i] = (size_t)self.fragmentationLength[i].unsignedIntValue; 50 } 51 52 return fragmentationHeader; 53} 54 55@end 56