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.

109 lines
2.7KB

  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, AVPacket *pkt)
  32. {
  33. uint8_t buf1[256];
  34. snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
  35. put_buffer(&s->pb, buf1, strlen(buf1));
  36. put_buffer(&s->pb, pkt->data, pkt->size);
  37. snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
  38. put_buffer(&s->pb, buf1, strlen(buf1));
  39. put_flush_packet(&s->pb);
  40. return 0;
  41. }
  42. static int mpjpeg_write_trailer(AVFormatContext *s)
  43. {
  44. return 0;
  45. }
  46. static AVOutputFormat mpjpeg_format = {
  47. "mpjpeg",
  48. "Mime multipart JPEG format",
  49. "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
  50. "mjpg",
  51. 0,
  52. CODEC_ID_NONE,
  53. CODEC_ID_MJPEG,
  54. mpjpeg_write_header,
  55. mpjpeg_write_packet,
  56. mpjpeg_write_trailer,
  57. };
  58. /*************************************/
  59. /* single frame JPEG */
  60. static int single_jpeg_write_header(AVFormatContext *s)
  61. {
  62. return 0;
  63. }
  64. static int single_jpeg_write_packet(AVFormatContext *s, AVPacket *pkt)
  65. {
  66. put_buffer(&s->pb, pkt->data, pkt->size);
  67. put_flush_packet(&s->pb);
  68. return 1; /* no more data can be sent */
  69. }
  70. static int single_jpeg_write_trailer(AVFormatContext *s)
  71. {
  72. return 0;
  73. }
  74. static AVOutputFormat single_jpeg_format = {
  75. "singlejpeg",
  76. "single JPEG image",
  77. "image/jpeg",
  78. NULL, /* note: no extension to favorize jpeg multiple images match */
  79. 0,
  80. CODEC_ID_NONE,
  81. CODEC_ID_MJPEG,
  82. single_jpeg_write_header,
  83. single_jpeg_write_packet,
  84. single_jpeg_write_trailer,
  85. };
  86. int jpeg_init(void)
  87. {
  88. av_register_output_format(&mpjpeg_format);
  89. av_register_output_format(&single_jpeg_format);
  90. return 0;
  91. }
  92. #endif //CONFIG_ENCODERS