11966
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4
|
|
5 #include "../config.h"
|
|
6 #include "../mp_msg.h"
|
|
7
|
|
8 #include "codec-cfg.h"
|
|
9 #include "stream.h"
|
|
10 #include "demuxer.h"
|
|
11 #include "stheader.h"
|
|
12
|
|
13 #include "muxer.h"
|
|
14
|
|
15 #include "img_format.h"
|
|
16 #include "mp_image.h"
|
|
17 #include "vf.h"
|
|
18
|
|
19
|
|
20 //===========================================================================//
|
|
21
|
|
22 struct vf_priv_s {
|
|
23 muxer_stream_t* mux;
|
|
24 };
|
|
25 #define mux_v (vf->priv->mux)
|
|
26
|
|
27 static int set_format(struct vf_instance_s *vf, unsigned int fmt) {
|
|
28 mux_v->bih->biCompression = fmt;
|
|
29
|
|
30 mux_v->bih->biPlanes = 1;
|
|
31 if (IMGFMT_IS_RGB(fmt)) {
|
|
32 if (IMGFMT_RGB_DEPTH(fmt) < 8 && !(fmt&128))
|
|
33 mux_v->bih->biBitCount = IMGFMT_RGB_DEPTH(fmt);
|
|
34 else
|
|
35 mux_v->bih->biBitCount = (IMGFMT_RGB_DEPTH(fmt)+7)&(~7);
|
|
36 return 1;
|
|
37 }
|
|
38 if (IMGFMT_IS_BGR(fmt)) {
|
|
39 if (IMGFMT_BGR_DEPTH(fmt) < 8 && !(fmt&128))
|
|
40 mux_v->bih->biBitCount = IMGFMT_BGR_DEPTH(fmt);
|
|
41 else
|
|
42 mux_v->bih->biBitCount = (IMGFMT_BGR_DEPTH(fmt)+7)&(~7);
|
|
43 return 1;
|
|
44 }
|
|
45 switch (fmt) {
|
|
46 case IMGFMT_I420:
|
|
47 case IMGFMT_IYUV:
|
|
48 case IMGFMT_YV12:
|
|
49 case IMGFMT_411P:
|
|
50 mux_v->bih->biPlanes = 3;
|
|
51 mux_v->bih->biBitCount = 12;
|
|
52 break;
|
|
53 case IMGFMT_444P:
|
|
54 mux_v->bih->biPlanes = 3;
|
|
55 mux_v->bih->biBitCount = 24;
|
|
56 break;
|
|
57 case IMGFMT_422P:
|
|
58 mux_v->bih->biPlanes = 3;
|
|
59 mux_v->bih->biBitCount = 16;
|
|
60 break;
|
|
61 case IMGFMT_IF09:
|
|
62 mux_v->bih->biPlanes = 4;
|
|
63 case IMGFMT_YVU9:
|
|
64 mux_v->bih->biBitCount = 9;
|
|
65 break;
|
|
66 case IMGFMT_UYVY:
|
|
67 case IMGFMT_YUY2:
|
|
68 mux_v->bih->biBitCount = 16;
|
|
69 break;
|
|
70 default:
|
|
71 printf("ve_raw: raw output with fourcc [%x] not supported!\n", fmt);
|
|
72 mux_v->bih->biCompression = 0;
|
|
73 return 0;
|
|
74 }
|
|
75 return 1;
|
|
76 }
|
|
77
|
|
78
|
|
79 static int config(struct vf_instance_s *vf,
|
|
80 int width, int height, int d_width, int d_height,
|
|
81 unsigned int flags, unsigned int outfmt)
|
|
82 {
|
|
83 int ret;
|
|
84 mux_v->bih->biWidth = width;
|
|
85 mux_v->bih->biHeight = height;
|
|
86 ret = set_format(vf, outfmt);
|
|
87 if (!ret) return 0;
|
|
88
|
|
89 mux_v->bih->biSizeImage = mux_v->bih->biWidth*mux_v->bih->biHeight*mux_v->bih->biBitCount/8;
|
|
90 return 1;
|
|
91 }
|
|
92
|
|
93 static int control(struct vf_instance_s *vf, int request, void *data) {
|
|
94 return CONTROL_UNKNOWN;
|
|
95 }
|
|
96
|
|
97 static int query_format(struct vf_instance_s *vf, unsigned int fmt) {
|
|
98 if (IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt))
|
|
99 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
|
|
100 switch (fmt) {
|
|
101 case IMGFMT_I420:
|
|
102 case IMGFMT_IYUV:
|
|
103 case IMGFMT_YV12:
|
|
104 case IMGFMT_411P:
|
|
105 case IMGFMT_444P:
|
|
106 case IMGFMT_422P:
|
|
107 case IMGFMT_UYVY:
|
|
108 case IMGFMT_YUY2:
|
|
109 case IMGFMT_YVU9:
|
|
110 case IMGFMT_IF09:
|
|
111 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
|
|
112 }
|
|
113
|
|
114 return 0;
|
|
115 }
|
|
116
|
|
117 static int put_image(struct vf_instance_s *vf, mp_image_t *mpi) {
|
|
118 mux_v->buffer = mpi->planes[0];
|
|
119 muxer_write_chunk(mux_v, mpi->width*mpi->height*mux_v->bih->biBitCount/8, 0x10);
|
|
120 return 1;
|
|
121 }
|
|
122
|
|
123 //===========================================================================//
|
|
124
|
|
125 static int vf_open(vf_instance_t *vf, char* args){
|
|
126 vf->config = config;
|
|
127 vf->control = control;
|
|
128 vf->query_format = query_format;
|
|
129 vf->put_image = put_image;
|
|
130 vf->priv = malloc(sizeof(struct vf_priv_s));
|
|
131 memset(vf->priv, 0, sizeof(struct vf_priv_s));
|
|
132 vf->priv->mux = (muxer_stream_t*)args;
|
|
133
|
|
134 mux_v->bih = malloc(sizeof(BITMAPINFOHEADER));
|
|
135 mux_v->bih->biSize = sizeof(BITMAPINFOHEADER);
|
|
136 mux_v->bih->biWidth = 0;
|
|
137 mux_v->bih->biHeight = 0;
|
|
138
|
|
139 return 1;
|
|
140 }
|
|
141
|
|
142 vf_info_t ve_info_raw = {
|
|
143 "raw encoder",
|
|
144 "raw",
|
|
145 "jwe21@cam.ac.uk",
|
|
146 "Based on rawrgb",
|
|
147 vf_open
|
|
148 };
|
|
149
|
|
150 //===========================================================================//
|