poniedziałek, 30 kwietnia 2012

Notatki o Windows 8 Consumer Preview - odc. 19

W dzisiejszym odcinku będzie trochę hardcorowo, a mianowicie pozwolę sobie na cytaty z części niszowych dokumentów poświęconych tworzeniu aplikacji Metro dla urządzeń w ujęciu ogólnym oraz w dedykowanym przypadku dla kamer internetowych. Starałem się wyłapać ogólny sens i różne ciekawostki, które mogą być użyteczne nawet, gdy tylko będziemy korzystać z jakiegoś urządzenia w Windows 8. Niskopoziomowe szczegóły oczywiście zawarte są w dokumentach i przydadzą się producentom urządzeń (ewentualnie pasjonatom).

Metro style Device Apps

A Metro style device app involves several components:

  • Metro style Device Apps  - The Metro style Device App Lifecycle
  • Device Metadata in Windows 8 - Like in Windows 7, device manufacturers can use the device metadata system to deliver a device experience in Devices and Printers and Device Stage for a connected device or the PC. New to Windows 8, the device metadata system can also link the device or PC to Metro style device apps.
  • Device Drivers

Device Categories

  • Printers
  • Mobile Broadband
  • Cameras
  • Networked Entertainment Devices (Play To)
  • Specialized Devices

When the user plugs in or pairs a new device with the PC, Windows will identify the manufacturer and model of the device and then download the remaining components from Microsoft online services like Windows Update and Windows Store automatically. The user can also manually download it from the Windows Store. An Independent Software Vendor (ISV) may create the Metro style device app in partnership with the Independent Hardware Vendor (IHV), which supplies the device metadata and driver.

Device metadata is a set of XML files that create the link between a particular device and its Metro style device app. In addition to UI content for the device (localizable model name, description & photorealistic icons) the device metadata package indicates which app Windows should download. Device Metadata is authored using the Device Metadata Authoring Tool, and submitted to the Windows Hardware Center Dashboard.

Visual Studio 2011 Ultimate is required because it includes the Metadata Authoring Tool. Visual Studio 2011 Express doesn’t include WDK support or the recommended metadata tools.

image

Experience ID is part of the required information that the Windows Store uses when validating the Metro style device app. It is a 128-bit Globally Unique Identifier (GUID). The application developer then specifies in a file named StoreManifest.xml using a <ExperienceId> tag. The GUID is automatically generated by the Metadata Authoring Tool, and can be found in the PackageInfo XML component of the device metadata

image

 

<?xml version="1.0" encoding="utf-8"?>

<StoreManifest

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:noNamespaceSchemaLocation="StoreManifest.xsd"

  xmlns="http://schemas.microsoft.com/appx/2010/StoreManifest">

 

  <ProductFeatures>

    <DeviceCompanionApplication>

      <ExperienceIds>

        <ExperienceId>F9D916A7-AFD3-445B-8B9C-5B6466831C9E</ExperienceId>

        <ExperienceId>4A393BAA-DE6B-4B9A-A4BC-35FDE4A97FB2</ExperienceId>

      </ExperienceIds>

    </DeviceCompanionApplication>

</ProductFeatures>

 

</StoreManifest>

Each Device Metadata package can only reference a single Metro style device app, but the store manifest for a Metro style device app may list several Device Experience IDs, since many device models may use the same app.

If the Metro style device app is for a specialized device or a mobile broadband device, the app needs to declare the device interface in the application manifest (package.appxmanifest).

You must submit your device driver (if any) and your Metro style device app before you can submit device metadata.

There are three ways by which device software is acquired by the user:

  • Automatic Acquisition - The app is automatically acquired the first time an externally connected device is connected. This is the most common way Metro style device apps are acquired.
  • Windows Store Download - A user may find and purchase the app directly from the Windows Store. This is typically how app updates or additional apps are distributed.
  • OEM Preinstall - An app for a PC internal system component can be preloaded by an OEM as part of a new PC.

Automatic Acquisition

The user opts in to the Recommended Settings during Windows installation. This allows Windows to acquire drivers from Windows Update, metadata from WMIS, and the Metro style device app from the Windows Store.

Uninstalling Device Software

Devices may be uninstalled by the user. Only the driver and metadata are automatically uninstalled as part of device uninstall. The user needs to manually uninstall the Metro style device app. The user may choose to uninstall the Metro style device app without uninstalling the device as well, if they do not feel the app adds value to their experience.

Updating the Device Software Components

Updating Drivers

Driver updates are distributed through Windows Update as optional updates, provided that the user has opted in to receiving updates from Windows Update. Driver updates are not automatically distributed to devices if they have completed device setup, and already have metadata and drivers installed. Driver updates are not coupled to app updates, so driver updates should be designed to ensure compatibility with existing apps. If a driver update is distributed through Windows Update, or if the user manually reinstalls or updates the driver, the app should handle this appropriately.

