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

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

Issue 2328333002: New class AdaptedVideoTrackSource. (Closed)
Patch Set: Drop access to to apply_rotation lock. 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 int width,
32 int height) {
33 {
34 rtc::CritScope lock(&stats_crit_);
magjed_webrtc 2016/09/19 09:43:26 Can we move the stats_ thing to AdaptFrame instead
nisse-webrtc 2016/09/20 08:23:42 Done.
35 stats_ = rtc::Optional<Stats>({width, height});
36 }
37 rtc::CritScope lock(&apply_rotation_crit_);
38 if (apply_rotation_ && frame.rotation() != webrtc::kVideoRotation_0) {
39 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer(
40 frame.video_frame_buffer());
41 if (buffer->native_handle()) {
42 // Sources producing native frames must handle apply_rotation
43 // themselves. But even if they do, we may occasionally end up
44 // in this case, for frames in flight at the time
45 // applied_rotation is set to true. In that case, we just drop
46 // the frame.
47 LOG(LS_WARNING) << "Native frame requiring rotation. Discarding.";
48 return;
49 }
50 broadcaster_.OnFrame(cricket::WebRtcVideoFrame(
51 webrtc::I420Buffer::Rotate(buffer, frame.rotation()),
52 webrtc::kVideoRotation_0, frame.timestamp_us()));
53 } else {
54 broadcaster_.OnFrame(frame);
55 }
56 }
57
58 void AdaptedVideoTrackSource::AddOrUpdateSink(
59 rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
60 const rtc::VideoSinkWants& wants) {
61 RTC_DCHECK(thread_checker_.CalledOnValidThread());
62
63 broadcaster_.AddOrUpdateSink(sink, wants);
64 OnSinkWantsChanged(broadcaster_.wants());
65 }
66
67 void AdaptedVideoTrackSource::RemoveSink(
68 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) {
69 RTC_DCHECK(thread_checker_.CalledOnValidThread());
70
71 broadcaster_.RemoveSink(sink);
72 OnSinkWantsChanged(broadcaster_.wants());
73 }
74
75 bool AdaptedVideoTrackSource::apply_rotation() {
76 rtc::CritScope lock(&apply_rotation_crit_);
77 return apply_rotation_;
78 }
79
80 void AdaptedVideoTrackSource::OnSinkWantsChanged(
81 const rtc::VideoSinkWants& wants) {
82 {
83 rtc::CritScope lock(&apply_rotation_crit_);
84 apply_rotation_ = wants.rotation_applied;
85 }
86
87 video_adapter_.OnResolutionRequest(wants.max_pixel_count,
88 wants.max_pixel_count_step_up);
89 }
90
91 bool AdaptedVideoTrackSource::AdaptFrame(int width,
92 int height,
93 int64_t time_us,
94 int* out_width,
95 int* out_height,
96 int* crop_width,
97 int* crop_height,
98 int* crop_x,
99 int* crop_y) {
100 if (!broadcaster_.frame_wanted()) {
101 return false;
102 }
103
104 if (!video_adapter_.AdaptFrameResolution(
105 width, height, time_us * rtc::kNumNanosecsPerMicrosec,
106 crop_width, crop_height, out_width, out_height)) {
107 // VideoAdapter dropped the frame.
108 return false;
109 }
110
111 *crop_x = (width - *crop_width) / 2;
112 *crop_y = (height - *crop_height) / 2;
113 return true;
114 }
115
116 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698