blob: 1b22cae52b7829295334f311409bd4fe4251a177 [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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "modules/include/module_common_types.h"
22#include "modules/video_coding/include/video_error_codes.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010023
philipel9d3ab612015-12-21 04:12:39 -080024namespace webrtc {
Henrik Kjellander2557b862015-11-18 22:00:21 +010025
philipel9d3ab612015-12-21 04:12:39 -080026class RTPFragmentationHeader; // forward declaration
Henrik Kjellander2557b862015-11-18 22:00:21 +010027
Elad Alonf5b216a2019-01-28 14:25:17 +010028// Note: If any pointers are added to this struct, it must be fitted
Henrik Kjellander2557b862015-11-18 22:00:21 +010029// with a copy-constructor. See below.
Elad Alonf5b216a2019-01-28 14:25:17 +010030// Hack alert - the code assumes that thisstruct is memset when constructed.
Henrik Kjellander2557b862015-11-18 22:00:21 +010031struct CodecSpecificInfoVP8 {
Henrik Kjellander2557b862015-11-18 22:00:21 +010032 bool nonReference;
Henrik Kjellander2557b862015-11-18 22:00:21 +010033 uint8_t temporalIdx;
34 bool layerSync;
Henrik Kjellander2557b862015-11-18 22:00:21 +010035 int8_t keyIdx; // Negative value to skip keyIdx.
Henrik Kjellander2557b862015-11-18 22:00:21 +010036
Elad Alonf5b216a2019-01-28 14:25:17 +010037 // Used to generate the list of dependency frames.
38 // |referencedBuffers| and |updatedBuffers| contain buffer IDs.
39 // Note that the buffer IDs here have a one-to-one mapping with the actual
40 // codec buffers, but the exact mapping (i.e. whether 0 refers to Last,
41 // to Golden or to Arf) is not pre-determined.
42 // More references may be specified than are strictly necessary, but not less.
43 // TODO(bugs.webrtc.org/10242): Remove |useExplicitDependencies| once all
44 // encoder-wrappers are updated.
45 bool useExplicitDependencies;
46 static constexpr size_t kBuffersCount = 3;
47 size_t referencedBuffers[kBuffersCount];
48 size_t referencedBuffersCount;
49 size_t updatedBuffers[kBuffersCount];
50 size_t updatedBuffersCount;
51};
52static_assert(std::is_pod<CodecSpecificInfoVP8>::value, "");
53
54// Hack alert - the code assumes that thisstruct is memset when constructed.
Henrik Kjellander2557b862015-11-18 22:00:21 +010055struct CodecSpecificInfoVP9 {
Niels Möllerbb894ff2018-03-15 12:28:53 +010056 bool first_frame_in_picture; // First frame, increment picture_id.
Yves Gerey665174f2018-06-19 15:03:05 +020057 bool inter_pic_predicted; // This layer frame is dependent on previously
58 // coded frame(s).
Henrik Kjellander2557b862015-11-18 22:00:21 +010059 bool flexible_mode;
60 bool ss_data_available;
Sergey Silkinc5a131a2018-04-24 20:13:49 +020061 bool non_ref_for_inter_layer_pred;
Henrik Kjellander2557b862015-11-18 22:00:21 +010062
Henrik Kjellander2557b862015-11-18 22:00:21 +010063 uint8_t temporal_idx;
Henrik Kjellander2557b862015-11-18 22:00:21 +010064 bool temporal_up_switch;
65 bool inter_layer_predicted; // Frame is dependent on directly lower spatial
66 // layer frame.
67 uint8_t gof_idx;
68
69 // SS data.
70 size_t num_spatial_layers; // Always populated.
71 bool spatial_layer_resolution_present;
72 uint16_t width[kMaxVp9NumberOfSpatialLayers];
73 uint16_t height[kMaxVp9NumberOfSpatialLayers];
74 GofInfoVP9 gof;
75
76 // Frame reference data.
77 uint8_t num_ref_pics;
78 uint8_t p_diff[kMaxVp9RefPics];
Sergey Silkin2a1f1832018-04-04 11:45:41 +020079
Sergey Silkinbc0f0d32018-04-24 21:29:14 +020080 bool end_of_picture;
Henrik Kjellander2557b862015-11-18 22:00:21 +010081};
Elad Alonf5b216a2019-01-28 14:25:17 +010082static_assert(std::is_pod<CodecSpecificInfoVP9>::value, "");
Henrik Kjellander2557b862015-11-18 22:00:21 +010083
Elad Alonf5b216a2019-01-28 14:25:17 +010084// Hack alert - the code assumes that thisstruct is memset when constructed.
hta9aa96882016-12-06 05:36:03 -080085struct CodecSpecificInfoH264 {
86 H264PacketizationMode packetization_mode;
Johnny Lee1a1c52b2019-02-08 14:25:40 -050087 uint8_t temporal_idx;
88 bool base_layer_sync;
89 bool idr_frame;
hta9aa96882016-12-06 05:36:03 -080090};
Elad Alonf5b216a2019-01-28 14:25:17 +010091static_assert(std::is_pod<CodecSpecificInfoH264>::value, "");
Henrik Kjellander2557b862015-11-18 22:00:21 +010092
93union CodecSpecificInfoUnion {
Henrik Kjellander2557b862015-11-18 22:00:21 +010094 CodecSpecificInfoVP8 VP8;
95 CodecSpecificInfoVP9 VP9;
96 CodecSpecificInfoH264 H264;
97};
Elad Alonf5b216a2019-01-28 14:25:17 +010098static_assert(std::is_pod<CodecSpecificInfoUnion>::value, "");
Henrik Kjellander2557b862015-11-18 22:00:21 +010099
philipel9df33532019-03-04 16:37:50 +0100100// Note: if any pointers are added to this struct or its sub-structs, it
Henrik Kjellander2557b862015-11-18 22:00:21 +0100101// must be fitted with a copy-constructor. This is because it is copied
102// in the copy-constructor of VCMEncodedFrame.
philipel9d3ab612015-12-21 04:12:39 -0800103struct CodecSpecificInfo {
philipel9df33532019-03-04 16:37:50 +0100104 CodecSpecificInfo();
105 CodecSpecificInfo(const CodecSpecificInfo&);
106 ~CodecSpecificInfo();
philipeld1d03592019-03-01 13:53:55 +0100107
philipel9d3ab612015-12-21 04:12:39 -0800108 VideoCodecType codecType;
109 CodecSpecificInfoUnion codecSpecific;
philipel9df33532019-03-04 16:37:50 +0100110 absl::optional<GenericFrameInfo> generic_frame_info;
111 absl::optional<TemplateStructure> template_structure;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100112};
113
114} // namespace webrtc
115
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200116#endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_