MediaFrameReader
MediaFrameReader
MediaFrameReader
MediaFrameReader
Class
Definition
Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Prerelease APIs are identified by a Prerelease label.
[Contains prerelease APIs.]
Provides access to frames from a MediaFrameSource and notification when a new frame arrives.
public : sealed class MediaFrameReader : IClosable, IMediaFrameReaderpublic sealed class MediaFrameReader : IDisposable, IMediaFrameReaderPublic NotInheritable Class MediaFrameReader Implements IDisposable, IMediaFrameReader// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
Remarks
Get an instance of this class by calling CreateFrameReaderAsync on a MediaCapture object that has been initialized to use the desired media frame source.
For how-to guidance on using MediaFrameSource to capture frames, see Process media frames with MediaFrameReader.
Properties
AcquisitionMode AcquisitionMode AcquisitionMode AcquisitionMode
Prerelease. Gets or sets a value that specifies the way that the system should manage frames acquired from a MediaFrameReader when a new frame arrives before the app has finished processing the previous frame.
public : MediaFrameReaderAcquisitionMode AcquisitionMode { get; set; }public MediaFrameReaderAcquisitionMode AcquisitionMode { get; set; }Public ReadWrite Property AcquisitionMode As MediaFrameReaderAcquisitionMode// You can use this property in JavaScript.
- Value
- MediaFrameReaderAcquisitionMode MediaFrameReaderAcquisitionMode MediaFrameReaderAcquisitionMode MediaFrameReaderAcquisitionMode
A value that specifies the frame reader's acquisition mode.
| Device family |
Windows 10 Insider Preview (introduced v10.0.16257.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v5)
|
Remarks
If this property is set to Realtime, frames that arrive while the app's FrameArrived event handler is executing are dropped. This mode works well for scenarios where processing the most current frame is prioritized, such as real-time computer vision applications.
If this property is set to [Buffered]((https://docs.microsoft.com/uwp/api/windows.media.capture.frames.mediaframereaderacquisitionmode), frames that arrive while the app's FrameArrived event handler is executing are buffered in memory by the system. The FrameArrived event is raised for each buffered frame when the event handler for the previous frame has completed. This mode is intended for apps for which the sequence of frames is critical and for which dropped frames will break the scenario. Note that once the system's memory limit for buffered frames has been reached, no more frames will be acquired until the app processes buffered frames, freeing memory for the acquisition of additional frames.
- See Also
Methods
Close() Close() Close() Close()
Disposes of the object and associated resources.
public : void Close()This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
Remarks
The Close method is used by Universal Windows app using JavaScript. For apps written using the .NET Framework 4.5 in C# and VB.NET, the Close method is exposed as the Dispose() method on the MediaFrameReader object. For apps written in C++, the Close method will be called when using the delete keyword on the object.
Dispose() Dispose() Dispose() Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
This member is not implemented in C++void Dispose()Sub Disposevoid Dispose()
StartAsync() StartAsync() StartAsync() StartAsync()
Asynchronously starts the reading of frames from a MediaFrameSource.
public : IAsyncOperation<MediaFrameReaderStartStatus> StartAsync()public IAsyncOperation<MediaFrameReaderStartStatus> StartAsync()Public Function StartAsync() As IAsyncOperation( Of MediaFrameReaderStartStatus )// You can use this method in JavaScript.
An asynchronous operation that returns a MediaFrameReaderStartStatus on completion.
StopAsync() StopAsync() StopAsync() StopAsync()
Asynchronously stops the reading of frames from a MediaFrameSource.
public : IAsyncAction StopAsync()public IAsyncAction StopAsync()Public Function StopAsync() As IAsyncAction// You can use this method in JavaScript.
An asynchronous action.
TryAcquireLatestFrame() TryAcquireLatestFrame() TryAcquireLatestFrame() TryAcquireLatestFrame()
Attempts to obtain a MediaFrameReference object representing the latest frame from the MediaFrameSource.
public : MediaFrameReference TryAcquireLatestFrame()public MediaFrameReference TryAcquireLatestFrame()Public Function TryAcquireLatestFrame() As MediaFrameReference// You can use this method in JavaScript.
A MediaFrameReference representing the latest frame from the media frame source.
Remarks
Each MediaFrameReader maintains a circular buffer of MediaFrameReference objects obtained from TryAcquireLatestFrame. After all of the MediaFrameReference objects in the buffer have been used, subsequent calls to TryAcquireLatestFrame will cause the system to call Close (or Dispose in C#) on the oldest buffer object in order to reuse it. Once the object has been disposed, you can no longer use it to access the frame data. For this reason, you should not store the MediaFrameReference object longer than you actually need to process the frame. If your app scenario requires you to keep a reference to the data for longer, you should use one of the APIs provided to get the underlying data. These methods include:
- BufferMediaFrame.Buffer
- VideoMediaFrame.SoftwareBitmap
- VideoMediaFrame.GetVideoFrame
- VideoMediaFrame.CameraIntrinsics It is the responsibility of the app to call Close (or Dispose) on the objects returned by these APIs when they are no longer being used.
Important
If you access the SoftwareBitmap or Direct3DSurface objects provided by the VideoMediaFrame property of a MediaFrameReference, the system creates a strong reference to these objects, which means that they will not be disposed when you call Dispose on the containing MediaFrameReference. You must explicitly call the Dispose method of the SoftwareBitmap or Direct3DSurface directly for the objects to be immediately disposed. Otherwise, the garbage collector will eventually free the memory for these objects, but you can't know when this will occur, and if the number of allocated bitmaps or surfaces exceeds the maximum amount allowed by the system, the flow of new frames will stop.
Events
FrameArrived FrameArrived FrameArrived FrameArrived
Occurs when a new frame arrives from the media frame source associated with the MediaFrameReader.
public : event TypedEventHandler FrameArrived<MediaFrameReader, MediaFrameArrivedEventArgs>public event TypedEventHandler FrameArrived<MediaFrameReader, MediaFrameArrivedEventArgs>Public Event FrameArrived<MediaFrameReader, MediaFrameArrivedEventArgs>// You can use this event in JavaScript.
Remarks
In the handler for the FrameArrived event, call TryAcquireLatestFrame to get a MediaFrameReference representing the latest frame from the media frame source.