annotate mpjpeg.c @ 291:b19f70a6d60f libavformat

1/0 fix by (Tim Allen <tim at proximity dot com dot au>)
author michael
date Tue, 28 Oct 2003 10:55:15 +0000
parents a313e1080322
children 60f897e8dd2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
1 /*
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
2 * Multipart JPEG format
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001, 2002, 2003 Fabrice Bellard.
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
4 *
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
9 *
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
14 *
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
18 */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
19 #include "avformat.h"
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
20
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
21 /* Multipart JPEG */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
22
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
23 #define BOUNDARY_TAG "ffserver"
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
24
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
25 #ifdef CONFIG_ENCODERS
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
26 static int mpjpeg_write_header(AVFormatContext *s)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
27 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 47
diff changeset
28 uint8_t buf1[256];
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
29
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
30 snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
31 put_buffer(&s->pb, buf1, strlen(buf1));
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
32 put_flush_packet(&s->pb);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
33 return 0;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
34 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
35
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
36 static int mpjpeg_write_packet(AVFormatContext *s, int stream_index,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 65
diff changeset
37 const uint8_t *buf, int size, int64_t pts)
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
38 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 47
diff changeset
39 uint8_t buf1[256];
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
40
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
41 snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
42 put_buffer(&s->pb, buf1, strlen(buf1));
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
43 put_buffer(&s->pb, buf, size);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
44
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
45 snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
46 put_buffer(&s->pb, buf1, strlen(buf1));
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
47 put_flush_packet(&s->pb);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
48 return 0;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
49 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
50
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
51 static int mpjpeg_write_trailer(AVFormatContext *s)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
52 {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
53 return 0;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
54 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
55
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
56 static AVOutputFormat mpjpeg_format = {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
57 "mpjpeg",
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
58 "Mime multipart JPEG format",
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
59 "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
60 "mjpg",
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
61 0,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
62 CODEC_ID_NONE,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
63 CODEC_ID_MJPEG,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
64 mpjpeg_write_header,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
65 mpjpeg_write_packet,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
66 mpjpeg_write_trailer,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
67 };
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
68
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
69
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
70 /*************************************/
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
71 /* single frame JPEG */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
72
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
73 static int single_jpeg_write_header(AVFormatContext *s)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
74 {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
75 return 0;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
76 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
77
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
78 static int single_jpeg_write_packet(AVFormatContext *s, int stream_index,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 65
diff changeset
79 const uint8_t *buf, int size, int64_t pts)
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
80 {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
81 put_buffer(&s->pb, buf, size);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
82 put_flush_packet(&s->pb);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
83 return 1; /* no more data can be sent */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
84 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
85
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
86 static int single_jpeg_write_trailer(AVFormatContext *s)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
87 {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
88 return 0;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
89 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
90
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
91 static AVOutputFormat single_jpeg_format = {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
92 "singlejpeg",
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
93 "single JPEG image",
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
94 "image/jpeg",
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
95 NULL, /* note: no extension to favorize jpeg multiple images match */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
96 0,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
97 CODEC_ID_NONE,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
98 CODEC_ID_MJPEG,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
99 single_jpeg_write_header,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
100 single_jpeg_write_packet,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
101 single_jpeg_write_trailer,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
102 };
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
103
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
104 int jpeg_init(void)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
105 {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
106 av_register_output_format(&mpjpeg_format);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
107 av_register_output_format(&single_jpeg_format);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
108 return 0;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents:
diff changeset
109 }
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
110 #endif //CONFIG_ENCODERS