blob: eeaea1532e298352fb7f0bf401eaed25606ed7bf [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 Bonadei71207422017-09-15 13:58:09 +020017#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#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 * Set render time in milliseconds
32 */
philipel9d3ab612015-12-21 04:12:39 -080033 void SetRenderTime(const int64_t renderTimeMs) {
34 _renderTimeMs = renderTimeMs;
35 }
niklase@google.com470e71d2011-07-07 08:21:25 +000036
philipel9d3ab612015-12-21 04:12:39 -080037 /**
Yves Gerey665174f2018-06-19 15:03:05 +020038 * Set the encoded frame size
39 */
philipel9d3ab612015-12-21 04:12:39 -080040 void SetEncodedSize(uint32_t width, uint32_t height) {
41 _encodedWidth = width;
42 _encodedHeight = height;
43 }
gnishb2a318b2017-05-10 09:21:33 -070044
45 void SetPlayoutDelay(PlayoutDelay playout_delay) {
46 playout_delay_ = playout_delay;
47 }
48
philipel9d3ab612015-12-21 04:12:39 -080049 /**
Yves Gerey665174f2018-06-19 15:03:05 +020050 * Get the encoded image
51 */
philipel9d3ab612015-12-21 04:12:39 -080052 const webrtc::EncodedImage& EncodedImage() const {
53 return static_cast<const webrtc::EncodedImage&>(*this);
54 }
Niels Möller9c843902019-01-11 10:21:35 +010055
56 using EncodedImage::data;
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +010057 using EncodedImage::set_size;
Sergey Silkin61832dd2018-12-20 14:32:14 +010058 using EncodedImage::SetSpatialIndex;
Niels Möller23775882018-08-16 10:24:12 +020059 using EncodedImage::SetTimestamp;
Niels Möllerf0eee002018-11-28 16:31:29 +010060 using EncodedImage::size;
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +010061 using EncodedImage::Timestamp;
62
philipel9d3ab612015-12-21 04:12:39 -080063 /**
Yves Gerey665174f2018-06-19 15:03:05 +020064 * Get render time in milliseconds
65 */
philipel9d3ab612015-12-21 04:12:39 -080066 int64_t RenderTimeMs() const { return _renderTimeMs; }
67 /**
Yves Gerey665174f2018-06-19 15:03:05 +020068 * Get frame type
69 */
philipel9d3ab612015-12-21 04:12:39 -080070 webrtc::FrameType FrameType() const { return _frameType; }
71 /**
Yves Gerey665174f2018-06-19 15:03:05 +020072 * Get frame rotation
73 */
perkj414dda12016-07-04 01:45:23 -070074 VideoRotation rotation() const { return rotation_; }
philipel9d3ab612015-12-21 04:12:39 -080075 /**
ilnik00d802b2017-04-11 10:34:31 -070076 * Get video content type
77 */
78 VideoContentType contentType() const { return content_type_; }
79 /**
ilnik04f4d122017-06-19 07:18:55 -070080 * Get video timing
81 */
82 EncodedImage::Timing video_timing() const { return timing_; }
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +010083 EncodedImage::Timing* video_timing_mutable() { return &timing_; }
ilnik04f4d122017-06-19 07:18:55 -070084 /**
ilnik00d802b2017-04-11 10:34:31 -070085 * True if this frame is complete, false otherwise
86 */
philipel9d3ab612015-12-21 04:12:39 -080087 bool Complete() const { return _completeFrame; }
88 /**
Yves Gerey665174f2018-06-19 15:03:05 +020089 * True if there's a frame missing before this frame
90 */
philipel9d3ab612015-12-21 04:12:39 -080091 bool MissingFrame() const { return _missingFrame; }
92 /**
Yves Gerey665174f2018-06-19 15:03:05 +020093 * Payload type of the encoded payload
94 */
philipel9d3ab612015-12-21 04:12:39 -080095 uint8_t PayloadType() const { return _payloadType; }
96 /**
Yves Gerey665174f2018-06-19 15:03:05 +020097 * Get codec specific info.
98 * The returned pointer is only valid as long as the VCMEncodedFrame
99 * is valid. Also, VCMEncodedFrame owns the pointer and will delete
100 * the object.
101 */
philipel9d3ab612015-12-21 04:12:39 -0800102 const CodecSpecificInfo* CodecSpecific() const { return &_codecSpecificInfo; }
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +0100103 void SetCodecSpecific(const CodecSpecificInfo* codec_specific) {
104 _codecSpecificInfo = *codec_specific;
105 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
philipel9d3ab612015-12-21 04:12:39 -0800107 /**
Yves Gerey665174f2018-06-19 15:03:05 +0200108 * Verifies that current allocated buffer size is larger than or equal to the
109 * input size.
110 * If the current buffer size is smaller, a new allocation is made and the old
111 * buffer data
112 * is copied to the new buffer.
113 * Buffer size is updated to minimumSize.
114 */
philipel9d3ab612015-12-21 04:12:39 -0800115 void VerifyAndAllocate(size_t minimumSize);
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +0100117 protected:
philipel9d3ab612015-12-21 04:12:39 -0800118 void Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
philipel9d3ab612015-12-21 04:12:39 -0800120 void CopyCodecSpecific(const RTPVideoHeader* header);
henrik.lundin@webrtc.org473bac82011-08-17 09:47:33 +0000121
philipel9d3ab612015-12-21 04:12:39 -0800122 int64_t _renderTimeMs;
123 uint8_t _payloadType;
124 bool _missingFrame;
125 CodecSpecificInfo _codecSpecificInfo;
126 webrtc::VideoCodecType _codec;
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +0000127
philipel9d3ab612015-12-21 04:12:39 -0800128 // Video rotation is only set along with the last packet for each frame
129 // (same as marker bit). This |_rotation_set| is only for debugging purpose
130 // to ensure we don't set it twice for a frame.
131 bool _rotation_set;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132};
133
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000134} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200136#endif // MODULES_VIDEO_CODING_ENCODED_FRAME_H_