blob: bd5482025a7762525a3323cf50030017ad0bfadc [file] [log] [blame]
nisseaf916892017-01-10 07:44:26 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef API_VIDEO_VIDEO_FRAME_H_
12#define API_VIDEO_VIDEO_FRAME_H_
nisseaf916892017-01-10 07:44:26 -080013
14#include <stdint.h>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/video/video_rotation.h"
17#include "api/video/video_frame_buffer.h"
nisseaf916892017-01-10 07:44:26 -080018
nisseaf916892017-01-10 07:44:26 -080019namespace webrtc {
20
21class VideoFrame {
22 public:
Niels Möller2ac64462018-06-11 11:14:32 +020023 // Preferred constructor.
nisseaf916892017-01-10 07:44:26 -080024 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
25 webrtc::VideoRotation rotation,
26 int64_t timestamp_us);
27
Niels Möller2ac64462018-06-11 11:14:32 +020028 // For use by the parts of the pipeline that needs the RTP 90kHz timestamp.
nisseaf916892017-01-10 07:44:26 -080029 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
Niels Möller2ac64462018-06-11 11:14:32 +020030 uint32_t timestamp_rtp,
nisseaf916892017-01-10 07:44:26 -080031 int64_t render_time_ms,
32 VideoRotation rotation);
33
34 ~VideoFrame();
35
36 // Support move and copy.
37 VideoFrame(const VideoFrame&);
38 VideoFrame(VideoFrame&&);
39 VideoFrame& operator=(const VideoFrame&);
40 VideoFrame& operator=(VideoFrame&&);
41
42 // Get frame width.
43 int width() const;
nisseaf916892017-01-10 07:44:26 -080044 // Get frame height.
45 int height() const;
kthelgason2bc68642017-02-07 07:02:22 -080046 // Get frame size in pixels.
47 uint32_t size() const;
nisseaf916892017-01-10 07:44:26 -080048
49 // System monotonic clock, same timebase as rtc::TimeMicros().
50 int64_t timestamp_us() const { return timestamp_us_; }
51 void set_timestamp_us(int64_t timestamp_us) { timestamp_us_ = timestamp_us; }
52
53 // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame
54 // merge, timestamps other than timestamp_us will likely be
55 // deprecated.
56
57 // Set frame timestamp (90kHz).
58 void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; }
59
60 // Get frame timestamp (90kHz).
61 uint32_t timestamp() const { return timestamp_rtp_; }
62
63 // For now, transport_frame_id and rtp timestamp are the same.
64 // TODO(nisse): Must be handled differently for QUIC.
65 uint32_t transport_frame_id() const { return timestamp(); }
66
67 // Set capture ntp time in milliseconds.
nisse1c0dea82017-01-30 02:43:18 -080068 // TODO(nisse): Deprecated. Migrate all users to timestamp_us().
nisseaf916892017-01-10 07:44:26 -080069 void set_ntp_time_ms(int64_t ntp_time_ms) { ntp_time_ms_ = ntp_time_ms; }
70
71 // Get capture ntp time in milliseconds.
nisse1c0dea82017-01-30 02:43:18 -080072 // TODO(nisse): Deprecated. Migrate all users to timestamp_us().
nisseaf916892017-01-10 07:44:26 -080073 int64_t ntp_time_ms() const { return ntp_time_ms_; }
74
75 // Naming convention for Coordination of Video Orientation. Please see
76 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
77 //
78 // "pending rotation" or "pending" = a frame that has a VideoRotation > 0.
79 //
80 // "not pending" = a frame that has a VideoRotation == 0.
81 //
82 // "apply rotation" = modify a frame from being "pending" to being "not
83 // pending" rotation (a no-op for "unrotated").
84 //
85 VideoRotation rotation() const { return rotation_; }
86 void set_rotation(VideoRotation rotation) { rotation_ = rotation; }
87
nisseaf916892017-01-10 07:44:26 -080088 // Get render time in milliseconds.
nisse1c0dea82017-01-30 02:43:18 -080089 // TODO(nisse): Deprecated. Migrate all users to timestamp_us().
nisseaf916892017-01-10 07:44:26 -080090 int64_t render_time_ms() const;
91
92 // Return the underlying buffer. Never nullptr for a properly
93 // initialized VideoFrame.
94 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const;
95
96 // TODO(nisse): Deprecated.
97 // Return true if the frame is stored in a texture.
98 bool is_texture() const {
magjed3f075492017-06-01 10:02:26 -070099 return video_frame_buffer()->type() == VideoFrameBuffer::Type::kNative;
nisseaf916892017-01-10 07:44:26 -0800100 }
101
102 private:
103 // An opaque reference counted handle that stores the pixel data.
104 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_;
105 uint32_t timestamp_rtp_;
106 int64_t ntp_time_ms_;
107 int64_t timestamp_us_;
108 VideoRotation rotation_;
109};
110
111} // namespace webrtc
112
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200113#endif // API_VIDEO_VIDEO_FRAME_H_