You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
6.2 KiB

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