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.5KB

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