encoded_frame.h (3987B)
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 API_VIDEO_ENCODED_FRAME_H_ 12 #define API_VIDEO_ENCODED_FRAME_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <optional> 18 19 #include "api/units/timestamp.h" 20 #include "api/video/corruption_detection/frame_instrumentation_data.h" 21 #include "api/video/encoded_image.h" 22 #include "api/video/video_codec_type.h" 23 #include "modules/rtp_rtcp/source/rtp_video_header.h" 24 #include "modules/video_coding/include/video_codec_interface.h" 25 26 namespace webrtc { 27 28 // TODO(philipel): Move transport specific info out of EncodedFrame. 29 // NOTE: This class is still under development and may change without notice. 30 class EncodedFrame : public EncodedImage { 31 public: 32 static const uint8_t kMaxFrameReferences = 5; 33 34 EncodedFrame() = default; 35 EncodedFrame(const EncodedFrame&) = default; 36 virtual ~EncodedFrame() {} 37 38 // When this frame was received. 39 // TODO(bugs.webrtc.org/13756): Use Timestamp instead of int. 40 virtual int64_t ReceivedTime() const { return -1; } 41 // Returns a Timestamp from `ReceivedTime`, or nullopt if there is no receive 42 // time. 43 std::optional<Timestamp> ReceivedTimestamp() const; 44 45 // When this frame should be rendered. 46 // TODO(bugs.webrtc.org/13756): Use Timestamp instead of int. 47 virtual int64_t RenderTime() const { return _renderTimeMs; } 48 // TODO(bugs.webrtc.org/13756): Migrate to ReceivedTimestamp. 49 int64_t RenderTimeMs() const { return _renderTimeMs; } 50 // Returns a Timestamp from `RenderTime`, or nullopt if there is no 51 // render time. 52 std::optional<Timestamp> RenderTimestamp() const; 53 54 // This information is currently needed by the timing calculation class. 55 // TODO(philipel): Remove this function when a new timing class has 56 // been implemented. 57 virtual bool delayed_by_retransmission() const; 58 59 bool is_keyframe() const { return num_references == 0; } 60 61 void SetId(int64_t id) { id_ = id; } 62 int64_t Id() const { return id_; } 63 64 uint8_t PayloadType() const { return _payloadType; } 65 66 void SetRenderTime(const int64_t renderTimeMs) { 67 _renderTimeMs = renderTimeMs; 68 } 69 70 const webrtc::EncodedImage& EncodedImage() const { 71 return static_cast<const webrtc::EncodedImage&>(*this); 72 } 73 74 const CodecSpecificInfo* CodecSpecific() const { return &_codecSpecificInfo; } 75 void SetCodecSpecific(const CodecSpecificInfo* codec_specific) { 76 _codecSpecificInfo = *codec_specific; 77 } 78 void SetFrameInstrumentationData( 79 const std::optional<FrameInstrumentationData> frame_instrumentation) { 80 _codecSpecificInfo.frame_instrumentation_data = frame_instrumentation; 81 } 82 83 // TODO(philipel): Add simple modify/access functions to prevent adding too 84 // many `references`. 85 size_t num_references = 0; 86 int64_t references[kMaxFrameReferences]; 87 // Is this subframe the last one in the superframe (In RTP stream that would 88 // mean that the last packet has a marker bit set). 89 bool is_last_spatial_layer = true; 90 91 protected: 92 // TODO(https://bugs.webrtc.org/9378): Move RTP specifics down into a 93 // transport-aware subclass, eg RtpFrameObject. 94 void CopyCodecSpecific(const RTPVideoHeader* header); 95 96 // TODO(https://bugs.webrtc.org/9378): Make fields private with 97 // getters/setters as needed. 98 int64_t _renderTimeMs = -1; 99 uint8_t _payloadType = 0; 100 CodecSpecificInfo _codecSpecificInfo; 101 VideoCodecType _codec = kVideoCodecGeneric; 102 103 private: 104 // The ID of the frame is determined from RTP level information. The IDs are 105 // used to describe order and dependencies between frames. 106 int64_t id_ = -1; 107 }; 108 109 } // namespace webrtc 110 111 #endif // API_VIDEO_ENCODED_FRAME_H_