Commit f7b63545 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

video: increase quality

Set video quality to 1280x720 when using hardware acceleration.

Change-Id: I2931a88215baac0a74b52bef35781865ad31d357
parent 6ac0bbae
......@@ -139,7 +139,6 @@
0E7CF4DD20165BFB00CD967D /* ButtonsContainerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7CF4DC20165BFB00CD967D /* ButtonsContainerViewModel.swift */; };
0E7CF4DF2017918300CD967D /* ButtonsContainerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0E7CF4DE2017918300CD967D /* ButtonsContainerView.xib */; };
0E8E9A0520483E1200DA8E8B /* TitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E8E9A0420483E1200DA8E8B /* TitleView.swift */; };
0E96ED72225CFDB50016C07D /* encoder.json in Resources */ = {isa = PBXBuildFile; fileRef = 0E96ED71225CFDB50016C07D /* encoder.json */; };
0E96ED75225D06250016C07D /* GeneralSettingsViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E96ED74225D06250016C07D /* GeneralSettingsViewController.storyboard */; };
0E96ED77225D06380016C07D /* GeneralSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E96ED76225D06380016C07D /* GeneralSettingsViewController.swift */; };
0E96ED79225D06480016C07D /* GeneralSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E96ED78225D06480016C07D /* GeneralSettingsViewModel.swift */; };
......@@ -467,7 +466,6 @@
0E7CF4DC20165BFB00CD967D /* ButtonsContainerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonsContainerViewModel.swift; sourceTree = "<group>"; };
0E7CF4DE2017918300CD967D /* ButtonsContainerView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ButtonsContainerView.xib; sourceTree = "<group>"; };
0E8E9A0420483E1200DA8E8B /* TitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleView.swift; sourceTree = "<group>"; };
0E96ED71225CFDB50016C07D /* encoder.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = encoder.json; sourceTree = "<group>"; };
0E96ED74225D06250016C07D /* GeneralSettingsViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = GeneralSettingsViewController.storyboard; sourceTree = "<group>"; };
0E96ED76225D06380016C07D /* GeneralSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralSettingsViewController.swift; sourceTree = "<group>"; };
0E96ED78225D06480016C07D /* GeneralSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralSettingsViewModel.swift; sourceTree = "<group>"; };
......@@ -1512,7 +1510,6 @@
1ABE07C61F0D86B300D36361 /* Resources */ = {
isa = PBXGroup;
children = (
0E96ED71225CFDB50016C07D /* encoder.json */,
0EBCAA4D202E60F000E2A545 /* default.wav */,
1ABE07DA1F0D915100D36361 /* Localizable.strings */,
04399A021D1C2D9D00E99CD9 /* Images.xcassets */,
......@@ -1773,7 +1770,6 @@
0E6F545622403ADE00ECC3CE /* CreateSipAccountViewController.storyboard in Resources */,
1A2D18FD1F292DAD00B2C785 /* ConversationCell.xib in Resources */,
0E320D50224ADF840070B515 /* DialpadViewController.storyboard in Resources */,
0E96ED72225CFDB50016C07D /* encoder.json in Resources */,
1ABE07DC1F0D915100D36361 /* Localizable.strings in Resources */,
0EBCAA4E202E60F000E2A545 /* default.wav in Resources */,
1A2D18E61F29197100B2C785 /* MessageAccessoryView.xib in Resources */,
......
......@@ -117,8 +117,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
// sets output device to whatever is currently available (either spk / headset)
self.audioService.startAVAudioSession()
prepareVideoAcceleration()
// requests permission to use the camera
// will enumerate and add devices once permission has been granted
self.videoService.setupInputs()
......@@ -151,6 +149,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
self.window?.rootViewController = self.appCoordinator.rootViewController
self.window?.makeKeyAndVisible()
prepareVideoAcceleration()
self.accountService.initialAccountsLoading().subscribe(onCompleted: {
//set selected account if exists
self.appCoordinator.start()
......@@ -231,20 +231,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
let enable = keyExists ? UserDefaults.standard.bool(forKey: hardareAccelerationKey) : false
self.videoService.setDecodingAccelerated(withState: enable)
self.videoService.setEncodingAccelerated(withState: enable)
guard let codecInfoPath = Bundle.main.path(forResource: "encoder",
ofType: ".json") else {return}
guard let destPath =
NSSearchPathForDirectoriesInDomains(.documentDirectory,
.userDomainMask,
true).first else {return}
let fileManager = FileManager.default
guard let fullDestPath = NSURL(fileURLWithPath: destPath)
.appendingPathComponent("encoder.json") else {return}
let fullDestPathString = fullDestPath.path
do {
try fileManager.copyItem(atPath: codecInfoPath,
toPath: fullDestPathString)
} catch { }
}
// MARK: - Ring Daemon
......
......@@ -29,6 +29,7 @@
@property (class, nonatomic, weak) id <VideoAdapterDelegate> delegate;
- (void)addVideoDeviceWithName:(NSString*)deviceName withDevInfo:(NSDictionary*)deviceInfoDict;
- (void)setDefaultDevice:(NSString*)deviceName;
- (void)registerSinkTargetWithSinkId:sinkId withWidth:(NSInteger)w withHeight:(NSInteger)h;
- (void)removeSinkTargetWithSinkId:(NSString*)sinkId;
- (void)writeOutgoingFrameWithBuffer:(CVImageBufferRef)image
......
......@@ -234,6 +234,10 @@ static id <VideoAdapterDelegate> _delegate;
DRing::setDefaultDevice(std::string([deviceName UTF8String]));
}
- (void)setDefaultDevice:(NSString*)deviceName {
DRing::setDefaultDevice(std::string([deviceName UTF8String]));
}
- (void)setDecodingAccelerated:(BOOL)state {
DRing::setDecodingAccelerated(state);
}
......
......@@ -128,7 +128,7 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ZK1-Be-lcD" userLabel="ViewCapturedVideo">
<rect key="frame" x="0.0" y="-1" width="375" height="857"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="CfE-DF-buX" userLabel="CapturedVideo">
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="CfE-DF-buX" userLabel="CapturedVideo">
<rect key="frame" x="0.0" y="0.0" width="375" height="857"/>
</imageView>
<visualEffectView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="rt7-JS-vjg" userLabel="Blur Effect">
......
{
"h264_videotoolbox": {
"bit_rate": 700000
}
}
......@@ -44,19 +44,26 @@ enum VideoError: Error {
protocol FrameExtractorDelegate: class {
func captured(imageBuffer: CVImageBuffer?, image: UIImage)
func supportAVPixelFormat(support: Bool)
//func useHardwareAcceleration()-> Bool
//func updateVideoInputDevices()
}
class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
let nameLandscape = "frontCameraLanscape"
let namePortrait = "frontCameraPortrait"
let nameDevice1280_720 = "frontCameraPortrait1280_720"
let nameCamera = "camera://"
private let log = SwiftyBeaver.self
private let quality = AVCaptureSession.Preset.medium
private var quality = AVCaptureSession.Preset.hd1280x720
private var orientation = AVCaptureVideoOrientation.portrait
func setQuality(quality: AVCaptureSession.Preset) {
self.quality = quality
}
var getOrientation: AVCaptureVideoOrientation {
return orientation
}
......@@ -77,11 +84,11 @@ class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
super.init()
}
func getDeviceInfo(forPosition position: AVCaptureDevice.Position, orientation: UIDeviceOrientation) throws -> DeviceInfo {
func getDeviceInfo(forPosition position: AVCaptureDevice.Position, orientation: UIDeviceOrientation, quality: AVCaptureSession.Preset) throws -> DeviceInfo {
guard self.permissionGranted.value else {
throw VideoError.needPermission
}
self.captureSession.sessionPreset = self.quality
self.captureSession.sessionPreset = quality
guard let captureDevice = self.selectCaptureDevice(withPosition: position) else {
throw VideoError.selectDeviceFailed
}
......@@ -117,6 +124,11 @@ class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
self.captureSession.beginConfiguration()
self.captureSession.sessionPreset = self.quality
self.captureSession.commitConfiguration()
} else if self.captureSession.canSetSessionPreset(AVCaptureSession.Preset.medium) {
self.quality = AVCaptureSession.Preset.medium
self.captureSession.beginConfiguration()
self.captureSession.sessionPreset = self.quality
self.captureSession.commitConfiguration()
}
self.captureSession.startRunning()
}
......@@ -313,6 +325,7 @@ class VideoService: FrameExtractorDelegate {
self.videoAdapter = videoAdapter
currentOrientation = camera.getOrientation
VideoAdapter.delegate = self
self.hardwareAccelerated = videoAdapter.getEncodingAccelerated()
camera.delegate = self
}
......@@ -328,13 +341,28 @@ class VideoService: FrameExtractorDelegate {
camera.checkPermission()
}
private func enumerateVideoInputDevices() {
func enumerateVideoInputDevices() {
do {
try camera.configureSession(withPosition: AVCaptureDevice.Position.front, withOrientation: AVCaptureVideoOrientation.portrait)
self.log.debug("Camera successfully configured")
let frontLandscapeCameraDevInfo: [String: String] = try camera.getDeviceInfo(forPosition: AVCaptureDevice.Position.front, orientation: .landscapeLeft)
let frontPortraitCameraDevInfo: [String: String] = try camera.getDeviceInfo(forPosition: AVCaptureDevice.Position.front, orientation: .portrait)
videoAdapter.addVideoDevice(withName: camera.nameLandscape, withDevInfo: frontLandscapeCameraDevInfo)
let hd1280x720Device: [String: String] = try camera.getDeviceInfo(forPosition: AVCaptureDevice.Position.front, orientation: .portrait, quality: AVCaptureSession.Preset.hd1280x720)
let frontLandscapeCameraDevInfo: [String: String] =
try camera
.getDeviceInfo(forPosition: AVCaptureDevice.Position.front, orientation: .landscapeLeft,
quality: AVCaptureSession.Preset.medium)
let frontPortraitCameraDevInfo: [String: String] =
try camera.getDeviceInfo(forPosition: AVCaptureDevice.Position.front, orientation: .portrait,
quality: AVCaptureSession.Preset.medium)
videoAdapter.addVideoDevice(withName: camera.nameLandscape,
withDevInfo: frontLandscapeCameraDevInfo)
if self.hardwareAccelerated {
self.camera.setQuality(quality: AVCaptureSession.Preset.hd1280x720)
videoAdapter.addVideoDevice(withName: camera.namePortrait, withDevInfo: frontPortraitCameraDevInfo)
videoAdapter.addVideoDevice(withName: camera.nameDevice1280_720, withDevInfo: hd1280x720Device)
return
}
self.camera.setQuality(quality: AVCaptureSession.Preset.medium)
videoAdapter.addVideoDevice(withName: camera.nameDevice1280_720, withDevInfo: hd1280x720Device)
videoAdapter.addVideoDevice(withName: camera.namePortrait, withDevInfo: frontPortraitCameraDevInfo)
} catch let e as VideoError {
......@@ -417,6 +445,13 @@ extension VideoService: VideoAdapterDelegate {
func setEncodingAccelerated(withState state: Bool) {
videoAdapter.setEncodingAccelerated(state)
if state {
self.camera.setQuality(quality: AVCaptureSession.Preset.hd1280x720)
self.videoAdapter.setDefaultDevice(camera.nameDevice1280_720)
} else {
self.camera.setQuality(quality: AVCaptureSession.Preset.medium)
self.videoAdapter.setDefaultDevice(camera.namePortrait)
}
}
func getDecodingAccelerated() -> Bool {
......@@ -444,6 +479,7 @@ extension VideoService: VideoAdapterDelegate {
}
func startVideoCaptureBeforeCall() {
self.hardwareAccelerated = videoAdapter.getEncodingAccelerated()
self.camera.startCapturing()
}
......
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