From patchwork Mon Sep 14 15:24:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 22378 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 48DE644955E for ; Mon, 14 Sep 2020 18:24:44 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2483968B9E1; Mon, 14 Sep 2020 18:24:44 +0300 (EEST) 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 A14A368B9DE for ; Mon, 14 Sep 2020 18:24:37 +0300 (EEST) Received: by mail-ej1-f47.google.com with SMTP id u21so584287eja.2 for ; Mon, 14 Sep 2020 08:24:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=7jFP+y5aNkKBPCTpesZ34zNMuy4J8rRHH2mx+pDRW3Q=; b=f1QQq+Ez1rvYg4qlTOWCYb3iivxpDbMfi8sD3yjakMz8bpGNpLxlqq9ccvskrNA6QO nmJt2zRWgyLQMQXNQ8bkpWTZJiWtkGJJ1R02qBpKWYjKiCqXLndXcU0mLfT/MyiU/fbH wao5a+JaC7Odn5iMSabplTYQH7lJjYTWdMHe9Cl0N8ru5y8BCQZGJFVDtafExVYCjkLI +4jV2quYSHz1AK6y6TslwAtUD4QPZX7MnKOHkJB0LDudS7/7RIJmMkxqQSVHM2NIYTz1 CcnYFL6E8mPiF8nRoHVhzk5kj/4l55K5uHAvShr4FjizzbN1y9V866QBlgqbjHSkDtZS kJfg== 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=7jFP+y5aNkKBPCTpesZ34zNMuy4J8rRHH2mx+pDRW3Q=; b=Zr+dlNHSVfTlRlvzt8H4jXLYhleDuLZr+AkhhVSkJUx6OX3Qm3dfZbf4XHwmikOF8o LBRTjvAc5HwwUH0/Q4K+SA6xgrDj+DQNAyJhGGdXSIXtMU/0cDmUm8Kg4p3Hvsg1TxDE MrGMeTrEl1gwOcmh4CqqjLkOMYgunQGpo0L9oehSXxpRouvFfeFpVIQTkhy677j9JfiL ncnSvpoKyur+AHrnjAAaX5CpKJPoH4F9tKp70a652uMpG3iGSBky5n1AuekSKlQ3icsX NV4I7lJfbSNNiZSUxUMIw1dzYMMYTN5EcnsIT41gV8ot0z7QfqWA4ssp1Sz2//7kmZKJ FUdA== X-Gm-Message-State: AOAM5319Q0psd+5zBgL0VqCtApVJxoviaI0Gzw5oSOnbV9d/Cz1AXpdH PqFUXLIiK1Z/KmZY5y1FiTSOPA+aqzFFBg== X-Google-Smtp-Source: ABdhPJyYhrK8+Feb02mPbo3rPxhA3XXqurF5+ANnq88LE0uhp+UiF8aSRB1vN4VQsZ/9/HNigMcBxg== X-Received: by 2002:a17:906:a153:: with SMTP id bu19mr15071580ejb.142.1600097076648; Mon, 14 Sep 2020 08:24:36 -0700 (PDT) Received: from localhost.localdomain ([94.250.162.52]) by smtp.gmail.com with ESMTPSA id k6sm7973441ejr.104.2020.09.14.08.24.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 08:24:36 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Sep 2020 17:24:26 +0200 Message-Id: <20200914152427.26200-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec: add IPU Video decoder and 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 | 2 + libavcodec/allcodecs.c | 1 + libavcodec/codec_desc.c | 7 ++ libavcodec/codec_id.h | 1 + libavcodec/ipu_parser.c | 78 ++++++++++++++++++++ libavcodec/ipudec.c | 0 libavcodec/mpeg12dec.c | 155 ++++++++++++++++++++++++++++++++++++++++ libavcodec/parsers.c | 1 + 8 files changed, 245 insertions(+) create mode 100644 libavcodec/ipu_parser.c create mode 100644 libavcodec/ipudec.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3239a752ac..b6b743133f 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -419,6 +419,7 @@ OBJS-$(CONFIG_INDEO5_DECODER) += indeo5.o ivi.o OBJS-$(CONFIG_INTERPLAY_ACM_DECODER) += interplayacm.o OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o +OBJS-$(CONFIG_IPU_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o ass.o OBJS-$(CONFIG_JPEG2000_ENCODER) += j2kenc.o mqcenc.o mqc.o jpeg2000.o \ jpeg2000dwt.o @@ -1086,6 +1087,7 @@ OBJS-$(CONFIG_H261_PARSER) += h261_parser.o OBJS-$(CONFIG_H263_PARSER) += h263_parser.o OBJS-$(CONFIG_H264_PARSER) += h264_parser.o h264_sei.o h264data.o OBJS-$(CONFIG_HEVC_PARSER) += hevc_parser.o hevc_data.o +OBJS-$(CONFIG_IPU_PARSER) += ipu_parser.o OBJS-$(CONFIG_JPEG2000_PARSER) += jpeg2000_parser.o OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o OBJS-$(CONFIG_MLP_PARSER) += mlp_parse.o mlp_parser.o mlp.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 713c5686a4..17c88d6290 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -166,6 +166,7 @@ extern AVCodec ff_indeo3_decoder; extern AVCodec ff_indeo4_decoder; extern AVCodec ff_indeo5_decoder; extern AVCodec ff_interplay_video_decoder; +extern AVCodec ff_ipu_decoder; extern AVCodec ff_jpeg2000_encoder; extern AVCodec ff_jpeg2000_decoder; extern AVCodec ff_jpegls_encoder; diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index 9e73dcba27..002ec86fa6 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -1798,6 +1798,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("Kodak Photo CD"), .props = AV_CODEC_PROP_LOSSY, }, + { + .id = AV_CODEC_ID_IPU, + .type = AVMEDIA_TYPE_VIDEO, + .name = "ipu", + .long_name = NULL_IF_CONFIG_SMALL("IPU Video"), + .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, + }, /* various PCM "codecs" */ { diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h index e4eca5d580..e49ba1b28a 100644 --- a/libavcodec/codec_id.h +++ b/libavcodec/codec_id.h @@ -298,6 +298,7 @@ enum AVCodecID { AV_CODEC_ID_PFM, AV_CODEC_ID_MOBICLIP, AV_CODEC_ID_PHOTOCD, + AV_CODEC_ID_IPU, /* various PCM "codecs" */ AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs diff --git a/libavcodec/ipu_parser.c b/libavcodec/ipu_parser.c new file mode 100644 index 0000000000..3cc6fdd1fe --- /dev/null +++ b/libavcodec/ipu_parser.c @@ -0,0 +1,78 @@ +/* + * IPU parser + * Copyright (c) 2020 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 + * IPU parser + */ + +#include "parser.h" +#include "png.h" + +typedef struct IPUParseContext { + ParseContext pc; +} IPUParseContext; + +static int ipu_parse(AVCodecParserContext *s, AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + IPUParseContext *ipc = s->priv_data; + uint32_t state = ipc->pc.state; + int next = END_NOT_FOUND, i = 0; + + s->pict_type = AV_PICTURE_TYPE_NONE; + s->duration = 1; + + *poutbuf_size = 0; + *poutbuf = NULL; + + if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { + next = buf_size; + } else { + for (; i < buf_size; i++) { + state = (state << 8) | buf[i]; + if (state == 0x1b0) { + next = i + 1; + break; + } + } + + ipc->pc.state = state; + if (ff_combine_frame(&ipc->pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + + return next; +} + +AVCodecParser ff_ipu_parser = { + .codec_ids = { AV_CODEC_ID_IPU }, + .priv_data_size = sizeof(IPUParseContext), + .parser_parse = ipu_parse, + .parser_close = ff_parse_close, +}; diff --git a/libavcodec/ipudec.c b/libavcodec/ipudec.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index ab470187a1..1dd12196b9 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2984,3 +2984,158 @@ AVCodec ff_mpegvideo_decoder = { .flush = flush, .max_lowres = 3, }; + +typedef struct IPUContext { + MpegEncContext m; + + int flags; + DECLARE_ALIGNED(32, int16_t, block)[6][64]; +} IPUContext; + +static int ipu_decode_frame(AVCodecContext *avctx, void *data, + int *got_frame, AVPacket *avpkt) +{ + IPUContext *s = avctx->priv_data; + MpegEncContext *m = &s->m; + GetBitContext *gb = &m->gb; + AVFrame * const frame = data; + int ret; + + ret = ff_get_buffer(avctx, frame, 0); + if (ret < 0) + return ret; + + ret = init_get_bits8(gb, avpkt->data, avpkt->size); + if (ret < 0) + return ret; + + s->flags = get_bits(gb, 8); + if (!(s->flags & 0x80)) { + m->intra_dc_precision = s->flags & 3; + m->q_scale_type = !!(s->flags & 0x40); + m->intra_vlc_format = !!(s->flags & 0x20); + m->alternate_scan = !!(s->flags & 0x10); + + if (s->flags & 0x10) { + ff_init_scantable(m->idsp.idct_permutation, &m->inter_scantable, ff_alternate_vertical_scan); + ff_init_scantable(m->idsp.idct_permutation, &m->intra_scantable, ff_alternate_vertical_scan); + } else { + ff_init_scantable(m->idsp.idct_permutation, &m->inter_scantable, ff_zigzag_direct); + ff_init_scantable(m->idsp.idct_permutation, &m->intra_scantable, ff_zigzag_direct); + } + + m->last_dc[0] = m->last_dc[1] = m->last_dc[2] = 1 << (7 + (s->flags & 3)); + } + m->qscale = 1; + + for (int y = 0; y < avctx->height; y += 16) { + int intraquant; + + for (int x = 0; x < avctx->width; x += 16) { + if (x || y) { + if (!get_bits1(gb)) + return AVERROR_INVALIDDATA; + } + if (get_bits1(gb)) { + intraquant = 0; + } else { + if (!get_bits1(gb)) + return AVERROR_INVALIDDATA; + intraquant = 1; + } + + if (s->flags & 4) + skip_bits1(gb); + + if (intraquant) + m->qscale = mpeg_get_qscale(m); + + memset(s->block, 0, sizeof(s->block)); + + for (int n = 0; n < 6; n++) { + if (s->flags & 0x20) + ret = mpeg2_decode_block_intra(m, s->block[n], n); + else + ret = mpeg2_decode_block_non_intra(m, s->block[n], n); + if (ret < 0) + return ret; + } + + m->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x, + frame->linesize[0], s->block[0]); + m->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x + 8, + frame->linesize[0], s->block[1]); + m->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x, + frame->linesize[0], s->block[2]); + m->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x + 8, + frame->linesize[0], s->block[3]); + m->idsp.idct_put(frame->data[1] + (y >> 1) * frame->linesize[1] + (x >> 1), + frame->linesize[1], s->block[4]); + m->idsp.idct_put(frame->data[2] + (y >> 1) * frame->linesize[2] + (x >> 1), + frame->linesize[2], s->block[5]); + } + } + + align_get_bits(gb); + if (get_bits_left(gb) != 32) + return AVERROR_INVALIDDATA; + + frame->pict_type = AV_PICTURE_TYPE_I; + frame->key_frame = 1; + *got_frame = 1; + + return avpkt->size; +} + +static av_cold int ipu_decode_init(AVCodecContext *avctx) +{ + IPUContext *s = avctx->priv_data; + MpegEncContext *m = &s->m; + + avctx->pix_fmt = AV_PIX_FMT_YUV420P; + + ff_mpv_decode_defaults(m); + ff_mpv_decode_init(m, avctx); + s->m.avctx = avctx; + ff_mpv_idct_init(m); + ff_mpeg12_common_init(m); + ff_mpeg12_init_vlcs(); + + for (int i = 0; i < 64; i++) { + int j = m->idsp.idct_permutation[i]; + int v = ff_mpeg1_default_intra_matrix[i]; + m->intra_matrix[j] = v; + m->chroma_intra_matrix[j] = v; + } + + for (int i = 0; i < 64; i++) { + int j = m->idsp.idct_permutation[i]; + int v = ff_mpeg1_default_non_intra_matrix[i]; + m->inter_matrix[j] = v; + m->chroma_inter_matrix[j] = v; + } + + return 0; +} + +static av_cold int ipu_decode_end(AVCodecContext *avctx) +{ + IPUContext *s = avctx->priv_data; + + ff_mpv_common_end(&s->m); + + return 0; +} + +AVCodec ff_ipu_decoder = { + .name = "ipu", + .long_name = NULL_IF_CONFIG_SMALL("IPU Video"), + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_IPU, + .priv_data_size = sizeof(IPUContext), + .init = ipu_decode_init, + .decode = ipu_decode_frame, + .close = ipu_decode_end, + .capabilities = AV_CODEC_CAP_DR1, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, +}; diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index 7d75cea830..d23c603d34 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -48,6 +48,7 @@ extern AVCodecParser ff_h261_parser; extern AVCodecParser ff_h263_parser; extern AVCodecParser ff_h264_parser; extern AVCodecParser ff_hevc_parser; +extern AVCodecParser ff_ipu_parser; extern AVCodecParser ff_jpeg2000_parser; extern AVCodecParser ff_mjpeg_parser; extern AVCodecParser ff_mlp_parser; From patchwork Mon Sep 14 15:24:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 22379 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 309B644955E for ; Mon, 14 Sep 2020 18:24:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1738C68BA1F; Mon, 14 Sep 2020 18:24:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6C8B768B9DE for ; Mon, 14 Sep 2020 18:24:38 +0300 (EEST) Received: by mail-ej1-f65.google.com with SMTP id p9so545580ejf.6 for ; Mon, 14 Sep 2020 08:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=DbolpXWL609gWk3qgjVBfTqreBURBg/LDAtDlzJCWo4=; b=hfEsam3a/sDgHBqox7bWQ8BrYLe5iDU1LG5XcnTD0zllzZtD5Z/68YtDWHP/gdgXSf OJ2U1ASprqEbH7CCB60WsFvyvVrFqG1Kt8/MZEJzzVccp9N8ycSU4zxOoKA8CY+Vjxeu zU1xTRaf4kBar19Xb4f+zCU0P0Ck0O2N5MOJ5H5RGqRGk+xTibF0r+bIlcWUufGtfj1n CMwEYiRXvzWurUNIHrUrgf9UJmsT/muBnigMuFOGvjgiWYh2GacmTshfC9QA6vlyX7VU j3eoV/X6Ioj19DIICBlNJiyEL3GG58NSj1laXwQharaGWIAUco6oEOjPi/Gx3QNn2Xta BgoQ== 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:in-reply-to :references; bh=DbolpXWL609gWk3qgjVBfTqreBURBg/LDAtDlzJCWo4=; b=RCXv95gqsi5xZPd+ozTrxisHoZL8w5NLNwnjfW+ShljS4W5H1JUWHoekXbf73xqfwd dy/fh4EATh5WMjlYaSIuHTy4LbD6Py7PEmxdKZWtkr8JRa8BHEmkKQvWqtBF6xfRp5DT Lk9taEf29GqgjQDEUarXXOYkXp9QjwYZCYnMzUDhheYKi6mi6U+ncch1tLWjC/8p+jtB 3YVb4yNigsLLPGngckBMihKlv7uRqHuBWLObCSfeyz2XDW4WsMXsseFaeqYXaxmFkkKf u/zUF2WMY7gBzugVybsKE9YcSeMYo5pPltNIsR1ClahKxl7Sezh992x77IhHfRkgqrNt dI9A== X-Gm-Message-State: AOAM530gfD7kuP2WkjyMIDlpAJY748ueRdpUZbGlEkyzAhWIg9uzL8t0 K3dEoXccgw0LaihTyiVEvFf72Ua41Euzug== X-Google-Smtp-Source: ABdhPJz1a/sg3JatdRxGUpmeoOUzEQthyqJWZ3UilgSHtwaPgsO53uEa2TYM3WjHOYM0qCulQTt0cA== X-Received: by 2002:a17:906:cf9d:: with SMTP id um29mr15086984ejb.74.1600097077675; Mon, 14 Sep 2020 08:24:37 -0700 (PDT) Received: from localhost.localdomain ([94.250.162.52]) by smtp.gmail.com with ESMTPSA id k6sm7973441ejr.104.2020.09.14.08.24.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 08:24:37 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Sep 2020 17:24:27 +0200 Message-Id: <20200914152427.26200-2-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200914152427.26200-1-onemda@gmail.com> References: <20200914152427.26200-1-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] avformat: add IPU demuxer 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 --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/ipudec.c | 89 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 libavformat/ipudec.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 992d89a45f..213004cb45 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -278,6 +278,7 @@ OBJS-$(CONFIG_IMAGE_XPM_PIPE_DEMUXER) += img2dec.o img2.o OBJS-$(CONFIG_IMAGE_XWD_PIPE_DEMUXER) += img2dec.o img2.o OBJS-$(CONFIG_INGENIENT_DEMUXER) += ingenientdec.o rawdec.o OBJS-$(CONFIG_IPMOVIE_DEMUXER) += ipmovie.o +OBJS-$(CONFIG_IPU_DEMUXER) += ipudec.o OBJS-$(CONFIG_IRCAM_DEMUXER) += ircamdec.o ircam.o pcm.o OBJS-$(CONFIG_IRCAM_MUXER) += ircamenc.o ircam.o rawenc.o OBJS-$(CONFIG_ISS_DEMUXER) += iss.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index ac154a3f31..2946a80dd7 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -210,6 +210,7 @@ extern AVInputFormat ff_image2_alias_pix_demuxer; extern AVInputFormat ff_image2_brender_pix_demuxer; extern AVInputFormat ff_ingenient_demuxer; extern AVInputFormat ff_ipmovie_demuxer; +extern AVInputFormat ff_ipu_demuxer; extern AVOutputFormat ff_ipod_muxer; extern AVInputFormat ff_ircam_demuxer; extern AVOutputFormat ff_ircam_muxer; diff --git a/libavformat/ipudec.c b/libavformat/ipudec.c new file mode 100644 index 0000000000..df53df00d9 --- /dev/null +++ b/libavformat/ipudec.c @@ -0,0 +1,89 @@ +/* + * IPU video demuxer + * Copyright (c) 2020 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 + */ + +#include "avformat.h" +#include "internal.h" +#include "avio_internal.h" +#include "rawdec.h" + +#include "libavutil/intreadwrite.h" +#include "libavcodec/internal.h" + +static int ipu_read_probe(const AVProbeData *p) +{ + if (AV_RB32(p->buf) != MKBETAG('i', 'p', 'u', 'm')) + return 0; + + if (AV_RL32(p->buf + 4) == 0) + return 0; + + if (AV_RL16(p->buf + 8) == 0) + return 0; + + if (AV_RL16(p->buf + 10) == 0) + return 0; + + if (AV_RL32(p->buf + 12) == 0) + return 0; + + return AVPROBE_SCORE_MAX; +} + +static int ipu_read_header(AVFormatContext *s) +{ + AVIOContext *pb = s->pb; + AVStream *st = avformat_new_stream(s, NULL); + + if (!st) + return AVERROR(ENOMEM); + avio_skip(pb, 8); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_IPU; + st->codecpar->width = avio_rl16(pb); + st->codecpar->height = avio_rl16(pb); + st->start_time = 0; + st->duration = + st->nb_frames = avio_rl32(pb); + st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + avpriv_set_pts_info(st, 64, 1, 25); + + return 0; +} + +static const AVClass ipu_demuxer_class = { + .class_name = "ipu demuxer", + .item_name = av_default_item_name, + .option = ff_raw_options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVInputFormat ff_ipu_demuxer = { + .name = "ipu", + .long_name = NULL_IF_CONFIG_SMALL("raw IPU Video"), + .read_probe = ipu_read_probe, + .read_header = ipu_read_header, + .read_packet = ff_raw_read_partial_packet, + .extensions = "ipu", + .flags = AVFMT_GENERIC_INDEX, + .raw_codec_id = AV_CODEC_ID_IPU, + .priv_data_size = sizeof(FFRawDemuxerContext), + .priv_class = &ipu_demuxer_class, +};