OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 #include "webrtc/base/checks.h" |
11 #include "webrtc/modules/video_coding/frame_object.h" | 12 #include "webrtc/modules/video_coding/frame_object.h" |
12 #include "webrtc/modules/video_coding/packet_buffer.h" | 13 #include "webrtc/modules/video_coding/packet_buffer.h" |
13 | 14 |
14 namespace webrtc { | 15 namespace webrtc { |
15 namespace video_coding { | 16 namespace video_coding { |
16 | 17 |
17 FrameObject::FrameObject() | 18 FrameObject::FrameObject() |
18 : picture_id(0), | 19 : picture_id(0), |
19 spatial_layer(0), | 20 spatial_layer(0), |
20 timestamp(0), | 21 timestamp(0), |
21 num_references(0), | 22 num_references(0), |
22 inter_layer_predicted(false) {} | 23 inter_layer_predicted(false) {} |
23 | 24 |
24 RtpFrameObject::RtpFrameObject(PacketBuffer* packet_buffer, | 25 RtpFrameObject::RtpFrameObject(PacketBuffer* packet_buffer, |
25 uint16_t first_seq_num, | 26 uint16_t first_seq_num, |
26 uint16_t last_seq_num, | 27 uint16_t last_seq_num, |
27 size_t frame_size, | 28 size_t frame_size, |
28 int times_nacked, | 29 int times_nacked, |
29 int64_t received_time) | 30 int64_t received_time) |
30 : packet_buffer_(packet_buffer), | 31 : packet_buffer_(packet_buffer), |
31 first_seq_num_(first_seq_num), | 32 first_seq_num_(first_seq_num), |
32 last_seq_num_(last_seq_num), | 33 last_seq_num_(last_seq_num), |
33 received_time_(received_time), | 34 received_time_(received_time), |
34 times_nacked_(times_nacked) { | 35 times_nacked_(times_nacked) { |
35 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num); | 36 VCMPacket* first_packet = packet_buffer_->GetPacket(first_seq_num); |
36 if (packet) { | 37 RTC_DCHECK(first_packet); |
37 // RtpFrameObject members | |
38 frame_type_ = packet->frameType; | |
39 codec_type_ = packet->codec; | |
40 | 38 |
41 // TODO(philipel): Remove when encoded image is replaced by FrameObject. | 39 // RtpFrameObject members |
42 // VCMEncodedFrame members | 40 frame_type_ = first_packet->frameType; |
43 CopyCodecSpecific(&packet->video_header); | 41 codec_type_ = first_packet->codec; |
44 _completeFrame = true; | |
45 _payloadType = packet->payloadType; | |
46 _timeStamp = packet->timestamp; | |
47 ntp_time_ms_ = packet->ntp_time_ms_; | |
48 | 42 |
49 // Since FFmpeg use an optimized bitstream reader that reads in chunks of | 43 // TODO(philipel): Remove when encoded image is replaced by FrameObject. |
50 // 32/64 bits we have to add at least that much padding to the buffer | 44 // VCMEncodedFrame members |
51 // to make sure the decoder doesn't read out of bounds. | 45 CopyCodecSpecific(&first_packet->video_header); |
52 // NOTE! EncodedImage::_size is the size of the buffer (think capacity of | 46 _completeFrame = true; |
53 // an std::vector) and EncodedImage::_length is the actual size of | 47 _payloadType = first_packet->payloadType; |
54 // the bitstream (think size of an std::vector). | 48 _timeStamp = first_packet->timestamp; |
55 if (codec_type_ == kVideoCodecH264) | 49 ntp_time_ms_ = first_packet->ntp_time_ms_; |
56 _size = frame_size + EncodedImage::kBufferPaddingBytesH264; | |
57 else | |
58 _size = frame_size; | |
59 | 50 |
60 _buffer = new uint8_t[_size]; | 51 // Since FFmpeg use an optimized bitstream reader that reads in chunks of |
61 _length = frame_size; | 52 // 32/64 bits we have to add at least that much padding to the buffer |
62 _frameType = packet->frameType; | 53 // to make sure the decoder doesn't read out of bounds. |
63 GetBitstream(_buffer); | 54 // NOTE! EncodedImage::_size is the size of the buffer (think capacity of |
| 55 // an std::vector) and EncodedImage::_length is the actual size of |
| 56 // the bitstream (think size of an std::vector). |
| 57 if (codec_type_ == kVideoCodecH264) |
| 58 _size = frame_size + EncodedImage::kBufferPaddingBytesH264; |
| 59 else |
| 60 _size = frame_size; |
64 | 61 |
65 // FrameObject members | 62 _buffer = new uint8_t[_size]; |
66 timestamp = packet->timestamp; | 63 _length = frame_size; |
67 } | 64 _frameType = first_packet->frameType; |
| 65 GetBitstream(_buffer); |
| 66 |
| 67 // FrameObject members |
| 68 timestamp = first_packet->timestamp; |
| 69 |
| 70 VCMPacket* last_packet = packet_buffer_->GetPacket(last_seq_num); |
| 71 RTC_DCHECK(last_packet && last_packet->markerBit); |
| 72 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ |
| 73 // ts_126114v120700p.pdf Section 7.4.5. |
| 74 // The MTSI client shall add the payload bytes as defined in this clause |
| 75 // onto the last RTP packet in each group of packets which make up a key |
| 76 // frame (I-frame or IDR frame in H.264 (AVC), or an IRAP picture in H.265 |
| 77 // (HEVC)). |
| 78 rotation_ = last_packet->video_header.rotation; |
| 79 _rotation_set = true; |
68 } | 80 } |
69 | 81 |
70 RtpFrameObject::~RtpFrameObject() { | 82 RtpFrameObject::~RtpFrameObject() { |
71 packet_buffer_->ReturnFrame(this); | 83 packet_buffer_->ReturnFrame(this); |
72 } | 84 } |
73 | 85 |
74 uint16_t RtpFrameObject::first_seq_num() const { | 86 uint16_t RtpFrameObject::first_seq_num() const { |
75 return first_seq_num_; | 87 return first_seq_num_; |
76 } | 88 } |
77 | 89 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 rtc::Optional<RTPVideoTypeHeader> RtpFrameObject::GetCodecHeader() const { | 122 rtc::Optional<RTPVideoTypeHeader> RtpFrameObject::GetCodecHeader() const { |
111 rtc::CritScope lock(&packet_buffer_->crit_); | 123 rtc::CritScope lock(&packet_buffer_->crit_); |
112 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num_); | 124 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num_); |
113 if (!packet) | 125 if (!packet) |
114 return rtc::Optional<RTPVideoTypeHeader>(); | 126 return rtc::Optional<RTPVideoTypeHeader>(); |
115 return rtc::Optional<RTPVideoTypeHeader>(packet->video_header.codecHeader); | 127 return rtc::Optional<RTPVideoTypeHeader>(packet->video_header.codecHeader); |
116 } | 128 } |
117 | 129 |
118 } // namespace video_coding | 130 } // namespace video_coding |
119 } // namespace webrtc | 131 } // namespace webrtc |
OLD | NEW |