Esempio n. 1
0
void timestamp_apts_inc(s32 inc)
{
	if(audio_pts_up){
#ifdef MODIFY_TIMESTAMP_INC_WITH_PLL
	inc = inc*timestamp_inc_factor/PLL_FACTOR;
#endif
    if(tsync_get_mode()!=TSYNC_MODE_PCRMASTER){//timestamp_enable_resample_flag){
		if(timestamp_resample_type_flag==0){
			//0-->no resample  processing
		}else if(timestamp_resample_type_flag==1){//1-->down resample processing
			#ifdef CONFIG_AMAUDIO
				inc += inc*resample_delta / DEFALT_NUMSAMPS_PERCH;
				acc_apts_inc += inc*resample_delta % DEFALT_NUMSAMPS_PERCH;
				if(acc_apts_inc*resample_delta >= DEFALT_NUMSAMPS_PERCH){
					inc += acc_apts_inc*resample_delta / DEFALT_NUMSAMPS_PERCH;
					acc_apts_inc = acc_apts_inc*resample_delta % DEFALT_NUMSAMPS_PERCH;
				}
			#endif
		}else if(timestamp_resample_type_flag==2){//2-->up resample processing
			#ifdef CONFIG_AMAUDIO
				inc -= inc*resample_delta / DEFALT_NUMSAMPS_PERCH;
				acc_apts_dec += inc*resample_delta % DEFALT_NUMSAMPS_PERCH;
				if(acc_apts_dec*resample_delta >= DEFALT_NUMSAMPS_PERCH){
					inc -= acc_apts_dec*resample_delta / DEFALT_NUMSAMPS_PERCH;
					acc_apts_dec = acc_apts_dec*resample_delta % DEFALT_NUMSAMPS_PERCH;
				}
			#endif
		}
	}
    WRITE_MPEG_REG(AUDIO_PTS, READ_MPEG_REG(AUDIO_PTS) + inc);
	}
}
Esempio n. 2
0
void timestamp_pcrscr_inc(s32 inc)
{
    if (system_time_up) {
#ifdef MODIFY_TIMESTAMP_INC_WITH_PLL
        inc = inc*timestamp_inc_factor/PLL_FACTOR;
#endif
		if(tsync_get_mode()!=TSYNC_MODE_PCRMASTER){//timestamp_enable_resample_flag){
			if(timestamp_resample_type_flag==0){	  //0-->no resample  processing

			}else if(timestamp_resample_type_flag==1){//1-->down resample processing
				#ifdef CONFIG_AMAUDIO
				inc += inc*resample_delta / DEFALT_NUMSAMPS_PERCH;
				acc_pcrscr_inc += inc*resample_delta % DEFALT_NUMSAMPS_PERCH;
				if(acc_pcrscr_inc*resample_delta >= DEFALT_NUMSAMPS_PERCH){
					inc += acc_pcrscr_inc*resample_delta / DEFALT_NUMSAMPS_PERCH;
					acc_pcrscr_inc = acc_pcrscr_inc*resample_delta % DEFALT_NUMSAMPS_PERCH;
				}
				#endif
			}else if(timestamp_resample_type_flag==2){//2-->up resample processing
				#ifdef CONFIG_AMAUDIO
				inc -= inc*resample_delta / DEFALT_NUMSAMPS_PERCH;
				acc_pcrscr_dec += inc*resample_delta % DEFALT_NUMSAMPS_PERCH;
				if(acc_pcrscr_dec*resample_delta >= DEFALT_NUMSAMPS_PERCH){
					inc -= acc_pcrscr_dec*resample_delta / DEFALT_NUMSAMPS_PERCH;
					acc_pcrscr_dec = acc_pcrscr_dec*resample_delta % DEFALT_NUMSAMPS_PERCH;
				}
				#endif
			}
		}
        system_time += inc + system_time_inc_adj;
    }
}
void am_i2s_trigger_output(void)
{
    audio_stream_t *s = NULL;
	if (g_prtd == NULL)
	{
		printk("am_i2s_trigger_output g_prtd == NULL \n");
		return ;
	}
    s = &g_prtd->s;
	if (s == NULL)
	{

		printk("am_i2s_trigger_output g_prtd->s== NULL \n");
		return ;
	}
	if (s->audio_trigger_disable == 1) {
		unsigned int pts_audio, pts_scr;
		//unsigned int pts_audio_cur = 0;
		int sync_mode;

		pts_audio = tsync_get_firstapts();
		pts_scr = timestamp_pcrscr_get();
		sync_mode = tsync_get_mode();

		// when pcr chase to apts,start audio playback
		if ((sync_mode == TSYNC_MODE_PCRMASTER) &&  ((pts_audio <= pts_scr))) {
			s->disable_count = 0;
			s->audio_trigger_disable = 0;
			if (s->device_type == AML_AUDIO_I2SOUT) {
				printk("trigger aiu i2s playback enable audio %x pcr %x disable count %d \n", pts_audio, pts_scr,
				       s->disable_count);
				audio_out_i2s_enable(1);
				audio_hw_958_enable(1);
			}
			else if (s->device_type == AML_AUDIO_SPDIFOUT) {
				printk("trigger aiu 958 playback enable audio %x pcr %x disable count %d\n", pts_audio, pts_scr, s->disable_count);
				audio_hw_958_enable(1);
			}
		}
	}
	else
	{
		printk("s->audio_trigger_disable   %d \n", s->audio_trigger_disable);
	}

}
static int aml_i2s_trigger(struct snd_pcm_substream *substream,
                           int cmd)
{
    struct snd_pcm_runtime *rtd = substream->runtime;
    struct aml_runtime_data *prtd = rtd->private_data;
    audio_stream_t *s = &prtd->s;
    int ret = 0;
    unsigned int pts_audio, pts_scr;
    unsigned int diff = 0;
	int sync_mode;
    ALSA_TRACE();

    switch (cmd) {
    case SNDRV_PCM_TRIGGER_START:
    case SNDRV_PCM_TRIGGER_RESUME:
    case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:

#if USE_HRTIMER == 0 && !defined(USE_HW_TIMER)
        del_timer_sync(&prtd->timer);
#endif
        spin_lock(&s->lock);
#if USE_HRTIMER == 0 && !defined(USE_HW_TIMER)
        prtd->timer.expires = jiffies + 1;
        del_timer(&prtd->timer);
        add_timer(&prtd->timer);
#endif

		pts_audio = tsync_get_firstapts();
		pts_scr = timestamp_pcrscr_get();
		sync_mode = tsync_get_mode();

#if 1
		if (pts_audio > pts_scr)
			diff = pts_audio - pts_scr;
		else
			diff = pts_scr - pts_audio;
		if (IEC958_mode_codec == 0 && sync_mode == TSYNC_MODE_PCRMASTER &&  pts_audio > pts_scr && (pts_audio - pts_scr) < 90 * MAX_APTS_SCR_DELTA) {

			printk("aiu i2s playback enable trigger mode sync_mode %d audio %x pcr %x diff %d \n", sync_mode, pts_audio, pts_scr, diff);
			s->audio_trigger_disable = 1;
		}
		else
#endif

		{
			printk("aiu i2s/958 playback enable sync_mode %d audio %x pcr %x diff %d IEC958_mode_codec %d\n", sync_mode, pts_audio, pts_scr, diff, IEC958_mode_codec);
			s->disable_count = 0;
			s->audio_trigger_disable = 0;
			if (IEC958_mode_codec == 0) {
				printk("aiu i2s/958 playback enable sync_mode %d audio %x pcr %x diff %d \n", sync_mode, pts_audio, pts_scr, diff);
				audio_out_i2s_enable(1);
				audio_hw_958_enable(1);

			}
		}
		s->active = 1;
		spin_unlock(&s->lock);
		break;		/* SNDRV_PCM_TRIGGER_START */
	case SNDRV_PCM_TRIGGER_SUSPEND:
	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
	case SNDRV_PCM_TRIGGER_STOP:
		// TODO
		spin_lock(&s->lock);
		s->audio_trigger_disable = 0;
		s->disable_count = 0;
		if (IEC958_mode_codec == 0)
		{
			printk("aiu i2s playback disable\n");
			audio_out_i2s_enable(0);
			printk("aiu 958 playback disable\n");
			audio_hw_958_enable(0);
		}

		s->active = 0;
		spin_unlock(&s->lock);
		break;
	default:
		ret = -EINVAL;
	}
	/*	if(clock_gating_status&clock_gating_playback){
			if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
				aml_pcm_work.substream = substream;
		}
		else
			aml_pcm_work.substream = substream;


        if (clock_gating_status)
        {
            schedule_work(&aml_pcm_work.aml_codec_workqueue);
        }
        */
    //schedule_work(&aml_pcm_work.aml_codec_workqueue);
    return ret;
}