hls_sample_encryption.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Apple HTTP Live Streaming Sample Encryption/Decryption
  3. *
  4. * Copyright (c) 2021 Nachiket Tarate
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * Apple HTTP Live Streaming Sample Encryption
  25. * https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/HLS_Sample_Encryption
  26. */
  27. #ifndef AVFORMAT_HLS_SAMPLE_ENCRYPTION_H
  28. #define AVFORMAT_HLS_SAMPLE_ENCRYPTION_H
  29. #include <stddef.h>
  30. #include <stdint.h>
  31. #include "libavcodec/codec_id.h"
  32. #include "libavcodec/packet.h"
  33. #include "avformat.h"
  34. #define HLS_MAX_ID3_TAGS_DATA_LEN 138
  35. #define HLS_MAX_AUDIO_SETUP_DATA_LEN 10
  36. typedef struct HLSCryptoContext {
  37. struct AVAES *aes_ctx;
  38. uint8_t key[16];
  39. uint8_t iv[16];
  40. } HLSCryptoContext;
  41. typedef struct HLSAudioSetupInfo {
  42. enum AVCodecID codec_id;
  43. uint32_t codec_tag;
  44. uint16_t priming;
  45. uint8_t version;
  46. uint8_t setup_data_length;
  47. uint8_t setup_data[HLS_MAX_AUDIO_SETUP_DATA_LEN];
  48. } HLSAudioSetupInfo;
  49. void ff_hls_senc_read_audio_setup_info(HLSAudioSetupInfo *info, const uint8_t *buf, size_t size);
  50. int ff_hls_senc_parse_audio_setup_info(AVStream *st, HLSAudioSetupInfo *info);
  51. int ff_hls_senc_decrypt_frame(enum AVCodecID codec_id, HLSCryptoContext *crypto_ctx, AVPacket *pkt);
  52. #endif /* AVFORMAT_HLS_SAMPLE_ENCRYPTION_H */