OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 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_COMMON_VIDEO_INCLUDE_COREVIDEO_FRAME_BUFFER_H_ |
| 12 #define WEBRTC_COMMON_VIDEO_INCLUDE_COREVIDEO_FRAME_BUFFER_H_ |
| 13 |
| 14 #include <CoreVideo/CoreVideo.h> |
| 15 |
| 16 #include <vector> |
| 17 |
| 18 #include "webrtc/common_video/include/video_frame_buffer.h" |
| 19 |
| 20 namespace webrtc { |
| 21 |
| 22 class CoreVideoFrameBuffer : public NativeHandleBuffer { |
| 23 public: |
| 24 explicit CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer); |
| 25 CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer, |
| 26 int adapted_width, |
| 27 int adapted_height, |
| 28 int crop_width, |
| 29 int crop_height, |
| 30 int crop_x, |
| 31 int crop_y); |
| 32 ~CoreVideoFrameBuffer() override; |
| 33 |
| 34 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
| 35 // Returns true if the internal pixel buffer needs to be cropped. |
| 36 bool RequiresCropping() const; |
| 37 // Crop and scales the internal pixel buffer to the output pixel buffer. The |
| 38 // tmp buffer is used for intermediary splitting the UV channels. This |
| 39 // function returns true if successful. |
| 40 bool CropAndScaleTo(std::vector<uint8_t>* tmp_buffer, |
| 41 CVPixelBufferRef output_pixel_buffer) const; |
| 42 |
| 43 private: |
| 44 CVPixelBufferRef pixel_buffer_; |
| 45 // buffer_width/height is the actual pixel buffer resolution. The width/height |
| 46 // in NativeHandleBuffer, i.e. width()/height(), is the resolution we will |
| 47 // scale to in NativeToI420Buffer(). Cropping happens before scaling, so: |
| 48 // buffer_width >= crop_width >= width(). |
| 49 const int buffer_width_; |
| 50 const int buffer_height_; |
| 51 const int crop_width_; |
| 52 const int crop_height_; |
| 53 const int crop_x_; |
| 54 const int crop_y_; |
| 55 }; |
| 56 |
| 57 } // namespace webrtc |
| 58 |
| 59 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_COREVIDEO_FRAME_BUFFER_H_ |
OLD | NEW |