From patchwork Fri Feb 5 18:51:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 25455 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 223C14492BC for ; Fri, 5 Feb 2021 20:51:34 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EB92A689BDC; Fri, 5 Feb 2021 20:51:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 91A2368980E for ; Fri, 5 Feb 2021 20:51:27 +0200 (EET) Received: by mail-ej1-f47.google.com with SMTP id bl23so13493613ejb.5 for ; Fri, 05 Feb 2021 10:51:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=hQkV/MOplKOmUA7r9b2noHsV0l1QVqe/4YEtFXS3fHM=; b=M35bBB1Rp3mmWhtDtjnXkzwtCzXlgi5hf2ytlPgj+EpgyZXELeJSPF93Bb/OS84f3o UGG/tMpMkhpso96onD80NUH7oNnbDb73n5L5V8NlFVsU01yUh1wsnUhxtM2NHCdNudDJ wgK92KTpHEJGjzf3myh5ope9OXSUkG+yPUsMazIUyygB6SnGiNNF0l4C6iCfBFLLQmUL Tbz2r2xlIRFBPxCMoi2e5fvH3FoPISSOuVK6zW3jBk8hx8NxOfATjzsvSB14fC642pyn Fj+7iFtsrSiSElnHiMVbf57L11tPXOep9Ep51GltGGmbu9R4fwa/wlcfhcY75ZgUiX/q fHKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=hQkV/MOplKOmUA7r9b2noHsV0l1QVqe/4YEtFXS3fHM=; b=JK4RVAIwc6mHFBKDLss+LzhaiaYMjml0EmNrw/heb8yK33B91k6mLYgYeV+PEp4e9r Wl2A1YnkQ0UsoOD7Q5FMMTlNGVRHEsfZiJyDZUURuaJDCGtl4zkDa/zciE7pYUxVMQE2 ibjjk6VU6iU4L+3l5LUgMmx/XjWJ4M9x5t5B3YdBdmhX3dToENvyghz7nnKqJ4T7XC/j Zq0Vj1EOU+JwZEqCDI4pcyAOvsmbsA4u/KIXBuSIBdT1G85UttB2CI1SDWVFJCDe7U0h C8kR4OpIRUIQfJ380fi8icYRPR3ES+brKcy3KpaSIatsM3bS4qN2PKRhDe6ZKf068dCD 2AmQ== X-Gm-Message-State: AOAM532JpPsquQKZZz+5plJsCxMD5Gh6A93sjDfqKk9JZj1NGVklMqJ2 2BlQ77QWSzowCtMrNT005ojppUnmT2KC8g== X-Google-Smtp-Source: ABdhPJzmx6t3E7EYE6bup+H/Ari+L8YYlFeDQUCeIAG/B4NdOY0XgSkAsKHu2EfpmHMNZ3xHao+WAA== X-Received: by 2002:a17:907:1119:: with SMTP id qu25mr5176783ejb.268.1612551086881; Fri, 05 Feb 2021 10:51:26 -0800 (PST) Received: from localhost.localdomain ([31.45.254.141]) by smtp.gmail.com with ESMTPSA id i13sm4249558ejj.2.2021.02.05.10.51.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 10:51:26 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Feb 2021 19:51:18 +0100 Message-Id: <20210205185118.4042-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avcodec: add photocd parser 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavcodec/Makefile | 1 + libavcodec/parsers.c | 1 + libavcodec/photocd_parser.c | 87 +++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 libavcodec/photocd_parser.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 2ddf021f04..b06b028ae4 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1114,6 +1114,7 @@ OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o \ mpeg12.o mpeg12data.o OBJS-$(CONFIG_OPUS_PARSER) += opus_parser.o opus.o opustab.o \ opus_rc.o vorbis_data.o +OBJS-$(CONFIG_PHOTOCD_PARSER) += photocd_parser.o OBJS-$(CONFIG_PNG_PARSER) += png_parser.o OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index 93af25ac14..d3353a6b39 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -59,6 +59,7 @@ extern AVCodecParser ff_mpeg4video_parser; extern AVCodecParser ff_mpegaudio_parser; extern AVCodecParser ff_mpegvideo_parser; extern AVCodecParser ff_opus_parser; +extern AVCodecParser ff_photocd_parser; extern AVCodecParser ff_png_parser; extern AVCodecParser ff_pnm_parser; extern AVCodecParser ff_rv30_parser; diff --git a/libavcodec/photocd_parser.c b/libavcodec/photocd_parser.c new file mode 100644 index 0000000000..844327f799 --- /dev/null +++ b/libavcodec/photocd_parser.c @@ -0,0 +1,87 @@ +/* + * PhotoCD parser + * Copyright (c) 2021 Paul B Mahol + * + * 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 + */ + +/** + * @file + * PhotoCD parser + */ + +#include "libavutil/common.h" + +#include "parser.h" + +typedef struct PhotoCDParser { + ParseContext pc; + int count; +} PhotoCDParser; + +#define KEY (((uint64_t)'P' << 56) | ((uint64_t)'C' << 48) | \ + ((uint64_t)'D' << 40) | ((uint64_t)'_' << 32) | \ + ((uint64_t)'I' << 24) | ((uint64_t)'P' << 16) | \ + ((uint64_t)'I' << 8) | ((uint64_t)'\0'<< 0)) + +static int photocd_parse(AVCodecParserContext *s, AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + PhotoCDParser *bpc = s->priv_data; + uint64_t state = bpc->pc.state64; + int next = END_NOT_FOUND, i = 0; + + s->pict_type = AV_PICTURE_TYPE_I; + s->key_frame = 1; + s->duration = 1; + + *poutbuf_size = 0; + *poutbuf = NULL; + + for (; i < buf_size; i++) { + state = (state << 8) | buf[i]; + + if (state == KEY) + bpc->count++; + + if (state == KEY && bpc->count >= 2) { + next = i - (7+2048); + bpc->count = 0; + break; + } + } + + bpc->pc.state64 = state; + if (ff_combine_frame(&bpc->pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + + return next; +} + +AVCodecParser ff_photocd_parser = { + .codec_ids = { AV_CODEC_ID_PHOTOCD }, + .priv_data_size = sizeof(PhotoCDParser), + .parser_parse = photocd_parse, + .parser_close = ff_parse_close, +};