1 /*
2  *  Copyright (c) 2011 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 /*
12  * This file defines classes for doing reference picture selection, primarily
13  * with VP8.
14  */
15 
16 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_REFERENCE_PICTURE_SELECTION_H_
17 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_REFERENCE_PICTURE_SELECTION_H_
18 
19 #include "webrtc/typedefs.h"
20 
21 namespace webrtc {
22 
23 class ReferencePictureSelection {
24  public:
25   ReferencePictureSelection();
26   void Init();
27 
28   // Report a received reference picture selection indication. This will
29   // introduce a new established reference if the received RPSI isn't too late.
30   void ReceivedRPSI(int rpsi_picture_id);
31 
32   // Report a received slice loss indication. Returns true if a refresh frame
33   // must be sent to the receiver, which is accomplished by only predicting
34   // from the established reference.
35   // |now_ts| is the RTP timestamp corresponding to the current time. Typically
36   // the capture timestamp of the frame currently being processed.
37   // Returns true if it's time to encode a decoder refresh, otherwise false.
38   bool ReceivedSLI(uint32_t now_ts);
39 
40   // Returns the recommended VP8 encode flags needed. May refresh the decoder
41   // and/or update the reference buffers.
42   // |picture_id| picture id of the frame to be encoded.
43   // |send_refresh| should be set to true if a decoder refresh should be
44   // encoded, otherwise false.
45   // |now_ts| is the RTP timestamp corresponding to the current time. Typically
46   // the capture timestamp of the frame currently being processed.
47   // Returns the flags to be given to the libvpx encoder when encoding the next
48   // frame.
49   int EncodeFlags(int picture_id, bool send_refresh, uint32_t now_ts);
50 
51   // Notify the RPS that the frame with picture id |picture_id| was encoded as
52   // a key frame, effectively updating all reference buffers.
53   void EncodedKeyFrame(int picture_id);
54 
55   // Set the round-trip time between the sender and the receiver to |rtt|
56   // milliseconds.
57   void SetRtt(int64_t rtt);
58 
59  private:
60   static int64_t TimestampDiff(uint32_t new_ts, uint32_t old_ts);
61 
62   const double kRttConfidence;
63 
64   bool update_golden_next_;
65   bool established_golden_;
66   bool received_ack_;
67   int last_sent_ref_picture_id_;
68   uint32_t last_sent_ref_update_time_;
69   int established_ref_picture_id_;
70   uint32_t last_refresh_time_;
71   int64_t rtt_;
72 };
73 
74 }  // namespace webrtc
75 
76 #endif  // WEBRTC_MODULES_VIDEO_CODING_CODECS_REFERENCE_PICTURE_SELECTION_H_
77