blob: b786be1693d5721d4ab51d417d4b57b9f013ba4f [file] [log] [blame]
Henrik Kjellander2557b862015-11-18 22:00:21 +01001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_
12#define MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_
Henrik Kjellander2557b862015-11-18 22:00:21 +010013
14#include <vector>
15
philipel9df33532019-03-04 16:37:50 +010016#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/video/video_frame.h"
18#include "api/video_codecs/video_decoder.h"
19#include "api/video_codecs/video_encoder.h"
philipel9df33532019-03-04 16:37:50 +010020#include "common_video/generic_frame_descriptor/generic_frame_info.h"
Danil Chapovalov7c067772019-10-07 12:56:24 +020021#include "modules/video_coding/codecs/h264/include/h264_globals.h"
22#include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "modules/video_coding/include/video_error_codes.h"
Danil Chapovalov06bbeb32020-11-11 12:42:56 +010024#include "rtc_base/deprecation.h"
Mirko Bonadei66e76792019-04-02 11:33:59 +020025#include "rtc_base/system/rtc_export.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010026
philipel9d3ab612015-12-21 04:12:39 -080027namespace webrtc {
Henrik Kjellander2557b862015-11-18 22:00:21 +010028
Elad Alonf5b216a2019-01-28 14:25:17 +010029// Note: If any pointers are added to this struct, it must be fitted
Henrik Kjellander2557b862015-11-18 22:00:21 +010030// with a copy-constructor. See below.
Elad Alonf5b216a2019-01-28 14:25:17 +010031// Hack alert - the code assumes that thisstruct is memset when constructed.
Henrik Kjellander2557b862015-11-18 22:00:21 +010032struct CodecSpecificInfoVP8 {
Henrik Kjellander2557b862015-11-18 22:00:21 +010033 bool nonReference;
Henrik Kjellander2557b862015-11-18 22:00:21 +010034 uint8_t temporalIdx;
35 bool layerSync;
Henrik Kjellander2557b862015-11-18 22:00:21 +010036 int8_t keyIdx; // Negative value to skip keyIdx.
Henrik Kjellander2557b862015-11-18 22:00:21 +010037
Elad Alonf5b216a2019-01-28 14:25:17 +010038 // 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.
Qingsi Wang1c1b99e2020-01-07 19:16:33 +000044 // TODO(bugs.webrtc.org/10242): Remove |useExplicitDependencies| once all
45 // encoder-wrappers are updated.
46 bool useExplicitDependencies;
Elad Alonf5b216a2019-01-28 14:25:17 +010047 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};
53static_assert(std::is_pod<CodecSpecificInfoVP8>::value, "");
54
55// Hack alert - the code assumes that thisstruct is memset when constructed.
Henrik Kjellander2557b862015-11-18 22:00:21 +010056struct CodecSpecificInfoVP9 {
Niels Möllerbb894ff2018-03-15 12:28:53 +010057 bool first_frame_in_picture; // First frame, increment picture_id.
Yves Gerey665174f2018-06-19 15:03:05 +020058 bool inter_pic_predicted; // This layer frame is dependent on previously
59 // coded frame(s).
Henrik Kjellander2557b862015-11-18 22:00:21 +010060 bool flexible_mode;
61 bool ss_data_available;
Sergey Silkinc5a131a2018-04-24 20:13:49 +020062 bool non_ref_for_inter_layer_pred;
Henrik Kjellander2557b862015-11-18 22:00:21 +010063
Henrik Kjellander2557b862015-11-18 22:00:21 +010064 uint8_t temporal_idx;
Henrik Kjellander2557b862015-11-18 22:00:21 +010065 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.
Ilya Nikolaevskiyf5d87782020-02-04 10:06:33 +000072 size_t first_active_layer;
Henrik Kjellander2557b862015-11-18 22:00:21 +010073 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];
Sergey Silkin2a1f1832018-04-04 11:45:41 +020081
Danil Chapovalov06bbeb32020-11-11 12:42:56 +010082 RTC_DEPRECATED bool end_of_picture;
Henrik Kjellander2557b862015-11-18 22:00:21 +010083};
Elad Alonf5b216a2019-01-28 14:25:17 +010084static_assert(std::is_pod<CodecSpecificInfoVP9>::value, "");
Henrik Kjellander2557b862015-11-18 22:00:21 +010085
Elad Alonf5b216a2019-01-28 14:25:17 +010086// Hack alert - the code assumes that thisstruct is memset when constructed.
hta9aa96882016-12-06 05:36:03 -080087struct CodecSpecificInfoH264 {
88 H264PacketizationMode packetization_mode;
Johnny Lee1a1c52b2019-02-08 14:25:40 -050089 uint8_t temporal_idx;
90 bool base_layer_sync;
91 bool idr_frame;
hta9aa96882016-12-06 05:36:03 -080092};
Elad Alonf5b216a2019-01-28 14:25:17 +010093static_assert(std::is_pod<CodecSpecificInfoH264>::value, "");
Henrik Kjellander2557b862015-11-18 22:00:21 +010094
95union CodecSpecificInfoUnion {
Henrik Kjellander2557b862015-11-18 22:00:21 +010096 CodecSpecificInfoVP8 VP8;
97 CodecSpecificInfoVP9 VP9;
98 CodecSpecificInfoH264 H264;
99};
Elad Alonf5b216a2019-01-28 14:25:17 +0100100static_assert(std::is_pod<CodecSpecificInfoUnion>::value, "");
Henrik Kjellander2557b862015-11-18 22:00:21 +0100101
philipel9df33532019-03-04 16:37:50 +0100102// Note: if any pointers are added to this struct or its sub-structs, it
Henrik Kjellander2557b862015-11-18 22:00:21 +0100103// must be fitted with a copy-constructor. This is because it is copied
104// in the copy-constructor of VCMEncodedFrame.
Mirko Bonadei66e76792019-04-02 11:33:59 +0200105struct RTC_EXPORT CodecSpecificInfo {
philipel9df33532019-03-04 16:37:50 +0100106 CodecSpecificInfo();
107 CodecSpecificInfo(const CodecSpecificInfo&);
108 ~CodecSpecificInfo();
philipeld1d03592019-03-01 13:53:55 +0100109
philipel9d3ab612015-12-21 04:12:39 -0800110 VideoCodecType codecType;
111 CodecSpecificInfoUnion codecSpecific;
Danil Chapovalov06bbeb32020-11-11 12:42:56 +0100112 bool end_of_picture = true;
philipel9df33532019-03-04 16:37:50 +0100113 absl::optional<GenericFrameInfo> generic_frame_info;
Danil Chapovalovc2f56862019-06-27 12:11:03 +0200114 absl::optional<FrameDependencyStructure> template_structure;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100115};
116
117} // namespace webrtc
118
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200119#endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_