| 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 | #include "modules/video_coding/encoded_frame.h" |
| 12 |
| 13 | #include <string.h> |
| 14 |
| 15 | #include "absl/types/variant.h" |
| 16 | #include "api/video/video_timing.h" |
| 17 | #include "modules/video_coding/codecs/interface/common_constants.h" |
| 18 | #include "modules/video_coding/codecs/vp8/include/vp8_globals.h" |
| 19 | #include "modules/video_coding/codecs/vp9/include/vp9_globals.h" |
| 20 |
| 21 | namespace webrtc { |
| 22 |
| 23 | VCMEncodedFrame::VCMEncodedFrame() |
| 24 | : webrtc::EncodedImage(), |
| 25 | _renderTimeMs(-1), |
| 26 | _payloadType(0), |
| 27 | _missingFrame(false), |
| 28 | _codec(kVideoCodecGeneric) { |
| 29 | _codecSpecificInfo.codecType = kVideoCodecGeneric; |
| 30 | } |
| 31 |
| 32 | VCMEncodedFrame::VCMEncodedFrame(const VCMEncodedFrame&) = default; |
| 33 |
| 34 | VCMEncodedFrame::~VCMEncodedFrame() { |
| 35 | Reset(); |
| 36 | } |
| 37 |
| 38 | void VCMEncodedFrame::Reset() { |
| 39 | SetTimestamp(0); |
| 40 | SetSpatialIndex(absl::nullopt); |
| 41 | _renderTimeMs = -1; |
| 42 | _payloadType = 0; |
| 43 | _frameType = VideoFrameType::kVideoFrameDelta; |
| 44 | _encodedWidth = 0; |
| 45 | _encodedHeight = 0; |
| 46 | _completeFrame = false; |
| 47 | _missingFrame = false; |
| 48 | set_size(0); |
| 49 | _codecSpecificInfo.codecType = kVideoCodecGeneric; |
| 50 | _codec = kVideoCodecGeneric; |
| 51 | rotation_ = kVideoRotation_0; |
| 52 | content_type_ = VideoContentType::UNSPECIFIED; |
| 53 | timing_.flags = VideoSendTiming::kInvalid; |
| 54 | } |
| 55 |
| 56 | void VCMEncodedFrame::CopyCodecSpecific(const RTPVideoHeader* header) { |
| 57 | if (header) { |
| 58 | switch (header->codec) { |
| 59 | case kVideoCodecVP8: { |
| 60 | const auto& vp8_header = |
| 61 | absl::get<RTPVideoHeaderVP8>(header->video_type_header); |
| 62 | if (_codecSpecificInfo.codecType != kVideoCodecVP8) { |
| 63 | // This is the first packet for this frame. |
| 64 | _codecSpecificInfo.codecSpecific.VP8.temporalIdx = 0; |
| 65 | _codecSpecificInfo.codecSpecific.VP8.layerSync = false; |
| 66 | _codecSpecificInfo.codecSpecific.VP8.keyIdx = -1; |
| 67 | _codecSpecificInfo.codecType = kVideoCodecVP8; |
| 68 | } |
| 69 | _codecSpecificInfo.codecSpecific.VP8.nonReference = |
| 70 | vp8_header.nonReference; |
| 71 | if (vp8_header.temporalIdx != kNoTemporalIdx) { |
| 72 | _codecSpecificInfo.codecSpecific.VP8.temporalIdx = |
| 73 | vp8_header.temporalIdx; |
| 74 | _codecSpecificInfo.codecSpecific.VP8.layerSync = vp8_header.layerSync; |
| 75 | } |
| 76 | if (vp8_header.keyIdx != kNoKeyIdx) { |
| 77 | _codecSpecificInfo.codecSpecific.VP8.keyIdx = vp8_header.keyIdx; |
| 78 | } |
| 79 | break; |
| 80 | } |
| 81 | case kVideoCodecVP9: { |
| 82 | const auto& vp9_header = |
| 83 | absl::get<RTPVideoHeaderVP9>(header->video_type_header); |
| 84 | if (_codecSpecificInfo.codecType != kVideoCodecVP9) { |
| 85 | // This is the first packet for this frame. |
| 86 | _codecSpecificInfo.codecSpecific.VP9.temporal_idx = 0; |
| 87 | _codecSpecificInfo.codecSpecific.VP9.gof_idx = 0; |
| 88 | _codecSpecificInfo.codecSpecific.VP9.inter_layer_predicted = false; |
| 89 | _codecSpecificInfo.codecType = kVideoCodecVP9; |
| 90 | } |
| 91 | _codecSpecificInfo.codecSpecific.VP9.inter_pic_predicted = |
| 92 | vp9_header.inter_pic_predicted; |
| 93 | _codecSpecificInfo.codecSpecific.VP9.flexible_mode = |
| 94 | vp9_header.flexible_mode; |
| 95 | _codecSpecificInfo.codecSpecific.VP9.num_ref_pics = |
| 96 | vp9_header.num_ref_pics; |
| 97 | for (uint8_t r = 0; r < vp9_header.num_ref_pics; ++r) { |
| 98 | _codecSpecificInfo.codecSpecific.VP9.p_diff[r] = |
| 99 | vp9_header.pid_diff[r]; |
| 100 | } |
| 101 | _codecSpecificInfo.codecSpecific.VP9.ss_data_available = |
| 102 | vp9_header.ss_data_available; |
| 103 | if (vp9_header.temporal_idx != kNoTemporalIdx) { |
| 104 | _codecSpecificInfo.codecSpecific.VP9.temporal_idx = |
| 105 | vp9_header.temporal_idx; |
| 106 | _codecSpecificInfo.codecSpecific.VP9.temporal_up_switch = |
| 107 | vp9_header.temporal_up_switch; |
| 108 | } |
| 109 | if (vp9_header.spatial_idx != kNoSpatialIdx) { |
| 110 | _codecSpecificInfo.codecSpecific.VP9.inter_layer_predicted = |
| 111 | vp9_header.inter_layer_predicted; |
| 112 | SetSpatialIndex(vp9_header.spatial_idx); |
| 113 | } |
| 114 | if (vp9_header.gof_idx != kNoGofIdx) { |
| 115 | _codecSpecificInfo.codecSpecific.VP9.gof_idx = vp9_header.gof_idx; |
| 116 | } |
| 117 | if (vp9_header.ss_data_available) { |
| 118 | _codecSpecificInfo.codecSpecific.VP9.num_spatial_layers = |
| 119 | vp9_header.num_spatial_layers; |
| 120 | _codecSpecificInfo.codecSpecific.VP9 |
| 121 | .spatial_layer_resolution_present = |
| 122 | vp9_header.spatial_layer_resolution_present; |
| 123 | if (vp9_header.spatial_layer_resolution_present) { |
| 124 | for (size_t i = 0; i < vp9_header.num_spatial_layers; ++i) { |
| 125 | _codecSpecificInfo.codecSpecific.VP9.width[i] = |
| 126 | vp9_header.width[i]; |
| 127 | _codecSpecificInfo.codecSpecific.VP9.height[i] = |
| 128 | vp9_header.height[i]; |
| 129 | } |
| 130 | } |
| 131 | _codecSpecificInfo.codecSpecific.VP9.gof.CopyGofInfoVP9( |
| 132 | vp9_header.gof); |
| 133 | } |
| 134 | break; |
| 135 | } |
| 136 | case kVideoCodecH264: { |
| 137 | _codecSpecificInfo.codecType = kVideoCodecH264; |
| 138 | break; |
| 139 | } |
| 140 | #ifndef DISABLE_H265 |
| 141 | case kVideoCodecH265: { |
| 142 | _codecSpecificInfo.codecType = kVideoCodecH265; |
| 143 | break; |
| 144 | } |
| 145 | #endif |
| 146 | default: { |
| 147 | _codecSpecificInfo.codecType = kVideoCodecGeneric; |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 |
| 154 | } // namespace webrtc |
| 155 |