[FFmpeg-devel] [PATCH] avformat/utils: Don't parse encrypted packets.
Jacob Trimble
modmaker at google.com
Tue Aug 28 20:58:43 EEST 2018
If a packet is full-sample encrypted, then packet data can't be parsed
without decrypting it. So this skips the packet parsing for those
packets. If the packet has sub-sample encryption, it is assumed that
the headers are in the clear and the parser will only need that info.
Signed-off-by: Jacob Trimble <modmaker at google.com>
---
libavformat/utils.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/libavformat/utils.c b/libavformat/utils.c
index b0b5e164a6..1107787eae 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -27,6 +27,7 @@
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/dict.h"
+#include "libavutil/encryption_info.h"
#include "libavutil/internal.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
@@ -1576,6 +1577,9 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
while (!got_packet && !s->internal->parse_queue) {
AVStream *st;
AVPacket cur_pkt;
+ uint8_t *enc_side_data;
+ int enc_side_data_size;
+ int is_full_encrypted = 0;
/* read next packet */
ret = ff_read_packet(s, &cur_pkt);
@@ -1659,7 +1663,22 @@ FF_ENABLE_DEPRECATION_WARNINGS
st->parser->flags |= PARSER_FLAG_USE_CODEC_TS;
}
- if (!st->need_parsing || !st->parser) {
+ /* if the packet is full-sample encrypted, we can't parse it. If the
+ * packet uses sub-sample encryption, assume the headers are clear and
+ * can still be parsed.
+ */
+ enc_side_data = av_packet_get_side_data(
+ &cur_pkt, AV_PKT_DATA_ENCRYPTION_INFO, &enc_side_data_size);
+ if (enc_side_data) {
+ AVEncryptionInfo *enc_info =
+ av_encryption_info_get_side_data(enc_side_data, enc_side_data_size);
+ if (enc_info) {
+ is_full_encrypted = enc_info->subsample_count == 0;
+ av_encryption_info_free(enc_info);
+ }
+ }
+
+ if (!st->need_parsing || !st->parser || is_full_encrypted) {
/* no parsing needed: we just output the packet as is */
*pkt = cur_pkt;
compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
--
2.19.0.rc0.228.g281dcd1b4d0-goog
More information about the ffmpeg-devel
mailing list