#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/base/video_util.h"
#include <cmath>
#include "base/bits.h"
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/numerics/safe_math.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/raster_interface.h"
#include "gpu/command_buffer/common/capabilities.h"
#include "media/base/limits.h"
#include "media/base/video_frame.h"
#include "media/base/video_frame_pool.h"
#include "media/base/video_types.h"
#include "media/base/wait_and_replace_sync_token_client.h"
#include "third_party/libyuv/include/libyuv.h"
#include "third_party/skia/include/core/SkAlphaType.h"
#include "third_party/skia/include/core/SkColorType.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkPixmap.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkYUVAPixmaps.h"
#include "third_party/skia/include/gpu/GpuTypes.h"
#include "ui/gfx/gpu_memory_buffer.h"
namespace media {
namespace {
void FillRegionOutsideVisibleRect(uint8_t* data,
size_t stride,
const gfx::Size& coded_size,
const gfx::Size& visible_size) { … }
VideoPixelFormat ReadbackFormat(const VideoFrame& frame) { … }
bool ReadbackTexturePlaneToMemorySyncOOP(const VideoFrame& src_frame,
size_t src_plane,
gfx::Rect& src_rect,
uint8_t* dest_pixels,
size_t dest_stride,
gpu::raster::RasterInterface* ri) { … }
void LetterboxPlane(const gfx::Rect& view_area_in_bytes,
uint8_t* ptr,
int rows,
int row_bytes,
int stride,
int bytes_per_element,
uint8_t fill_byte) { … }
void LetterboxPlane(VideoFrame* frame,
int plane,
uint8_t* ptr,
const gfx::Rect& view_area_in_pixels,
uint8_t fill_byte) { … }
void LetterboxPlane(VideoFrame* frame,
VideoFrame::ScopedMapping* scoped_mapping,
int plane,
const gfx::Rect& view_area_in_pixels,
uint8_t fill_byte) { … }
}
void FillYUV(VideoFrame* frame, uint8_t y, uint8_t u, uint8_t v) { … }
void FillYUVA(VideoFrame* frame, uint8_t y, uint8_t u, uint8_t v, uint8_t a) { … }
void LetterboxVideoFrame(VideoFrame* frame, const gfx::Rect& view_area) { … }
void RotatePlaneByPixels(const uint8_t* src,
uint8_t* dest,
int width,
int height,
int rotation,
bool flip_vert,
bool flip_horiz) { … }
static int RoundedDivision(int64_t a, int b) { … }
static gfx::Size ScaleSizeToTarget(const gfx::Size& size,
const gfx::Size& target,
bool fit_within_target) { … }
gfx::Rect ComputeLetterboxRegion(const gfx::Rect& bounds,
const gfx::Size& content) { … }
gfx::Rect ComputeLetterboxRegionForI420(const gfx::Rect& bounds,
const gfx::Size& content) { … }
gfx::Rect MinimallyShrinkRectForI420(const gfx::Rect& rect) { … }
gfx::Size ScaleSizeToFitWithinTarget(const gfx::Size& size,
const gfx::Size& target) { … }
gfx::Size ScaleSizeToEncompassTarget(const gfx::Size& size,
const gfx::Size& target) { … }
gfx::Rect CropSizeForScalingToTarget(const gfx::Size& size,
const gfx::Size& target,
size_t alignment) { … }
gfx::Size GetRectSizeFromOrigin(const gfx::Rect& rect) { … }
gfx::Size PadToMatchAspectRatio(const gfx::Size& size,
const gfx::Size& target) { … }
scoped_refptr<VideoFrame> ConvertToMemoryMappedFrame(
scoped_refptr<VideoFrame> video_frame) { … }
scoped_refptr<VideoFrame> WrapAsI420VideoFrame(
scoped_refptr<VideoFrame> frame) { … }
bool I420CopyWithPadding(const VideoFrame& src_frame, VideoFrame* dst_frame) { … }
scoped_refptr<VideoFrame> ReadbackTextureBackedFrameToMemorySync(
VideoFrame& txt_frame,
gpu::raster::RasterInterface* ri,
const gpu::Capabilities& caps,
VideoFramePool* pool) { … }
bool ReadbackTexturePlaneToMemorySync(VideoFrame& src_frame,
size_t src_plane,
gfx::Rect& src_rect,
uint8_t* dest_pixels,
size_t dest_stride,
gpu::raster::RasterInterface* ri,
const gpu::Capabilities& caps) { … }
MEDIA_EXPORT SkColorType SkColorTypeForPlane(VideoPixelFormat format,
size_t plane) { … }
MEDIA_EXPORT VideoPixelFormat
VideoPixelFormatFromSkColorType(SkColorType sk_color_type, bool is_opaque) { … }
scoped_refptr<VideoFrame> CreateFromSkImage(sk_sp<SkImage> sk_image,
const gfx::Rect& visible_rect,
const gfx::Size& natural_size,
base::TimeDelta timestamp,
bool force_opaque) { … }
std::tuple<SkYUVAInfo::PlaneConfig, SkYUVAInfo::Subsampling>
VideoPixelFormatToSkiaValues(VideoPixelFormat video_format) { … }
}