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.

110 lines
3.2KB

  1. /*
  2. * MD5 encoder (for codec/format testing)
  3. * Copyright (c) 2009 Reimar Döffinger, based on crcenc (c) 2002 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/md5.h"
  22. #include "avformat.h"
  23. #include "internal.h"
  24. #define PRIVSIZE 512
  25. static void md5_finish(struct AVFormatContext *s, char *buf)
  26. {
  27. uint8_t md5[16];
  28. int i, offset = strlen(buf);
  29. av_md5_final(s->priv_data, md5);
  30. for (i = 0; i < sizeof(md5); i++) {
  31. snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
  32. offset += 2;
  33. }
  34. buf[offset] = '\n';
  35. buf[offset+1] = 0;
  36. avio_write(s->pb, buf, strlen(buf));
  37. avio_flush(s->pb);
  38. }
  39. #if CONFIG_MD5_MUXER
  40. static int write_header(struct AVFormatContext *s)
  41. {
  42. if (PRIVSIZE < av_md5_size) {
  43. av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
  44. return -1;
  45. }
  46. av_md5_init(s->priv_data);
  47. return 0;
  48. }
  49. static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
  50. {
  51. av_md5_update(s->priv_data, pkt->data, pkt->size);
  52. return 0;
  53. }
  54. static int write_trailer(struct AVFormatContext *s)
  55. {
  56. char buf[64] = "MD5=";
  57. md5_finish(s, buf);
  58. return 0;
  59. }
  60. AVOutputFormat ff_md5_muxer = {
  61. .name = "md5",
  62. .long_name = NULL_IF_CONFIG_SMALL("MD5 testing format"),
  63. .priv_data_size = PRIVSIZE,
  64. .audio_codec = CODEC_ID_PCM_S16LE,
  65. .video_codec = CODEC_ID_RAWVIDEO,
  66. .write_header = write_header,
  67. .write_packet = write_packet,
  68. .write_trailer = write_trailer,
  69. .flags = AVFMT_NOTIMESTAMPS,
  70. };
  71. #endif
  72. #if CONFIG_FRAMEMD5_MUXER
  73. static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
  74. {
  75. char buf[256];
  76. if (PRIVSIZE < av_md5_size) {
  77. av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
  78. return -1;
  79. }
  80. av_md5_init(s->priv_data);
  81. av_md5_update(s->priv_data, pkt->data, pkt->size);
  82. snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8d, %8d, ",
  83. pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
  84. md5_finish(s, buf);
  85. return 0;
  86. }
  87. AVOutputFormat ff_framemd5_muxer = {
  88. .name = "framemd5",
  89. .long_name = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"),
  90. .priv_data_size = PRIVSIZE,
  91. .audio_codec = CODEC_ID_PCM_S16LE,
  92. .video_codec = CODEC_ID_RAWVIDEO,
  93. .write_header = ff_framehash_write_header,
  94. .write_packet = framemd5_write_packet,
  95. .flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
  96. };
  97. #endif