1 /*
2  *  Copyright (c) 2018 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_TEMPORAL_LAYERS_H_
12 #define API_VIDEO_CODECS_VP8_TEMPORAL_LAYERS_H_
13 
14 #include <memory>
15 #include <vector>
16 
17 #include "api/fec_controller_override.h"
18 #include "api/video_codecs/video_codec.h"
19 #include "api/video_codecs/vp8_frame_buffer_controller.h"
20 #include "api/video_codecs/vp8_frame_config.h"
21 
22 namespace webrtc {
23 
24 // Two different flavors of temporal layers are currently available:
25 // kFixedPattern uses a fixed repeating pattern of 1-4 layers.
26 // kBitrateDynamic can allocate frames dynamically to 1 or 2 layers, based on
27 // the bitrate produced.
28 // TODO(eladalon): Remove this enum.
29 enum class Vp8TemporalLayersType { kFixedPattern, kBitrateDynamic };
30 
31 // This interface defines a way of getting the encoder settings needed to
32 // realize a temporal layer structure.
33 class Vp8TemporalLayers final : public Vp8FrameBufferController {
34  public:
35   Vp8TemporalLayers(
36       std::vector<std::unique_ptr<Vp8FrameBufferController>>&& controllers,
37       FecControllerOverride* fec_controller_override);
38   ~Vp8TemporalLayers() override = default;
39 
40   void SetQpLimits(size_t stream_index, int min_qp, int max_qp) override;
41 
42   size_t StreamCount() const override;
43 
44   bool SupportsEncoderFrameDropping(size_t stream_index) const override;
45 
46   void OnRatesUpdated(size_t stream_index,
47                       const std::vector<uint32_t>& bitrates_bps,
48                       int framerate_fps) override;
49 
50   Vp8EncoderConfig UpdateConfiguration(size_t stream_index) override;
51 
52   Vp8FrameConfig NextFrameConfig(size_t stream_index,
53                                  uint32_t rtp_timestamp) override;
54 
55   void OnEncodeDone(size_t stream_index,
56                     uint32_t rtp_timestamp,
57                     size_t size_bytes,
58                     bool is_keyframe,
59                     int qp,
60                     CodecSpecificInfo* info) override;
61 
62   void OnFrameDropped(size_t stream_index, uint32_t rtp_timestamp) override;
63 
64   void OnPacketLossRateUpdate(float packet_loss_rate) override;
65 
66   void OnRttUpdate(int64_t rtt_ms) override;
67 
68   void OnLossNotification(
69       const VideoEncoder::LossNotification& loss_notification) override;
70 
71  private:
72   std::vector<std::unique_ptr<Vp8FrameBufferController>> controllers_;
73 };
74 
75 }  // namespace webrtc
76 
77 #endif  // API_VIDEO_CODECS_VP8_TEMPORAL_LAYERS_H_
78