blob: a08eb0769c77f9f4aeb33fc9e1f15c2daec148a5 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_CODING_ENCODED_FRAME_H_
12#define MODULES_VIDEO_CODING_ENCODED_FRAME_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
stefan@webrtc.orgc5300432012-10-08 07:06:53 +000014#include <vector>
15
Mirko Bonadei71207422017-09-15 13:58:09 +020016#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "common_video/include/video_frame.h"
18#include "modules/include/module_common_types.h"
19#include "modules/video_coding/include/video_codec_interface.h"
20#include "modules/video_coding/include/video_coding_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
philipel9d3ab612015-12-21 04:12:39 -080022namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000023
philipel9d3ab612015-12-21 04:12:39 -080024class VCMEncodedFrame : protected EncodedImage {
25 public:
26 VCMEncodedFrame();
Niels Möller72f52a12018-06-26 11:14:11 +020027 VCMEncodedFrame(const VCMEncodedFrame&) = delete;
niklase@google.com470e71d2011-07-07 08:21:25 +000028
philipel9d3ab612015-12-21 04:12:39 -080029 ~VCMEncodedFrame();
30 /**
Yves Gerey665174f2018-06-19 15:03:05 +020031 * Delete VideoFrame and resets members to zero
32 */
philipel9d3ab612015-12-21 04:12:39 -080033 void Free();
34 /**
Yves Gerey665174f2018-06-19 15:03:05 +020035 * Set render time in milliseconds
36 */
philipel9d3ab612015-12-21 04:12:39 -080037 void SetRenderTime(const int64_t renderTimeMs) {
38 _renderTimeMs = renderTimeMs;
39 }
niklase@google.com470e71d2011-07-07 08:21:25 +000040
philipel9d3ab612015-12-21 04:12:39 -080041 /**
Yves Gerey665174f2018-06-19 15:03:05 +020042 * Set the encoded frame size
43 */
philipel9d3ab612015-12-21 04:12:39 -080044 void SetEncodedSize(uint32_t width, uint32_t height) {
45 _encodedWidth = width;
46 _encodedHeight = height;
47 }
gnishb2a318b2017-05-10 09:21:33 -070048
49 void SetPlayoutDelay(PlayoutDelay playout_delay) {
50 playout_delay_ = playout_delay;
51 }
52
philipel9d3ab612015-12-21 04:12:39 -080053 /**
Yves Gerey665174f2018-06-19 15:03:05 +020054 * Get the encoded image
55 */
philipel9d3ab612015-12-21 04:12:39 -080056 const webrtc::EncodedImage& EncodedImage() const {
57 return static_cast<const webrtc::EncodedImage&>(*this);
58 }
59 /**
Yves Gerey665174f2018-06-19 15:03:05 +020060 * Get pointer to frame buffer
61 */
philipel9d3ab612015-12-21 04:12:39 -080062 const uint8_t* Buffer() const { return _buffer; }
63 /**
Yves Gerey665174f2018-06-19 15:03:05 +020064 * Get frame length
65 */
philipel9d3ab612015-12-21 04:12:39 -080066 size_t Length() const { return _length; }
Niels Möller23775882018-08-16 10:24:12 +020067
philipel9d3ab612015-12-21 04:12:39 -080068 /**
Niels Möller23775882018-08-16 10:24:12 +020069 * Frame RTP timestamp (90kHz)
Yves Gerey665174f2018-06-19 15:03:05 +020070 */
Niels Möller23775882018-08-16 10:24:12 +020071 using EncodedImage::Timestamp;
72 using EncodedImage::SetTimestamp;
philipel9d3ab612015-12-21 04:12:39 -080073 /**
Yves Gerey665174f2018-06-19 15:03:05 +020074 * Get render time in milliseconds
75 */
philipel9d3ab612015-12-21 04:12:39 -080076 int64_t RenderTimeMs() const { return _renderTimeMs; }
77 /**
Yves Gerey665174f2018-06-19 15:03:05 +020078 * Get frame type
79 */
philipel9d3ab612015-12-21 04:12:39 -080080 webrtc::FrameType FrameType() const { return _frameType; }
81 /**
Yves Gerey665174f2018-06-19 15:03:05 +020082 * Get frame rotation
83 */
perkj414dda12016-07-04 01:45:23 -070084 VideoRotation rotation() const { return rotation_; }
philipel9d3ab612015-12-21 04:12:39 -080085 /**
ilnik00d802b2017-04-11 10:34:31 -070086 * Get video content type
87 */
88 VideoContentType contentType() const { return content_type_; }
89 /**
ilnik04f4d122017-06-19 07:18:55 -070090 * Get video timing
91 */
92 EncodedImage::Timing video_timing() const { return timing_; }
93 /**
ilnik00d802b2017-04-11 10:34:31 -070094 * True if this frame is complete, false otherwise
95 */
philipel9d3ab612015-12-21 04:12:39 -080096 bool Complete() const { return _completeFrame; }
97 /**
Yves Gerey665174f2018-06-19 15:03:05 +020098 * True if there's a frame missing before this frame
99 */
philipel9d3ab612015-12-21 04:12:39 -0800100 bool MissingFrame() const { return _missingFrame; }
101 /**
Yves Gerey665174f2018-06-19 15:03:05 +0200102 * Payload type of the encoded payload
103 */
philipel9d3ab612015-12-21 04:12:39 -0800104 uint8_t PayloadType() const { return _payloadType; }
105 /**
Yves Gerey665174f2018-06-19 15:03:05 +0200106 * Get codec specific info.
107 * The returned pointer is only valid as long as the VCMEncodedFrame
108 * is valid. Also, VCMEncodedFrame owns the pointer and will delete
109 * the object.
110 */
philipel9d3ab612015-12-21 04:12:39 -0800111 const CodecSpecificInfo* CodecSpecific() const { return &_codecSpecificInfo; }
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
philipel9d3ab612015-12-21 04:12:39 -0800113 protected:
114 /**
Yves Gerey665174f2018-06-19 15:03:05 +0200115 * Verifies that current allocated buffer size is larger than or equal to the
116 * input size.
117 * If the current buffer size is smaller, a new allocation is made and the old
118 * buffer data
119 * is copied to the new buffer.
120 * Buffer size is updated to minimumSize.
121 */
philipel9d3ab612015-12-21 04:12:39 -0800122 void VerifyAndAllocate(size_t minimumSize);
niklase@google.com470e71d2011-07-07 08:21:25 +0000123
philipel9d3ab612015-12-21 04:12:39 -0800124 void Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
philipel9d3ab612015-12-21 04:12:39 -0800126 void CopyCodecSpecific(const RTPVideoHeader* header);
henrik.lundin@webrtc.org473bac82011-08-17 09:47:33 +0000127
philipel9d3ab612015-12-21 04:12:39 -0800128 int64_t _renderTimeMs;
129 uint8_t _payloadType;
130 bool _missingFrame;
131 CodecSpecificInfo _codecSpecificInfo;
132 webrtc::VideoCodecType _codec;
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +0000133
philipel9d3ab612015-12-21 04:12:39 -0800134 // Video rotation is only set along with the last packet for each frame
135 // (same as marker bit). This |_rotation_set| is only for debugging purpose
136 // to ensure we don't set it twice for a frame.
137 bool _rotation_set;
niklase@google.com470e71d2011-07-07 08:21:25 +0000138};
139
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000140} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200142#endif // MODULES_VIDEO_CODING_ENCODED_FRAME_H_