vo_glamo: sub.h was moved to sub directory in c9026cb3210205b07e2e068467a18ee40f9259a3
[mplayer/glamo.git] / libvo / vo_md5sum.c
blob0a2170bbd7bfc9e51dc8a5f17845d9f7a69c5c6e
1 /* ------------------------------------------------------------------------- */
3 /*
4 * md5sum video output driver
6 * Copyright (C) 2004, 2005, 2006 Ivo van Poorten
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 /* ------------------------------------------------------------------------- */
27 /* Global Includes */
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <errno.h>
34 /* ------------------------------------------------------------------------- */
36 /* Local Includes */
38 #include "config.h"
39 #include "subopt-helper.h"
40 #include "mp_msg.h"
41 #include "video_out.h"
42 #include "video_out_internal.h"
43 #include "mplayer.h" /* for exit_player_bad() */
44 #include "libavutil/md5.h"
46 /* ------------------------------------------------------------------------- */
48 /* Defines */
50 /* Used for temporary buffers to store file- and pathnames */
51 #define BUFLENGTH 512
53 /* ------------------------------------------------------------------------- */
55 /* Info */
57 static const vo_info_t info=
59 "md5sum of each frame",
60 "md5sum",
61 "Ivo van Poorten (ivop@euronet.nl)",
65 const LIBVO_EXTERN (md5sum)
67 /* ------------------------------------------------------------------------- */
69 /* Global Variables */
71 char *md5sum_outfile = NULL;
73 FILE *md5sum_fd;
74 int framenum = 0;
76 /* ------------------------------------------------------------------------- */
78 /** \brief An error occured while writing to a file.
80 * The program failed to write data to a file.
81 * It displays a message and exits the player.
83 * \return nothing It does not return.
86 static void md5sum_write_error(void) {
87 mp_tmsg(MSGT_VO, MSGL_ERR, "%s: Error writing file.\n", info.short_name);
88 exit_player_bad(_("Fatal error"));
91 /* ------------------------------------------------------------------------- */
93 /** \brief Pre-initialisation.
95 * This function is called before initialising the video output driver. It
96 * parses all suboptions and sets variables accordingly. If an error occurs
97 * (like an option being out of range, not having any value or an unknown
98 * option is stumbled upon) the player will exit. It also sets default
99 * values if necessary.
101 * \param arg A string containing all the suboptions passed to the video
102 * output driver.
104 * \return 0 All went well.
107 static int preinit(const char *arg)
109 const opt_t subopts[] = {
110 {"outfile", OPT_ARG_MSTRZ, &md5sum_outfile, NULL},
111 {NULL, 0, NULL, NULL}
114 mp_msg(MSGT_VO, MSGL_V, "%s: %s\n", info.short_name,
115 "Parsing suboptions.");
117 md5sum_outfile = strdup("md5sums");
118 if (subopt_parse(arg, subopts) != 0) {
119 return -1;
122 mp_msg(MSGT_VO, MSGL_V, "%s: outfile --> %s\n", info.short_name,
123 md5sum_outfile);
125 mp_msg(MSGT_VO, MSGL_V, "%s: %s\n", info.short_name,
126 "Suboptions parsed OK.");
127 return 0;
130 /* ------------------------------------------------------------------------- */
132 /** \brief Configure the video output driver.
134 * This functions configures the video output driver. It opens the output
135 * file to which this driver will write all the MD5 sums. If something
136 * goes wrong, the player will exit.
138 * \return 0 All went well.
141 static int config(uint32_t width, uint32_t height, uint32_t d_width,
142 uint32_t d_height, uint32_t flags, char *title,
143 uint32_t format)
145 if (vo_config_count > 0 ) { /* Already configured */
146 return 0;
149 if ( (md5sum_fd = fopen(md5sum_outfile, "w") ) == NULL ) {
150 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s\n", info.short_name,
151 _("Unable to create output file."));
152 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n",
153 info.short_name, _("This error has occurred"), strerror(errno) );
154 exit_player_bad(_("Fatal error"));
157 return 0;
160 /* ------------------------------------------------------------------------- */
162 /** \brief Write MD5 sum to output file.
164 * This function writes an ASCII representation of a 16-byte hexadecimal
165 * MD5 sum to our output file. The file descriptor is a global variable.
167 * \param md5sum Sixteen bytes that represent an MD5 sum.
169 * \return None The player will exit if a write error occurs.
172 static void md5sum_output_sum(unsigned char *md5sum) {
173 int i;
175 for(i=0; i<16; i++) {
176 if ( fprintf(md5sum_fd, "%02x", md5sum[i]) < 0 ) md5sum_write_error();
178 if ( fprintf(md5sum_fd, " frame%08d\n", framenum) < 0 )
179 md5sum_write_error();
181 framenum++;
184 /* ------------------------------------------------------------------------- */
186 static int draw_frame(uint8_t *src[])
188 mp_msg(MSGT_VO, MSGL_V, "%s: draw_frame() is called!\n", info.short_name);
189 return -1;
192 /* ------------------------------------------------------------------------- */
194 static uint32_t draw_image(mp_image_t *mpi)
196 unsigned char md5sum[16];
197 uint32_t w = mpi->w;
198 uint32_t h = mpi->h;
199 uint8_t *rgbimage = mpi->planes[0];
200 uint8_t *planeY = mpi->planes[0];
201 uint8_t *planeU = mpi->planes[1];
202 uint8_t *planeV = mpi->planes[2];
203 uint32_t strideY = mpi->stride[0];
204 uint32_t strideU = mpi->stride[1];
205 uint32_t strideV = mpi->stride[2];
207 uint8_t md5_context_memory[av_md5_size];
208 struct AVMD5 *md5_context = (struct AVMD5*) md5_context_memory;
209 unsigned int i;
211 if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Planar */
212 if (mpi->flags & MP_IMGFLAG_YUV) { /* Planar YUV */
213 av_md5_init(md5_context);
214 for (i=0; i<h; i++) {
215 av_md5_update(md5_context, planeY + i * strideY, w);
217 w = w / 2;
218 h = h / 2;
219 for (i=0; i<h; i++) {
220 av_md5_update(md5_context, planeU + i * strideU, w);
222 for (i=0; i<h; i++) {
223 av_md5_update(md5_context, planeV + i * strideV, w);
225 av_md5_final(md5_context, md5sum);
226 md5sum_output_sum(md5sum);
227 return VO_TRUE;
228 } else { /* Planar RGB */
229 return VO_FALSE;
231 } else { /* Packed */
232 if (mpi->flags & MP_IMGFLAG_YUV) { /* Packed YUV */
234 return VO_FALSE;
235 } else { /* Packed RGB */
236 av_md5_sum(md5sum, rgbimage, mpi->w * (mpi->bpp >> 3) * mpi->h);
237 md5sum_output_sum(md5sum);
238 return VO_TRUE;
242 return VO_FALSE;
245 /* ------------------------------------------------------------------------- */
247 static int draw_slice(uint8_t *src[], int stride[], int w, int h,
248 int x, int y)
250 return 0;
253 /* ------------------------------------------------------------------------- */
255 static int query_format(uint32_t format)
257 switch (format) {
258 case IMGFMT_RGB24:
259 case IMGFMT_YV12:
260 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
261 default:
262 return 0;
266 /* ------------------------------------------------------------------------- */
268 static int control(uint32_t request, void *data)
270 switch (request) {
271 case VOCTRL_QUERY_FORMAT:
272 return query_format(*((uint32_t*)data));
273 case VOCTRL_DRAW_IMAGE:
274 return draw_image(data);
276 return VO_NOTIMPL;
279 /* ------------------------------------------------------------------------- */
281 static void uninit(void)
283 free(md5sum_outfile);
284 md5sum_outfile = NULL;
285 if (md5sum_fd) fclose(md5sum_fd);
288 /* ------------------------------------------------------------------------- */
290 static void check_events(void)
294 /* ------------------------------------------------------------------------- */
296 static void draw_osd(void)
300 /* ------------------------------------------------------------------------- */
302 static void flip_page (void)
306 /* ------------------------------------------------------------------------- */
308 #undef BUFLENGTH
309 #undef MD5SUM_RGB_MODE
310 #undef MD5SUM_YUV_MODE
312 /* ------------------------------------------------------------------------- */