[ create a new paste ] login | about

Link: http://codepad.org/gsJU4Ydp    [ raw code | output | fork ]

C, pasted on Jun 10:
static int audio_decode_frame2(VideoState *is)
{
ALOGD("------Enter %s",__FUNCTION__);
    AVPacket *pkt_temp = &is->audio_pkt_temp;
    AVPacket *pkt = &is->audio_pkt;
    AVCodecContext *dec = is->audio_st->codec;

    int len1;
    int got_frame;

    for(;;)
    {
        while (pkt_temp->stream_index != -1 ) 
        {
            if (!is->frame) {
                if (!(is->frame = avcodec_alloc_frame()))
                    return AVERROR(ENOMEM);
            } else {
                av_frame_unref(is->frame);
                avcodec_get_frame_defaults(is->frame);
            }

            len1 = avcodec_decode_audio4(dec, is->frame, &got_frame, pkt_temp);
            if (len1 < 0) {
                /* if error, we skip the frame */
                pkt_temp->size = 0;
                ALOGE("-----------------------break, pkt_temp is over");
                break;
            }
            pkt_temp->data += len1;
            pkt_temp->size -= len1;

            if (pkt_temp->data && pkt_temp->size <= 0 )
            {
                ALOGD("over pkt_temp");
                pkt_temp->stream_index = -1;
            }

            if (!got_frame)
                continue;

            if( is->swr_ctx== NULL)
            {
                ALOGD("+++++++ swr_init++++++++");
                is->swr_ctx=swr_alloc_set_opts(NULL,
                                            AV_CH_LAYOUT_STEREO, 
                                            AV_SAMPLE_FMT_S16, 
                                            44100,  
                                            dec->channel_layout,
                                            dec->sample_fmt , 
                                            dec->sample_rate,
                                            0, 
                                            NULL); 
                swr_init(is->swr_ctx);            
            }

            if (is->swr_ctx) 
            {


                int needed_buf_size = av_samples_get_buffer_size(NULL, 
                                                                dec->channels, 
                                                                is->frame->nb_samples, 
                                                                AV_SAMPLE_FMT_S16, 0);
                ALOGD("needed_buf_size  :%d [AV_SAMPLE_FMT_S16]",needed_buf_size);

                uint8_t *out[] = { audio_buf };
                int outsamples = swr_convert(is->swr_ctx, 
                                            out, 
                                            needed_buf_size, 
                                            (const uint8_t**)is->frame->extended_data, 
                                            is->frame->nb_samples);

                is->audio_buf = audio_buf;

                int resampled_data_size = outsamples * dec->channels * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
                ALOGD("--[%02x],[%02x],[%02x],[%02x],[%02x],[%02x],[%02x],[%02x],[%02x],[%02x],[%02x],[%02x]",
                    is->audio_buf[0],is->audio_buf[1],is->audio_buf[2],is->audio_buf[3],is->audio_buf[4],
                    is->audio_buf[5],is->audio_buf[6],is->audio_buf[7],is->audio_buf[8],is->audio_buf[9],
                    is->audio_buf[10],is->audio_buf[11]);
ALOGD("------Enter %s",__FUNCTION__);

                return resampled_data_size;

            }

        }

ALOGD("------get----------- %s",__FUNCTION__);
        /* free the current packet */
        if (pkt->data)
            av_free_packet(pkt);
        memset(pkt_temp, 0, sizeof(*pkt_temp));
        pkt_temp->stream_index = -1;

        if (is->audioq.abort_request) {
            return -1;
        }

        if (is->audioq.nb_packets == 0)
            SDL_CondSignal(is->continue_read_thread);

        /* read next packet */
        if ((packet_queue_get(&is->audioq, pkt, 1, &is->audio_pkt_temp_serial)) < 0)
            return -1;

        if (pkt->data == flush_pkt.data) {
            avcodec_flush_buffers(dec);
            is->audio_buf_frames_pending = 0;
            is->audio_frame_next_pts = AV_NOPTS_VALUE;
            if ((is->ic->iformat->flags & (AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK)) && !is->ic->iformat->read_seek)
                is->audio_frame_next_pts = is->audio_st->start_time;
        }

        *pkt_temp = *pkt;

ALOGD("------get-----------new packet");
    }
}


Output:
1
Line 1: error: expected ')' before '*' token


Create a new paste based on this one


Comments: