movenccenc.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * MOV CENC (Common Encryption) writer
  3. * Copyright (c) 2015 Eran Kornblau <erankor at gmail dot com>
  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. #ifndef AVFORMAT_MOVENCCENC_H
  22. #define AVFORMAT_MOVENCCENC_H
  23. #include "libavutil/aes_ctr.h"
  24. #include "avformat.h"
  25. #include "avio.h"
  26. #define CENC_KID_SIZE (16)
  27. struct MOVTrack;
  28. typedef struct {
  29. struct AVAESCTR* aes_ctr;
  30. uint8_t* auxiliary_info;
  31. size_t auxiliary_info_size;
  32. size_t auxiliary_info_alloc_size;
  33. uint32_t auxiliary_info_entries;
  34. /* subsample support */
  35. int use_subsamples;
  36. uint16_t subsample_count;
  37. size_t auxiliary_info_subsample_start;
  38. uint8_t* auxiliary_info_sizes;
  39. size_t auxiliary_info_sizes_alloc_size;
  40. } MOVMuxCencContext;
  41. /**
  42. * Initialize a CENC context
  43. * @param key encryption key, must have a length of AES_CTR_KEY_SIZE
  44. * @param use_subsamples when enabled parts of a packet can be encrypted, otherwise the whole packet is encrypted
  45. */
  46. int ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t* encryption_key, int use_subsamples, int bitexact);
  47. /**
  48. * Free a CENC context
  49. */
  50. void ff_mov_cenc_free(MOVMuxCencContext* ctx);
  51. /**
  52. * Write a fully encrypted packet
  53. */
  54. int ff_mov_cenc_write_packet(MOVMuxCencContext* ctx, AVIOContext *pb, const uint8_t *buf_in, int size);
  55. /**
  56. * Parse AVC NAL units from annex B format, the nal size and type are written in the clear while the body is encrypted
  57. */
  58. int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb, const uint8_t *buf_in, int size);
  59. /**
  60. * Write AVC NAL units that are in MP4 format, the nal size and type are written in the clear while the body is encrypted
  61. */
  62. int ff_mov_cenc_avc_write_nal_units(AVFormatContext *s, MOVMuxCencContext* ctx, int nal_length_size,
  63. AVIOContext *pb, const uint8_t *buf_in, int size);
  64. /**
  65. * Write the cenc atoms that should reside inside stbl
  66. */
  67. void ff_mov_cenc_write_stbl_atoms(MOVMuxCencContext* ctx, AVIOContext *pb);
  68. /**
  69. * Write the sinf atom, contained inside stsd
  70. */
  71. int ff_mov_cenc_write_sinf_tag(struct MOVTrack* track, AVIOContext *pb, uint8_t* kid);
  72. #endif /* AVFORMAT_MOVENCCENC_H */