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

Side by Side Diff: webrtc/media/base/adaptedvideotracksource.cc

Issue 2328333002: New class AdaptedVideoTrackSource. (Closed)
Patch Set: Move stats update from OnFrame to AdaptFrame. 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 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 #include "webrtc/media/base/adaptedvideotracksource.h"
12
13 namespace rtc {
14
15 AdaptedVideoTrackSource::AdaptedVideoTrackSource() {
16 thread_checker_.DetachFromThread();
17 }
18
19 bool AdaptedVideoTrackSource::GetStats(Stats* stats) {
20 rtc::CritScope lock(&stats_crit_);
21
22 if (!stats_) {
23 return false;
24 }
25
26 *stats = *stats_;
27 return true;
28 }
29
30 void AdaptedVideoTrackSource::OnFrame(const cricket::VideoFrame& frame) {
31 rtc::CritScope lock(&apply_rotation_crit_);
perkj_webrtc 2016/09/20 12:26:09 I would avoid holding a lock when you call the bro
nisse-webrtc 2016/09/20 13:17:47 The lock is needed to ensure that a sink that sets
32 if (apply_rotation_ && frame.rotation() != webrtc::kVideoRotation_0) {
33 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer(
34 frame.video_frame_buffer());
35 if (buffer->native_handle()) {
36 // Sources producing native frames must handle apply_rotation
37 // themselves. But even if they do, we may occasionally end up
38 // in this case, for frames in flight at the time
39 // applied_rotation is set to true. In that case, we just drop
40 // the frame.
41 LOG(LS_WARNING) << "Native frame requiring rotation. Discarding.";
42 return;
43 }
44 broadcaster_.OnFrame(cricket::WebRtcVideoFrame(
45 webrtc::I420Buffer::Rotate(buffer, frame.rotation()),
46 webrtc::kVideoRotation_0, frame.timestamp_us()));
47 } else {
48 broadcaster_.OnFrame(frame);
49 }
50 }
51
52 void AdaptedVideoTrackSource::AddOrUpdateSink(
53 rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
54 const rtc::VideoSinkWants& wants) {
55 RTC_DCHECK(thread_checker_.CalledOnValidThread());
56
57 broadcaster_.AddOrUpdateSink(sink, wants);
58 OnSinkWantsChanged(broadcaster_.wants());
59 }
60
61 void AdaptedVideoTrackSource::RemoveSink(
62 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) {
63 RTC_DCHECK(thread_checker_.CalledOnValidThread());
64
65 broadcaster_.RemoveSink(sink);
66 OnSinkWantsChanged(broadcaster_.wants());
67 }
68
69 bool AdaptedVideoTrackSource::apply_rotation() {
70 rtc::CritScope lock(&apply_rotation_crit_);
71 return apply_rotation_;
72 }
73
74 void AdaptedVideoTrackSource::OnSinkWantsChanged(
75 const rtc::VideoSinkWants& wants) {
perkj_webrtc 2016/09/20 12:26:09 add thread checker. Should be called on same threa
nisse-webrtc 2016/09/20 13:17:47 Done. Even if it seems a bit overkill to me: metho
76 {
77 rtc::CritScope lock(&apply_rotation_crit_);
78 apply_rotation_ = wants.rotation_applied;
79 }
80
81 video_adapter_.OnResolutionRequest(wants.max_pixel_count,
82 wants.max_pixel_count_step_up);
83 }
84
85 bool AdaptedVideoTrackSource::AdaptFrame(int width,
86 int height,
87 int64_t time_us,
88 int* out_width,
89 int* out_height,
90 int* crop_width,
91 int* crop_height,
92 int* crop_x,
93 int* crop_y) {
94 {
95 rtc::CritScope lock(&stats_crit_);
96 stats_ = rtc::Optional<Stats>({width, height});
97 }
98
99 if (!broadcaster_.frame_wanted()) {
100 return false;
101 }
102
103 if (!video_adapter_.AdaptFrameResolution(
104 width, height, time_us * rtc::kNumNanosecsPerMicrosec,
105 crop_width, crop_height, out_width, out_height)) {
106 // VideoAdapter dropped the frame.
107 return false;
108 }
109
110 *crop_x = (width - *crop_width) / 2;
111 *crop_y = (height - *crop_height) / 2;
112 return true;
113 }
114
115 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698