Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_04 / synfig-core / src / modules / mod_libavcodec / libavformat / mpjpeg.c
1 /*
2  * Multipart JPEG format
3  * Copyright (c) 2000, 2001, 2002, 2003 Fabrice Bellard.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19 #include "avformat.h"
20
21 /* Multipart JPEG */
22
23 #define BOUNDARY_TAG "ffserver"
24
25 static int mpjpeg_write_header(AVFormatContext *s)
26 {
27     uint8_t buf1[256];
28
29     snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG);
30     put_buffer(&s->pb, buf1, strlen(buf1));
31     put_flush_packet(&s->pb);
32     return 0;
33 }
34
35 static int mpjpeg_write_packet(AVFormatContext *s, int stream_index, 
36                                const uint8_t *buf, int size, int64_t pts)
37 {
38     uint8_t buf1[256];
39
40     snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
41     put_buffer(&s->pb, buf1, strlen(buf1));
42     put_buffer(&s->pb, buf, size);
43
44     snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
45     put_buffer(&s->pb, buf1, strlen(buf1));
46     put_flush_packet(&s->pb);
47     return 0;
48 }
49
50 static int mpjpeg_write_trailer(AVFormatContext *s)
51 {
52     return 0;
53 }
54
55 static AVOutputFormat mpjpeg_format = {
56     "mpjpeg",
57     "Mime multipart JPEG format",
58     "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
59     "mjpg",
60     0,
61     CODEC_ID_NONE,
62     CODEC_ID_MJPEG,
63     mpjpeg_write_header,
64     mpjpeg_write_packet,
65     mpjpeg_write_trailer,
66 };
67
68
69 /*************************************/
70 /* single frame JPEG */
71
72 static int single_jpeg_write_header(AVFormatContext *s)
73 {
74     return 0;
75 }
76
77 static int single_jpeg_write_packet(AVFormatContext *s, int stream_index,
78                                     const uint8_t *buf, int size, int64_t pts)
79 {
80     put_buffer(&s->pb, buf, size);
81     put_flush_packet(&s->pb);
82     return 1; /* no more data can be sent */
83 }
84
85 static int single_jpeg_write_trailer(AVFormatContext *s)
86 {
87     return 0;
88 }
89
90 static AVOutputFormat single_jpeg_format = {
91     "singlejpeg",
92     "single JPEG image",
93     "image/jpeg",
94     NULL, /* note: no extension to favorize jpeg multiple images match */
95     0,
96     CODEC_ID_NONE,
97     CODEC_ID_MJPEG,
98     single_jpeg_write_header,
99     single_jpeg_write_packet,
100     single_jpeg_write_trailer,
101 };
102
103 int jpeg_init(void)
104 {
105     av_register_output_format(&mpjpeg_format);
106     av_register_output_format(&single_jpeg_format);
107     return 0;
108 }