Mercurial > mplayer.hg
annotate libmpcodecs/vd_ffmpeg.c @ 5207:d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
| author | alex |
|---|---|
| date | Tue, 19 Mar 2002 22:12:18 +0000 |
| parents | 3dcbf67c0de0 |
| children | 9a2e8b32db2a |
| rev | line source |
|---|---|
| 4952 | 1 #include <stdio.h> |
| 2 #include <stdlib.h> | |
| 3 #include <assert.h> | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "mp_msg.h" | |
| 7 #include "help_mp.h" | |
| 8 | |
| 9 #ifdef USE_LIBAVCODEC | |
| 10 | |
| 11 #include "bswap.h" | |
| 12 | |
| 13 #include "vd_internal.h" | |
| 14 | |
| 15 static vd_info_t info = { | |
| 16 "FFmpeg's libavcodec codec family", | |
| 17 "ffmpeg", | |
| 18 VFM_FFMPEG, | |
| 19 "A'rpi", | |
| 20 "http://ffmpeg.sf.net", | |
| 21 "native codecs" | |
| 22 }; | |
| 23 | |
| 24 LIBVD_EXTERN(ffmpeg) | |
| 25 | |
| 26 #ifdef USE_LIBAVCODEC_SO | |
| 27 #include <libffmpeg/avcodec.h> | |
| 28 #else | |
| 29 #include "libavcodec/avcodec.h" | |
| 30 #endif | |
| 31 | |
| 32 int avcodec_inited=0; | |
| 33 | |
| 34 //#ifdef FF_POSTPROCESS | |
| 35 //unsigned int lavc_pp=0; | |
| 36 //#endif | |
| 37 | |
| 38 // to set/get/query special features/parameters | |
| 39 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
| 40 return CONTROL_UNKNOWN; | |
| 41 } | |
| 42 | |
| 43 // init driver | |
| 44 static int init(sh_video_t *sh){ | |
| 45 AVCodec *lavc_codec; | |
| 46 AVCodecContext *ctx; | |
| 47 | |
| 48 if(!avcodec_inited){ | |
| 49 avcodec_init(); | |
| 50 avcodec_register_all(); | |
| 51 avcodec_inited=1; | |
| 52 } | |
| 53 | |
| 54 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh->codec->dll); | |
| 55 if(!lavc_codec){ | |
| 56 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); | |
| 57 return 0; | |
| 58 } | |
| 59 | |
| 60 ctx = sh->context = malloc(sizeof(AVCodecContext)); | |
| 61 memset(ctx, 0, sizeof(AVCodecContext)); | |
| 62 | |
| 63 ctx->width = sh->disp_w; | |
| 64 ctx->height= sh->disp_h; | |
| 65 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",ctx->width,ctx->height); | |
| 66 if (sh->format == mmioFOURCC('R', 'V', '1', '3')) | |
| 67 ctx->sub_id = 3; | |
| 68 /* open it */ | |
| 69 if (avcodec_open(ctx, lavc_codec) < 0) { | |
| 70 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); | |
| 71 return 0; | |
| 72 } | |
| 73 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
| 5124 | 74 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); |
| 4952 | 75 } |
| 76 | |
| 77 // uninit driver | |
| 78 static void uninit(sh_video_t *sh){ | |
| 79 if (avcodec_close(sh->context) < 0) | |
| 80 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); | |
| 81 } | |
| 82 | |
| 83 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
| 84 | |
| 85 // decode a frame | |
| 86 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
| 87 int got_picture=0; | |
| 88 int ret; | |
| 89 AVPicture lavc_picture; | |
| 90 AVCodecContext *ctx = sh->context; | |
| 91 mp_image_t* mpi; | |
| 92 | |
| 93 if(len<=0) return NULL; // skipped frame | |
| 94 | |
| 95 ret = avcodec_decode_video(sh->context, &lavc_picture, | |
| 96 &got_picture, data, len); | |
| 97 | |
| 98 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); | |
| 99 if(!got_picture) return NULL; // skipped image | |
| 100 | |
|
5207
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
101 if ((ctx->width != sh->disp_w) || |
|
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
102 (ctx->height != sh->disp_h)) |
|
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
103 { |
|
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
104 if (mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12)) |
|
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
105 return NULL; |
|
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
106 } |
|
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
107 |
| 4952 | 108 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, |
| 109 ctx->width, ctx->height); | |
| 110 if(!mpi){ // temporary! | |
|
5207
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
111 printf("couldn't allocate image for codec\n"); |
| 4952 | 112 return NULL; |
| 113 } | |
| 114 | |
| 115 mpi->planes[0]=lavc_picture.data[0]; | |
| 116 mpi->planes[1]=lavc_picture.data[1]; | |
| 117 mpi->planes[2]=lavc_picture.data[2]; | |
| 118 mpi->stride[0]=lavc_picture.linesize[0]; | |
| 119 mpi->stride[1]=lavc_picture.linesize[1]; | |
| 120 mpi->stride[2]=lavc_picture.linesize[2]; | |
| 121 | |
| 122 if(ctx->pix_fmt==PIX_FMT_YUV422P){ | |
| 123 mpi->stride[1]*=2; | |
| 124 mpi->stride[2]*=2; | |
| 125 } | |
| 126 | |
| 127 return mpi; | |
| 128 } | |
| 129 | |
| 130 #endif | |
| 131 |
