annotate libmpcodecs/vd.c @ 4910:e99d47acfce6

strike period over, commiting stuff. next commit will be rewrite. (?) - Gabu
author jonas
date Fri, 01 Mar 2002 22:27:01 +0000
parents c84d841ef43b
children f6990fad0ab3
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;
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
26
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
27 vd_functions_t* mpcodecs_vd_drivers[] = {
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
28 &mpcodecs_vd_null,
4884
c758cf9360d9 cinepak added
arpi
parents: 4878
diff changeset
29 &mpcodecs_vd_cinepak,
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
30 NULL
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
31 };
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
32
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
33 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
34
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
35 return 1;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
36 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
37
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
38 static mp_image_t* static_images[2];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
39 static mp_image_t* temp_images[1];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
40 static int static_idx=0;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
41
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
42 // mp_imgtype: buffering type, see mp_image.h
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
43 // mp_imgflag: buffer requirements (read/write, preserve, stride limits), see mp_image.h
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
44 // returns NULL or allocated mp_image_t*
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
45 // Note: buffer allocation may be moved to mpcodecs_config_vo() later...
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
46 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
47 mp_image_t* mpi=NULL;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
48 // Note: we should call libvo first to check if it supports direct rendering
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
49 // and if not, then fallback to software buffers:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
50 switch(mp_imgtype){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
51 case MP_IMGTYPE_EXPORT:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
52 mpi=new_mp_image(w,h);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
53 break;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
54 case MP_IMGTYPE_STATIC:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
55 if(!static_images[0]) static_images[0]=new_mp_image(w,h);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
56 mpi=static_images[0];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
57 break;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
58 case MP_IMGTYPE_TEMP:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
59 if(!temp_images[0]) temp_images[0]=new_mp_image(w,h);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
60 mpi=temp_images[0];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
61 break;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
62 case MP_IMGTYPE_IPB:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
63 if(!(mp_imgflag&MP_IMGFLAG_READABLE)){ // B frame:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
64 if(!temp_images[0]) temp_images[0]=new_mp_image(w,h);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
65 mpi=temp_images[0];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
66 break;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
67 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
68 case MP_IMGTYPE_IP:
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
69 if(!static_images[static_idx]) static_images[static_idx]=new_mp_image(w,h);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
70 mpi=static_images[static_idx];
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
71 static_idx^=1;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
72 break;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
73 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
74 if(mpi){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
75 mpi->type=mp_imgtype;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
76 mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
77 mpi->flags|=mp_imgflag&(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
78 if(!mpi->bpp){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
79 mp_image_setfmt(mpi,sh->codec->outfmt[sh->outfmtidx]);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
80 if(!(mpi->flags&(MP_IMGFLAG_ALLOCATED|MP_IMGFLAG_DIRECT))
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
81 && mpi->type>MP_IMGTYPE_EXPORT){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
82 // 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
83 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
84 mpi->width,mpi->height,mpi->bpp,
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
85 (mpi->flags&MP_IMGFLAG_YUV)?"YUV":"RGB",
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
86 (mpi->flags&MP_IMGFLAG_PLANAR)?"planar":"packed",
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
87 mpi->bpp*mpi->width*mpi->height/8);
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
88 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*mpi->height/8);
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
89 if(mpi->flags&MP_IMGFLAG_PLANAR){
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
90 // 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
91 if(!mpi->stride[0]) mpi->stride[0]=mpi->width;
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
92 if(!mpi->stride[1]) mpi->stride[1]=mpi->stride[2]=mpi->width/2;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
93 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
94 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
95 } else {
c84d841ef43b fixed stride for packed formats, more detailed printf at image allocation
arpi
parents: 4885
diff changeset
96 if(!mpi->stride[0]) mpi->stride[0]=mpi->width*mpi->bpp/8;
4878
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
97 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
98 mpi->flags|=MP_IMGFLAG_ALLOCATED;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
99 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
100 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
101 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
102 return mpi;
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
103 }
eff8a76e515f libmpcodecs core - initial version
arpi
parents:
diff changeset
104