From patchwork Fri Jun 14 19:51:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cameron Cawley X-Patchwork-Id: 13538 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 86EDD448B98 for ; Fri, 14 Jun 2019 23:00:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5CAF068A706; Fri, 14 Jun 2019 23:00:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C54FC689C60 for ; Fri, 14 Jun 2019 23:00:48 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id f9so3701663wre.12 for ; Fri, 14 Jun 2019 13:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YhKf1KkuuE2EdrQOWa2szXf/73daJ5FMPE1enLUwIeU=; b=n6XW0dCJ3f5VnfIPZAUVrS0QZpTQOjhW+793TKw17PVqlkg0c80uG0Ci9ythFLCeD7 ndifGVfdmrpLVdNDzo7Qlvr0LYo9/D25QqpS9owOoHgXBSpgBAsJnXcibk8wavYnt0GC pWn7lqgEGuquHALF4rH1JgP7dBqQv1NzPDXqBg0dHBrPzHzOt1t/bg3fD6QZs//fetUJ HhSqYrtW/PXnloEyrvNisDjYKxjQfjrrunRVsmbFoMCCQcFqu8VLaSRDSPUwdzpkhI8A GW6NBlhetD3mUwY5v5I7uR6ojqFbIRmyTPoWMaBk6N23qhYho0amDKSRpRGUSJn7d4Ez AtrQ== 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:in-reply-to :references; bh=YhKf1KkuuE2EdrQOWa2szXf/73daJ5FMPE1enLUwIeU=; b=rbHowgtxhoOaR61lnu3ho9FQEEBr6psKqdg2cFwUYQYI3rQ0VDaCNDef3xF8YtvYhb O8F95jRHInXEJlc0MZERfCngAUd2+7rgdS7hRelV0hAB9pfreh4+hBvVGNbLH3ozV99y 3OIrGwkY/sV5Ol37mEF9nMa8U9POp5NF6WLLBqZFbYRLkjQYbUfny94dhqzD5l7M17jf +VWDtLdWFD2n2SLJIgEB3l5NUnZ/x01f25mWLrRCmWgGbimDkdCJxEwPkXcBQNK9T5Hu /HrFMKz/6ZrPlMnktA8/zgG/tELgU6dF1l8e//FfYrX2PGK0AQJPx6JIVUfGu+H8GOkD 7cYQ== X-Gm-Message-State: APjAAAV+BNy28UfScSHZ7QEE1kaWv6Sj7NDZ3lbzcVHoIdGfF0oCB1cd N82ZnfntaCsgJtHc7zX+3eyPLyNF X-Google-Smtp-Source: APXvYqznxpWftxCzWQMwxwLQO6SPmbY505ldUlwWmZdd8mwgW9XjTSJz59MTvzhctmoELmIXU6QYDA== X-Received: by 2002:a5d:5745:: with SMTP id q5mr10051623wrw.75.1560542055922; Fri, 14 Jun 2019 12:54:15 -0700 (PDT) Received: from localhost.localdomain (host109-155-177-56.range109-155.btcentralplus.com. [109.155.177.56]) by smtp.gmail.com with ESMTPSA id y16sm2668221wru.28.2019.06.14.12.54.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jun 2019 12:54:15 -0700 (PDT) From: Cameron Cawley To: ffmpeg-devel@ffmpeg.org Date: Fri, 14 Jun 2019 20:51:34 +0100 Message-Id: <20190614195134.19205-2-ccawley2011@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614195134.19205-1-ccawley2011@gmail.com> References: <20190614195134.19205-1-ccawley2011@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] avformat/rpl: Allow a file to have audio, but not video 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: Cameron Cawley MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Cameron Cawley --- libavformat/rpl.c | 78 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/libavformat/rpl.c b/libavformat/rpl.c index 683b3a835a..dbbcd13b41 100644 --- a/libavformat/rpl.c +++ b/libavformat/rpl.c @@ -124,7 +124,7 @@ static int rpl_read_header(AVFormatContext *s) uint32_t i; - int32_t audio_format, chunk_catalog_offset, number_of_chunks; + int32_t video_format, audio_format, chunk_catalog_offset, number_of_chunks; AVRational fps; char line[RPL_LINE_LENGTH]; @@ -144,39 +144,47 @@ static int rpl_read_header(AVFormatContext *s) av_dict_set(&s->metadata, "author" , line, 0); // video headers - vst = avformat_new_stream(s, NULL); - if (!vst) - return AVERROR(ENOMEM); - vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codecpar->codec_tag = read_line_and_int(pb, &error); // video format - vst->codecpar->width = read_line_and_int(pb, &error); // video width - vst->codecpar->height = read_line_and_int(pb, &error); // video height - vst->codecpar->bits_per_coded_sample = read_line_and_int(pb, &error); // video bits per sample - error |= read_line(pb, line, sizeof(line)); // video frames per second - fps = read_fps(line, &error); - avpriv_set_pts_info(vst, 32, fps.den, fps.num); - - // Figure out the video codec - switch (vst->codecpar->codec_tag) { + video_format = read_line_and_int(pb, &error); + if (video_format) { + vst = avformat_new_stream(s, NULL); + if (!vst) + return AVERROR(ENOMEM); + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_tag = video_format; + vst->codecpar->width = read_line_and_int(pb, &error); // video width + vst->codecpar->height = read_line_and_int(pb, &error); // video height + vst->codecpar->bits_per_coded_sample = read_line_and_int(pb, &error); // video bits per sample + + // Figure out the video codec + switch (vst->codecpar->codec_tag) { #if 0 - case 122: - vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE122; - break; + case 122: + vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE122; + break; #endif - case 124: - vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE124; - // The header is wrong here, at least sometimes - vst->codecpar->bits_per_coded_sample = 16; - break; - case 130: - vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE130; - break; - default: - avpriv_report_missing_feature(s, "Video format %s", - av_fourcc2str(vst->codecpar->codec_tag)); - vst->codecpar->codec_id = AV_CODEC_ID_NONE; + case 124: + vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE124; + // The header is wrong here, at least sometimes + vst->codecpar->bits_per_coded_sample = 16; + break; + case 130: + vst->codecpar->codec_id = AV_CODEC_ID_ESCAPE130; + break; + default: + avpriv_report_missing_feature(s, "Video format %s", + av_fourcc2str(vst->codecpar->codec_tag)); + vst->codecpar->codec_id = AV_CODEC_ID_NONE; + } + } else { + for (i = 0; i < 3; i++) + error |= read_line(pb, line, sizeof(line)); } + error |= read_line(pb, line, sizeof(line)); // video frames per second + fps = read_fps(line, &error); + if (vst) + avpriv_set_pts_info(vst, 32, fps.den, fps.num); + // Audio headers // ARMovie supports multiple audio tracks; I don't have any @@ -246,7 +254,7 @@ static int rpl_read_header(AVFormatContext *s) } rpl->frames_per_chunk = read_line_and_int(pb, &error); // video frames per chunk - if (rpl->frames_per_chunk > 1 && vst->codecpar->codec_tag != 124) + if (vst && rpl->frames_per_chunk > 1 && vst->codecpar->codec_tag != 124) av_log(s, AV_LOG_WARNING, "Don't know how to split frames for video format %s. " "Video stream will be broken!\n", av_fourcc2str(vst->codecpar->codec_tag)); @@ -261,7 +269,8 @@ static int rpl_read_header(AVFormatContext *s) read_line_and_int(pb, &error); // (file index) error |= read_line(pb, line, sizeof(line)); // offset to "helpful" sprite error |= read_line(pb, line, sizeof(line)); // size of "helpful" sprite - error |= read_line(pb, line, sizeof(line)); // offset to key frame list + if (vst) + error |= read_line(pb, line, sizeof(line)); // offset to key frame list // Read the index avio_seek(pb, chunk_catalog_offset, SEEK_SET); @@ -274,8 +283,9 @@ static int rpl_read_header(AVFormatContext *s) error = -1; continue; } - av_add_index_entry(vst, offset, i * rpl->frames_per_chunk, - video_size, rpl->frames_per_chunk, 0); + if (vst) + av_add_index_entry(vst, offset, i * rpl->frames_per_chunk, + video_size, rpl->frames_per_chunk, 0); if (ast) av_add_index_entry(ast, offset + video_size, total_audio_size, audio_size, audio_size * 8, 0);