static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **options)
{
    int16_t *samples;
    AVCodec *codec;
    int got_picture, data_size, ret=0;
    AVFrame picture;

    if(!st->codec->codec){
        codec = avcodec_find_decoder(st->codec->codec_id);
        if (!codec)
            return -1;
        ret = avcodec_open2(st->codec, codec, options);
        if (ret < 0)
            return ret;
    }

    if(!has_codec_parameters(st->codec) || !has_decode_delay_been_guessed(st) ||
       (!st->codec_info_nb_frames && st->codec->codec->capabilities & CODEC_CAP_CHANNEL_CONF)) {
        switch(st->codec->codec_type) {
        case AVMEDIA_TYPE_VIDEO:
            avcodec_get_frame_defaults(&picture);
            ret = avcodec_decode_video2(st->codec, &picture,
                                        &got_picture, avpkt);
            if (got_picture)
                st->info->nb_decoded_frames++;
            break;
        case AVMEDIA_TYPE_AUDIO:
            data_size = FFMAX(avpkt->size, AVCODEC_MAX_AUDIO_FRAME_SIZE);
            samples = av_malloc(data_size);
            if (!samples)
                goto fail;
            ret = avcodec_decode_audio3(st->codec, samples,
                                        &data_size, avpkt);
            av_free(samples);
            break;
        default:
            break;
        }
    }
 fail:
    return ret;
}