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/base/checks.h" |
| 12 #include "webrtc/common_video/h264/h264_common.h" |
12 #include "webrtc/modules/video_coding/frame_object.h" | 13 #include "webrtc/modules/video_coding/frame_object.h" |
13 #include "webrtc/modules/video_coding/packet_buffer.h" | 14 #include "webrtc/modules/video_coding/packet_buffer.h" |
14 | 15 |
15 namespace webrtc { | 16 namespace webrtc { |
16 namespace video_coding { | 17 namespace video_coding { |
17 | 18 |
18 FrameObject::FrameObject() | 19 FrameObject::FrameObject() |
19 : picture_id(0), | 20 : picture_id(0), |
20 spatial_layer(0), | 21 spatial_layer(0), |
21 timestamp(0), | 22 timestamp(0), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // NOTE! EncodedImage::_size is the size of the buffer (think capacity of | 59 // NOTE! EncodedImage::_size is the size of the buffer (think capacity of |
59 // an std::vector) and EncodedImage::_length is the actual size of | 60 // an std::vector) and EncodedImage::_length is the actual size of |
60 // the bitstream (think size of an std::vector). | 61 // the bitstream (think size of an std::vector). |
61 if (codec_type_ == kVideoCodecH264) | 62 if (codec_type_ == kVideoCodecH264) |
62 _size = frame_size + EncodedImage::kBufferPaddingBytesH264; | 63 _size = frame_size + EncodedImage::kBufferPaddingBytesH264; |
63 else | 64 else |
64 _size = frame_size; | 65 _size = frame_size; |
65 | 66 |
66 _buffer = new uint8_t[_size]; | 67 _buffer = new uint8_t[_size]; |
67 _length = frame_size; | 68 _length = frame_size; |
68 _frameType = first_packet->frameType; | 69 |
| 70 // For H264 frames we can't determine the frame type by just looking at the |
| 71 // first packet. Instead we consider the frame to be a keyframe if it |
| 72 // contains an IDR NALU. |
| 73 if (codec_type_ == kVideoCodecH264) { |
| 74 _frameType = kVideoFrameDelta; |
| 75 frame_type_ = kVideoFrameDelta; |
| 76 for (uint16_t seq_num = first_seq_num; |
| 77 seq_num != last_seq_num + 1 && _frameType == kVideoFrameDelta; |
| 78 ++seq_num) { |
| 79 VCMPacket* packet = packet_buffer_->GetPacket(seq_num); |
| 80 RTC_DCHECK(packet); |
| 81 const RTPVideoHeaderH264& header = packet->video_header.codecHeader.H264; |
| 82 for (size_t i = 0; i < header.nalus_length; ++i) { |
| 83 if (header.nalus[i].type == H264::NaluType::kIdr) { |
| 84 _frameType = kVideoFrameKey; |
| 85 frame_type_ = kVideoFrameKey; |
| 86 break; |
| 87 } |
| 88 } |
| 89 } |
| 90 } else { |
| 91 _frameType = first_packet->frameType; |
| 92 frame_type_ = first_packet->frameType; |
| 93 } |
| 94 |
69 GetBitstream(_buffer); | 95 GetBitstream(_buffer); |
70 _encodedWidth = first_packet->width; | 96 _encodedWidth = first_packet->width; |
71 _encodedHeight = first_packet->height; | 97 _encodedHeight = first_packet->height; |
72 | 98 |
73 // FrameObject members | 99 // FrameObject members |
74 timestamp = first_packet->timestamp; | 100 timestamp = first_packet->timestamp; |
75 | 101 |
76 VCMPacket* last_packet = packet_buffer_->GetPacket(last_seq_num); | 102 VCMPacket* last_packet = packet_buffer_->GetPacket(last_seq_num); |
77 RTC_DCHECK(last_packet && last_packet->markerBit); | 103 RTC_DCHECK(last_packet && last_packet->markerBit); |
78 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ | 104 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 rtc::Optional<RTPVideoTypeHeader> RtpFrameObject::GetCodecHeader() const { | 158 rtc::Optional<RTPVideoTypeHeader> RtpFrameObject::GetCodecHeader() const { |
133 rtc::CritScope lock(&packet_buffer_->crit_); | 159 rtc::CritScope lock(&packet_buffer_->crit_); |
134 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num_); | 160 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num_); |
135 if (!packet) | 161 if (!packet) |
136 return rtc::Optional<RTPVideoTypeHeader>(); | 162 return rtc::Optional<RTPVideoTypeHeader>(); |
137 return rtc::Optional<RTPVideoTypeHeader>(packet->video_header.codecHeader); | 163 return rtc::Optional<RTPVideoTypeHeader>(packet->video_header.codecHeader); |
138 } | 164 } |
139 | 165 |
140 } // namespace video_coding | 166 } // namespace video_coding |
141 } // namespace webrtc | 167 } // namespace webrtc |
OLD | NEW |