annotate libmpcodecs/vd.c @ 4962:993f274191ff

ACCEPT_WIDTH flag added
author arpi
date Wed, 06 Mar 2002 23:40:31 +0000
parents ca6f6b35baf4
children 236b06410b03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
1 #include <stdio.h>
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
2 #include <stdlib.h>
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
3 #include <string.h>
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
4
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
5 #include "config.h"
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
6 #include "mp_msg.h"
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
7
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
8 #ifdef HAVE_MALLOC_H
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
9 #include <malloc.h>
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
10 #endif
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
11
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
12 #include "codec-cfg.h"
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
13 //#include "mp_image.h"
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
14
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
15 #include "../libvo/img_format.h"
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
16
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
17 #include "stream.h"
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
18 #include "demuxer.h"
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
19 #include "stheader.h"
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
20
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
21 #include "vd.h"
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
22 //#include "vd_internal.h"
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
23
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
24 extern vd_functions_t mpcodecs_vd_null;
4885
fbafa2f216f5 cinepak added
arpi
parents: 4884
diff changeset
25 extern vd_functions_t mpcodecs_vd_cinepak;
4915
f6990fad0ab3 Qt RPZA decoder interface by Roberto Togni <rtogni@bresciaonline.it>
arpi
parents: 4899
diff changeset
26 extern vd_functions_t mpcodecs_vd_qtrpza;
4951
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
27 extern vd_functions_t mpcodecs_vd_ffmpeg;
4958
ca6f6b35baf4 vd_dshow added
arpi
parents: 4951
diff changeset
28 extern vd_functions_t mpcodecs_vd_dshow;
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
29
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
30 vd_functions_t* mpcodecs_vd_drivers[] = {
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
31 &mpcodecs_vd_null,
4884
c758cf9360d9 cinepak added
arpi
parents: 4878
diff changeset
32 &mpcodecs_vd_cinepak,
4915
f6990fad0ab3 Qt RPZA decoder interface by Roberto Togni <rtogni@bresciaonline.it>
arpi
parents: 4899
diff changeset
33 &mpcodecs_vd_qtrpza,
4951
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
34 #ifdef USE_LIBAVCODEC
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
35 &mpcodecs_vd_ffmpeg,
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
36 #endif
4958
ca6f6b35baf4 vd_dshow added
arpi
parents: 4951
diff changeset
37 #ifdef USE_DIRECTSHOW
ca6f6b35baf4 vd_dshow added
arpi
parents: 4951
diff changeset
38 &mpcodecs_vd_dshow,
ca6f6b35baf4 vd_dshow added
arpi
parents: 4951
diff changeset
39 #endif
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
40 NULL
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
41 };
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
42
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
43 int mpcodecs_config_vo(sh_video_t *sh, int w, int h, unsigned int preferred_outfmt){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
44
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
45 return 1;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
46 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
47
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
48 static mp_image_t* static_images[2];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
49 static mp_image_t* temp_images[1];
4951
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
50 static mp_image_t* export_images[1];
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
51 static int static_idx=0;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
52
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
53 // mp_imgtype: buffering type, see mp_image.h
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
54 // mp_imgflag: buffer requirements (read/write, preserve, stride limits), see mp_image.h
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
55 // returns NULL or allocated mp_image_t*
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
56 // Note: buffer allocation may be moved to mpcodecs_config_vo() later...
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
57 mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
58 mp_image_t* mpi=NULL;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
59 // Note: we should call libvo first to check if it supports direct rendering
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
60 // and if not, then fallback to software buffers:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
61 switch(mp_imgtype){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
62 case MP_IMGTYPE_EXPORT:
4951
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
63 // mpi=new_mp_image(w,h);
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
64 if(!export_images[0]) export_images[0]=new_mp_image(w,h);
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
65 mpi=export_images[0];
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
66 break;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
67 case MP_IMGTYPE_STATIC:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
68 if(!static_images[0]) static_images[0]=new_mp_image(w,h);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
69 mpi=static_images[0];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
70 break;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
71 case MP_IMGTYPE_TEMP:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
72 if(!temp_images[0]) temp_images[0]=new_mp_image(w,h);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
73 mpi=temp_images[0];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
74 break;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
75 case MP_IMGTYPE_IPB:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
76 if(!(mp_imgflag&MP_IMGFLAG_READABLE)){ // B frame:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
77 if(!temp_images[0]) temp_images[0]=new_mp_image(w,h);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
78 mpi=temp_images[0];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
79 break;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
80 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
81 case MP_IMGTYPE_IP:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
82 if(!static_images[static_idx]) static_images[static_idx]=new_mp_image(w,h);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
83 mpi=static_images[static_idx];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
84 static_idx^=1;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
85 break;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
86 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
87 if(mpi){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
88 mpi->type=mp_imgtype;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
89 mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
90 mpi->flags|=mp_imgflag&(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE);
4951
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
91 if((mpi->width!=w || mpi->height!=h) && !(mpi->flags&MP_IMGFLAG_DIRECT)){
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
92 mpi->width=w;
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
93 mpi->height=h;
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
94 if(mpi->flags&MP_IMGFLAG_ALLOCATED){
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
95 // need to re-allocate buffer memory:
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
96 free(mpi->planes[0]);
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
97 mpi->flags&=~MP_IMGFLAG_ALLOCATED;
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
98 }
e5bd91881646 vd_ffmpeg added, handling of EXPORT imgtype changed
arpi
parents: 4915
diff changeset
99 }
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
100 if(!mpi->bpp){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
101 mp_image_setfmt(mpi,sh->codec->outfmt[sh->outfmtidx]);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
102 if(!(mpi->flags&(MP_IMGFLAG_ALLOCATED|MP_IMGFLAG_DIRECT))
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
103 && mpi->type>MP_IMGTYPE_EXPORT){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
104 // non-direct and not yet allocaed image. allocate it!
4899
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
105 printf("*** Allocating mp_image_t, %dx%dx%dbpp %s %s, %d bytes\n",
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
106 mpi->width,mpi->height,mpi->bpp,
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
107 (mpi->flags&MP_IMGFLAG_YUV)?"YUV":"RGB",
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
108 (mpi->flags&MP_IMGFLAG_PLANAR)?"planar":"packed",
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
109 mpi->bpp*mpi->width*mpi->height/8);
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
110 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*mpi->height/8);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
111 if(mpi->flags&MP_IMGFLAG_PLANAR){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
112 // YV12/I420. feel free to add other planar formats here...
4899
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
113 if(!mpi->stride[0]) mpi->stride[0]=mpi->width;
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
114 if(!mpi->stride[1]) mpi->stride[1]=mpi->stride[2]=mpi->width/2;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
115 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
116 mpi->planes[2]=mpi->planes[1]+mpi->width*mpi->height/4;
4899
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
117 } else {
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
118 if(!mpi->stride[0]) mpi->stride[0]=mpi->width*mpi->bpp/8;
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
119 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
120 mpi->flags|=MP_IMGFLAG_ALLOCATED;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
121 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
122 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
123 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
124 return mpi;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
125 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
126