1 /*
2  *  Copyright (c) 2019 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 API_VIDEO_CODECS_VP8_FRAME_CONFIG_H_
12 #define API_VIDEO_CODECS_VP8_FRAME_CONFIG_H_
13 
14 #include <stdint.h>
15 
16 namespace webrtc {
17 
18 // Configuration of a VP8 frame - which buffers are to be referenced
19 // by it, which buffers should be updated, etc.
20 struct Vp8FrameConfig {
GetIntraFrameConfigVp8FrameConfig21   static Vp8FrameConfig GetIntraFrameConfig() {
22     Vp8FrameConfig frame_config = Vp8FrameConfig(
23         BufferFlags::kUpdate, BufferFlags::kUpdate, BufferFlags::kUpdate);
24     frame_config.packetizer_temporal_idx = 0;
25     return frame_config;
26   }
27 
28   enum BufferFlags : int {
29     kNone = 0,
30     kReference = 1,
31     kUpdate = 2,
32     kReferenceAndUpdate = kReference | kUpdate,
33   };
34 
35   enum FreezeEntropy { kFreezeEntropy };
36 
37   // Defined bit-maskable reference to the three buffers available in VP8.
38   enum class Vp8BufferReference : uint8_t {
39     kNone = 0,
40     kLast = 1,
41     kGolden = 2,
42     kAltref = 4
43   };
44 
45   Vp8FrameConfig();
46 
47   Vp8FrameConfig(BufferFlags last, BufferFlags golden, BufferFlags arf);
48   Vp8FrameConfig(BufferFlags last,
49                  BufferFlags golden,
50                  BufferFlags arf,
51                  FreezeEntropy);
52 
53   enum class Buffer : int { kLast = 0, kGolden = 1, kArf = 2, kCount };
54 
55   bool References(Buffer buffer) const;
56 
57   bool Updates(Buffer buffer) const;
58 
IntraFrameVp8FrameConfig59   bool IntraFrame() const {
60     // Intra frames do not reference any buffers, and update all buffers.
61     return last_buffer_flags == kUpdate && golden_buffer_flags == kUpdate &&
62            arf_buffer_flags == kUpdate;
63   }
64 
65   bool drop_frame;
66   BufferFlags last_buffer_flags;
67   BufferFlags golden_buffer_flags;
68   BufferFlags arf_buffer_flags;
69 
70   // The encoder layer ID is used to utilize the correct bitrate allocator
71   // inside the encoder. It does not control references nor determine which
72   // "actual" temporal layer this is. The packetizer temporal index determines
73   // which layer the encoded frame should be packetized into.
74   // Normally these are the same, but current temporal-layer strategies for
75   // screenshare use one bitrate allocator for all layers, but attempt to
76   // packetize / utilize references to split a stream into multiple layers,
77   // with different quantizer settings, to hit target bitrate.
78   // TODO(sprang): Screenshare layers are being reconsidered at the time of
79   // writing, we might be able to remove this distinction, and have a temporal
80   // layer imply both (the normal case).
81   int encoder_layer_id;
82   // TODO(eladalon/sprang): Move out of this class.
83   int packetizer_temporal_idx;
84 
85   // TODO(eladalon/sprang): Move out of this class.
86   bool layer_sync;
87 
88   bool freeze_entropy;
89 
90   // Indicates in which order the encoder should search the reference buffers
91   // when doing motion prediction. Set to kNone to use unspecified order. Any
92   // buffer indicated here must not have the corresponding no_ref bit set.
93   // If all three buffers can be reference, the one not listed here should be
94   // searched last.
95   Vp8BufferReference first_reference;
96   Vp8BufferReference second_reference;
97 
98   // Whether this frame is eligible for retransmission.
99   bool retransmission_allowed;
100 
101  private:
102   Vp8FrameConfig(BufferFlags last,
103                  BufferFlags golden,
104                  BufferFlags arf,
105                  bool freeze_entropy);
106 };
107 
108 }  // namespace webrtc
109 
110 #endif  // API_VIDEO_CODECS_VP8_FRAME_CONFIG_H_
111