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.

111 lines
2.9KB

  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. /* Multipart JPEG */
  21. #define BOUNDARY_TAG "ffserver"
  22. #ifdef CONFIG_ENCODERS
  23. static int mpjpeg_write_header(AVFormatContext *s)
  24. {
  25. uint8_t buf1[256];
  26. snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG);
  27. put_buffer(&s->pb, buf1, strlen(buf1));
  28. put_flush_packet(&s->pb);
  29. return 0;
  30. }
  31. static int mpjpeg_write_packet(AVFormatContext *s, int stream_index,
  32. const uint8_t *buf, int size, int64_t pts)
  33. {
  34. uint8_t buf1[256];
  35. snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
  36. put_buffer(&s->pb, buf1, strlen(buf1));
  37. put_buffer(&s->pb, buf, size);
  38. snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
  39. put_buffer(&s->pb, buf1, strlen(buf1));
  40. put_flush_packet(&s->pb);
  41. return 0;
  42. }
  43. static int mpjpeg_write_trailer(AVFormatContext *s)
  44. {
  45. return 0;
  46. }
  47. static AVOutputFormat mpjpeg_format = {
  48. "mpjpeg",
  49. "Mime multipart JPEG format",
  50. "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
  51. "mjpg",
  52. 0,
  53. CODEC_ID_NONE,
  54. CODEC_ID_MJPEG,
  55. mpjpeg_write_header,
  56. mpjpeg_write_packet,
  57. mpjpeg_write_trailer,
  58. };
  59. /*************************************/
  60. /* single frame JPEG */
  61. static int single_jpeg_write_header(AVFormatContext *s)
  62. {
  63. return 0;
  64. }
  65. static int single_jpeg_write_packet(AVFormatContext *s, int stream_index,
  66. const uint8_t *buf, int size, int64_t pts)
  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 single_jpeg_write_trailer(AVFormatContext *s)
  73. {
  74. return 0;
  75. }
  76. static AVOutputFormat single_jpeg_format = {
  77. "singlejpeg",
  78. "single JPEG image",
  79. "image/jpeg",
  80. NULL, /* note: no extension to favorize jpeg multiple images match */
  81. 0,
  82. CODEC_ID_NONE,
  83. CODEC_ID_MJPEG,
  84. single_jpeg_write_header,
  85. single_jpeg_write_packet,
  86. single_jpeg_write_trailer,
  87. };
  88. int jpeg_init(void)
  89. {
  90. av_register_output_format(&mpjpeg_format);
  91. av_register_output_format(&single_jpeg_format);
  92. return 0;
  93. }
  94. #endif //CONFIG_ENCODERS