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

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

Issue 2328333002: New class AdaptedVideoTrackSource. (Closed)
Patch Set: Comment improvement. 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 | « webrtc/media/base/adaptedvideotracksource.h ('k') | webrtc/media/base/videobroadcaster.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::scoped_refptr<webrtc::VideoFrameBuffer> buffer(
32 frame.video_frame_buffer());
33 /* Note that this is a "best effort" approach to
34 wants.rotation_applied; apply_rotation_ can change from false to
35 true between the check of apply_rotation() and the call to
36 broadcaster_.OnFrame(), in which case we generate a frame with
37 pending rotation despite some sink with wants.rotation_applied ==
38 true was just added. The VideoBroadcaster enforces
39 synchronization for us in this case, by not passing the frame on
40 to sinks which don't want it. */
41 if (apply_rotation() &&
42 frame.rotation() != webrtc::kVideoRotation_0 &&
43 !buffer->native_handle()) {
44 /* Apply pending rotation. */
45 broadcaster_.OnFrame(cricket::WebRtcVideoFrame(
46 webrtc::I420Buffer::Rotate(buffer, frame.rotation()),
47 webrtc::kVideoRotation_0, frame.timestamp_us()));
48 } else {
49 broadcaster_.OnFrame(frame);
50 }
51 }
52
53 void AdaptedVideoTrackSource::AddOrUpdateSink(
54 rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
55 const rtc::VideoSinkWants& wants) {
56 RTC_DCHECK(thread_checker_.CalledOnValidThread());
57
58 broadcaster_.AddOrUpdateSink(sink, wants);
59 OnSinkWantsChanged(broadcaster_.wants());
60 }
61
62 void AdaptedVideoTrackSource::RemoveSink(
63 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) {
64 RTC_DCHECK(thread_checker_.CalledOnValidThread());
65
66 broadcaster_.RemoveSink(sink);
67 OnSinkWantsChanged(broadcaster_.wants());
68 }
69
70 bool AdaptedVideoTrackSource::apply_rotation() {
71 return broadcaster_.wants().rotation_applied;
72 }
73
74 void AdaptedVideoTrackSource::OnSinkWantsChanged(
75 const rtc::VideoSinkWants& wants) {
76 RTC_DCHECK(thread_checker_.CalledOnValidThread());
77 video_adapter_.OnResolutionRequest(wants.max_pixel_count,
78 wants.max_pixel_count_step_up);
79 }
80
81 bool AdaptedVideoTrackSource::AdaptFrame(int width,
82 int height,
83 int64_t time_us,
84 int* out_width,
85 int* out_height,
86 int* crop_width,
87 int* crop_height,
88 int* crop_x,
89 int* crop_y) {
90 {
91 rtc::CritScope lock(&stats_crit_);
92 stats_ = rtc::Optional<Stats>({width, height});
93 }
94
95 if (!broadcaster_.frame_wanted()) {
96 return false;
97 }
98
99 if (!video_adapter_.AdaptFrameResolution(
100 width, height, time_us * rtc::kNumNanosecsPerMicrosec,
101 crop_width, crop_height, out_width, out_height)) {
102 // VideoAdapter dropped the frame.
103 return false;
104 }
105
106 *crop_x = (width - *crop_width) / 2;
107 *crop_y = (height - *crop_height) / 2;
108 return true;
109 }
110
111 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/media/base/adaptedvideotracksource.h ('k') | webrtc/media/base/videobroadcaster.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698