LCOV - code coverage report
Current view: top level - libavcodec - vp8_parser.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 30 83.3 %
Date: 2017-12-14 08:27:08 Functions: 1 1 100.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 "libavutil/intreadwrite.h"
      20             : 
      21             : #include "avcodec.h"
      22             : 
      23        1447 : static int parse(AVCodecParserContext *s,
      24             :                  AVCodecContext *avctx,
      25             :                  const uint8_t **poutbuf, int *poutbuf_size,
      26             :                  const uint8_t *buf, int buf_size)
      27             : {
      28             :     unsigned int frame_type;
      29             :     unsigned int profile;
      30             : 
      31        1447 :     if (buf_size < 3)
      32          29 :         return buf_size;
      33             : 
      34        1418 :     frame_type = buf[0] & 1;
      35        1418 :     profile    = (buf[0] >> 1) & 7;
      36        1418 :     if (profile > 3) {
      37           0 :         av_log(avctx, AV_LOG_ERROR, "Invalid profile %u.\n", profile);
      38           0 :         return buf_size;
      39             :     }
      40             : 
      41        1418 :     avctx->profile = profile;
      42        1418 :     s->key_frame   = frame_type == 0;
      43        1418 :     s->pict_type   = frame_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
      44        1418 :     s->format      = AV_PIX_FMT_YUV420P;
      45        1418 :     s->field_order = AV_FIELD_PROGRESSIVE;
      46        1418 :     s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
      47             : 
      48        1418 :     if (frame_type == 0) {
      49             :         unsigned int sync_code;
      50             :         unsigned int width, height;
      51             : 
      52          49 :         if (buf_size < 10)
      53           0 :             return buf_size;
      54             : 
      55          49 :         sync_code = AV_RL24(buf + 3);
      56          49 :         if (sync_code != 0x2a019d) {
      57           0 :             av_log(avctx, AV_LOG_ERROR, "Invalid sync code %06x.\n", sync_code);
      58           0 :             return buf_size;
      59             :         }
      60             : 
      61          49 :         width  = AV_RL16(buf + 6) & 0x3fff;
      62          49 :         height = AV_RL16(buf + 8) & 0x3fff;
      63             : 
      64          49 :         s->width        = width;
      65          49 :         s->height       = height;
      66          49 :         s->coded_width  = FFALIGN(width,  16);
      67          49 :         s->coded_height = FFALIGN(height, 16);
      68             :     }
      69             : 
      70        1418 :     *poutbuf      = buf;
      71        1418 :     *poutbuf_size = buf_size;
      72        1418 :     return buf_size;
      73             : }
      74             : 
      75             : AVCodecParser ff_vp8_parser = {
      76             :     .codec_ids    = { AV_CODEC_ID_VP8 },
      77             :     .parser_parse = parse,
      78             : };

Generated by: LCOV version 1.13