Пример #1
0
static void *video_decode_loop (void *arg)
{
    dt_av_frame_t frame;
    dtvideo_decoder_t *decoder = (dtvideo_decoder_t *) arg;
    vd_wrapper_t *wrapper = decoder->wrapper;
    dtvideo_context_t *vctx = (dtvideo_context_t *) decoder->parent;
    queue_t *picture_queue = vctx->vo_queue;
    /*used for decode */
    AVPicture_t *picture = NULL;
    int ret;
    dt_info (TAG, "[%s:%d] start decode loop \n", __FUNCTION__, __LINE__);

    do
    {
        if (decoder->status == VDEC_STATUS_IDLE)
        {
            dt_info (TAG, "[%s:%d] Idle status ,please wait \n", __FUNCTION__, __LINE__);
            usleep (100);
            continue;
        }
        if (decoder->status == VDEC_STATUS_EXIT)
        {
            dt_info (TAG, "[%s:%d] receive decode loop exit cmd \n", __FUNCTION__, __LINE__);
            break;
        }

        /*read frame */
        if (!decoder->parent)
        {
            usleep (100);
            continue;
        }

        if (picture_queue->length >= VIDEO_OUT_MAX_COUNT)
        {
            //vo queue full
            usleep (1000);
            continue;
        }
        ret = dtvideo_read_frame (decoder->parent, &frame);
        if (ret < 0)
        {
            usleep (100);
            dt_debug (TAG, "[%s:%d] dtaudio decoder loop read frame failed \n", __FUNCTION__, __LINE__);
            continue;
        }
        /*read one frame,enter decode frame module */
        //will exec once for one time
        ret = wrapper->decode_frame (wrapper, &frame, &picture);
        if (ret <= 0)
        {
            decoder->decode_err_cnt++;
            dt_debug (TAG, "[%s:%d]decode failed \n", __FUNCTION__, __LINE__);
            picture = NULL;
            goto DECODE_END;
        }
        if (!picture)
            goto DECODE_END;
        decoder->frame_count++;
        //Got one frame
        //picture->pts = frame.pts;
        
        //update current pts, clear the buffer size
        if (frame.pts >= 0 && decoder->pts_first == -1)
        {
            //we will use first pts to estimate pts
            dt_info (TAG, "[%s:%d]first frame decoded ok, pts:0x%x dts:0x%x duration:%d size:%d\n", __FUNCTION__, __LINE__, frame.pts, frame.dts, frame.duration, frame.size);
            decoder->pts_first = pts_exchange (decoder, picture->pts);
            decoder->pts_current = decoder->pts_first;
        }
        else
        {
            if(pts_mode)
            {
                int fps = decoder->para.fps;
                float dur_inc = 90000/fps;
                picture->pts = decoder->pts_current + dur_inc;
                decoder->pts_current = picture->pts; 
            }
        }

        /*queue in */
        queue_push_tail (picture_queue, picture);
        picture = NULL;
      DECODE_END:
        //we successfully decodec one frame
        if (frame.data)
        {
            free (frame.data);
            frame.data = NULL;
            frame.size = 0;
            frame.pts = -1;
        }
    }
    while (1);
    dt_info (TAG, "[file:%s][%s:%d]decoder loop thread exit ok\n", __FILE__, __FUNCTION__, __LINE__);
    pthread_exit (NULL);
    return NULL;
}
Пример #2
0
static void *video_decode_loop (void *arg)
{
    dt_av_pkt_t frame;
    dtvideo_decoder_t *decoder = (dtvideo_decoder_t *) arg;
    vd_wrapper_t *wrapper = decoder->wrapper;
    dtvideo_context_t *vctx = (dtvideo_context_t *) decoder->parent;
    dtvideo_filter_t *filter = (dtvideo_filter_t *) &(vctx->video_filt);
    queue_t *picture_queue = vctx->vo_queue;
    /*used for decode */
    dt_av_frame_t *picture = NULL;
    int ret;
    dt_info (TAG, "[%s:%d] start decode loop \n", __FUNCTION__, __LINE__);

    do
    {
        //exit check before idle, maybe recieve exit cmd in idle status
        if (decoder->status == VDEC_STATUS_EXIT)
        {
            dt_info (TAG, "[%s:%d] receive decode loop exit cmd \n", __FUNCTION__, __LINE__);
            break;
        }

        if (decoder->status == VDEC_STATUS_IDLE)
        {
            dt_info (TAG, "[%s:%d] Idle status ,please wait \n", __FUNCTION__, __LINE__);
            usleep (100);
            continue;
        }

        /*read frame */
        if (!decoder->parent)
        {
            usleep (100);
            continue;
        }

        if (picture_queue->length >= VIDEO_OUT_MAX_COUNT)
        {
            //vo queue full
            usleep (1000);
            continue;
        }
        ret = dtvideo_read_frame (decoder->parent, &frame);
        if (ret < 0)
        {
            if(decoder->pts_first == -1 || decoder->pts_first == DT_NOPTS_VALUE)
            {
                usleep(1000);
                continue;
            }
            //no data left, maybe eof, need to flush left data
            memset(&frame,0,sizeof(dt_av_pkt_t));
            dt_info (TAG, "[%s:%d] no video frame left, flush left frames \n", __FUNCTION__, __LINE__);
        }
        /*read one frame,enter decode frame module */
        //will exec once for one time
        ret = wrapper->decode_frame (decoder, &frame, &picture);
        if (ret <= 0)
        {
            decoder->decode_err_cnt++;
            dt_info (TAG, "[%s:%d]decode failed \n", __FUNCTION__, __LINE__);
            picture = NULL;
            usleep(10000);
            goto DECODE_END;
        }
        if (!picture)
            goto DECODE_END;

        //got one frame, filter process
        if(wrapper->info_changed(decoder))
        {
            memcpy(&decoder->para, &wrapper->para, sizeof(dtvideo_para_t));
            memcpy(&filter->para, &wrapper->para, sizeof(dtvideo_para_t));
            video_filter_reset(filter, &decoder->para);
        }

        video_filter_process(filter, picture);

        decoder->frame_count++;
        //Got one frame
        //picture->pts = frame.pts;
        
        //update current pts, clear the buffer size
        if (frame.pts >= 0 && decoder->pts_first == -1)
        {
            //we will use first pts to estimate pts
            dt_info (TAG, "[%s:%d]first frame decoded ok, pts:0x%llx dts:0x%llx duration:%d size:%d\n", __FUNCTION__, __LINE__, frame.pts, frame.dts, frame.duration, frame.size);
            decoder->pts_first = pts_exchange (decoder, picture->pts);
            decoder->pts_current = decoder->pts_first;
        }
        else
        {
            if(pts_mode)
            {
                int fps = decoder->para.fps;
                float dur_inc = 90000/fps;
                picture->pts = decoder->pts_current + dur_inc;
                decoder->pts_current = picture->pts; 
            }
        }

        /*queue in */
        queue_push_tail (picture_queue, picture);
        picture = NULL;
      DECODE_END:
        //we successfully decodec one frame
        if (frame.data)
        {
            if(frame.data)
                free (frame.data);
            frame.data = NULL;
            frame.size = 0;
            frame.pts = -1;
        }
    }
    while (1);
    dt_info (TAG, "[file:%s][%s:%d]decoder loop thread exit ok\n", __FILE__, __FUNCTION__, __LINE__);

    //filter release
    video_filter_stop(filter);

    pthread_exit (NULL);
    return NULL;
}
Пример #3
0
static void *video_decode_loop(void *arg)
{
    dt_av_pkt_t frame;
    dtvideo_decoder_t *decoder = (dtvideo_decoder_t *) arg;
    vd_wrapper_t *wrapper = decoder->wrapper;
    vd_statistics_info_t *p_vd_statistics_info = &decoder->statistics_info;
    dtvideo_context_t *vctx = (dtvideo_context_t *) decoder->parent;
    queue_t *picture_queue = vctx->vo_queue;
    /*used for decode */
    dt_av_frame_t *picture = NULL;
    int ret;
    dt_info(TAG, "[%s:%d] start decode loop \n", __FUNCTION__, __LINE__);

    do {
        //exit check before idle, maybe recieve exit cmd in idle status
        if (decoder->status == VDEC_STATUS_EXIT) {
            dt_info(TAG, "[%s:%d] receive decode loop exit cmd \n", __FUNCTION__, __LINE__);
            break;
        }

        if (decoder->status == VDEC_STATUS_IDLE) {
            dt_info(TAG, "[%s:%d] Idle status ,please wait \n", __FUNCTION__, __LINE__);
            usleep(100);
            continue;
        }

        /*read frame */
        if (!decoder->parent) {
            usleep(100);
            continue;
        }

        if (picture_queue->length >= VIDEO_OUT_MAX_COUNT) {
            //vo queue full
            usleep(1000);
            continue;
        }
        ret = dtvideo_read_frame(decoder->parent, &frame);
        if (ret < 0) {
            dt_usleep(1000);
            if (decoder->pts_first == DT_NOPTS_VALUE) {
                continue;
            }
            //no data left, maybe eof, need to flush left data
            memset(&frame, 0, sizeof(dt_av_pkt_t));
            dt_debug(TAG, "[%s:%d] no video frame left, flush left frames \n", __FUNCTION__,
                     __LINE__);
        }
        /*read one frame,enter decode frame module */
        //will exec once for one time
        ret = wrapper->decode_frame(decoder, &frame, &picture);
        if (ret <= 0) {
            decoder->decode_err_cnt++;
            dt_debug(TAG, "[%s:%d]decode failed \n", __FUNCTION__, __LINE__);
            picture = NULL;
            //usleep(10000);
            goto DECODE_END;
        }
        if (!picture) {
            goto DECODE_END;
        }

        // statistics collection
        {
            p_vd_statistics_info->decoded_frame_count++;
        }
        decoder->frame_count++;
        //Got one frame
        //update current pts, clear the buffer size
        if (PTS_VALID(picture->pts)) {
            picture->pts = pts_exchange(decoder, picture->pts);
        }
        if (decoder->first_frame_decoded == 0 && PTS_INVALID(decoder->pts_first)) {
            decoder->pts_first = decoder->pts_current = picture->pts;
            decoder->first_frame_decoded = 1;
            dt_info(TAG, "[%s:%d]first frame decoded ok, pts:0x%llx dts:0x%llx\n",
                    __FUNCTION__, __LINE__, picture->pts, picture->dts);
        } else {
            if (pts_mode || PTS_INVALID(picture->pts)) {
                int fps = decoder->para.fps;
                int dur_inc = (int)((double)90000 / fps);
                picture->pts = decoder->pts_current + dur_inc;
                decoder->pts_current = picture->pts;
                dt_debug(TAG, "vpts inc itself. pts_mode:%d pts:0x%llx inc:%d\n", pts_mode,
                         picture->pts, dur_inc);
            }
        }

        /*queue in */
        queue_push_tail(picture_queue, picture);
        picture = NULL;
DECODE_END:
        //we successfully decodec one frame
        if (frame.data) {
            if (frame.data) {
                free(frame.data);
            }
            frame.data = NULL;
            frame.size = 0;
            frame.pts = -1;
        }
    } while (1);
    dt_info(TAG, "[file:%s][%s:%d]decoder loop thread exit ok\n", __FILE__,
            __FUNCTION__, __LINE__);

    pthread_exit(NULL);
    return NULL;
}