niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_ENCODED_FRAME_H_ |
| 12 | #define MODULES_VIDEO_CODING_ENCODED_FRAME_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
stefan@webrtc.org | c530043 | 2012-10-08 07:06:53 +0000 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
Niels Möller | 4dc66c5 | 2018-10-05 14:17:58 +0200 | [diff] [blame] | 16 | #include "api/video/encoded_image.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 23 | class VCMEncodedFrame : protected EncodedImage { |
| 24 | public: |
| 25 | VCMEncodedFrame(); |
Niels Möller | 72f52a1 | 2018-06-26 11:14:11 +0200 | [diff] [blame] | 26 | VCMEncodedFrame(const VCMEncodedFrame&) = delete; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 28 | ~VCMEncodedFrame(); |
| 29 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 30 | * Set render time in milliseconds |
| 31 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 32 | void SetRenderTime(const int64_t renderTimeMs) { |
| 33 | _renderTimeMs = renderTimeMs; |
| 34 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 36 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 37 | * Set the encoded frame size |
| 38 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 39 | void SetEncodedSize(uint32_t width, uint32_t height) { |
| 40 | _encodedWidth = width; |
| 41 | _encodedHeight = height; |
| 42 | } |
gnish | b2a318b | 2017-05-10 09:21:33 -0700 | [diff] [blame] | 43 | |
| 44 | void SetPlayoutDelay(PlayoutDelay playout_delay) { |
| 45 | playout_delay_ = playout_delay; |
| 46 | } |
| 47 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 48 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 49 | * Get the encoded image |
| 50 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 51 | const webrtc::EncodedImage& EncodedImage() const { |
| 52 | return static_cast<const webrtc::EncodedImage&>(*this); |
| 53 | } |
Niels Möller | 9c84390 | 2019-01-11 10:21:35 +0100 | [diff] [blame] | 54 | |
Ilya Nikolaevskiy | 2ebf523 | 2019-05-13 16:13:36 +0200 | [diff] [blame] | 55 | using EncodedImage::ColorSpace; |
Niels Möller | 9c84390 | 2019-01-11 10:21:35 +0100 | [diff] [blame] | 56 | using EncodedImage::data; |
Ilya Nikolaevskiy | 5546aef | 2018-12-04 15:54:52 +0100 | [diff] [blame] | 57 | using EncodedImage::set_size; |
Ilya Nikolaevskiy | 2ebf523 | 2019-05-13 16:13:36 +0200 | [diff] [blame] | 58 | using EncodedImage::SetColorSpace; |
Sergey Silkin | 61832dd | 2018-12-20 14:32:14 +0100 | [diff] [blame] | 59 | using EncodedImage::SetSpatialIndex; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 60 | using EncodedImage::SetTimestamp; |
Niels Möller | f0eee00 | 2018-11-28 16:31:29 +0100 | [diff] [blame] | 61 | using EncodedImage::size; |
Ilya Nikolaevskiy | 5546aef | 2018-12-04 15:54:52 +0100 | [diff] [blame] | 62 | using EncodedImage::Timestamp; |
| 63 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 64 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 65 | * Get render time in milliseconds |
| 66 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 67 | int64_t RenderTimeMs() const { return _renderTimeMs; } |
| 68 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 69 | * Get frame type |
| 70 | */ |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 71 | webrtc::VideoFrameType FrameType() const { return _frameType; } |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 72 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 73 | * Get frame rotation |
| 74 | */ |
perkj | 414dda1 | 2016-07-04 01:45:23 -0700 | [diff] [blame] | 75 | VideoRotation rotation() const { return rotation_; } |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 76 | /** |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 77 | * Get video content type |
| 78 | */ |
| 79 | VideoContentType contentType() const { return content_type_; } |
| 80 | /** |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 81 | * Get video timing |
| 82 | */ |
| 83 | EncodedImage::Timing video_timing() const { return timing_; } |
Ilya Nikolaevskiy | 5546aef | 2018-12-04 15:54:52 +0100 | [diff] [blame] | 84 | EncodedImage::Timing* video_timing_mutable() { return &timing_; } |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 85 | /** |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 86 | * True if this frame is complete, false otherwise |
| 87 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 88 | bool Complete() const { return _completeFrame; } |
| 89 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 90 | * True if there's a frame missing before this frame |
| 91 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 92 | bool MissingFrame() const { return _missingFrame; } |
| 93 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 94 | * Payload type of the encoded payload |
| 95 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 96 | uint8_t PayloadType() const { return _payloadType; } |
| 97 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 98 | * Get codec specific info. |
| 99 | * The returned pointer is only valid as long as the VCMEncodedFrame |
| 100 | * is valid. Also, VCMEncodedFrame owns the pointer and will delete |
| 101 | * the object. |
| 102 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 103 | const CodecSpecificInfo* CodecSpecific() const { return &_codecSpecificInfo; } |
Ilya Nikolaevskiy | 5546aef | 2018-12-04 15:54:52 +0100 | [diff] [blame] | 104 | void SetCodecSpecific(const CodecSpecificInfo* codec_specific) { |
| 105 | _codecSpecificInfo = *codec_specific; |
| 106 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 108 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 109 | * Verifies that current allocated buffer size is larger than or equal to the |
| 110 | * input size. |
| 111 | * If the current buffer size is smaller, a new allocation is made and the old |
| 112 | * buffer data |
| 113 | * is copied to the new buffer. |
| 114 | * Buffer size is updated to minimumSize. |
| 115 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 116 | void VerifyAndAllocate(size_t minimumSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | |
Ilya Nikolaevskiy | 5546aef | 2018-12-04 15:54:52 +0100 | [diff] [blame] | 118 | protected: |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 119 | void Reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 121 | void CopyCodecSpecific(const RTPVideoHeader* header); |
henrik.lundin@webrtc.org | 473bac8 | 2011-08-17 09:47:33 +0000 | [diff] [blame] | 122 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 123 | int64_t _renderTimeMs; |
| 124 | uint8_t _payloadType; |
| 125 | bool _missingFrame; |
| 126 | CodecSpecificInfo _codecSpecificInfo; |
| 127 | webrtc::VideoCodecType _codec; |
guoweis@webrtc.org | 54d072e | 2015-03-17 21:54:50 +0000 | [diff] [blame] | 128 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 129 | // Video rotation is only set along with the last packet for each frame |
| 130 | // (same as marker bit). This |_rotation_set| is only for debugging purpose |
| 131 | // to ensure we don't set it twice for a frame. |
| 132 | bool _rotation_set; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 135 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 137 | #endif // MODULES_VIDEO_CODING_ENCODED_FRAME_H_ |