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

Side by Side Diff: media/cast/sender/video_sender.cc

Issue 955253002: Add metadata to media::VideoFrame and plumb it through IPC/MediaStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tommi's nits addressed Created 5 years, 9 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 | « media/base/video_frame_unittest.cc ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (!video_frame.metadata()->GetTimeTicks(
41 media::VideoFrameMetadata::CAPTURE_BEGIN_TIME, &capture_begin_time) ||
42 !video_frame.metadata()->GetTimeTicks(
43 media::VideoFrameMetadata::CAPTURE_END_TIME, &capture_end_time)) {
44 // The frame capture timestamps were not provided by the video capture
45 // source. Simply log the events as happening right now.
46 capture_begin_time = capture_end_time =
47 cast_environment.Clock()->NowTicks();
48 }
49 cast_environment.Logging()->InsertFrameEvent(
50 capture_begin_time, FRAME_CAPTURE_BEGIN, VIDEO_EVENT, rtp_timestamp,
51 kFrameIdUnknown);
52 cast_environment.Logging()->InsertFrameEvent(
53 capture_end_time, FRAME_CAPTURE_END, VIDEO_EVENT, rtp_timestamp,
54 kFrameIdUnknown);
55 }
56
33 } // namespace 57 } // namespace
34 58
35 // Note, we use a fixed bitrate value when external video encoder is used. 59 // 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 60 // Some hardware encoder shows bad behavior if we set the bitrate too
37 // frequently, e.g. quality drop, not abiding by target bitrate, etc. 61 // frequently, e.g. quality drop, not abiding by target bitrate, etc.
38 // See details: crbug.com/392086. 62 // See details: crbug.com/392086.
39 VideoSender::VideoSender( 63 VideoSender::VideoSender(
40 scoped_refptr<CastEnvironment> cast_environment, 64 scoped_refptr<CastEnvironment> cast_environment,
41 const VideoSenderConfig& video_config, 65 const VideoSenderConfig& video_config,
42 const StatusChangeCallback& status_change_cb, 66 const StatusChangeCallback& status_change_cb,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 const base::TimeTicks& reference_time) { 125 const base::TimeTicks& reference_time) {
102 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 126 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
103 127
104 if (!video_encoder_) { 128 if (!video_encoder_) {
105 NOTREACHED(); 129 NOTREACHED();
106 return; 130 return;
107 } 131 }
108 132
109 const RtpTimestamp rtp_timestamp = 133 const RtpTimestamp rtp_timestamp =
110 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency); 134 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency);
111 const base::TimeTicks insertion_time = cast_environment_->Clock()->NowTicks(); 135 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 136
121 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc 137 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc
122 TRACE_EVENT_INSTANT2( 138 TRACE_EVENT_INSTANT2(
123 "cast_perf_test", "InsertRawVideoFrame", 139 "cast_perf_test", "InsertRawVideoFrame",
124 TRACE_EVENT_SCOPE_THREAD, 140 TRACE_EVENT_SCOPE_THREAD,
125 "timestamp", reference_time.ToInternalValue(), 141 "timestamp", reference_time.ToInternalValue(),
126 "rtp_timestamp", rtp_timestamp); 142 "rtp_timestamp", rtp_timestamp);
127 143
128 // Drop the frame if either its RTP or reference timestamp is not an increase 144 // 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 145 // over the last frame's. This protects: 1) the duration calculations that
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 DCHECK_GE(frames_in_encoder_, 0); 241 DCHECK_GE(frames_in_encoder_, 0);
226 242
227 duration_in_encoder_ = 243 duration_in_encoder_ =
228 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; 244 last_enqueued_frame_reference_time_ - encoded_frame->reference_time;
229 245
230 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); 246 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass());
231 } 247 }
232 248
233 } // namespace cast 249 } // namespace cast
234 } // namespace media 250 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame_unittest.cc ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698