Updating Device Metadata

The metadata that’s distributed by WMIS may be updated to point to a new or different Metro style device app.

Approximately 8 to 15 days after the submission of updated metadata that indicates a new app, new devices that are connected and set up for the first time will get the new app.

However, a new app indicated in updated metadata is not automatically distributed to PCs for which the device setup is already complete, because the users have previously received device metadata for the device. The Metro style device app is automatically downloaded only once, when the device is initially set up.

If the device metadata is updated to point to a different app, the old Metro style device app should advertise the new one to the user, so that users can acquire it from the Windows Store manually. Eventually, the old app should be removed from the Windows Store.

Users can also get to the new app, if they go to the Settings > Devices Page and click the ‘Get app’ link for that device.

Updating the Metro style Device App

Metro style device app updates are manually triggered by users, just like any other Metro style app updates. The Windows Store shows all available application updates to the user. The user manually chooses to update the app.

You should design apps to be compatible with older metadata and drivers. The device metadata or driver might not be up-to-date with the app, since manual installation of a Metro style device app from the Windows Store doesn’t automatically trigger distribution of metadata or drivers.

Metro style Device Apps for Cameras

image

Links

Your camera’s driver must use the AvStream driver model.

Windows 8 offers IHVs and system OEMs the ability to create video processing plug-ins in the form of a Media Foundation Transform (MFT). This special MFT is known as the driver MFT. It is also known as MFT0 to indicate it is the first MFT to operate in the source reader. A separate instance of MFT0 is attached to every pin on the capture source. For some system OEMs, the AVStream capture driver must support a preview pin, a capture pin, and a still pin. This means that there may be three instances of MFT0.

Two popular functions for MFT0 are:

  • Analyzing the video stream to provide feedback to the camera for improved capture (such as host-based auto focus and auto exposure).
  • Adding video effects.

Additionally, there are two final compounding factors:

  • Each instance of the MFT0 may be created or shut down at any time.
  • The Metro style device app is only connected to one instance of the MFT0, currently the one associated with the preview pin.

When your camera’s Metro style device app is registered with Windows, the features it implements are automatically made available to any Metro style apps that call the Windows.Media.Capture.CameraOptionsUI.Show API to display a camera options user interface.

image

The Driver MFT is the Media Foundation Transform (MFT) that implements the effects. This media extension that provides the effects is an implementation of IMediaTransform. This MFT is the first transform applied to the video stream coming out of the driver.

A Metro style device app for camera can be launched in two different contexts: the Start experience (when the app is launched from the app tile in the Start screen), and the Options experience.

image

 

image

 

A Metro style device app that is declared as a camera settings extension can be activated by Windows when a user clicks the Options button or an app calls Windows.Media.Capture.CameraOptionsUI.Show. The Metro style device app then handles the event that is raised when the app is activated

image

var activatedHandler = function (eventArgs) {

        var kind = eventArgs.detail.kind;

        var activationType =

            Windows.ApplicationModel.Activation.ActivationKind;

        if (kind === activationType.cameraSettings)

        { 

           // Initialize logic for the flyout that provides camera

           // effects here.

 

        } else if (kind === activationType.launch)

        {

           // Do not provide settings or effects if launched.

           // Instead, you may provide support, services,

           // or other functionality that does not apply effects.   

 

        }

}

WinJS.Application.start();

WinJS.Application.addEventListener("activated", activatedHandler, false);

namespace CameraMetrostyleDeviceApp

{

    public partial class App

    {

        public App()

        {

            InitializeComponent();

        }

 

        protected override void OnLaunched(

             LaunchActivatedEventArgs args)

        {

            // Initialize the start page

            Window.Current.Content = new StartPage();

            Window.Current.Activate();

        }

 

 

        protected override void OnActivated(IActivatedEventArgs args)

        {

            if (args.Kind == ActivationKind.CameraSettings)

            {

                base.OnActivated(args);

                MainPage page = new MainPage();

                Window.Current.Content = page;

 

           // The args object contains properties for

           // controlling the device settings                      

              page.Initialize((CameraSettingsActivatedEventArgs)args);

 

                Window.Current.Activate();

            }

        }

    }

}

Type Windows.ApplicationModel.Activation.CameraSettingsActivatedEventArgs exposes two properties for controlling the camera.

  • The VideoDeviceController property provides methods for adjusting standard settings. It is an object of type Windows.Media.Devices.VideoDeviceController.
  • The VideoDeviceExtension is a pointer to the Driver MFT interfaces for applying custom settings.

var videodev = null;

var videoext = null;

var lcWrapper = null;

 

