It has been suggested to me that my recent problems with segfaults are the 
result of me trying to close things I shouldn't be touching.  I can completely 
believe that, since I'm really just guessing about that methods I should be 
calling.  So hopefully someone here can point me in the right direction.

I'm opening the AVFormatContext and AVCodecContext like this (excluding my 
error handling and some extra header stuff I have to do before connecting):

void my_open_url(AVFormatContext **fc, const char *url)
{
  URLContext *uc = NULL;
  AVInputFormat *fmt = NULL;
  ByteIOContext *pb = NULL;

  url_alloc(&uc, url, URL_RDONLY);
  url_connect(uc);
  url_fdopen(&pb, uc);
  ff_probe_input_buffer(&pb, &fmt, url, NULL, 0, 0);
  av_open_input_stream(fc, pb, url, fmt, NULL);
}

void my_open_stream(AVFormatContext  *fc, int idx)
{
        AVCodecContext *ctx = fc->streams[idx]->codec;
        AVCodec *codec = avcodec_find_decoder(ctx->codec_id);
        avcodec_open(ctx, codec);
}

I'm trying to close these two contexts like this:

void my_close_stream(AVFormatContext *fc, AVCodecContext *ctx)
{
        if (ctx)
        {
                avcodec_close(ctx);
        }

        if (fc)
        {
                av_close_input_file(fc);
        }
}

As far as I can tell, I'm doing the correct amount of cleaning up behind 
myself, but both of those close methods segfault every time.  The segfaults 
seems to be caused by items that should be allocated normally suddenly 
becoming invalid, but I can't figure out why.  I'm using ffmpeg inside of a 
JNI object, which may be doing who knows what with my memory allocations, but 
the problem *only* manifests on close (playback works fine).  Does anyone have 
any experience with this kind of problem?

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

Reply via email to