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 
11 #ifndef MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_
12 #define MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_
13 
14 #include <vector>
15 
16 #include "absl/base/attributes.h"
17 #include "absl/types/optional.h"
18 #include "api/video/video_frame.h"
19 #include "api/video_codecs/video_decoder.h"
20 #include "api/video_codecs/video_encoder.h"
21 #include "common_video/generic_frame_descriptor/generic_frame_info.h"
22 #include "modules/video_coding/codecs/h264/include/h264_globals.h"
23 #ifndef DISABLE_H265
24 #include "modules/video_coding/codecs/h265/include/h265_globals.h"
25 #endif
26 #include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
27 #include "modules/video_coding/include/video_error_codes.h"
28 #include "rtc_base/system/rtc_export.h"
29 
30 namespace webrtc {
31 
32 // Note: If any pointers are added to this struct, it must be fitted
33 // with a copy-constructor. See below.
34 // Hack alert - the code assumes that thisstruct is memset when constructed.
35 struct CodecSpecificInfoVP8 {
36   bool nonReference;
37   uint8_t temporalIdx;
38   bool layerSync;
39   int8_t keyIdx;  // Negative value to skip keyIdx.
40 
41   // Used to generate the list of dependency frames.
42   // |referencedBuffers| and |updatedBuffers| contain buffer IDs.
43   // Note that the buffer IDs here have a one-to-one mapping with the actual
44   // codec buffers, but the exact mapping (i.e. whether 0 refers to Last,
45   // to Golden or to Arf) is not pre-determined.
46   // More references may be specified than are strictly necessary, but not less.
47   // TODO(bugs.webrtc.org/10242): Remove |useExplicitDependencies| once all
48   // encoder-wrappers are updated.
49   bool useExplicitDependencies;
50   static constexpr size_t kBuffersCount = 3;
51   size_t referencedBuffers[kBuffersCount];
52   size_t referencedBuffersCount;
53   size_t updatedBuffers[kBuffersCount];
54   size_t updatedBuffersCount;
55 };
56 static_assert(std::is_pod<CodecSpecificInfoVP8>::value, "");
57 
58 // Hack alert - the code assumes that thisstruct is memset when constructed.
59 struct CodecSpecificInfoVP9 {
60   bool first_frame_in_picture;  // First frame, increment picture_id.
61   bool inter_pic_predicted;     // This layer frame is dependent on previously
62                                 // coded frame(s).
63   bool flexible_mode;
64   bool ss_data_available;
65   bool non_ref_for_inter_layer_pred;
66 
67   uint8_t temporal_idx;
68   bool temporal_up_switch;
69   bool inter_layer_predicted;  // Frame is dependent on directly lower spatial
70                                // layer frame.
71   uint8_t gof_idx;
72 
73   // SS data.
74   size_t num_spatial_layers;  // Always populated.
75   size_t first_active_layer;
76   bool spatial_layer_resolution_present;
77   uint16_t width[kMaxVp9NumberOfSpatialLayers];
78   uint16_t height[kMaxVp9NumberOfSpatialLayers];
79   GofInfoVP9 gof;
80 
81   // Frame reference data.
82   uint8_t num_ref_pics;
83   uint8_t p_diff[kMaxVp9RefPics];
84 
85   ABSL_DEPRECATED("") bool end_of_picture;
86 };
87 static_assert(std::is_pod<CodecSpecificInfoVP9>::value, "");
88 
89 // Hack alert - the code assumes that thisstruct is memset when constructed.
90 struct CodecSpecificInfoH264 {
91   H264PacketizationMode packetization_mode;
92   uint8_t temporal_idx;
93   bool base_layer_sync;
94   bool idr_frame;
95 };
96 
97 #ifndef DISABLE_H265
98 struct CodecSpecificInfoH265 {
99   H265PacketizationMode packetization_mode;
100   bool idr_frame;
101 };
102 #endif
103 
104 static_assert(std::is_pod<CodecSpecificInfoH264>::value, "");
105 
106 union CodecSpecificInfoUnion {
107   CodecSpecificInfoVP8 VP8;
108   CodecSpecificInfoVP9 VP9;
109   CodecSpecificInfoH264 H264;
110 #ifndef DISABLE_H265
111   CodecSpecificInfoH265 H265;
112 #endif
113 };
114 static_assert(std::is_pod<CodecSpecificInfoUnion>::value, "");
115 
116 // Note: if any pointers are added to this struct or its sub-structs, it
117 // must be fitted with a copy-constructor. This is because it is copied
118 // in the copy-constructor of VCMEncodedFrame.
119 struct RTC_EXPORT CodecSpecificInfo {
120   CodecSpecificInfo();
121   CodecSpecificInfo(const CodecSpecificInfo&);
122   ~CodecSpecificInfo();
123 
124   VideoCodecType codecType;
125   CodecSpecificInfoUnion codecSpecific;
126   bool end_of_picture = true;
127   absl::optional<GenericFrameInfo> generic_frame_info;
128   absl::optional<FrameDependencyStructure> template_structure;
129 };
130 
131 }  // namespace webrtc
132 
133 #endif  // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_
134