You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.4KB

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