Skip to main content
Version: 21 Aug 2024

ml_media_data_source.h

Types

Name
typedef int64_t()(MLHandle media_data_source, size_t position, size_t size, uint8_t buffer, void *context)MLMediaDataSourceReadAt
Called to request data from the given position.
typedef int64_t()(MLHandle media_data_source, void context)MLMediaDataSourceGetSize
Called to get the size of the data source.
typedef void()(MLHandle media_data_source, void context)MLMediaDataSourceClose
Called before deleting

Functions

Name
MLResultMLMediaDataSourceCreate(MLMediaDataSourceReadAt read_at, MLMediaDataSourceGetSize get_size, MLMediaDataSourceClose close, void context, MLHandle out_handle)
Create a new MediaDataSource object.
MLResultMLMediaDataSourceDestroy(MLHandle media_data_source)
Destroy a #MediaDataSource object.

Types Documentation

MLMediaDataSourceReadAt

typedef int64_t(* MLMediaDataSourceReadAt) (MLHandle media_data_source, size_t position, size_t size, uint8_t *buffer, void *context);

Called to request data from the given position.

Parameters

media_data_sourceMLHandle as returned by MLMediaDataSourceCreate().
positionThe position in the data source to read from.
sizeThe number of bytes to read.
bufferThe buffer to read the data into.
contextUser data as passed to MLMediaDataSourceCreate().

Implementations should should write up to size bytes into buffer, and return the number of bytes written.

Return 0 to indicate that end of stream is reached. Return -1 on error.

Return: The number of bytes read, or -1 if there was an error.


MLMediaDataSourceGetSize

typedef int64_t(* MLMediaDataSourceGetSize) (MLHandle media_data_source, void *context);

Called to get the size of the data source.

Parameters

media_data_sourceMLHandle as returned by MLMediaDataSourceCreate().
contextUser data as passed to MLMediaDataSourceCreate().

Return: the size of data source in bytes, or -1 if the size is unknown.


MLMediaDataSourceClose

typedef void(* MLMediaDataSourceClose) (MLHandle media_data_source, void *context);

Called before deleting |this|. The other methods may return errors if they're called after calling close().

Parameters

media_data_sourceMLHandle as returned by MLMediaDataSourceCreate().
contextUser data as passed to MLMediaDataSourceCreate().

Functions Documentation

MLMediaDataSourceCreate

MLResult MLMediaDataSourceCreate(
MLMediaDataSourceReadAt read_at,
MLMediaDataSourceGetSize get_size,
MLMediaDataSourceClose close,
void * context,
MLHandle * out_handle
)

Create a new MediaDataSource object.

Parameters

MLMediaDataSourceReadAtread_atMLMediaDataSourceReadAt callback.
MLMediaDataSourceGetSizeget_sizeMLMediaDataSourceGetSize callback.
MLMediaDataSourceClosecloseMLMediaDataSourceClose 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.


MLMediaDataSourceDestroy

MLResult MLMediaDataSourceDestroy(
MLHandle media_data_source
)

Destroy a #MediaDataSource object.

Parameters

MLHandlemedia_data_sourceMLHandle to the #MediaDataSource 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.


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 int64_t (*MLMediaDataSourceReadAt) (MLHandle media_data_source, size_t position, size_t size, uint8_t *buffer, void *context);

typedef int64_t (*MLMediaDataSourceGetSize) (MLHandle media_data_source, void *context);

typedef void (*MLMediaDataSourceClose) (MLHandle media_data_source, void *context);

ML_DEPRECATED_MSG("Use standard Android SDK APIs.")
ML_API MLResult ML_CALL MLMediaDataSourceCreate(MLMediaDataSourceReadAt read_at, MLMediaDataSourceGetSize get_size, MLMediaDataSourceClose close, void *context, MLHandle *out_handle);

ML_DEPRECATED_MSG("Use standard Android SDK APIs.")
ML_API MLResult ML_CALL MLMediaDataSourceDestroy(MLHandle media_data_source);

ML_EXTERN_C_END