From patchwork Tue Jul 10 21:52:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Keroulas X-Patchwork-Id: 9664 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp4140337jad; Tue, 10 Jul 2018 14:52:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdkoXou+mFxggssJ97OCQYG9473MR0sv7eHsuh8qKhXgPI/LDjFVrcJdujdHV7vbGxXz6Me X-Received: by 2002:adf:9aa3:: with SMTP id a32-v6mr3075191wrc.75.1531259552773; Tue, 10 Jul 2018 14:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531259552; cv=none; d=google.com; s=arc-20160816; b=rjTBE/xaABQhofxI8+BskYfH3XbmvRKf0xJbMYc54Bf25B8lh8y2TCTjxkXwXlkDea Sj2mNLeVCouAnqm+6XW2EcAl6O6dMFsnoDmR6d/ILwlFlxGU6mqT/XeSWaNl2xjwH+6T +naBsoGR0Y+H0ZqQL8w1hlzABUOCS6qUJRPscUdoJf3k9nLDmpHAV8Op/0f0FNkG1RUB NIn7EpWn5EZUqcKqG38dJmClMGQtxIqnjsU3NNSdrBcb4FgOZZC1k5fqrqtYXGAUF4v7 s736YK5/bLbYYE2zT0/1Lcse7BpXrpO33R6bp7sXjQO76WbQkhZMWOtqdSGxI7pG8BBD anVw== 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:delivered-to:arc-authentication-results; bh=1h0UtlXDaJO2ZQiuUUvCmd6wrOps0wtHdDPdxUad8xg=; b=ZiL2lSHRnUd9gOtm42CLSOlDgMANptChxNy+wtciy7l0+X1IuvB0Qgo9bJfiVg8ft9 gaw/PwiDuDT/NMfPINQAdf3r8Bzz7NQMqEeA0BODiYVtlrhC5mWWgk3dXtv48aNAGw9X ImdWDbkFZdxD8S1R8BHgTyIwtXI5QJGtJqtOMYy+7WeNGK40CjEkU9C2UsWhrYRxerqt 7qAeWRyc5KRS6Wctj6Z5wS92OYROMFPLLG5BsnD6iqyjV0izHTN0/0UWOe1/s1biTwZg P+znP/fW1PAvtNS59hLXHJU/nFlb/bHKOzV+RNuGQEwNB5NxVw00Ollnvz/I4vJBndbz KaoA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t43-v6si4021341wrc.195.2018.07.10.14.52.32; Tue, 10 Jul 2018 14:52:32 -0700 (PDT) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5799468A594; Wed, 11 Jul 2018 00:52:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.savoirfairelinux.com (mail.savoirfairelinux.com [208.88.110.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D91D368A03A for ; Wed, 11 Jul 2018 00:51:58 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 940489C218B for ; Tue, 10 Jul 2018 17:52:05 -0400 (EDT) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 04A2vgVhvy-y; Tue, 10 Jul 2018 17:52:05 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 149DA9C316B; Tue, 10 Jul 2018 17:52:05 -0400 (EDT) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Dua2wY5WKyLU; Tue, 10 Jul 2018 17:52:04 -0400 (EDT) Received: from pkeroulas.cbc-rc.ca (unknown [192.168.50.171]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id E94859C218B; Tue, 10 Jul 2018 17:52:04 -0400 (EDT) From: Patrick Keroulas To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Jul 2018 17:52:01 -0400 Message-Id: <1531259521-19421-3-git-send-email-patrick.keroulas@savoirfairelinux.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531259521-19421-1-git-send-email-patrick.keroulas@savoirfairelinux.com> References: <1531259521-19421-1-git-send-email-patrick.keroulas@savoirfairelinux.com> Subject: [FFmpeg-devel] [PATCH v8 3/3] avformat/rtpdec_rfc4175: handle interlace format 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: Damien Riegel , Patrick Keroulas MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Damien Riegel In order to handle the interlaced formats, the demuxer has only a few things to do: - parse the SDP correctly and propagate the information - check the field bit in the RFC4175 header, and pass that information to the decoder In interlaced mode, received data only consist of fields, and their heights are half of the frame size, so some adjustments must be done here and there to take that into account. Signed-off-by: Damien Riegel Signed-off-by: Patrick Keroulas --- libavformat/rtpdec_rfc4175.c | 57 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/libavformat/rtpdec_rfc4175.c b/libavformat/rtpdec_rfc4175.c index e9c62c1..b9619be 100644 --- a/libavformat/rtpdec_rfc4175.c +++ b/libavformat/rtpdec_rfc4175.c @@ -23,6 +23,7 @@ #include "avio_internal.h" #include "rtpdec_formats.h" +#include "libavutil/ancillary_data.h" #include "libavutil/avstring.h" #include "libavutil/pixdesc.h" @@ -31,6 +32,8 @@ struct PayloadContext { int depth; int width; int height; + int interlaced; + int field; uint8_t *frame; unsigned int frame_size; @@ -65,10 +68,18 @@ static int rfc4175_parse_format(AVStream *stream, PayloadContext *data) return AVERROR_INVALIDDATA; } + if (data->interlaced) + stream->codecpar->field_order = AV_FIELD_TT; + else + stream->codecpar->field_order = AV_FIELD_PROGRESSIVE; + stream->codecpar->format = pixfmt; stream->codecpar->codec_tag = tag; stream->codecpar->bits_per_coded_sample = bits_per_sample; - data->frame_size = data->width * data->height * data->pgroup / data->xinc; + if (data->interlaced) + data->frame_size = data->width * (data->height / 2) * data->pgroup / data->xinc; + else + data->frame_size = data->width * data->height * data->pgroup / data->xinc; return 0; } @@ -85,6 +96,8 @@ static int rfc4175_parse_fmtp(AVFormatContext *s, AVStream *stream, data->sampling = av_strdup(value); else if (!strncmp(attr, "depth", 5)) data->depth = atoi(value); + else if (!strncmp(attr, "interlace", 9)) + data->interlaced = 1; return 0; } @@ -123,17 +136,38 @@ static int rfc4175_parse_sdp_line(AVFormatContext *s, int st_index, static int rfc4175_finalize_packet(PayloadContext *data, AVPacket *pkt, int stream_index) { - int ret; + AVAncillaryData * ancillary; + int ret; + uint8_t * side_data; + + pkt->stream_index = stream_index; + ret = av_packet_from_data(pkt, data->frame, data->frame_size); + if (ret < 0) { + av_freep(&data->frame); + } - pkt->stream_index = stream_index; - ret = av_packet_from_data(pkt, data->frame, data->frame_size); - if (ret < 0) { - av_freep(&data->frame); - } + /* In the packet header, the field is set to 0 for top field + * and 1 for bottom */ + if (data->interlaced) { + ancillary = av_ancillary_data_alloc(); + if (!ancillary) + return AVERROR(ENOMEM); - data->frame = NULL; + ancillary->field = data->field ? AV_ANCILLARY_DATA_FIELD_BOTTOM_FIELD + : AV_ANCILLARY_DATA_FIELD_TOP_FIELD; - return ret; + side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_ANCILLARY, + sizeof(AVAncillaryData)); + if (!side_data) + return AVERROR(ENOMEM); + + memcpy(side_data, ancillary, sizeof(AVAncillaryData)); + } + + data->frame = NULL; + data->field = 0; + + return ret; } static int rfc4175_handle_packet(AVFormatContext *ctx, PayloadContext *data, @@ -141,7 +175,7 @@ static int rfc4175_handle_packet(AVFormatContext *ctx, PayloadContext *data, const uint8_t * buf, int len, uint16_t seq, int flags) { - int length, line, offset, cont; + int length, line, offset, cont, field; const uint8_t *headers = buf + 2; /* skip extended seqnum */ const uint8_t *payload = buf + 2; int payload_len = len - 2; @@ -194,11 +228,14 @@ static int rfc4175_handle_packet(AVFormatContext *ctx, PayloadContext *data, return AVERROR_INVALIDDATA; length = (headers[0] << 8) | headers[1]; + field = (headers[2] & 0x80); line = ((headers[2] & 0x7f) << 8) | headers[3]; offset = ((headers[4] & 0x7f) << 8) | headers[5]; cont = headers[4] & 0x80; headers += 6; + data->field = field; + if (length % data->pgroup) return AVERROR_INVALIDDATA;