This source file includes following definitions.
- FM_FAKE_PULL_CanHandleURL
- get_esd
- FM_FAKE_PULL_GetOD
- ext_media_load_th
- FM_FAKE_PULL_Connect
- FM_FAKE_PULL_Disconnect
- FM_FAKE_PULL_GetData
- FM_FAKE_PULL_ReleaseData
#include <gpac/thread.h>
#include "hyb_in.h"
#define EXT_MEDIA_LOAD_THREADED
#define FM_FAKE_PULL_AUDIO_FREQ 44100
#define FM_FAKE_PULL_CHAN_NUM 2
#define FM_FAKE_PULL_BITS 16
#define FM_FAKE_PULL_TYPE s16
#define FM_FAKE_PULL_FRAME_DUR 60
#define FM_FAKE_PULL_FRAME_LEN ((FM_FAKE_PULL_FRAME_DUR*FM_FAKE_PULL_CHAN_NUM*FM_FAKE_PULL_BITS*FM_FAKE_PULL_AUDIO_FREQ)/(1000*8))
typedef struct s_FM_FAKE_PULL {
u64 PTS;
unsigned char buffer10[FM_FAKE_PULL_FRAME_LEN];
unsigned char buffer90[FM_FAKE_PULL_FRAME_LEN];
#ifdef EXT_MEDIA_LOAD_THREADED
GF_Thread *media_th;
#endif
} FM_FAKE_PULL;
FM_FAKE_PULL FM_FAKE_PULL_private_data;
static Bool FM_FAKE_PULL_CanHandleURL(const char *url);
static GF_ObjectDescriptor* FM_FAKE_PULL_GetOD(void);
static GF_Err FM_FAKE_PULL_Connect(GF_HYBMEDIA *self, GF_ClientService *service, const char *url);
static GF_Err FM_FAKE_PULL_Disconnect(GF_HYBMEDIA *self);
static GF_Err FM_FAKE_PULL_GetData(GF_HYBMEDIA *self, char **out_data_ptr, u32 *out_data_size, GF_SLHeader *out_sl_hdr);
static GF_Err FM_FAKE_PULL_ReleaseData(GF_HYBMEDIA *self);
GF_HYBMEDIA master_fm_fake_pull = {
"Fake FM (pull mode)",
FM_FAKE_PULL_CanHandleURL,
FM_FAKE_PULL_GetOD,
FM_FAKE_PULL_Connect,
FM_FAKE_PULL_Disconnect,
NULL,
FM_FAKE_PULL_GetData,
FM_FAKE_PULL_ReleaseData,
HYB_PULL,
&FM_FAKE_PULL_private_data
};
static Bool FM_FAKE_PULL_CanHandleURL(const char *url)
{
if (!strnicmp(url, "fm://fake_pull", 14))
return 1;
return 0;
}
static GF_ESD* get_esd()
{
GF_BitStream *dsi = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
GF_ESD *esd = gf_odf_desc_esd_new(0);
esd->ESID = 1;
esd->decoderConfig->streamType = GF_STREAM_AUDIO;
esd->decoderConfig->objectTypeIndication = GPAC_OTI_RAW_MEDIA_STREAM;
esd->decoderConfig->avgBitrate = esd->decoderConfig->maxBitrate = 0;
esd->slConfig->timestampResolution = FM_FAKE_PULL_AUDIO_FREQ;
gf_bs_write_u32(dsi, FM_FAKE_PULL_AUDIO_FREQ);
gf_bs_write_u16(dsi, FM_FAKE_PULL_CHAN_NUM);
gf_bs_write_u16(dsi, FM_FAKE_PULL_BITS);
gf_bs_write_u32(dsi, FM_FAKE_PULL_FRAME_LEN);
gf_bs_write_u32(dsi, 0);
gf_bs_get_content(dsi, &esd->decoderConfig->decoderSpecificInfo->data, &esd->decoderConfig->decoderSpecificInfo->dataLength);
gf_bs_del(dsi);
return esd;
}
static GF_ObjectDescriptor* FM_FAKE_PULL_GetOD(void)
{
GF_ObjectDescriptor *od = (GF_ObjectDescriptor*)gf_odf_desc_new(GF_ODF_OD_TAG);
GF_ESD *esd = get_esd();
od->objectDescriptorID = 1;
gf_list_add(od->ESDescriptors, esd);
return od;
}
static u32 ext_media_load_th(void *par) {
GF_HYBMEDIA *self = (GF_HYBMEDIA*) par;
GF_ObjectDescriptor *od = (GF_ObjectDescriptor*)gf_odf_desc_new(GF_ODF_OD_TAG);
od->URLString = gf_strdup("http://gpac.sourceforge.net/screenshots/lion.jpg");
od->objectDescriptorID = 0;
gf_sleep(2000);
gf_service_declare_media(self->owner, (GF_Descriptor*)od, 0);
return 0;
}
static GF_Err FM_FAKE_PULL_Connect(GF_HYBMEDIA *self, GF_ClientService *service, const char *url)
{
u32 i;
if (!self)
return GF_BAD_PARAM;
if (!service)
return GF_BAD_PARAM;
self->owner = service;
assert(self->private_data);
memset(self->private_data, 0, sizeof(FM_FAKE_PULL));
for (i=0; i<(FM_FAKE_PULL_FRAME_LEN*8)/FM_FAKE_PULL_BITS; i++) {
if (((2*i)/(FM_FAKE_PULL_CHAN_NUM*100))%2)
*((FM_FAKE_PULL_TYPE*)((FM_FAKE_PULL*)self->private_data)->buffer10+i) = 1 << (FM_FAKE_PULL_BITS-1);
}
if (1) {
#ifdef EXT_MEDIA_LOAD_THREADED
GF_Thread **th = &((FM_FAKE_PULL*)self->private_data)->media_th;
assert(*th == NULL);
*th = gf_th_new("HYB-FM fake external media load thread");
gf_th_run(*th, ext_media_load_th, self);
#else
ext_media_load_th(self);
#endif
}
return GF_OK;
}
static GF_Err FM_FAKE_PULL_Disconnect(GF_HYBMEDIA *self)
{
FM_FAKE_PULL *priv = (FM_FAKE_PULL*)self->private_data;
self->owner = NULL;
#ifdef EXT_MEDIA_LOAD_THREADED
gf_th_del(priv->media_th);
#endif
return GF_OK;
}
static GF_Err FM_FAKE_PULL_GetData(GF_HYBMEDIA *self, char **out_data_ptr, u32 *out_data_size, GF_SLHeader *out_sl_hdr)
{
u64 delta_pts = (FM_FAKE_PULL_FRAME_DUR*FM_FAKE_PULL_AUDIO_FREQ)/1000;
assert(!(FM_FAKE_PULL_FRAME_DUR*FM_FAKE_PULL_AUDIO_FREQ%1000));
memset(out_sl_hdr, 0, sizeof(GF_SLHeader));
out_sl_hdr->compositionTimeStampFlag = 1;
out_sl_hdr->compositionTimeStamp = ((FM_FAKE_PULL*)self->private_data)->PTS;
out_sl_hdr->accessUnitStartFlag = 1;
if ((((FM_FAKE_PULL*)self->private_data)->PTS%(10*delta_pts))) {
*out_data_ptr = ((FM_FAKE_PULL*)self->private_data)->buffer90;
} else {
*out_data_ptr = ((FM_FAKE_PULL*)self->private_data)->buffer10;
}
*out_data_size = FM_FAKE_PULL_FRAME_LEN;
((FM_FAKE_PULL*)self->private_data)->PTS += delta_pts;
return GF_OK;
}
static GF_Err FM_FAKE_PULL_ReleaseData(GF_HYBMEDIA *self)
{
return GF_OK;
}