LCOV - code coverage report
Current view: top level - libavcodec - eac3_core_bsf.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 12 32 37.5 %
Date: 2018-05-20 11:54:08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2018 Paul B Mahol
       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 "avcodec.h"
      22             : #include "bsf.h"
      23             : #include "get_bits.h"
      24             : #include "ac3_parser_internal.h"
      25             : 
      26         314 : static int eac3_core_filter(AVBSFContext *ctx, AVPacket *pkt)
      27             : {
      28             :     AC3HeaderInfo hdr;
      29             :     GetBitContext gbc;
      30             :     int ret;
      31             : 
      32         314 :     ret = ff_bsf_get_packet_ref(ctx, pkt);
      33         314 :     if (ret < 0)
      34         157 :         return ret;
      35         157 :     ret = init_get_bits8(&gbc, pkt->data, pkt->size);
      36         157 :     if (ret < 0)
      37           0 :         goto fail;
      38             : 
      39         157 :     ret = ff_ac3_parse_header(&gbc, &hdr);
      40         157 :     if (ret < 0) {
      41           0 :         ret = AVERROR_INVALIDDATA;
      42           0 :         goto fail;
      43             :     }
      44             : 
      45         314 :     if (hdr.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
      46         157 :         hdr.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
      47         157 :         pkt->size = FFMIN(hdr.frame_size, pkt->size);
      48           0 :     } else if (hdr.frame_type == EAC3_FRAME_TYPE_DEPENDENT && pkt->size > hdr.frame_size) {
      49             :         AC3HeaderInfo hdr2;
      50             : 
      51           0 :         ret = init_get_bits8(&gbc, pkt->data + hdr.frame_size, pkt->size - hdr.frame_size);
      52           0 :         if (ret < 0)
      53           0 :             goto fail;
      54             : 
      55           0 :         ret = ff_ac3_parse_header(&gbc, &hdr2);
      56           0 :         if (ret < 0) {
      57           0 :             ret = AVERROR_INVALIDDATA;
      58           0 :             goto fail;
      59             :         }
      60             : 
      61           0 :         if (hdr2.frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
      62           0 :             hdr2.frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
      63           0 :             pkt->size -= hdr.frame_size;
      64           0 :             pkt->data += hdr.frame_size;
      65             :         } else {
      66           0 :             pkt->size = 0;
      67             :         }
      68             :     } else {
      69           0 :         pkt->size = 0;
      70             :     }
      71             : 
      72         157 :     return 0;
      73           0 : fail:
      74           0 :     av_packet_unref(pkt);
      75           0 :     return ret;
      76             : }
      77             : 
      78             : static const enum AVCodecID codec_ids[] = {
      79             :     AV_CODEC_ID_EAC3, AV_CODEC_ID_NONE,
      80             : };
      81             : 
      82             : const AVBitStreamFilter ff_eac3_core_bsf = {
      83             :     .name      = "eac3_core",
      84             :     .filter    = eac3_core_filter,
      85             :     .codec_ids = codec_ids,
      86             : };

Generated by: LCOV version 1.13