blob: 3ee381b09146ec423d47fc52da3f1fe447a350e3 [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
11#ifndef WEBRTC_API_VIDEO_VIDEO_FRAME_H_
12#define WEBRTC_API_VIDEO_VIDEO_FRAME_H_
13
14#include <stdint.h>
15
16#include "webrtc/api/video/video_rotation.h"
17#include "webrtc/api/video/video_frame_buffer.h"
18
nisseaf916892017-01-10 07:44:26 -080019namespace webrtc {
20
21class VideoFrame {
22 public:
23 // TODO(nisse): This constructor is consistent with the now deleted
24 // cricket::WebRtcVideoFrame. We should consider whether or not we
25 // want to stick to this style and deprecate the other constructor.
26 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
27 webrtc::VideoRotation rotation,
28 int64_t timestamp_us);
29
30 // Preferred constructor.
31 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
32 uint32_t timestamp,
33 int64_t render_time_ms,
34 VideoRotation rotation);
35
36 ~VideoFrame();
37
38 // Support move and copy.
39 VideoFrame(const VideoFrame&);
40 VideoFrame(VideoFrame&&);
41 VideoFrame& operator=(const VideoFrame&);
42 VideoFrame& operator=(VideoFrame&&);
43
44 // Get frame width.
45 int width() const;
nisseaf916892017-01-10 07:44:26 -080046 // Get frame height.
47 int height() const;
kthelgason2bc68642017-02-07 07:02:22 -080048 // Get frame size in pixels.
49 uint32_t size() const;
nisseaf916892017-01-10 07:44:26 -080050
51 // System monotonic clock, same timebase as rtc::TimeMicros().
52 int64_t timestamp_us() const { return timestamp_us_; }
53 void set_timestamp_us(int64_t timestamp_us) { timestamp_us_ = timestamp_us; }
54
55 // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame
56 // merge, timestamps other than timestamp_us will likely be
57 // deprecated.
58
59 // Set frame timestamp (90kHz).
60 void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; }
61
62 // Get frame timestamp (90kHz).
63 uint32_t timestamp() const { return timestamp_rtp_; }
64
65 // For now, transport_frame_id and rtp timestamp are the same.
66 // TODO(nisse): Must be handled differently for QUIC.
67 uint32_t transport_frame_id() const { return timestamp(); }
68
69 // Set capture ntp time in milliseconds.
nisse1c0dea82017-01-30 02:43:18 -080070 // TODO(nisse): Deprecated. Migrate all users to timestamp_us().
nisseaf916892017-01-10 07:44:26 -080071 void set_ntp_time_ms(int64_t ntp_time_ms) { ntp_time_ms_ = ntp_time_ms; }
72
73 // Get capture ntp time in milliseconds.
nisse1c0dea82017-01-30 02:43:18 -080074 // TODO(nisse): Deprecated. Migrate all users to timestamp_us().
nisseaf916892017-01-10 07:44:26 -080075 int64_t ntp_time_ms() const { return ntp_time_ms_; }
76
77 // Naming convention for Coordination of Video Orientation. Please see
78 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
79 //
80 // "pending rotation" or "pending" = a frame that has a VideoRotation > 0.
81 //
82 // "not pending" = a frame that has a VideoRotation == 0.
83 //
84 // "apply rotation" = modify a frame from being "pending" to being "not
85 // pending" rotation (a no-op for "unrotated").
86 //
87 VideoRotation rotation() const { return rotation_; }
88 void set_rotation(VideoRotation rotation) { rotation_ = rotation; }
89
nisseaf916892017-01-10 07:44:26 -080090 // Get render time in milliseconds.
nisse1c0dea82017-01-30 02:43:18 -080091 // TODO(nisse): Deprecated. Migrate all users to timestamp_us().
nisseaf916892017-01-10 07:44:26 -080092 int64_t render_time_ms() const;
93
94 // Return the underlying buffer. Never nullptr for a properly
95 // initialized VideoFrame.
96 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const;
97
98 // TODO(nisse): Deprecated.
99 // Return true if the frame is stored in a texture.
100 bool is_texture() const {
magjed3f075492017-06-01 10:02:26 -0700101 return video_frame_buffer()->type() == VideoFrameBuffer::Type::kNative;
nisseaf916892017-01-10 07:44:26 -0800102 }
103
104 private:
105 // An opaque reference counted handle that stores the pixel data.
106 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_;
107 uint32_t timestamp_rtp_;
108 int64_t ntp_time_ms_;
109 int64_t timestamp_us_;
110 VideoRotation rotation_;
111};
112
113} // namespace webrtc
114
115#endif // WEBRTC_API_VIDEO_VIDEO_FRAME_H_