1 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
2  *
3  *  Use of this source code is governed by a BSD-style license
4  *  that can be found in the LICENSE file in the root of the source
5  *  tree. An additional intellectual property rights grant can be found
6  *  in the file PATENTS.  All contributing project authors may
7  *  be found in the AUTHORS file in the root of the source tree.
8  */
9 /*
10  * This file defines classes for doing temporal layers with VP8.
11  */
12 #ifndef MODULES_VIDEO_CODING_CODECS_VP8_DEFAULT_TEMPORAL_LAYERS_H_
13 #define MODULES_VIDEO_CODING_CODECS_VP8_DEFAULT_TEMPORAL_LAYERS_H_
14 
15 #include <set>
16 #include <vector>
17 
18 #include "modules/video_coding/codecs/vp8/temporal_layers.h"
19 
20 #include "api/optional.h"
21 
22 namespace webrtc {
23 
24 class DefaultTemporalLayers : public TemporalLayers {
25  public:
26   DefaultTemporalLayers(int number_of_temporal_layers,
27                         uint8_t initial_tl0_pic_idx);
~DefaultTemporalLayers()28   virtual ~DefaultTemporalLayers() {}
29 
30   // Returns the recommended VP8 encode flags needed. May refresh the decoder
31   // and/or update the reference buffers.
32   TemporalLayers::FrameConfig UpdateLayerConfig(uint32_t timestamp) override;
33 
34   // Update state based on new bitrate target and incoming framerate.
35   // Returns the bitrate allocation for the active temporal layers.
36   std::vector<uint32_t> OnRatesUpdated(int bitrate_kbps,
37                                        int max_bitrate_kbps,
38                                        int framerate) override;
39 
40   bool UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) override;
41 
42   void PopulateCodecSpecific(bool frame_is_keyframe,
43                              const TemporalLayers::FrameConfig& tl_config,
44                              CodecSpecificInfoVP8* vp8_info,
45                              uint32_t timestamp) override;
46 
FrameEncoded(unsigned int size,int qp)47   void FrameEncoded(unsigned int size, int qp) override {}
48 
49   uint8_t Tl0PicIdx() const override;
50 
51  private:
52   const size_t num_layers_;
53   const std::vector<unsigned int> temporal_ids_;
54   const std::vector<bool> temporal_layer_sync_;
55   const std::vector<TemporalLayers::FrameConfig> temporal_pattern_;
56 
57   uint8_t tl0_pic_idx_;
58   uint8_t pattern_idx_;
59   bool last_base_layer_sync_;
60   rtc::Optional<std::vector<uint32_t>> new_bitrates_kbps_;
61 };
62 
63 class DefaultTemporalLayersChecker : public TemporalLayersChecker {
64  public:
65   DefaultTemporalLayersChecker(int number_of_temporal_layers,
66                                uint8_t initial_tl0_pic_idx);
67   bool CheckTemporalConfig(
68       bool frame_is_keyframe,
69       const TemporalLayers::FrameConfig& frame_config) override;
70 
71  private:
72   struct BufferState {
BufferStateBufferState73     BufferState()
74         : is_updated_this_cycle(false), is_keyframe(true), pattern_idx(0) {}
75 
76     bool is_updated_this_cycle;
77     bool is_keyframe;
78     uint8_t pattern_idx;
79   };
80   const size_t num_layers_;
81   std::vector<unsigned int> temporal_ids_;
82   const std::vector<std::set<uint8_t>> temporal_dependencies_;
83   BufferState last_;
84   BufferState arf_;
85   BufferState golden_;
86   uint8_t pattern_idx_;
87 };
88 
89 }  // namespace webrtc
90 #endif  // MODULES_VIDEO_CODING_CODECS_VP8_DEFAULT_TEMPORAL_LAYERS_H_
91