annotate libvo/vo_jpeg.c @ 13217:43fe55f36522

One-time cosmetics update. I finally got rid of the horrible one-space indentation. Changed it to four spaces. Also changed all function calls, assignments, et cetera, to conform to a certain 'standard'. Removed all trailing whitespace. No more tabs (width can be different from editor to editor), it's all spaces now. Next semi-cosmetics stop will be doxygen comments. Tested: It compiles to exactly the same object as before. No functional change has been made.
author ivo
date Wed, 01 Sep 2004 02:31:24 +0000
parents b872a27aea9e
children 933b45ad31d5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
1 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
2
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
3 /*
12857
db49cdedb88d embarassing typo
diego
parents: 9989
diff changeset
4 * vo_jpeg.c, JPEG Renderer for MPlayer
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
5 *
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
6 *
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
7 * Changelog
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
8 *
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
9 * Original version: Copyright 2002 by Pontscho (pontscho@makacs.poliod.hu)
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
10 * 2003-04-25 Spring cleanup -- Alex
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
11 * 2004-08-04 Added multiple subdirectory support -- Ivo (ivop@euronet.nl)
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
12 * 2004-09-01 Cosmetics update -- Ivo
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
13 *
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
14 */
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
15
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
16 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
17
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
18 /* Global Includes */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
19
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
20 #include <stdio.h>
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
21 #include <stdlib.h>
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
22 #include <string.h>
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
23 #include <errno.h>
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
24 #include <jpeglib.h>
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
25 #include <sys/stat.h>
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
26 #include <sys/types.h>
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
27 #include <unistd.h>
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
28
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
29 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
30
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
31 /* Local Includes */
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
32
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
33 #include "config.h"
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
34 #include "mp_msg.h"
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
35 #include "video_out.h"
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
36 #include "video_out_internal.h"
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
37 #include "mplayer.h" /* for exit_player() */
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
38 #include "help_mp.h"
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
39
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
40 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
41
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
42 /* Defines */
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
43
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
44 /* Used for temporary buffers to store file- and pathnames */
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
45 #define BUFLENGTH 512
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
46
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
47 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
48
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
49 /* Info */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
50
8148
5b39e79af5fe removed get_info, using the same sheme as in libmpcodecs instead
alex
parents: 7487
diff changeset
51 static vo_info_t info=
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
52 {
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
53 "JPEG file",
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
54 "jpeg",
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
55 "Zoltan Ponekker (pontscho@makacs.poliod.hu)",
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
56 ""
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
57 };
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
58
8148
5b39e79af5fe removed get_info, using the same sheme as in libmpcodecs instead
alex
parents: 7487
diff changeset
59 LIBVO_EXTERN (jpeg)
5b39e79af5fe removed get_info, using the same sheme as in libmpcodecs instead
alex
parents: 7487
diff changeset
60
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
61 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
62
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
63 /* Global Variables */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
64
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
65 static int image_width;
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
66 static int image_height;
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
67
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
68 int jpeg_baseline = 1;
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
69 int jpeg_progressive_mode = 0;
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
70 int jpeg_optimize = 100;
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
71 int jpeg_smooth = 0;
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
72 int jpeg_quality = 75;
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
73 char *jpeg_outdir = ".";
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
74 char *jpeg_subdirs = NULL;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
75 int jpeg_maxfiles = 1000;
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
76
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
77 static int framenum = 0;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
78
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
79 /* ------------------------------------------------------------------------- */
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
80
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
81 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
82 uint32_t d_height, uint32_t fullscreen, char *title,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
83 uint32_t format)
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
84 {
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
85 char buf[BUFLENGTH];
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
86 struct stat stat_p;
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
87
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
88 /* Create outdir.
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
89 * If it already exists, test if it's a writable directory */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
90
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
91 snprintf(buf, BUFLENGTH, "%s", jpeg_outdir);
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
92
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
93 if ( mkdir(buf, 0755) < 0 ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
94 switch (errno) { /* use switch in case other errors need to be caught
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
95 and handled in the future */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
96 case EEXIST:
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
97 if ( stat(buf, &stat_p ) < 0 ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
98 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
99 MSGTR_VO_JPEG_GenericError, strerror(errno) );
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
100 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
101 MSGTR_VO_JPEG_UnableToAccess,buf);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
102 exit_player(MSGTR_Exit_error);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
103 }
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
104 if ( !S_ISDIR(stat_p.st_mode) ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
105 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
106 buf, MSGTR_VO_JPEG_ExistsButNoDirectory);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
107 exit_player(MSGTR_Exit_error);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
108 }
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
109 if ( !(stat_p.st_mode & S_IWUSR) ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
110 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
111 MSGTR_VO_JPEG_DirExistsButNotWritable);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
112 exit_player(MSGTR_Exit_error);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
113 }
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
114
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
115 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
116 MSGTR_VO_JPEG_DirExistsAndIsWritable);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
117 break;
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
118
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
119 default:
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
120 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
121 MSGTR_VO_JPEG_GenericError, strerror(errno) );
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
122 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
123 MSGTR_VO_JPEG_CantCreateDirectory);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
124 exit_player(MSGTR_Exit_error);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
125 } /* end switch */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
126 } else {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
127 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
128 MSGTR_VO_JPEG_DirectoryCreateSuccess);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
129 } /* end if */
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
130
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
131 image_height = height;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
132 image_width = width;
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
133
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
134 return 0;
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
135 }
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
136
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
137 /* ------------------------------------------------------------------------- */
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
138
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
139 static uint32_t jpeg_write(uint8_t * name, uint8_t * buffer)
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
140 {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
141 FILE *outfile;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
142 struct jpeg_compress_struct cinfo;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
143 struct jpeg_error_mgr jerr;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
144 JSAMPROW row_pointer[1];
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
145 int row_stride;
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
146
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
147 if ( !buffer ) return 1;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
148 if ( (outfile = fopen(name, "wb") ) == NULL ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
149 return 1;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
150 }
8267
1ac2523775ad patch from tonglijing <tong@intec.iscas.ac.cn>
pontscho
parents: 8148
diff changeset
151
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
152 cinfo.err = jpeg_std_error(&jerr);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
153 jpeg_create_compress(&cinfo);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
154 jpeg_stdio_dest(&cinfo, outfile);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
155
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
156 cinfo.image_width = image_width;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
157 cinfo.image_height = image_height;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
158 cinfo.input_components = 3;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
159 cinfo.in_color_space = JCS_RGB;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
160
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
161 jpeg_set_defaults(&cinfo);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
162 jpeg_set_quality(&cinfo,jpeg_quality, jpeg_baseline);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
163 cinfo.optimize_coding = jpeg_optimize;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
164 cinfo.smoothing_factor = jpeg_smooth;
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
165
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
166 if ( jpeg_progressive_mode ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
167 jpeg_simple_progression(&cinfo);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
168 }
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
169
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
170 jpeg_start_compress(&cinfo, TRUE);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
171
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
172 row_stride = image_width * 3;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
173 while (cinfo.next_scanline < cinfo.image_height) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
174 row_pointer[0] = &buffer[cinfo.next_scanline * row_stride];
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
175 (void)jpeg_write_scanlines(&cinfo, row_pointer,1);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
176 }
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
177
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
178 jpeg_finish_compress(&cinfo);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
179 fclose(outfile);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
180 jpeg_destroy_compress(&cinfo);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
181
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
182 return 0;
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
183 }
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
184
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
185 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
186
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
187 static uint32_t draw_frame(uint8_t *src[])
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
188 {
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
189 static uint32_t framecounter = 0, subdircounter = 0;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
190 char buf[BUFLENGTH];
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
191 uint8_t *dst = src[0];
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
192 static char subdirname[BUFLENGTH] = "";
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
193 struct stat stat_p;
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
194
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
195 /* Start writing to new subdirectory after a certain amount of frames */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
196 if ( framecounter == jpeg_maxfiles ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
197 framecounter = 0;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
198 }
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
199
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
200 /* If framecounter is zero (or reset to zero), increment subdirectory
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
201 * number and create the subdirectory.
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
202 * If jpeg_subdirs is not set, do nothing and resort to old behaviour. */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
203 if ( !framecounter && jpeg_subdirs ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
204 snprintf(subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
205 ++subdircounter);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
206 snprintf(buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
207 if ( mkdir(buf, 0755) < 0 ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
208 switch (errno) { /* use switch in case other errors need to be
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
209 caught and handled in the future */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
210 case EEXIST:
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
211 if ( stat(buf, &stat_p) < 0 ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
212 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n",
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
213 info.short_name, MSGTR_VO_JPEG_GenericError,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
214 strerror(errno) );
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
215 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n",
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
216 info.short_name, MSGTR_VO_JPEG_UnableToAccess,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
217 buf);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
218 exit_player(MSGTR_Exit_error);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
219 }
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
220 if ( !S_ISDIR(stat_p.st_mode) ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
221 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s %s\n",
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
222 info.short_name, buf,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
223 MSGTR_VO_JPEG_ExistsButNoDirectory);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
224 exit_player(MSGTR_Exit_error);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
225 }
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
226 if ( !(stat_p.st_mode & S_IWUSR) ) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
227 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s\n",
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
228 info.short_name, buf,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
229 MSGTR_VO_JPEG_DirExistsButNotWritable);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
230 exit_player(MSGTR_Exit_error);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
231 }
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
232
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
233 mp_msg(MSGT_VO, MSGL_INFO, "\n%s: %s - %s\n",
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
234 info.short_name, buf,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
235 MSGTR_VO_JPEG_DirExistsAndIsWritable);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
236 break;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
237
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
238 default:
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
239 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
240 MSGTR_VO_JPEG_GenericError, strerror(errno) );
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
241 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s.\n",
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
242 info.short_name, buf,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
243 MSGTR_VO_JPEG_CantCreateDirectory);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
244 exit_player(MSGTR_Exit_error);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
245 break;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
246 }
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
247 } /* switch */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
248 } /* if !framecounter && jpeg_subdirs */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
249
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
250 framenum++;
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
251
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
252 /* snprintf the full pathname of the outputfile */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
253 snprintf(buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
254 framenum);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
255
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
256 framecounter++;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
257
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
258 return jpeg_write(buf, src[0]);
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
259 }
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
260
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
261 /* ------------------------------------------------------------------------- */
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
262
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
263 static void draw_osd(void)
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
264 {
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
265 }
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
266
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
267 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
268
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
269 static void flip_page (void)
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
270 {
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
271 }
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
272
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
273 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
274
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
275 static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h,
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
276 int x, int y)
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
277 {
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
278 return 0;
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
279 }
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
280
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
281 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
282
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
283 static uint32_t query_format(uint32_t format)
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
284 {
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
285 if (format == IMGFMT_RGB24) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
286 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
287 }
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
288
9989
98791b90215a Spring cleanup: supporting only RGB24 as input (native jpeg lib supports only that, maybe we could later add nativ YCbCr (YUV) support, but not swscale ones)
alex
parents: 9019
diff changeset
289 return 0;
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
290 }
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
291
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
292 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
293
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
294 static void uninit(void)
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
295 {
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
296 }
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
297
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
298 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
299
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
300 static void check_events(void)
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
301 {
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
302 }
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
303
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
304 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
305
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
306 static uint32_t preinit(const char *arg)
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
307 {
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
308 return 0;
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
309 }
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
310
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
311 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
312
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
313 static uint32_t control(uint32_t request, void *data, ...)
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
314 {
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
315 switch (request) {
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
316 case VOCTRL_QUERY_FORMAT:
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
317 return query_format(*((uint32_t*)data));
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
318 }
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
319 return VO_NOTIMPL;
5648
c3ca8f05b3a9 add jpeg support for libvo
pontscho
parents:
diff changeset
320 }
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
321
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
322 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
323
13158
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
324 #undef BUFLENGTH
b872a27aea9e Added output to multiple directories for vo_jpeg.
ivo
parents: 12857
diff changeset
325
13217
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
326 /* ------------------------------------------------------------------------- */
43fe55f36522 One-time cosmetics update.
ivo
parents: 13158
diff changeset
327