#ifndef _GF_HTMLMSE_H_
#define _GF_HTMLMSE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <gpac/setup.h>
#include <gpac/html5_media.h>
#include <gpac/internal/smjs_api.h>
typedef enum
{
MEDIA_SOURCE_READYSTATE_CLOSED = 0,
MEDIA_SOURCE_READYSTATE_OPEN = 1,
MEDIA_SOURCE_READYSTATE_ENDED = 2,
} GF_HTML_MediaSource_ReadyState;
typedef enum
{
MEDIA_SOURCE_APPEND_MODE_SEGMENTS = 0,
MEDIA_SOURCE_APPEND_MODE_SEQUENCE = 1
} GF_HTML_MediaSource_AppendMode;
typedef enum
{
MEDIA_SOURCE_APPEND_STATE_WAITING_FOR_SEGMENT = 0,
MEDIA_SOURCE_APPEND_STATE_PARSING_INIT_SEGMENT = 1,
MEDIA_SOURCE_APPEND_STATE_PARSING_MEDIA_SEGMENT = 2
} GF_HTML_MediaSource_AppendState;
typedef struct
{
struct _html_mediasource *mediasource;
JSObject *_this;
Bool updating;
GF_HTML_MediaTimeRanges *buffered;
s64 timestampOffset;
double appendWindowStart;
double appendWindowEnd;
u32 timescale;
GF_HTML_MediaSource_AppendState append_state;
Bool buffer_full_flag;
GF_HTML_MediaSource_AppendMode append_mode;
u64 group_start_timestamp;
Bool group_start_timestamp_flag;
u64 group_end_timestamp;
Bool group_end_timestamp_set;
Bool first_init_segment;
u64 remove_start;
u64 remove_end;
GF_List *tracks;
GF_List *input_buffer;
void *prev_buffer;
GF_InputService *parser;
GF_ObjectDescriptor *service_desc;
Bool parser_connected;
GF_List *threads;
GF_Thread *parser_thread;
GF_Thread *remove_thread;
GF_DOMEventTarget *evt_target;
} GF_HTML_SourceBuffer;
typedef struct
{
JSObject *_this;
GF_List *list;
struct _html_mediasource *parent;
#ifndef GPAC_DISABLE_SVG
GF_DOMEventTarget *evt_target;
#endif
} GF_HTML_SourceBufferList;
typedef enum
{
DURATION_NAN = 0,
DURATION_INFINITY = 1,
DURATION_VALUE = 2
} GF_HTML_MediaSource_DurationType;
typedef struct _html_mediasource
{
JSContext *c;
JSObject *_this;
u32 reference_count;
GF_HTML_SourceBufferList sourceBuffers;
GF_HTML_SourceBufferList activeSourceBuffers;
double duration;
GF_HTML_MediaSource_DurationType durationType;
u32 readyState;
char *blobURI;
GF_ClientService *service;
GF_SceneGraph *sg;
GF_Node *node;
#ifndef GPAC_DISABLE_SVG
GF_DOMEventTarget *evt_target;
#endif
} GF_HTML_MediaSource;
GF_HTML_MediaSource *gf_mse_media_source_new();
void gf_mse_mediasource_del(GF_HTML_MediaSource *ms, Bool del_js);
void gf_mse_mediasource_open(GF_HTML_MediaSource *ms, struct _mediaobj *mo);
void gf_mse_mediasource_close(GF_HTML_MediaSource *ms);
void gf_mse_mediasource_end(GF_HTML_MediaSource *ms);
void gf_mse_mediasource_add_source_buffer(GF_HTML_MediaSource *ms, GF_HTML_SourceBuffer *sb);
GF_HTML_SourceBuffer *gf_mse_source_buffer_new(GF_HTML_MediaSource *mediasource);
void gf_mse_source_buffer_set_timestampOffset(GF_HTML_SourceBuffer *sb, double d);
void gf_mse_source_buffer_set_timescale(GF_HTML_SourceBuffer *sb, u32 timescale);
GF_Err gf_mse_source_buffer_load_parser(GF_HTML_SourceBuffer *sourcebuffer, const char *mime);
GF_Err gf_mse_remove_source_buffer(GF_HTML_MediaSource *ms, GF_HTML_SourceBuffer *sb);
void gf_mse_source_buffer_del(GF_HTML_SourceBuffer *sb);
GF_Err gf_mse_source_buffer_abort(GF_HTML_SourceBuffer *sb);
void gf_mse_source_buffer_append_arraybuffer(GF_HTML_SourceBuffer *sb, GF_HTML_ArrayBuffer *buffer);
void gf_mse_source_buffer_update_buffered(GF_HTML_SourceBuffer *sb);
void gf_mse_remove(GF_HTML_SourceBuffer *sb, double start, double end);
typedef struct
{
char *data;
u32 size;
GF_SLHeader sl_header;
Bool is_compressed;
Bool is_new_data;
GF_Err status;
} GF_MSE_Packet;
GF_Err gf_mse_proxy(GF_InputService *parser, GF_NetworkCommand *command);
void gf_mse_packet_del(GF_MSE_Packet *packet);
GF_Err gf_mse_track_buffer_get_next_packet(GF_HTML_Track *track,
char **out_data_ptr, u32 *out_data_size,
GF_SLHeader *out_sl_hdr, Bool *sl_compressed,
GF_Err *out_reception_status, Bool *is_new_data);
GF_Err gf_mse_track_buffer_release_packet(GF_HTML_Track *track);
#ifdef __cplusplus
}
#endif
#endif