blob: 8840782cad03ba70e69657b227e8ddf7aabfbcb3 [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
19// TODO(nisse): Transition hack, some downstream applications expect
20// that including this file also defines base/timeutils.h constants.
21// Delete after applications are fixed to include the right headers.
22#include "webrtc/base/timeutils.h"
23
24namespace webrtc {
25
26class VideoFrame {
27 public:
28 // TODO(nisse): This constructor is consistent with the now deleted
29 // cricket::WebRtcVideoFrame. We should consider whether or not we
30 // want to stick to this style and deprecate the other constructor.
31 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
32 webrtc::VideoRotation rotation,
33 int64_t timestamp_us);
34
35 // Preferred constructor.
36 VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
37 uint32_t timestamp,
38 int64_t render_time_ms,
39 VideoRotation rotation);
40
41 ~VideoFrame();
42
43 // Support move and copy.
44 VideoFrame(const VideoFrame&);
45 VideoFrame(VideoFrame&&);
46 VideoFrame& operator=(const VideoFrame&);
47 VideoFrame& operator=(VideoFrame&&);
48
49 // Get frame width.
50 int width() const;
nisseaf916892017-01-10 07:44:26 -080051 // Get frame height.
52 int height() const;
kthelgason2bc68642017-02-07 07:02:22 -080053 // Get frame size in pixels.
54 uint32_t size() const;
nisseaf916892017-01-10 07:44:26 -080055
56 // System monotonic clock, same timebase as rtc::TimeMicros().
57 int64_t timestamp_us() const { return timestamp_us_; }
58 void set_timestamp_us(int64_t timestamp_us) { timestamp_us_ = timestamp_us; }
59
60 // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame
61 // merge, timestamps other than timestamp_us will likely be
62 // deprecated.
63
64 // Set frame timestamp (90kHz).
65 void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; }
66
67 // Get frame timestamp (90kHz).
68 uint32_t timestamp() const { return timestamp_rtp_; }
69
70 // For now, transport_frame_id and rtp timestamp are the same.
71 // TODO(nisse): Must be handled differently for QUIC.
72 uint32_t transport_frame_id() const { return timestamp(); }
73
74 // Set capture ntp time in milliseconds.
nisse1c0dea82017-01-30 02:43:18 -080075 // TODO(nisse): Deprecated. Migrate all users to timestamp_us().
nisseaf916892017-01-10 07:44:26 -080076 void set_ntp_time_ms(int64_t ntp_time_ms) { ntp_time_ms_ = ntp_time_ms; }
77
78 // Get capture ntp time in milliseconds.
nisse1c0dea82017-01-30 02:43:18 -080079 // TODO(nisse): Deprecated. Migrate all users to timestamp_us().
nisseaf916892017-01-10 07:44:26 -080080 int64_t ntp_time_ms() const { return ntp_time_ms_; }
81
82 // Naming convention for Coordination of Video Orientation. Please see
83 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
84 //
85 // "pending rotation" or "pending" = a frame that has a VideoRotation > 0.
86 //
87 // "not pending" = a frame that has a VideoRotation == 0.
88 //
89 // "apply rotation" = modify a frame from being "pending" to being "not
90 // pending" rotation (a no-op for "unrotated").
91 //
92 VideoRotation rotation() const { return rotation_; }
93 void set_rotation(VideoRotation rotation) { rotation_ = rotation; }
94
nisseaf916892017-01-10 07:44:26 -080095 // Get render time in milliseconds.
nisse1c0dea82017-01-30 02:43:18 -080096 // TODO(nisse): Deprecated. Migrate all users to timestamp_us().
nisseaf916892017-01-10 07:44:26 -080097 int64_t render_time_ms() const;
98
99 // Return the underlying buffer. Never nullptr for a properly
100 // initialized VideoFrame.
101 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const;
102
103 // TODO(nisse): Deprecated.
104 // Return true if the frame is stored in a texture.
105 bool is_texture() const {
106 return video_frame_buffer()->native_handle() != nullptr;
107 }
108
109 private:
110 // An opaque reference counted handle that stores the pixel data.
111 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_;
112 uint32_t timestamp_rtp_;
113 int64_t ntp_time_ms_;
114 int64_t timestamp_us_;
115 VideoRotation rotation_;
116};
117
118} // namespace webrtc
119
120#endif // WEBRTC_API_VIDEO_VIDEO_FRAME_H_