Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MEDIA_BASE_VIDEOFRAMEFACTORY_H_ | 11 #ifndef WEBRTC_MEDIA_BASE_VIDEOFRAMEFACTORY_H_ |
| 12 #define WEBRTC_MEDIA_BASE_VIDEOFRAMEFACTORY_H_ | 12 #define WEBRTC_MEDIA_BASE_VIDEOFRAMEFACTORY_H_ |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 #include "webrtc/media/base/videoframe.h" | 16 #include "webrtc/media/base/videoframe.h" |
| 17 | 17 |
| 18 namespace cricket { | 18 namespace cricket { |
| 19 | 19 |
| 20 struct CapturedFrame; | 20 struct CapturedFrame; |
| 21 class VideoFrame; | 21 class VideoFrame; |
| 22 | 22 |
| 23 // Creates cricket::VideoFrames, or a subclass of cricket::VideoFrame | 23 // Creates cricket::VideoFrames, or a subclass of cricket::VideoFrame |
| 24 // depending on the subclass of VideoFrameFactory. | 24 // depending on the subclass of VideoFrameFactory. |
| 25 class VideoFrameFactory { | 25 class VideoFrameFactory { |
| 26 public: | 26 public: |
| 27 VideoFrameFactory() : apply_rotation_(false) {} | 27 VideoFrameFactory() : apply_rotation_(false) {} |
| 28 virtual ~VideoFrameFactory() {} | 28 virtual ~VideoFrameFactory() {} |
| 29 | 29 |
| 30 // Convert a CapturedFrame to a VideoFrame. |width| and |height| | |
| 31 // give the desired size, and the factory is expected to first crop | |
| 32 // the frame to get a matching aspect ratio, and then scale it to | |
| 33 // the right size. The size refers the the image before application | |
| 34 // of |input_frame->rotation|. Subclasses usually only need to | |
| 35 // override CreateScaledCroppedFrame, see below. | |
| 36 virtual std::unique_ptr<VideoFrame> CreateScaledFrame( | |
| 37 const CapturedFrame* input_frame, | |
| 38 int width, | |
| 39 int height) const; | |
| 40 | |
| 41 // The CreateAliasedFrame methods are deprecated, since cropping is | |
| 42 // no longer supported, and we don't want raw pointer return types. | |
| 43 // TODO(nisse): Delete when all users are updated. | |
| 44 | |
| 30 // The returned frame aliases the aliased_frame if the input color | 45 // The returned frame aliases the aliased_frame if the input color |
| 31 // space allows for aliasing, otherwise a color conversion will | 46 // space allows for aliasing, otherwise a color conversion will |
| 32 // occur. Returns NULL if conversion fails. | 47 // occur. Returns NULL if conversion fails. |
| 33 | 48 |
| 34 // The returned frame will be a center crop of |input_frame| with | 49 // The returned frame will be a center crop of |input_frame| with |
| 35 // size |cropped_width| x |cropped_height|. | 50 // size |cropped_width| x |cropped_height|. |
| 36 virtual VideoFrame* CreateAliasedFrame(const CapturedFrame* input_frame, | 51 virtual VideoFrame* CreateAliasedFrame(const CapturedFrame* input_frame, |
| 37 int cropped_width, | 52 int cropped_width, |
| 38 int cropped_height) const = 0; | 53 int cropped_height) const { |
| 39 | 54 // Dummy default implementation, to make it easier to delete in |
| 55 // subclasses. | |
| 56 return NULL; | |
|
perkj_webrtc
2016/05/11 10:05:17
return nullptr;
| |
| 57 } | |
| 40 // The returned frame will be a center crop of |input_frame| with size | 58 // The returned frame will be a center crop of |input_frame| with size |
| 41 // |cropped_width| x |cropped_height|, scaled to |output_width| x | 59 // |cropped_width| x |cropped_height|, scaled to |output_width| x |
| 42 // |output_height|. | 60 // |output_height|. |
| 43 virtual VideoFrame* CreateAliasedFrame(const CapturedFrame* input_frame, | 61 virtual VideoFrame* CreateAliasedFrame(const CapturedFrame* input_frame, |
| 44 int cropped_input_width, | 62 int cropped_input_width, |
| 45 int cropped_input_height, | 63 int cropped_input_height, |
| 46 int output_width, | 64 int output_width, |
| 47 int output_height) const; | 65 int output_height) const; |
| 48 | 66 |
| 49 void SetApplyRotation(bool enable) { apply_rotation_ = enable; } | 67 void SetApplyRotation(bool enable) { apply_rotation_ = enable; } |
| 50 | 68 |
| 51 protected: | 69 protected: |
| 70 // Similar to CreateScaledFrame, but gets cropping parameters as | |
| 71 // inputs, and relies on the caller to choose them so that aspect | |
| 72 // ration is preserved. | |
| 73 virtual std::unique_ptr<VideoFrame> CreateScaledCroppedFrame( | |
| 74 const CapturedFrame* input_frame, | |
| 75 int crop_x, | |
| 76 int crop_y, | |
| 77 int crop_width, | |
|
perkj_webrtc
2016/05/11 10:05:17
please document what the arguments mean.
nisse-webrtc
2016/05/12 12:23:06
I'm adding a comment. I'm also renaming the method
| |
| 78 int crop_height, | |
| 79 int dst_width, | |
| 80 int dst_height) const; | |
| 81 | |
| 52 bool apply_rotation_; | 82 bool apply_rotation_; |
| 53 | 83 |
| 54 private: | 84 private: |
| 55 // An internal frame buffer to avoid reallocations. It is mutable because it | 85 // An internal frame buffer to avoid reallocations. It is mutable because it |
| 56 // does not affect behaviour, only performance. | 86 // does not affect behaviour, only performance. |
| 57 mutable std::unique_ptr<VideoFrame> output_frame_; | 87 mutable std::unique_ptr<VideoFrame> output_frame_; |
| 58 }; | 88 }; |
| 59 | 89 |
| 60 } // namespace cricket | 90 } // namespace cricket |
| 61 | 91 |
| 62 #endif // WEBRTC_MEDIA_BASE_VIDEOFRAMEFACTORY_H_ | 92 #endif // WEBRTC_MEDIA_BASE_VIDEOFRAMEFACTORY_H_ |
| OLD | NEW |