blob: fc76921ba3cea674f9a49c0e9a74082723e536d3 [file] [log] [blame]
kthelgasonfb143122017-07-25 07:55:58 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/safe_conversions.h"
magjed43467b02017-09-12 02:29:43 -070016
kthelgasonfb143122017-07-25 07:55:58 -070017@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;
sprangba050a62017-08-18 02:51:12 -070025@synthesize flags = _flags;
kthelgasonfb143122017-07-25 07:55:58 -070026@synthesize encodeStartMs = _encodeStartMs;
27@synthesize encodeFinishMs = _encodeFinishMs;
28@synthesize frameType = _frameType;
29@synthesize rotation = _rotation;
30@synthesize completeFrame = _completeFrame;
31@synthesize qp = _qp;
magjed73c0eb52017-08-07 06:55:28 -070032@synthesize contentType = _contentType;
kthelgasonfb143122017-07-25 07:55:58 -070033
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];
magjed43467b02017-09-12 02:29:43 -070040 _encodedWidth = rtc::dchecked_cast<int32_t>(encodedImage._encodedWidth);
41 _encodedHeight = rtc::dchecked_cast<int32_t>(encodedImage._encodedHeight);
kthelgasonfb143122017-07-25 07:55:58 -070042 _timeStamp = encodedImage._timeStamp;
43 _captureTimeMs = encodedImage.capture_time_ms_;
44 _ntpTimeMs = encodedImage.ntp_time_ms_;
sprangba050a62017-08-18 02:51:12 -070045 _flags = encodedImage.timing_.flags;
kthelgasonfb143122017-07-25 07:55:58 -070046 _encodeStartMs = encodedImage.timing_.encode_start_ms;
47 _encodeFinishMs = encodedImage.timing_.encode_finish_ms;
magjed43467b02017-09-12 02:29:43 -070048 _frameType = static_cast<RTCFrameType>(encodedImage._frameType);
49 _rotation = static_cast<RTCVideoRotation>(encodedImage.rotation_);
kthelgasonfb143122017-07-25 07:55:58 -070050 _completeFrame = encodedImage._completeFrame;
51 _qp = encodedImage.qp_ == -1 ? nil : @(encodedImage.qp_);
magjed73c0eb52017-08-07 06:55:28 -070052 _contentType = (encodedImage.content_type_ == webrtc::VideoContentType::SCREENSHARE) ?
53 RTCVideoContentTypeScreenshare :
54 RTCVideoContentTypeUnspecified;
kthelgasonfb143122017-07-25 07:55:58 -070055 }
56
57 return self;
58}
59
magjed8eab09c2017-07-31 02:56:35 -070060- (webrtc::EncodedImage)nativeEncodedImage {
kthelgasonfb143122017-07-25 07:55:58 -070061 // Return the pointer without copying.
62 webrtc::EncodedImage encodedImage(
63 (uint8_t *)_buffer.bytes, (size_t)_buffer.length, (size_t)_buffer.length);
magjed43467b02017-09-12 02:29:43 -070064 encodedImage._encodedWidth = rtc::dchecked_cast<uint32_t>(_encodedWidth);
65 encodedImage._encodedHeight = rtc::dchecked_cast<uint32_t>(_encodedHeight);
kthelgasonfb143122017-07-25 07:55:58 -070066 encodedImage._timeStamp = _timeStamp;
67 encodedImage.capture_time_ms_ = _captureTimeMs;
68 encodedImage.ntp_time_ms_ = _ntpTimeMs;
sprangba050a62017-08-18 02:51:12 -070069 encodedImage.timing_.flags = _flags;
kthelgasonfb143122017-07-25 07:55:58 -070070 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;
magjed73c0eb52017-08-07 06:55:28 -070076 encodedImage.content_type_ = (_contentType == RTCVideoContentTypeScreenshare) ?
77 webrtc::VideoContentType::SCREENSHARE :
78 webrtc::VideoContentType::UNSPECIFIED;
kthelgasonfb143122017-07-25 07:55:58 -070079
80 return encodedImage;
81}
82
83@end