Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1341)

Side by Side Diff: webrtc/common_video/video_frame.cc

Issue 2282713002: Introduce webrtc::VideoFrame::timestamp_us, and corresponding constructor. (Closed)
Patch Set: Rename timestamp_ --> timestamp_rtp_ Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvideoengine2.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/video_frame.h" 11 #include "webrtc/video_frame.h"
12 12
13 #include <string.h> 13 #include <string.h>
14 14
15 #include <algorithm> // swap 15 #include <algorithm> // swap
16 16
17 #include "webrtc/base/bind.h" 17 #include "webrtc/base/bind.h"
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 21
22 // FFmpeg's decoder, used by H264DecoderImpl, requires up to 8 bytes padding due 22 // FFmpeg's decoder, used by H264DecoderImpl, requires up to 8 bytes padding due
23 // to optimized bitstream readers. See avcodec_decode_video2. 23 // to optimized bitstream readers. See avcodec_decode_video2.
24 const size_t EncodedImage::kBufferPaddingBytesH264 = 8; 24 const size_t EncodedImage::kBufferPaddingBytesH264 = 8;
25 25
26 VideoFrame::VideoFrame() 26 VideoFrame::VideoFrame()
27 : video_frame_buffer_(nullptr), 27 : video_frame_buffer_(nullptr),
28 timestamp_(0), 28 timestamp_rtp_(0),
29 ntp_time_ms_(0), 29 ntp_time_ms_(0),
30 render_time_ms_(0), 30 timestamp_us_(0),
31 rotation_(kVideoRotation_0) {} 31 rotation_(kVideoRotation_0) {}
32 32
33 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, 33 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
34 webrtc::VideoRotation rotation,
35 int64_t timestamp_us)
36 : video_frame_buffer_(buffer),
37 timestamp_rtp_(0),
38 ntp_time_ms_(0),
39 timestamp_us_(timestamp_us),
40 rotation_(rotation) {}
41
42 VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
34 uint32_t timestamp, 43 uint32_t timestamp,
35 int64_t render_time_ms, 44 int64_t render_time_ms,
36 VideoRotation rotation) 45 VideoRotation rotation)
37 : video_frame_buffer_(buffer), 46 : video_frame_buffer_(buffer),
38 timestamp_(timestamp), 47 timestamp_rtp_(timestamp),
39 ntp_time_ms_(0), 48 ntp_time_ms_(0),
40 render_time_ms_(render_time_ms), 49 timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec),
41 rotation_(rotation) { 50 rotation_(rotation) {
42 RTC_DCHECK(buffer); 51 RTC_DCHECK(buffer);
43 } 52 }
44 53
45 void VideoFrame::CreateEmptyFrame(int width, 54 void VideoFrame::CreateEmptyFrame(int width,
46 int height, 55 int height,
47 int stride_y, 56 int stride_y,
48 int stride_u, 57 int stride_u,
49 int stride_v) { 58 int stride_v) {
50 const int half_width = (width + 1) / 2; 59 const int half_width = (width + 1) / 2;
51 RTC_DCHECK_GT(width, 0); 60 RTC_DCHECK_GT(width, 0);
52 RTC_DCHECK_GT(height, 0); 61 RTC_DCHECK_GT(height, 0);
53 RTC_DCHECK_GE(stride_y, width); 62 RTC_DCHECK_GE(stride_y, width);
54 RTC_DCHECK_GE(stride_u, half_width); 63 RTC_DCHECK_GE(stride_u, half_width);
55 RTC_DCHECK_GE(stride_v, half_width); 64 RTC_DCHECK_GE(stride_v, half_width);
56 65
57 // Creating empty frame - reset all values. 66 // Creating empty frame - reset all values.
58 timestamp_ = 0; 67 timestamp_rtp_ = 0;
59 ntp_time_ms_ = 0; 68 ntp_time_ms_ = 0;
60 render_time_ms_ = 0; 69 timestamp_us_ = 0;
61 rotation_ = kVideoRotation_0; 70 rotation_ = kVideoRotation_0;
62 71
63 // Allocate a new buffer. 72 // Allocate a new buffer.
64 video_frame_buffer_ = I420Buffer::Create( 73 video_frame_buffer_ = I420Buffer::Create(
65 width, height, stride_y, stride_u, stride_v); 74 width, height, stride_y, stride_u, stride_v);
66 } 75 }
67 76
68 void VideoFrame::CreateFrame(const uint8_t* buffer_y, 77 void VideoFrame::CreateFrame(const uint8_t* buffer_y,
69 const uint8_t* buffer_u, 78 const uint8_t* buffer_u,
70 const uint8_t* buffer_v, 79 const uint8_t* buffer_v,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 ShallowCopy(videoFrame); 112 ShallowCopy(videoFrame);
104 113
105 // If backed by a plain memory buffer, create a new, non-shared, copy. 114 // If backed by a plain memory buffer, create a new, non-shared, copy.
106 if (video_frame_buffer_ && !video_frame_buffer_->native_handle()) { 115 if (video_frame_buffer_ && !video_frame_buffer_->native_handle()) {
107 video_frame_buffer_ = I420Buffer::Copy(video_frame_buffer_); 116 video_frame_buffer_ = I420Buffer::Copy(video_frame_buffer_);
108 } 117 }
109 } 118 }
110 119
111 void VideoFrame::ShallowCopy(const VideoFrame& videoFrame) { 120 void VideoFrame::ShallowCopy(const VideoFrame& videoFrame) {
112 video_frame_buffer_ = videoFrame.video_frame_buffer(); 121 video_frame_buffer_ = videoFrame.video_frame_buffer();
113 timestamp_ = videoFrame.timestamp_; 122 timestamp_rtp_ = videoFrame.timestamp_rtp_;
114 ntp_time_ms_ = videoFrame.ntp_time_ms_; 123 ntp_time_ms_ = videoFrame.ntp_time_ms_;
115 render_time_ms_ = videoFrame.render_time_ms_; 124 timestamp_us_ = videoFrame.timestamp_us_;
116 rotation_ = videoFrame.rotation_; 125 rotation_ = videoFrame.rotation_;
117 } 126 }
118 127
119 // TODO(nisse): Delete. Besides test code, only one use, in 128 // TODO(nisse): Delete. Besides test code, only one use, in
120 // webrtcvideoengine2.cc:CreateBlackFrame. 129 // webrtcvideoengine2.cc:CreateBlackFrame.
121 int VideoFrame::allocated_size(PlaneType type) const { 130 int VideoFrame::allocated_size(PlaneType type) const {
122 const int plane_height = (type == kYPlane) ? height() : (height() + 1) / 2; 131 const int plane_height = (type == kYPlane) ? height() : (height() + 1) / 2;
123 int stride; 132 int stride;
124 switch (type) { 133 switch (type) {
125 case kYPlane: 134 case kYPlane:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 case kVideoCodecULPFEC: 176 case kVideoCodecULPFEC:
168 case kVideoCodecGeneric: 177 case kVideoCodecGeneric:
169 case kVideoCodecUnknown: 178 case kVideoCodecUnknown:
170 return 0; 179 return 0;
171 } 180 }
172 RTC_NOTREACHED(); 181 RTC_NOTREACHED();
173 return 0; 182 return 0;
174 } 183 }
175 184
176 } // namespace webrtc 185 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvideoengine2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698