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

          Line data    Source code
       1             : /*
       2             : * Copyright (c) 2013 Nicolas George
       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 License
       8             : * 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
      14             : * GNU Lesser General Public License for more details.
      15             : *
      16             : * You should have received a copy of the GNU Lesser General Public License
      17             : * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
      18             : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      19             : */
      20             : 
      21             : #include "libavutil/adler32.h"
      22             : #include "libavutil/avassert.h"
      23             : #include "libavutil/bprint.h"
      24             : #include "libavutil/imgutils.h"
      25             : #include "libavutil/pixdesc.h"
      26             : #include "avformat.h"
      27             : #include "internal.h"
      28             : 
      29             : /* Identical to Adler32 when the type is uint8_t. */
      30             : #define DEFINE_CKSUM_LINE(name, type, conv) \
      31             : static void cksum_line_ ## name(unsigned *cksum, void *data, unsigned size) \
      32             : { \
      33             :     type *p = data; \
      34             :     unsigned a = *cksum & 0xFFFF, b = *cksum >> 16; \
      35             :     for (; size > 0; size--, p++) { \
      36             :         a = (a + (unsigned)(conv)) % 65521; \
      37             :         b = (b + a) % 65521; \
      38             :     } \
      39             :     *cksum = a | (b << 16); \
      40             : }
      41             : 
      42           0 : DEFINE_CKSUM_LINE(u8,  uint8_t, *p)
      43           0 : DEFINE_CKSUM_LINE(s16, int16_t, *p + 0x8000)
      44           0 : DEFINE_CKSUM_LINE(s32, int32_t, *p + 0x80000000)
      45           0 : DEFINE_CKSUM_LINE(flt, float,   *p * 0x80000000 + 0x80000000)
      46           0 : DEFINE_CKSUM_LINE(dbl, double,  *p * 0x80000000 + 0x80000000)
      47             : 
      48           0 : static void video_frame_cksum(AVBPrint *bp, AVFrame *frame)
      49             : {
      50           0 :     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
      51             :     int i, y;
      52             :     uint8_t *data;
      53           0 :     int linesize[5] = { 0 };
      54             : 
      55           0 :     av_bprintf(bp, ", %d x %d", frame->width, frame->height);
      56           0 :     if (!desc) {
      57           0 :         av_bprintf(bp, ", unknown");
      58           0 :         return;
      59             :     }
      60           0 :     if (av_image_fill_linesizes(linesize, frame->format, frame->width) < 0)
      61           0 :         return;
      62           0 :     av_bprintf(bp, ", %s", desc->name);
      63           0 :     for (i = 0; linesize[i]; i++) {
      64           0 :         unsigned cksum = 0;
      65           0 :         int h = frame->height;
      66           0 :         if ((i == 1 || i == 2) && desc->nb_components >= 3)
      67           0 :             h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
      68           0 :         data = frame->data[i];
      69           0 :         for (y = 0; y < h; y++) {
      70           0 :             cksum = av_adler32_update(cksum, data, linesize[i]);
      71           0 :             data += frame->linesize[i];
      72             :         }
      73           0 :         av_bprintf(bp, ", 0x%08x", cksum);
      74             :     }
      75             : }
      76             : 
      77           0 : static void audio_frame_cksum(AVBPrint *bp, AVFrame *frame)
      78             : {
      79             :     int nb_planes, nb_samples, p;
      80             :     const char *name;
      81             : 
      82           0 :     nb_planes  = frame->channels;
      83           0 :     nb_samples = frame->nb_samples;
      84           0 :     if (!av_sample_fmt_is_planar(frame->format)) {
      85           0 :         nb_samples *= nb_planes;
      86           0 :         nb_planes = 1;
      87             :     }
      88           0 :     name = av_get_sample_fmt_name(frame->format);
      89           0 :     av_bprintf(bp, ", %d samples", frame->nb_samples);
      90           0 :     av_bprintf(bp, ", %s", name ? name : "unknown");
      91           0 :     for (p = 0; p < nb_planes; p++) {
      92           0 :         uint32_t cksum = 0;
      93           0 :         void *d = frame->extended_data[p];
      94           0 :         switch (frame->format) {
      95           0 :         case AV_SAMPLE_FMT_U8:
      96             :         case AV_SAMPLE_FMT_U8P:
      97           0 :             cksum_line_u8(&cksum, d, nb_samples);
      98           0 :             break;
      99           0 :         case AV_SAMPLE_FMT_S16:
     100             :         case AV_SAMPLE_FMT_S16P:
     101           0 :             cksum_line_s16(&cksum, d, nb_samples);
     102           0 :             break;
     103           0 :         case AV_SAMPLE_FMT_S32:
     104             :         case AV_SAMPLE_FMT_S32P:
     105           0 :             cksum_line_s32(&cksum, d, nb_samples);
     106           0 :             break;
     107           0 :         case AV_SAMPLE_FMT_FLT:
     108             :         case AV_SAMPLE_FMT_FLTP:
     109           0 :             cksum_line_flt(&cksum, d, nb_samples);
     110           0 :             break;
     111           0 :         case AV_SAMPLE_FMT_DBL:
     112             :         case AV_SAMPLE_FMT_DBLP:
     113           0 :             cksum_line_dbl(&cksum, d, nb_samples);
     114           0 :             break;
     115           0 :         default:
     116           0 :             av_assert0(!"reached");
     117             :         }
     118           0 :         av_bprintf(bp, ", 0x%08"PRIx32, cksum);
     119             :     }
     120           0 : }
     121             : 
     122           0 : static int write_header(struct AVFormatContext *s)
     123             : {
     124           0 :     return ff_framehash_write_header(s);
     125             : }
     126             : 
     127           0 : static int write_frame(struct AVFormatContext *s, int stream_index,
     128             :                        AVFrame **frame, unsigned flags)
     129             : {
     130             :     AVBPrint bp;
     131           0 :     int ret = 0;
     132             :     enum AVMediaType type;
     133             :     const char *type_name;
     134             : 
     135           0 :     if ((flags & AV_WRITE_UNCODED_FRAME_QUERY))
     136           0 :         return 0;
     137             : 
     138           0 :     av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
     139           0 :     av_bprintf(&bp, "%d, %10"PRId64"",
     140           0 :                stream_index, (*frame)->pts);
     141           0 :     type = s->streams[stream_index]->codecpar->codec_type;
     142           0 :     type_name = av_get_media_type_string(type);
     143           0 :     av_bprintf(&bp, ", %s", type_name ? type_name : "unknown");
     144           0 :     switch (type) {
     145           0 :         case AVMEDIA_TYPE_VIDEO:
     146           0 :             video_frame_cksum(&bp, *frame);
     147           0 :             break;
     148           0 :         case AVMEDIA_TYPE_AUDIO:
     149           0 :             audio_frame_cksum(&bp, *frame);
     150           0 :             break;
     151             :     }
     152             : 
     153           0 :     av_bprint_chars(&bp, '\n', 1);
     154           0 :     if (av_bprint_is_complete(&bp))
     155           0 :         avio_write(s->pb, bp.str, bp.len);
     156             :     else
     157           0 :         ret = AVERROR(ENOMEM);
     158           0 :     av_bprint_finalize(&bp, NULL);
     159           0 :     return ret;
     160             : }
     161             : 
     162           0 : static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
     163             : {
     164           0 :     return AVERROR(ENOSYS);
     165             : }
     166             : 
     167             : AVOutputFormat ff_uncodedframecrc_muxer = {
     168             :     .name              = "uncodedframecrc",
     169             :     .long_name         = NULL_IF_CONFIG_SMALL("uncoded framecrc testing"),
     170             :     .audio_codec       = AV_CODEC_ID_PCM_S16LE,
     171             :     .video_codec       = AV_CODEC_ID_RAWVIDEO,
     172             :     .write_header      = write_header,
     173             :     .write_packet      = write_packet,
     174             :     .write_uncoded_frame = write_frame,
     175             :     .flags             = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT |
     176             :                          AVFMT_TS_NEGATIVE,
     177             : };

Generated by: LCOV version 1.13