Hi guys

Basically my program was working fine for a while but after I upgraded
AVLibrary code to the latest and greatest I am having issues where SDL
is crashing. Basically I grab a video frame, encodes it, sends it out
via rtp stream and then take that same encoded frame and decode its and
plays it to the screen using SDL on the local computer (think of it a
preview player). Before I did the update of the AVLibrary code my
program works fine, but after I updated the AVLibrary code,
SDL_UnlockYUVOverlay() throws a seg fault. Here is what my code looks
likes 

 

             //first I encode the packet

      out_size = avcodec_encode_video(c, video_outbuf,
video_outbuf_size, picture);

        

      //allocate the sws convertion context

SrcToOut_ctx =  sws_getContext(     c->width,

                                          c->height,

                                          c->pix_fmt,

                                          c->width,

                                          c->height,

                                          PIX_FMT_YUV420P,

                                          sws_flags,NULL,NULL,NULL );

      if (out_size > 0) {

      AVPacket pkt;

      av_init_packet(&pkt);

 

      if (c->coded_frame->pts != AV_NOPTS_VALUE)

            pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base,
st->time_base);

      if(c->coded_frame->key_frame)

            pkt.flags |= PKT_FLAG_KEY;

      pkt.stream_index= st->index;

      pkt.data= video_outbuf;

      pkt.size= out_size;

 

      //Sends the packet out the rtp stream

      /* write the compressed frame in the media file */

      ret = av_write_frame(oc, &pkt);

      //Decode the packet that I just encoded so I can get an idea of
what the viewer

      //might see when he gets the packet                         

      avcodec_decode_video(pPreviewCodecCtx, pPreviewFrame,
&frameFinished, 

                              pkt.data, pkt.size);

                  

                  

// Did we get a video frame?

      if(frameFinished) 

      {

            AVPicture pict;

            

            SDL_LockYUVOverlay(bmp);      

            pict.data[0] = bmp->pixels[0];

            pict.data[1] = bmp->pixels[2];

            pict.data[2] = bmp->pixels[1];

 

            pict.linesize[0] = bmp->pitches[0];

            pict.linesize[1] = bmp->pitches[2];

            pict.linesize[2] = bmp->pitches[1];

 

            sws_scale(  SrcToOut_ctx , pPreviewFrame->data,
pPreviewFrame->linesize,

                        0, c->height, pict.data, pict.linesize);

      

            SDL_UnlockYUVOverlay(bmp);

      

            }

            repeat_poll = TRUE;

            while( repeat_poll )

            {

                  SDL_PollEvent(&event);

                  switch(event.type) {

                  case SDL_QUIT:

                  {

                        SDL_Quit();

                        exit(0);

                        break;

                  }

                  default:

                  {

                        repeat_poll = FALSE;

                        break;

                  }

            }

        }

 

Am I doing anything wrong? I have spent a loooottt of time trying to
figure this out so any help you guys can offer would be greatly
appreciated.

 

Xin Cai

_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to