#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/capture/video/fake_video_capture_device.h"
#include <stddef.h>
#include <algorithm>
#include <utility>
#include "base/containers/heap_array.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/stringprintf.h"
#include "base/task/bind_post_task.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
#include "gpu/ipc/common/gpu_memory_buffer_support.h"
#include "media/audio/fake_audio_input_stream.h"
#include "media/base/video_frame.h"
#include "media/capture/mojom/image_capture_types.h"
#include "media/capture/video/gpu_memory_buffer_utils.h"
#include "skia/ext/font_utils.h"
#include "skia/ext/legacy_display_globals.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/codec/png_codec.h"
namespace media {
namespace {
static const float kPacmanAngularVelocity = …;
static const int kBeepInterval = …;
static const float kGradientFrequency = …;
static const double kMinPan = …;
static const double kMaxPan = …;
static const double kPanStep = …;
static const double kMinTilt = …;
static const double kMaxTilt = …;
static const double kTiltStep = …;
static const double kMinZoom = …;
static const double kMaxZoom = …;
static const double kZoomStep = …;
static const double kMinExposureTime = …;
static const double kMaxExposureTime = …;
static const double kExposureTimeStep = …;
static const double kMinFocusDistance = …;
static const double kMaxFocusDistance = …;
static const double kFocusDistanceStep = …;
enum class PixelFormatMatchType : int { … };
PixelFormatMatchType DetermineFormatMatchType(
VideoPixelFormat supported_format,
VideoPixelFormat requested_format) { … }
VideoCaptureFormat FindClosestSupportedFormat(
const VideoCaptureFormat& requested_format,
const VideoCaptureFormats& supported_formats,
bool video_capture_use_gmb) { … }
gfx::ColorSpace GetDefaultColorSpace(VideoPixelFormat format) { … }
}
FakeDeviceState::FakeDeviceState(double pan,
double tilt,
double zoom,
double exposure_time,
double focus_distance,
float frame_rate,
VideoPixelFormat pixel_format)
: … { … }
class FrameDeliverer { … };
class OwnBufferFrameDeliverer : public FrameDeliverer { … };
class ClientBufferFrameDeliverer : public FrameDeliverer { … };
class JpegEncodingFrameDeliverer : public FrameDeliverer { … };
class GpuMemoryBufferFrameDeliverer : public FrameDeliverer { … };
FrameDelivererFactory::FrameDelivererFactory(
FakeVideoCaptureDevice::DeliveryMode delivery_mode,
const FakeDeviceState* device_state,
std::unique_ptr<gpu::GpuMemoryBufferSupport> gmb_support)
: … { … }
FrameDelivererFactory::~FrameDelivererFactory() = default;
std::unique_ptr<FrameDeliverer> FrameDelivererFactory::CreateFrameDeliverer(
const VideoCaptureFormat& format,
bool video_capture_use_gmb) { … }
PacmanFramePainter::PacmanFramePainter(Format pixel_format,
const FakeDeviceState* fake_device_state)
: … { … }
void PacmanFramePainter::PaintFrame(base::TimeDelta elapsed_time,
uint8_t* target_buffer,
int bytes_per_row) { … }
void PacmanFramePainter::DrawGradientSquares(base::TimeDelta elapsed_time,
uint8_t* target_buffer,
int bytes_per_row) { … }
void PacmanFramePainter::DrawPacman(base::TimeDelta elapsed_time,
uint8_t* target_buffer,
int bytes_per_row) { … }
FakePhotoDevice::FakePhotoDevice(
std::unique_ptr<PacmanFramePainter> sk_n32_painter,
const FakeDeviceState* fake_device_state,
const FakePhotoDeviceConfig& config)
: … { … }
FakePhotoDevice::~FakePhotoDevice() = default;
void FakePhotoDevice::TakePhoto(VideoCaptureDevice::TakePhotoCallback callback,
base::TimeDelta elapsed_time) { … }
FakeVideoCaptureDevice::FakeVideoCaptureDevice(
const VideoCaptureFormats& supported_formats,
std::unique_ptr<FrameDelivererFactory> frame_deliverer_factory,
std::unique_ptr<FakePhotoDevice> photo_device,
std::unique_ptr<FakeDeviceState> device_state)
: … { … }
FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { … }
void FakeVideoCaptureDevice::AllocateAndStart(
const VideoCaptureParams& params,
std::unique_ptr<VideoCaptureDevice::Client> client) { … }
void FakeVideoCaptureDevice::StopAndDeAllocate() { … }
void FakeVideoCaptureDevice::GetPhotoState(GetPhotoStateCallback callback) { … }
void FakePhotoDevice::GetPhotoState(
VideoCaptureDevice::GetPhotoStateCallback callback) { … }
void FakeVideoCaptureDevice::SetPhotoOptions(mojom::PhotoSettingsPtr settings,
SetPhotoOptionsCallback callback) { … }
void FakePhotoDevice::SetPhotoOptions(
mojom::PhotoSettingsPtr settings,
VideoCaptureDevice::SetPhotoOptionsCallback callback,
FakeDeviceState* device_state_write_access) { … }
void FakeVideoCaptureDevice::TakePhoto(TakePhotoCallback callback) { … }
OwnBufferFrameDeliverer::OwnBufferFrameDeliverer(
std::unique_ptr<PacmanFramePainter> frame_painter)
: … { … }
OwnBufferFrameDeliverer::~OwnBufferFrameDeliverer() = default;
void OwnBufferFrameDeliverer::Initialize(
VideoPixelFormat pixel_format,
std::unique_ptr<VideoCaptureDevice::Client> client,
const FakeDeviceState* device_state) { … }
void OwnBufferFrameDeliverer::PaintAndDeliverNextFrame(
base::TimeDelta timestamp_to_paint) { … }
ClientBufferFrameDeliverer::ClientBufferFrameDeliverer(
std::unique_ptr<PacmanFramePainter> frame_painter)
: … { … }
ClientBufferFrameDeliverer::~ClientBufferFrameDeliverer() = default;
void ClientBufferFrameDeliverer::PaintAndDeliverNextFrame(
base::TimeDelta timestamp_to_paint) { … }
JpegEncodingFrameDeliverer::JpegEncodingFrameDeliverer(
std::unique_ptr<PacmanFramePainter> frame_painter)
: … { … }
JpegEncodingFrameDeliverer::~JpegEncodingFrameDeliverer() = default;
void JpegEncodingFrameDeliverer::PaintAndDeliverNextFrame(
base::TimeDelta timestamp_to_paint) { … }
GpuMemoryBufferFrameDeliverer::GpuMemoryBufferFrameDeliverer(
std::unique_ptr<PacmanFramePainter> frame_painter,
gpu::GpuMemoryBufferSupport* gmb_support)
: … { … }
GpuMemoryBufferFrameDeliverer::~GpuMemoryBufferFrameDeliverer() = default;
void GpuMemoryBufferFrameDeliverer::PaintAndDeliverNextFrame(
base::TimeDelta timestamp_to_paint) { … }
void FakeVideoCaptureDevice::BeepAndScheduleNextCapture(
base::TimeTicks expected_execution_time) { … }
void FakeVideoCaptureDevice::OnNextFrameDue(
base::TimeTicks expected_execution_time,
int session_id) { … }
}