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

          Line data    Source code
       1             : /*
       2             :  * This file is part of FFmpeg.
       3             :  *
       4             :  * FFmpeg is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Lesser General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2.1 of the License, or (at your option) any later version.
       8             :  *
       9             :  * FFmpeg is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Lesser General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public
      15             :  * License along with FFmpeg; if not, write to the Free Software
      16             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      17             :  */
      18             : 
      19             : #include <stdio.h>
      20             : 
      21             : #include "libavutil/avstring.h"
      22             : #include "libavutil/common.h"
      23             : #include "libavutil/log.h"
      24             : 
      25             : #include "bsf.h"
      26             : #include "cbs.h"
      27             : 
      28             : 
      29             : typedef struct TraceHeadersContext {
      30             :     CodedBitstreamContext *cbc;
      31             : } TraceHeadersContext;
      32             : 
      33             : 
      34           0 : static int trace_headers_init(AVBSFContext *bsf)
      35             : {
      36           0 :     TraceHeadersContext *ctx = bsf->priv_data;
      37             :     int err;
      38             : 
      39           0 :     err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
      40           0 :     if (err < 0)
      41           0 :         return err;
      42             : 
      43           0 :     ctx->cbc->trace_enable = 1;
      44           0 :     ctx->cbc->trace_level  = AV_LOG_INFO;
      45             : 
      46           0 :     if (bsf->par_in->extradata) {
      47             :         CodedBitstreamFragment ps;
      48             : 
      49           0 :         av_log(bsf, AV_LOG_INFO, "Extradata\n");
      50             : 
      51           0 :         err = ff_cbs_read_extradata(ctx->cbc, &ps, bsf->par_in);
      52           0 :         if (err < 0) {
      53           0 :             av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
      54           0 :             return err;
      55             :         }
      56             : 
      57           0 :         ff_cbs_fragment_uninit(ctx->cbc, &ps);
      58             :     }
      59             : 
      60           0 :     return 0;
      61             : }
      62             : 
      63           0 : static void trace_headers_close(AVBSFContext *bsf)
      64             : {
      65           0 :     TraceHeadersContext *ctx = bsf->priv_data;
      66             : 
      67           0 :     ff_cbs_close(&ctx->cbc);
      68           0 : }
      69             : 
      70           0 : static int trace_headers(AVBSFContext *bsf, AVPacket *out)
      71             : {
      72           0 :     TraceHeadersContext *ctx = bsf->priv_data;
      73             :     CodedBitstreamFragment au;
      74             :     AVPacket *in;
      75           0 :     char tmp[256] = { 0 };
      76             :     int err;
      77             : 
      78           0 :     err = ff_bsf_get_packet(bsf, &in);
      79           0 :     if (err < 0)
      80           0 :         return err;
      81             : 
      82           0 :     if (in->flags & AV_PKT_FLAG_KEY)
      83           0 :         av_strlcat(tmp, ", key frame", sizeof(tmp));
      84           0 :     if (in->flags & AV_PKT_FLAG_CORRUPT)
      85           0 :         av_strlcat(tmp, ", corrupt", sizeof(tmp));
      86             : 
      87           0 :     if (in->pts != AV_NOPTS_VALUE)
      88           0 :         av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, in->pts);
      89             :     else
      90           0 :         av_strlcat(tmp, ", no pts", sizeof(tmp));
      91           0 :     if (in->dts != AV_NOPTS_VALUE)
      92           0 :         av_strlcatf(tmp, sizeof(tmp), ", dts %"PRId64, in->dts);
      93             :     else
      94           0 :         av_strlcat(tmp, ", no dts", sizeof(tmp));
      95           0 :     if (in->duration > 0)
      96           0 :         av_strlcatf(tmp, sizeof(tmp), ", duration %"PRId64, in->duration);
      97             : 
      98           0 :     av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", in->size, tmp);
      99             : 
     100           0 :     err = ff_cbs_read_packet(ctx->cbc, &au, in);
     101           0 :     if (err < 0)
     102           0 :         return err;
     103             : 
     104           0 :     ff_cbs_fragment_uninit(ctx->cbc, &au);
     105             : 
     106           0 :     av_packet_move_ref(out, in);
     107           0 :     av_packet_free(&in);
     108             : 
     109           0 :     return 0;
     110             : }
     111             : 
     112             : static const enum AVCodecID trace_headers_codec_ids[] = {
     113             :     AV_CODEC_ID_H264,
     114             :     AV_CODEC_ID_HEVC,
     115             :     AV_CODEC_ID_MPEG2VIDEO,
     116             :     AV_CODEC_ID_NONE,
     117             : };
     118             : 
     119             : const AVBitStreamFilter ff_trace_headers_bsf = {
     120             :     .name           = "trace_headers",
     121             :     .priv_data_size = sizeof(TraceHeadersContext),
     122             :     .init           = &trace_headers_init,
     123             :     .close          = &trace_headers_close,
     124             :     .filter         = &trace_headers,
     125             :     .codec_ids      = trace_headers_codec_ids,
     126             : };

Generated by: LCOV version 1.13