Commit f4b4b2d0 authored by Markus Handell's avatar Markus Handell Committed by Commit Bot

VideoCaptureDeviceAVFoundation: move static functionality to a new utils file.

This change prepares for development of capturer features behind a new flag. Moving static functionality into a separate file allows the capturer implementation to be duped, and the creator to create either implementation based on a flag.

Future CLs will add the flag and perform the duplication.

Bug: chromium:1126690
Change-Id: I8592a2ba81765e999c497eda9a6f09cc644e1423
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401520Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Commit-Queue: Markus Handell <handellm@google.com>
Cr-Commit-Position: refs/heads/master@{#805965}
parent 2adf0823
...@@ -164,6 +164,8 @@ component("capture_lib") { ...@@ -164,6 +164,8 @@ component("capture_lib") {
sources += [ sources += [
"video/mac/video_capture_device_avfoundation_mac.h", "video/mac/video_capture_device_avfoundation_mac.h",
"video/mac/video_capture_device_avfoundation_mac.mm", "video/mac/video_capture_device_avfoundation_mac.mm",
"video/mac/video_capture_device_avfoundation_utils_mac.h",
"video/mac/video_capture_device_avfoundation_utils_mac.mm",
"video/mac/video_capture_device_decklink_mac.h", "video/mac/video_capture_device_decklink_mac.h",
"video/mac/video_capture_device_decklink_mac.mm", "video/mac/video_capture_device_decklink_mac.mm",
"video/mac/video_capture_device_factory_mac.h", "video/mac/video_capture_device_factory_mac.h",
......
...@@ -16,23 +16,12 @@ ...@@ -16,23 +16,12 @@
namespace media { namespace media {
class VideoCaptureDeviceMac; class VideoCaptureDeviceMac;
// Find the best capture format from |formats| for the specified dimensions and
// frame rate. Returns an element of |formats|, or nil.
AVCaptureDeviceFormat* CAPTURE_EXPORT
FindBestCaptureFormat(NSArray<AVCaptureDeviceFormat*>* formats,
int width,
int height,
float frame_rate);
} // namespace media } // namespace media
// Class used by VideoCaptureDeviceMac (VCDM) for video and image capture using // Class used by VideoCaptureDeviceMac (VCDM) for video and image capture using
// AVFoundation API. This class lives inside the thread created by its owner // AVFoundation API. This class lives inside the thread created by its owner
// VCDM. // VCDM.
// //
// * Clients (VCDM) should call +deviceNames to fetch the list of devices
// available in the system; this method returns the list of device names that
// have to be used with -setCaptureDevice:.
// * Previous to any use, clients (VCDM) must call -initWithFrameReceiver: to // * Previous to any use, clients (VCDM) must call -initWithFrameReceiver: to
// initialise an object of this class and register a |frameReceiver_|. // initialise an object of this class and register a |frameReceiver_|.
// * Frame receiver registration or removal can also happen via explicit call // * Frame receiver registration or removal can also happen via explicit call
...@@ -86,13 +75,6 @@ FindBestCaptureFormat(NSArray<AVCaptureDeviceFormat*>* formats, ...@@ -86,13 +75,6 @@ FindBestCaptureFormat(NSArray<AVCaptureDeviceFormat*>* formats,
base::ThreadChecker _main_thread_checker; base::ThreadChecker _main_thread_checker;
} }
// Returns a dictionary of capture devices with friendly name and unique id.
+ (NSDictionary*)deviceNames;
// Retrieve the capture supported formats for a given device |descriptor|.
+ (void)getDevice:(const media::VideoCaptureDeviceDescriptor&)descriptor
supportedFormats:(media::VideoCaptureFormats*)formats;
// Initializes the instance and the underlying capture session and registers the // Initializes the instance and the underlying capture session and registers the
// frame receiver. // frame receiver.
- (id)initWithFrameReceiver:(media::VideoCaptureDeviceMac*)frameReceiver; - (id)initWithFrameReceiver:(media::VideoCaptureDeviceMac*)frameReceiver;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_AVFOUNDATION_UTILS_MAC_H_
#define MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_AVFOUNDATION_UTILS_MAC_H_
#import <AVFoundation/AVFoundation.h>
#import <CoreMedia/CoreMedia.h>
#import <CoreVideo/CoreVideo.h>
#include "base/mac/scoped_nsobject.h"
#include "media/capture/video/video_capture_device_descriptor.h"
#include "media/capture/video_capture_types.h"
namespace media {
// Find the best capture format from |formats| for the specified dimensions and
// frame rate. Returns an element of |formats|, or nil.
AVCaptureDeviceFormat* CAPTURE_EXPORT
FindBestCaptureFormat(NSArray<AVCaptureDeviceFormat*>* formats,
int width,
int height,
float frame_rate);
// Returns a dictionary of capture devices with friendly name and unique id.
// VideoCaptureDeviceMac should call this function to fetch the list of devices
// available in the system; this method returns the list of device names that
// have to be used with -[VideoCaptureDeviceAVFoundation setCaptureDevice:].
base::scoped_nsobject<NSDictionary> GetVideoCaptureDeviceNames();
// Retrieve the capture supported formats for a given device |descriptor|.
media::VideoCaptureFormats GetDeviceSupportedFormats(
const media::VideoCaptureDeviceDescriptor& descriptor);
// This function translates Mac Core Video pixel formats to Chromium pixel
// formats.
media::VideoPixelFormat FourCCToChromiumPixelFormat(FourCharCode code);
// Extracts |base_address| and |length| out of a SampleBuffer.
void ExtractBaseAddressAndLength(char** base_address,
size_t* length,
CMSampleBufferRef sample_buffer);
} // namespace media
#endif // MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_AVFOUNDATION_UTILS_MAC_H_
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#import "media/capture/video/mac/video_capture_device_avfoundation_mac.h" #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h"
#import "media/capture/video/mac/video_capture_device_avfoundation_utils_mac.h"
#import "media/capture/video/mac/video_capture_device_decklink_mac.h" #import "media/capture/video/mac/video_capture_device_decklink_mac.h"
#include "media/capture/video/mac/video_capture_device_mac.h" #include "media/capture/video/mac/video_capture_device_mac.h"
#include "services/video_capture/public/uma/video_capture_service_event.h" #include "services/video_capture/public/uma/video_capture_service_event.h"
...@@ -102,12 +103,12 @@ void VideoCaptureDeviceFactoryMac::GetDevicesInfo( ...@@ -102,12 +103,12 @@ void VideoCaptureDeviceFactoryMac::GetDevicesInfo(
// Loop through all available devices and add to |devices_info|. // Loop through all available devices and add to |devices_info|.
std::vector<VideoCaptureDeviceInfo> devices_info; std::vector<VideoCaptureDeviceInfo> devices_info;
NSDictionary* capture_devices;
DVLOG(1) << "Enumerating video capture devices using AVFoundation"; DVLOG(1) << "Enumerating video capture devices using AVFoundation";
capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; base::scoped_nsobject<NSDictionary> capture_devices =
GetVideoCaptureDeviceNames();
// Enumerate all devices found by AVFoundation, translate the info for each // Enumerate all devices found by AVFoundation, translate the info for each
// to class Name and add it to |device_names|. // to class Name and add it to |device_names|.
for (NSString* key in capture_devices) { for (NSString* key in capture_devices.get()) {
const std::string device_id = [key UTF8String]; const std::string device_id = [key UTF8String];
const VideoCaptureApi capture_api = VideoCaptureApi::MACOSX_AVFOUNDATION; const VideoCaptureApi capture_api = VideoCaptureApi::MACOSX_AVFOUNDATION;
int transport_type = [[capture_devices valueForKey:key] transportType]; int transport_type = [[capture_devices valueForKey:key] transportType];
...@@ -128,9 +129,8 @@ void VideoCaptureDeviceFactoryMac::GetDevicesInfo( ...@@ -128,9 +129,8 @@ void VideoCaptureDeviceFactoryMac::GetDevicesInfo(
devices_info.emplace_back(descriptor); devices_info.emplace_back(descriptor);
// Get supported formats // Get supported formats
[VideoCaptureDeviceAVFoundation devices_info.back().supported_formats =
getDevice:descriptor GetDeviceSupportedFormats(descriptor);
supportedFormats:&devices_info.back().supported_formats];
} }
// Also retrieve Blackmagic devices, if present, via DeckLink SDK API. // Also retrieve Blackmagic devices, if present, via DeckLink SDK API.
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "media/capture/video/mac/video_capture_device_avfoundation_mac.h" #include "media/capture/video/mac/video_capture_device_avfoundation_mac.h"
#include "media/capture/video/mac/video_capture_device_avfoundation_utils_mac.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment