From patchwork Wed Nov 13 17:22:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Coudurier X-Patchwork-Id: 16250 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 48D1A449EA3 for ; Wed, 13 Nov 2019 19:22:32 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2BCCE68A7FD; Wed, 13 Nov 2019 19:22:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B9B2A689CDC for ; Wed, 13 Nov 2019 19:22:25 +0200 (EET) Received: by mail-pf1-f177.google.com with SMTP id q26so2073716pfn.11 for ; Wed, 13 Nov 2019 09:22:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z0IF/KAaMy2IZjMQwbdK4uj7t68LkRJTz7PHXH2rxwY=; b=X/u3pON+Esgi7tNg2+1jumyn+FB1nuJ+WwE5sN2c5CLd6W0sbUcH1GMlVghGW/Uyqj a3nalZSUOmPA1HyFT6ruLRKDtdDWWHWiblQDTfG3rqjLNYNSmFh1SZKcIPyfZ8zMRT0e 6ati5Ov8ukWE+m761jWWJyZ+9Y3qOJNZEGliyH49augpvRk7YhUeg92Ejjy8PAqHFc6v C1VnQhavayImbq2NkIS4dFqI2qAegWG38VqpKOLBoSJRBfZLxt+7FQ0/iEI/M3G7J2Yz I5LxqTL+UrcGA7jvYSrSbH7+/SPdBr7c0j20XChj8TFn8sbDt23ptRGYrHW3hrH7Tszz IsdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z0IF/KAaMy2IZjMQwbdK4uj7t68LkRJTz7PHXH2rxwY=; b=A/lUA9TI23RQEMaoos6zJ5TOPcvEZuraK8lvQms8JezERFPZWDq5VegKR7p7BNsgXD btjqUFgOtuPAdw5ysaG9Z10Q3oiCOJ1Rn72cqwH+BndzJwsBD7X+qS/ZR8x1svCF3LhE Lrh4Ocqb80rEqPXK8FfH2k+9ouBcAHWHkp0y16yuG6F2C1xt7Q9n4hFXM+BgODODBJRm H8/gcqAtxmC3ZZIcSJN2oZBIWlWjfMZjPLh1M2HiJdHtqDZHdgPW+WdBBnieXv44qpI0 0gMEh7RITKNDXBKZ3VCKGnRMc5i4VKOuzFFrXcIbT7jUno/Xxhz7X8P9VUMvMacBVm7I mMlw== X-Gm-Message-State: APjAAAURs4AcztDIYpXcm8P29/jJbTXroDa6qdL6xcgfV69mYdDi17++ 4lHgjFU/dzCpl68TJI7diG0Do115 X-Google-Smtp-Source: APXvYqyKCwHDBpgtI0W5tWNeurYv+8ntk2Kucf2xC2M44jdHOPaCoxUkIAlh9fgFiLVSmF6LYi3CWw== X-Received: by 2002:a17:90a:f496:: with SMTP id bx22mr6529173pjb.101.1573665743551; Wed, 13 Nov 2019 09:22:23 -0800 (PST) Received: from baptiste.quibi.com (cpe-104-173-251-254.socal.res.rr.com. [104.173.251.254]) by smtp.gmail.com with ESMTPSA id s69sm3146770pgs.65.2019.11.13.09.22.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Nov 2019 09:22:23 -0800 (PST) From: Baptiste Coudurier To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Nov 2019 09:22:20 -0800 Message-Id: <20191113172220.62439-1-baptiste.coudurier@gmail.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/dvenc: support muxing dvcprohd 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: Baptiste Coudurier Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavformat/dvenc.c | 48 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c index 93c103b316..a7d1413eb2 100644 --- a/libavformat/dvenc.c +++ b/libavformat/dvenc.c @@ -28,7 +28,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include -#include #include "avformat.h" #include "internal.h" @@ -48,8 +47,8 @@ struct DVMuxContext { AVClass *av_class; const AVDVProfile* sys; /* current DV profile, e.g.: 525/60, 625/50 */ int n_ast; /* number of stereo audio streams (up to 2) */ - AVStream *ast[2]; /* stereo audio streams */ - AVFifoBuffer *audio_data[2]; /* FIFO for storing excessive amounts of PCM */ + AVStream *ast[4]; /* stereo audio streams */ + AVFifoBuffer *audio_data[4]; /* FIFO for storing excessive amounts of PCM */ int frames; /* current frame number */ int64_t start_time; /* recording start time */ int has_audio; /* frame under construction has audio */ @@ -87,14 +86,12 @@ static int dv_audio_frame_size(const AVDVProfile* sys, int frame, int sample_rat sizeof(sys->audio_samples_dist[0]))]; } -static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* buf, ...) +static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* buf, int channel, int seq) { struct tm tc; time_t ct; uint32_t timecode; - va_list ap; int audio_type = 0; - int channel; buf[0] = (uint8_t)pack_id; switch (pack_id) { @@ -104,8 +101,6 @@ static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* bu AV_WB32(buf + 1, timecode); break; case dv_audio_source: /* AAUX source pack */ - va_start(ap, buf); - channel = va_arg(ap, int); if (c->ast[channel]->codecpar->sample_rate == 44100) { audio_type = 1; } else if (c->ast[channel]->codecpar->sample_rate == 32000) @@ -118,17 +113,16 @@ static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* bu buf[2] = (0 << 7) | /* multi-stereo */ (0 << 5) | /* #of audio channels per block: 0 -- 1 channel */ (0 << 4) | /* pair bit: 0 -- one pair of channels */ - !!va_arg(ap, int); /* audio mode */ + (seq >= c->sys->difseg_size/2); /* audio mode (1st or 2nd channel) */ buf[3] = (1 << 7) | /* res */ (1 << 6) | /* multi-language flag */ (c->sys->dsf << 5) | /* system: 60fields/50fields */ - (c->sys->n_difchan & 2); /* definition: 0 -- 25Mbps, 2 -- 50Mbps */ + (DV_PROFILE_IS_HD(c->sys) ? 0x3 : c->sys->video_stype ? 2 : 0); /* stype */ buf[4] = (1 << 7) | /* emphasis: 1 -- off */ (0 << 6) | /* emphasis time constant: 0 -- reserved */ (audio_type << 3) | /* frequency: 0 -- 48kHz, 1 -- 44,1kHz, 2 -- 32kHz */ 0; /* quantization: 0 -- 16-bit linear, 1 -- 12-bit nonlinear */ - va_end(ap); break; case dv_audio_control: buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */ @@ -192,7 +186,7 @@ static void dv_inject_audio(DVMuxContext *c, int channel, uint8_t* frame_ptr) for (i = 0; i < c->sys->difseg_size; i++) { frame_ptr += 6 * 80; /* skip DIF segment header */ for (j = 0; j < 9; j++) { - dv_write_pack(dv_aaux_packs_dist[i][j], c, &frame_ptr[3], channel, i >= c->sys->difseg_size/2); + dv_write_pack(dv_aaux_packs_dist[i][j], c, &frame_ptr[3], channel, i); for (d = 8; d < 80; d+=2) { of = c->sys->audio_shuffle[i][j] + (d - 8)/2 * c->sys->audio_stride; if (of*2 >= size) @@ -210,27 +204,28 @@ static void dv_inject_metadata(DVMuxContext *c, uint8_t* frame) { int j, k; uint8_t* buf; + int seq = 0; - for (buf = frame; buf < frame + c->sys->frame_size; buf += 150 * 80) { + for (buf = frame; buf < frame + c->sys->frame_size; buf += 150 * 80, seq++) { /* DV subcode: 2nd and 3d DIFs */ for (j = 80; j < 80 * 3; j += 80) { for (k = 6; k < 6 * 8; k += 8) - dv_write_pack(dv_timecode, c, &buf[j+k]); + dv_write_pack(dv_timecode, c, &buf[j+k], 0, seq); if (((long)(buf-frame)/(c->sys->frame_size/(c->sys->difseg_size*c->sys->n_difchan))%c->sys->difseg_size) > 5) { /* FIXME: is this really needed ? */ - dv_write_pack(dv_video_recdate, c, &buf[j+14]); - dv_write_pack(dv_video_rectime, c, &buf[j+22]); - dv_write_pack(dv_video_recdate, c, &buf[j+38]); - dv_write_pack(dv_video_rectime, c, &buf[j+46]); + dv_write_pack(dv_video_recdate, c, &buf[j+14], 0, seq); + dv_write_pack(dv_video_rectime, c, &buf[j+22], 0, seq); + dv_write_pack(dv_video_recdate, c, &buf[j+38], 0, seq); + dv_write_pack(dv_video_rectime, c, &buf[j+46], 0, seq); } } /* DV VAUX: 4th, 5th and 6th 3DIFs */ for (j = 80*3 + 3; j < 80*6; j += 80) { - dv_write_pack(dv_video_recdate, c, &buf[j+5*2]); - dv_write_pack(dv_video_rectime, c, &buf[j+5*3]); - dv_write_pack(dv_video_recdate, c, &buf[j+5*11]); - dv_write_pack(dv_video_rectime, c, &buf[j+5*12]); + dv_write_pack(dv_video_recdate, c, &buf[j+5* 2], 0, seq); + dv_write_pack(dv_video_rectime, c, &buf[j+5* 3], 0, seq); + dv_write_pack(dv_video_recdate, c, &buf[j+5*11], 0, seq); + dv_write_pack(dv_video_rectime, c, &buf[j+5*12], 0, seq); } } } @@ -307,11 +302,11 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s) int i; /* we support at most 1 video and 2 audio streams */ - if (s->nb_streams > 3) + if (s->nb_streams > 5) return NULL; c->n_ast = 0; - c->ast[0] = c->ast[1] = NULL; + c->ast[0] = c->ast[1] = c->ast[2] = c->ast[3] = NULL; /* We have to sort out where audio and where video stream is */ for (i=0; inb_streams; i++) { @@ -355,8 +350,9 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s) goto bail_out; } - if ((c->n_ast > 1) && (c->sys->n_difchan < 2)) { - /* only 1 stereo pair is allowed in 25Mbps mode */ + if (((c->n_ast > 1) && (c->sys->n_difchan < 2)) || + ((c->n_ast > 2) && (c->sys->n_difchan < 4))) { + /* only 2 stereo pairs allowed in 50Mbps mode */ goto bail_out; }