blob: aadfcdf52e9fa8ab480a37eb6980b3a3f7139f31 [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();
27 explicit VCMEncodedFrame(const webrtc::EncodedImage& rhs);
28 VCMEncodedFrame(const VCMEncodedFrame& rhs);
niklase@google.com470e71d2011-07-07 08:21:25 +000029
philipel9d3ab612015-12-21 04:12:39 -080030 ~VCMEncodedFrame();
31 /**
Yves Gerey665174f2018-06-19 15:03:05 +020032 * Delete VideoFrame and resets members to zero
33 */
philipel9d3ab612015-12-21 04:12:39 -080034 void Free();
35 /**
Yves Gerey665174f2018-06-19 15:03:05 +020036 * Set render time in milliseconds
37 */
philipel9d3ab612015-12-21 04:12:39 -080038 void SetRenderTime(const int64_t renderTimeMs) {
39 _renderTimeMs = renderTimeMs;
40 }
niklase@google.com470e71d2011-07-07 08:21:25 +000041
philipel9d3ab612015-12-21 04:12:39 -080042 /**
Yves Gerey665174f2018-06-19 15:03:05 +020043 * Set the encoded frame size
44 */
philipel9d3ab612015-12-21 04:12:39 -080045 void SetEncodedSize(uint32_t width, uint32_t height) {
46 _encodedWidth = width;
47 _encodedHeight = height;
48 }
gnishb2a318b2017-05-10 09:21:33 -070049
50 void SetPlayoutDelay(PlayoutDelay playout_delay) {
51 playout_delay_ = playout_delay;
52 }
53
philipel9d3ab612015-12-21 04:12:39 -080054 /**
Yves Gerey665174f2018-06-19 15:03:05 +020055 * Get the encoded image
56 */
philipel9d3ab612015-12-21 04:12:39 -080057 const webrtc::EncodedImage& EncodedImage() const {
58 return static_cast<const webrtc::EncodedImage&>(*this);
59 }
60 /**
Yves Gerey665174f2018-06-19 15:03:05 +020061 * Get pointer to frame buffer
62 */
philipel9d3ab612015-12-21 04:12:39 -080063 const uint8_t* Buffer() const { return _buffer; }
64 /**
Yves Gerey665174f2018-06-19 15:03:05 +020065 * Get frame length
66 */
philipel9d3ab612015-12-21 04:12:39 -080067 size_t Length() const { return _length; }
Niels Möllerf34d4672018-06-25 09:22:45 +020068
philipel9d3ab612015-12-21 04:12:39 -080069 /**
Niels Möllerf34d4672018-06-25 09:22:45 +020070 * Frame RTP timestamp (90kHz)
Yves Gerey665174f2018-06-19 15:03:05 +020071 */
Niels Möllerf34d4672018-06-25 09:22:45 +020072 using EncodedImage::Timestamp;
73 using EncodedImage::SetTimestamp;
philipel9d3ab612015-12-21 04:12:39 -080074 /**
Yves Gerey665174f2018-06-19 15:03:05 +020075 * Get render time in milliseconds
76 */
philipel9d3ab612015-12-21 04:12:39 -080077 int64_t RenderTimeMs() const { return _renderTimeMs; }
78 /**
Yves Gerey665174f2018-06-19 15:03:05 +020079 * Get frame type
80 */
philipel9d3ab612015-12-21 04:12:39 -080081 webrtc::FrameType FrameType() const { return _frameType; }
82 /**
Yves Gerey665174f2018-06-19 15:03:05 +020083 * Get frame rotation
84 */
perkj414dda12016-07-04 01:45:23 -070085 VideoRotation rotation() const { return rotation_; }
philipel9d3ab612015-12-21 04:12:39 -080086 /**
ilnik00d802b2017-04-11 10:34:31 -070087 * Get video content type
88 */
89 VideoContentType contentType() const { return content_type_; }
90 /**
ilnik04f4d122017-06-19 07:18:55 -070091 * Get video timing
92 */
93 EncodedImage::Timing video_timing() const { return timing_; }
94 /**
ilnik00d802b2017-04-11 10:34:31 -070095 * True if this frame is complete, false otherwise
96 */
philipel9d3ab612015-12-21 04:12:39 -080097 bool Complete() const { return _completeFrame; }
98 /**
Yves Gerey665174f2018-06-19 15:03:05 +020099 * True if there's a frame missing before this frame
100 */
philipel9d3ab612015-12-21 04:12:39 -0800101 bool MissingFrame() const { return _missingFrame; }
102 /**
Yves Gerey665174f2018-06-19 15:03:05 +0200103 * Payload type of the encoded payload
104 */
philipel9d3ab612015-12-21 04:12:39 -0800105 uint8_t PayloadType() const { return _payloadType; }
106 /**
Yves Gerey665174f2018-06-19 15:03:05 +0200107 * Get codec specific info.
108 * The returned pointer is only valid as long as the VCMEncodedFrame
109 * is valid. Also, VCMEncodedFrame owns the pointer and will delete
110 * the object.
111 */
philipel9d3ab612015-12-21 04:12:39 -0800112 const CodecSpecificInfo* CodecSpecific() const { return &_codecSpecificInfo; }
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
philipel9d3ab612015-12-21 04:12:39 -0800114 protected:
115 /**
Yves Gerey665174f2018-06-19 15:03:05 +0200116 * Verifies that current allocated buffer size is larger than or equal to the
117 * input size.
118 * If the current buffer size is smaller, a new allocation is made and the old
119 * buffer data
120 * is copied to the new buffer.
121 * Buffer size is updated to minimumSize.
122 */
philipel9d3ab612015-12-21 04:12:39 -0800123 void VerifyAndAllocate(size_t minimumSize);
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
philipel9d3ab612015-12-21 04:12:39 -0800125 void Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
philipel9d3ab612015-12-21 04:12:39 -0800127 void CopyCodecSpecific(const RTPVideoHeader* header);
henrik.lundin@webrtc.org473bac82011-08-17 09:47:33 +0000128
philipel9d3ab612015-12-21 04:12:39 -0800129 int64_t _renderTimeMs;
130 uint8_t _payloadType;
131 bool _missingFrame;
132 CodecSpecificInfo _codecSpecificInfo;
133 webrtc::VideoCodecType _codec;
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +0000134
philipel9d3ab612015-12-21 04:12:39 -0800135 // Video rotation is only set along with the last packet for each frame
136 // (same as marker bit). This |_rotation_set| is only for debugging purpose
137 // to ensure we don't set it twice for a frame.
138 bool _rotation_set;
niklase@google.com470e71d2011-07-07 08:21:25 +0000139};
140
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000141} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200143#endif // MODULES_VIDEO_CODING_ENCODED_FRAME_H_