LCOV - code coverage report
Current view: top level - libavcodec - h261_parser.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 7 32 21.9 %
Date: 2017-12-15 11:05:35 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*
       2             :  * H.261 parser
       3             :  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
       4             :  * Copyright (c) 2004 Maarten Daniels
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : /**
      24             :  * @file
      25             :  * H.261 parser
      26             :  */
      27             : 
      28             : #include "parser.h"
      29             : 
      30           0 : static int h261_find_frame_end(ParseContext *pc, AVCodecContext *avctx,
      31             :                                const uint8_t *buf, int buf_size)
      32             : {
      33             :     int vop_found, i, j;
      34             :     uint32_t state;
      35             : 
      36           0 :     vop_found = pc->frame_start_found;
      37           0 :     state     = pc->state;
      38             : 
      39           0 :     for (i = 0; i < buf_size && !vop_found; i++) {
      40           0 :         state = (state << 8) | buf[i];
      41           0 :         for (j = 0; j < 8; j++) {
      42           0 :             if (((state >> j) & 0xFFFFF0) == 0x000100) {
      43           0 :                 vop_found = 1;
      44           0 :                 break;
      45             :             }
      46             :         }
      47             :     }
      48           0 :     if (vop_found) {
      49           0 :         for (; i < buf_size; i++) {
      50           0 :             state = (state << 8) | buf[i];
      51           0 :             for (j = 0; j < 8; j++) {
      52           0 :                 if (((state >> j) & 0xFFFFF0) == 0x000100) {
      53           0 :                     pc->frame_start_found = 0;
      54           0 :                     pc->state             = (state >> (3 * 8)) + 0xFF00;
      55           0 :                     return i - 2;
      56             :                 }
      57             :             }
      58             :         }
      59             :     }
      60             : 
      61           0 :     pc->frame_start_found = vop_found;
      62           0 :     pc->state             = state;
      63           0 :     return END_NOT_FOUND;
      64             : }
      65             : 
      66         332 : static int h261_parse(AVCodecParserContext *s,
      67             :                       AVCodecContext *avctx,
      68             :                       const uint8_t **poutbuf, int *poutbuf_size,
      69             :                       const uint8_t *buf, int buf_size)
      70             : {
      71         332 :     ParseContext *pc = s->priv_data;
      72             :     int next;
      73             : 
      74         332 :     if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
      75         332 :         next = buf_size;
      76             :     } else {
      77           0 :         next = h261_find_frame_end(pc, avctx, buf, buf_size);
      78           0 :         if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
      79           0 :             *poutbuf      = NULL;
      80           0 :             *poutbuf_size = 0;
      81           0 :             return buf_size;
      82             :         }
      83             :     }
      84         332 :     *poutbuf      = buf;
      85         332 :     *poutbuf_size = buf_size;
      86         332 :     return next;
      87             : }
      88             : 
      89             : AVCodecParser ff_h261_parser = {
      90             :     .codec_ids      = { AV_CODEC_ID_H261 },
      91             :     .priv_data_size = sizeof(ParseContext),
      92             :     .parser_parse   = h261_parse,
      93             :     .parser_close   = ff_parse_close,
      94             : };

Generated by: LCOV version 1.13