Mercurial > mplayer.hg
annotate libmpcodecs/vd_ffmpeg.c @ 5331:6bab0f8a75e4
Fix aspect info for square pixel.
| author | atmos4 |
|---|---|
| date | Mon, 25 Mar 2002 09:52:15 +0000 |
| parents | ea8f3e8f39c1 |
| children | f248c9e86423 |
| 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 | |
| 5280 | 34 typedef struct { |
| 35 AVCodec *lavc_codec; | |
| 36 AVCodecContext *avctx; | |
| 37 int last_aspect; | |
| 38 } vd_ffmpeg_ctx; | |
| 39 | |
| 4952 | 40 //#ifdef FF_POSTPROCESS |
| 41 //unsigned int lavc_pp=0; | |
| 42 //#endif | |
| 43 | |
| 44 // to set/get/query special features/parameters | |
| 45 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
| 46 return CONTROL_UNKNOWN; | |
| 47 } | |
| 48 | |
| 49 // init driver | |
| 50 static int init(sh_video_t *sh){ | |
| 5280 | 51 AVCodecContext *avctx; |
| 52 vd_ffmpeg_ctx *ctx; | |
| 4952 | 53 |
| 54 if(!avcodec_inited){ | |
| 55 avcodec_init(); | |
| 56 avcodec_register_all(); | |
| 57 avcodec_inited=1; | |
| 58 } | |
| 5280 | 59 |
| 60 ctx = sh->context = malloc(sizeof(vd_ffmpeg_ctx)); | |
| 61 if (!ctx) | |
| 62 return(0); | |
| 63 memset(ctx, 0, sizeof(vd_ffmpeg_ctx)); | |
| 4952 | 64 |
| 5280 | 65 ctx->lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh->codec->dll); |
| 66 if(!ctx->lavc_codec){ | |
| 4952 | 67 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); |
| 68 return 0; | |
| 69 } | |
| 70 | |
| 5280 | 71 ctx->avctx = malloc(sizeof(AVCodecContext)); |
| 72 memset(ctx->avctx, 0, sizeof(AVCodecContext)); | |
| 73 avctx = ctx->avctx; | |
| 4952 | 74 |
| 5280 | 75 avctx->width = sh->disp_w; |
| 76 avctx->height= sh->disp_h; | |
| 77 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",avctx->width,avctx->height); | |
| 4952 | 78 if (sh->format == mmioFOURCC('R', 'V', '1', '3')) |
| 5280 | 79 avctx->sub_id = 3; |
| 4952 | 80 /* open it */ |
| 5280 | 81 if (avcodec_open(avctx, ctx->lavc_codec) < 0) { |
| 4952 | 82 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); |
| 83 return 0; | |
| 84 } | |
| 85 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
| 5124 | 86 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); |
| 4952 | 87 } |
| 88 | |
| 89 // uninit driver | |
| 90 static void uninit(sh_video_t *sh){ | |
| 5280 | 91 vd_ffmpeg_ctx *ctx = sh->context; |
| 92 AVCodecContext *avctx = ctx->avctx; | |
| 93 | |
| 94 if (avcodec_close(avctx) < 0) | |
| 4952 | 95 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); |
| 5280 | 96 if (avctx) |
| 97 free(avctx); | |
| 98 if (ctx) | |
| 99 free(ctx); | |
| 4952 | 100 } |
| 101 | |
| 102 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
| 103 | |
| 104 // decode a frame | |
| 105 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
| 106 int got_picture=0; | |
| 107 int ret; | |
| 108 AVPicture lavc_picture; | |
| 5280 | 109 vd_ffmpeg_ctx *ctx = sh->context; |
| 110 AVCodecContext *avctx = ctx->avctx; | |
| 4952 | 111 mp_image_t* mpi; |
| 112 | |
| 113 if(len<=0) return NULL; // skipped frame | |
| 114 | |
| 5280 | 115 ret = avcodec_decode_video(avctx, &lavc_picture, |
| 4952 | 116 &got_picture, data, len); |
| 117 | |
| 118 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); | |
| 119 if(!got_picture) return NULL; // skipped image | |
| 5280 | 120 |
| 121 if (avctx->aspect_ratio_info != ctx->last_aspect) | |
| 122 { | |
| 123 ctx->last_aspect = avctx->aspect_ratio_info; | |
| 124 switch(avctx->aspect_ratio_info) | |
| 125 { | |
| 126 case FF_ASPECT_4_3_625: | |
| 127 case FF_ASPECT_4_3_525: | |
| 128 sh->aspect = 4.0/3.0; | |
| 129 break; | |
| 130 case FF_ASPECT_16_9_625: | |
| 131 case FF_ASPECT_16_9_525: | |
| 132 sh->aspect = 16.0/9.0; | |
| 133 break; | |
| 134 case FF_ASPECT_SQUARE: | |
| 135 default: | |
| 136 sh->aspect = 0.0; | |
| 137 break; | |
| 138 } | |
| 139 if (mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12)) | |
| 140 return NULL; | |
| 141 } | |
| 4952 | 142 |
| 5280 | 143 if ((avctx->width != sh->disp_w) || |
| 144 (avctx->height != sh->disp_h)) | |
|
5207
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
145 { |
| 5219 | 146 /* and what about the sh->bih (BitmapInfoHeader) width/height values? */ |
| 5280 | 147 sh->disp_w = avctx->width; |
| 148 sh->disp_h = avctx->height; | |
|
5207
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
149 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
|
150 return NULL; |
| 5280 | 151 } |
|
5207
d337cc4ab0ee
config vo if resolution changed (after decoded image read the dimensions out of lavc context)
alex
parents:
5124
diff
changeset
|
152 |
| 4952 | 153 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, |
| 5280 | 154 avctx->width, avctx->height); |
| 4952 | 155 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
|
156 printf("couldn't allocate image for codec\n"); |
| 4952 | 157 return NULL; |
| 158 } | |
| 159 | |
| 160 mpi->planes[0]=lavc_picture.data[0]; | |
| 161 mpi->planes[1]=lavc_picture.data[1]; | |
| 162 mpi->planes[2]=lavc_picture.data[2]; | |
| 163 mpi->stride[0]=lavc_picture.linesize[0]; | |
| 164 mpi->stride[1]=lavc_picture.linesize[1]; | |
| 165 mpi->stride[2]=lavc_picture.linesize[2]; | |
| 166 | |
| 5280 | 167 if(avctx->pix_fmt==PIX_FMT_YUV422P){ |
| 4952 | 168 mpi->stride[1]*=2; |
| 169 mpi->stride[2]*=2; | |
| 170 } | |
| 171 | |
| 172 return mpi; | |
| 173 } | |
| 174 | |
| 175 #endif | |
| 176 |
