philipel | c70e4ec | 2016-04-01 09:01:54 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 WEBRTC_MODULES_VIDEO_CODING_FRAME_OBJECT_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_FRAME_OBJECT_H_ |
| 13 | |
philipel | 871cc2c | 2016-05-13 13:01:03 | [diff] [blame] | 14 | #include "webrtc/common_types.h" |
| 15 | #include "webrtc/modules/include/module_common_types.h" |
philipel | ca7ea5f | 2016-07-04 14:18:55 | [diff] [blame] | 16 | #include "webrtc/modules/video_coding/encoded_frame.h" |
Edward Lemur | 76de83e | 2017-07-06 17:44:34 | [diff] [blame] | 17 | #include "webrtc/rtc_base/optional.h" |
philipel | c70e4ec | 2016-04-01 09:01:54 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | namespace video_coding { |
| 21 | |
philipel | ca7ea5f | 2016-07-04 14:18:55 | [diff] [blame] | 22 | class FrameObject : public webrtc::VCMEncodedFrame { |
philipel | c70e4ec | 2016-04-01 09:01:54 | [diff] [blame] | 23 | public: |
philipel | 2d4f108 | 2016-04-20 08:26:34 | [diff] [blame] | 24 | static const uint8_t kMaxFrameReferences = 5; |
| 25 | |
philipel | 2e86f76 | 2016-05-09 09:41:48 | [diff] [blame] | 26 | FrameObject(); |
philipel | d053dee | 2016-07-11 15:46:29 | [diff] [blame] | 27 | virtual ~FrameObject() {} |
philipel | 2e86f76 | 2016-05-09 09:41:48 | [diff] [blame] | 28 | |
philipel | c70e4ec | 2016-04-01 09:01:54 | [diff] [blame] | 29 | virtual bool GetBitstream(uint8_t* destination) const = 0; |
philipel | d053dee | 2016-07-11 15:46:29 | [diff] [blame] | 30 | |
| 31 | // The capture timestamp of this frame. |
| 32 | virtual uint32_t Timestamp() const = 0; |
| 33 | |
| 34 | // When this frame was received. |
| 35 | virtual int64_t ReceivedTime() const = 0; |
| 36 | |
| 37 | // When this frame should be rendered. |
| 38 | virtual int64_t RenderTime() const = 0; |
| 39 | |
philipel | fdbe39f | 2017-01-25 16:56:23 | [diff] [blame] | 40 | // This information is currently needed by the timing calculation class. |
| 41 | // TODO(philipel): Remove this function when a new timing class has |
| 42 | // been implemented. |
| 43 | virtual bool delayed_by_retransmission() const { return 0; } |
| 44 | |
philipel | 43eaad5 | 2017-08-04 13:39:31 | [diff] [blame] | 45 | size_t size() const { return _length; } |
philipel | 2d4f108 | 2016-04-20 08:26:34 | [diff] [blame] | 46 | |
philipel | 21950c6 | 2017-08-18 11:55:02 | [diff] [blame] | 47 | bool is_keyframe() const { return num_references == 0; } |
| 48 | |
philipel | 2e86f76 | 2016-05-09 09:41:48 | [diff] [blame] | 49 | // The tuple (|picture_id|, |spatial_layer|) uniquely identifies a frame |
| 50 | // object. For codec types that don't necessarily have picture ids they |
| 51 | // have to be constructed from the header data relevant to that codec. |
philipel | 2d4f108 | 2016-04-20 08:26:34 | [diff] [blame] | 52 | uint16_t picture_id; |
philipel | 2e86f76 | 2016-05-09 09:41:48 | [diff] [blame] | 53 | uint8_t spatial_layer; |
philipel | 1934b82 | 2016-05-19 10:19:35 | [diff] [blame] | 54 | uint32_t timestamp; |
philipel | 2e86f76 | 2016-05-09 09:41:48 | [diff] [blame] | 55 | |
philipel | c81ec9b | 2017-06-15 16:06:21 | [diff] [blame] | 56 | // TODO(philipel): Add simple modify/access functions to prevent adding too |
| 57 | // many |references|. |
philipel | 2d4f108 | 2016-04-20 08:26:34 | [diff] [blame] | 58 | size_t num_references; |
philipel | 2d4f108 | 2016-04-20 08:26:34 | [diff] [blame] | 59 | uint16_t references[kMaxFrameReferences]; |
philipel | 2e86f76 | 2016-05-09 09:41:48 | [diff] [blame] | 60 | bool inter_layer_predicted; |
philipel | c70e4ec | 2016-04-01 09:01:54 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | class PacketBuffer; |
| 64 | |
| 65 | class RtpFrameObject : public FrameObject { |
| 66 | public: |
| 67 | RtpFrameObject(PacketBuffer* packet_buffer, |
philipel | 871cc2c | 2016-05-13 13:01:03 | [diff] [blame] | 68 | uint16_t first_seq_num, |
philipel | 0aeed85 | 2016-05-24 08:20:47 | [diff] [blame] | 69 | uint16_t last_seq_num, |
| 70 | size_t frame_size, |
philipel | d053dee | 2016-07-11 15:46:29 | [diff] [blame] | 71 | int times_nacked, |
| 72 | int64_t received_time); |
philipel | 2d4f108 | 2016-04-20 08:26:34 | [diff] [blame] | 73 | |
philipel | c70e4ec | 2016-04-01 09:01:54 | [diff] [blame] | 74 | ~RtpFrameObject(); |
philipel | 2d4f108 | 2016-04-20 08:26:34 | [diff] [blame] | 75 | uint16_t first_seq_num() const; |
| 76 | uint16_t last_seq_num() const; |
philipel | 0aeed85 | 2016-05-24 08:20:47 | [diff] [blame] | 77 | int times_nacked() const; |
philipel | ca7ea5f | 2016-07-04 14:18:55 | [diff] [blame] | 78 | enum FrameType frame_type() const; |
philipel | 871cc2c | 2016-05-13 13:01:03 | [diff] [blame] | 79 | VideoCodecType codec_type() const; |
philipel | c70e4ec | 2016-04-01 09:01:54 | [diff] [blame] | 80 | bool GetBitstream(uint8_t* destination) const override; |
philipel | d053dee | 2016-07-11 15:46:29 | [diff] [blame] | 81 | uint32_t Timestamp() const override; |
| 82 | int64_t ReceivedTime() const override; |
| 83 | int64_t RenderTime() const override; |
philipel | fdbe39f | 2017-01-25 16:56:23 | [diff] [blame] | 84 | bool delayed_by_retransmission() const override; |
philipel | 4bf739e | 2016-11-03 15:56:54 | [diff] [blame] | 85 | rtc::Optional<RTPVideoTypeHeader> GetCodecHeader() const; |
philipel | c70e4ec | 2016-04-01 09:01:54 | [diff] [blame] | 86 | |
| 87 | private: |
philipel | 5093466 | 2016-08-11 13:09:26 | [diff] [blame] | 88 | rtc::scoped_refptr<PacketBuffer> packet_buffer_; |
philipel | ca7ea5f | 2016-07-04 14:18:55 | [diff] [blame] | 89 | enum FrameType frame_type_; |
philipel | 871cc2c | 2016-05-13 13:01:03 | [diff] [blame] | 90 | VideoCodecType codec_type_; |
| 91 | uint16_t first_seq_num_; |
| 92 | uint16_t last_seq_num_; |
philipel | d053dee | 2016-07-11 15:46:29 | [diff] [blame] | 93 | uint32_t timestamp_; |
| 94 | int64_t received_time_; |
philipel | 0aeed85 | 2016-05-24 08:20:47 | [diff] [blame] | 95 | |
| 96 | // Equal to times nacked of the packet with the highet times nacked |
| 97 | // belonging to this frame. |
| 98 | int times_nacked_; |
philipel | c70e4ec | 2016-04-01 09:01:54 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | } // namespace video_coding |
| 102 | } // namespace webrtc |
| 103 | |
| 104 | #endif // WEBRTC_MODULES_VIDEO_CODING_FRAME_OBJECT_H_ |