#ifndef _GF_HTMLMEDIA_H_
#define _GF_HTMLMEDIA_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <gpac/internal/scenegraph_dev.h>
#include <gpac/nodes_svg.h>
#include <gpac/events.h>
#include <gpac/utf.h>
#include <gpac/download.h>
#include <gpac/network.h>
#include <gpac/modules/service.h>
#include <gpac/xml.h>
#include <gpac/internal/terminal_dev.h>
#ifdef GPAC_HAS_SPIDERMONKEY
#include <gpac/internal/smjs_api.h>
#endif
typedef struct
{
u32 nb_inst;
GF_JSClass arrayBufferClass;
GF_JSClass htmlVideoElementClass;
GF_JSClass htmlAudioElementClass;
GF_JSClass htmlSourceElementClass;
GF_JSClass htmlTrackElementClass;
GF_JSClass htmlMediaElementClass;
GF_JSClass mediaControllerClass;
GF_JSClass audioTrackListClass;
GF_JSClass audioTrackClass;
GF_JSClass videoTrackListClass;
GF_JSClass videoTrackClass;
GF_JSClass textTrackListClass;
GF_JSClass textTrackClass;
GF_JSClass textTrackCueListClass;
GF_JSClass textTrackCueClass;
GF_JSClass timeRangesClass;
GF_JSClass trackEventClass;
GF_JSClass mediaErrorClass;
GF_JSClass mediaSourceClass;
GF_JSClass sourceBufferClass;
GF_JSClass sourceBufferListClass;
GF_JSClass URLClass;
GF_JSClass mediaStreamClass;
GF_JSClass localMediaStreamClass;
GF_JSClass mediaStreamTrackClass;
GF_JSClass mediaStreamTrackListClass;
GF_JSClass navigatorUserMediaClass;
GF_JSClass navigatorUserMediaErrorClass;
} GF_HTML_MediaRuntime;
typedef enum
{
MEDIA_ERR_ABORTED = 1,
MEDIA_ERR_NETWORK = 2,
MEDIA_ERR_DECODE = 3,
MEDIA_ERR_SRC_NOT_SUPPORTED = 4
} GF_HTML_MediaErrorCode;
typedef enum
{
NETWORK_EMPTY = 0,
NETWORK_IDLE = 1,
NETWORK_LOADING = 2,
NETWORK_NO_SOURCE = 3
} GF_HTML_NetworkState;
typedef enum
{
HAVE_NOTHING = 0,
HAVE_METADATA = 1,
HAVE_CURRENT_DATA = 2,
HAVE_FUTURE_DATA = 3,
HAVE_ENOUGH_DATA = 4
} GF_HTML_MediaReadyState;
typedef struct
{
JSContext *c;
JSObject *_this;
GF_HTML_MediaErrorCode code;
} GF_HTML_MediaError;
typedef struct _timerange
{
JSContext *c;
JSObject *_this;
GF_List *times;
u32 timescale;
} GF_HTML_MediaTimeRanges;
typedef enum {
HTML_MEDIA_TRACK_TYPE_UNKNOWN = 0,
HTML_MEDIA_TRACK_TYPE_AUDIO = 1,
HTML_MEDIA_TRACK_TYPE_VIDEO = 2,
HTML_MEDIA_TRACK_TYPE_TEXT = 3
} GF_HTML_TrackType;
#define BASE_HTML_TRACK \
\
JSContext *c;\
\
JSObject *_this;\
\
u32 bin_id; \
LPNETCHANNEL channel; \
GF_ObjectDescriptor *od; \
GF_List *buffer; \
u32 packet_index; \
GF_Mutex *buffer_mutex;\
Bool last_dts_set; \
u64 last_dts; \
u32 last_dur; \
Bool highest_pts_set; \
u64 highest_pts; \
Bool needs_rap; \
u32 timescale; \
s64 timestampOffset; \
\
GF_HTML_TrackType type;\
char *id;\
char *kind;\
char *label;\
char *language;\
char *mime; \
Bool enabled_or_selected;
typedef struct
{
BASE_HTML_TRACK
} GF_HTML_Track;
typedef struct
{
BASE_HTML_TRACK
JSFunction *oncuechange;
char *inBandMetadataTrackDispatchType;
} GF_HTML_TextTrack;
#define BASE_HTML_TRACK_LIST \
\
JSContext *c;\
\
JSObject *_this;\
GF_List *tracks; \
jsval onchange; \
jsval onaddtrack; \
jsval onremovetrack; \
u32 selected_index;
typedef struct
{
BASE_HTML_TRACK_LIST
} GF_HTML_TrackList;
typedef enum
{
MEDIA_CONTROLLER_WAITING = 0,
MEDIA_CONTROLLER_PLAYING = 1,
MEDIA_CONTROLLER_ENDED = 2
} GF_HTML_MediaControllerPlaybackState;
typedef struct
{
JSContext *c;
JSObject *_this;
GF_HTML_MediaTimeRanges *buffered;
GF_HTML_MediaTimeRanges *seekable;
GF_HTML_MediaTimeRanges *played;
Bool paused;
GF_HTML_MediaControllerPlaybackState playbackState;
double defaultPlaybackRate;
GF_List *media_elements;
} GF_HTML_MediaController;
typedef struct
{
JSContext *c;
JSObject *_this;
GF_Node *node;
GF_HTML_MediaError error;
char *currentSrc;
GF_HTML_MediaTimeRanges *buffered;
Bool seeking;
char *startDate;
Bool paused;
double defaultPlaybackRate;
GF_HTML_MediaTimeRanges *played;
GF_HTML_MediaTimeRanges *seekable;
GF_HTML_MediaController *controller;
GF_HTML_TrackList audioTracks;
GF_HTML_TrackList videoTracks;
GF_HTML_TrackList textTracks;
GF_DOMEventTarget *evt_target;
} GF_HTML_MediaElement;
typedef struct
{
JSContext *c;
JSObject *_this;
char *data;
u32 length;
char *url;
Bool is_init;
u32 reference_count;
} GF_HTML_ArrayBuffer;
GF_HTML_MediaTimeRanges *gf_html_timeranges_new(u32 timescale);
GF_Err gf_html_timeranges_add_start(GF_HTML_MediaTimeRanges *timeranges, u64 start);
GF_Err gf_html_timeranges_add_end(GF_HTML_MediaTimeRanges *timeranges, u64 end);
void gf_html_timeranges_reset(GF_HTML_MediaTimeRanges *range);
void gf_html_timeranges_del(GF_HTML_MediaTimeRanges *range);
GF_HTML_MediaTimeRanges *gf_html_timeranges_intersection(GF_HTML_MediaTimeRanges *a, GF_HTML_MediaTimeRanges *b);
GF_HTML_MediaTimeRanges *gf_html_timeranges_union(GF_HTML_MediaTimeRanges *a, GF_HTML_MediaTimeRanges *b);
GF_HTML_Track *html_media_add_new_track_to_list(GF_HTML_TrackList *tracklist,
GF_HTML_TrackType type, const char *mime, Bool enable_or_selected,
const char *id, const char *kind, const char *label, const char *lang);
Bool html_media_tracklist_has_track(GF_HTML_TrackList *tracklist, const char *id);
GF_HTML_Track *html_media_tracklist_get_track(GF_HTML_TrackList *tracklist, const char *id);
void gf_html_tracklist_del(GF_HTML_TrackList *tlist);
GF_HTML_Track *gf_html_media_track_new(GF_HTML_TrackType type, const char *mime, Bool enable_or_selected,
const char *id, const char *kind, const char *label, const char *lang);
void gf_html_track_del(GF_HTML_Track *track);
GF_HTML_MediaElement *gf_html_media_element_new(GF_Node *media_node, GF_HTML_MediaController *mc);
void gf_html_media_element_del(GF_HTML_MediaElement *me);
void html_media_element_js_init(JSContext *c, JSObject *new_obj, GF_Node *n);
GF_HTML_MediaController *gf_html_media_controller_new();
void gf_html_media_controller_del(GF_HTML_MediaController *mc);
GF_HTML_ArrayBuffer *gf_arraybuffer_new(char *data, u32 length);
JSObject *gf_arraybuffer_js_new(JSContext *c, char *data, u32 length, JSObject *parent);
void gf_arraybuffer_del(GF_HTML_ArrayBuffer *buffer, Bool del_js);
#ifdef __cplusplus
}
#endif
#endif