From patchwork Thu May 2 05:03:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Goyal X-Patchwork-Id: 12965 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 02B78448835 for ; Thu, 2 May 2019 08:03:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E0E666882FF; Thu, 2 May 2019 08:03:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail6.iitk.ac.in (mail6.iitk.ac.in [202.3.77.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DEDB468017D for ; Thu, 2 May 2019 08:03:44 +0300 (EEST) Received: from webmail.iitk.ac.in (webmail.iitk.ac.in [172.31.1.213]) by mail6.iitk.ac.in (Postfix) with ESMTP id B1E5E60 for ; Thu, 2 May 2019 10:33:41 +0530 (IST) Received: from webmail.iitk.ac.in (localhost [127.0.0.1]) by webmail.iitk.ac.in (Postfix) with ESMTP id A4BC62924A for ; Thu, 2 May 2019 10:33:41 +0530 (IST) Received: from 103.117.232.6 by webmail.iitk.ac.in with HTTP; Thu, 2 May 2019 10:33:41 +0530 Message-ID: Date: Thu, 2 May 2019 10:33:41 +0530 From: shivgo@iitk.ac.in To: ffmpeg-devel@ffmpeg.org User-Agent: SquirrelMail/1.4.22-16.el7 MIME-Version: 1.0 X-Priority: 3 (Normal) Importance: Normal Subject: [FFmpeg-devel] [PATCH v7] lavf/flv: Add XV (Xunlei Video) Support. Fixes ticket #3720 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" lavf/flv: Add XV (Xunlei Video) Support. The patch fixes ticket #3720. It would just skip the first packet, which stores the decrypted data and moves on the next packet. Also, Thank you Moritz Barsnick for commenting this on the ticket. It really helped me. I would also add the documentation for this once the patch is applied. Thank you, Shivam Goyal From 954f6583ec79d0c5484787ba4782a12073558995 Mon Sep 17 00:00:00 2001 From: Shivam Goyal Date: Thu, 2 May 2019 10:16:49 +0530 Subject: [PATCH] lavf/flv: Add XV (Xunlei Video) Support. Fixes ticket #3720 --- Changelog | 1 + libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/flvdec.c | 74 ++++++++++++++++++++++++++++++++++++++++ libavformat/version.h | 2 +- 5 files changed, 78 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index a3fa0c14a2..a9dc982d08 100644 --- a/Changelog +++ b/Changelog @@ -26,6 +26,7 @@ version : - lscr decoder - lagfun filter - asoftclip filter +- XV (Xunlei Video) demuxer version 4.1: diff --git a/libavformat/Makefile b/libavformat/Makefile index 99be60d184..e090c051f1 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -561,6 +561,7 @@ OBJS-$(CONFIG_WV_MUXER) += wvenc.o wv.o apetag.o img2.o OBJS-$(CONFIG_XA_DEMUXER) += xa.o OBJS-$(CONFIG_XBIN_DEMUXER) += bintext.o sauce.o OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o +OBJS-$(CONFIG_XV_DEMUXER) += flvdec.o OBJS-$(CONFIG_XVAG_DEMUXER) += xvag.o OBJS-$(CONFIG_XWMA_DEMUXER) += xwma.o OBJS-$(CONFIG_YOP_DEMUXER) += yop.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index d316a0529a..b499186071 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -456,6 +456,7 @@ extern AVOutputFormat ff_wv_muxer; extern AVInputFormat ff_xa_demuxer; extern AVInputFormat ff_xbin_demuxer; extern AVInputFormat ff_xmv_demuxer; +extern AVInputFormat ff_xv_demuxer; extern AVInputFormat ff_xvag_demuxer; extern AVInputFormat ff_xwma_demuxer; extern AVInputFormat ff_yop_demuxer; diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index b531a39adc..bdb79400da 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -127,6 +127,19 @@ static int kux_probe(const AVProbeData *p) return 0; } +static int xv_probe(const AVProbeData *p) +{ + const uint8_t *d = p->buf; + + if (d[0] == 'X' && + d[1] == 'L' && + d[2] == 'V' && + d[3] == 'F') { + return AVPROBE_SCORE_EXTENSION + 1; + } + return 0; +} + static void add_keyframes_index(AVFormatContext *s) { FLVContext *flv = s->priv_data; @@ -783,6 +796,46 @@ static int flv_read_header(AVFormatContext *s) return 0; } +static int xv_read_header(AVFormatContext *s) +{ + int flags; + FLVContext *xv = s->priv_data; + AVIOContext *ic = s->pb; + int offset; + int enc_tag_size; + int rot; + + //Find the rot value for rotating the bytes + avio_skip(ic, 0x200000); + rot = 0x46 - avio_r8(ic); + + avio_skip(ic, 3); + + flags = (avio_r8(ic) + rot) & 0xff; + + xv->missing_streams = flags & (FLV_HEADER_FLAG_HASVIDEO | FLV_HEADER_FLAG_HASAUDIO); + + s->ctx_flags |= AVFMTCTX_NOHEADER; + + offset = ((avio_r8(ic) + rot & 0xff) << 24 | + (avio_r8(ic) + rot & 0xff) << 16 | + (avio_r8(ic) + rot & 0xff) << 8 | + (avio_r8(ic) + rot & 0xff)) + 0x200000; + avio_seek(ic, offset + 5, SEEK_SET); + + enc_tag_size = ((avio_r8(ic) + rot & 0xff) << 16 | + (avio_r8(ic) + rot & 0xff) << 8 | + (avio_r8(ic) + rot & 0xff)); + //Skip encrypted data + avio_skip(ic, enc_tag_size + 11); + + s->start_time = 0; + xv->sum_flv_tag_size = 0; + xv->last_keyframe_stream_index = -1; + + return 0; +} + static int flv_read_close(AVFormatContext *s) { int i; @@ -1424,3 +1477,24 @@ AVInputFormat ff_kux_demuxer = { .extensions = "kux", .priv_class = &kux_class, }; + +static const AVClass xv_class = { + .class_name = "xvdec", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVInputFormat ff_xv_demuxer = { + .name = "xv", + .long_name = NULL_IF_CONFIG_SMALL("Xunlei(Thunder) Video File"), + .priv_data_size = sizeof(FLVContext), + .read_probe = xv_probe, + .read_header = xv_read_header, + .read_packet = flv_read_packet, + .read_seek = flv_read_seek, + .read_close = flv_read_close, + .extensions = "xv", + .priv_class = &xv_class, + .flags = AVFMT_TS_DISCONT +}; diff --git a/libavformat/version.h b/libavformat/version.h index 150a72e27d..17c841ae83 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 -#define LIBAVFORMAT_VERSION_MINOR 27 +#define LIBAVFORMAT_VERSION_MINOR 28 #define LIBAVFORMAT_VERSION_MICRO 103 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ -- 2.21.0