repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
SBEMU | github_2023 | crazii | c | snd_trident_spdif_default_info | static int snd_trident_spdif_default_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
uinfo->count = 1;
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_spdif_default
Description: put/get the S/PDIF default settings
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2469-L2475 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_spdif_mask_info | static int snd_trident_spdif_mask_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
uinfo->count = 1;
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_spdif_mask
Description: put/get the S/PDIF mask
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2531-L2537 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_spdif_stream_info | static int snd_trident_spdif_stream_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
uinfo->count = 1;
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_spdif_stream
Description: put/get the S/PDIF stream settings
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2564-L2570 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_vol_control_info | static int snd_trident_vol_control_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 2;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 255;
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_vol_control
Description: wave & music volume control
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2677-L2685 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_pcm_vol_control_info | static int snd_trident_pcm_vol_control_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
struct snd_trident *trident = snd_kcontrol_chip(kcontrol);
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 255;
if (trident->device == TRIDENT_DEVICE_ID_SI7018)
uinfo->value.integer.max = 1023;
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_pcm_vol_control
Description: PCM front volume control
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2747-L2759 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_pcm_pan_control_info | static int snd_trident_pcm_pan_control_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 127;
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_pcm_pan_control
Description: PCM front pan control
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2815-L2823 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_pcm_rvol_control_info | static int snd_trident_pcm_rvol_control_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 127;
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_pcm_rvol_control
Description: PCM reverb volume control
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2878-L2886 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_pcm_cvol_control_info | static int snd_trident_pcm_cvol_control_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 127;
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_pcm_cvol_control
Description: PCM chorus volume control
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2936-L2944 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_mixer | static int snd_trident_mixer(struct snd_trident *trident, int pcm_spdif_device)
{
struct snd_ac97_template _ac97;
struct snd_card *card = trident->card;
struct snd_kcontrol *kctl;
#if 0
struct snd_ctl_elem_value *uctl;
#endif
int idx, err, retries = 2;
#if 0
static struct snd_ac97_bus_ops ops = {
.write = snd_trident_codec_write,
.read = snd_trident_codec_read,
};
uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
if (!uctl)
return -ENOMEM;
if ((err = snd_ac97_bus(trident->card, 0, &ops, NULL, &trident->ac97_bus)) < 0)
goto __out;
memset(&_ac97, 0, sizeof(_ac97));
_ac97.private_data = trident;
trident->ac97_detect = 1;
__again:
if ((err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97)) < 0) {
if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
if ((err = snd_trident_sis_reset(trident)) < 0)
goto __out;
if (retries-- > 0)
goto __again;
err = -EIO;
}
goto __out;
}
/* secondary codec? */
if (trident->device == TRIDENT_DEVICE_ID_SI7018 &&
(inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_PRIMARY_READY) != 0) {
_ac97.num = 1;
err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec);
if (err < 0)
dev_err(trident->card->dev,
"SI7018: the secondary codec - invalid access\n");
#if 0 // only for my testing purpose --jk
{
struct snd_ac97 *mc97;
err = snd_ac97_modem(trident->card, &_ac97, &mc97);
if (err < 0)
dev_err(trident->card->dev,
"snd_ac97_modem returned error %i\n", err);
}
#endif
}
#endif
trident->ac97_detect = 0;
if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
#if 0
if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_vol_wave_control, trident))) < 0)
goto __out;
kctl->put(kctl, uctl);
if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_vol_music_control, trident))) < 0)
goto __out;
kctl->put(kctl, uctl);
#endif
outl(trident->musicvol_wavevol = 0x00000000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
} else {
outl(trident->musicvol_wavevol = 0xffff0000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
}
for (idx = 0; idx < 32; idx++) {
struct snd_trident_pcm_mixer *tmix;
tmix = &trident->pcm_mixer[idx];
tmix->voice = NULL;
}
#if 0
if ((trident->ctl_vol = snd_ctl_new1(&snd_trident_pcm_vol_control, trident)) == NULL)
goto __nomem;
if ((err = snd_ctl_add(card, trident->ctl_vol)))
goto __out;
if ((trident->ctl_pan = snd_ctl_new1(&snd_trident_pcm_pan_control, trident)) == NULL)
goto __nomem;
if ((err = snd_ctl_add(card, trident->ctl_pan)))
goto __out;
if ((trident->ctl_rvol = snd_ctl_new1(&snd_trident_pcm_rvol_control, trident)) == NULL)
goto __nomem;
if ((err = snd_ctl_add(card, trident->ctl_rvol)))
goto __out;
if ((trident->ctl_cvol = snd_ctl_new1(&snd_trident_pcm_cvol_control, trident)) == NULL)
goto __nomem;
if ((err = snd_ctl_add(card, trident->ctl_cvol)))
goto __out;
if (trident->device == TRIDENT_DEVICE_ID_NX) {
if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_ac97_rear_control, trident))) < 0)
goto __out;
kctl->put(kctl, uctl);
}
if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) {
kctl = snd_ctl_new1(&snd_trident_spdif_control, trident);
if (kctl == NULL) {
err = -ENOMEM;
goto __out;
}
if (trident->ac97->ext_id & AC97_EI_SPDIF)
kctl->id.index++;
if (trident->ac97_sec && (trident->ac97_sec->ext_id & AC97_EI_SPDIF))
kctl->id.index++;
idx = kctl->id.index;
if ((err = snd_ctl_add(card, kctl)) < 0)
goto __out;
kctl->put(kctl, uctl);
kctl = snd_ctl_new1(&snd_trident_spdif_default, trident);
if (kctl == NULL) {
err = -ENOMEM;
goto __out;
}
kctl->id.index = idx;
kctl->id.device = pcm_spdif_device;
if ((err = snd_ctl_add(card, kctl)) < 0)
goto __out;
kctl = snd_ctl_new1(&snd_trident_spdif_mask, trident);
if (kctl == NULL) {
err = -ENOMEM;
goto __out;
}
kctl->id.index = idx;
kctl->id.device = pcm_spdif_device;
if ((err = snd_ctl_add(card, kctl)) < 0)
goto __out;
kctl = snd_ctl_new1(&snd_trident_spdif_stream, trident);
if (kctl == NULL) {
err = -ENOMEM;
goto __out;
}
kctl->id.index = idx;
kctl->id.device = pcm_spdif_device;
if ((err = snd_ctl_add(card, kctl)) < 0)
goto __out;
trident->spdif_pcm_ctl = kctl;
}
#endif
snd_trident_ac97_init(trident);
err = 0;
goto __out;
__nomem:
err = -ENOMEM;
__out:
#if 0
kfree(uctl);
#endif
return err;
} | /*---------------------------------------------------------------------------
snd_trident_mixer
Description: This routine registers the 4DWave device for mixer support.
Parameters: trident - pointer to target device class for 4DWave.
Returns: None
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3056-L3225 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | do_delay | static inline void do_delay(struct snd_trident *chip)
{
//schedule_timeout_uninterruptible(1);
udelay(1);
} | /* CONFIG_GAMEPORT */
/*
* delay for 1 tick
*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3331-L3335 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_sis_reset | static int snd_trident_sis_reset(struct snd_trident *trident)
{
unsigned long end_time;
unsigned int i;
int r;
r = trident->in_suspend ? 0 : 2; /* count of retries */
__si7018_retry:
pci_write_config_byte(trident->pci, 0x46, 0x04); /* SOFTWARE RESET */
udelay(100);
pci_write_config_byte(trident->pci, 0x46, 0x00);
udelay(100);
/* disable AC97 GPIO interrupt */
outb(0x00, TRID_REG(trident, SI_AC97_GPIO));
/* initialize serial interface, force cold reset */
i = PCMOUT|SURROUT|CENTEROUT|LFEOUT|SECONDARY_ID|COLD_RESET;
outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
udelay(1000);
/* remove cold reset */
i &= ~COLD_RESET;
outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
udelay(2000);
/* wait, until the codec is ready */
end_time = (jiffies + (HZ * 3) / 4) + 1;
do {
if ((inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_PRIMARY_READY) != 0)
goto __si7018_ok;
do_delay(trident);
} while (time_after_eq(end_time, jiffies));
dev_err(trident->card->dev, "AC'97 codec ready error [0x%x]\n",
inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)));
if (r-- > 0) {
end_time = jiffies + HZ;
do {
do_delay(trident);
} while (time_after_eq(end_time, jiffies));
goto __si7018_retry;
}
__si7018_ok:
/* wait for the second codec */
do {
if ((inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_SECONDARY_READY) != 0)
break;
do_delay(trident);
} while (time_after_eq(end_time, jiffies));
/* enable 64 channel mode */
outl(BANK_B_EN, TRID_REG(trident, T4D_LFO_GC_CIR));
return 0;
} | /*
* SiS reset routine
*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3341-L3389 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_proc_read | static void snd_trident_proc_read(struct snd_info_entry *entry,
struct snd_info_buffer *buffer)
{
struct snd_trident *trident = entry->private_data;
char *s;
switch (trident->device) {
case TRIDENT_DEVICE_ID_SI7018:
s = "SiS 7018 Audio";
break;
case TRIDENT_DEVICE_ID_DX:
s = "Trident 4DWave PCI DX";
break;
case TRIDENT_DEVICE_ID_NX:
s = "Trident 4DWave PCI NX";
break;
default:
s = "???";
}
snd_iprintf(buffer, "%s\n\n", s);
snd_iprintf(buffer, "Spurious IRQs : %d\n", trident->spurious_irq_count);
snd_iprintf(buffer, "Spurious IRQ dlta: %d\n", trident->spurious_irq_max_delta);
if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018)
snd_iprintf(buffer, "IEC958 Mixer Out : %s\n", trident->spdif_ctrl == 0x28 ? "on" : "off");
if (trident->device == TRIDENT_DEVICE_ID_NX) {
snd_iprintf(buffer, "Rear Speakers : %s\n", trident->ac97_ctrl & 0x00000010 ? "on" : "off");
if (trident->tlb.entries) {
snd_iprintf(buffer,"\nVirtual Memory\n");
snd_iprintf(buffer, "Memory Maximum : %d\n", trident->tlb.memhdr->size);
snd_iprintf(buffer, "Memory Used : %d\n", trident->tlb.memhdr->used);
snd_iprintf(buffer, "Memory Free : %d\n", snd_util_mem_avail(trident->tlb.memhdr));
}
}
} | /*
* /proc interface
*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3396-L3429 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_tlb_alloc | static int snd_trident_tlb_alloc(struct snd_trident *trident)
{
int i;
/* TLB array must be aligned to 16kB !!! so we allocate
32kB region and correct offset when necessary */
if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci),
2 * SNDRV_TRIDENT_MAX_PAGES * 4, &trident->tlb.buffer) < 0) {
dev_err(trident->card->dev, "unable to allocate TLB buffer\n");
return -ENOMEM;
}
trident->tlb.entries = (unsigned int*)ALIGN((unsigned long)trident->tlb.buffer.area, SNDRV_TRIDENT_MAX_PAGES * 4);
trident->tlb.entries_dmaaddr = ALIGN(trident->tlb.buffer.addr, SNDRV_TRIDENT_MAX_PAGES * 4);
/* allocate shadow TLB page table (virtual addresses) */
trident->tlb.shadow_entries = vmalloc(SNDRV_TRIDENT_MAX_PAGES*sizeof(unsigned long));
if (trident->tlb.shadow_entries == NULL) {
dev_err(trident->card->dev,
"unable to allocate shadow TLB entries\n");
return -ENOMEM;
}
/* allocate and setup silent page and initialise TLB entries */
if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci),
SNDRV_TRIDENT_PAGE_SIZE, &trident->tlb.silent_page) < 0) {
dev_err(trident->card->dev, "unable to allocate silent page\n");
return -ENOMEM;
}
memset(trident->tlb.silent_page.area, 0, SNDRV_TRIDENT_PAGE_SIZE);
for (i = 0; i < SNDRV_TRIDENT_MAX_PAGES; i++) {
trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page.addr & ~(SNDRV_TRIDENT_PAGE_SIZE-1));
trident->tlb.shadow_entries[i] = (unsigned long)trident->tlb.silent_page.area;
}
/* use emu memory block manager code to manage tlb page allocation */
trident->tlb.memhdr = snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE * SNDRV_TRIDENT_MAX_PAGES);
if (trident->tlb.memhdr == NULL)
return -ENOMEM;
trident->tlb.memhdr->block_extra_size = sizeof(struct snd_trident_memblk_arg);
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_tlb_alloc
Description: Allocate and set up the TLB page table on 4D NX.
Each entry has 4 bytes (physical PCI address).
Parameters: trident - pointer to target device class for 4DWave.
Returns: 0 or negative error code
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3461-L3501 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_stop_all_voices | static void snd_trident_stop_all_voices(struct snd_trident *trident)
{
outl(0xffffffff, TRID_REG(trident, T4D_STOP_A));
outl(0xffffffff, TRID_REG(trident, T4D_STOP_B));
outl(0, TRID_REG(trident, T4D_AINTEN_A));
outl(0, TRID_REG(trident, T4D_AINTEN_B));
} | /*
* initialize 4D DX chip
*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3507-L3513 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_4d_nx_init | static int snd_trident_4d_nx_init(struct snd_trident *trident)
{
struct pci_dev *pci = trident->pci;
unsigned long end_time;
/* reset the legacy configuration and whole audio/wavetable block */
pci_write_config_dword(pci, 0x40, 0); /* DDMA */
pci_write_config_byte(pci, 0x44, 0); /* ports */
pci_write_config_byte(pci, 0x45, 0); /* Legacy DMA */
pci_write_config_byte(pci, 0x46, 1); /* reset */
udelay(100);
pci_write_config_byte(pci, 0x46, 0); /* release reset */
udelay(100);
/* warm reset of the AC'97 codec */
outl(0x00000001, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
udelay(100);
outl(0x00000000, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
/* wait, until the codec is ready */
end_time = (jiffies + (HZ * 3) / 4) + 1;
do {
if ((inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT)) & 0x0008) != 0)
goto __nx_ok;
do_delay(trident);
} while (time_after_eq(end_time, jiffies));
dev_err(trident->card->dev, "AC'97 codec ready error [0x%x]\n",
inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT)));
return -EIO;
__nx_ok:
/* DAC on */
trident->ac97_ctrl = 0x00000002;
outl(trident->ac97_ctrl, TRID_REG(trident, NX_ACR0_AC97_COM_STAT));
/* disable SB IRQ */
outl(NX_SB_IRQ_DISABLE, TRID_REG(trident, T4D_MISCINT));
snd_trident_stop_all_voices(trident);
if (trident->tlb.entries != NULL) {
unsigned int i;
/* enable virtual addressing via TLB */
i = trident->tlb.entries_dmaaddr;
i |= 0x00000001;
outl(i, TRID_REG(trident, NX_TLBC));
} else {
outl(0, TRID_REG(trident, NX_TLBC));
}
/* initialize S/PDIF */
outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
return 0;
} | /*
* initialize 4D NX chip
*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3555-L3608 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_sis_init | static int snd_trident_sis_init(struct snd_trident *trident)
{
int err;
if ((err = snd_trident_sis_reset(trident)) < 0)
return err;
snd_trident_stop_all_voices(trident);
/* initialize S/PDIF */
outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
return 0;
} | /*
* initialize sis7018 chip
*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3613-L3626 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_create | int snd_trident_create(struct snd_card *card,
struct pci_dev *pci,
int pcm_streams,
int pcm_spdif_device,
int max_wavetable_size,
struct snd_trident ** rtrident)
{
struct snd_trident *trident;
int i, err;
struct snd_trident_voice *voice;
struct snd_trident_pcm_mixer *tmix;
static struct snd_device_ops ops = {
.dev_free = snd_trident_dev_free,
};
*rtrident = NULL;
/* enable PCI device */
if ((err = pci_enable_device(pci)) < 0)
return err;
/* check, if we can restrict PCI DMA transfers to 30 bits */
if (dma_set_mask(&pci->dev, DMA_BIT_MASK(30)) < 0 ||
dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(30)) < 0) {
dev_err(card->dev,
"architecture does not support 30bit PCI busmaster DMA\n");
pci_disable_device(pci);
return -ENXIO;
}
trident = kzalloc(sizeof(*trident), GFP_KERNEL);
if (trident == NULL) {
pci_disable_device(pci);
return -ENOMEM;
}
trident->device = (pci->vendor << 16) | pci->device;
trident->card = card;
trident->pci = pci;
spin_lock_init(&trident->reg_lock);
spin_lock_init(&trident->event_lock);
spin_lock_init(&trident->voice_alloc);
if (pcm_streams < 1)
pcm_streams = 1;
if (pcm_streams > 32)
pcm_streams = 32;
trident->ChanPCM = pcm_streams;
if (max_wavetable_size < 0 )
max_wavetable_size = 0;
trident->synth.max_size = max_wavetable_size * 1024;
trident->irq = -1;
pci_set_master(pci);
if ((err = pci_request_regions(pci, "Trident Audio")) < 0) {
kfree(trident);
pci_disable_device(pci);
return err;
}
trident->port = pci_resource_start(pci, 0);
trident->midi_port = TRID_REG(trident, T4D_MPU401_BASE);
#if 0
if (request_irq(pci->irq, snd_trident_interrupt, IRQF_SHARED,
KBUILD_MODNAME, trident)) {
dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
snd_trident_free(trident);
return -EBUSY;
}
#endif
trident->irq = pci->irq;
/* allocate 16k-aligned TLB for NX cards */
trident->tlb.entries = NULL;
trident->tlb.buffer.area = NULL;
if (trident->device == TRIDENT_DEVICE_ID_NX) {
if ((err = snd_trident_tlb_alloc(trident)) < 0) {
snd_trident_free(trident);
return err;
}
}
trident->spdif_bits = trident->spdif_pcm_bits = SNDRV_PCM_DEFAULT_CON_SPDIF;
/* initialize chip */
switch (trident->device) {
case TRIDENT_DEVICE_ID_DX:
err = snd_trident_4d_dx_init(trident);
break;
case TRIDENT_DEVICE_ID_NX:
err = snd_trident_4d_nx_init(trident);
break;
case TRIDENT_DEVICE_ID_SI7018:
err = snd_trident_sis_init(trident);
break;
default:
snd_BUG();
break;
}
if (err < 0) {
snd_trident_free(trident);
return err;
}
#if 0
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, trident, &ops)) < 0) {
snd_trident_free(trident);
return err;
}
#endif
if ((err = snd_trident_mixer(trident, pcm_spdif_device)) < 0)
return err;
/* initialise synth voices */
for (i = 0; i < 64; i++) {
voice = &trident->synth.voices[i];
voice->number = i;
voice->trident = trident;
}
/* initialize pcm mixer entries */
for (i = 0; i < 32; i++) {
tmix = &trident->pcm_mixer[i];
tmix->vol = T4D_DEFAULT_PCM_VOL;
tmix->pan = T4D_DEFAULT_PCM_PAN;
tmix->rvol = T4D_DEFAULT_PCM_RVOL;
tmix->cvol = T4D_DEFAULT_PCM_CVOL;
}
snd_trident_enable_eso(trident);
#if 0
// Legacy ports
pci_write_config_byte(pci, 0x44, 3 << 2); // Adlib at 0x38C
pci_write_config_byte(pci, 0x44, 3 << 6); // MPU-401 at 0x300
#endif
#if 0
snd_trident_proc_init(trident);
#endif
*rtrident = trident;
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_create
Description: This routine will create the device specific class for
the 4DWave card. It will also perform basic initialization.
Parameters: card - which card to create
pci - interface to PCI bus resource info
dma1ptr - playback dma buffer
dma2ptr - capture dma buffer
irqptr - interrupt resource info
Returns: 4DWave device class private data
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3666-L3806 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_free | int snd_trident_free(struct snd_trident *trident)
{
snd_trident_free_gameport(trident);
snd_trident_disable_eso(trident);
// Disable S/PDIF out
if (trident->device == TRIDENT_DEVICE_ID_NX)
outb(0x00, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
}
if (trident->irq >= 0)
free_irq(trident->irq, trident);
if (trident->tlb.buffer.area) {
outl(0, TRID_REG(trident, NX_TLBC));
snd_util_memhdr_free(trident->tlb.memhdr);
if (trident->tlb.silent_page.area)
snd_dma_free_pages(&trident->tlb.silent_page);
vfree(trident->tlb.shadow_entries);
snd_dma_free_pages(&trident->tlb.buffer);
}
pci_release_regions(trident->pci);
pci_disable_device(trident->pci);
kfree(trident);
return 0;
} | /*---------------------------------------------------------------------------
snd_trident_free
Description: This routine will free the device specific class for
the 4DWave card.
Parameters: trident - device specific private data for 4DWave card
Returns: None.
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3820-L3844 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_interrupt | irqreturn_t snd_trident_interrupt(int irq, void *dev_id)
{
struct snd_trident *trident = dev_id;
unsigned int audio_int, chn_int, stimer, channel, mask, tmp;
int delta;
struct snd_trident_voice *voice;
audio_int = inl(TRID_REG(trident, T4D_MISCINT));
if ((audio_int & (ADDRESS_IRQ|MPU401_IRQ)) == 0)
return IRQ_NONE;
if (audio_int & ADDRESS_IRQ) {
// get interrupt status for all channels
spin_lock(&trident->reg_lock);
stimer = inl(TRID_REG(trident, T4D_STIMER)) & 0x00ffffff;
chn_int = inl(TRID_REG(trident, T4D_AINT_A));
if (chn_int == 0)
goto __skip1;
outl(chn_int, TRID_REG(trident, T4D_AINT_A)); /* ack */
__skip1:
chn_int = inl(TRID_REG(trident, T4D_AINT_B));
if (chn_int == 0)
goto __skip2;
for (channel = 63; channel >= 32; channel--) {
mask = 1 << (channel&0x1f);
if ((chn_int & mask) == 0)
continue;
voice = &trident->synth.voices[channel];
if (!voice->pcm || voice->substream == NULL) {
outl(mask, TRID_REG(trident, T4D_STOP_B));
continue;
}
delta = (int)stimer - (int)voice->stimer;
if (delta < 0)
delta = -delta;
if ((unsigned int)delta < voice->spurious_threshold) {
/* do some statistics here */
trident->spurious_irq_count++;
if (trident->spurious_irq_max_delta < (unsigned int)delta)
trident->spurious_irq_max_delta = delta;
continue;
}
voice->stimer = stimer;
if (voice->isync) {
if (!voice->isync3) {
tmp = inw(TRID_REG(trident, T4D_SBBL_SBCL));
if (trident->bDMAStart & 0x40)
tmp >>= 1;
if (tmp > 0)
tmp = voice->isync_max - tmp;
} else {
tmp = inl(TRID_REG(trident, NX_SPCTRL_SPCSO)) & 0x00ffffff;
}
if (tmp < voice->isync_mark) {
if (tmp > 0x10)
tmp = voice->isync_ESO - 7;
else
tmp = voice->isync_ESO + 2;
/* update ESO for IRQ voice to preserve sync */
snd_trident_stop_voice(trident, voice->number);
snd_trident_write_eso_reg(trident, voice, tmp);
snd_trident_start_voice(trident, voice->number);
}
} else if (voice->isync2) {
voice->isync2 = 0;
/* write original ESO and update CSO for IRQ voice to preserve sync */
snd_trident_stop_voice(trident, voice->number);
snd_trident_write_cso_reg(trident, voice, voice->isync_mark);
snd_trident_write_eso_reg(trident, voice, voice->ESO);
snd_trident_start_voice(trident, voice->number);
}
#if 0
if (voice->extra) {
/* update CSO for extra voice to preserve sync */
snd_trident_stop_voice(trident, voice->extra->number);
snd_trident_write_cso_reg(trident, voice->extra, 0);
snd_trident_start_voice(trident, voice->extra->number);
}
#endif
#if 0
spin_unlock(&trident->reg_lock);
snd_pcm_period_elapsed(voice->substream);
spin_lock(&trident->reg_lock);
#endif
}
outl(chn_int, TRID_REG(trident, T4D_AINT_B)); /* ack */
__skip2:
spin_unlock(&trident->reg_lock);
}
if (audio_int & MPU401_IRQ) {
if (trident->rmidi) {
//snd_mpu401_uart_interrupt(irq, trident->rmidi->private_data);
} else {
inb(TRID_REG(trident, T4D_MPUR0));
}
}
// outl((ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), TRID_REG(trident, T4D_MISCINT));
return IRQ_HANDLED;
} | /*---------------------------------------------------------------------------
snd_trident_interrupt
Description: ISR for Trident 4DWave device
Parameters: trident - device specific private data for 4DWave card
Problems: It seems that Trident chips generates interrupts more than
one time in special cases. The spurious interrupts are
detected via sample timer (T4D_STIMER) and computing
corresponding delta value. The limits are detected with
the method try & fail so it is possible that it won't
work on all computers. [jaroslav]
Returns: None.
---------------------------------------------------------------------------*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L3864-L3961 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | set_tlb_bus | static inline void set_tlb_bus(struct snd_trident *trident, int page,
unsigned long ptr, dma_addr_t addr)
{
page <<= 1;
__set_tlb_bus(trident, page, ptr, addr);
__set_tlb_bus(trident, page+1, ptr + SNDRV_TRIDENT_PAGE_SIZE, addr + SNDRV_TRIDENT_PAGE_SIZE);
} | /* fill TLB entries -- we need to fill two entries */ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_memory.c#L73-L79 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | set_tlb_bus | static inline void set_tlb_bus(struct snd_trident *trident, int page,
unsigned long ptr, dma_addr_t addr)
{
int i;
page *= UNIT_PAGES;
for (i = 0; i < UNIT_PAGES; i++, page++) {
__set_tlb_bus(trident, page, ptr, addr);
ptr += SNDRV_TRIDENT_PAGE_SIZE;
addr += SNDRV_TRIDENT_PAGE_SIZE;
}
} | /* fill TLB entries -- UNIT_PAGES entries must be filled */ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_memory.c#L103-L113 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | is_valid_page | static int is_valid_page(unsigned long ptr)
{
if (ptr & ~0x3fffffffUL) {
snd_printk(KERN_ERR "max memory size is 1GB!!\n");
return 0;
}
if (ptr & (SNDRV_TRIDENT_PAGE_SIZE-1)) {
snd_printk(KERN_ERR "page is not aligned\n");
return 0;
}
return 1;
} | /*
* check if the given pointer is valid for pages
*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_memory.c#L173-L184 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_trident_free_pages | int snd_trident_free_pages(struct snd_trident *trident,
struct snd_util_memblk *blk)
{
struct snd_util_memhdr *hdr;
int page;
if (snd_BUG_ON(!trident || !blk))
return -EINVAL;
hdr = trident->tlb.memhdr;
mutex_lock(&hdr->block_mutex);
/* reset TLB entries */
for (page = firstpg(blk); page <= lastpg(blk); page++)
set_silent_tlb(trident, page);
/* free memory block */
__snd_util_mem_free(hdr, blk);
mutex_unlock(&hdr->block_mutex);
return 0;
} | /*
* release DMA buffer from page table
*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_memory.c#L297-L315 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | mdma_ISA_bufpos_test | static unsigned int mdma_ISA_bufpos_test(struct mpxplay_audioout_info_s *aui)
{
unsigned int last=MDma_ISA_getbufpos(aui),retry;
retry=10;
do{
if(last!=MDma_ISA_getbufpos(aui))
return 1;
delay(10);
}while(--retry);
return 0;
} | //------------------------------------------------------------------------- | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/dmairq.c#L376-L386 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | pcibios_GetBus | static uint8_t pcibios_GetBus(void)
{
union REGS reg;
pcibios_clear_regs(reg);
reg.h.ah = PCI_FUNCTION_ID;
reg.h.al = PCI_BIOS_PRESENT;
reg.w.cflag=1;
int386(PCI_SERVICE, ®, ®);
if(reg.w.cflag)
return 0;
return 1;
} | //just to make vscode happy | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/pcibios.c#L37-L53 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | pcibios_search_devices | uint8_t pcibios_search_devices(pci_device_s devices[],pci_config_s *ppkey)
{
if(pcibios_GetBus()){
unsigned int i=0;
while(devices[i].vendor_id){
if(pcibios_FindDevice(devices[i].vendor_id,devices[i].device_id,ppkey)==PCI_SUCCESSFUL){
if(ppkey){
ppkey->device_name=devices[i].device_name;
ppkey->device_type=devices[i].device_type;
}
return PCI_SUCCESSFUL;
}
i++;
}
}
return PCI_DEVICE_NOTFOUND;
} | //_MSC_VER | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/pcibios.c#L82-L98 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | pcibios_ReadConfig_Byte | uint8_t pcibios_ReadConfig_Byte(pci_config_s * ppkey, uint16_t wAdr)
{
union REGS reg;
pcibios_clear_regs(reg);
reg.h.ah = PCI_FUNCTION_ID;
reg.h.al = PCI_READ_BYTE;
reg.h.bh = ppkey->bBus;
reg.h.bl = PCIDEVFUNC(ppkey->bDev, ppkey->bFunc);
reg.w.di = wAdr;
int386(PCI_SERVICE, ®, ®);
return reg.h.cl;
} | //BIOS INT service may freeze on some PC (tested a 845M laptop), use pure IOs. | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/pcibios.c#L101-L115 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | ALS4000_writeMIXER | static void ALS4000_writeMIXER (struct mpxplay_audioout_info_s *aui, unsigned long reg, unsigned long val)
{
struct als4000_card_s *card = aui->card_private_data;
als4000dbg("write mixer val: %X\n", val);
} | // XXX need to defer writing until start is called??? | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_als4000.c#L167-L171 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | CMI8X38_writeMIXER | static void CMI8X38_writeMIXER(struct mpxplay_audioout_info_s *aui,unsigned long reg, unsigned long val)
{
struct cmi8x38_card *card=aui->card_private_data;
//_LOG("write mixer: %x, %x->%x\n", reg, snd_cmipci_mixer_read(card,reg), val);
snd_cmipci_mixer_write(card,reg,val);
} | //--------------------------------------------------------------------------
//mixer | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_cmi.c#L944-L949 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_es1371_wait_src_ready | static unsigned int snd_es1371_wait_src_ready(struct ensoniq_card_s *card)
{
unsigned int t, r = 0;
for (t = 0; t < POLL_COUNT; t++) {
r = inl(card->port + ES_REG_1371_SMPRATE);
if ((r & ES_1371_SRC_RAM_BUSY) == 0)
return r;
}
mpxplay_debugf(ENS_DEBUG_OUTPUT,"wait_src_ready timeout r=%8.8X",r);
return 0;
} | //-------------------------------------------------------------------------
// low level write & read | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_e1371.c#L129-L140 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_es1371_buffer_init | static unsigned int snd_es1371_buffer_init(struct ensoniq_card_s *card,struct mpxplay_audioout_info_s *aui)
{
unsigned int bytes_per_sample=2; // 16 bit
card->pcmout_bufsize=MDma_get_max_pcmoutbufsize(aui,0,ES1371_DMABUF_ALIGN,bytes_per_sample,0);
card->dm=MDma_alloc_cardmem(card->pcmout_bufsize);
card->pcmout_buffer=(char *)card->dm->linearptr;
aui->card_DMABUFF=card->pcmout_buffer;
mpxplay_debugf(ENS_DEBUG_OUTPUT,"buffer init: pcmoutbuf:%8.8X size:%d",(unsigned long)card->pcmout_buffer,card->pcmout_bufsize);
return 1;
} | //------------------------------------------------------------------------- | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_e1371.c#L326-L335 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | ES1371_getbufpos | static long ES1371_getbufpos(struct mpxplay_audioout_info_s *aui)
{
struct ensoniq_card_s *card=aui->card_private_data;
unsigned long bufpos=0;
if(inl(card->port + ES_REG_CONTROL) & ES_DAC1_EN) {
outl((card->port + ES_REG_MEM_PAGE), ES_MEM_PAGEO(ES_PAGE_DAC));
bufpos = ES_REG_FCURR_COUNTI(inl(card->port + ES_REG_DAC1_SIZE));
if(bufpos<aui->card_dmasize)
aui->card_dma_lastgoodpos=bufpos;
}
mpxplay_debugf(ENS_DEBUG_OUTPUT,"bufpos:%5d gpos:%5d dmasize:%5d",bufpos,aui->card_dma_lastgoodpos,aui->card_dmasize);
return aui->card_dma_lastgoodpos;
} | //------------------------------------------------------------------------ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_e1371.c#L585-L598 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | ES1371_writeMIXER | static void ES1371_writeMIXER(struct mpxplay_audioout_info_s *aui,unsigned long reg, unsigned long val)
{
struct ensoniq_card_s *card=aui->card_private_data;
snd_es1371_codec_write(card,reg,val);
} | //--------------------------------------------------------------------------
//mixer | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_e1371.c#L603-L607 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | INTELICH_writedata | static void INTELICH_writedata(struct mpxplay_audioout_info_s *aui,char *src,unsigned long left)
{
struct intel_card_s *card=aui->card_private_data;
MDma_writedata(aui,src,left);
} | //------------------------------------------------------------------------ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_ich.c#L718-L723 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | INTELICH_writeMIXER | static void INTELICH_writeMIXER(struct mpxplay_audioout_info_s *aui,unsigned long reg, unsigned long val)
{
struct intel_card_s *card=aui->card_private_data;
mpxplay_debugf(ICH_DEBUG_OUTPUT,"writeMIXER %X %X", reg, val);
snd_intel_codec_write(card,reg,val);
} | //--------------------------------------------------------------------------
//mixer | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_ich.c#L787-L792 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | update_pci_byte | static void update_pci_byte(pci_config_s *pci, unsigned int reg,
unsigned char mask, unsigned char val)
{
unsigned char data;
data=pcibios_ReadConfig_Byte(pci, reg);
data &= ~mask;
data |= (val & mask);
pcibios_WriteConfig_Byte(pci, reg, data);
} | //------------------------------------------------------------------------- | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_inthd.c#L136-L145 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | azx_corb_start | static void azx_corb_start(struct intelhd_card_s *chip, int confirm)
{
int timeout = 2000;
azx_writeb(chip, CORBCTL, CORBRUN); //start corb
// https://www.intel.com/content/dam/www/public/us/en/documents/product-specifications/high-definition-audio-specification.pdf
// According to page 37, when enabling DMA, you "Must read the value back"
// or simply delaying might work: pds_delay_10us(1000);
do
{
if(azx_readb(chip, CORBCTL)&CORBRUN) //read back, spec required.
break;
pds_delay_10us(10);
}while(confirm && (--timeout));
if(!timeout) mpxplay_debugf(IHD_DEBUG_OUTPUT, "stop rirb timeout");
//start rirb, without RINTCTL it might freeze (RIRBSTS interrupt bit won't be set on tested PC).
//IRQ should be mask out if ISR not installed, or else the driver init routine needs a ISR to ack the CORB/RIRB interrupt
azx_writeb(chip, RIRBCTL, RINTCTL|RIRBDMAEN);
} | //------------------------------------------------------------------------- | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_inthd.c#L190-L208 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_hda_get_sub_nodes | static unsigned int snd_hda_get_sub_nodes(struct intelhd_card_s *card, hda_nid_t nid,
hda_nid_t *start_id)
{
int parm;
parm = snd_hda_param_read(card, nid, AC_PAR_NODE_COUNT);
if(parm<0)
return 0;
*start_id = (parm >> 16) & 0xff;
return (parm & 0xff);
} | //------------------------------------------------------------------------ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_inthd.c#L520-L530 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | azx_reset | static unsigned int azx_reset(struct intelhd_card_s *chip)
{
int timeout;
mpxplay_debugf(IHD_DEBUG_OUTPUT,"azx reset_start: gctl1:%8.8X",azx_readl(chip, GCTL));
#if SBEMU_USE_CORB
azx_corb_stop(chip); //spec require corb stopped before reset(set CRST=0). this might be needed after a DOS hot reset
#endif
azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);
mpxplay_debugf(IHD_DEBUG_OUTPUT,"gctl2b:%8.8X gctl2d:%8.8X",(unsigned long)azx_readb(chip, GCTL),azx_readl(chip, GCTL));
timeout = 500;
while(((azx_readb(chip, GCTL)&ICH6_GCTL_RESET)!=0) && (--timeout))
pds_delay_10us(100);
mpxplay_debugf(IHD_DEBUG_OUTPUT,"gctl3:%8.8X timeout:%d",azx_readl(chip, GCTL),timeout);
pds_delay_10us(100);
azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
timeout = 500;
while(((azx_readb(chip, GCTL)&ICH6_GCTL_RESET)==0) && (--timeout))
pds_delay_10us(100);
pds_delay_10us(100);
mpxplay_debugf(IHD_DEBUG_OUTPUT,"gctl4:%8.8X timeout:%d ",(unsigned long)azx_readb(chip, GCTL),timeout);
if(!azx_readb(chip, GCTL)){
mpxplay_debugf(IHD_DEBUG_OUTPUT,"HDA controller not ready!");
return 0;
}
// disable unsolicited responses (single cmd mode)
azx_writel(chip, GCTL, (azx_readl(chip, GCTL) & (~ICH6_GCTL_UREN)));
pds_delay_10us(100);
chip->codec_mask = azx_readw(chip, STATESTS);
mpxplay_debugf(IHD_DEBUG_OUTPUT,"azx_reset_end: codec_mask:%8.8X",chip->codec_mask);
#if SBEMU_USE_CORB
azx_corb_init(chip);
#endif
return 1;
} | //------------------------------------------------------------------------ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_inthd.c#L875-L927 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_hda_get_max_freq | static unsigned long snd_hda_get_max_freq(struct intelhd_card_s *card)
{
unsigned long i,freq=0;
for(i=0; rate_bits[i].hz; i++)
if((card->supported_formats&(1<<i)) && (rate_bits[i].hz<0xffffffff))
freq=rate_bits[i].hz;
return freq;
} | //------------------------------------------------------------------------- | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_inthd.c#L930-L937 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_ihd_buffer_init | static unsigned int snd_ihd_buffer_init(struct mpxplay_audioout_info_s *aui,struct intelhd_card_s *card)
{
unsigned int bytes_per_sample=(aui->bits_set>16)? 4:2;
#if SBEMU_USE_CORB
unsigned long allbufsize=BDL_SIZE+1024 + (HDA_CORB_MAXSIZE+HDA_CORB_ALIGN+HDA_RIRB_MAXSIZE+HDA_RIRB_ALIGN);
#else
unsigned long allbufsize=BDL_SIZE+1024;
#endif
unsigned long gcap, sdo_offset;
unsigned int beginmem_aligned;
card->pcmout_period_size = AZX_PERIOD_SIZE;
card->pcmout_bufsize = MDma_get_max_pcmoutbufsize(aui,0,card->pcmout_period_size,bytes_per_sample*aui->chan_card/2,aui->freq_set);
allbufsize += card->pcmout_bufsize;
card->dm=MDma_alloc_cardmem(allbufsize);
if(!card->dm)
return 0;
beginmem_aligned=(((unsigned long)card->dm->linearptr+1023)&(~1023));
card->table_buffer=(uint32_t *)beginmem_aligned;
#if SBEMU_USE_CORB //put corb/rirb before pucmout incase pcmout overrite them
card->corb_buffer = (long*)((uintptr_t)beginmem_aligned + BDL_SIZE);
card->rirb_buffer = (long long*)((uintptr_t)card->corb_buffer + HDA_CORB_MAXSIZE);
card->pcmout_buffer=(char *)((uintptr_t)card->rirb_buffer+HDA_RIRB_MAXSIZE);
assert((((uint32_t)card->corb_buffer)&(HDA_CORB_ALIGN-1)) == 0);
assert((((uint32_t)card->rirb_buffer)&(HDA_RIRB_ALIGN-1)) == 0);
#else
card->pcmout_buffer=(char *)(beginmem_aligned+BDL_SIZE);
#endif
gcap = (unsigned long)azx_readw(card,GCAP);
card->is_count = (gcap >> 8) & 0xF;
card->os_count = (gcap >> 12) & 0xF;
card->bs_count = (gcap >> 3) & 0x1F;
if(!(card->config_select & AUCARDSCONFIG_IHD_USE_FIXED_SDO) && (card->os_count || card->bs_count)) // number of playback streams
sdo_offset = card->is_count * 0x20 + 0x80; // number of capture streams
else{
switch(card->board_driver_type){
case AZX_DRIVER_ATIHDMI:
case AZX_DRIVER_ATIHDMI_NS: sdo_offset = 0x80; break;
case AZX_DRIVER_TERA: sdo_offset = 0xe0; break;
case AZX_DRIVER_ULI: sdo_offset = 0x120; break;
default: sdo_offset = 0x100;break;
}
}
mpxplay_debugf(IHD_DEBUG_OUTPUT,"cs:%d csc:%d GCAP:%8.8X sdo: %8.8X",
card->config_select, aui->card_select_config, gcap, sdo_offset);
card->sd_addr = card->iobase + sdo_offset;
card->pcmout_num_periods = card->pcmout_bufsize / card->pcmout_period_size;
assert(card->pcmout_num_periods>=2); //spec required
return 1;
} | //-------------------------------------------------------------------------
// init & close | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_inthd.c#L953-L1009 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | INTELHD_writeMIXER | static void INTELHD_writeMIXER(struct mpxplay_audioout_info_s *aui,unsigned long reg, unsigned long val)
{
struct intelhd_card_s *card=aui->card_private_data;
snd_hda_put_vol_mute(card,reg,0,HDA_OUTPUT,0,val&0x7f); //force clear mute bit(7)
snd_hda_put_vol_mute(card,reg,1,HDA_OUTPUT,0,val&0x7f); //force clear mute bit(7)
} | //--------------------------------------------------------------------------
//mixer | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_inthd.c#L1621-L1626 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_ca0106_ptr_read | static unsigned int snd_ca0106_ptr_read(struct emu10k1_card *card,unsigned int reg,unsigned int chn)
{
unsigned int regptr, val;
regptr = (reg << 16) | chn;
outl(card->iobase + PTR, regptr);
val = inl(card->iobase + DATA);
return val;
} | // AUDIGYLS_USE_AC97
//-------------------------------------------------------------------- | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbl24.c#L76-L86 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_live24_mixer_read | static unsigned int snd_live24_mixer_read(struct emu10k1_card *card,unsigned int reg)
{
unsigned int channel_id=reg>>8;
reg&=0xff;
return snd_ca0106_ptr_read(card,reg,channel_id);
} | // Live 24 cards have no ac97 | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbl24.c#L356-L361 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_emu10k1_hw_init | static void snd_emu10k1_hw_init(struct emu10k1_card *card)
{
int ch;
uint32_t silent_page;
// disable audio and lock cache
emu10k1_writefn0(card,HCFG,HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE);
// reset recording buffers
emu10k1_writeptr(card, MICBS, 0, ADCBS_BUFSIZE_NONE);
emu10k1_writeptr(card, MICBA, 0, 0);
emu10k1_writeptr(card, FXBS, 0, ADCBS_BUFSIZE_NONE);
emu10k1_writeptr(card, FXBA, 0, 0);
emu10k1_writeptr(card, ADCBS, 0, ADCBS_BUFSIZE_NONE);
emu10k1_writeptr(card, ADCBA, 0, 0);
// disable channel interrupt
emu10k1_writefn0(card, INTE, 0);
emu10k1_writeptr(card, CLIEL, 0, 0);
emu10k1_writeptr(card, CLIEH, 0, 0);
emu10k1_writeptr(card, HLIEL, 0, 0);
emu10k1_writeptr(card, HLIEH, 0, 0);
emu10k1_writeptr(card, SOLEL, 0, 0);
emu10k1_writeptr(card, SOLEH, 0, 0);
if(card->chips&EMU_CHIPS_10K2){
emu10k1_writeptr(card, SPBYPASS, 0, SPBYPASS_FORMAT);
#ifdef AUDIGY1_USE_AC97
emu10k1_writeptr(card, AC97SLOT, 0, AC97SLOT_REAR_RIGHT|AC97SLOT_REAR_LEFT); // ?? no ac97 rear out on Audigy
#endif
}
// init envelope engine
for (ch = 0; ch < NUM_G; ch++){
emu10k1_writeptr(card, DCYSUSV, ch, 0);
emu10k1_writeptr(card, IP, ch, 0);
emu10k1_writeptr(card, VTFT, ch, 0xffff);
emu10k1_writeptr(card, CVCF, ch, 0xffff);
emu10k1_writeptr(card, PTRX, ch, 0);
emu10k1_writeptr(card, CPF, ch, 0);
emu10k1_writeptr(card, CCR, ch, 0);
emu10k1_writeptr(card, PSST, ch, 0);
emu10k1_writeptr(card, DSL, ch, 0x10);
emu10k1_writeptr(card, CCCA, ch, 0);
emu10k1_writeptr(card, Z1, ch, 0);
emu10k1_writeptr(card, Z2, ch, 0);
emu10k1_writeptr(card, FXRT, ch, 0x32100000);
emu10k1_writeptr(card, ATKHLDM, ch, 0);
emu10k1_writeptr(card, DCYSUSM, ch, 0);
emu10k1_writeptr(card, IFATN, ch, 0xffff);
emu10k1_writeptr(card, PEFE, ch, 0);
emu10k1_writeptr(card, FMMOD, ch, 0);
emu10k1_writeptr(card, TREMFRQ, ch, 24); // 1 Hz
emu10k1_writeptr(card, FM2FRQ2, ch, 24); // 1 Hz
emu10k1_writeptr(card, TEMPENV, ch, 0);
// these are last so OFF prevents writing
emu10k1_writeptr(card, LFOVAL2, ch, 0);
emu10k1_writeptr(card, LFOVAL1, ch, 0);
emu10k1_writeptr(card, ATKHLDV, ch, 0);
emu10k1_writeptr(card, ENVVOL, ch, 0);
emu10k1_writeptr(card, ENVVAL, ch, 0);
// Audigy extra stuffs
if (card->chips&EMU_CHIPS_10K2) {
emu10k1_writeptr(card, 0x4c, ch, 0); // ??
emu10k1_writeptr(card, 0x4d, ch, 0); // ??
emu10k1_writeptr(card, 0x4e, ch, 0); // ??
emu10k1_writeptr(card, 0x4f, ch, 0); // ??
emu10k1_writeptr(card, A_FXRT1, ch, 0x03020100);
emu10k1_writeptr(card, A_FXRT2, ch, 0x3f3f3f3f);
emu10k1_writeptr(card, A_SENDAMOUNTS, ch, 0);
}
}
/*
* Init to 0x02109204 :
* Clock accuracy = 0 (1000ppm)
* Sample Rate = 2 (48kHz)
* Audio Channel = 1 (Left of 2)
* Source Number = 0 (Unspecified)
* Generation Status = 1 (Original for Cat Code 12)
* Cat Code = 12 (Digital Signal Mixer)
* Mode = 0 (Mode 0)
* Emphasis = 0 (None)
* CP = 1 (Copyright unasserted)
* AN = 0 (Audio data)
* P = 0 (Consumer)
*/
emu10k1_writeptr(card, SPCS0, 0,
SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
SPCS_GENERATIONSTATUS | 0x00001200 |
0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
emu10k1_writeptr(card, SPCS1, 0,
SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
SPCS_GENERATIONSTATUS | 0x00001200 |
0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
emu10k1_writeptr(card, SPCS2, 0,
SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
SPCS_GENERATIONSTATUS | 0x00001200 |
0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
if(card->card_capabilities->chips&EMU_CHIPS_0151) { // audigy2,4 (24 bit)
// Hacks for Alice3 to work independent of haP16V driver
uint32_t tmp;
//Setup SRCMulti_I2S SamplingRate
tmp = emu10k1_readptr(card, A_SPDIF_SAMPLERATE, 0);
tmp &= 0xfffff1ff;
tmp |= (0x2<<9);
emu10k1_writeptr(card, A_SPDIF_SAMPLERATE, 0, tmp);
// Setup SRCSel (Enable Spdif,I2S SRCMulti)
emu10k1_ptr20_write(card, SRCSel, 0, 0x14);
// Setup SRCMulti Input Audio Enable
emu10k1_ptr20_write(card, SRCMULTI_ENABLE, 0, 0xFFFFFFFF);
// Enabled Phased (8-channel) P16V playback
//outl(card->iobase + HCFG2, 0x0201); // in ALSA
// enable 2 channel P16V playback
outl(card->iobase + HCFG2, 0x0001); // in Mpxplay
// Set playback routing.
emu10k1_ptr20_write(card, CAPTURE_P16V_SOURCE, 0, 0x0000); // ??? in Mpxplay (was 0x0400)
//emu10k1_ptr20_write(card, CAPTURE_P16V_SOURCE, 0, 0x78e4); // in ALSA
}
if(card->chips&EMU_CHIPS_0108){ // Audigy2 Value
// Hacks for Alice3 to work independent of haP16V driver
uint32_t tmp;
//Setup SRCMulti_I2S SamplingRate
tmp = emu10k1_readptr(card, A_SPDIF_SAMPLERATE, 0);
tmp &= 0xfffff1ff;
tmp |= (0x2<<9);
emu10k1_writeptr(card, A_SPDIF_SAMPLERATE, 0, tmp);
// Setup SRCSel (Enable Spdif,I2S SRCMulti)
outl(card->iobase + 0x20, 0x600000);
outl(card->iobase + 0x24, 0x14);
// Setup SRCMulti Input Audio Enable
outl(card->iobase + 0x20, 0x7b0000);
outl(card->iobase + 0x24, 0xFF000000);
// Setup SPDIF Out Audio Enable
// The Audigy 2 Value has a separate SPDIF out,
// so no need for a mixer switch
outl(card->iobase + 0x20, 0x7a0000);
outl(card->iobase + 0x24, 0xFF000000);
tmp = inl(card->iobase + A_IOCFG) & ~0x8; // Clear bit 3
outl(card->iobase + A_IOCFG, tmp);
}
if(card->chip_select&EMU_CHIPS_10KX){
//buffer config
emu10k1_writeptr(card, PTB, 0, (uint32_t) pds_cardmem_physicalptr(card->dm, card->virtualpagetable));
emu10k1_writeptr(card, TCB, 0, 0);
emu10k1_writeptr(card, TCBS, 0, 4);
silent_page = (((uint32_t)card->silentpage) << 1) | MAP_PTI_MASK;
for (ch = 0; ch < NUM_G; ch++) {
emu10k1_writeptr(card, MAPA, ch, (uint32_t)pds_cardmem_physicalptr(card->dm,silent_page));
emu10k1_writeptr(card, MAPB, ch, (uint32_t)pds_cardmem_physicalptr(card->dm,silent_page));
}
}
// setup HCFG
if(card->chips&EMU_CHIPS_10KX){
if(card->chips&EMU_CHIPS_10K2){ // Audigy
if(card->chiprev == 4) // Audigy 2,4
emu10k1_writefn0(card,HCFG,HCFG_AC3ENABLE_CDSPDIF | HCFG_AC3ENABLE_GPSPDIF | HCFG_AUTOMUTE | HCFG_JOYENABLE);
else // Audigy 1
emu10k1_writefn0(card,HCFG,HCFG_AUTOMUTE | HCFG_JOYENABLE);
}else{ // SB Live
if(card->model == 0x20 || card->model == 0xc400 || (card->model == 0x21 && card->chiprev < 6))
emu10k1_writefn0(card,HCFG,HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE);
else
emu10k1_writefn0(card,HCFG,HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE);
}
}
if(card->chips&EMU_CHIPS_10K2) { // enable analog output
uint32_t tmp = inl(card->iobase + A_IOCFG);
outl(card->iobase + A_IOCFG, tmp | A_IOCFG_GPOUT0);
}
//mixer (routing) config
if(card->chip_select&EMU_CHIPS_10KX)
snd_emu10kx_fx_init(card);
//Enable the audio bit
outl(card->iobase + HCFG, inl(card->iobase + HCFG) | HCFG_AUDIOENABLE);
if(card->chips&EMU_CHIPS_10K2){
uint32_t tmp = inl(card->iobase + A_IOCFG);
tmp&=~0x44;
if(card->chiprev==4) // Audigy2,4 Unmute Analog now. Set GPO6 to 1 for Apollo.
tmp|=0x0040;
else
if(card->chips&EMU_CHIPS_0108) // Audigy2 Value
tmp|=0x0060; // unmute
else // Audigy 1
#ifdef AUDIGY1_USE_AC97
tmp&=~0x0080; // enable routing from AC97 line out to Front speakers
#else
tmp|=0x0080; // disable routing from AC97 line out to Front speakers
#endif
outl(card->iobase + A_IOCFG, tmp);
}
} | //-----------------------------------------------------------------------
// init & close | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbliv.c#L116-L332 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_emu_set_spdif_freq | static void snd_emu_set_spdif_freq(struct emu10k1_card *card,unsigned long freq)
{
uint32_t tmp=emu10k1_readptr(card,A_SPDIF_SAMPLERATE,0) & (~A_SPDIF_RATE_MASK);
switch(freq){
case 44100 :tmp|= A_SPDIF_44100;break;
case 96000 :tmp|= A_SPDIF_96000;break;
case 192000:tmp|= A_SPDIF_192000;break;
default :tmp|= A_SPDIF_48000;break;
}
emu10k1_writeptr(card, A_SPDIF_SAMPLERATE, 0, tmp);
} | //--------------------------------------------------------------------------
// mixer (FX) | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbliv.c#L378-L388 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_emu_ac97_init | static void snd_emu_ac97_init(struct emu10k1_card *card)
{
snd_emu_ac97_write(card, AC97_RESET, 0); // resets the volumes too
snd_emu_ac97_read(card, AC97_RESET);
// initial ac97 volumes (and clear mute flag)
snd_emu_ac97_write(card, AC97_MASTER_VOL_STEREO, 0x0202);
snd_emu_ac97_write(card, AC97_SURROUND_MASTER, 0x0202);
snd_emu_ac97_write(card, AC97_PCMOUT_VOL, 0x0202);
snd_emu_ac97_write(card, AC97_HEADPHONE_VOL, 0x0202);
snd_emu_ac97_write(card, AC97_CD_VOL, 0x0202);
/*snd_emu_ac97_unmute(card, AC97_MASTER_VOL_STEREO);
snd_emu_ac97_unmute(card, AC97_SURROUND_MASTER);
snd_emu_ac97_unmute(card, AC97_PCMOUT_VOL);
snd_emu_ac97_unmute(card, AC97_HEADPHONE_VOL);*/
snd_emu_ac97_write(card, AC97_EXTENDED_STATUS, AC97_EA_SPDIF);
} | /*static void snd_emu_ac97_unmute(struct emu10k1_card *card,unsigned int reg)
{
uint32_t tmp=snd_emu_ac97_read(card,reg);
tmp&=~AC97_MUTE;
snd_emu_ac97_write(card,reg,tmp);
}*/ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbliv.c#L417-L435 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | emu10k1_clear_stop_on_loop | static void emu10k1_clear_stop_on_loop(struct emu10k1_card *card, uint32_t voicenum)
{
if (voicenum >= 32)
emu10k1_writeptr(card, SOLEH | ((0x0100 | (voicenum - 32)) << 16), 0, 0);
else
emu10k1_writeptr(card, SOLEL | ((0x0100 | voicenum) << 16), 0, 0);
} | //--------------------------------------------------------------------------
// emu10kx (k1,k2) routines | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbliv.c#L550-L556 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_emu10k1_selector | static unsigned int snd_emu10k1_selector(struct emu10k1_card *card,struct mpxplay_audioout_info_s *aui)
{
if(card->chips&EMU_CHIPS_10K1)
return 1;
return 0;
} | //------------------------------------------------------------------------
//emu10kx api (SB Live 5.1, SB Audigy 1,2,4) | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbliv.c#L786-L791 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | hw_read_20kx | static inline uint32_t hw_read_20kx(struct emu20kx_card_s *card,uint32_t reg)
{
outl(card->iobase + 0x0,reg);
return ((uint32_t)inl(card->iobase + 0x4));
} | //------------------------------------------------------------------------- | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbxfi.c#L224-L228 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | uint16_to_float14 | static unsigned int uint16_to_float14(unsigned int x)
{
unsigned int i;
if(x < 17)
return 0;
x *= 2031;
x /= 65535;
x += 16;
for (i = 0; !(x & 0x400); i++)
x <<= 1;
x = (((7 - i) & 0x7) << 10) | (x & 0x3ff);
return x;
} | // Map integer value ranging from 0 to 65535 to 14-bit float value ranging from 2^-6 to (1+1023/1024) | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbxfi.c#L318-L335 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | set_interval_timer | static void set_interval_timer(struct emu20kx_card_s *card, int msecs)
{
int tic = (HARDWARE_RATE*msecs)/1000;
hw_write_20kx (card, TIMR, tic | TIMR_IE|TIMR_IP);
} | //------------------------------------------------------------------------- | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbxfi.c#L356-L361 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | hw_reset_dac | static int hw_reset_dac(struct emu20kx_card_s *card)
{
uint32_t i = 0;
uint16_t gpioorg = 0;
unsigned int ret = 0;
if(i2c_unlock(card))
return -1;
do{
ret = hw_read_pci(card, 0xEC);
}while(!(ret & 0x800000));
hw_write_pci(card, 0xEC, 0x05); /* write to i2c status control */
/* To be effective, need to reset the DAC twice. */
for(i = 0; i < 2; i++){
/* set gpio */
pds_delay_10us(100*100);
gpioorg = (uint16_t)hw_read_20kx(card, GPIO);
gpioorg &= 0xfffd;
hw_write_20kx(card, GPIO, gpioorg);
pds_delay_10us(1);
hw_write_20kx(card, GPIO, gpioorg | 0x2);
}
i2c_write(card, 0x00180080, 0x01, 0x80);
i2c_write(card, 0x00180080, 0x02, 0x10);
i2c_lock(card);
return 0;
} | /* DAC operations */ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbxfi.c#L462-L493 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_emu20kx_set_output_format | static void snd_emu20kx_set_output_format(struct emu20kx_card_s *card,struct mpxplay_audioout_info_s *aui)
{
switch(aui->card_wave_id){
case MPXPLAY_WAVEID_PCM_FLOAT:card->sfnum=SRC_SF_F32;break;
default:
switch(aui->bits_card){
case 32:card->sfnum=SRC_SF_S32;break;
case 24:card->sfnum=SRC_SF_S24;break;
default:card->sfnum=SRC_SF_S16;aui->bits_card=16;break;
}
aui->card_wave_id=MPXPLAY_WAVEID_PCM_SLE;
}
if(aui->freq_card<3000)
aui->freq_card=3000;
else if((aui->freq_card>96000) && (aui->chan_set>2))
aui->freq_card=96000;
else if(aui->freq_card>192000)
aui->freq_card=192000;
if(aui->freq_card==44100){
card->dac_output_freq=44100;
card->rsr=44100;
card->msr=1;
}else if(aui->freq_card<=48000){
card->dac_output_freq=48000;
card->rsr=48000;
card->msr=1;
}else if(aui->freq_card<=96000){
card->dac_output_freq=96000;
card->rsr=48000;
card->msr=2;
}else{
card->dac_output_freq=192000;
card->rsr=48000;
card->msr=4;
}
card->max_cisz=aui->chan_card*card->msr;
card->max_cisz=128*((card->max_cisz<8)? card->max_cisz:8);
} | //-------------------------------------------------------------------------
/*#include "ac97_def.h"
#define AC97D 0x1C5400
#define AC97A 0x1C5404
static void emu20kx_ac97_write(struct emu20kx_card_s *card,unsigned int reg,unsigned int data)
{
hw_write_20kx(card,AC97A,reg);
hw_write_20kx(card,AC97D,data);
}
static void snd_emu20kx_ac97_init(struct emu20kx_card_s *card)
{
emu20kx_ac97_write(card, AC97_MASTER_VOL_STEREO, 0x0404);
emu20kx_ac97_write(card, AC97_PCMOUT_VOL, 0x0404);
emu20kx_ac97_write(card, AC97_HEADPHONE_VOL, 0x0404);
emu20kx_ac97_write(card, AC97_EXTENDED_STATUS,AC97_EA_SPDIF);
mpxplay_debugf(XFI_DEBUG_OUTPUT,"ac97 init end");
}*/
//------------------------------------------------------------------------- | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbxfi.c#L570-L610 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_emu20kx_buffer_init | static unsigned int snd_emu20kx_buffer_init(struct emu20kx_card_s *card,struct mpxplay_audioout_info_s *aui)
{
unsigned int bytes_per_sample=((aui->bits_set>16) || (aui->card_wave_id==MPXPLAY_WAVEID_PCM_FLOAT))? 4:2;
uint32_t pagecount,pcmbufp;
card->pcmout_bufsize=MDma_get_max_pcmoutbufsize(aui,0,EMU20KX_PAGESIZE,bytes_per_sample,0);
card->dm=MDma_alloc_cardmem( EMU20KX_MAXPAGES*sizeof(uint32_t)// virtualpage
+EMU20KX_PAGESIZE // silentpage
+card->pcmout_bufsize // pcm output
+0x1000 ); // to round
card->silentpage=(void *)(((uint32_t)card->dm->linearptr+0x0fff)&0xfffff000); // buffer begins on page boundary
card->virtualpagetable=(uint32_t *)((uint32_t)card->silentpage+EMU20KX_PAGESIZE);
card->pcmout_buffer=(char *)(card->virtualpagetable+EMU20KX_MAXPAGES);
pcmbufp=(uint32_t)card->pcmout_buffer;
pcmbufp<<=1;
for(pagecount = 0; pagecount < (card->pcmout_bufsize/EMU20KX_PAGESIZE); pagecount++){
card->virtualpagetable[pagecount] = (uint32_t)pds_cardmem_physicalptr(card->dm, pcmbufp) | pagecount;
pcmbufp+=EMU20KX_PAGESIZE*2;
}
for( ; pagecount<EMU20KX_MAXPAGES; pagecount++)
card->virtualpagetable[pagecount] = ((uint32_t)pds_cardmem_physicalptr(card->dm, card->silentpage))<<1;
aui->card_DMABUFF=card->pcmout_buffer;
mpxplay_debugf(XFI_DEBUG_OUTPUT,"buffer init: pcmoutbuf:%8.8X size:%d",(unsigned long)card->pcmout_buffer,card->pcmout_bufsize);
return 1;
} | //------------------------------------------------------------------------- | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbxfi.c#L615-L642 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | EMU20KX_getbufpos | static long EMU20KX_getbufpos(struct mpxplay_audioout_info_s *aui)
{
struct emu20kx_card_s *card=aui->card_private_data;
unsigned long bufpos=0,ctl_ca;
ctl_ca=hw_read_20kx(card, SRCCA+card->src_idx*0x100);
bufpos=get_field(ctl_ca, SRCCA_CA);
bufpos=(bufpos + aui->card_dmasize - card->max_cisz - (unsigned long)card->pcmout_buffer) % aui->card_dmasize;
aui->card_dma_lastgoodpos=bufpos;
mpxplay_debugf(XFI_DEBUG_OUTPUT,"bufpos:%5d dmasize:%5d",bufpos,aui->card_dmasize);
return aui->card_dma_lastgoodpos;
} | //------------------------------------------------------------------------ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbxfi.c#L891-L906 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | EMU20KX_writeMIXER | static void EMU20KX_writeMIXER(struct mpxplay_audioout_info_s *aui,unsigned long reg, unsigned long val)
{
//struct emu20kx_card_s *card=aui->card_private_data;
} | //--------------------------------------------------------------------------
//mixer | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_sbxfi.c#L911-L914 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | via82xx_ReadAC97Codec_sub | static unsigned long via82xx_ReadAC97Codec_sub(unsigned int baseport)
{
unsigned long d0;
int retry = 2048;
do{
d0 = inl(baseport + VIA_REG_AC97_CTRL);
if( (d0 & VIA_REG_AC97_PRIMARY_VALID) != 0 )
break;
pds_delay_10us(1);
}while(--retry);
d0 = inl(baseport + VIA_REG_AC97_CTRL);
return d0;
} | //--------------------------------------------------------------------------
//mixer | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_via82.c#L464-L478 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | YMF_close | static void YMF_close (struct mpxplay_audioout_info_s *aui)
{
#if YMF_DEBUG
DBG_Logi("YMF_close\n");
#endif
struct ymf_card_s *card = aui->card_private_data;
if (card) {
if (card->iobase) {
pds_dpmi_unmap_physycal_memory(card->iobase);
}
}
if (card->dm)
MDma_free_cardmem(card->dm);
if (card->dm2)
MDma_free_cardmem(card->dm2);
if (card->pci_dev)
pds_free(card->pci_dev);
pds_free(card);
aui->card_private_data = NULL;
} | // SIEN:IMOD 0:0 = legacy irq, 0:1 = INTA, 1:0 = serialized IRQ | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_ymf.c#L346-L365 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_ymfpci_timer_start | static int snd_ymfpci_timer_start (struct mpxplay_audioout_info_s *aui)
{
struct ymf_card_s *card = aui->card_private_data;
unsigned long flags;
unsigned int count;
spin_lock_irqsave(&card->reg_lock, flags);
count = 480; // 5ms: 0.005/(1/96000)
snd_ymfpci_writew(card, YDSXGR_TIMERCOUNT, count);
snd_ymfpci_writeb(card, YDSXGR_TIMERCTRL, 0x03);
spin_unlock_irqrestore(&card->reg_lock, flags);
return 0;
} | // .resolution = 10417, // 1 / 96 kHz = 10.41666...us
// .ticks = 0x10000, | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_ymf.c#L943-L956 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | YMF_mixer_init | void YMF_mixer_init (struct ymf_card_s *card)
{
#define IEC958_AES0_CON_EMPHASIS_NONE (0<<3) // none emphasis
#define IEC958_AES1_CON_ORIGINAL (1<<7) // depends on the category code
#define IEC958_AES1_CON_DIGDIGCONV_ID 0x02
#define IEC958_AES1_CON_PCM_CODER (IEC958_AES1_CON_DIGDIGCONV_ID|0x00)
#define IEC958_AES3_CON_FS_48000 (2<<0) // 48kHz
#define SNDRV_PCM_DEFAULT_CON_SPDIF (IEC958_AES0_CON_EMPHASIS_NONE| \
(IEC958_AES1_CON_ORIGINAL<<8)| \
(IEC958_AES1_CON_PCM_CODER<<8)| \
(IEC958_AES3_CON_FS_48000<<24))
// $ iecset
// Mode: consumer
// Data: audio
// Rate: 48000 Hz
// Copyright: permitted
// Emphasis: none
// Category: PCM coder
// Original: original
// Clock: 1000 ppm
// $ iecset -x
// AES0=0x04,AES1=0x82,AES2=0x00,AES3=0x02
// S/PDIF output initialization
//card->spdif_bits = card->spdif_pcm_bits = (SNDRV_PCM_DEFAULT_CON_SPDIF & 0xffff);
// enable recording
//card->spdif_bits = card->spdif_pcm_bits = 0x02008204;
// Only set the first 16 bits. The sample rate (48KHz) bits in the fourth byte are set automatically in HW.
card->spdif_bits = card->spdif_pcm_bits = 0x8204;
snd_ymfpci_writel(card, YDSXGR_SPDIFOUTCTRL, 1); // S/PDIF on
snd_ymfpci_writew(card, YDSXGR_SPDIFOUTSTATUS, card->spdif_bits);
// S/PDIF input initialization
snd_ymfpci_writel(card, YDSXGR_SPDIFINCTRL, 0);
// digital mixer setup
for (unsigned int reg = 0x80; reg < 0xc0; reg += 4)
snd_ymfpci_writel(card, reg, 0);
//snd_ymfpci_writel(card, YDSXGR_NATIVEDACOUTVOL, 0x3fff3fff);
//snd_ymfpci_writel(card, YDSXGR_BUF441OUTVOL, 0x3fff3fff);
snd_ymfpci_writel(card, YDSXGR_ZVOUTVOL, 0x3fff3fff);
snd_ymfpci_writel(card, YDSXGR_SPDIFOUTVOL, 0x3fff3fff);
snd_ymfpci_writel(card, YDSXGR_NATIVEADCINVOL, 0x3fff3fff);
snd_ymfpci_writel(card, YDSXGR_NATIVEDACINVOL, 0x3fff3fff);
snd_ymfpci_writel(card, YDSXGR_PRIADCLOOPVOL, 0x3fff3fff);
snd_ymfpci_writel(card, YDSXGR_LEGACYOUTVOL, 0x3fff3fff);
} | // PCM | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_ymf.c#L971-L1019 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | snd_ymfpci_playback_prepare | static int snd_ymfpci_playback_prepare (struct mpxplay_audioout_info_s *aui)
{
//struct snd_pcm_runtime *runtime = substream->runtime;
struct ymf_card_s *card = aui->card_private_data;
//struct snd_ymfpci_pcm *ypcm = runtime->private_data;
//struct snd_kcontrol *kctl;
unsigned int nvoice;
//ypcm->period_size = runtime->period_size;
//ypcm->buffer_size = runtime->buffer_size;
card->period_pos = 0;
card->last_pos = 0;
for (nvoice = 0; nvoice < aui->chan_card; nvoice++)
snd_ymfpci_pcm_init_voice(aui, nvoice, 0);
//if (substream->pcm == card->pcm && !ypcm->use_441_slot) {
// kctl = card->pcm_mixer[substream->number].ctl;
// kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
// snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO, &kctl->id);
//}
return 0;
} | //static int snd_ymfpci_playback_prepare (struct snd_pcm_substream *substream) | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/mpxplay/au_cards/sc_ymf.c#L1752-L1773 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | DBG_Logv | void DBG_Logv(const char* fmt, va_list aptr)
{
#define SIZE (DUMP_BUFF_SIZE*4)
char buf[SIZE];
int len = vsprintf(buf, fmt, aptr);
assert(len < SIZE);
len = min(len, SIZE-1);
buf[len] = '\0';
if (ser_puts(buf)) {
return;
}
if(!(CPU_FLAGS()&CPU_IFLAG))
{ //use VGA when in interrupt
VGA_Print(buf);
}
else
{ //direct VGA mode will mess other tools, i.e. SCROLLit, normally use BIOS function
#if 0
DPMI_REG r = {0};
for(int i = 0; i < len; ++i)
{
r.h.ah = 0x0E;
r.h.al = (uint8_t)buf[i];
DPMI_CallRealModeINT(0x10,&r);
if(buf[i] =='\n')
{
r.h.ah = 0x0E;
r.h.al = '\r';
DPMI_CallRealModeINT(0x10,&r);
}
}
#else //debug out. not used (crashed)
textcolor(DARKGRAY);
int crlf = buf[len-1] == '\n';
buf[len-1] = crlf ? '\0' : buf[len-1];
cputs(buf);
textcolor(LIGHTGRAY);
if(crlf) cputs("\r\n");
#endif
}
#undef SIZE
} | //needs to work in interrupt handler. now use IN/OUT controls VGA directly. | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/sbemu/dpmi/dbgutil.c#L130-L173 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | DPMI_InitTSR | BOOL DPMI_InitTSR(uint32_t base, uint32_t newbase, uint32_t* outputp poffset, uint32_t* outputp psize)
{
if(poffset == NULL || psize == NULL)
return 0;
if(*poffset == 0 || *psize == 0)
{
int fd = open(__dos_argv0, O_RDONLY|O_BINARY, S_IRUSR);
BOOL ok = fd >= 0;
uint16_t MZ6[3]; //0:
if(ok)
ok = read(fd, MZ6, 6) == 6;
if(ok)
{
if(MZ6[0] == 0x5A4D) //MZ header, stubbed
ok = lseek(fd, MZ6[2]*512+MZ6[1],SEEK_SET) != -1;
else if(MZ6[0] == I386MAGIC)
ok = lseek(fd, 0, SEEK_SET) != -1;
}
struct external_filehdr hdr;
if(ok)
ok = read(fd, &hdr, FILHSZ) == FILHSZ && hdr.f_magic == I386MAGIC;
if(ok)
ok = lseek(fd, hdr.f_opthdr, SEEK_CUR) != -1;
if(ok)
{
for(int i = 0; i < hdr.f_nscns; ++i)
{
struct external_scnhdr sechdr;
ok = read(fd, &sechdr, sizeof(sechdr)) == sizeof(sechdr);
if(!ok)
break;
//printf("%5s: %08lx, %08lx\n", sechdr.s_name, sechdr.s_vaddr, sechdr.s_size);
BOOL text = memcmp(sechdr.s_name, _TEXT,6) == 0;
BOOL data = memcmp(sechdr.s_name, _DATA,6) == 0;
BOOL bss = memcmp(sechdr.s_name, _BSS,5) == 0;
if( text || data || bss) //should be consecutive by COFF spec
{
ProgramOffset = min(ProgramOffset, sechdr.s_vaddr);
ProgramSize += sechdr.s_size;
int index = text ? 0 : (data ? 1 : 2);
SectionOffset[index] = sechdr.s_vaddr;
SectionSize[index] = sechdr.s_size;
}
}
}
if(!ok || ProgramOffset == 0xFFFFFFFF || ProgramSize == 0)
{
printf("failed reading file.\n");
return FALSE;
}
void (*volatile pfree)(void*) = free; //prevent optimization
void*(*volatile pmalloc)(size_t) = malloc;
// |CODE|DATA|BSS|STACK|C HEAP|XMS_HEAP| (all fixed size)
pfree(pmalloc(NEW_BASE_ALIGNMENT)); //preserve space for C runtime heap
/*uintptr_t end0 = (uintptr_t)sbrk(0);
//printf("%08lx\n",_go32_info_block.size_of_transfer_buffer);
if(!stdout->_base) //printf hack
{
stdout->_bufsiz = _go32_info_block.size_of_transfer_buffer;
stdout->_base = malloc(stdout->_bufsiz);
stdout->_flag |= _IOLBF|0x40;//_IOMYBUF;
stdout->_cnt = 0;
stdout->_ptr = stdout->_base;
//printf("pre alloc stdout buffer: %08lx, %08lx\n", end0, sbrk(0));
}*/
uintptr_t end = (uintptr_t)sbrk(0);
ProgramSize = (uintptr_t)max(end - ProgramOffset, ProgramSize);
*poffset = ProgramOffset;
*psize = align(ProgramOffset+ProgramSize, NEW_BASE_ALIGNMENT);
//sbrk(*psize - end);
//assert((uintptr_t)sbrk(0) == *psize);
if(*psize > (uintptr_t)sbrk(0) + 0x100)
pfree(pmalloc(*psize - (uintptr_t)sbrk(0) - 0x100));
return FALSE;
}
*psize = align(*psize, NEW_BASE_ALIGNMENT);
uint32_t offset = *poffset;
uint32_t size = *psize;
assert(offset == ProgramOffset);
//TODO: shrink stack as we may not need too much space?
//TODO: custom keep of code & data like DOS TSR. we can do the TSR init on exit (we still need physical addr for driver before TSR)
//printf("min stack: %08lx, min keep: %08lx\n", _stubinfo->minstack, _stubinfo->minkeep);
//printf("%08lx, %08lx: %08lx\n", base, ProgramOffset, ProgramSize);
ProgramNewCS = (uint16_t)__dpmi_create_alias_descriptor(_my_cs());
//int16_t ProgramNewCS = __dpmi_allocate_ldt_descriptors(1);
int32_t ar = __dpmi_get_descriptor_access_rights(ProgramNewCS);
ar |= 0x08; //code: 0x08
__dpmi_set_descriptor_access_rights(ProgramNewCS,ar);
__dpmi_set_segment_limit(ProgramNewCS, size-1);
__dpmi_set_segment_base_address(ProgramNewCS, newbase);
ProgramNewDS = (uint16_t)__dpmi_create_alias_descriptor(_my_ds());
__dpmi_set_segment_limit(ProgramNewDS, size-1);
__dpmi_set_segment_base_address(ProgramNewDS, newbase);
volatile uint32_t PreventOptimize;//prevent optimization out code after ljmp
asm __volatile__("xor %0, %0":"=r"(PreventOptimize) : :"memory");
if(PreventOptimize)
goto switch_space;
assert(ProgramOffset+ProgramSize <= size);
asm __volatile__( //save data before switch.
"pushw %%ds\n\t popw %0\n\t"
"pushw %%cs\n\t popw %1\n\t"
:"=m"(ProgramOldDS),"=m"(ProgramOldCS)
::"memory");
//jump buffer
uint32_t fjmp[2] = {(uintptr_t)&&switch_space, ProgramNewCS};
//int eip;
//asm("movl $., %0" :: "r"(eip) :"memory");
//printf("%04x:%08lx, %08lx, %08lx, %08lx\n", fjmp[1], fjmp[0], newbase, size-1,eip);
//printf("src: %08lx, dest : %08lx, size: %08lx\n", base + ProgramOffset, newbase + ProgramOffset, ProgramSize);
DPMI_CopyLinear(newbase + ProgramOffset, base + ProgramOffset, ProgramSize); //after local vars inited
//TODO: we could probably use physical remap instead of jump.
asm("ljmp *%0" :: "m"(fjmp));
switch_space:
asm __volatile__(
"pushw %0\n\t popw %%ds\n\t"
"pushw %0\n\t popw %%es\n\t"
"pushw %0\n\t popw %%ss\n\t"
::"m"(ProgramNewDS)
:"memory");
//*(int*)0=0;
__djgpp_ds_alias_old = __djgpp_ds_alias;
__djgpp_base_address_old = __djgpp_base_address;
__djgpp_ds_alias = ProgramNewDS;
__djgpp_base_address = newbase;
//make address persistent
_crt0_startup_flags = (_crt0_startup_flags&~_CRT0_FLAG_UNIX_SBRK) | _CRT0_FLAG_NONMOVE_SBRK;
return TRUE;
} | //copy self to new linear base (relloc)
//poffset: start offset of code/data with current segment base addr
//psize: total size starting at current segment base addr | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/sbemu/dpmi/dpmi_tsr.c#L55-L192 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
SBEMU | github_2023 | crazii | c | DPMI_ShutdownTSR | BOOL DPMI_ShutdownTSR(void)
{
volatile uint32_t PreventOptimize;//prevent optimization out code after ljmp
asm __volatile__("xor %0, %0":"=r"(PreventOptimize) : :"memory");
if(PreventOptimize)
goto switch_back;
uint32_t fjmp[2] = {(uintptr_t)&&switch_back, ProgramOldCS};
uintptr_t oldend = ProgramSize + ProgramOffset;
uintptr_t end = (uintptr_t)sbrk(0);
//assert(oldend <= end);
if(end > oldend)
{
/*asm __volatile__("pushw %0\n\t popw %%ds\n\t" ::"m"(ProgramOldDS));
sbrk(end-oldend);
asm __volatile__("pushw %0\n\t popw %%ds\n\t": :"m"(ProgramNewDS));*/
//ProgramSize = end - ProgramOffset;
}
__djgpp_exception_toggle();
int x = __dpmi_get_and_disable_virtual_interrupt_state();
//DPMI_CopyLinear(__djgpp_base_address_old + ProgramOffset, __djgpp_base_address + ProgramOffset, ProgramSize);
uint32_t stack = SectionOffset[2] + SectionSize[2];
DPMI_CopyLinear(__djgpp_base_address_old + stack, __djgpp_base_address + stack, ProgramSize-stack);
__dpmi_get_and_set_virtual_interrupt_state(x);
__djgpp_exception_toggle();
asm("ljmp *%0" :: "m"(fjmp));
switch_back:
asm __volatile__( //if we don't copy data back, we must restore data segs after jump(cs seg)
"pushw %0\n\t popw %%es\n\t"
"pushw %0\n\t popw %%ss\n\t"
"pushw %0\n\t popw %%ds\n\t"
:
:"m"(ProgramOldDS)
:"memory");
/*
__djgpp_ds_alias = __djgpp_ds_alias_old;
__djgpp_base_address = __djgpp_base_address_old;
__djgpp_ds_alias_old = 0;
__djgpp_base_address_old = 0;
*/
__dpmi_free_ldt_descriptor(ProgramNewCS);
__dpmi_free_ldt_descriptor(ProgramNewDS);
ProgramNewCS = ProgramNewDS = 0;
//*(int*)0=0;
return TRUE;
} | //enable normal exit, if fails out before TSR | https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/sbemu/dpmi/dpmi_tsr.c#L195-L242 | f0cbde063396deb2c1246c9b3108a37755c68e9a |
kurento | github_2023 | Kurento | c | send_dummy_event | static void
send_dummy_event (GstPad * pad)
{
GstElement *parent = gst_pad_get_parent_element (pad);
if (parent == NULL) {
return;
}
if (GST_PAD_IS_SINK (pad)) {
gst_pad_send_event (pad,
gst_event_new_custom (GST_EVENT_TYPE_DOWNSTREAM |
GST_EVENT_TYPE_SERIALIZED,
gst_structure_new_from_string ("dummy")));
} else {
gst_pad_send_event (pad,
gst_event_new_custom (GST_EVENT_TYPE_UPSTREAM |
GST_EVENT_TYPE_SERIALIZED,
gst_structure_new_from_string ("dummy")));
}
g_object_unref (parent);
} | /*
* This function sends a dummy event to force blocked probe to be called
*/ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/kmsagnosticbin.c#L157-L179 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | remove_element_on_unlinked | static void
remove_element_on_unlinked (GstElement * element, const gchar * pad_name,
gchar * sink_name)
{
GstPad *pad = gst_element_get_static_pad (element, pad_name);
if (pad == NULL) {
return;
}
g_signal_connect (pad, "unlinked", G_CALLBACK (remove_on_unlinked_cb),
sink_name);
g_object_unref (pad);
} | /* Sink name should be static memory */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/kmsagnosticbin.c#L309-L323 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_agnostic_bin2_link_pad | static void
kms_agnostic_bin2_link_pad (KmsAgnosticBin2 * self, GstPad * pad, GstPad * peer)
{
GstCaps *pad_caps, *peer_caps;
GstBin *bin;
GST_TRACE_OBJECT (self, "Linking: %" GST_PTR_FORMAT
" to %" GST_PTR_FORMAT, pad, peer);
// FIXME: There is a corner case not well covered by current implementation that is triggered for example
// when we chain two GStreamerFilters
// The point is that at the time of pad linking caps are ot yet fixed and that causes uncertainties on the
// correct decoder/coder configuration. On the example given, source pad may show an ANY caps
// and the sink will accept the same pads accedted by the gstreamer element sink pad in the filter
// If that happens, at link time an enctreebin with an encoder suited to any of the accepted caps on Gstreamer
// element sink pad will be chosen and inserted in place.
// The problem is that later on, the source caps may get fixed and it happens as the encoder on the sink pad is already
// chosen so the sink pads are already fixed, causing the source element agnostic bin to create an encoder
// to encode to the requested caps.
// In the example tested: two consecutive GStreamerFilter, first with an audiorate, and second with a videorate
// First one will transcode video from whatever codec is (e.g. VP8) to the first codec selected for videorate caps
// that is jpegencoder, While a first decoding to video/x-raw would have been more efficient and had also
// matched the required in videorate source caps.
// One possible fix would be to reset enctreebin and dectreebin compoennts so that the codec chosen on
// initial negotiation is not forced
pad_caps = gst_pad_query_caps (pad, NULL);
if (pad_caps != NULL) {
GST_DEBUG_OBJECT (self, "Upstream provided caps: %" GST_PTR_FORMAT, pad_caps);
gst_caps_unref (pad_caps);
}
peer_caps = gst_pad_query_caps (peer, NULL);
if (peer_caps == NULL) {
goto end;
}
GST_DEBUG_OBJECT (self, "Downstream wanted caps: %" GST_PTR_FORMAT, peer_caps);
bin = kms_agnostic_bin2_find_or_create_bin_for_caps (self, &peer_caps);
if (bin != NULL) {
GstElement *tee = kms_tree_bin_get_output_tee (KMS_TREE_BIN (bin));
if (!kms_utils_caps_is_rtp (peer_caps)) {
kms_utils_drop_until_keyframe (pad, TRUE);
}
kms_agnostic_bin2_link_to_tee (self, pad, tee, peer_caps);
}
gst_caps_unref (peer_caps);
end:
g_object_unref (peer);
} | /**
* Link a pad internally
*
* @self: The #KmsAgnosticBin2 owner of the pad
* @pad: (transfer full): The pad to be linked
* @peer: (transfer full): The peer pad
*/ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/kmsagnosticbin.c#L789-L842 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_agnostic_bin2_process_pad | static gboolean
kms_agnostic_bin2_process_pad (KmsAgnosticBin2 * self, GstPad * pad)
{
GstPad *peer = NULL;
if (!GST_OBJECT_FLAG_IS_SET (pad, KMS_AGNOSTIC_PAD_STARTED)) {
return FALSE;
}
if (!self->priv->started) {
return FALSE;
}
GST_TRACE_OBJECT (self, "Processing pad: %" GST_PTR_FORMAT, pad);
if (pad == NULL) {
return FALSE;
}
peer = gst_pad_get_peer (pad);
if (peer != NULL) {
GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
if (target) {
GstCaps *caps = gst_pad_get_current_caps (pad);
if (caps != NULL) {
gboolean accepted;
accepted = gst_pad_query_accept_caps (peer, caps);
gst_caps_unref (caps);
if (accepted) {
GST_TRACE_OBJECT (self, "No need to reconfigure pad %" GST_PTR_FORMAT,
pad);
g_object_unref (target);
g_object_unref (peer);
return FALSE;
}
remove_target_pad (pad);
}
g_object_unref (target);
}
kms_agnostic_bin2_link_pad (self, pad, peer);
}
return TRUE;
} | /**
* Process a pad for connecting or disconnecting, it should be always called
* with the agnostic lock hold.
*
* @self: The #KmsAgnosticBin2 owner of the pad
* @pad: The pad to be processed
*/ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/kmsagnosticbin.c#L851-L902 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | ext_data_destroy | static void
ext_data_destroy (ExtData * edata)
{
g_slice_free (ExtData, edata);
} | /* RtpMediaConfig end */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsbasertpendpoint.c#L189-L193 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | on_offer_media_direction | static GstSDPDirection
on_offer_media_direction (KmsSdpMediaDirectionExt * ext,
KmsBaseRtpEndpoint * self)
{
GstSDPDirection offer_dir;
g_object_get (self, "offer-dir", &offer_dir, NULL);
return offer_dir;
} | /* RTP hdrext end */
/* Media handler management begin */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsbasertpendpoint.c#L497-L506 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_base_rtp_endpoint_request_local_key_frame | static gboolean
kms_base_rtp_endpoint_request_local_key_frame (KmsBaseRtpEndpoint * self)
{
GstPad *pad;
GstEvent *event;
gboolean ret;
GST_DEBUG_OBJECT (self, "Forcing a new keyframe request");
pad =
gst_element_get_static_pad (self->priv->rtpbin,
VIDEO_RTPBIN_SEND_RTP_SRC);
if (pad == NULL) {
GST_WARNING_OBJECT (self,
"Keyframe request failed: No output configured (must be requested from a subscriber element)");
return FALSE;
}
event =
gst_video_event_new_upstream_force_key_unit (GST_CLOCK_TIME_NONE,
TRUE, 0);
ret = gst_pad_send_event (pad, event);
g_object_unref (pad);
if (ret == FALSE) {
GST_WARNING_OBJECT (self,
"Keyframe request failed: Event not handled (must be requested from a subscriber element)");
}
return ret;
} | /* Start Transport Send end */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsbasertpendpoint.c#L1160-L1190 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_base_rtp_endpoint_connect_input_elements | static void
kms_base_rtp_endpoint_connect_input_elements (KmsBaseSdpEndpoint *
base_endpoint, KmsSdpSession * sess)
{
KmsBaseRtpEndpoint *self = KMS_BASE_RTP_ENDPOINT (base_endpoint);
KmsBaseRtpSession *base_rtp_sess = KMS_BASE_RTP_SESSION (sess);
guint i, len;
len = gst_sdp_message_medias_len (sess->neg_sdp);
for (i = 0; i < len; i++) {
const GstSDPMedia *neg_media = gst_sdp_message_get_media (sess->neg_sdp, i);
KmsSdpMediaHandler *handler;
const gchar *media;
if (sdp_utils_media_is_inactive (neg_media)) {
GST_DEBUG_OBJECT (self, "Media at possition %u is inactive", i);
continue;
}
handler = kms_sdp_agent_get_handler_by_index (sess->agent, i);
if (handler == NULL) {
GST_ERROR_OBJECT (self, "No media handler got for media at %u", i);
continue;
}
media = gst_sdp_media_get_media (neg_media);
if (g_strcmp0 (media, AUDIO_STREAM_NAME) == 0 ||
g_strcmp0 (media, VIDEO_STREAM_NAME) == 0) {
kms_base_rtp_endpoint_set_media_payloader (self, base_rtp_sess, handler,
neg_media);
}
g_object_unref (handler);
}
} | /* Payloading configuration end */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsbasertpendpoint.c#L1611-L1648 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | connection_state_changed | static void
connection_state_changed (KmsSdpSession * sess, guint new_state,
KmsBaseRtpEndpoint * self)
{
g_signal_emit (self, obj_signals[CONNECTION_STATE_CHANGED], 0, sess->id_str,
new_state);
} | /* Connect input elements end */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsbasertpendpoint.c#L1652-L1658 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_base_rtp_endpoint_jitterbuffer_set_latency | static void
kms_base_rtp_endpoint_jitterbuffer_set_latency (GstElement * jitterbuffer,
gint latency)
{
GstPad *src_pad;
GST_INFO_OBJECT (jitterbuffer, "Add probe: Set jitterbuffer latency");
src_pad = gst_element_get_static_pad (jitterbuffer, "src");
gst_pad_add_probe (src_pad,
GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
kms_base_rtp_endpoint_jitterbuffer_set_latency_probe,
GINT_TO_POINTER (latency), NULL);
g_object_unref (src_pad);
} | // Latency is set only when there are actual buffers flowing out | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsbasertpendpoint.c#L1993-L2007 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | ssrcs_are_mapped | static gboolean
ssrcs_are_mapped (GstElement * ssrcdemux,
guint32 local_ssrc, guint32 remote_ssrc)
{
GstElement *rtcpdemux =
g_object_get_qdata (G_OBJECT (ssrcdemux), rtcp_demux_peer_quark ());
guint local_ssrc_pair;
g_signal_emit_by_name (rtcpdemux, "get-local-rr-ssrc-pair", remote_ssrc,
&local_ssrc_pair);
return ((local_ssrc != SSRC_INVALID) && (local_ssrc_pair == local_ssrc));
} | /* Connection management end */
/* Start Transport Send begin */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsbasertpsession.c#L282-L294 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_base_rtp_session_enable_connection_stats | static void
kms_base_rtp_session_enable_connection_stats (gpointer key, gpointer value,
gpointer user_data)
{
kms_i_rtp_connection_collect_latency_stats (KMS_I_RTP_CONNECTION (value),
TRUE);
} | /* Start Transport Send end */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsbasertpsession.c#L784-L790 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_base_sdp_endpoint_configure_media | static gboolean
kms_base_sdp_endpoint_configure_media (KmsSdpAgent * agent,
KmsSdpMediaHandler * handler, GstSDPMedia * media, gpointer user_data)
{
KmsSdpSession *sess = KMS_SDP_SESSION (user_data);
KmsBaseSdpEndpointClass *base_sdp_endpoint_class =
KMS_BASE_SDP_ENDPOINT_CLASS (G_OBJECT_GET_CLASS (sess->ep));
gint id, index;
g_object_get (handler, "id", &id, "index", &index, NULL);
GST_LOG ("Handler id: %d, SDP index: %d, Media: %s", id, index,
gst_sdp_media_get_media (media));
return base_sdp_endpoint_class->configure_media (sess->ep, sess, handler,
media);
} | /* KmsSdpSession begin */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsbasesdpendpoint.c#L122-L138 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_base_sdp_endpoint_create_media_handler_impl | static void
kms_base_sdp_endpoint_create_media_handler_impl (KmsBaseSdpEndpoint * self,
const gchar * media, KmsSdpMediaHandler ** handler)
{
KmsBaseSdpEndpointClass *klass =
KMS_BASE_SDP_ENDPOINT_CLASS (G_OBJECT_GET_CLASS (self));
if (klass->create_media_handler ==
kms_base_sdp_endpoint_create_media_handler_impl) {
GST_WARNING_OBJECT (self, "%s does not reimplement 'create_media_handler'",
G_OBJECT_CLASS_NAME (klass));
}
} | /* KmsSdpSession end */
/* Media handler management begin */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsbasesdpendpoint.c#L316-L328 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | check_caps_probe | static GstPadProbeReturn
check_caps_probe (GstPad * pad, GstPadProbeInfo * info, gpointer data)
{
int width, height;
GstCaps *filter_caps, *caps;
GstElement *element;
GstStructure *st;
gboolean needs_filter = FALSE;
GstEvent *event = gst_pad_probe_info_get_event (info);
if (GST_EVENT_TYPE (event) != GST_EVENT_CAPS) {
return GST_PAD_PROBE_OK;
}
gst_event_parse_caps (event, &caps);
st = gst_caps_get_structure (caps, 0);
gst_structure_get (st, "width", G_TYPE_INT, &width, NULL);
gst_structure_get (st, "height", G_TYPE_INT, &height, NULL);
if (width % 2) {
GST_WARNING ("Width is odd");
needs_filter = TRUE;
width--;
}
if (height % 2) {
GST_WARNING ("Height is odd");
needs_filter = TRUE;
height--;
}
if (!needs_filter)
return GST_PAD_PROBE_OK;
filter_caps = gst_caps_from_string ("video/x-raw,format=I420");
gst_caps_set_simple (filter_caps, "width", G_TYPE_INT, width, NULL);
gst_caps_set_simple (filter_caps, "height", G_TYPE_INT, height, NULL);
element = gst_pad_get_parent_element (pad);
g_object_set (element, "caps", filter_caps, NULL);
gst_caps_unref (filter_caps);
g_object_unref (element);
return GST_PAD_PROBE_OK;
} | /*
* FIXME: This is a hack to make x264 work.
*
* We have notice that x264 doesn't work if width or height is odd,
* so we force a rescale increasing one pixel that dimension
* when we detect this situation.
*/ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsenctreebin.c#L457-L504 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_remb_local_on_sending_rtcp | static gboolean
kms_remb_local_on_sending_rtcp (GObject *rtpsession,
GstBuffer *buffer, gboolean is_early, KmsRembLocal *self)
{
gboolean ret = FALSE;
GstClockTime current_time, elapsed;
KmsRTCPPSFBAFBREMBPacket remb_packet;
GstRTCPBuffer rtcp = {0,};
GstRTCPPacket packet;
guint packet_ssrc;
AddSsrcsData data;
GST_LOG_OBJECT (rtpsession, "Signal \"RTPSession::on-sending-rtcp\" ...");
current_time = kms_utils_get_time_nsecs ();
elapsed = current_time - self->last_sent_time;
if (self->last_sent_time != 0 && (elapsed < REMB_MAX_INTERVAL * GST_MSECOND)) {
GST_LOG_OBJECT (rtpsession, "... Not sending: Interval < %u ms", REMB_MAX_INTERVAL);
return ret;
}
if (!gst_rtcp_buffer_map (buffer, GST_MAP_READWRITE, &rtcp)) {
GST_WARNING_OBJECT (rtpsession, "... Cannot map RTCP buffer");
return ret;
}
if (!gst_rtcp_buffer_add_packet (&rtcp, GST_RTCP_TYPE_PSFB, &packet)) {
GST_WARNING_OBJECT (rtpsession, "... Cannot add RTCP packet");
goto end;
}
// Update the REMB bitrate estimations
if (!kms_remb_local_update (self)) {
GST_LOG_OBJECT (rtpsession, "... Not sending: Stats not updated");
gst_rtcp_packet_remove (&packet);
goto end;
}
//const guint32 old_bitrate = self->remb_sent;
guint32 new_bitrate = self->remb;
if (self->event_manager != NULL) {
guint remb_local_max;
remb_local_max = kms_utils_remb_event_manager_get_min (self->event_manager);
if (remb_local_max > 0) {
GST_TRACE_OBJECT (rtpsession, "Local max: %" G_GUINT32_FORMAT,
remb_local_max);
new_bitrate = MIN (new_bitrate, remb_local_max);
}
}
if (self->min_bw > 0) {
new_bitrate = MAX (new_bitrate, self->min_bw * 1000);
}
new_bitrate = MAX (new_bitrate, REMB_MIN);
self->remb_sent = new_bitrate;
remb_packet.bitrate = new_bitrate;
remb_packet.n_ssrcs = 0;
data.rl = self;
data.remb_packet = &remb_packet;
g_slist_foreach (self->remote_sessions, (GFunc) add_ssrcs, &data);
g_object_get (rtpsession, "internal-ssrc", &packet_ssrc, NULL);
if (!kms_rtcp_psfb_afb_remb_marshall_packet (&packet, &remb_packet,
packet_ssrc)) {
gst_rtcp_packet_remove (&packet);
}
self->last_sent_time = current_time;
ret = TRUE;
end:
gst_rtcp_buffer_unmap (&rtcp);
return ret;
} | // Signal "RTPSession::on-sending-rtcp" doc: GStreamer/rtpsession.c | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsremb.c#L452-L530 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | is_remb | static gboolean
is_remb (KmsRTCPPSFBAFBPacket * packet)
{
GstMapInfo map = packet->rtcp_psfb_afb->map;
guint8 *fci = map.data;
if (map.size < 4) {
return FALSE;
}
return (memcmp (fci, "REMB", 4) == 0);
} | /* REMB begin */
// Receiver Estimated Max Bitrate (REMB) (draft-alvestrand-rmcat-remb).
//
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| FMT=15 | PT=206 | length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of packet sender |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of media source |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Unique identifier 'R' 'E' 'M' 'B' |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Num SSRC | BR Exp | BR Mantissa |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC feedback |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | ... |
/* Inspired in The WebRTC project */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsrtcp.c#L75-L86 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_rtcp_psfb_afb_remb_get_packet | gboolean
kms_rtcp_psfb_afb_remb_get_packet (KmsRTCPPSFBAFBPacket * afb_packet,
KmsRTCPPSFBAFBREMBPacket * remb_packet)
{
GstMapInfo map;
guint length;
guint8 *fci, *fci_end, br_exp;
guint32 br_mantissa;
int i;
g_return_val_if_fail (afb_packet != NULL, FALSE);
g_return_val_if_fail (afb_packet->type == KMS_RTCP_PSFB_AFB_TYPE_REMB, FALSE);
g_return_val_if_fail (GST_IS_BUFFER (afb_packet->rtcp_psfb_afb->buffer),
FALSE);
g_return_val_if_fail (afb_packet->rtcp_psfb_afb->map.flags & GST_MAP_READ,
FALSE);
g_return_val_if_fail (remb_packet != NULL, FALSE);
map = afb_packet->rtcp_psfb_afb->map;
fci = map.data;
length = map.size;
fci_end = map.data + length;
if (!is_remb (afb_packet)) {
GST_ERROR ("This is not a REMB packet");
return FALSE;
}
fci += 4; /* Previously consumed by is_remb */
length = fci_end - fci;
if (length < 4) {
GST_ERROR ("Inconsistent REMB packet length)");
return FALSE;
}
remb_packet->n_ssrcs = *fci++;
br_exp = (fci[0] >> 2) & 0x3F;
br_mantissa = (fci[0] & 0x03) << 16;
br_mantissa += (fci[1] << 8);
br_mantissa += (fci[2]);
remb_packet->bitrate = br_mantissa << br_exp;
fci += 3;
length = fci_end - fci;
if (length < 4 * remb_packet->n_ssrcs) {
GST_ERROR ("Inconsistent REMB packet (n_ssrcs)");
return FALSE;
}
for (i = 0; i < remb_packet->n_ssrcs; i++) {
remb_packet->ssrcs[i] = g_ntohl (*(guint32 *) fci);
fci += 4;
}
return TRUE;
} | /* Inspired in The WebRTC project */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsrtcp.c#L121-L177 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | compute_mantissa_and_6_bit_base_2_expoonent | static gboolean
compute_mantissa_and_6_bit_base_2_expoonent (guint32 input_base10,
guint8 bits_mantissa, guint32 * mantissa, guint8 * exp)
{
guint32 mantissa_max;
guint8 exponent = 0;
gint i;
/* input_base10 = mantissa * 2^exp */
if (bits_mantissa > 32) {
GST_ERROR ("bits_mantissa must be <= 32");
return FALSE;
}
mantissa_max = (1 << bits_mantissa) - 1;
for (i = 0; i < 64; ++i) {
if (input_base10 <= (mantissa_max << i)) {
exponent = i;
break;
}
}
*exp = exponent;
*mantissa = input_base10 >> exponent;
return TRUE;
} | /* Inspired in The WebRTC project */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsrtcp.c#L180-L207 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_utils_bin_remove | void
kms_utils_bin_remove (GstBin * bin, GstElement * element)
{
GST_DEBUG ("Remove %" GST_PTR_FORMAT " from %" GST_PTR_FORMAT, element, bin);
if (!gst_element_set_locked_state (element, TRUE)) {
GST_ERROR ("Cannot lock element %" GST_PTR_FORMAT, element);
}
gst_element_set_state (element, GST_STATE_NULL);
// gst_bin_remove() unlinks all pads and unrefs the object
gst_bin_remove (bin, element);
} | /* ---- GstBin ---- */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsutils.c#L112-L125 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | is_dropping | static inline gboolean
is_dropping (GstPad * pad)
{
return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (pad),
dropping_until_key_frame_quark ()));
} | /* Call this function holding the lock */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsutils.c#L335-L340 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | set_dropping | static inline void
set_dropping (GstPad * pad, gboolean dropping)
{
g_object_set_qdata (G_OBJECT (pad), dropping_until_key_frame_quark (),
GINT_TO_POINTER (dropping));
} | /* Call this function holding the lock */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsutils.c#L343-L348 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | send_dummy_event | static void
send_dummy_event (GstPad * pad, const gchar * name)
{
GstElement *parent = gst_pad_get_parent_element (pad);
if (parent == NULL) {
return;
}
if (GST_PAD_IS_SINK (pad)) {
gst_pad_send_event (pad,
gst_event_new_custom (GST_EVENT_TYPE_DOWNSTREAM |
GST_EVENT_TYPE_SERIALIZED, gst_structure_new_empty (name)));
} else {
gst_pad_send_event (pad,
gst_event_new_custom (GST_EVENT_TYPE_UPSTREAM |
GST_EVENT_TYPE_SERIALIZED, gst_structure_new_empty (name)));
}
g_object_unref (parent);
} | /*
* This function sends a dummy event to force blocked probe to be called
*/ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsutils.c#L696-L716 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_utils_get_time_nsecs | GstClockTime
kms_utils_get_time_nsecs ()
{
GstClockTime time;
time = g_get_monotonic_time () * GST_USECOND;
return time;
} | /* REMB event end */
/* time begin */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsutils.c#L1088-L1096 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_utils_contains_proto | gboolean
kms_utils_contains_proto (const gchar * search_term, const gchar * proto)
{
gchar *pattern;
GRegex *regex;
gboolean ret;
pattern = g_strdup_printf ("(%s|.+/%s|%s/.+|.+/%s/.+)", proto, proto, proto,
proto);
regex = g_regex_new (pattern, 0, 0, NULL);
ret = g_regex_match (regex, search_term, G_REGEX_MATCH_ANCHORED, NULL);
g_regex_unref (regex);
g_free (pattern);
return ret;
} | /* time end */
/* RTP connection end */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/kmsutils.c#L1102-L1117 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_sdp_agent_add_proto_handler | gint
kms_sdp_agent_add_proto_handler (KmsSdpAgent * agent, const gchar * media,
KmsSdpMediaHandler * handler, GError ** error)
{
g_return_val_if_fail (KMS_IS_SDP_AGENT (agent), -1);
return KMS_SDP_AGENT_GET_CLASS (agent)->add_proto_handler (agent, media,
handler, error);
} | /* TODO: rename to _add_media_handler */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/src/gst-plugins/commons/sdpagent/kmssdpagent.c#L2130-L2138 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | remove_audiotestsrc | static gboolean
remove_audiotestsrc (GstElement * audiotestsrc)
{
GstElement *pipeline = GST_ELEMENT (gst_element_get_parent (audiotestsrc));
GST_DEBUG ("Remove element %" GST_PTR_FORMAT, audiotestsrc);
gst_object_ref (audiotestsrc);
gst_element_set_locked_state (audiotestsrc, TRUE);
gst_element_set_state (audiotestsrc, GST_STATE_NULL);
if (!gst_bin_remove (GST_BIN (pipeline), audiotestsrc))
GST_ERROR ("Can not remove %" GST_PTR_FORMAT, audiotestsrc);
gst_object_unref (pipeline);
gst_object_unref (audiotestsrc);
return G_SOURCE_REMOVE;
} | // ENABLE_EXPERIMENTAL_TESTS | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-core/tests/check/element/audiomixerbin.c#L241-L258 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_player_endpoint_disable_latency_probe | static void
kms_player_endpoint_disable_latency_probe (KmsPlayerEndpoint * self)
{
GstPad *pad;
if (self->priv->stats.src == NULL || self->priv->stats.meta_id == 0UL) {
return;
}
pad = gst_element_get_static_pad (self->priv->stats.src, "src");
if (pad == NULL) {
GST_WARNING_OBJECT (self, "No source pad got from %" GST_PTR_FORMAT,
self->priv->stats.src);
return;
}
gst_pad_remove_probe (pad, self->priv->stats.meta_id);
self->priv->stats.meta_id = 0UL;
g_object_unref (pad);
} | /* This function must be called holding the element mutex */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-elements/src/gst-plugins/kmsplayerendpoint.c#L287-L308 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_player_endpoint_enable_latency_probe | static void
kms_player_endpoint_enable_latency_probe (KmsPlayerEndpoint * self)
{
GstPad *pad;
if (self->priv->stats.src == NULL) {
GST_DEBUG_OBJECT (self, "No source element for stats is yet available");
return;
}
pad = gst_element_get_static_pad (self->priv->stats.src, "src");
if (pad == NULL) {
GST_WARNING_OBJECT (self, "No source pad got from %" GST_PTR_FORMAT,
self->priv->stats.src);
return;
}
if (self->priv->stats.enabled) {
self->priv->stats.meta_id = kms_stats_add_buffer_latency_meta_probe (pad,
FALSE, 0);
}
g_object_unref (pad);
} | /* This function must be called holding the element mutex */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-elements/src/gst-plugins/kmsplayerendpoint.c#L311-L335 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | recv_sample | static GstFlowReturn
recv_sample (GstAppSink * appsink, gpointer user_data)
{
KmsRecorderEndpoint *self =
KMS_RECORDER_ENDPOINT (GST_OBJECT_PARENT (appsink));
KmsUriEndpointState state = KMS_URI_ENDPOINT_STATE_STOP;
BaseTimeType *base_time = NULL;
GstCaps *caps = NULL;
gboolean unlock_element = FALSE;
GstSample *sample = NULL;
GstFlowReturn ret = GST_FLOW_OK;
GstAppSrc *appsrc =
g_object_get_qdata (G_OBJECT (appsink), kms_appsrc_id_key_quark ());
if (appsrc == NULL) {
GST_ERROR_OBJECT (appsink, "No appsrc attached");
ret = GST_FLOW_NOT_LINKED;
goto end;
}
sample = gst_app_sink_pull_sample (appsink);
if (sample == NULL) {
ret = GST_FLOW_OK;
goto end;
}
GstBuffer *buffer = gst_sample_get_buffer (sample);
if (buffer == NULL) {
if (gst_sample_get_buffer_list (sample) != NULL) {
GST_ERROR_OBJECT (appsink,
"Discarding buffer list at the recorder endpoint");
g_warning ("Discarding buffer list at the recorder endpoint");
}
ret = GST_FLOW_OK;
goto end;
}
const GstSegment *segment = gst_sample_get_segment (sample);
unlock_element = TRUE;
KMS_ELEMENT_LOCK (self);
state = kms_uri_endpoint_get_state (KMS_URI_ENDPOINT (self));
if (!((state == KMS_URI_ENDPOINT_STATE_START &&
self->priv->transition == KMS_RECORDER_ENDPOINT_COMPLETED) ||
self->priv->transition == KMS_RECORDER_ENDPOINT_STARTING)) {
GST_LOG_OBJECT (appsink,
"Not recording, drop buffer %" GST_PTR_FORMAT, buffer);
ret = GST_FLOW_OK;
goto end;
}
gst_buffer_ref (buffer);
buffer = gst_buffer_make_writable (buffer);
// Ensure that PTS/DTS are measured from 00:00:00. Do this by replacing each
// one by their GStreamer running time, which always starts from 0 wrt. its
// containing segment.
{
if (GST_BUFFER_PTS_IS_VALID (buffer)) {
GST_BUFFER_PTS (buffer) = gst_segment_to_running_time (
segment, GST_FORMAT_TIME, GST_BUFFER_PTS (buffer));
}
if (GST_BUFFER_DTS_IS_VALID (buffer)) {
GST_BUFFER_DTS (buffer) = gst_segment_to_running_time (
segment, GST_FORMAT_TIME, GST_BUFFER_DTS (buffer));
}
}
BASE_TIME_LOCK (self);
// First time this runs, create a new BaseTime storage.
{
base_time = g_object_get_qdata (G_OBJECT (self), base_time_key_quark ());
if (base_time == NULL) {
base_time = g_slice_new0 (BaseTimeType);
base_time->pts = GST_CLOCK_TIME_NONE;
base_time->dts = GST_CLOCK_TIME_NONE;
base_time->audio_gaps = 0;
g_object_set_qdata_full (G_OBJECT (self), base_time_key_quark (),
base_time, release_base_time_type);
}
if (!GST_CLOCK_TIME_IS_VALID (base_time->pts)
&& GST_BUFFER_PTS_IS_VALID (buffer)) {
base_time->pts = GST_BUFFER_PTS (buffer);
GST_DEBUG_OBJECT (self, "Setting PTS base time to %" GST_TIME_FORMAT,
GST_TIME_ARGS (base_time->pts));
}
if (!GST_CLOCK_TIME_IS_VALID (base_time->dts)
&& GST_BUFFER_DTS_IS_VALID (buffer)) {
base_time->dts = GST_BUFFER_DTS (buffer);
GST_DEBUG_OBJECT (self, "Setting DTS base time to %" GST_TIME_FORMAT,
GST_TIME_ARGS (base_time->dts));
}
}
// Adjust PTS/DTS of all buffers, so recordings are always created with an
// initial timestamp of 0 (0:00:00.000).
{
// FIXME: There is some skew introduced each time the recording is paused.
// The 'paused_time' doesn't account exactly for all the time, it is missing
// some milliseconds. Maybe due to latency in upstream elements?
GstClockTime common_offset = self->priv->paused_time;
if (self->priv->gaps_fix == KMS_RECORDER_GAPS_FIX_GENPTS) {
// In GenPTS mode, add the total time that has been lost in the form
// of gaps, typically caused by packet loss from an RTP source.
common_offset += base_time->audio_gaps;
}
if (GST_CLOCK_TIME_IS_VALID (base_time->pts)
&& GST_BUFFER_PTS_IS_VALID (buffer)) {
const GstClockTime offset = common_offset + base_time->pts;
// PTS -= offset, but preventing underflows.
if (GST_BUFFER_PTS (buffer) > offset) {
GST_BUFFER_PTS (buffer) -= offset;
} else {
GST_BUFFER_PTS (buffer) = 0;
}
}
if (GST_CLOCK_TIME_IS_VALID (base_time->dts)
&& GST_BUFFER_DTS_IS_VALID (buffer)) {
const GstClockTime offset = common_offset + base_time->dts;
// DTS -= offset, but preventing underflows.
if (GST_BUFFER_DTS (buffer) > offset) {
GST_BUFFER_DTS (buffer) -= offset;
} else {
GST_BUFFER_DTS (buffer) = 0;
}
}
}
BASE_TIME_UNLOCK (self);
// Set some flags to make sure the buffer is appropriately handled downstream.
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_LIVE);
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_HEADER)) {
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
}
KMS_ELEMENT_UNLOCK (self);
unlock_element = FALSE;
caps = gst_app_src_get_caps (appsrc);
if (caps == NULL) {
GST_ERROR_OBJECT (appsrc, "Trying to push buffer without setting caps");
} else {
gst_caps_unref (caps);
}
ret = gst_app_src_push_buffer (appsrc, buffer);
if (ret != GST_FLOW_OK) {
GST_ERROR_OBJECT (self, "Could not send buffer to appsrc %s. Cause: %s",
GST_ELEMENT_NAME (appsrc), gst_flow_get_name (ret));
ret = GST_FLOW_CUSTOM_SUCCESS;
}
end:
if (unlock_element) {
KMS_ELEMENT_UNLOCK (self);
}
if (sample != NULL) {
gst_sample_unref (sample);
}
return ret;
} | // Adjust timestamps to avoid gaps created by paused recordings. | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-elements/src/gst-plugins/recorderendpoint/kmsrecorderendpoint.c#L274-L451 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_recorder_endpoint_send_eos_to_appsrcs | static guint
kms_recorder_endpoint_send_eos_to_appsrcs (KmsRecorderEndpoint * self)
{
guint size;
KMS_ELEMENT_UNLOCK (self);
SRCS_LOCK (self);
size = g_hash_table_size (self->priv->srcs);
if (size == 0) {
kms_base_media_muxer_set_state (self->priv->mux, GST_STATE_NULL);
goto end;
}
kms_base_media_muxer_set_state (self->priv->mux, GST_STATE_PLAYING);
g_hash_table_foreach (self->priv->srcs, (GHFunc) send_eos_cb, NULL);
end:
SRCS_UNLOCK (self);
KMS_ELEMENT_LOCK (self);
return size;
} | /*
* It should be always called with the element lock hold.
*/ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-elements/src/gst-plugins/recorderendpoint/kmsrecorderendpoint.c#L553-L576 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_rtp_endpoint_set_addr | static void
kms_rtp_endpoint_set_addr (KmsRtpEndpoint * self)
{
GList *ips, *l;
gboolean done = FALSE;
ips = nice_interfaces_get_local_ips (FALSE);
for (l = ips; l != NULL && !done; l = l->next) {
GInetAddress *addr;
gboolean is_ipv6 = FALSE;
GST_DEBUG_OBJECT (self, "Check local address: %s", (const gchar*)l->data);
addr = g_inet_address_new_from_string (l->data);
if (G_IS_INET_ADDRESS (addr)) {
switch (g_inet_address_get_family (addr)) {
case G_SOCKET_FAMILY_INVALID:
case G_SOCKET_FAMILY_UNIX:
/* Ignore this addresses */
break;
case G_SOCKET_FAMILY_IPV6:
is_ipv6 = TRUE;
case G_SOCKET_FAMILY_IPV4:
{
gchar *addr_str;
gboolean use_ipv6;
g_object_get (self, "use-ipv6", &use_ipv6, NULL);
if (is_ipv6 != use_ipv6) {
GST_DEBUG_OBJECT (self, "Skip address (wanted IPv6: %d)", use_ipv6);
break;
}
addr_str = g_inet_address_to_string (addr);
if (addr_str != NULL) {
g_object_set (self, "addr", addr_str, NULL);
g_free (addr_str);
done = TRUE;
}
break;
}
}
}
if (G_IS_OBJECT (addr)) {
g_object_unref (addr);
}
}
g_list_free_full (ips, g_free);
if (!done) {
GST_WARNING_OBJECT (self, "Addr not set");
}
} | /* Internal session management begin */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-elements/src/gst-plugins/rtpendpoint/kmsrtpendpoint.c#L321-L375 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | get_max_key_size | static guint
get_max_key_size (SrtpCryptoSuite crypto)
{
switch (crypto) {
case KMS_SDES_EXT_AES_CM_128_HMAC_SHA1_32:
case KMS_SDES_EXT_AES_CM_128_HMAC_SHA1_80:
return KMS_SRTP_CIPHER_AES_CM_128_SIZE;
case KMS_SDES_EXT_AES_256_CM_HMAC_SHA1_32:
case KMS_SDES_EXT_AES_256_CM_HMAC_SHA1_80:
return KMS_SRTP_CIPHER_AES_CM_256_SIZE;
default:
return 0;
}
} | /* Internal session management end */
/* Media handler management begin */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-elements/src/gst-plugins/rtpendpoint/kmsrtpendpoint.c#L408-L421 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_rtp_endpoint_configure_connection_keys | static void
kms_rtp_endpoint_configure_connection_keys (KmsRtpEndpoint * self,
KmsRtpBaseConnection * conn, const gchar * media)
{
SdesKeys *sdes_keys;
KMS_ELEMENT_LOCK (self);
sdes_keys = g_hash_table_lookup (self->priv->sdes_keys, media);
if (sdes_keys == NULL) {
GST_ERROR_OBJECT (self, "No keys configured for %s connection", media);
goto end;
} else {
sdes_keys->conn = g_object_ref (conn);
}
if (!kms_rtp_endpoint_set_local_srtp_connection_key (self, media, sdes_keys)) {
GST_ERROR_OBJECT (self, "Can not configure local connection key");
goto end;
}
kms_rtp_endpoint_set_remote_srtp_connection_key (self, media, sdes_keys);
end:
KMS_ELEMENT_UNLOCK (self);
} | /* Media handler management end */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-elements/src/gst-plugins/rtpendpoint/kmsrtpendpoint.c#L698-L724 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
kurento | github_2023 | Kurento | c | kms_rtp_endpoint_configure_media | static gboolean
kms_rtp_endpoint_configure_media (KmsBaseSdpEndpoint * base_sdp_endpoint,
KmsSdpSession * sess, KmsSdpMediaHandler * handler, GstSDPMedia * media)
{
KmsRtpEndpoint *self = KMS_RTP_ENDPOINT (base_sdp_endpoint);
guint conn_len, c;
guint attr_len, a;
KmsRtpBaseConnection *conn;
gboolean ret = TRUE;
/* Chain up */
ret = KMS_BASE_SDP_ENDPOINT_CLASS
(kms_rtp_endpoint_parent_class)->configure_media (base_sdp_endpoint, sess,
handler, media);
if (ret == FALSE) {
media->port = 0;
GST_WARNING_OBJECT (base_sdp_endpoint,
"Setting port to 0 because connection could not be created");
return FALSE;
}
conn_len = gst_sdp_media_connections_len (media);
for (c = 0; c < conn_len; c++) {
gst_sdp_media_remove_connection (media, c);
}
conn = kms_rtp_endpoint_get_connection (KMS_RTP_ENDPOINT (base_sdp_endpoint),
sess, handler, media);
if (conn == NULL) {
return TRUE;
}
media->port = kms_rtp_base_connection_get_rtp_port (conn);
attr_len = gst_sdp_media_attributes_len (media);
for (a = 0; a < attr_len; a++) {
GstSDPAttribute *attr =
(GstSDPAttribute *) gst_sdp_media_get_attribute (media, a);
if (g_strcmp0 (attr->key, "rtcp") == 0) {
const guint rtcp_port = kms_rtp_base_connection_get_rtcp_port (conn);
g_free (attr->value);
attr->value = g_strdup_printf ("%" G_GUINT32_FORMAT, rtcp_port);
}
}
if (self->priv->use_sdes) {
kms_rtp_endpoint_configure_connection_keys (self, conn,
gst_sdp_media_get_media (media));
}
return TRUE;
} | /* Configure media SDP begin */ | https://github.com/Kurento/kurento/blob/b04c741488b60a10692f08d01e87b8bb08ef0300/server/module-elements/src/gst-plugins/rtpendpoint/kmsrtpendpoint.c#L727-L780 | b04c741488b60a10692f08d01e87b8bb08ef0300 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.