From patchwork Tue Nov 16 12:49:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 31442 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp7336377iob; Tue, 16 Nov 2021 04:49:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrccJUQuyQThgjtPYPViM5sLdj6uVbmR2jB+XhnX+9LbCq0kdIcwylYISHMRowWKH+lSBg X-Received: by 2002:a17:907:168f:: with SMTP id hc15mr9563645ejc.115.1637066990016; Tue, 16 Nov 2021 04:49:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637066990; cv=none; d=google.com; s=arc-20160816; b=h5dWQ/+iZbNIgqULwMYFOUuSeHor+KcPa9s2/baAtIB6QPKlubFInCW4NG8vWpolhr YsiwRoqNYxa9fjRJBB2dldx9L+udnGWIU8LMs/AtEgwU2B72donGGpnNMfawz2OwYSVi lkaGc5XYHQ6sUfeHde/5oIlDC6wSoSZJIlSAXl9pv6DIkWNxsIXnl0Xj6piLenarPitd tl/slt4o+2Hfhy9H9+p0GcrU+t2aeBlfSaP5Z+WZHLGYL3/CexGEF4zyUE29NShJjVqM hW3YXtVUYJsPxajVIZdC63zNADoljVqZwP8p7CqaRy7MKSI6YfOY6rmdFl9BhDbp4+ya UjaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=J0vZPqoXd94z9pizRyDGaHGpgLid2EkSPg2U6AzWXmk=; b=iDiW2Jme2NWmy1P57gDwvpewu/FwMsZ5dJSLTPKf9oh+p+XnEjZTQwarVyMS6VYpM/ UUPzvf6GCcRpjSMbM4tOpf9+TzEQE+WA0EFnJWUOg+uMOVCncRxMrtDNNPdfDYFJGYkU MYrNuapYFf1/DaXjSLRoz4ih8wif2g9NKr6JSF7Cf7umkaVLiV+n2zV8N7Q8l4mhzxjb +0U56ax1n6KxUXX6GnAhcITX18CeoPAwYDcJURleXjQkpV++vstXeS06NW5tZqvyUWnz qRnv8zrxbRCbQ6iPEVzrp58gZ0Nlsf9ZXuuMdtllu9W8uAtU+R5xYuo37X4hEPd3PCeh OY8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=e5UVv4MW; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f10si9585420edf.107.2021.11.16.04.49.48; Tue, 16 Nov 2021 04:49:50 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=e5UVv4MW; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 97D6F68A778; Tue, 16 Nov 2021 14:49:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 29E07687FCE for ; Tue, 16 Nov 2021 14:49:37 +0200 (EET) Received: by mail-pg1-f171.google.com with SMTP id q12so5788359pgh.5 for ; Tue, 16 Nov 2021 04:49:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Gb1KUbzmaX62UxXbXhV0Ahd/KK1/drvkgCnVENhCJPg=; b=e5UVv4MWTMFz5XfQkYO7tKMuUbxmavJIEMTSFY/pZngI9BsRNXwHoEHY+q29NJPp5x E8Z/mvJMIwcTovuKWnCG/vzv3//9L7uBc+OPmAa5CmRJC9LQRqxFE9yvPbUHlz1g/eJ1 n7EgVDEno95E2IZz2Et9IMWGfVxX4EPune9qVHIfxWEW2GIadiJ+3ba1a5mDIZKcCArM gcQ0c5IY3XkBROZSuF8CnAuhOH9z1e9/b1kp5l/NsAkFbdoRvJmeUFnQNiOAepsdWPRL 9srBqNdaVWDGh4bnVM8tZoERn/CrRktCpAAFj2Y8+jrOooNXU45uCDYtNS/xDMZ/Xg19 n80A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Gb1KUbzmaX62UxXbXhV0Ahd/KK1/drvkgCnVENhCJPg=; b=L0YQI662dNWSQOzBgSFQXOZtTw8dzC1qad5kyEU2KlyHkGprdOjG7e/Onsz/64lXWk 2KcbV7j3//TU2Unds+uP0Xed2yCfWx1Fv1c9EL2vgLlTWfKfnsrIM64WCew6hqHQTQLR Dh37F/eAYB6t4tzfKerFRxZMHwi8ur1jvOipuhGnYkLhVftTpbYKWUM0cpRMokcyssO8 u+wBXrd6KjSLLMf1u5aN+101pITgvNd5XBs1Smru/mj7DBffhKanAgfZDjpsiq/juViN YdqPk27TDwHKAeex2XAHqREdEBFJHse8MESjjTAg478NZICKelOGotBvGFFa/FxqK03l k0Eg== X-Gm-Message-State: AOAM531ZrcbditvuDzy8Qao055PY7X3YVPD45GJHpk4NfnDC3H4wnDwQ TjHraFpMsYKz8A3u8b1LG4PFinqXVI4= X-Received: by 2002:a62:5a02:0:b0:4a2:a6ee:4d8e with SMTP id o2-20020a625a02000000b004a2a6ee4d8emr20255700pfb.47.1637066974264; Tue, 16 Nov 2021 04:49:34 -0800 (PST) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id p15sm2229506pjh.1.2021.11.16.04.49.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Nov 2021 04:49:33 -0800 (PST) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Nov 2021 20:49:28 +0800 Message-Id: <1637066968-4697-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1636712536-13114-5-git-send-email-lance.lmwang@gmail.com> References: <1636712536-13114-5-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v2 05/12] avformat/rtpenc: adds partial support for the RFC 4175 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Q6BqRXBgp9p3 From: Limin Wang Signed-off-by: Limin Wang --- Changelog | 1 + libavformat/Makefile | 1 + libavformat/rtpenc.c | 4 ++ libavformat/rtpenc.h | 1 + libavformat/rtpenc_rfc4175.c | 116 +++++++++++++++++++++++++++++++++++ libavformat/sdp.c | 25 ++++++++ libavformat/version.h | 2 +- 7 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 libavformat/rtpenc_rfc4175.c diff --git a/Changelog b/Changelog index 765ec82915..4fecc5b9d0 100644 --- a/Changelog +++ b/Changelog @@ -30,6 +30,7 @@ version : - xcorrelate video filter - varblur video filter - huesaturation video filter +- RTP packetizer for uncompressed video (RFC rfc4175) version 4.4: diff --git a/libavformat/Makefile b/libavformat/Makefile index 3d6c8ef8f5..a19d2e0c88 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -482,6 +482,7 @@ OBJS-$(CONFIG_RTP_MUXER) += rtp.o \ rtpenc_jpeg.o \ rtpenc_mpv.o \ rtpenc.o \ + rtpenc_rfc4175.o \ rtpenc_vc2hq.o \ rtpenc_vp8.o \ rtpenc_vp9.o \ diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c index 2a1c176066..4f115cc77e 100644 --- a/libavformat/rtpenc.c +++ b/libavformat/rtpenc.c @@ -84,6 +84,7 @@ static int is_supported(enum AVCodecID id) case AV_CODEC_ID_MJPEG: case AV_CODEC_ID_SPEEX: case AV_CODEC_ID_OPUS: + case AV_CODEC_ID_RAWVIDEO: return 1; default: return 0; @@ -619,6 +620,9 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) case AV_CODEC_ID_MJPEG: ff_rtp_send_jpeg(s1, pkt->data, size); break; + case AV_CODEC_ID_RAWVIDEO: + ff_rtp_send_raw_rfc4175 (s1, pkt->data, size); + break; case AV_CODEC_ID_OPUS: if (size > s->max_payload_size) { av_log(s1, AV_LOG_ERROR, diff --git a/libavformat/rtpenc.h b/libavformat/rtpenc.h index 62dc9ab10a..70ea85bf3f 100644 --- a/libavformat/rtpenc.h +++ b/libavformat/rtpenc.h @@ -95,6 +95,7 @@ void ff_rtp_send_vc2hq(AVFormatContext *s1, const uint8_t *buf, int size, int in void ff_rtp_send_vp8(AVFormatContext *s1, const uint8_t *buff, int size); void ff_rtp_send_vp9(AVFormatContext *s1, const uint8_t *buff, int size); void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buff, int size); +void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size); const uint8_t *ff_h263_find_resync_marker_reverse(const uint8_t *av_restrict start, const uint8_t *av_restrict end); diff --git a/libavformat/rtpenc_rfc4175.c b/libavformat/rtpenc_rfc4175.c new file mode 100644 index 0000000000..6fa34b64cb --- /dev/null +++ b/libavformat/rtpenc_rfc4175.c @@ -0,0 +1,116 @@ +/* + * RTP Packetization of RAW video (RFC4175) + * Copyright (c) 2021 Limin Wang + * + * 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 "avformat.h" +#include "rtpenc.h" + +void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size) +{ + RTPMuxContext *s = s1->priv_data; + int width = s1->streams[0]->codecpar->width; + int height = s1->streams[0]->codecpar->height; + int xinc, yinc, pgroup; + int field = 0; + int i = 0; + int offset = 0; + + s->timestamp = s->cur_timestamp; + switch (s1->streams[0]->codecpar->format) { + case AV_PIX_FMT_UYVY422: + xinc = yinc = 2; + pgroup = 4; + break; + case AV_PIX_FMT_YUV420P: + xinc = yinc = 4; + pgroup = 6; + break; + default: + return; + } + + while (i < height) { + int left = s->max_payload_size; + uint8_t *dest = s->buf; + uint8_t *headers; + const int head_size = 6; + int next_line; + int length, cont, pixels; + + /* Extended Sequence Number */ + *dest++ = 0; + *dest++ = 0; + left -= 2; + + headers = dest; + do { + pixels = width * xinc - offset; + length = (pixels * pgroup) / xinc; + + left -= head_size; + if (left >= length) { + next_line = 1; + } else { + pixels = (left / pgroup) * xinc; + length = (pixels * pgroup) / xinc; + next_line = 0; + } + left -= length; + + /* Length */ + *dest++ = (length >> 8) & 0xff; + *dest++ = length & 0xff; + + /* Line No */ + *dest++ = ((i >> 8) & 0x7f) | ((field << 7) & 0x80); + *dest++ = i & 0xff; + if (next_line) i += yinc; + + cont = (left > (head_size + pgroup) && i < height) ? 0x80 : 0x00; + /* Offset and Continuation marker */ + *dest++ = ((offset >> 8) & 0x7f) | cont; + *dest++ = offset & 0xff; + + if (next_line) + offset = 0; + else + offset += pixels; + } while (cont); + + do { + int l_line; + int l_off; + int copy_offset; + + length = (headers[0] << 8) | headers[1]; + l_line = ((headers[2] & 0x7f) << 8) | headers[3]; + l_off = ((headers[4] & 0x7f) << 8) | headers[5]; + cont = headers[4] & 0x80; + headers += head_size; + + copy_offset = (l_line * width + l_off) * pgroup / xinc; + if (copy_offset + length > size) + break; + memcpy (dest, buf + copy_offset, length); + dest += length; + } while (cont); + + ff_rtp_send_data (s1, s->buf, s->max_payload_size - left, i >= height); + } +} diff --git a/libavformat/sdp.c b/libavformat/sdp.c index 1200e553f9..cc04d70c0d 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -660,6 +660,31 @@ static char *sdp_write_media_attributes(char *buff, int size, AVStream *st, int p->width, p->height, pix_fmt, config); break; } + case AV_CODEC_ID_RAWVIDEO: { + const char *pix_fmt; + int bit_depth = 8; + + switch (p->format) { + case AV_PIX_FMT_UYVY422: + pix_fmt = "YCbCr-4:2:2"; + break; + case AV_PIX_FMT_YUV420P: + pix_fmt = "YCbCr-4:2:0"; + break; + default: + av_log(fmt, AV_LOG_ERROR, "Unsupported pixel format.\n"); + return NULL; + } + + av_strlcatf(buff, size, "a=rtpmap:%d raw/90000\r\n" + "a=fmtp:%d sampling=%s; " + "width=%d; height=%d; " + "depth=%d\r\n", + payload_type, payload_type, + pix_fmt, p->width, p->height, bit_depth); + break; + } + case AV_CODEC_ID_VP8: av_strlcatf(buff, size, "a=rtpmap:%d VP8/90000\r\n", payload_type); diff --git a/libavformat/version.h b/libavformat/version.h index 81ed517609..0f76f50892 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -33,7 +33,7 @@ // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 59 #define LIBAVFORMAT_VERSION_MINOR 8 -#define LIBAVFORMAT_VERSION_MICRO 100 +#define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \