LCOV - code coverage report
Current view: top level - libavformat - oggparsedirac.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 56 0.0 %
Date: 2017-12-16 21:16:39 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2008  David Conrad
       3             :  *
       4             :  * This file is part of FFmpeg.
       5             :  *
       6             :  * FFmpeg is free software; you can redistribute it and/or
       7             :  * modify it under the terms of the GNU Lesser General Public
       8             :  * License as published by the Free Software Foundation; either
       9             :  * version 2.1 of the License, or (at your option) any later version.
      10             :  *
      11             :  * FFmpeg is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public
      17             :  * License along with FFmpeg; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : 
      21             : #include "libavutil/imgutils.h"
      22             : #include "libavutil/intreadwrite.h"
      23             : #include "libavcodec/dirac.h"
      24             : #include "avformat.h"
      25             : #include "internal.h"
      26             : #include "oggdec.h"
      27             : 
      28           0 : static int dirac_header(AVFormatContext *s, int idx)
      29             : {
      30           0 :     struct ogg *ogg = s->priv_data;
      31           0 :     struct ogg_stream *os = ogg->streams + idx;
      32           0 :     AVStream *st = s->streams[idx];
      33             :     AVDiracSeqHeader *dsh;
      34             :     int ret;
      35             : 
      36             :     // already parsed the header
      37           0 :     if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC)
      38           0 :         return 0;
      39             : 
      40           0 :     ret = av_dirac_parse_sequence_header(&dsh, os->buf + os->pstart + 13, (os->psize - 13), s);
      41           0 :     if (ret < 0)
      42           0 :         return ret;
      43             : 
      44           0 :     st->codecpar->codec_type      = AVMEDIA_TYPE_VIDEO;
      45           0 :     st->codecpar->codec_id        = AV_CODEC_ID_DIRAC;
      46           0 :     st->codecpar->width           = dsh->width;
      47           0 :     st->codecpar->height          = dsh->height;
      48           0 :     st->codecpar->format          = dsh->pix_fmt;
      49           0 :     st->codecpar->color_range     = dsh->color_range;
      50           0 :     st->codecpar->color_trc       = dsh->color_trc;
      51           0 :     st->codecpar->color_primaries = dsh->color_primaries;
      52           0 :     st->codecpar->color_space     = dsh->colorspace;
      53           0 :     st->codecpar->profile         = dsh->profile;
      54           0 :     st->codecpar->level           = dsh->level;
      55           0 :     if (av_image_check_sar(st->codecpar->width, st->codecpar->height, dsh->sample_aspect_ratio) >= 0)
      56           0 :         st->sample_aspect_ratio = dsh->sample_aspect_ratio;
      57             : 
      58             :     // Dirac in Ogg always stores timestamps as though the video were interlaced
      59           0 :     avpriv_set_pts_info(st, 64, dsh->framerate.den, 2 * dsh->framerate.num);
      60             : 
      61           0 :     av_freep(&dsh);
      62           0 :     return 1;
      63             : }
      64             : 
      65             : // various undocumented things: granule is signed (only for Dirac!)
      66           0 : static uint64_t dirac_gptopts(AVFormatContext *s, int idx, uint64_t granule,
      67             :                               int64_t *dts_out)
      68             : {
      69           0 :     int64_t gp = granule;
      70           0 :     struct ogg *ogg = s->priv_data;
      71           0 :     struct ogg_stream *os = ogg->streams + idx;
      72             : 
      73           0 :     unsigned dist  = ((gp >> 14) & 0xff00) | (gp & 0xff);
      74           0 :     int64_t  dts   = (gp >> 31);
      75           0 :     int64_t  pts   = dts + ((gp >> 9) & 0x1fff);
      76             : 
      77           0 :     if (!dist)
      78           0 :         os->pflags |= AV_PKT_FLAG_KEY;
      79             : 
      80           0 :     if (dts_out)
      81           0 :         *dts_out = dts;
      82             : 
      83           0 :     return pts;
      84             : }
      85             : 
      86           0 : static int old_dirac_header(AVFormatContext *s, int idx)
      87             : {
      88           0 :     struct ogg *ogg = s->priv_data;
      89           0 :     struct ogg_stream *os = ogg->streams + idx;
      90           0 :     AVStream *st = s->streams[idx];
      91           0 :     uint8_t *buf = os->buf + os->pstart;
      92             : 
      93           0 :     if (buf[0] != 'K')
      94           0 :         return 0;
      95             : 
      96           0 :     st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
      97           0 :     st->codecpar->codec_id = AV_CODEC_ID_DIRAC;
      98           0 :     avpriv_set_pts_info(st, 64, AV_RB32(buf+12), AV_RB32(buf+8));
      99           0 :     return 1;
     100             : }
     101             : 
     102           0 : static uint64_t old_dirac_gptopts(AVFormatContext *s, int idx, uint64_t gp,
     103             :                                   int64_t *dts)
     104             : {
     105           0 :     struct ogg *ogg = s->priv_data;
     106           0 :     struct ogg_stream *os = ogg->streams + idx;
     107           0 :     uint64_t iframe = gp >> 30;
     108           0 :     uint64_t pframe = gp & 0x3fffffff;
     109             : 
     110           0 :     if (!pframe)
     111           0 :         os->pflags |= AV_PKT_FLAG_KEY;
     112             : 
     113           0 :     return iframe + pframe;
     114             : }
     115             : 
     116             : const struct ogg_codec ff_dirac_codec = {
     117             :     .magic = "BBCD\0",
     118             :     .magicsize = 5,
     119             :     .header = dirac_header,
     120             :     .gptopts = dirac_gptopts,
     121             :     .granule_is_start = 1,
     122             :     .nb_header = 1,
     123             : };
     124             : 
     125             : const struct ogg_codec ff_old_dirac_codec = {
     126             :     .magic = "KW-DIRAC",
     127             :     .magicsize = 8,
     128             :     .header = old_dirac_header,
     129             :     .gptopts = old_dirac_gptopts,
     130             :     .granule_is_start = 1,
     131             :     .nb_header = 1,
     132             : };

Generated by: LCOV version 1.13