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