[Libav-user] av_read_frame

Andy Huang andy.y.huang at gmail.com
Thu Mar 28 16:45:35 CET 2013


Hi, I am trying to write a mpeg player for iOS, for some reason, same code
that calls "av_read_frame" has different result on Windows and iOS. after
calling "av_read_frame", "stream_index" field inside "
AVPacket" has non-zero value in iOS whereas on Windows it is always 0, when
trying to play same stream.
The code snipper is following:
       // header file

        class LibavDecoder

        {

                ..........

                 AVFormatContext
*avFormatContextPtr;

                 AVPacket                                avpkt;

        }

       // cpp file

void                LibavDecoder::initStreams
(AVFormatContext *avFormatContextPtr)

{

    AVStream      *tempStream   = NULL;

    AVCodec       *tempCodec    = NULL;

    StreamConfig  tempConfig;


    for (size_t streamcnt = 0; streamcnt < avFormatContextPtr->nb_streams;
++streamcnt)

    {

        tempStream = avFormatContextPtr->streams[streamcnt];


        if ((tempStream->codec->codec_type == AVMEDIA_TYPE_VIDEO) ||

            (tempStream->codec->codec_type == AVMEDIA_TYPE_AUDIO))

        {

            tempConfig.stream         = tempStream;

            tempCodec
= avcodec_find_decoder(tempStream->codec->codec_id);

            tempConfig.codecContext   = tempStream->codec;

            tempConfig.frameCnt       = 0;


            avcodec_open2(tempConfig.codecContext, tempCodec, NULL);

            this->streamconfigs.push_back(tempConfig);

        }

    }

}

StreamConfig*       LibavDecoder::getNextFrame            (AVFormatContext*
avFormatContextPtr, AVPacket* avpkt)

{

    int           loop               = 1;

    int           err                = 0;

    size_t        configcnt          = 0;

    StreamConfig  *tempConfig        = 0;



    while (loop == 1)

    {

        err = *av_read_frame*(avFormatContextPtr, avpkt);

        if (err < 0)

        {

            if (err != -11) //Ressource not available, try again

            {

                if ((size_t)err != AVERROR_EOF)

                {

                    error("Error while av_read_frame", err);

                }

                loop = 0;

            }

        } else

        {

            configcnt = 0;

            while ((loop == 1) && (configcnt < this->streamconfigs.size()))

            {

                if (this->streamconfigs.at(configcnt).stream->index == *
avpkt->stream_index*)

                {

                    tempConfig = &this->streamconfigs.at(configcnt);

                    loop = 0;

                }

                configcnt++;

            }

        }

        if (loop == 1)

            av_free_packet(avpkt);

    }

    return tempConfig;

}


any ideas while this happens? Thanks a bunch in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130328/3ada66a8/attachment.html>


More information about the Libav-user mailing list