Commit | Line | Data |
---|---|---|
de6d9b64 FB |
1 | /* |
2 | * Miscellaneous MJPEG based formats | |
3 | * Copyright (c) 2000 Gerard Lantau. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program 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 | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 | */ | |
19 | #include <stdlib.h> | |
20 | #include <stdio.h> | |
21 | #include <netinet/in.h> | |
22 | #include <string.h> | |
23 | #include "avformat.h" | |
24 | ||
25 | /* Multipart JPEG */ | |
26 | ||
27 | #define BOUNDARY_TAG "ffserver" | |
28 | ||
29 | static int mpjpeg_write_header(AVFormatContext *s) | |
30 | { | |
31 | UINT8 buf1[256]; | |
32 | ||
33 | snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG); | |
34 | put_buffer(&s->pb, buf1, strlen(buf1)); | |
35 | put_flush_packet(&s->pb); | |
36 | return 0; | |
37 | } | |
38 | ||
39 | static int mpjpeg_write_packet(AVFormatContext *s, | |
40 | int stream_index, UINT8 *buf, int size) | |
41 | { | |
42 | UINT8 buf1[256]; | |
43 | ||
44 | snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n"); | |
45 | put_buffer(&s->pb, buf1, strlen(buf1)); | |
46 | put_buffer(&s->pb, buf, size); | |
47 | ||
48 | snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG); | |
49 | put_buffer(&s->pb, buf1, strlen(buf1)); | |
50 | put_flush_packet(&s->pb); | |
51 | return 0; | |
52 | } | |
53 | ||
54 | static int mpjpeg_write_trailer(AVFormatContext *s) | |
55 | { | |
56 | return 0; | |
57 | } | |
58 | ||
59 | AVFormat mpjpeg_format = { | |
60 | "mpjpeg", | |
61 | "Mime multipart JPEG format", | |
62 | "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG, | |
63 | "mjpg", | |
64 | CODEC_ID_NONE, | |
65 | CODEC_ID_MJPEG, | |
66 | mpjpeg_write_header, | |
67 | mpjpeg_write_packet, | |
68 | mpjpeg_write_trailer, | |
69 | }; | |
70 | ||
71 | ||
72 | /* single frame JPEG */ | |
73 | ||
74 | static int jpeg_write_header(AVFormatContext *s) | |
75 | { | |
76 | return 0; | |
77 | } | |
78 | ||
79 | static int jpeg_write_packet(AVFormatContext *s, int stream_index, | |
80 | UINT8 *buf, int size) | |
81 | { | |
82 | put_buffer(&s->pb, buf, size); | |
83 | put_flush_packet(&s->pb); | |
84 | return 1; /* no more data can be sent */ | |
85 | } | |
86 | ||
87 | static int jpeg_write_trailer(AVFormatContext *s) | |
88 | { | |
89 | return 0; | |
90 | } | |
91 | ||
92 | AVFormat jpeg_format = { | |
93 | "jpeg", | |
94 | "JPEG image", | |
95 | "image/jpeg", | |
96 | "jpg,jpeg", | |
97 | CODEC_ID_NONE, | |
98 | CODEC_ID_MJPEG, | |
99 | jpeg_write_header, | |
100 | jpeg_write_packet, | |
101 | jpeg_write_trailer, | |
102 | }; |