LCOV - code coverage report
Current view: top level - libavformat - supenc.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 30 0.0 %
Date: 2017-12-16 13:57:32 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  * SUP muxer
       3             :  * Copyright (c) 2014 Petri Hintukainen <phintuka@users.sourceforge.net>
       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 "libavutil/intreadwrite.h"
      25             : 
      26             : #define SUP_PGS_MAGIC 0x5047 /* "PG", big endian */
      27             : 
      28           0 : static int sup_write_packet(AVFormatContext *s, AVPacket *pkt)
      29             : {
      30           0 :     uint8_t *data = pkt->data;
      31           0 :     size_t size = pkt->size;
      32           0 :     uint32_t pts = 0, dts = 0;
      33             : 
      34           0 :     if (pkt->pts != AV_NOPTS_VALUE) {
      35           0 :         pts = (uint32_t)pkt->pts;
      36             :     }
      37           0 :     if (pkt->dts != AV_NOPTS_VALUE) {
      38           0 :         dts = (uint32_t)pkt->dts;
      39             :     }
      40             : 
      41             :     /*
      42             :       Split frame to segments.
      43             :       mkvmerge stores multiple segments in one frame.
      44             :     */
      45           0 :     while (size > 2) {
      46           0 :         size_t len = AV_RB16(data + 1) + 3;
      47             : 
      48           0 :         if (len > size) {
      49           0 :             av_log(s, AV_LOG_ERROR, "Not enough data, skipping %d bytes\n",
      50             :                      (int)size);
      51           0 :             return AVERROR_INVALIDDATA;
      52             :         }
      53             : 
      54             :         /* header */
      55           0 :         avio_wb16(s->pb, SUP_PGS_MAGIC);
      56           0 :         avio_wb32(s->pb, pts);
      57           0 :         avio_wb32(s->pb, dts);
      58             : 
      59           0 :         avio_write(s->pb, data, len);
      60             : 
      61           0 :         data += len;
      62           0 :         size -= len;
      63             :     }
      64             : 
      65           0 :     if (size > 0) {
      66           0 :         av_log(s, AV_LOG_ERROR, "Skipping %d bytes after last segment in frame\n",
      67             :                  (int)size);
      68           0 :         return AVERROR_INVALIDDATA;
      69             :     }
      70             : 
      71           0 :     return 0;
      72             : }
      73             : 
      74           0 : static int sup_write_header(AVFormatContext *s)
      75             : {
      76           0 :     if (s->nb_streams != 1) {
      77           0 :         av_log(s, AV_LOG_ERROR, "%s files have exactly one stream\n",
      78           0 :                s->oformat->name);
      79           0 :         return AVERROR(EINVAL);
      80             :     }
      81             : 
      82           0 :     avpriv_set_pts_info(s->streams[0], 32, 1, 90000);
      83             : 
      84           0 :     return 0;
      85             : }
      86             : 
      87             : AVOutputFormat ff_sup_muxer = {
      88             :     .name           = "sup",
      89             :     .long_name      = NULL_IF_CONFIG_SMALL("raw HDMV Presentation Graphic Stream subtitles"),
      90             :     .extensions     = "sup",
      91             :     .mime_type      = "application/x-pgs",
      92             :     .subtitle_codec = AV_CODEC_ID_HDMV_PGS_SUBTITLE,
      93             :     .write_header   = sup_write_header,
      94             :     .write_packet   = sup_write_packet,
      95             :     .flags          = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
      96             : };

Generated by: LCOV version 1.13