function activatedHandler(eventArgs) {

    if (eventArgs.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.cameraSettings) {

        videoext = eventArgs.detail.videoDeviceExtension;

        videodev = eventArgs.detail.videoDeviceController;

 

        if (videoext !== null) {

            initializeExtension(videoext);

        }

 

        if (videodev !== null) {

            initializeSlider();

            // do other initialization here…

        }

    }

}

 

WinJS.Application.start();

WinJS.Application.addEventListener("activated", activatedHandler, false);

 

function initializeExtension(mft0) {

    lcWrapper = Wrapper.WinRTComponent();

    lcWrapper.initialize(mft0);

}

 

// Initialize a slider element using the VideoDeviceController object

function initializeSlider() {

    try {

        var bValue = 0;

        var bAuto = 0;

        var slider;

            if (videodev != null) {

                bValue = videodev.brightness.tryGetValue();

                slider = document.getElementById("slBrt");

                slider.value = bValue.value;

                slider.min = videodev.brightness.capabilities.min;

                slider.max = videodev.brightness.capabilities.max;

            }

}

If your Metro style device app is more than 560 pixels in height, the user may slide or scroll to view parts of the app that are above or below the viewable area. A Metro style device app should not exceed 340 pixels in width.

Suggested effects
  • Color effects, such as grayscale, sepia tone, or solarizing the entire picture.
  • Face-tracking effects - these are often overlays, where a face is identified in the picture and an overlay, such as a hat or a pair of glasses, is added on top of it.
  • Scene modes - these are preset exposure and focus modes for different lighting conditions.
Suggested settings
  • Your Metro style device app can provide a switch to enable hardware-implemented settings, such as color correction schemes. Some examples of color correction schemes are TrueColor and RightColor.
  • Implement basic properties that supplement the other settings exposed by your Metro style device app. For example, many devices may expose controls for adjusting brightness, contrast, flicker, focus, and exposure, but a device that implements TrueColor to automatically adjust the brightness and contrast may not need to provide these settings.

Restrictions

  • Do not show a user interface for selecting settings or effects if the app is launched from its tile in Start rather than from a capture app. Settings will not persist from the Start experience.
  • Do not provide a preview or otherwise take ownership of the video stream from inside your Metro style device app.
  • Do not adjust resolution in your Metro style device app.
  • Do not attempt to display pop-ups, notifications, or dialogs outside of the area intended for the Metro style device app’s Options experience
  • Do not declare the Webcam, Microphone, SMS device capabilities

image

The Metro style device app for camera runs in a different process than the app that is capturing from the camera.

Note that the Driver MFT is not strictly required for a Metro style device app, but it supplies the custom settings and effects. A device manufacturer may choose to implement a Metro style device app without a Driver MFT, simply to provide a differentiated user interface containing branding for their hardware, without applying custom effects to the video stream.

The Driver MFT implements IMFTransform. It also must be exposed to the Windows Runtime, so it must also implement IInspectable.

A Driver MFT is registered with Windows as a COM interface so that the transform it implements can be applied to the media stream coming out of a specific device, such as a camera. When an app initiates a video capture, a Media Foundation Source Reader is instantiated to provide the video stream. This media source reads a registry value from the device registry key. If the CLSID of the Driver MFT’s COM class is found in the registry value, the source reader instantiates the Driver MFT and inserts it into the media pipeline.

In addition to Metro style device apps, the Driver MFT functionality can be accessed when the device associated with it is used to capture video using the following APIs:

  • HTML5 <video> tags in a Metro style app using HTML.
  • Windows.Media.MediaCapture API in a Metro style app using the Windows Runtime

To write a Metro style device app in C# or JavaScript that interacts with a Driver MFT, you need to create an additional component in the Metro style device app’s Visual Studio project. This component is a wrapper that exposes the Driver MFT interfaces in a Windows Runtime Component that is visible to the Metro style device app.

 

KSCATEGORY_VIDEO_CAMERA:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\{E5323777-F976-4f5b-9B55-B94699C46E44}\##?#USB#VID_045E&PID_075D&MI_00#8&23C3DB65&0&0000#{E5323777-F976-4f5b-9B55-B94699C46E44}\#GLOBAL\Device Parameters]

"CLSID"="{17CCA71B-ECD7-11D0-B908-00A0C9223196}"

"FriendlyName"="USB Video Device"

"RTCFlags"=dword:00000010

"CameraPostProcessingPluginCLSID"="{3456A71B-ECD7-11D0-B908-00A0C9223196}"

Internal cameras embedded inside a portable computer do not have their Metro style device app downloaded, because there is no act of connecting the camera to trigger the download.

You submit your camera’s Metro style device app to the Windows Store or preinstall it, in the case of internal cameras.

Brak komentarzy: