OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import "WebRTC/RTCVideoCodec.h" | 11 #import "WebRTC/RTCVideoCodec.h" |
12 | 12 |
13 #import "RTCVideoCodec+Private.h" | 13 #import "RTCVideoCodec+Private.h" |
14 | 14 |
| 15 #include "webrtc/rtc_base/safe_conversions.h" |
| 16 |
15 @implementation RTCEncodedImage | 17 @implementation RTCEncodedImage |
16 | 18 |
17 @synthesize buffer = _buffer; | 19 @synthesize buffer = _buffer; |
18 @synthesize encodedWidth = _encodedWidth; | 20 @synthesize encodedWidth = _encodedWidth; |
19 @synthesize encodedHeight = _encodedHeight; | 21 @synthesize encodedHeight = _encodedHeight; |
20 @synthesize timeStamp = _timeStamp; | 22 @synthesize timeStamp = _timeStamp; |
21 @synthesize captureTimeMs = _captureTimeMs; | 23 @synthesize captureTimeMs = _captureTimeMs; |
22 @synthesize ntpTimeMs = _ntpTimeMs; | 24 @synthesize ntpTimeMs = _ntpTimeMs; |
23 @synthesize flags = _flags; | 25 @synthesize flags = _flags; |
24 @synthesize encodeStartMs = _encodeStartMs; | 26 @synthesize encodeStartMs = _encodeStartMs; |
25 @synthesize encodeFinishMs = _encodeFinishMs; | 27 @synthesize encodeFinishMs = _encodeFinishMs; |
26 @synthesize frameType = _frameType; | 28 @synthesize frameType = _frameType; |
27 @synthesize rotation = _rotation; | 29 @synthesize rotation = _rotation; |
28 @synthesize completeFrame = _completeFrame; | 30 @synthesize completeFrame = _completeFrame; |
29 @synthesize qp = _qp; | 31 @synthesize qp = _qp; |
30 @synthesize contentType = _contentType; | 32 @synthesize contentType = _contentType; |
31 | 33 |
32 - (instancetype)initWithNativeEncodedImage:(webrtc::EncodedImage)encodedImage { | 34 - (instancetype)initWithNativeEncodedImage:(webrtc::EncodedImage)encodedImage { |
33 if (self = [super init]) { | 35 if (self = [super init]) { |
34 // Wrap the buffer in NSData without copying, do not take ownership. | 36 // Wrap the buffer in NSData without copying, do not take ownership. |
35 _buffer = [NSData dataWithBytesNoCopy:encodedImage._buffer | 37 _buffer = [NSData dataWithBytesNoCopy:encodedImage._buffer |
36 length:encodedImage._length | 38 length:encodedImage._length |
37 freeWhenDone:NO]; | 39 freeWhenDone:NO]; |
38 _encodedWidth = encodedImage._encodedWidth; | 40 _encodedWidth = rtc::dchecked_cast<int32_t>(encodedImage._encodedWidth); |
39 _encodedHeight = encodedImage._encodedHeight; | 41 _encodedHeight = rtc::dchecked_cast<int32_t>(encodedImage._encodedHeight); |
40 _timeStamp = encodedImage._timeStamp; | 42 _timeStamp = encodedImage._timeStamp; |
41 _captureTimeMs = encodedImage.capture_time_ms_; | 43 _captureTimeMs = encodedImage.capture_time_ms_; |
42 _ntpTimeMs = encodedImage.ntp_time_ms_; | 44 _ntpTimeMs = encodedImage.ntp_time_ms_; |
43 _flags = encodedImage.timing_.flags; | 45 _flags = encodedImage.timing_.flags; |
44 _encodeStartMs = encodedImage.timing_.encode_start_ms; | 46 _encodeStartMs = encodedImage.timing_.encode_start_ms; |
45 _encodeFinishMs = encodedImage.timing_.encode_finish_ms; | 47 _encodeFinishMs = encodedImage.timing_.encode_finish_ms; |
46 _frameType = (RTCFrameType)encodedImage._frameType; | 48 _frameType = static_cast<RTCFrameType>(encodedImage._frameType); |
47 _rotation = encodedImage.rotation_; | 49 _rotation = static_cast<RTCVideoRotation>(encodedImage.rotation_); |
48 _completeFrame = encodedImage._completeFrame; | 50 _completeFrame = encodedImage._completeFrame; |
49 _qp = encodedImage.qp_ == -1 ? nil : @(encodedImage.qp_); | 51 _qp = encodedImage.qp_ == -1 ? nil : @(encodedImage.qp_); |
50 _contentType = (encodedImage.content_type_ == webrtc::VideoContentType::SCRE
ENSHARE) ? | 52 _contentType = (encodedImage.content_type_ == webrtc::VideoContentType::SCRE
ENSHARE) ? |
51 RTCVideoContentTypeScreenshare : | 53 RTCVideoContentTypeScreenshare : |
52 RTCVideoContentTypeUnspecified; | 54 RTCVideoContentTypeUnspecified; |
53 } | 55 } |
54 | 56 |
55 return self; | 57 return self; |
56 } | 58 } |
57 | 59 |
58 - (webrtc::EncodedImage)nativeEncodedImage { | 60 - (webrtc::EncodedImage)nativeEncodedImage { |
59 // Return the pointer without copying. | 61 // Return the pointer without copying. |
60 webrtc::EncodedImage encodedImage( | 62 webrtc::EncodedImage encodedImage( |
61 (uint8_t *)_buffer.bytes, (size_t)_buffer.length, (size_t)_buffer.length); | 63 (uint8_t *)_buffer.bytes, (size_t)_buffer.length, (size_t)_buffer.length); |
62 encodedImage._encodedWidth = _encodedWidth; | 64 encodedImage._encodedWidth = rtc::dchecked_cast<uint32_t>(_encodedWidth); |
63 encodedImage._encodedHeight = _encodedHeight; | 65 encodedImage._encodedHeight = rtc::dchecked_cast<uint32_t>(_encodedHeight); |
64 encodedImage._timeStamp = _timeStamp; | 66 encodedImage._timeStamp = _timeStamp; |
65 encodedImage.capture_time_ms_ = _captureTimeMs; | 67 encodedImage.capture_time_ms_ = _captureTimeMs; |
66 encodedImage.ntp_time_ms_ = _ntpTimeMs; | 68 encodedImage.ntp_time_ms_ = _ntpTimeMs; |
67 encodedImage.timing_.flags = _flags; | 69 encodedImage.timing_.flags = _flags; |
68 encodedImage.timing_.encode_start_ms = _encodeStartMs; | 70 encodedImage.timing_.encode_start_ms = _encodeStartMs; |
69 encodedImage.timing_.encode_finish_ms = _encodeFinishMs; | 71 encodedImage.timing_.encode_finish_ms = _encodeFinishMs; |
70 encodedImage._frameType = webrtc::FrameType(_frameType); | 72 encodedImage._frameType = webrtc::FrameType(_frameType); |
71 encodedImage.rotation_ = webrtc::VideoRotation(_rotation); | 73 encodedImage.rotation_ = webrtc::VideoRotation(_rotation); |
72 encodedImage._completeFrame = _completeFrame; | 74 encodedImage._completeFrame = _completeFrame; |
73 encodedImage.qp_ = _qp ? _qp.intValue : -1; | 75 encodedImage.qp_ = _qp ? _qp.intValue : -1; |
74 encodedImage.content_type_ = (_contentType == RTCVideoContentTypeScreenshare)
? | 76 encodedImage.content_type_ = (_contentType == RTCVideoContentTypeScreenshare)
? |
75 webrtc::VideoContentType::SCREENSHARE : | 77 webrtc::VideoContentType::SCREENSHARE : |
76 webrtc::VideoContentType::UNSPECIFIED; | 78 webrtc::VideoContentType::UNSPECIFIED; |
77 | 79 |
78 return encodedImage; | 80 return encodedImage; |
79 } | 81 } |
80 | 82 |
81 @end | 83 @end |
OLD | NEW |