From patchwork Fri Jan 5 11:34:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: misty@brew.sh X-Patchwork-Id: 7140 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.78.2 with SMTP id r2csp661642jaa; Fri, 5 Jan 2018 03:35:54 -0800 (PST) X-Google-Smtp-Source: ACJfBosMNJdClg0af4BHdrqLjPkcmcWLaTQaY3njnGpe8lRYxdW3pAR+xEiwF4PQhewq/LMfpdd1 X-Received: by 10.28.194.138 with SMTP id s132mr1894950wmf.129.1515152154139; Fri, 05 Jan 2018 03:35:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515152154; cv=none; d=google.com; s=arc-20160816; b=agy4pc0p6vv26nkpN5cH7eIuaLfiK8CCOzD6WF9fFaDKUkCqZDD5UvFVgvrUZFDQQ4 Y2PZ9X/8QV3PRRAmlUEpE+0BhpSan214V0LN1rVjF+434FcMbpb3kKHxKVkye5tN+0cz kbGY5dOvJMnb3UtvAZKyaz3URsYhRzxZp68+j6I+IhkQikWJPvWKLf16O/EUH8NERcXZ DNeGMSYzIyno5aLaAz1oE4rAQzGTd9rgp6ye1AO6EjXmgZpMm/KB/JJk8FJ3E2tjQA9S gBGjhiPQiAYAw/k0JvqNZIyg6n+whI7VVhh8AfyQV/cprc9RpEZ9IpXHrtdZguJ7k6BJ Q9bA== 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:arc-authentication-results; bh=zKnoNKKl6fGNybLZfynmsHOdIirV0/+2K1rb5P/NedM=; b=xpPXklb2FWjEbcNnYuI8dhP+Fx6Qlx87F5tDNf+6eaZkJPl15c/Npaa8Dv0hPETEAn RbpoN3qM/Uu2o2ELzrukTYXQ3nGjqKS7M9kAPW39O6N3NBmrtZTwgA6olGBFaNZ1z1AV 9DEydFxXdGpLW6PcH2GIVmwN/r4Tw8/NksK/EYA9eX8AfX1mOoUWOBh+2uSbEprxgo1A o9pLeVeKB2+MkhQdumxsB+1ztEEFQiu518EXyu8LEC7ogT8GpcUZjI9Konc2imkT7Q6s S8lOabRUSJZ085Lh/tKKA2K8E6twEguq29P4gDqWxo9gKYL2p5XJWsdAoE2oTQP4P8QB 58qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=UkyRJ99A; 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 9si4202114wra.274.2018.01.05.03.35.53; Fri, 05 Jan 2018 03:35:54 -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=20161025 header.b=UkyRJ99A; 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 33373689A53; Fri, 5 Jan 2018 13:35:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl0-f42.google.com (mail-pl0-f42.google.com [209.85.160.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 52FB4689A31 for ; Fri, 5 Jan 2018 13:34:56 +0200 (EET) Received: by mail-pl0-f42.google.com with SMTP id z5so2900815plo.10 for ; Fri, 05 Jan 2018 03:35:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EsnHSJ+5x5drB/Pc9xqlnAxVWUAuxPFsxdT4RsIW6XI=; b=UkyRJ99AT6ICqLxzonbjdBATij9tKwiy0Il3fiuOJpEMj857bx9dld04F8fa6xDO8/ hxYnmE5nw8YguVAtkg1TVXVyt/RGK4hw7q5K5GHLsxSutlzvgp8/Us4S9RwT+XFo+sKR RACLErPAnlVOQfWrul6Td2Xu2K/0lLssh4NKC+8F9MYEN1EJCfku3coN2HWBDXgKE+fi 9xCYgpUvWr7Yiu7Y2XgTaMNyc5GfOJ8a6PGSfj3l4dv8JRv72vX++ER740EGjkLT12E/ ruq2XzpWW1nPg9ZxExufpdeipCVLaXDSrLqPRkVGC5CzDKcnPX8ODzrcD8/Dm8CA4buc XD4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=EsnHSJ+5x5drB/Pc9xqlnAxVWUAuxPFsxdT4RsIW6XI=; b=llNGuJbAPluROd84XMjomWQTM9gQeaLZddt/Q+5saVyFv5anQRd5kM2jmL2E7W2gjw SUUm1xdDvDVMzXdqJuHIr3TVnPGnyayhXcU9P67ID+ih37d2cO5DDzOEYEhvkXxzStCb letkyozUk2LYTZbf82/rtBg7JhEwHzB9DU62M59PUnJNZwNuaCuw2b/tP570nnjYX56o ytOUMw00+hGOv3fhbt/bm0RLkbSE+gpyw//5Me84xLs583iioFPv8vUVIFUAiEttbMA4 jB4CliOnqwUJQLdbC39h7hH4xTFh8F6CRlAM8jil5m3hIrKL8q5kjvW68LwyzBNH99mn 8q2Q== X-Gm-Message-State: AKGB3mJMTSPK7vX1TG55iQXIljp1Rrl3Pw5f/p9Ni1kZU2blzJjuTCuo 2MS2NQVQszcxy0dmjX2+1kPU/RCQ X-Received: by 10.159.198.72 with SMTP id y8mr2809887plt.197.1515152111826; Fri, 05 Jan 2018 03:35:11 -0800 (PST) Received: from localhost.localdomain (180-150-45-216.NBN.mel.aussiebb.net. [180.150.45.216]) by smtp.gmail.com with ESMTPSA id s184sm11549586pfb.9.2018.01.05.03.35.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Jan 2018 03:35:11 -0800 (PST) From: misty@brew.sh To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Jan 2018 22:34:46 +1100 Message-Id: <20180105113448.13917-5-misty@brew.sh> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180105113448.13917-1-misty@brew.sh> References: <20180102213143.GE4926@michaelspb> <20180105113448.13917-1-misty@brew.sh> Subject: [FFmpeg-devel] [PATCH 4/6] Fix detecting ATRAC3 audio from MPS files 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: Misty De Meo MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Misty De Meo MPS files are MPEG files used on PSP Video discs. They lack the PSMF header used by .pms files, and so the special casing in the original patch fails to support their audio. This patch fixes this by unconditionally reading a new byte for the startcode for PRIVATE_STREAM_1 sections, and doing the comparison on that to find ATRAC-3 streams. In my testing, it works fine for both MPS and PSMF files. --- Changelog | 1 + libavformat/mpeg.c | 50 +++++++++++++++++++++++++++----------------------- libavformat/mpeg.h | 1 + 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Changelog b/Changelog index 3d966c202b..d4761ec7f9 100644 --- a/Changelog +++ b/Changelog @@ -33,6 +33,7 @@ version : - deconvolve video filter - entropy video filter - hilbert audio filter source +- ATRAC-3 support for Sony PSP MPEG files version 3.4: diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index 895c6fb231..afde768199 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -148,8 +148,6 @@ static int mpegps_read_header(AVFormatContext *s) avio_get_str(s->pb, 6, buffer, sizeof(buffer)); if (!memcmp("IMKH", buffer, 4)) { m->imkh_cctv = 1; - } else if (!memcmp("PSMF00", buffer, 6)) { - m->sony_psmf = 1; } else if (!memcmp("Sofdec", buffer, 6)) { m->sofdec = 1; } else @@ -444,7 +442,7 @@ redo: goto redo; } - if (startcode == PRIVATE_STREAM_1 && !m->sony_psmf) { + if (startcode == PRIVATE_STREAM_1) { startcode = avio_r8(s->pb); len--; } @@ -507,6 +505,19 @@ redo: goto found; } + /* These bytes in the PES header can be used to identify + * the first ATRAC packets in a Sony ATRAC video */ + if (!m->sony_psmf) { + avio_seek(s->pb, -4, SEEK_CUR); + unsigned char atrac_buf[3]; + avio_read(s->pb, atrac_buf, 3); + avio_skip(s->pb, 1); + + m->sony_psmf = memcmp(atrac_buf, "\x1E\x60\x08", 3) == 0 || + memcmp(atrac_buf, "\x1E\x60\x04", 3) == 0 || + memcmp(atrac_buf, "\x1E\x60\x14", 3) == 0; + } + es_type = m->psm_es_type[startcode & 0xff]; if (es_type == STREAM_TYPE_VIDEO_MPEG1) { codec_id = AV_CODEC_ID_MPEG2VIDEO; @@ -544,28 +555,21 @@ redo: else request_probe= 1; type = AVMEDIA_TYPE_VIDEO; - } else if (startcode == PRIVATE_STREAM_1 && m->sony_psmf) { - uint8_t stream_id; - - if (len < 2) - goto skip; - stream_id = avio_r8(s->pb); + // Sony PSP video with ATRAC-3 audio + } else if (startcode < 0x20 && m->sony_psmf) { avio_r8(s->pb); // skip padding - len -= 2; - if (!(stream_id & 0xF0)) { // seems like we got an ATRAC stream - /* check if an appropriate stream already exists */ - for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - st->codec->codec_id == AV_CODEC_ID_ATRAC3P && - st->id - 0x1BD0 == (stream_id & 0xF)) - goto found; - } - - startcode = 0x1BD0 + (stream_id & 0xF); - type = AVMEDIA_TYPE_AUDIO; - codec_id = AV_CODEC_ID_ATRAC3P; + len--; + for (i = 0; i < s->nb_streams; i++) { + st = s->streams[i]; + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && + st->codec->codec_id == AV_CODEC_ID_ATRAC3P && + st->id - 0x1BD0 == (startcode & 0xF)) + goto found; } + + startcode = 0x1BD0 + (startcode & 0xF); + type = AVMEDIA_TYPE_AUDIO; + codec_id = AV_CODEC_ID_ATRAC3P; } else if (startcode == PRIVATE_STREAM_2) { type = AVMEDIA_TYPE_DATA; codec_id = AV_CODEC_ID_DVD_NAV; diff --git a/libavformat/mpeg.h b/libavformat/mpeg.h index 617e36cba8..efbadec8ba 100644 --- a/libavformat/mpeg.h +++ b/libavformat/mpeg.h @@ -58,6 +58,7 @@ #define STREAM_TYPE_VIDEO_CAVS 0x42 #define STREAM_TYPE_AUDIO_AC3 0x81 +#define STREAM_TYPE_AUDIO_ATRAC3 0xF0 static const int lpcm_freq_tab[4] = { 48000, 96000, 44100, 32000 };