1/* 2 * IPU video demuxer 3 * Copyright (c) 2020 Paul B Mahol 4 * 5 * This file is part of FFmpeg. 6 * 7 * FFmpeg is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * FFmpeg is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with FFmpeg; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22#include "avformat.h" 23#include "internal.h" 24#include "avio_internal.h" 25#include "rawdec.h" 26 27#include "libavutil/intreadwrite.h" 28 29static int ipu_read_probe(const AVProbeData *p) 30{ 31 if (AV_RB32(p->buf) != MKBETAG('i', 'p', 'u', 'm')) 32 return 0; 33 34 if (AV_RL32(p->buf + 4) == 0) 35 return 0; 36 37 if (AV_RL16(p->buf + 8) == 0) 38 return 0; 39 40 if (AV_RL16(p->buf + 10) == 0) 41 return 0; 42 43 if (AV_RL32(p->buf + 12) == 0) 44 return 0; 45 46 return AVPROBE_SCORE_MAX; 47} 48 49static int ipu_read_header(AVFormatContext *s) 50{ 51 AVIOContext *pb = s->pb; 52 AVStream *st = avformat_new_stream(s, NULL); 53 54 if (!st) 55 return AVERROR(ENOMEM); 56 avio_skip(pb, 8); 57 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; 58 st->codecpar->codec_id = AV_CODEC_ID_IPU; 59 st->codecpar->width = avio_rl16(pb); 60 st->codecpar->height = avio_rl16(pb); 61 st->start_time = 0; 62 st->duration = 63 st->nb_frames = avio_rl32(pb); 64 ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; 65 avpriv_set_pts_info(st, 64, 1, 25); 66 67 return 0; 68} 69 70static const AVClass ipu_demuxer_class = { 71 .class_name = "ipu demuxer", 72 .item_name = av_default_item_name, 73 .option = ff_raw_options, 74 .version = LIBAVUTIL_VERSION_INT, 75}; 76 77const AVInputFormat ff_ipu_demuxer = { 78 .name = "ipu", 79 .long_name = NULL_IF_CONFIG_SMALL("raw IPU Video"), 80 .read_probe = ipu_read_probe, 81 .read_header = ipu_read_header, 82 .read_packet = ff_raw_read_partial_packet, 83 .extensions = "ipu", 84 .flags = AVFMT_GENERIC_INDEX, 85 .raw_codec_id = AV_CODEC_ID_IPU, 86 .priv_data_size = sizeof(FFRawDemuxerContext), 87 .priv_class = &ff_raw_demuxer_class, 88}; 89