<div dir="ltr"><div>I am developing rtsp streaming player, and followed the below approach. <br><br><br></div><b>1) Read packet, decode, display -> works perfectly.<br></b><div><div><br>           while (1) {<br>                   if ( av_read_frame(pFormatCtx, &packet) >= 0) {<br>
                           if (packet.stream_index == videoStream) {<br>                                   retDecoder = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);<br>                                   if  ( retDecoder <= 0)<br>
                                        LOGD (" Unable to Decode...retval %d ", retDecoder);<br>                                   if (frameFinished) {<br>                                   }<br>                           }<br>
                                av_free_packet (&packet);<br>                   }<br>           }<br><br><br><br><br>Whereas,<br><br><b>I introduced 2 thread, one is reading and pushing into the LIst. and the second one is reading from the queue. <br>
</b><br>My problem is while reading the same packet, and decode, i m unable to decode, the return value of the <b>av_video_decode2 is -1094995529 .<br></b><br>Below is the short description of code.  Kindly help to solve this issue?.<br>
<br><br><br>AVPacketList *firstNode=NULL, *lastNode=NULL;<br><br><br>int pushPacket (AVPacket * pkt)<br>{<br>        AVPacketList *newNode = av_malloc(sizeof(AVPacketList));<br>        newNode->pkt = *pkt;     // IS IT OK ?<br>
        newNode->next = NULL;<br><br>        SDL_LockMutex (rwMutex);<br><br>        if (lastNode != NULL )  {<br>                lastNode->next = newNode;<br>                lastNode = newNode;<br>        } else {<br>
             firstNode = lastNode = newNode;<br>        }<br><br> SDL_UnlockMutex (rwMutex);<br><br>}<br><br><br><br><br>int pullPacket ()<br>{<br><br>        AVPacketList *tempNode;<br>        AVPacket *pkt;<br>        int res=0;<br>
<br>        SDL_LockMutex (rwMutex);<br><br>                if ( firstNode != NULL ) {<br>                        tempNode = firstNode;<br>                        *pkt = tempNode->pkt;<br>                           res = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, pkt);  // HERE IS THE PROBLEM. <br>
                           if (frameFinished) {<br>                                        LOGD (" fRAME DECODED.. %d \n", counter++);<br>                                }<br><br><br>                        if (firstNode->next != NULL) {    <br>
                                firstNode = firstNode->next;<br>                        }<br>                        else {<br>                                firstNode = NULL;<br>                                lastNode = NULL;<br>
                        }<br>                        av_free (tempNode);<br>                }   <br><br>}<br><br><br>In Thread 1:<br><br>int PacketReader (void *ptr)<br>{<br>        AVPacket pkt1, *rpacket;<br>        rpacket = &pkt1;<br>
        while (globalQuit != 0)  {<br><br>                if ( av_read_frame(pFormatCtx, rpacket) >= 0) {<br><br>                        if (packet.stream_index == videoStream) {<br>                                pushPacket (rpacket);<br>
                                }<br>                                av_free_packet(rpacket);<br>                        }<br><br>                }<br><br>}<br><br><br>In thread 2:<br><br> while (1) {<br>   pullPacket ();<br>
}<br></div></div></div>