blob: b04e1ca5243d5d75eb8e631809987455c0a616ed [file] [log] [blame]
Niels Möller4dc66c52018-10-05 14:17:58 +02001/*
2 * Copyright (c) 2014 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
11#ifndef API_VIDEO_ENCODED_IMAGE_H_
12#define API_VIDEO_ENCODED_IMAGE_H_
13
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stdint.h>
15
Niels Möller4dc66c52018-10-05 14:17:58 +020016#include "absl/types/optional.h"
Johannes Kron9973fa82018-11-07 14:39:26 +010017#include "api/video/hdr_metadata.h"
Yves Gerey988cc082018-10-23 12:03:01 +020018#include "api/video/video_bitrate_allocation.h"
Niels Möller4dc66c52018-10-05 14:17:58 +020019#include "api/video/video_content_type.h"
20#include "api/video/video_rotation.h"
21#include "api/video/video_timing.h"
22#include "common_types.h" // NOLINT(build/include)
Yves Gerey988cc082018-10-23 12:03:01 +020023#include "rtc_base/checks.h"
Mirko Bonadeiac194142018-10-22 17:08:37 +020024#include "rtc_base/system/rtc_export.h"
Niels Möller4dc66c52018-10-05 14:17:58 +020025
26namespace webrtc {
27
28// TODO(bug.webrtc.org/9378): This is a legacy api class, which is slowly being
29// cleaned up. Direct use of its members is strongly discouraged.
Mirko Bonadeiac194142018-10-22 17:08:37 +020030class RTC_EXPORT EncodedImage {
Niels Möller4dc66c52018-10-05 14:17:58 +020031 public:
32 static const size_t kBufferPaddingBytesH264;
33
34 // Some decoders require encoded image buffers to be padded with a small
35 // number of additional bytes (due to over-reading byte readers).
36 static size_t GetBufferPaddingBytes(VideoCodecType codec_type);
37
38 EncodedImage();
39 EncodedImage(const EncodedImage&);
40 EncodedImage(uint8_t* buffer, size_t length, size_t size);
41
42 // TODO(nisse): Change style to timestamp(), set_timestamp(), for consistency
43 // with the VideoFrame class.
44 // Set frame timestamp (90kHz).
45 void SetTimestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; }
46
47 // Get frame timestamp (90kHz).
48 uint32_t Timestamp() const { return timestamp_rtp_; }
49
50 void SetEncodeTime(int64_t encode_start_ms, int64_t encode_finish_ms);
51
52 absl::optional<int> SpatialIndex() const {
Niels Möller4dc66c52018-10-05 14:17:58 +020053 return spatial_index_;
54 }
55 void SetSpatialIndex(absl::optional<int> spatial_index) {
56 RTC_DCHECK_GE(spatial_index.value_or(0), 0);
57 RTC_DCHECK_LT(spatial_index.value_or(0), kMaxSpatialLayers);
Johannes Kron9973fa82018-11-07 14:39:26 +010058 spatial_index_ = spatial_index;
59 }
60
61 const webrtc::HdrMetadata* HdrMetadata() const {
62 return hdr_metadata_ ? &*hdr_metadata_ : nullptr;
63 }
64 void SetHdrMetadata(const webrtc::HdrMetadata* hdr_metadata) {
65 hdr_metadata_ =
66 hdr_metadata ? absl::make_optional(*hdr_metadata) : absl::nullopt;
Niels Möller4dc66c52018-10-05 14:17:58 +020067 }
68
69 uint32_t _encodedWidth = 0;
70 uint32_t _encodedHeight = 0;
71 // NTP time of the capture time in local timebase in milliseconds.
72 int64_t ntp_time_ms_ = 0;
73 int64_t capture_time_ms_ = 0;
74 FrameType _frameType = kVideoFrameDelta;
75 uint8_t* _buffer;
76 size_t _length;
77 size_t _size;
78 VideoRotation rotation_ = kVideoRotation_0;
79 VideoContentType content_type_ = VideoContentType::UNSPECIFIED;
80 bool _completeFrame = false;
81 int qp_ = -1; // Quantizer value.
82
83 // When an application indicates non-zero values here, it is taken as an
84 // indication that all future frames will be constrained with those limits
85 // until the application indicates a change again.
86 PlayoutDelay playout_delay_ = {-1, -1};
87
88 struct Timing {
89 uint8_t flags = VideoSendTiming::kInvalid;
90 int64_t encode_start_ms = 0;
91 int64_t encode_finish_ms = 0;
92 int64_t packetization_finish_ms = 0;
93 int64_t pacer_exit_ms = 0;
94 int64_t network_timestamp_ms = 0;
95 int64_t network2_timestamp_ms = 0;
96 int64_t receive_start_ms = 0;
97 int64_t receive_finish_ms = 0;
98 } timing_;
99
100 private:
101 uint32_t timestamp_rtp_ = 0;
Johannes Kron9973fa82018-11-07 14:39:26 +0100102 absl::optional<int> spatial_index_;
103 absl::optional<webrtc::HdrMetadata> hdr_metadata_;
Niels Möller4dc66c52018-10-05 14:17:58 +0200104};
105
106} // namespace webrtc
107
108#endif // API_VIDEO_ENCODED_IMAGE_H_