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