1 /* ------------------------------------------------------------------------- */
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 /* ------------------------------------------------------------------------- */
34 /* ------------------------------------------------------------------------- */
39 #include "subopt-helper.h"
41 #include "video_out.h"
42 #include "video_out_internal.h"
43 #include "mplayer.h" /* for exit_player_bad() */
45 #include "libavutil/md5.h"
47 /* ------------------------------------------------------------------------- */
51 /* Used for temporary buffers to store file- and pathnames */
54 /* ------------------------------------------------------------------------- */
58 static const vo_info_t info
=
60 "md5sum of each frame",
62 "Ivo van Poorten (ivop@euronet.nl)",
66 const LIBVO_EXTERN (md5sum
)
68 /* ------------------------------------------------------------------------- */
70 /* Global Variables */
72 char *md5sum_outfile
= NULL
;
77 /* ------------------------------------------------------------------------- */
79 /** \brief An error occured while writing to a file.
81 * The program failed to write data to a file.
82 * It displays a message and exits the player.
84 * \return nothing It does not return.
87 static void md5sum_write_error(void) {
88 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_ErrorWritingFile
, info
.short_name
);
89 exit_player_bad(MSGTR_Exit_error
);
92 /* ------------------------------------------------------------------------- */
94 /** \brief Pre-initialisation.
96 * This function is called before initialising the video output driver. It
97 * parses all suboptions and sets variables accordingly. If an error occurs
98 * (like an option being out of range, not having any value or an unknown
99 * option is stumbled upon) the player will exit. It also sets default
100 * values if necessary.
102 * \param arg A string containing all the suboptions passed to the video
105 * \return 0 All went well.
108 static int preinit(const char *arg
)
110 const opt_t subopts
[] = {
111 {"outfile", OPT_ARG_MSTRZ
, &md5sum_outfile
, NULL
},
112 {NULL
, 0, NULL
, NULL
}
115 mp_msg(MSGT_VO
, MSGL_INFO
, "%s: %s\n", info
.short_name
,
116 MSGTR_VO_ParsingSuboptions
);
118 md5sum_outfile
= strdup("md5sums");
119 if (subopt_parse(arg
, subopts
) != 0) {
123 mp_msg(MSGT_VO
, MSGL_V
, "%s: outfile --> %s\n", info
.short_name
,
126 mp_msg(MSGT_VO
, MSGL_INFO
, "%s: %s\n", info
.short_name
,
127 MSGTR_VO_SuboptionsParsedOK
);
131 /* ------------------------------------------------------------------------- */
133 /** \brief Configure the video output driver.
135 * This functions configures the video output driver. It opens the output
136 * file to which this driver will write all the MD5 sums. If something
137 * goes wrong, the player will exit.
139 * \return 0 All went well.
142 static int config(uint32_t width
, uint32_t height
, uint32_t d_width
,
143 uint32_t d_height
, uint32_t flags
, char *title
,
146 if (vo_config_count
> 0 ) { /* Already configured */
150 if ( (md5sum_fd
= fopen(md5sum_outfile
, "w") ) == NULL
) {
151 mp_msg(MSGT_VO
, MSGL_ERR
, "\n%s: %s\n", info
.short_name
,
152 MSGTR_VO_CantCreateFile
);
153 mp_msg(MSGT_VO
, MSGL_ERR
, "%s: %s: %s\n",
154 info
.short_name
, MSGTR_VO_GenericError
, strerror(errno
) );
155 exit_player_bad(MSGTR_Exit_error
);
161 /* ------------------------------------------------------------------------- */
163 /** \brief Write MD5 sum to output file.
165 * This function writes an ASCII representation of a 16-byte hexadecimal
166 * MD5 sum to our output file. The file descriptor is a global variable.
168 * \param md5sum Sixteen bytes that represent an MD5 sum.
170 * \return None The player will exit if a write error occurs.
173 static void md5sum_output_sum(unsigned char *md5sum
) {
176 for(i
=0; i
<16; i
++) {
177 if ( fprintf(md5sum_fd
, "%02x", md5sum
[i
]) < 0 ) md5sum_write_error();
179 if ( fprintf(md5sum_fd
, " frame%08d\n", framenum
) < 0 )
180 md5sum_write_error();
185 /* ------------------------------------------------------------------------- */
187 static int draw_frame(uint8_t *src
[])
189 mp_msg(MSGT_VO
, MSGL_V
, "%s: draw_frame() is called!\n", info
.short_name
);
193 /* ------------------------------------------------------------------------- */
195 static uint32_t draw_image(mp_image_t
*mpi
)
197 unsigned char md5sum
[16];
200 uint8_t *rgbimage
= mpi
->planes
[0];
201 uint8_t *planeY
= mpi
->planes
[0];
202 uint8_t *planeU
= mpi
->planes
[1];
203 uint8_t *planeV
= mpi
->planes
[2];
204 uint32_t strideY
= mpi
->stride
[0];
205 uint32_t strideU
= mpi
->stride
[1];
206 uint32_t strideV
= mpi
->stride
[2];
208 uint8_t md5_context_memory
[av_md5_size
];
209 struct AVMD5
*md5_context
= (struct AVMD5
*) md5_context_memory
;
212 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) { /* Planar */
213 if (mpi
->flags
& MP_IMGFLAG_YUV
) { /* Planar YUV */
214 av_md5_init(md5_context
);
215 for (i
=0; i
<h
; i
++) {
216 av_md5_update(md5_context
, planeY
+ i
* strideY
, w
);
220 for (i
=0; i
<h
; i
++) {
221 av_md5_update(md5_context
, planeU
+ i
* strideU
, w
);
222 av_md5_update(md5_context
, planeV
+ i
* strideV
, w
);
224 av_md5_final(md5_context
, md5sum
);
225 md5sum_output_sum(md5sum
);
227 } else { /* Planar RGB */
230 } else { /* Packed */
231 if (mpi
->flags
& MP_IMGFLAG_YUV
) { /* Packed YUV */
234 } else { /* Packed RGB */
235 av_md5_sum(md5sum
, rgbimage
, mpi
->w
* (mpi
->bpp
>> 3) * mpi
->h
);
236 md5sum_output_sum(md5sum
);
244 /* ------------------------------------------------------------------------- */
246 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
,
252 /* ------------------------------------------------------------------------- */
254 static int query_format(uint32_t format
)
259 return VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
;
265 /* ------------------------------------------------------------------------- */
267 static int control(uint32_t request
, void *data
)
270 case VOCTRL_QUERY_FORMAT
:
271 return query_format(*((uint32_t*)data
));
272 case VOCTRL_DRAW_IMAGE
:
273 return draw_image(data
);
278 /* ------------------------------------------------------------------------- */
280 static void uninit(void)
282 if (md5sum_outfile
) {
283 free(md5sum_outfile
);
284 md5sum_outfile
= NULL
;
286 if (md5sum_fd
) fclose(md5sum_fd
);
289 /* ------------------------------------------------------------------------- */
291 static void check_events(void)
295 /* ------------------------------------------------------------------------- */
297 static void draw_osd(void)
301 /* ------------------------------------------------------------------------- */
303 static void flip_page (void)
307 /* ------------------------------------------------------------------------- */
310 #undef MD5SUM_RGB_MODE
311 #undef MD5SUM_YUV_MODE
313 /* ------------------------------------------------------------------------- */