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