Skip to main content
Version: 21 Aug 2024

ml_media_stream_source.h

Types

Name
typedef void()(MLHandle media_stream_source, void context)MLMediaStreamSourceOnBufferAvailable
Called when buffers becomes available.

Functions

Name
MLResultMLMediaStreamSourceCreate(MLMediaStreamSourceOnBufferAvailable on_buffer_available, void context, MLHandle out_handle)
Create a new MediaStreamSource object.
MLResultMLMediaStreamSourceDestroy(MLHandle media_stream_source)
Destroy a MediaStreamSource object.
MLResultMLMediaStreamSourceGetBuffer(MLHandle media_stream_source, size_t out_id, uint8_t ** out_ptr, size_t out_size)
Get a buffer where data can be written.
MLResultMLMediaStreamSourcePushBuffer(MLHandle media_stream_source, size_t id, size_t size)
Push a buffer.
MLResultMLMediaStreamSourcePushEOS(MLHandle media_stream_source)
Push End-Of-Stream event.

Types Documentation

MLMediaStreamSourceOnBufferAvailable

typedef void(* MLMediaStreamSourceOnBufferAvailable) (MLHandle media_stream_source, void *context);

Called when buffers becomes available.

Parameters

media_stream_sourceMLHandle as returned by MLMediaStreamSourceCreate().
contextUser data as passed to MLMediaStreamSourceCreate().

Signal that at least one buffer is now available. Application should then call getBuffer() as much as possible until it returns false, or until no more data is currently available in the application.


Functions Documentation

MLMediaStreamSourceCreate

MLResult MLMediaStreamSourceCreate(
MLMediaStreamSourceOnBufferAvailable on_buffer_available,
void * context,
MLHandle * out_handle
)

Create a new MediaStreamSource object.

Parameters

MLMediaStreamSourceOnBufferAvailableon_buffer_availableMLMediaStreamSourceOnBufferAvailable callback.
void *contextUser data to be passed to callbacks.
MLHandle *out_handleThe MLHandle to the new source object created. Only valid if result is MLResult_Ok.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkIf operation was successful.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None
Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaStreamSourceDestroy

MLResult MLMediaStreamSourceDestroy(
MLHandle media_stream_source
)

Destroy a MediaStreamSource object.

Parameters

MLHandlemedia_stream_sourceMLHandle to the MediaStreamSource object to destroy.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkIf operation was successful.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None
Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaStreamSourceGetBuffer

MLResult MLMediaStreamSourceGetBuffer(
MLHandle media_stream_source,
size_t * out_id,
uint8_t ** out_ptr,
size_t * out_size
)

Get a buffer where data can be written.

Parameters

MLHandlemedia_stream_sourceMLHandle as returned by MLMediaStreamSourceCreate().
size_t *out_idAn opaque ID that should be passed to MLMediaStreamSourcePushBuffer().
uint8_t **out_ptrThe location where to write data.
size_t *out_sizeMaximum bytes that can be written in out_ptr.

Returns

MLResultMLResult_OkIf operation was successful.
MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

If a buffer is available, true is returned and out_id, out_ptr and out_size are set. Application can then write up to out_size bytes into out_ptr and push that data using MLMediaStreamSourcePushBuffer().

If no buffer is available, false is returned and application should wait for MLMediaStreamSourceOnBufferAvailable() to be called before retrying.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaStreamSourcePushBuffer

MLResult MLMediaStreamSourcePushBuffer(
MLHandle media_stream_source,
size_t id,
size_t size
)

Push a buffer.

Parameters

MLHandlemedia_stream_sourceMLHandle as returned by MLMediaStreamSourceCreate().
size_tidThe ID of the buffer as given by MLMediaStreamSourceGetBuffer().
size_tsizeThe number of bytes actually written in the buffer.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkIf operation was successful.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

Queue a buffer acquired from MLMediaStreamSourceGetBuffer() once data has been written.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaStreamSourcePushEOS

MLResult MLMediaStreamSourcePushEOS(
MLHandle media_stream_source
)

Push End-Of-Stream event.

Parameters

MLHandlemedia_stream_sourceMLHandle as returned by MLMediaStreamSourceCreate().

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkIf operation was successful.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

Signal that the end of stream is reached and no more data will be pushed.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.


Source code

// %BANNER_BEGIN%
// ---------------------------------------------------------------------
// %COPYRIGHT_BEGIN%
// Copyright (c) 2017 Magic Leap, Inc. All Rights Reserved.
// Use of this file is governed by the Software License Agreement,
// located here: https://www.magicleap.com/software-license-agreement-ml2
// Terms and conditions applicable to third-party materials accompanying
// this distribution may also be found in the top-level NOTICE file
// appearing herein.
// %COPYRIGHT_END%
// ---------------------------------------------------------------------
// %BANNER_END%

#pragma once

#include "ml_api.h"
#include "ml_types.h"

ML_EXTERN_C_BEGIN

typedef void (*MLMediaStreamSourceOnBufferAvailable) (MLHandle media_stream_source, void *context);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaStreamSourceCreate(MLMediaStreamSourceOnBufferAvailable on_buffer_available, void *context, MLHandle *out_handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaStreamSourceDestroy(MLHandle media_stream_source);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaStreamSourceGetBuffer(MLHandle media_stream_source, size_t *out_id, uint8_t **out_ptr, size_t *out_size);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaStreamSourcePushBuffer(MLHandle media_stream_source, size_t id, size_t size);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaStreamSourcePushEOS(MLHandle media_stream_source);

ML_EXTERN_C_END