LCOV - code coverage report
Current view: top level - libavformat - rtpdec_svq3.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 36 0.0 %
Date: 2017-12-11 04:34:20 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Sorenson-3 (SVQ3/SV3V) payload for RTP
       3             :  * Copyright (c) 2010 Ronald S. Bultje
       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             :  * @brief RTP support for the SV3V (SVQ3) payload
      25             :  * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
      26             :  * @see http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization
      27             :  */
      28             : 
      29             : #include <string.h>
      30             : #include "libavutil/intreadwrite.h"
      31             : #include "avio_internal.h"
      32             : #include "internal.h"
      33             : #include "rtp.h"
      34             : #include "rtpdec.h"
      35             : #include "rtpdec_formats.h"
      36             : 
      37             : struct PayloadContext {
      38             :     AVIOContext *pktbuf;
      39             :     int64_t        timestamp;
      40             : };
      41             : 
      42             : /** return 0 on packet, <0 on partial packet or error... */
      43           0 : static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv,
      44             :                               AVStream *st, AVPacket *pkt,
      45             :                               uint32_t *timestamp,
      46             :                               const uint8_t *buf, int len, uint16_t seq,
      47             :                               int flags)
      48             : {
      49             :     int config_packet, start_packet, end_packet;
      50             : 
      51           0 :     if (len < 2)
      52           0 :         return AVERROR_INVALIDDATA;
      53             : 
      54           0 :     config_packet = buf[0] & 0x40;
      55           0 :     start_packet  = buf[0] & 0x20;
      56           0 :     end_packet    = buf[0] & 0x10;
      57           0 :     buf += 2;     // ignore buf[1]
      58           0 :     len -= 2;
      59             : 
      60           0 :     if (config_packet) {
      61             : 
      62           0 :         av_freep(&st->codecpar->extradata);
      63           0 :         st->codecpar->extradata_size = 0;
      64             : 
      65           0 :         if (len < 2 || ff_alloc_extradata(st->codecpar, len + 8))
      66           0 :             return AVERROR_INVALIDDATA;
      67             : 
      68           0 :         memcpy(st->codecpar->extradata, "SEQH", 4);
      69           0 :         AV_WB32(st->codecpar->extradata + 4, len);
      70           0 :         memcpy(st->codecpar->extradata + 8, buf, len);
      71             : 
      72             :         /* We set codec_id to AV_CODEC_ID_NONE initially to
      73             :          * delay decoder initialization since extradata is
      74             :          * carried within the RTP stream, not SDP. Here,
      75             :          * by setting codec_id to AV_CODEC_ID_SVQ3, we are signalling
      76             :          * to the decoder that it is OK to initialize. */
      77           0 :         st->codecpar->codec_id = AV_CODEC_ID_SVQ3;
      78             : 
      79           0 :         return AVERROR(EAGAIN);
      80             :     }
      81             : 
      82           0 :     if (start_packet) {
      83             :         int res;
      84             : 
      85           0 :         ffio_free_dyn_buf(&sv->pktbuf);
      86           0 :         if ((res = avio_open_dyn_buf(&sv->pktbuf)) < 0)
      87           0 :             return res;
      88           0 :         sv->timestamp   = *timestamp;
      89             :     }
      90             : 
      91           0 :     if (!sv->pktbuf)
      92           0 :         return AVERROR_INVALIDDATA;
      93             : 
      94           0 :     avio_write(sv->pktbuf, buf, len);
      95             : 
      96           0 :     if (end_packet) {
      97           0 :         int ret = ff_rtp_finalize_packet(pkt, &sv->pktbuf, st->index);
      98           0 :         if (ret < 0)
      99           0 :             return ret;
     100             : 
     101           0 :         *timestamp        = sv->timestamp;
     102           0 :         return 0;
     103             :     }
     104             : 
     105           0 :     return AVERROR(EAGAIN);
     106             : }
     107             : 
     108           0 : static void svq3_close_context(PayloadContext *sv)
     109             : {
     110           0 :     ffio_free_dyn_buf(&sv->pktbuf);
     111           0 : }
     112             : 
     113             : RTPDynamicProtocolHandler ff_svq3_dynamic_handler = {
     114             :     .enc_name         = "X-SV3V-ES",
     115             :     .codec_type       = AVMEDIA_TYPE_VIDEO,
     116             :     .codec_id         = AV_CODEC_ID_NONE,      // see if (config_packet) above
     117             :     .priv_data_size   = sizeof(PayloadContext),
     118             :     .close            = svq3_close_context,
     119             :     .parse_packet     = svq3_parse_packet,
     120             : };

Generated by: LCOV version 1.13