LCOV - code coverage report
Current view: top level - libavformat - rawdec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 65 83 78.3 %
Date: 2017-12-17 04:34:43 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /*
       2             :  * RAW demuxers
       3             :  * Copyright (c) 2001 Fabrice Bellard
       4             :  * Copyright (c) 2005 Alex Beregszaszi
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : #include "avformat.h"
      24             : #include "internal.h"
      25             : #include "avio_internal.h"
      26             : #include "rawdec.h"
      27             : #include "libavutil/opt.h"
      28             : #include "libavutil/parseutils.h"
      29             : #include "libavutil/pixdesc.h"
      30             : #include "libavutil/avassert.h"
      31             : #include "libavutil/intreadwrite.h"
      32             : 
      33             : #define RAW_PACKET_SIZE 1024
      34             : 
      35      484043 : int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
      36             : {
      37             :     int ret, size;
      38             : 
      39      484043 :     size = RAW_PACKET_SIZE;
      40             : 
      41      484043 :     if (av_new_packet(pkt, size) < 0)
      42           0 :         return AVERROR(ENOMEM);
      43             : 
      44      484043 :     pkt->pos= avio_tell(s->pb);
      45      484043 :     pkt->stream_index = 0;
      46      484043 :     ret = avio_read_partial(s->pb, pkt->data, size);
      47      484043 :     if (ret < 0) {
      48        2121 :         av_packet_unref(pkt);
      49        2121 :         return ret;
      50             :     }
      51      481922 :     av_shrink_packet(pkt, ret);
      52      481922 :     return ret;
      53             : }
      54             : 
      55          25 : int ff_raw_audio_read_header(AVFormatContext *s)
      56             : {
      57          25 :     AVStream *st = avformat_new_stream(s, NULL);
      58          25 :     if (!st)
      59           0 :         return AVERROR(ENOMEM);
      60          25 :     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
      61          25 :     st->codecpar->codec_id = s->iformat->raw_codec_id;
      62          25 :     st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
      63          25 :     st->start_time = 0;
      64             :     /* the parameters will be extracted from the compressed bitstream */
      65             : 
      66          25 :     return 0;
      67             : }
      68             : 
      69             : /* MPEG-1/H.263 input */
      70         509 : int ff_raw_video_read_header(AVFormatContext *s)
      71             : {
      72             :     AVStream *st;
      73         509 :     FFRawVideoDemuxerContext *s1 = s->priv_data;
      74         509 :     int ret = 0;
      75             : 
      76             : 
      77         509 :     st = avformat_new_stream(s, NULL);
      78         509 :     if (!st) {
      79           0 :         ret = AVERROR(ENOMEM);
      80           0 :         goto fail;
      81             :     }
      82             : 
      83         509 :     st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
      84         509 :     st->codecpar->codec_id = s->iformat->raw_codec_id;
      85         509 :     st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
      86             : 
      87         509 :     st->internal->avctx->framerate = s1->framerate;
      88         509 :     avpriv_set_pts_info(st, 64, 1, 1200000);
      89             : 
      90         509 : fail:
      91         509 :     return ret;
      92             : }
      93             : 
      94           0 : int ff_raw_data_read_header(AVFormatContext *s)
      95             : {
      96           0 :     AVStream *st = avformat_new_stream(s, NULL);
      97           0 :     if (!st)
      98           0 :         return AVERROR(ENOMEM);
      99           0 :     st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
     100           0 :     st->codecpar->codec_id = s->iformat->raw_codec_id;
     101           0 :     st->start_time = 0;
     102           0 :     return 0;
     103             : }
     104             : 
     105             : /* Note: Do not forget to add new entries to the Makefile as well. */
     106             : 
     107             : #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
     108             : #define DEC AV_OPT_FLAG_DECODING_PARAM
     109             : const AVOption ff_rawvideo_options[] = {
     110             :     { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC},
     111             :     { NULL },
     112             : };
     113             : 
     114             : #if CONFIG_DATA_DEMUXER
     115             : AVInputFormat ff_data_demuxer = {
     116             :     .name           = "data",
     117             :     .long_name      = NULL_IF_CONFIG_SMALL("raw data"),
     118             :     .read_header    = ff_raw_data_read_header,
     119             :     .read_packet    = ff_raw_read_partial_packet,
     120             :     .raw_codec_id   = AV_CODEC_ID_NONE,
     121             :     .flags          = AVFMT_NOTIMESTAMPS,
     122             : };
     123             : #endif
     124             : 
     125             : #if CONFIG_MJPEG_DEMUXER
     126        6130 : static int mjpeg_probe(AVProbeData *p)
     127             : {
     128             :     int i;
     129        6130 :     int state = -1;
     130        6130 :     int nb_invalid = 0;
     131        6130 :     int nb_frames = 0;
     132             : 
     133   128268535 :     for (i=0; i<p->buf_size-2; i++) {
     134             :         int c;
     135   128262405 :         if (p->buf[i] != 0xFF)
     136   126017907 :             continue;
     137     2244498 :         c = p->buf[i+1];
     138     2244498 :         switch (c) {
     139       33847 :         case 0xD8:
     140       33847 :             state = 0xD8;
     141       33847 :             break;
     142       58964 :         case 0xC0:
     143             :         case 0xC1:
     144             :         case 0xC2:
     145             :         case 0xC3:
     146             :         case 0xC5:
     147             :         case 0xC6:
     148             :         case 0xC7:
     149             :         case 0xF7:
     150       58964 :             if (state == 0xD8) {
     151       16129 :                 state = 0xC0;
     152             :             } else
     153       42835 :                 nb_invalid++;
     154       58964 :             break;
     155       17158 :         case 0xDA:
     156       17158 :             if (state == 0xC0) {
     157        5340 :                 state = 0xDA;
     158             :             } else
     159       11818 :                 nb_invalid++;
     160       17158 :             break;
     161       14492 :         case 0xD9:
     162       14492 :             if (state == 0xDA) {
     163        1793 :                 state = 0xD9;
     164        1793 :                 nb_frames++;
     165             :             } else
     166       12699 :                 nb_invalid++;
     167       14492 :             break;
     168     2120037 :         default:
     169     2120037 :             if (  (c >= 0x02 && c <= 0xBF)
     170     1008641 :                 || c == 0xC8) {
     171     1117253 :                 nb_invalid++;
     172             :             }
     173             :         }
     174             :     }
     175             : 
     176        6130 :     if (nb_invalid*4 + 1 < nb_frames) {
     177             :         static const char ct_jpeg[] = "\r\nContent-Type: image/jpeg\r\n";
     178             :         int i;
     179             : 
     180           0 :         for (i=0; i<FFMIN(p->buf_size - (int)sizeof(ct_jpeg), 100); i++)
     181           0 :             if (!memcmp(p->buf + i, ct_jpeg, sizeof(ct_jpeg) - 1))
     182           0 :                 return AVPROBE_SCORE_EXTENSION;
     183             : 
     184           0 :         if (nb_invalid == 0 && nb_frames > 2)
     185           0 :             return AVPROBE_SCORE_EXTENSION / 2;
     186           0 :         return AVPROBE_SCORE_EXTENSION / 4;
     187             :     }
     188             : 
     189        6130 :     return 0;
     190             : }
     191             : 
     192             : FF_DEF_RAWVIDEO_DEMUXER2(mjpeg, "raw MJPEG video", mjpeg_probe, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG, AVFMT_GENERIC_INDEX|AVFMT_NOTIMESTAMPS)
     193             : #endif

Generated by: LCOV version 1.13