blob: 2ebef31d01cf5e8d934662a83d8f85c9b2db915c [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
Niels Möller4dc66c52018-10-05 14:17:58 +020016#include "api/video/encoded_image.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/include/module_common_types.h"
18#include "modules/video_coding/include/video_codec_interface.h"
19#include "modules/video_coding/include/video_coding_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
philipel9d3ab612015-12-21 04:12:39 -080021namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022
philipel9d3ab612015-12-21 04:12:39 -080023class VCMEncodedFrame : protected EncodedImage {
24 public:
25 VCMEncodedFrame();
Niels Möller72f52a12018-06-26 11:14:11 +020026 VCMEncodedFrame(const VCMEncodedFrame&) = delete;
niklase@google.com470e71d2011-07-07 08:21:25 +000027
philipel9d3ab612015-12-21 04:12:39 -080028 ~VCMEncodedFrame();
29 /**
Yves Gerey665174f2018-06-19 15:03:05 +020030 * Set render time in milliseconds
31 */
philipel9d3ab612015-12-21 04:12:39 -080032 void SetRenderTime(const int64_t renderTimeMs) {
33 _renderTimeMs = renderTimeMs;
34 }
niklase@google.com470e71d2011-07-07 08:21:25 +000035
philipel9d3ab612015-12-21 04:12:39 -080036 /**
Yves Gerey665174f2018-06-19 15:03:05 +020037 * Set the encoded frame size
38 */
philipel9d3ab612015-12-21 04:12:39 -080039 void SetEncodedSize(uint32_t width, uint32_t height) {
40 _encodedWidth = width;
41 _encodedHeight = height;
42 }
gnishb2a318b2017-05-10 09:21:33 -070043
44 void SetPlayoutDelay(PlayoutDelay playout_delay) {
45 playout_delay_ = playout_delay;
46 }
47
philipel9d3ab612015-12-21 04:12:39 -080048 /**
Yves Gerey665174f2018-06-19 15:03:05 +020049 * Get the encoded image
50 */
philipel9d3ab612015-12-21 04:12:39 -080051 const webrtc::EncodedImage& EncodedImage() const {
52 return static_cast<const webrtc::EncodedImage&>(*this);
53 }
Niels Möller9c843902019-01-11 10:21:35 +010054
Ilya Nikolaevskiy2ebf5232019-05-13 16:13:36 +020055 using EncodedImage::ColorSpace;
Niels Möller9c843902019-01-11 10:21:35 +010056 using EncodedImage::data;
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +010057 using EncodedImage::set_size;
Ilya Nikolaevskiy2ebf5232019-05-13 16:13:36 +020058 using EncodedImage::SetColorSpace;
Niels Möller4d504c72019-06-18 15:56:56 +020059 using EncodedImage::SetEncodedData;
Sergey Silkin61832dd2018-12-20 14:32:14 +010060 using EncodedImage::SetSpatialIndex;
Sergey Silkin2799e632019-05-17 09:51:39 +020061 using EncodedImage::SetSpatialLayerFrameSize;
Niels Möller23775882018-08-16 10:24:12 +020062 using EncodedImage::SetTimestamp;
Niels Möllerf0eee002018-11-28 16:31:29 +010063 using EncodedImage::size;
Sergey Silkin2799e632019-05-17 09:51:39 +020064 using EncodedImage::SpatialIndex;
65 using EncodedImage::SpatialLayerFrameSize;
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +010066 using EncodedImage::Timestamp;
67
philipel9d3ab612015-12-21 04:12:39 -080068 /**
Yves Gerey665174f2018-06-19 15:03:05 +020069 * Get render time in milliseconds
70 */
philipel9d3ab612015-12-21 04:12:39 -080071 int64_t RenderTimeMs() const { return _renderTimeMs; }
72 /**
Yves Gerey665174f2018-06-19 15:03:05 +020073 * Get frame type
74 */
Niels Möller87e2d782019-03-07 10:18:23 +010075 webrtc::VideoFrameType FrameType() const { return _frameType; }
philipel9d3ab612015-12-21 04:12:39 -080076 /**
Yves Gerey665174f2018-06-19 15:03:05 +020077 * Get frame rotation
78 */
perkj414dda12016-07-04 01:45:23 -070079 VideoRotation rotation() const { return rotation_; }
philipel9d3ab612015-12-21 04:12:39 -080080 /**
ilnik00d802b2017-04-11 10:34:31 -070081 * Get video content type
82 */
83 VideoContentType contentType() const { return content_type_; }
84 /**
ilnik04f4d122017-06-19 07:18:55 -070085 * Get video timing
86 */
87 EncodedImage::Timing video_timing() const { return timing_; }
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +010088 EncodedImage::Timing* video_timing_mutable() { return &timing_; }
ilnik04f4d122017-06-19 07:18:55 -070089 /**
ilnik00d802b2017-04-11 10:34:31 -070090 * True if this frame is complete, false otherwise
91 */
philipel9d3ab612015-12-21 04:12:39 -080092 bool Complete() const { return _completeFrame; }
93 /**
Yves Gerey665174f2018-06-19 15:03:05 +020094 * True if there's a frame missing before this frame
95 */
philipel9d3ab612015-12-21 04:12:39 -080096 bool MissingFrame() const { return _missingFrame; }
97 /**
Yves Gerey665174f2018-06-19 15:03:05 +020098 * Payload type of the encoded payload
99 */
philipel9d3ab612015-12-21 04:12:39 -0800100 uint8_t PayloadType() const { return _payloadType; }
101 /**
Yves Gerey665174f2018-06-19 15:03:05 +0200102 * Get codec specific info.
103 * The returned pointer is only valid as long as the VCMEncodedFrame
104 * is valid. Also, VCMEncodedFrame owns the pointer and will delete
105 * the object.
106 */
philipel9d3ab612015-12-21 04:12:39 -0800107 const CodecSpecificInfo* CodecSpecific() const { return &_codecSpecificInfo; }
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +0100108 void SetCodecSpecific(const CodecSpecificInfo* codec_specific) {
109 _codecSpecificInfo = *codec_specific;
110 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
philipel9d3ab612015-12-21 04:12:39 -0800112 /**
Yves Gerey665174f2018-06-19 15:03:05 +0200113 * Verifies that current allocated buffer size is larger than or equal to the
114 * input size.
115 * If the current buffer size is smaller, a new allocation is made and the old
116 * buffer data
117 * is copied to the new buffer.
118 * Buffer size is updated to minimumSize.
119 */
philipel9d3ab612015-12-21 04:12:39 -0800120 void VerifyAndAllocate(size_t minimumSize);
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +0100122 protected:
philipel9d3ab612015-12-21 04:12:39 -0800123 void Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
philipel9d3ab612015-12-21 04:12:39 -0800125 void CopyCodecSpecific(const RTPVideoHeader* header);
henrik.lundin@webrtc.org473bac82011-08-17 09:47:33 +0000126
philipel9d3ab612015-12-21 04:12:39 -0800127 int64_t _renderTimeMs;
128 uint8_t _payloadType;
129 bool _missingFrame;
130 CodecSpecificInfo _codecSpecificInfo;
131 webrtc::VideoCodecType _codec;
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +0000132
philipel9d3ab612015-12-21 04:12:39 -0800133 // Video rotation is only set along with the last packet for each frame
134 // (same as marker bit). This |_rotation_set| is only for debugging purpose
135 // to ensure we don't set it twice for a frame.
136 bool _rotation_set;
niklase@google.com470e71d2011-07-07 08:21:25 +0000137};
138
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000139} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200141#endif // MODULES_VIDEO_CODING_ENCODED_FRAME_H_