Skip to content

Commit

Permalink
feat(windows_media): add MediaCapture APIs (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
halildurmus committed Jul 10, 2023
1 parent 009e6d1 commit 81584de
Show file tree
Hide file tree
Showing 362 changed files with 34,924 additions and 14 deletions.
21 changes: 21 additions & 0 deletions packages/windows_foundation/lib/src/internal/native_structs.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ final class NativeBitmapPlaneDescription extends Struct {
external int stride;
}

/// @nodoc
final class NativeBitmapSize extends Struct {
@Uint32()
external int width;

@Uint32()
external int height;
}

/// @nodoc
final class NativeColor extends Struct {
@Uint8()
Expand Down Expand Up @@ -504,6 +513,18 @@ final class NativeVector4 extends Struct {
external double w;
}

/// @nodoc
final class NativeWhiteBalanceGain extends Struct {
@Double()
external double r;

@Double()
external double g;

@Double()
external double b;
}

/// @nodoc
final class NativeWindowId extends Struct {
@Uint64()
Expand Down
1 change: 1 addition & 0 deletions packages/windows_graphics/lib/src/exports.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export 'imaging/bitmapplanedescription.dart';
export 'imaging/bitmappropertiesview.dart';
export 'imaging/bitmappropertyset.dart';
export 'imaging/bitmaprotation.dart';
export 'imaging/bitmapsize.dart';
export 'imaging/bitmaptransform.dart';
export 'imaging/bitmaptypedvalue.dart';
export 'imaging/colormanagementmode.dart';
Expand Down
55 changes: 55 additions & 0 deletions packages/windows_graphics/lib/src/imaging/bitmapsize.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

/// Represents the size of a bitmap, in pixels.
final class BitmapSize implements WinRTStruct {
BitmapSize(this.width, this.height);

final int width;
final int height;

@override
Pointer<NativeBitmapSize> toNative({Allocator allocator = malloc}) {
final nativeStructPtr = allocator<NativeBitmapSize>();
nativeStructPtr.ref
..width = width
..height = height;
return nativeStructPtr;
}

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is BitmapSize &&
width == other.width &&
height == other.height;
}

@override
int get hashCode => width.hashCode ^ height.hashCode;
}

/// @nodoc
extension PointerNativeBitmapSizeConversion on Pointer<NativeBitmapSize> {
/// Converts this [NativeBitmapSize] to a Dart [BitmapSize].
BitmapSize toDart() {
final ref = this.ref;
return BitmapSize(ref.width, ref.height);
}

/// Creates a `List<BitmapSize>` from `Pointer<NativeBitmapSize>`.
///
/// [length] must not be greater than the number of elements stored inside the
/// `Pointer<NativeBitmapSize>`.
List<BitmapSize> toList({int length = 1}) =>
[for (var i = 0; i < length; i++) elementAt(i).toDart()];
}
45 changes: 45 additions & 0 deletions packages/windows_media/lib/src/audiobuffer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: constant_identifier_names, non_constant_identifier_names
// ignore_for_file: unnecessary_import, unused_import

import 'dart:async';
import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart' hide DocumentProperties;
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

import 'iaudiobuffer.dart';

/// Represents a buffer containing audio data.
class AudioBuffer extends IInspectable
implements IAudioBuffer, IMemoryBuffer, IClosable {
AudioBuffer.fromPtr(super.ptr);

late final _iAudioBuffer = IAudioBuffer.from(this);

@override
int get capacity => _iAudioBuffer.capacity;

@override
int get length => _iAudioBuffer.length;

@override
set length(int value) => _iAudioBuffer.length = value;

late final _iMemoryBuffer = IMemoryBuffer.from(this);

@override
IMemoryBufferReference? createReference() => _iMemoryBuffer.createReference();

late final _iClosable = IClosable.from(this);

@override
void close() => _iClosable.close();
}
27 changes: 27 additions & 0 deletions packages/windows_media/lib/src/audiobufferaccessmode.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: deprecated_member_use_from_same_package

import 'package:windows_foundation/windows_foundation.dart';

/// Defines the access mode of an AudioBuffer returned by
/// AudioFrame.LockBuffer.
enum AudioBufferAccessMode implements WinRTEnum {
read(0),
readWrite(1),
write(2);

@override
final int value;

const AudioBufferAccessMode(this.value);

factory AudioBufferAccessMode.from(int value) =>
AudioBufferAccessMode.values.firstWhere((e) => e.value == value,
orElse: () => throw ArgumentError.value(
value, 'value', 'No enum value with that value'));
}
81 changes: 81 additions & 0 deletions packages/windows_media/lib/src/audioframe.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: constant_identifier_names, non_constant_identifier_names
// ignore_for_file: unnecessary_import, unused_import

import 'dart:async';
import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart' hide DocumentProperties;
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

import 'audiobuffer.dart';
import 'audiobufferaccessmode.dart';
import 'iaudioframe.dart';
import 'iaudioframefactory.dart';
import 'imediaframe.dart';

/// Represents a single frame of audio data.
class AudioFrame extends IInspectable
implements IAudioFrame, IMediaFrame, IClosable {
AudioFrame.fromPtr(super.ptr);

static const _className = 'Windows.Media.AudioFrame';

factory AudioFrame.create(int capacity) => createActivationFactory(
IAudioFrameFactory.fromPtr, _className, IID_IAudioFrameFactory)
.create(capacity);

late final _iAudioFrame = IAudioFrame.from(this);

@override
AudioBuffer? lockBuffer(AudioBufferAccessMode mode) =>
_iAudioFrame.lockBuffer(mode);

late final _iMediaFrame = IMediaFrame.from(this);

@override
String get type => _iMediaFrame.type;

@override
bool get isReadOnly => _iMediaFrame.isReadOnly;

@override
set relativeTime(Duration? value) => _iMediaFrame.relativeTime = value;

@override
Duration? get relativeTime => _iMediaFrame.relativeTime;

@override
set systemRelativeTime(Duration? value) =>
_iMediaFrame.systemRelativeTime = value;

@override
Duration? get systemRelativeTime => _iMediaFrame.systemRelativeTime;

@override
set duration(Duration? value) => _iMediaFrame.duration = value;

@override
Duration? get duration => _iMediaFrame.duration;

@override
set isDiscontinuous(bool value) => _iMediaFrame.isDiscontinuous = value;

@override
bool get isDiscontinuous => _iMediaFrame.isDiscontinuous;

@override
IPropertySet? get extendedProperties => _iMediaFrame.extendedProperties;

late final _iClosable = IClosable.from(this);

@override
void close() => _iClosable.close();
}
25 changes: 25 additions & 0 deletions packages/windows_media/lib/src/audioprocessing.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: deprecated_member_use_from_same_package

import 'package:windows_foundation/windows_foundation.dart';

/// Defines the audio processing modes.
enum AudioProcessing implements WinRTEnum {
default_(0),
raw(1);

@override
final int value;

const AudioProcessing(this.value);

factory AudioProcessing.from(int value) =>
AudioProcessing.values.firstWhere((e) => e.value == value,
orElse: () => throw ArgumentError.value(
value, 'value', 'No enum value with that value'));
}
45 changes: 45 additions & 0 deletions packages/windows_media/lib/src/capture/advancedcapturedphoto.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: constant_identifier_names, non_constant_identifier_names
// ignore_for_file: unnecessary_import, unused_import

import 'dart:async';
import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart' hide DocumentProperties;
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

import '../devices/advancedphotomode.dart';
import 'capturedframe.dart';
import 'iadvancedcapturedphoto.dart';
import 'iadvancedcapturedphoto2.dart';

/// Represents a photo captured using system-provided computational
/// photography techniques provided by the AdvancedPhotoCapture class.
class AdvancedCapturedPhoto extends IInspectable
implements IAdvancedCapturedPhoto, IAdvancedCapturedPhoto2 {
AdvancedCapturedPhoto.fromPtr(super.ptr);

late final _iAdvancedCapturedPhoto = IAdvancedCapturedPhoto.from(this);

@override
CapturedFrame? get frame => _iAdvancedCapturedPhoto.frame;

@override
AdvancedPhotoMode get mode => _iAdvancedCapturedPhoto.mode;

@override
Object? get context => _iAdvancedCapturedPhoto.context;

late final _iAdvancedCapturedPhoto2 = IAdvancedCapturedPhoto2.from(this);

@override
Rect? get frameBoundsRelativeToReferencePhoto =>
_iAdvancedCapturedPhoto2.frameBoundsRelativeToReferencePhoto;
}
55 changes: 55 additions & 0 deletions packages/windows_media/lib/src/capture/advancedphotocapture.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: constant_identifier_names, non_constant_identifier_names
// ignore_for_file: unnecessary_import, unused_import

import 'dart:async';
import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart' hide DocumentProperties;
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

import 'advancedcapturedphoto.dart';
import 'iadvancedphotocapture.dart';

/// Provides methods for capturing photos using system-provided
/// computational photography techniques.
class AdvancedPhotoCapture extends IInspectable
implements IAdvancedPhotoCapture {
AdvancedPhotoCapture.fromPtr(super.ptr);

late final _iAdvancedPhotoCapture = IAdvancedPhotoCapture.from(this);

@override
Future<AdvancedCapturedPhoto?> captureAsync() =>
_iAdvancedPhotoCapture.captureAsync();

@override
Future<AdvancedCapturedPhoto?> captureWithContextAsync(Object? context) =>
_iAdvancedPhotoCapture.captureWithContextAsync(context);

@override
int add_OptionalReferencePhotoCaptured(Pointer<COMObject> handler) =>
_iAdvancedPhotoCapture.add_OptionalReferencePhotoCaptured(handler);

@override
void remove_OptionalReferencePhotoCaptured(int token) =>
_iAdvancedPhotoCapture.remove_OptionalReferencePhotoCaptured(token);

@override
int add_AllPhotosCaptured(Pointer<COMObject> handler) =>
_iAdvancedPhotoCapture.add_AllPhotosCaptured(handler);

@override
void remove_AllPhotosCaptured(int token) =>
_iAdvancedPhotoCapture.remove_AllPhotosCaptured(token);

@override
Future<void> finishAsync() => _iAdvancedPhotoCapture.finishAsync();
}

0 comments on commit 81584de

Please sign in to comment.