*pts_ptr = pts;
if (pts != 0) { is->audio_clock = pts; } else { int n; n = 2 * is->audio_st->codec.channels; is->audio_clock += (double)data_size / (double)(n * is->audio_st->codec.sample_rate); } #if defined(DEBUG_SYNC) { static double last_clock; printf("audio: delay=%0.3f clock=%0.3f pts=%0.3f\n", is->audio_clock - last_clock, is->audio_clock, pts); last_clock = is->audio_clock; } #endif *pts_ptr = is->audio_clock;
static int audio_decode_frame(VideoState *is, uint8_t *audio_buf, double *pts_ptr){    AVPacket *pkt = &is->audio_pkt;    int len1, data_size;    double pts;    for(;;) {        if (is->paused || is->audioq.abort_request) {            return -1;        }        while (is->audio_pkt_size > 0) {            len1 = avcodec_decode_audio(&is->audio_st->codec,                                         (int16_t *)audio_buf, &data_size,                                         is->audio_pkt_data, is->audio_pkt_size);            if (len1 < 0)                break;            is->audio_pkt_data += len1;            is->audio_pkt_size -= len1;            if (data_size > 0) {                pts = 0;                if (is->audio_pkt_ipts != AV_NOPTS_VALUE)                    pts = (double)is->audio_pkt_ipts * is->ic->pts_num / is->ic->pts_den;                *pts_ptr = pts;                is->audio_pkt_ipts = AV_NOPTS_VALUE;                /* we got samples : we can exit now */                return data_size;            }        }        /* free previous packet if any */        if (pkt->destruct)            av_free_packet(pkt);        /* read next packet */        if (packet_queue_get(&is->audioq, pkt, 1) < 0)            return -1;        is->audio_pkt_data = pkt->data;        is->audio_pkt_size = pkt->size;        is->audio_pkt_ipts = pkt->pts;    }}