LCOV - code coverage report
Current view: top level - libavformat - frmdec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 38 10.5 %
Date: 2017-12-16 13:57:32 Functions: 1 3 33.3 %

          Line data    Source code
       1             : /*
       2             :  * Megalux Frame demuxer
       3             :  * Copyright (c) 2010 Peter Ross <pross@xvid.org>
       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             : /**
      23             :  * @file
      24             :  * Megalux Frame demuxer
      25             :  */
      26             : 
      27             : #include "libavcodec/raw.h"
      28             : #include "libavutil/imgutils.h"
      29             : #include "libavutil/intreadwrite.h"
      30             : #include "avformat.h"
      31             : 
      32             : static const PixelFormatTag frm_pix_fmt_tags[] = {
      33             :     { AV_PIX_FMT_RGB555, 1 },
      34             :     { AV_PIX_FMT_RGB0,   2 },
      35             :     { AV_PIX_FMT_RGB24,  3 },
      36             :     { AV_PIX_FMT_BGR0,   4 },
      37             :     { AV_PIX_FMT_BGRA,   5 },
      38             :     { AV_PIX_FMT_NONE,   0 },
      39             : };
      40             : 
      41             : typedef struct {
      42             :     int count;
      43             : } FrmContext;
      44             : 
      45        6130 : static int frm_read_probe(AVProbeData *p)
      46             : {
      47       12260 :     if (p->buf_size > 8 &&
      48        6178 :         p->buf[0] == 'F' && p->buf[1] == 'R' && p->buf[2] == 'M' &&
      49           0 :         AV_RL16(&p->buf[4]) && AV_RL16(&p->buf[6]))
      50           0 :         return AVPROBE_SCORE_MAX / 4;
      51        6130 :     return 0;
      52             : }
      53             : 
      54           0 : static int frm_read_header(AVFormatContext *avctx)
      55             : {
      56           0 :     AVIOContext *pb = avctx->pb;
      57           0 :     AVStream *st = avformat_new_stream(avctx, 0);
      58           0 :     if (!st)
      59           0 :         return AVERROR(ENOMEM);
      60             : 
      61           0 :     st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
      62           0 :     st->codecpar->codec_id   = AV_CODEC_ID_RAWVIDEO;
      63           0 :     avio_skip(pb, 3);
      64             : 
      65           0 :     st->codecpar->format    = avpriv_find_pix_fmt(frm_pix_fmt_tags, avio_r8(pb));
      66           0 :     if (!st->codecpar->format)
      67           0 :         return AVERROR_INVALIDDATA;
      68             : 
      69           0 :     st->codecpar->codec_tag  = 0;
      70           0 :     st->codecpar->width      = avio_rl16(pb);
      71           0 :     st->codecpar->height     = avio_rl16(pb);
      72           0 :     return 0;
      73             : }
      74             : 
      75           0 : static int frm_read_packet(AVFormatContext *avctx, AVPacket *pkt)
      76             : {
      77           0 :     FrmContext *s = avctx->priv_data;
      78           0 :     AVCodecParameters *par = avctx->streams[0]->codecpar;
      79             :     int packet_size, ret;
      80             : 
      81           0 :     if (s->count)
      82           0 :         return AVERROR_EOF;
      83             : 
      84           0 :     packet_size = av_image_get_buffer_size(par->format, par->width, par->height, 1);
      85           0 :     if (packet_size < 0)
      86           0 :         return AVERROR_INVALIDDATA;
      87             : 
      88           0 :     ret = av_get_packet(avctx->pb, pkt, packet_size);
      89           0 :     if (ret < 0)
      90           0 :         return ret;
      91             : 
      92           0 :     if (par->format == AV_PIX_FMT_BGRA) {
      93             :         int i;
      94           0 :         for (i = 3; i + 1 <= pkt->size; i += 4)
      95           0 :             pkt->data[i] = 0xFF - pkt->data[i];
      96             :     }
      97             : 
      98           0 :     pkt->stream_index = 0;
      99           0 :     s->count++;
     100             : 
     101           0 :     return 0;
     102             : }
     103             : 
     104             : AVInputFormat ff_frm_demuxer = {
     105             :     .name           = "frm",
     106             :     .priv_data_size = sizeof(FrmContext),
     107             :     .long_name      = NULL_IF_CONFIG_SMALL("Megalux Frame"),
     108             :     .read_probe     = frm_read_probe,
     109             :     .read_header    = frm_read_header,
     110             :     .read_packet    = frm_read_packet,
     111             : };

Generated by: LCOV version 1.13