blob: ed58d969525214a0a25c14930763dd0954de10d3 [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
14#include "absl/types/optional.h"
15#include "api/video/video_content_type.h"
16#include "api/video/video_rotation.h"
17#include "api/video/video_timing.h"
18#include "common_types.h" // NOLINT(build/include)
19
20namespace webrtc {
21
22// TODO(bug.webrtc.org/9378): This is a legacy api class, which is slowly being
23// cleaned up. Direct use of its members is strongly discouraged.
24class EncodedImage {
25 public:
26 static const size_t kBufferPaddingBytesH264;
27
28 // Some decoders require encoded image buffers to be padded with a small
29 // number of additional bytes (due to over-reading byte readers).
30 static size_t GetBufferPaddingBytes(VideoCodecType codec_type);
31
32 EncodedImage();
33 EncodedImage(const EncodedImage&);
34 EncodedImage(uint8_t* buffer, size_t length, size_t size);
35
36 // TODO(nisse): Change style to timestamp(), set_timestamp(), for consistency
37 // with the VideoFrame class.
38 // Set frame timestamp (90kHz).
39 void SetTimestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; }
40
41 // Get frame timestamp (90kHz).
42 uint32_t Timestamp() const { return timestamp_rtp_; }
43
44 void SetEncodeTime(int64_t encode_start_ms, int64_t encode_finish_ms);
45
46 absl::optional<int> SpatialIndex() const {
47 if (spatial_index_ < 0)
48 return absl::nullopt;
49 return spatial_index_;
50 }
51 void SetSpatialIndex(absl::optional<int> spatial_index) {
52 RTC_DCHECK_GE(spatial_index.value_or(0), 0);
53 RTC_DCHECK_LT(spatial_index.value_or(0), kMaxSpatialLayers);
54 spatial_index_ = spatial_index.value_or(-1);
55 }
56
57 uint32_t _encodedWidth = 0;
58 uint32_t _encodedHeight = 0;
59 // NTP time of the capture time in local timebase in milliseconds.
60 int64_t ntp_time_ms_ = 0;
61 int64_t capture_time_ms_ = 0;
62 FrameType _frameType = kVideoFrameDelta;
63 uint8_t* _buffer;
64 size_t _length;
65 size_t _size;
66 VideoRotation rotation_ = kVideoRotation_0;
67 VideoContentType content_type_ = VideoContentType::UNSPECIFIED;
68 bool _completeFrame = false;
69 int qp_ = -1; // Quantizer value.
70
71 // When an application indicates non-zero values here, it is taken as an
72 // indication that all future frames will be constrained with those limits
73 // until the application indicates a change again.
74 PlayoutDelay playout_delay_ = {-1, -1};
75
76 struct Timing {
77 uint8_t flags = VideoSendTiming::kInvalid;
78 int64_t encode_start_ms = 0;
79 int64_t encode_finish_ms = 0;
80 int64_t packetization_finish_ms = 0;
81 int64_t pacer_exit_ms = 0;
82 int64_t network_timestamp_ms = 0;
83 int64_t network2_timestamp_ms = 0;
84 int64_t receive_start_ms = 0;
85 int64_t receive_finish_ms = 0;
86 } timing_;
87
88 private:
89 uint32_t timestamp_rtp_ = 0;
90 // -1 means not set. Use a plain int rather than optional, to keep this class
91 // copyable with memcpy.
92 int spatial_index_ = -1;
93};
94
95} // namespace webrtc
96
97#endif // API_VIDEO_ENCODED_IMAGE_H_