OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/cast/sender/video_sender.h" | 5 #include "media/cast/sender/video_sender.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 // playout delay (when allowed). They were calculated using | 23 // playout delay (when allowed). They were calculated using |
24 // a combination of cast_benchmark runs and manual testing. | 24 // a combination of cast_benchmark runs and manual testing. |
25 // | 25 // |
26 // This is how many round trips we think we need on the network. | 26 // This is how many round trips we think we need on the network. |
27 const int kRoundTripsNeeded = 4; | 27 const int kRoundTripsNeeded = 4; |
28 // This is an estimate of all the the constant time needed independent of | 28 // This is an estimate of all the the constant time needed independent of |
29 // network quality (e.g., additional time that accounts for encode and decode | 29 // network quality (e.g., additional time that accounts for encode and decode |
30 // time). | 30 // time). |
31 const int kConstantTimeMs = 75; | 31 const int kConstantTimeMs = 75; |
32 | 32 |
| 33 // Extract capture begin/end timestamps from |video_frame|'s metadata and log |
| 34 // it. |
| 35 void LogVideoCaptureTimestamps(const CastEnvironment& cast_environment, |
| 36 const media::VideoFrame& video_frame, |
| 37 RtpTimestamp rtp_timestamp) { |
| 38 base::TimeTicks capture_begin_time; |
| 39 base::TimeTicks capture_end_time; |
| 40 double capture_begin_time_internal = 0; |
| 41 double capture_end_time_internal = 0; |
| 42 if (video_frame.metadata().GetDouble("captureBeginTimeTicks", |
| 43 &capture_begin_time_internal) && |
| 44 video_frame.metadata().GetDouble("captureEndTimeTicks", |
| 45 &capture_end_time_internal)) { |
| 46 // See comments in media/capture/content_video_capture_device_core.cc |
| 47 // for why casting between double and int64 is reasonable. |
| 48 capture_begin_time = base::TimeTicks::FromInternalValue( |
| 49 static_cast<int64>(capture_begin_time_internal)); |
| 50 capture_end_time = base::TimeTicks::FromInternalValue( |
| 51 static_cast<int64>(capture_end_time_internal)); |
| 52 } else { |
| 53 // The frame capture timestamps were not provided by the video capture |
| 54 // source. Simply log the events as happening right now. |
| 55 capture_begin_time = capture_end_time = |
| 56 cast_environment.Clock()->NowTicks(); |
| 57 } |
| 58 cast_environment.Logging()->InsertFrameEvent( |
| 59 capture_begin_time, FRAME_CAPTURE_BEGIN, VIDEO_EVENT, rtp_timestamp, |
| 60 kFrameIdUnknown); |
| 61 cast_environment.Logging()->InsertFrameEvent( |
| 62 capture_end_time, FRAME_CAPTURE_END, VIDEO_EVENT, rtp_timestamp, |
| 63 kFrameIdUnknown); |
| 64 } |
| 65 |
33 } // namespace | 66 } // namespace |
34 | 67 |
35 // Note, we use a fixed bitrate value when external video encoder is used. | 68 // Note, we use a fixed bitrate value when external video encoder is used. |
36 // Some hardware encoder shows bad behavior if we set the bitrate too | 69 // Some hardware encoder shows bad behavior if we set the bitrate too |
37 // frequently, e.g. quality drop, not abiding by target bitrate, etc. | 70 // frequently, e.g. quality drop, not abiding by target bitrate, etc. |
38 // See details: crbug.com/392086. | 71 // See details: crbug.com/392086. |
39 VideoSender::VideoSender( | 72 VideoSender::VideoSender( |
40 scoped_refptr<CastEnvironment> cast_environment, | 73 scoped_refptr<CastEnvironment> cast_environment, |
41 const VideoSenderConfig& video_config, | 74 const VideoSenderConfig& video_config, |
42 const StatusChangeCallback& status_change_cb, | 75 const StatusChangeCallback& status_change_cb, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 const base::TimeTicks& reference_time) { | 134 const base::TimeTicks& reference_time) { |
102 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 135 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
103 | 136 |
104 if (!video_encoder_) { | 137 if (!video_encoder_) { |
105 NOTREACHED(); | 138 NOTREACHED(); |
106 return; | 139 return; |
107 } | 140 } |
108 | 141 |
109 const RtpTimestamp rtp_timestamp = | 142 const RtpTimestamp rtp_timestamp = |
110 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency); | 143 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency); |
111 const base::TimeTicks insertion_time = cast_environment_->Clock()->NowTicks(); | 144 LogVideoCaptureTimestamps(*cast_environment_, *video_frame, rtp_timestamp); |
112 // TODO(miu): Plumb in capture timestamps. For now, make it look like capture | |
113 // took zero time by setting the BEGIN and END event to the same timestamp. | |
114 cast_environment_->Logging()->InsertFrameEvent( | |
115 insertion_time, FRAME_CAPTURE_BEGIN, VIDEO_EVENT, rtp_timestamp, | |
116 kFrameIdUnknown); | |
117 cast_environment_->Logging()->InsertFrameEvent( | |
118 insertion_time, FRAME_CAPTURE_END, VIDEO_EVENT, rtp_timestamp, | |
119 kFrameIdUnknown); | |
120 | 145 |
121 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 146 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
122 TRACE_EVENT_INSTANT2( | 147 TRACE_EVENT_INSTANT2( |
123 "cast_perf_test", "InsertRawVideoFrame", | 148 "cast_perf_test", "InsertRawVideoFrame", |
124 TRACE_EVENT_SCOPE_THREAD, | 149 TRACE_EVENT_SCOPE_THREAD, |
125 "timestamp", reference_time.ToInternalValue(), | 150 "timestamp", reference_time.ToInternalValue(), |
126 "rtp_timestamp", rtp_timestamp); | 151 "rtp_timestamp", rtp_timestamp); |
127 | 152 |
128 // Drop the frame if either its RTP or reference timestamp is not an increase | 153 // Drop the frame if either its RTP or reference timestamp is not an increase |
129 // over the last frame's. This protects: 1) the duration calculations that | 154 // over the last frame's. This protects: 1) the duration calculations that |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 DCHECK_GE(frames_in_encoder_, 0); | 250 DCHECK_GE(frames_in_encoder_, 0); |
226 | 251 |
227 duration_in_encoder_ = | 252 duration_in_encoder_ = |
228 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; | 253 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; |
229 | 254 |
230 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); | 255 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); |
231 } | 256 } |
232 | 257 |
233 } // namespace cast | 258 } // namespace cast |
234 } // namespace media | 259 } // namespace media |
OLD | NEW |