Chromium Code Reviews| OLD | NEW | 
|---|---|
| (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 #ifndef WEBRTC_MEDIA_BASE_ADAPTEDVIDEOTRACKSOURCE_H_ | |
| 12 #define WEBRTC_MEDIA_BASE_ADAPTEDVIDEOTRACKSOURCE_H_ | |
| 13 | |
| 14 #include "webrtc/api/mediastreaminterface.h" | |
| 15 #include "webrtc/api/notifier.h" | |
| 16 #include "webrtc/media/base/videoadapter.h" | |
| 17 #include "webrtc/media/base/videobroadcaster.h" | |
| 18 | |
| 19 namespace rtc { | |
| 20 | |
| 21 // Base class for sources which needs video adaptation, e.g., video | |
| 22 // capture sources. Sinks must be added and removed on one and only | |
| 23 // one thread, while AdaptFrame and OnFrame may be called on any | |
| 24 // thread. | |
| 25 class AdaptedVideoTrackSource | |
| 26 : public webrtc::Notifier<webrtc::VideoTrackSourceInterface> { | |
| 27 public: | |
| 28 AdaptedVideoTrackSource(); | |
| 29 | |
| 30 // Returns false if no stats are available, e.g, for a remote | |
| 31 // source, or a source which has not seen its first frame yet. | |
| 32 // Should avoid blocking. | |
| 33 bool GetStats(Stats* stats) override; | |
| 
 
perkj_webrtc
2016/09/21 08:59:23
Also private?
 
 | |
| 34 | |
| 35 protected: | |
| 36 // Checks the apply_rotation_ flag. If the frame needs rotation, it | |
| 37 // will be rotated if it is a plain memory frame, and discarded it | |
| 38 // if it is a native frame. (Subclasses producing native frames must | |
| 39 // handle apply_rotation_ themselves). | |
| 40 void OnFrame(const cricket::VideoFrame& frame); | |
| 41 | |
| 42 // Reports the appropriate frame size after adaptation. Returns true | |
| 43 // if a frame is wanted. Returns false if there are no interested | |
| 44 // sinks, or if the VideoAdapter decides to drop the frame. | |
| 45 bool AdaptFrame(int width, | |
| 46 int height, | |
| 47 int64_t time_us, | |
| 48 int* out_width, | |
| 49 int* out_height, | |
| 50 int* crop_width, | |
| 51 int* crop_height, | |
| 52 int* crop_x, | |
| 53 int* crop_y); | |
| 54 | |
| 55 // Returns the current value of the apply_rotation flag, derived | |
| 56 // from the VideoSinkWants of registered sinks. Beware that when | |
| 57 // using this method, the value may become stale before it is used. | |
| 58 bool apply_rotation(); | |
| 59 | |
| 60 cricket::VideoAdapter* video_adapter() { return &video_adapter_; } | |
| 61 | |
| 62 private: | |
| 63 // Implements rtc::VideoSourceInterface. | |
| 64 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, | |
| 65 const rtc::VideoSinkWants& wants) override; | |
| 66 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; | |
| 67 | |
| 68 void OnSinkWantsChanged(const rtc::VideoSinkWants& wants); | |
| 69 | |
| 70 rtc::ThreadChecker thread_checker_; | |
| 71 | |
| 72 cricket::VideoAdapter video_adapter_; | |
| 73 | |
| 74 rtc::CriticalSection apply_rotation_crit_; | |
| 75 bool apply_rotation_ GUARDED_BY(apply_rotation_crit_); | |
| 76 | |
| 77 rtc::CriticalSection stats_crit_; | |
| 78 rtc::Optional<Stats> stats_ GUARDED_BY(stats_crit_); | |
| 79 | |
| 80 VideoBroadcaster broadcaster_; | |
| 81 }; | |
| 82 | |
| 83 } // namespace rtc | |
| 84 | |
| 85 #endif // WEBRTC_MEDIA_BASE_ADAPTEDVIDEOTRACKSOURCE_H_ | |
| OLD | NEW |