| 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 "api/video/encoded_frame.h" |
| 12 |
| 13 | #include "absl/types/optional.h" |
| 14 | #include "modules/rtp_rtcp/source/rtp_video_header.h" |
| 15 |
| 16 | namespace webrtc { |
| 17 |
| 18 | absl::optional<Timestamp> EncodedFrame::ReceivedTimestamp() const { |
| 19 | return ReceivedTime() >= 0 |
| 20 | ? absl::make_optional(Timestamp::Millis(ReceivedTime())) |
| 21 | : absl::nullopt; |
| 22 | } |
| 23 |
| 24 | absl::optional<Timestamp> EncodedFrame::RenderTimestamp() const { |
| 25 | return RenderTimeMs() >= 0 |
| 26 | ? absl::make_optional(Timestamp::Millis(RenderTimeMs())) |
| 27 | : absl::nullopt; |
| 28 | } |
| 29 |
| 30 | bool EncodedFrame::delayed_by_retransmission() const { |
| 31 | return false; |
| 32 | } |
| 33 |
| 34 | void EncodedFrame::CopyCodecSpecific(const RTPVideoHeader* header) { |
| 35 | if (header) { |
| 36 | switch (header->codec) { |
| 37 | case kVideoCodecVP8: { |
| 38 | const auto& vp8_header = |
| 39 | absl::get<RTPVideoHeaderVP8>(header->video_type_header); |
| 40 | if (_codecSpecificInfo.codecType != kVideoCodecVP8) { |
| 41 | // This is the first packet for this frame. |
| 42 | _codecSpecificInfo.codecSpecific.VP8.temporalIdx = 0; |
| 43 | _codecSpecificInfo.codecSpecific.VP8.layerSync = false; |
| 44 | _codecSpecificInfo.codecSpecific.VP8.keyIdx = -1; |
| 45 | _codecSpecificInfo.codecType = kVideoCodecVP8; |
| 46 | } |
| 47 | _codecSpecificInfo.codecSpecific.VP8.nonReference = |
| 48 | vp8_header.nonReference; |
| 49 | if (vp8_header.temporalIdx != kNoTemporalIdx) { |
| 50 | _codecSpecificInfo.codecSpecific.VP8.temporalIdx = |
| 51 | vp8_header.temporalIdx; |
| 52 | _codecSpecificInfo.codecSpecific.VP8.layerSync = vp8_header.layerSync; |
| 53 | } |
| 54 | if (vp8_header.keyIdx != kNoKeyIdx) { |
| 55 | _codecSpecificInfo.codecSpecific.VP8.keyIdx = vp8_header.keyIdx; |
| 56 | } |
| 57 | break; |
| 58 | } |
| 59 | case kVideoCodecVP9: { |
| 60 | const auto& vp9_header = |
| 61 | absl::get<RTPVideoHeaderVP9>(header->video_type_header); |
| 62 | if (_codecSpecificInfo.codecType != kVideoCodecVP9) { |
| 63 | // This is the first packet for this frame. |
| 64 | _codecSpecificInfo.codecSpecific.VP9.temporal_idx = 0; |
| 65 | _codecSpecificInfo.codecSpecific.VP9.gof_idx = 0; |
| 66 | _codecSpecificInfo.codecSpecific.VP9.inter_layer_predicted = false; |
| 67 | _codecSpecificInfo.codecType = kVideoCodecVP9; |
| 68 | } |
| 69 | _codecSpecificInfo.codecSpecific.VP9.inter_pic_predicted = |
| 70 | vp9_header.inter_pic_predicted; |
| 71 | _codecSpecificInfo.codecSpecific.VP9.flexible_mode = |
| 72 | vp9_header.flexible_mode; |
| 73 | _codecSpecificInfo.codecSpecific.VP9.num_ref_pics = |
| 74 | vp9_header.num_ref_pics; |
| 75 | for (uint8_t r = 0; r < vp9_header.num_ref_pics; ++r) { |
| 76 | _codecSpecificInfo.codecSpecific.VP9.p_diff[r] = |
| 77 | vp9_header.pid_diff[r]; |
| 78 | } |
| 79 | _codecSpecificInfo.codecSpecific.VP9.ss_data_available = |
| 80 | vp9_header.ss_data_available; |
| 81 | if (vp9_header.temporal_idx != kNoTemporalIdx) { |
| 82 | _codecSpecificInfo.codecSpecific.VP9.temporal_idx = |
| 83 | vp9_header.temporal_idx; |
| 84 | _codecSpecificInfo.codecSpecific.VP9.temporal_up_switch = |
| 85 | vp9_header.temporal_up_switch; |
| 86 | } |
| 87 | if (vp9_header.spatial_idx != kNoSpatialIdx) { |
| 88 | _codecSpecificInfo.codecSpecific.VP9.inter_layer_predicted = |
| 89 | vp9_header.inter_layer_predicted; |
| 90 | SetSpatialIndex(vp9_header.spatial_idx); |
| 91 | } |
| 92 | if (vp9_header.gof_idx != kNoGofIdx) { |
| 93 | _codecSpecificInfo.codecSpecific.VP9.gof_idx = vp9_header.gof_idx; |
| 94 | } |
| 95 | if (vp9_header.ss_data_available) { |
| 96 | _codecSpecificInfo.codecSpecific.VP9.num_spatial_layers = |
| 97 | vp9_header.num_spatial_layers; |
| 98 | _codecSpecificInfo.codecSpecific.VP9 |
| 99 | .spatial_layer_resolution_present = |
| 100 | vp9_header.spatial_layer_resolution_present; |
| 101 | if (vp9_header.spatial_layer_resolution_present) { |
| 102 | for (size_t i = 0; i < vp9_header.num_spatial_layers; ++i) { |
| 103 | _codecSpecificInfo.codecSpecific.VP9.width[i] = |
| 104 | vp9_header.width[i]; |
| 105 | _codecSpecificInfo.codecSpecific.VP9.height[i] = |
| 106 | vp9_header.height[i]; |
| 107 | } |
| 108 | } |
| 109 | _codecSpecificInfo.codecSpecific.VP9.gof.CopyGofInfoVP9( |
| 110 | vp9_header.gof); |
| 111 | } |
| 112 | break; |
| 113 | } |
| 114 | case kVideoCodecH264: { |
| 115 | _codecSpecificInfo.codecType = kVideoCodecH264; |
| 116 | break; |
| 117 | } |
| 118 | case kVideoCodecH265: { |
| 119 | _codecSpecificInfo.codecType = kVideoCodecH265; |
| 120 | break; |
| 121 | } |
| 122 | case kVideoCodecAV1: { |
| 123 | _codecSpecificInfo.codecType = kVideoCodecAV1; |
| 124 | break; |
| 125 | } |
| 126 | default: { |
| 127 | _codecSpecificInfo.codecType = kVideoCodecGeneric; |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 |
| 134 | } // namespace webrtc |
| 135 |