#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/capture/video/file_video_capture_device.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <optional>
#include <string_view>
#include <utility>
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/single_thread_task_runner.h"
#include "media/base/video_frame.h"
#include "media/capture/mojom/image_capture_types.h"
#include "media/capture/video/blob_utils.h"
#include "media/capture/video/gpu_memory_buffer_utils.h"
#include "media/capture/video_capture_types.h"
#include "media/parsers/jpeg_parser.h"
#include "third_party/libyuv/include/libyuv.h"
namespace media {
namespace {
int gcd(int a, int b) { … }
}
static const int kY4MHeaderMaxSize = …;
static const char kY4MSimpleFrameDelimiter[] = …;
static const int kY4MSimpleFrameDelimiterSize = …;
static const float kMJpegFrameRate = …;
int ParseY4MInt(const std::string_view token) { … }
void ParseY4MRational(const std::string_view token,
int* numerator,
int* denominator) { … }
void ParseY4MTags(const std::string& file_header,
VideoCaptureFormat* video_format) { … }
class VideoFileParser { … };
class Y4mFileParser final : public VideoFileParser { … };
class MjpegFileParser final : public VideoFileParser { … };
VideoFileParser::VideoFileParser(const base::FilePath& file_path)
: … { … }
VideoFileParser::~VideoFileParser() = default;
Y4mFileParser::Y4mFileParser(const base::FilePath& file_path)
: … { … }
Y4mFileParser::~Y4mFileParser() = default;
bool Y4mFileParser::Initialize(VideoCaptureFormat* capture_format) { … }
base::span<const uint8_t> Y4mFileParser::GetNextFrame() { … }
MjpegFileParser::MjpegFileParser(const base::FilePath& file_path)
: … { … }
MjpegFileParser::~MjpegFileParser() = default;
bool MjpegFileParser::Initialize(VideoCaptureFormat* capture_format) { … }
base::span<const uint8_t> MjpegFileParser::GetNextFrame() { … }
bool FileVideoCaptureDevice::GetVideoCaptureFormat(
const base::FilePath& file_path,
VideoCaptureFormat* video_format) { … }
std::unique_ptr<VideoFileParser> FileVideoCaptureDevice::GetVideoFileParser(
const base::FilePath& file_path,
VideoCaptureFormat* video_format) { … }
std::vector<uint8_t> FileVideoCaptureDevice::CropPTZRegion(
const uint8_t* frame,
size_t frame_buffer_size,
VideoPixelFormat* final_pixel_format) { … }
FileVideoCaptureDevice::FileVideoCaptureDevice(
const base::FilePath& file_path,
std::unique_ptr<gpu::GpuMemoryBufferSupport> gmb_support)
: … { … }
FileVideoCaptureDevice::~FileVideoCaptureDevice() { … }
void FileVideoCaptureDevice::AllocateAndStart(
const VideoCaptureParams& params,
std::unique_ptr<VideoCaptureDevice::Client> client) { … }
void FileVideoCaptureDevice::StopAndDeAllocate() { … }
void FileVideoCaptureDevice::GetPhotoState(GetPhotoStateCallback callback) { … }
void FileVideoCaptureDevice::OnGetPhotoState(GetPhotoStateCallback callback) { … }
void FileVideoCaptureDevice::SetPhotoOptions(mojom::PhotoSettingsPtr settings,
SetPhotoOptionsCallback callback) { … }
void FileVideoCaptureDevice::OnSetPhotoOptions(
mojom::PhotoSettingsPtr settings,
SetPhotoOptionsCallback callback) { … }
void FileVideoCaptureDevice::TakePhoto(TakePhotoCallback callback) { … }
void FileVideoCaptureDevice::OnAllocateAndStart(
const VideoCaptureParams& params,
std::unique_ptr<VideoCaptureDevice::Client> client) { … }
void FileVideoCaptureDevice::OnStopAndDeAllocate() { … }
void FileVideoCaptureDevice::OnCaptureTask() { … }
}