From patchwork Wed Aug 19 06:25:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hwren X-Patchwork-Id: 21730 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 8F49E449418 for ; Wed, 19 Aug 2020 09:33:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 72B67688379; Wed, 19 Aug 2020 09:33:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from m15111.mail.126.com (m15111.mail.126.com [220.181.15.111]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D3FF6689247 for ; Wed, 19 Aug 2020 09:32:56 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=qlxih NxGsz06jrlO2JDxhezvAoqvAKpQ6S10ZVzeTQQ=; b=fngfwSFlzilyrpruS0hrG gnnRV+Z0W9Cr1Qi3NoeDUIvoHEVTkO3vq5oHhXmsWrV8BHCGxvUTEfC8vbysB1Nl A5GZ1zK8YvPDmyOQc+VX8ZoNxhAqABI7KQM73kGABZah7VtMOn+bXosL4nneGNbw AalambZK+q0Yu2bwpqN9xE= Received: from localhost.localdomain (unknown [111.34.131.254]) by smtp1 (Coremail) with SMTP id C8mowABXm0WNxzxfC6TjIg--.43533S3; Wed, 19 Aug 2020 14:32:47 +0800 (CST) From: hwrenx@126.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 Aug 2020 14:25:52 +0800 Message-Id: <20200819062556.1396-2-hwrenx@126.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20200819062556.1396-1-hwrenx@126.com> References: <20200818164506.2006-1-hwrenx@126.com> <20200819062556.1396-1-hwrenx@126.com> MIME-Version: 1.0 X-CM-TRANSID: C8mowABXm0WNxzxfC6TjIg--.43533S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Xr1xZw4Uuw15Gr1xCFW7Arb_yoW8Jr4Upr sIqr13KFWaqF9xA397Jr1UCF1jkFy3XF97W3sFqw12kr4Sq34UJryavrZrW3WxZrZ09F9r uwnxGw1kXw4UJaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jb189UUUUU= X-Originating-IP: [111.34.131.254] X-CM-SenderInfo: pkzuv0b06rjloofrz/1tbiTw+F6VpEBUruuQABsr Subject: [FFmpeg-devel] [PATCH v5 1/5] lavc: add AVS3 codec id and desc 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 Cc: hwren , hbj Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: hwren Signed-off-by: hbj Signed-off-by: hwren --- libavcodec/codec_desc.c | 7 +++++++ libavcodec/codec_id.h | 1 + 2 files changed, 8 insertions(+) diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index 0ae6aee63b..61473178fc 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -1412,6 +1412,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("PGX (JPEG2000 Test Format)"), .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, }, + { + .id = AV_CODEC_ID_AVS3, + .type = AVMEDIA_TYPE_VIDEO, + .name = "avs3", + .long_name = NULL_IF_CONFIG_SMALL("AVS3-P2/IEEE1857.10"), + .props = AV_CODEC_PROP_LOSSY, + }, { .id = AV_CODEC_ID_Y41P, .type = AVMEDIA_TYPE_VIDEO, diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h index 896ecb0ce0..47aa0787b6 100644 --- a/libavcodec/codec_id.h +++ b/libavcodec/codec_id.h @@ -242,6 +242,7 @@ enum AVCodecID { AV_CODEC_ID_RSCC, AV_CODEC_ID_AVS2, AV_CODEC_ID_PGX, + AV_CODEC_ID_AVS3, AV_CODEC_ID_Y41P = 0x8000, AV_CODEC_ID_AVRP, From patchwork Wed Aug 19 06:25:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hwren X-Patchwork-Id: 21733 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 C87E5449418 for ; Wed, 19 Aug 2020 09:33:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B183668974F; Wed, 19 Aug 2020 09:33:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from m15111.mail.126.com (m15111.mail.126.com [220.181.15.111]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 062DF689722 for ; Wed, 19 Aug 2020 09:32:56 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=sP4O0 g+KKGM9Cw2X7SBLuxQPT9H+hcciGXJzO/wRQ/s=; b=RWPfzkDQrsxOISVYgNkh7 3mij0VobK7b5gZN5EhrqTxIbmT/uu/mRyYCOAZl4Ke6rx53+0bLSDG0bddwL2amp sTNx6Ownu4ETTsiam771x7PaJWNpoOlzZWXUg+TJ6oOI71CBPIxtFr5QzKE4eTiU vJVo2mH5Ff05PNWHupMsQg= Received: from localhost.localdomain (unknown [111.34.131.254]) by smtp1 (Coremail) with SMTP id C8mowABXm0WNxzxfC6TjIg--.43533S4; Wed, 19 Aug 2020 14:32:48 +0800 (CST) From: hwrenx@126.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 Aug 2020 14:25:53 +0800 Message-Id: <20200819062556.1396-3-hwrenx@126.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20200819062556.1396-1-hwrenx@126.com> References: <20200818164506.2006-1-hwrenx@126.com> <20200819062556.1396-1-hwrenx@126.com> MIME-Version: 1.0 X-CM-TRANSID: C8mowABXm0WNxzxfC6TjIg--.43533S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxuw1DJF1rKrWfCw13Jw4kXrb_yoW7ZFW7pF 47Cwn8GF1kJw4S9r93GF1jyF13G393XF1jga4Iqa12qw1Yvrs5Jrn7KFy8Ga1fXrn8uayY gr4q9w15Cr1kJw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Ut739UUUUU= X-Originating-IP: [111.34.131.254] X-CM-SenderInfo: pkzuv0b06rjloofrz/1tbiZhCF6VpD-GYElAAAsJ Subject: [FFmpeg-devel] [PATCH v5 2/5] lavc/avs3: add AVS3 related definitions 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 Cc: hwren Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: hwren Signed-off-by: hwren --- libavcodec/Makefile | 2 + libavcodec/avs3.c | 95 +++++++++++++++++++++++++++++++++++++++++++++ libavcodec/avs3.h | 52 +++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 libavcodec/avs3.c create mode 100644 libavcodec/avs3.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3431ba2dca..e1e0c4629d 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -6,6 +6,7 @@ HEADERS = ac3_parser.h \ avcodec.h \ avdct.h \ avfft.h \ + avs3.h \ bsf.h \ codec.h \ codec_desc.h \ @@ -32,6 +33,7 @@ OBJS = ac3_parser.o \ avdct.o \ avpacket.o \ avpicture.o \ + avs3.o \ bitstream.o \ bitstream_filter.o \ bitstream_filters.o \ diff --git a/libavcodec/avs3.c b/libavcodec/avs3.c new file mode 100644 index 0000000000..8587e36def --- /dev/null +++ b/libavcodec/avs3.c @@ -0,0 +1,95 @@ +/* + * AVS3 related definition + * + * Copyright (C) 2020 Huiwen Ren, + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avs3.h" + +const AVRational ff_avs3_frame_rate_tab[16] = { + { 0 , 0 }, // forbid + { 24000, 1001}, + { 24 , 1 }, + { 25 , 1 }, + { 30000, 1001}, + { 30 , 1 }, + { 50 , 1 }, + { 60000, 1001}, + { 60 , 1 }, + { 100 , 1 }, + { 120 , 1 }, + { 200 , 1 }, + { 240 , 1 }, + { 300 , 1 }, + { 0 , 0 }, // reserved + { 0 , 0 } // reserved +}; + +const int ff_avs3_color_primaries_tab[10] = { + AVCOL_PRI_RESERVED0 , // 0 + AVCOL_PRI_BT709 , // 1 + AVCOL_PRI_UNSPECIFIED , // 2 + AVCOL_PRI_RESERVED , // 3 + AVCOL_PRI_BT470M , // 4 + AVCOL_PRI_BT470BG , // 5 + AVCOL_PRI_SMPTE170M , // 6 + AVCOL_PRI_SMPTE240M , // 7 + AVCOL_PRI_FILM , // 8 + AVCOL_PRI_BT2020 // 9 +}; + +const int ff_avs3_color_transfer_tab[15] = { + AVCOL_TRC_RESERVED0 , // 0 + AVCOL_TRC_BT709 , // 1 + AVCOL_TRC_UNSPECIFIED , // 2 + AVCOL_TRC_RESERVED , // 3 + AVCOL_TRC_GAMMA22 , // 4 + AVCOL_TRC_GAMMA28 , // 5 + AVCOL_TRC_SMPTE170M , // 6 + AVCOL_TRC_SMPTE240M , // 7 + AVCOL_TRC_LINEAR , // 8 + AVCOL_TRC_LOG , // 9 + AVCOL_TRC_LOG_SQRT , // 10 + AVCOL_TRC_BT2020_12 , // 11 + AVCOL_TRC_SMPTE2084 , // 12 + AVCOL_TRC_UNSPECIFIED , // 13 + AVCOL_TRC_ARIB_STD_B67 // 14 +}; + +const int ff_avs3_color_matrix_tab[12] = { + AVCOL_SPC_RESERVED , // 0 + AVCOL_SPC_BT709 , // 1 + AVCOL_SPC_UNSPECIFIED , // 2 + AVCOL_SPC_RESERVED , // 3 + AVCOL_SPC_FCC , // 4 + AVCOL_SPC_BT470BG , // 5 + AVCOL_SPC_SMPTE170M , // 6 + AVCOL_SPC_SMPTE240M , // 7 + AVCOL_SPC_BT2020_NCL , // 8 + AVCOL_SPC_BT2020_CL , // 9 + AVCOL_SPC_UNSPECIFIED , // 10 + AVCOL_SPC_UNSPECIFIED // 11 +}; + +const enum AVPictureType ff_avs3_image_type[4] = { + AV_PICTURE_TYPE_NONE, + AV_PICTURE_TYPE_I, + AV_PICTURE_TYPE_P, + AV_PICTURE_TYPE_B +}; \ No newline at end of file diff --git a/libavcodec/avs3.h b/libavcodec/avs3.h new file mode 100644 index 0000000000..9f79adb7bf --- /dev/null +++ b/libavcodec/avs3.h @@ -0,0 +1,52 @@ +/* + * AVS3 related definition + * + * Copyright (C) 2020 Huiwen Ren, + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_AVS3_H +#define AVCODEC_AVS3_H + +#define AVS3_NAL_START_CODE 0x010000 +#define AVS3_SEQ_START_CODE 0xB0 +#define AVS3_SEQ_END_CODE 0xB1 +#define AVS3_USER_DATA_START_CODE 0xB2 +#define AVS3_INTRA_PIC_START_CODE 0xB3 +#define AVS3_UNDEF_START_CODE 0xB4 +#define AVS3_EXTENSION_START_CODE 0xB5 +#define AVS3_INTER_PIC_START_CODE 0xB6 +#define AVS3_VIDEO_EDIT_CODE 0xB7 +#define AVS3_FIRST_SLICE_START_CODE 0x00 +#define AVS3_PROFILE_BASELINE_MAIN 0x20 +#define AVS3_PROFILE_BASELINE_MAIN10 0x22 + +#define ISPIC(x) ((x) == AVS3_INTRA_PIC_START_CODE || (x) == AVS3_INTER_PIC_START_CODE) +#define ISUNIT(x) ((x) == AVS3_SEQ_START_CODE || ISPIC(x)) + +#include "libavutil/avutil.h" +#include "libavutil/pixfmt.h" +#include "libavutil/rational.h" + +extern const AVRational ff_avs3_frame_rate_tab[16]; +extern const int ff_avs3_color_primaries_tab[10]; +extern const int ff_avs3_color_transfer_tab[15]; +extern const int ff_avs3_color_matrix_tab[12]; +extern const enum AVPictureType ff_avs3_image_type[4]; + +#endif /* AVCODEC_AVS3_H */ From patchwork Wed Aug 19 06:25:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hwren X-Patchwork-Id: 21731 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 A8E86449418 for ; Wed, 19 Aug 2020 09:33:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 92F6E6898AE; Wed, 19 Aug 2020 09:33:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from m15111.mail.126.com (m15111.mail.126.com [220.181.15.111]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AE37687FBB for ; Wed, 19 Aug 2020 09:32:54 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=6RIRS bsmUrysQ3dkhE4iZKChvxK638vb7c0LInQdoIg=; b=oBaW0r2OUgYaMsxeoAgXf vIttWmNL306h1svrTIfjdtg1xzll7w6nBoF7FBKq7Few+qiPTKTjbiw+crVZ2j00 q4lvHr4Lj6CbiQdfCokXPY/6FDzvAOYgUg0h0cy4EznB/GAOHu7gsCXtTicDqxLi 5WjfsfCvPbSulr4D4BBtK0= Received: from localhost.localdomain (unknown [111.34.131.254]) by smtp1 (Coremail) with SMTP id C8mowABXm0WNxzxfC6TjIg--.43533S5; Wed, 19 Aug 2020 14:32:48 +0800 (CST) From: hwrenx@126.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 Aug 2020 14:25:54 +0800 Message-Id: <20200819062556.1396-4-hwrenx@126.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20200819062556.1396-1-hwrenx@126.com> References: <20200818164506.2006-1-hwrenx@126.com> <20200819062556.1396-1-hwrenx@126.com> MIME-Version: 1.0 X-CM-TRANSID: C8mowABXm0WNxzxfC6TjIg--.43533S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxuw1DJrWDWFy5Jrykuw1UAwb_yoWxGF15pF sxCr4rJr4xta1SkrZ7tr13G3W5WF9YqFy8tFWfur1rtws3KryDJ3Z7GFy2k3ySgr9avFy5 urs8XF1jkw4qq3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U_3ktUUUUU= X-Originating-IP: [111.34.131.254] X-CM-SenderInfo: pkzuv0b06rjloofrz/1tbiDxCF6VpEBSsUVQAAsC Subject: [FFmpeg-devel] [PATCH v5 3/5] lavc/avs3_parser: add avs3 parser 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 Cc: hwren , hbj Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: hwren Signed-off-by: hbj Signed-off-by: hwren --- libavcodec/Makefile | 1 + libavcodec/avs3_parser.c | 180 +++++++++++++++++++++++++++++++++++++++ libavcodec/parsers.c | 1 + 3 files changed, 182 insertions(+) create mode 100644 libavcodec/avs3_parser.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index e1e0c4629d..4c596515ee 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1061,6 +1061,7 @@ OBJS-$(CONFIG_AC3_PARSER) += ac3tab.o aac_ac3_parser.o OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o adx.o OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o OBJS-$(CONFIG_AVS2_PARSER) += avs2_parser.o +OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o OBJS-$(CONFIG_CAVSVIDEO_PARSER) += cavs_parser.o OBJS-$(CONFIG_COOK_PARSER) += cook_parser.o diff --git a/libavcodec/avs3_parser.c b/libavcodec/avs3_parser.c new file mode 100644 index 0000000000..36ca19797d --- /dev/null +++ b/libavcodec/avs3_parser.c @@ -0,0 +1,180 @@ +/* + * AVS3-P2/IEEE1857.10 video parser. + * Copyright (c) 2020 Zhenyu Wang + * Bingjie Han + * Huiwen Ren + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avs3.h" +#include "get_bits.h" +#include "parser.h" + +static int avs3_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) +{ + int pic_found = pc->frame_start_found; + uint32_t state = pc->state; + int cur = 0; + + if (!pic_found) { + for (; cur < buf_size; ++cur) { + state = (state << 8) | buf[cur]; + if (ISPIC(buf[cur])){ + ++cur; + pic_found = 1; + break; + } + } + } + + if (pic_found) { + if (!buf_size) + return END_NOT_FOUND; + for (; cur < buf_size; ++cur) { + state = (state << 8) | buf[cur]; + if ((state & 0xFFFFFF00) == 0x100 && ISUNIT(state & 0xFF)) { + pc->frame_start_found = 0; + pc->state = -1; + return cur - 3; + } + } + } + + pc->frame_start_found = pic_found; + pc->state = state; + + return END_NOT_FOUND; +} + +static void parse_avs3_nal_units(AVCodecParserContext *s, const uint8_t *buf, + int buf_size, AVCodecContext *avctx) +{ + if (buf_size < 5) { + return; + } + + if (buf[0] == 0x0 && buf[1] == 0x0 && buf[2] == 0x1) { + if (buf[3] == AVS3_SEQ_START_CODE) { + GetBitContext gb; + int profile, ratecode; + + init_get_bits(&gb, buf + 4, buf_size - 4); + + s->key_frame = 1; + s->pict_type = AV_PICTURE_TYPE_I; + + profile = get_bits(&gb, 8); + // Skip bits: level(8) + // progressive(1) + // field(1) + // library(2) + // resv(1) + // width(14) + // resv(1) + // height(14) + // chroma(2) + // sampe_precision(3) + skip_bits(&gb, 47); + + if (profile == AVS3_PROFILE_BASELINE_MAIN10) { + int sample_precision = get_bits(&gb, 3); + if (sample_precision == 1) { + avctx->pix_fmt = AV_PIX_FMT_YUV420P; + } else if (sample_precision == 2) { + avctx->pix_fmt = AV_PIX_FMT_YUV420P10LE; + } else { + avctx->pix_fmt = AV_PIX_FMT_NONE; + } + } + + // Skip bits: resv(1) + // aspect(4) + skip_bits(&gb, 5); + + ratecode = get_bits(&gb, 4); + + // Skip bits: resv(1) + // bitrate_low(18) + // resv(1) + // bitrate_high(12) + // low_delay + skip_bits(&gb, 32); + + avctx->has_b_frames = !get_bits(&gb, 1); + + avctx->framerate.num = avctx->time_base.den = ff_avs3_frame_rate_tab[ratecode].num; + avctx->framerate.den = avctx->time_base.num = ff_avs3_frame_rate_tab[ratecode].den; + + s->width = s->coded_width = avctx->width; + s->height = s->coded_height = avctx->height; + + av_log(avctx, AV_LOG_DEBUG, + "avs3 parse seq hdr: profile %d; coded wxh: %dx%d; " + "frame_rate_code %d\n", profile, avctx->width, avctx->height, ratecode); + + } else if (buf[3] == AVS3_INTRA_PIC_START_CODE) { + s->key_frame = 1; + s->pict_type = AV_PICTURE_TYPE_I; + } else if (buf[3] == AVS3_INTER_PIC_START_CODE){ + s->key_frame = 0; + if (buf_size > 9) { + int pic_code_type = buf[8] & 0x3; + if (pic_code_type == 1 || pic_code_type == 3) { + s->pict_type = AV_PICTURE_TYPE_P; + } else { + s->pict_type = AV_PICTURE_TYPE_B; + } + } + } + } +} + + +static int avs3_parse(AVCodecParserContext *s, AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { + next = buf_size; + } else { + next = avs3_find_frame_end(pc, buf, buf_size); + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } + + parse_avs3_nal_units(s, buf, buf_size, avctx); + + *poutbuf = buf; + *poutbuf_size = buf_size; + + return next; +} + +AVCodecParser ff_avs3_parser = { + .codec_ids = { AV_CODEC_ID_AVS3 }, + .priv_data_size = sizeof(ParseContext), + .parser_parse = avs3_parse, + .parser_close = ff_parse_close, + .split = ff_mpeg4video_split, +}; diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index 7d75cea830..aab1d5e3e5 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -28,6 +28,7 @@ extern AVCodecParser ff_ac3_parser; extern AVCodecParser ff_adx_parser; extern AVCodecParser ff_av1_parser; extern AVCodecParser ff_avs2_parser; +extern AVCodecParser ff_avs3_parser; extern AVCodecParser ff_bmp_parser; extern AVCodecParser ff_cavsvideo_parser; extern AVCodecParser ff_cook_parser; From patchwork Wed Aug 19 06:25:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hwren X-Patchwork-Id: 21732 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 B322E449418 for ; Wed, 19 Aug 2020 09:33:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9F4726899A1; Wed, 19 Aug 2020 09:33:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from m15111.mail.126.com (m15111.mail.126.com [220.181.15.111]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6C52E6880F2 for ; Wed, 19 Aug 2020 09:32:57 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=JZLvs 2h+S7iQmwhhPg/3+w7J9l7Z3YBU04OOsP5Ig1o=; b=WK8IQUUNw1wyY01GpxBF3 yZdLcwgd+Z5z5hGQn9WM33eplJPe71d7S/lPtq78bctQqgv96R0wgpM1lksvL31r AYve2yGScGB52el/bbRhVumNyqNuxdJm5fxRyFkHVDJU5S5TZrinExgG4qSaNQjh KWfyf7KAJCxcDb+QD3z2yE= Received: from localhost.localdomain (unknown [111.34.131.254]) by smtp1 (Coremail) with SMTP id C8mowABXm0WNxzxfC6TjIg--.43533S6; Wed, 19 Aug 2020 14:32:49 +0800 (CST) From: hwrenx@126.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 Aug 2020 14:25:55 +0800 Message-Id: <20200819062556.1396-5-hwrenx@126.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20200819062556.1396-1-hwrenx@126.com> References: <20200818164506.2006-1-hwrenx@126.com> <20200819062556.1396-1-hwrenx@126.com> MIME-Version: 1.0 X-CM-TRANSID: C8mowABXm0WNxzxfC6TjIg--.43533S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxJw48XFyDCF4fJryDAw1xGrg_yoWrZryrp3 Z3uw15Jr1kJa12yr97JFW5Jws5Can5KFyxXa47ur10kFnxWry8Xr9FkFW2yrs7W3srGF48 XF4Yy3WYkw15JaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UEfO7UUUUU= X-Originating-IP: [111.34.131.254] X-CM-SenderInfo: pkzuv0b06rjloofrz/1tbiTxGF6VpEBUruwwAAsO Subject: [FFmpeg-devel] [PATCH v5 4/5] lavf/avs3dec: add raw avs3 demuxer 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 Cc: hwren , hbj Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: hwren Signed-off-by: hbj Signed-off-by: hwren --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/avs3dec.c | 68 ++++++++++++++++++++++++++++++++++++++++ libavformat/version.h | 2 +- 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 libavformat/avs3dec.c diff --git a/libavformat/Makefile b/libavformat/Makefile index cbb33fe37c..8ddab3aee5 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -122,6 +122,7 @@ OBJS-$(CONFIG_AVR_DEMUXER) += avr.o pcm.o OBJS-$(CONFIG_AVS_DEMUXER) += avs.o voc_packet.o vocdec.o voc.o OBJS-$(CONFIG_AVS2_DEMUXER) += davs2.o rawdec.o OBJS-$(CONFIG_AVS2_MUXER) += rawenc.o +OBJS-$(CONFIG_AVS3_DEMUXER) += avs3dec.o rawdec.o OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o OBJS-$(CONFIG_BINK_DEMUXER) += bink.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 0aa9dd7198..7f41c12d7c 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -84,6 +84,7 @@ extern AVInputFormat ff_avr_demuxer; extern AVInputFormat ff_avs_demuxer; extern AVInputFormat ff_avs2_demuxer; extern AVOutputFormat ff_avs2_muxer; +extern AVInputFormat ff_avs3_demuxer; extern AVInputFormat ff_bethsoftvid_demuxer; extern AVInputFormat ff_bfi_demuxer; extern AVInputFormat ff_bintext_demuxer; diff --git a/libavformat/avs3dec.c b/libavformat/avs3dec.c new file mode 100644 index 0000000000..af14550b55 --- /dev/null +++ b/libavformat/avs3dec.c @@ -0,0 +1,68 @@ +/* + * RAW AVS3-P2/IEEE1857.10 video demuxer + * Copyright (c) 2020 Zhenyu Wang + * Bingjie Han + * Huiwen Ren + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavcodec/avs3.h" +#include "libavcodec/internal.h" +#include "avformat.h" +#include "rawdec.h" + +static int avs3video_probe(const AVProbeData *p) +{ + const uint8_t *ptr = p->buf, *end = p->buf + p->buf_size; + uint32_t code = -1; + uint8_t state = 0; + int pic = 0, seq = 0, slice_pos = 0; + int ret = 0; + + while (ptr < end) { + ptr = avpriv_find_start_code(ptr, end, &code); + state = code & 0xFF; + if ((code & 0xFFFFFF00) == 0x100) { + if (state < AVS3_SEQ_START_CODE) { + if (code < slice_pos) + return 0; + slice_pos = code; + } else { + slice_pos = 0; + } + if (state == AVS3_SEQ_START_CODE) { + seq++; + if (*ptr != AVS3_PROFILE_BASELINE_MAIN && *ptr != AVS3_PROFILE_BASELINE_MAIN10) + return 0; + } else if (ISPIC(state)) { + pic++; + } else if ((state == AVS3_UNDEF_START_CODE) || + (state > AVS3_VIDEO_EDIT_CODE)) { + return 0; + } + } + } + + if (seq && pic && av_match_ext(p->filename, "avs3")) { + ret = AVPROBE_SCORE_MAX; + } + + return ret; +} + +FF_DEF_RAWVIDEO_DEMUXER(avs3, "raw AVS3-P2/IEEE1857.10", avs3video_probe, "avs3", AV_CODEC_ID_AVS3) \ No newline at end of file diff --git a/libavformat/version.h b/libavformat/version.h index aa309ecc77..146db09d1b 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 51 +#define LIBAVFORMAT_VERSION_MINOR 52 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \