Initial revision
[libav.git] / jpegenc.c
CommitLineData
9aeeeb63
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 "mpegenc.h"
24
25/* Multipart JPEG */
26
27#define BOUNDARY_TAG "ffserver"
28
29static 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
39static int mpjpeg_write_video(AVFormatContext *s, UINT8 *buf, int size)
40{
41 UINT8 buf1[256];
42
43 snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
44 put_buffer(&s->pb, buf1, strlen(buf1));
45 put_buffer(&s->pb, buf, size);
46
47 snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
48 put_buffer(&s->pb, buf1, strlen(buf1));
49 put_flush_packet(&s->pb);
50 return 0;
51}
52
53static int mpjpeg_write_trailer(AVFormatContext *s)
54{
55 return 0;
56}
57
58AVFormat mpjpeg_format = {
59 "mpjpeg",
60 "Mime multipart JPEG format",
61 "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
62 "mjpg",
63 CODEC_ID_NONE,
64 CODEC_ID_MJPEG,
65 mpjpeg_write_header,
66 NULL,
67 mpjpeg_write_video,
68 mpjpeg_write_trailer,
69};
70
71
72/* single frame JPEG */
73
74static int jpeg_write_header(AVFormatContext *s)
75{
76 return 0;
77}
78
79static int jpeg_write_video(AVFormatContext *s, UINT8 *buf, int size)
80{
81 put_buffer(&s->pb, buf, size);
82 put_flush_packet(&s->pb);
83 return 1; /* no more data can be sent */
84}
85
86static int jpeg_write_trailer(AVFormatContext *s)
87{
88 return 0;
89}
90
91AVFormat jpeg_format = {
92 "jpeg",
93 "JPEG image",
94 "image/jpeg",
95 "jpg,jpeg",
96 CODEC_ID_NONE,
97 CODEC_ID_MJPEG,
98 jpeg_write_header,
99 NULL,
100 jpeg_write_video,
101 jpeg_write_trailer,
102};