annotate libmpcodecs/vd_black.c @ 35334:3397976a029b

stream ftp: readline: Always initialize output parameter buf Only exception if passed parameter max is less than or equal to zero. That cannot happen with the current code. Additionally change readresp function to always copy the first response line if the parameter rsp is non-NULL. This fixes some error reporting that used uninitialized stack arrays.
author al
date Tue, 20 Nov 2012 22:16:29 +0000
parents 36d09dcaf732
children abece00352ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35155
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
1 /*
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
2 * Copyright (C) 2012 Xidorn Quan
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
3 *
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
4 * This file is part of MPlayer.
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
5 *
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
9 * (at your option) any later version.
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
10 *
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
14 * GNU General Public License for more details.
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
15 *
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License along
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
19 */
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
20
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
21 #include <stdlib.h>
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
22
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
23 #include "config.h"
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
24 #include "mp_msg.h"
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
25
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
26 #include "vd_internal.h"
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
27
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
28 static const vd_info_t info = {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
29 "black video generator",
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
30 "black",
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
31 "",
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
32 "Xidorn Quan",
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
33 "no decoding, always outputs black frames"
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
34 };
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
35
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
36 LIBVD_EXTERN(black)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
37
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
38 typedef struct {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
39 unsigned char *planes[MP_MAX_PLANES];
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
40 int stride[MP_MAX_PLANES];
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
41 int w, h;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
42 } vd_black_ctx;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
43
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
44 static const unsigned int fmt_list[] = {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
45 IMGFMT_YV12,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
46 IMGFMT_IYUV,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
47 IMGFMT_I420,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
48 IMGFMT_UYVY,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
49 IMGFMT_YUY2,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
50 IMGFMT_BGR24,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
51 IMGFMT_RGB24,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
52 0
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
53 };
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
54
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
55 // to set/get/query special features/parameters
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
56 static int control(sh_video_t *sh, int cmd, void *arg, ...)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
57 {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
58 unsigned int format;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
59 const unsigned int *p;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
60
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
61 switch (cmd) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
62 case VDCTRL_QUERY_FORMAT:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
63 format = *(unsigned int *)arg;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
64 for (p = fmt_list; *p; ++p)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
65 if (format == *p)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
66 return CONTROL_TRUE;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
67 return CONTROL_FALSE;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
68 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
69
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
70 return CONTROL_UNKNOWN;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
71 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
72
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
73 // init driver
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
74 static int init(sh_video_t *sh)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
75 {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
76 unsigned int format;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
77 vd_black_ctx *ctx;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
78 int w, h;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
79 int i;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
80
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
81 ctx = sh->context = calloc(1, sizeof(*ctx));
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
82 if (!ctx)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
83 return 0;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
84
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
85 ctx->w = w = sh->disp_w;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
86 ctx->h = h = sh->disp_h;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
87 if (!mpcodecs_config_vo(sh, w, h, IMGFMT_BGR24))
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
88 goto error;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
89 format = sh->codec->outfmt[sh->outfmtidx];
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
90
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
91 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[vd_black] format: %s\n", vo_format_name(format));
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
92 switch (format) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
93 case IMGFMT_RGB24:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
94 case IMGFMT_BGR24:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
95 ctx->planes[0] = malloc(w * h * 3);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
96 if (!ctx->planes[0])
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
97 goto error;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
98 ctx->stride[0] = w * 3;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
99 memset(ctx->planes[0], 0, w * h * 3);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
100 break;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
101 case IMGFMT_UYVY:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
102 case IMGFMT_YUY2:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
103 ctx->planes[0] = malloc(w * h * 2);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
104 ctx->stride[0] = w * 2;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
105 if (format == IMGFMT_UYVY) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
106 for (i = 0; i < w * h * 2; i += 4) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
107 ctx->planes[0][i + 0] = 128;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
108 ctx->planes[0][i + 1] = 16;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
109 ctx->planes[0][i + 2] = 128;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
110 ctx->planes[0][i + 3] = 16;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
111 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
112 } else {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
113 for (i = 0; i < w * h * 2; i += 4) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
114 ctx->planes[0][i + 0] = 16;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
115 ctx->planes[0][i + 1] = 128;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
116 ctx->planes[0][i + 2] = 16;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
117 ctx->planes[0][i + 3] = 128;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
118 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
119 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
120
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
121 break;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
122 case IMGFMT_YV12:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
123 case IMGFMT_IYUV:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
124 case IMGFMT_I420:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
125 ctx->planes[0] = malloc(w * h);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
126 ctx->planes[1] = malloc(w * h / 4);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
127 ctx->planes[2] = malloc(w * h / 4);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
128 if (!ctx->planes[0] || !ctx->planes[1] || !ctx->planes[2])
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
129 goto error;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
130 ctx->stride[0] = w;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
131 ctx->stride[1] = w / 2;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
132 ctx->stride[2] = w / 2;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
133 memset(ctx->planes[0], 16, w * h);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
134 memset(ctx->planes[1], 128, w * h / 4);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
135 memset(ctx->planes[2], 128, w * h / 4);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
136 break;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
137 default:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
138 goto error;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
139 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
140
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
141 return 1;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
142
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
143 error:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
144 uninit(sh);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
145 return 0;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
146 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
147
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
148 // uninit driver
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
149 static void uninit(sh_video_t *sh)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
150 {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
151 int i;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
152 vd_black_ctx *ctx = sh->context;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
153
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
154 for (i = 0; i < MP_MAX_PLANES; ++i) {
35188
36d09dcaf732 vd_black: simplify code
upsuper
parents: 35155
diff changeset
155 free(ctx->planes[i]);
36d09dcaf732 vd_black: simplify code
upsuper
parents: 35155
diff changeset
156 ctx->planes[i] = NULL;
35155
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
157 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
158
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
159 free(ctx);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
160 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
161
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
162 // decode a frame
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
163 static mp_image_t* decode(sh_video_t *sh, void *data, int len, int flags)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
164 {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
165 mp_image_t *mpi = NULL;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
166 vd_black_ctx *ctx = sh->context;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
167 int i;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
168
35188
36d09dcaf732 vd_black: simplify code
upsuper
parents: 35155
diff changeset
169 if (sh->num_buffered_pts != FF_ARRAY_ELEMS(sh->buffered_pts) - 1)
35155
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
170 return NULL;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
171
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
172 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
173 ctx->w, ctx->h);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
174 if (!mpi)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
175 return NULL;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
176 for (i = 0; i < MP_MAX_PLANES; ++i) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
177 mpi->planes[i] = ctx->planes[i];
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
178 mpi->stride[i] = ctx->stride[i];
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
179 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
180 return mpi;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
181 }