Home | History | Annotate | Download | only in vp8
      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 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
     10 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
     11 
     12 #include <list>
     13 
     14 #include "vpx/vpx_encoder.h"
     15 
     16 #include "webrtc/base/timeutils.h"
     17 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
     18 #include "webrtc/modules/video_coding/utility/frame_dropper.h"
     19 #include "webrtc/typedefs.h"
     20 
     21 namespace webrtc {
     22 
     23 struct CodecSpecificInfoVP8;
     24 
     25 class ScreenshareLayers : public TemporalLayers {
     26  public:
     27   static const double kMaxTL0FpsReduction;
     28   static const double kAcceptableTargetOvershoot;
     29   static const int kTl0Flags;
     30   static const int kTl1Flags;
     31   static const int kTl1SyncFlags;
     32 
     33   ScreenshareLayers(int num_temporal_layers, uint8_t initial_tl0_pic_idx);
     34   virtual ~ScreenshareLayers() {}
     35 
     36   // Returns the recommended VP8 encode flags needed. May refresh the decoder
     37   // and/or update the reference buffers.
     38   int EncodeFlags(uint32_t timestamp) override;
     39 
     40   bool ConfigureBitrates(int bitrate_kbps,
     41                          int max_bitrate_kbps,
     42                          int framerate,
     43                          vpx_codec_enc_cfg_t* cfg) override;
     44 
     45   void PopulateCodecSpecific(bool base_layer_sync,
     46                              CodecSpecificInfoVP8* vp8_info,
     47                              uint32_t timestamp) override;
     48 
     49   void FrameEncoded(unsigned int size, uint32_t timestamp, int qp) override;
     50 
     51   int CurrentLayerId() const override;
     52 
     53   // Allows the layers adapter to update the encoder configuration prior to a
     54   // frame being encoded. Return true if the configuration should be updated
     55   // and false if now change is needed.
     56   bool UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) override;
     57 
     58  private:
     59   bool TimeToSync(int64_t timestamp) const;
     60 
     61   int number_of_temporal_layers_;
     62   bool last_base_layer_sync_;
     63   uint8_t tl0_pic_idx_;
     64   int active_layer_;
     65   int64_t last_timestamp_;
     66   int64_t last_sync_timestamp_;
     67   rtc::TimestampWrapAroundHandler time_wrap_handler_;
     68   int min_qp_;
     69   int max_qp_;
     70   uint32_t max_debt_bytes_;
     71   int frame_rate_;
     72 
     73   static const int kMaxNumTemporalLayers = 2;
     74   struct TemporalLayer {
     75     TemporalLayer()
     76         : state(State::kNormal),
     77           enhanced_max_qp(-1),
     78           last_qp(-1),
     79           debt_bytes_(0),
     80           target_rate_kbps_(0) {}
     81 
     82     enum class State {
     83       kNormal,
     84       kDropped,
     85       kReencoded,
     86       kQualityBoost,
     87     } state;
     88 
     89     int enhanced_max_qp;
     90     int last_qp;
     91     uint32_t debt_bytes_;
     92     uint32_t target_rate_kbps_;
     93 
     94     void UpdateDebt(int64_t delta_ms);
     95   } layers_[kMaxNumTemporalLayers];
     96 };
     97 }  // namespace webrtc
     98 
     99 #endif  // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
    100