diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c index dfd19c2..6420a6a 100644 --- a/libmpcodecs/vd_ffmpeg.c +++ b/libmpcodecs/vd_ffmpeg.c @@ -58,7 +58,6 @@ static const vd_info_t info = { int avcodec_initialized=0; typedef struct { - AVCodecContext *avctx; AVFrame *pic; enum PixelFormat pix_fmt; int do_slices; @@ -124,7 +123,7 @@ static enum AVDiscard str2AVDiscard(char *str) { // to set/get/query special features/parameters static int control(sh_video_t *sh, int cmd, void *arg, ...){ vd_ffmpeg_ctx *ctx = sh->context; - AVCodecContext *avctx = ctx->avctx; + AVCodecContext *avctx = sh->avcctx; switch(cmd){ case VDCTRL_QUERY_FORMAT: { @@ -199,8 +198,12 @@ static int init(sh_video_t *sh){ ctx->ip_count= ctx->b_count= 0; ctx->pic = avcodec_alloc_frame(); - ctx->avctx = avcodec_alloc_context(); - avctx = ctx->avctx; + if (!sh->avcctx) { + avctx = avcodec_alloc_context(); + sh->avcctx = avctx; + } else { + avctx = sh->avcctx; + } avctx->opaque = sh; avctx->codec_type = CODEC_TYPE_VIDEO; avctx->codec_id = lavc_codec->id; @@ -376,7 +379,7 @@ static int init(sh_video_t *sh){ // uninit driver static void uninit(sh_video_t *sh){ vd_ffmpeg_ctx *ctx = sh->context; - AVCodecContext *avctx = ctx->avctx; + AVCodecContext *avctx = sh->avcctx; if(sh->opts->lavc_param.vstats){ int i; @@ -452,7 +455,7 @@ static void draw_slice(struct AVCodecContext *s, static int init_vo(sh_video_t *sh, enum PixelFormat pix_fmt){ vd_ffmpeg_ctx *ctx = sh->context; - AVCodecContext *avctx = ctx->avctx; + AVCodecContext *avctx = sh->avcctx; float aspect= av_q2d(avctx->sample_aspect_ratio) * avctx->width / avctx->height; int width, height; @@ -728,7 +731,7 @@ static struct mp_image *decode(struct sh_video *sh, void *data, int len, int ret; vd_ffmpeg_ctx *ctx = sh->context; AVFrame *pic= ctx->pic; - AVCodecContext *avctx = ctx->avctx; + AVCodecContext *avctx = sh->avcctx; struct lavc_param *lavc_param = &sh->opts->lavc_param; mp_image_t *mpi=NULL; int dr1= ctx->do_dr1; diff --git a/libmpdemux/demux_rtp.cpp b/libmpdemux/demux_rtp.cpp index 8a5cfb8..aa61d66 100644 --- a/libmpdemux/demux_rtp.cpp +++ b/libmpdemux/demux_rtp.cpp @@ -118,9 +118,6 @@ int rtsp_transport_tcp = 0; #endif extern int rtsp_port; -#ifdef CONFIG_LIBAVCODEC -extern AVCodecContext *avcctx; -#endif extern "C" demuxer_t* demux_open_rtp(demuxer_t* demuxer) { struct MPOpts *opts = demuxer->opts; @@ -393,9 +390,6 @@ extern "C" void demux_close_rtp(demuxer_t* demuxer) { delete rtpState->videoBufferQueue; delete[] rtpState->sdpDescription; delete rtpState; -#ifdef CONFIG_LIBAVCODEC - av_freep(&avcctx); -#endif env->reclaim(); delete scheduler; } @@ -568,8 +562,9 @@ static demux_packet_t* getBuffer(demuxer_t* demuxer, demux_stream_t* ds, bufferQueue->nextpacket = NULL; } if (headersize == 3 && h264parserctx) { // h264 + sh_video_t* sh_video = (sh_video_t *)demuxer->video->sh; consumed = h264parserctx->parser->parser_parse(h264parserctx, - avcctx, + (AVCodecContext *)sh_video->avcctx, &poutbuf, &poutbuf_size, dp->buffer, dp->len); diff --git a/libmpdemux/demux_rtp_codec.cpp b/libmpdemux/demux_rtp_codec.cpp index 36d770f..7c4c3f7 100644 --- a/libmpdemux/demux_rtp_codec.cpp +++ b/libmpdemux/demux_rtp_codec.cpp @@ -29,7 +29,6 @@ extern "C" { #ifdef CONFIG_LIBAVCODEC AVCodecParserContext * h264parserctx; -AVCodecContext *avcctx; #endif // Copied from vlc @@ -138,7 +137,10 @@ void rtpCodecInitialize_video(demuxer_t* demuxer, #ifdef CONFIG_LIBAVCODEC avcodec_register_all(); h264parserctx = av_parser_init(CODEC_ID_H264); - avcctx = avcodec_alloc_context(); + AVCodecContext *avcctx = avcodec_alloc_context(); + avcctx->extradata_size = configLen; + avcctx->extradata = (uint8_t *)(bih+1); + sh_video->avcctx = avcctx; #endif needVideoFrameRate(demuxer, subsession); } else if (strcmp(subsession->codecName(), "H261") == 0) { diff --git a/libmpdemux/stheader.h b/libmpdemux/stheader.h index b11b886..0083f2e 100644 --- a/libmpdemux/stheader.h +++ b/libmpdemux/stheader.h @@ -128,6 +128,9 @@ typedef struct sh_video { AVIStreamHeader video; BITMAPINFOHEADER* bih; void* ImageDesc; // for quicktime codecs +#ifdef CONFIG_LIBAVCODEC + void* avcctx; // AVCodecContext +#endif } sh_video_t; typedef struct sh_sub {