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 | |
| 13 | #import "RTCVideoCodec+Private.h" |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 15 | #include "rtc_base/safe_conversions.h" |
magjed | 43467b0 | 2017-09-12 02:29:43 -0700 | [diff] [blame] | 16 | |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 17 | @implementation RTCEncodedImage |
| 18 | |
| 19 | @synthesize buffer = _buffer; |
| 20 | @synthesize encodedWidth = _encodedWidth; |
| 21 | @synthesize encodedHeight = _encodedHeight; |
| 22 | @synthesize timeStamp = _timeStamp; |
| 23 | @synthesize captureTimeMs = _captureTimeMs; |
| 24 | @synthesize ntpTimeMs = _ntpTimeMs; |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 25 | @synthesize flags = _flags; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 26 | @synthesize encodeStartMs = _encodeStartMs; |
| 27 | @synthesize encodeFinishMs = _encodeFinishMs; |
| 28 | @synthesize frameType = _frameType; |
| 29 | @synthesize rotation = _rotation; |
| 30 | @synthesize completeFrame = _completeFrame; |
| 31 | @synthesize qp = _qp; |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 32 | @synthesize contentType = _contentType; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 33 | |
| 34 | - (instancetype)initWithNativeEncodedImage:(webrtc::EncodedImage)encodedImage { |
| 35 | if (self = [super init]) { |
| 36 | // Wrap the buffer in NSData without copying, do not take ownership. |
| 37 | _buffer = [NSData dataWithBytesNoCopy:encodedImage._buffer |
| 38 | length:encodedImage._length |
| 39 | freeWhenDone:NO]; |
magjed | 43467b0 | 2017-09-12 02:29:43 -0700 | [diff] [blame] | 40 | _encodedWidth = rtc::dchecked_cast<int32_t>(encodedImage._encodedWidth); |
| 41 | _encodedHeight = rtc::dchecked_cast<int32_t>(encodedImage._encodedHeight); |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 42 | _timeStamp = encodedImage._timeStamp; |
| 43 | _captureTimeMs = encodedImage.capture_time_ms_; |
| 44 | _ntpTimeMs = encodedImage.ntp_time_ms_; |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 45 | _flags = encodedImage.timing_.flags; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 46 | _encodeStartMs = encodedImage.timing_.encode_start_ms; |
| 47 | _encodeFinishMs = encodedImage.timing_.encode_finish_ms; |
magjed | 43467b0 | 2017-09-12 02:29:43 -0700 | [diff] [blame] | 48 | _frameType = static_cast<RTCFrameType>(encodedImage._frameType); |
| 49 | _rotation = static_cast<RTCVideoRotation>(encodedImage.rotation_); |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 50 | _completeFrame = encodedImage._completeFrame; |
| 51 | _qp = encodedImage.qp_ == -1 ? nil : @(encodedImage.qp_); |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 52 | _contentType = (encodedImage.content_type_ == webrtc::VideoContentType::SCREENSHARE) ? |
| 53 | RTCVideoContentTypeScreenshare : |
| 54 | RTCVideoContentTypeUnspecified; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | return self; |
| 58 | } |
| 59 | |
magjed | 8eab09c | 2017-07-31 02:56:35 -0700 | [diff] [blame] | 60 | - (webrtc::EncodedImage)nativeEncodedImage { |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 61 | // Return the pointer without copying. |
| 62 | webrtc::EncodedImage encodedImage( |
| 63 | (uint8_t *)_buffer.bytes, (size_t)_buffer.length, (size_t)_buffer.length); |
magjed | 43467b0 | 2017-09-12 02:29:43 -0700 | [diff] [blame] | 64 | encodedImage._encodedWidth = rtc::dchecked_cast<uint32_t>(_encodedWidth); |
| 65 | encodedImage._encodedHeight = rtc::dchecked_cast<uint32_t>(_encodedHeight); |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 66 | encodedImage._timeStamp = _timeStamp; |
| 67 | encodedImage.capture_time_ms_ = _captureTimeMs; |
| 68 | encodedImage.ntp_time_ms_ = _ntpTimeMs; |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 69 | encodedImage.timing_.flags = _flags; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 70 | encodedImage.timing_.encode_start_ms = _encodeStartMs; |
| 71 | encodedImage.timing_.encode_finish_ms = _encodeFinishMs; |
| 72 | encodedImage._frameType = webrtc::FrameType(_frameType); |
| 73 | encodedImage.rotation_ = webrtc::VideoRotation(_rotation); |
| 74 | encodedImage._completeFrame = _completeFrame; |
| 75 | encodedImage.qp_ = _qp ? _qp.intValue : -1; |
magjed | 73c0eb5 | 2017-08-07 06:55:28 -0700 | [diff] [blame] | 76 | encodedImage.content_type_ = (_contentType == RTCVideoContentTypeScreenshare) ? |
| 77 | webrtc::VideoContentType::SCREENSHARE : |
| 78 | webrtc::VideoContentType::UNSPECIFIED; |
kthelgason | fb14312 | 2017-07-25 07:55:58 -0700 | [diff] [blame] | 79 | |
| 80 | return encodedImage; |
| 81 | } |
| 82 | |
| 83 | @end |