status_t AudioALSACaptureDataProviderBTSCO::GetCaptureTimeStamp(time_info_struct_t *Time_Info, size_t read_size)
{
    ALOGV("%s()", __FUNCTION__);
    ASSERT(mPcm != NULL);

    long ret_ns;
    size_t avail;
    Time_Info->timestamp_get.tv_sec  = 0;
    Time_Info->timestamp_get.tv_nsec = 0;
    Time_Info->frameInfo_get = 0;
    Time_Info->buffer_per_time = 0;
    Time_Info->kernelbuffer_ns = 0;

    //ALOGD("%s(), Going to check pcm_get_htimestamp", __FUNCTION__);
    if (pcm_get_htimestamp(mPcm, &Time_Info->frameInfo_get, &Time_Info->timestamp_get) == 0)
    {
        Time_Info->buffer_per_time = pcm_bytes_to_frames(mPcm, read_size);
        Time_Info->kernelbuffer_ns = 1000000000 / mStreamAttributeSource.sample_rate * (Time_Info->buffer_per_time + Time_Info->frameInfo_get);
        ALOGV("%s pcm_get_htimestamp sec= %ld, nsec=%ld, frameInfo_get = %d, buffer_per_time=%d, ret_ns = %ld\n",
              __FUNCTION__, Time_Info->timestamp_get.tv_sec, Time_Info->timestamp_get.tv_nsec, Time_Info->frameInfo_get,
              Time_Info->buffer_per_time, Time_Info->kernelbuffer_ns);
    }
    else
    {
        ALOGE("%s pcm_get_htimestamp fail %s\n", __FUNCTION__, pcm_get_error(mPcm));
    }
    return NO_ERROR;
}
示例#2
0
EXTERN_TAG int  pcm_output_latency()
{
#if 1
	struct timespec tstamp;
	unsigned int  avail = 0;
	int ret;
	ret = pcm_get_htimestamp(wfd_pcm,&avail, &tstamp);
	//adec_print("pcm_get_latency ret %d,latency %d \n",ret,avail*1000/48000);
	if(ret)
		return ret;
	else
		return avail*1000/wfd_config_out.rate;
#else
	return pcm_hw_lantency(wfd_pcm);
#endif
}
int proxy_get_presentation_position(const alsa_device_proxy * proxy,
        uint64_t *frames, struct timespec *timestamp)
{
    int ret = -EPERM; // -1
    unsigned int avail;
    if (proxy->pcm != NULL
            && pcm_get_htimestamp(proxy->pcm, &avail, timestamp) == 0) {
        const size_t kernel_buffer_size =
                proxy->alsa_config.period_size * proxy->alsa_config.period_count;
        if (avail > kernel_buffer_size) {
            ALOGE("available frames(%u) > buffer size(%zu)", avail, kernel_buffer_size);
        } else {
            int64_t signed_frames = proxy->transferred - kernel_buffer_size + avail;
            // It is possible to compensate for additional driver and device delay
            // by changing signed_frames.  Example:
            // signed_frames -= 20 /* ms */ * proxy->alsa_config.rate / 1000;
            if (signed_frames >= 0) {
                *frames = signed_frames;
                ret = 0;
            }
        }
    }
    return ret;
}