annotate libmpcodecs/vd_black.c @ 36304:6f0ab9dd1429

Fix definition of sh->original_aspect. Since 0 is a valid aspect ratio, initialization must be different. This has been a bug in r36391.
author ib
date Sun, 04 Aug 2013 18:12:24 +0000
parents abece00352ec
children
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];
35411
abece00352ec Prevent dropping last frames in vd_black.
upsuper
parents: 35188
diff changeset
41 int buffer_filled;
35155
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
42 int w, h;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
43 } vd_black_ctx;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
44
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
45 static const unsigned int fmt_list[] = {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
46 IMGFMT_YV12,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
47 IMGFMT_IYUV,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
48 IMGFMT_I420,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
49 IMGFMT_UYVY,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
50 IMGFMT_YUY2,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
51 IMGFMT_BGR24,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
52 IMGFMT_RGB24,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
53 0
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
54 };
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
55
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
56 // to set/get/query special features/parameters
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
57 static int control(sh_video_t *sh, int cmd, void *arg, ...)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
58 {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
59 unsigned int format;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
60 const unsigned int *p;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
61
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
62 switch (cmd) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
63 case VDCTRL_QUERY_FORMAT:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
64 format = *(unsigned int *)arg;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
65 for (p = fmt_list; *p; ++p)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
66 if (format == *p)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
67 return CONTROL_TRUE;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
68 return CONTROL_FALSE;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
69 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
70
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
71 return CONTROL_UNKNOWN;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
72 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
73
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
74 // init driver
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
75 static int init(sh_video_t *sh)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
76 {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
77 unsigned int format;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
78 vd_black_ctx *ctx;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
79 int w, h;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
80 int i;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
81
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
82 ctx = sh->context = calloc(1, sizeof(*ctx));
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
83 if (!ctx)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
84 return 0;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
85
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
86 ctx->w = w = sh->disp_w;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
87 ctx->h = h = sh->disp_h;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
88 if (!mpcodecs_config_vo(sh, w, h, IMGFMT_BGR24))
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
89 goto error;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
90 format = sh->codec->outfmt[sh->outfmtidx];
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
91
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
92 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[vd_black] format: %s\n", vo_format_name(format));
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
93 switch (format) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
94 case IMGFMT_RGB24:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
95 case IMGFMT_BGR24:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
96 ctx->planes[0] = malloc(w * h * 3);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
97 if (!ctx->planes[0])
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
98 goto error;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
99 ctx->stride[0] = w * 3;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
100 memset(ctx->planes[0], 0, w * h * 3);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
101 break;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
102 case IMGFMT_UYVY:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
103 case IMGFMT_YUY2:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
104 ctx->planes[0] = malloc(w * h * 2);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
105 ctx->stride[0] = w * 2;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
106 if (format == IMGFMT_UYVY) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
107 for (i = 0; i < w * h * 2; i += 4) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
108 ctx->planes[0][i + 0] = 128;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
109 ctx->planes[0][i + 1] = 16;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
110 ctx->planes[0][i + 2] = 128;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
111 ctx->planes[0][i + 3] = 16;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
112 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
113 } else {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
114 for (i = 0; i < w * h * 2; i += 4) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
115 ctx->planes[0][i + 0] = 16;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
116 ctx->planes[0][i + 1] = 128;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
117 ctx->planes[0][i + 2] = 16;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
118 ctx->planes[0][i + 3] = 128;
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
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
122 break;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
123 case IMGFMT_YV12:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
124 case IMGFMT_IYUV:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
125 case IMGFMT_I420:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
126 ctx->planes[0] = malloc(w * h);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
127 ctx->planes[1] = malloc(w * h / 4);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
128 ctx->planes[2] = malloc(w * h / 4);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
129 if (!ctx->planes[0] || !ctx->planes[1] || !ctx->planes[2])
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
130 goto error;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
131 ctx->stride[0] = w;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
132 ctx->stride[1] = w / 2;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
133 ctx->stride[2] = w / 2;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
134 memset(ctx->planes[0], 16, w * h);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
135 memset(ctx->planes[1], 128, w * h / 4);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
136 memset(ctx->planes[2], 128, w * h / 4);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
137 break;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
138 default:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
139 goto error;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
140 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
141
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
142 return 1;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
143
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
144 error:
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
145 uninit(sh);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
146 return 0;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
147 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
148
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
149 // uninit driver
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
150 static void uninit(sh_video_t *sh)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
151 {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
152 int i;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
153 vd_black_ctx *ctx = sh->context;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
154
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
155 for (i = 0; i < MP_MAX_PLANES; ++i) {
35188
36d09dcaf732 vd_black: simplify code
upsuper
parents: 35155
diff changeset
156 free(ctx->planes[i]);
36d09dcaf732 vd_black: simplify code
upsuper
parents: 35155
diff changeset
157 ctx->planes[i] = NULL;
35155
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
158 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
159
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
160 free(ctx);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
161 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
162
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
163 // decode a frame
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
164 static mp_image_t* decode(sh_video_t *sh, void *data, int len, int flags)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
165 {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
166 mp_image_t *mpi = NULL;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
167 vd_black_ctx *ctx = sh->context;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
168 int i;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
169
35411
abece00352ec Prevent dropping last frames in vd_black.
upsuper
parents: 35188
diff changeset
170 if (sh->num_buffered_pts == FF_ARRAY_ELEMS(sh->buffered_pts) - 1)
abece00352ec Prevent dropping last frames in vd_black.
upsuper
parents: 35188
diff changeset
171 ctx->buffer_filled = 1;
abece00352ec Prevent dropping last frames in vd_black.
upsuper
parents: 35188
diff changeset
172 if (!ctx->buffer_filled || !sh->num_buffered_pts)
35155
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
173 return NULL;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
174
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
175 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE,
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
176 ctx->w, ctx->h);
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
177 if (!mpi)
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
178 return NULL;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
179 for (i = 0; i < MP_MAX_PLANES; ++i) {
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
180 mpi->planes[i] = ctx->planes[i];
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
181 mpi->stride[i] = ctx->stride[i];
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
182 }
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
183 return mpi;
303bf4bab982 libmpcodecs: Add vd_black
al
parents:
diff changeset
184 }