| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | #include "parser_internal.h" | ||
| 30 | |||
| 31 | ✗ | static int h261_find_frame_end(ParseContext *pc, AVCodecContext *avctx, | |
| 32 | const uint8_t *buf, int buf_size) | ||
| 33 | { | ||
| 34 | int vop_found, i, j; | ||
| 35 | uint32_t state; | ||
| 36 | |||
| 37 | ✗ | vop_found = pc->frame_start_found; | |
| 38 | ✗ | state = pc->state; | |
| 39 | |||
| 40 | ✗ | for (i = 0; i < buf_size && !vop_found; i++) { | |
| 41 | ✗ | state = (state << 8) | buf[i]; | |
| 42 | ✗ | for (j = 0; j < 8; j++) { | |
| 43 | ✗ | if (((state >> j) & 0xFFFFF0) == 0x000100) { | |
| 44 | ✗ | vop_found = 1; | |
| 45 | ✗ | break; | |
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 | ✗ | if (vop_found) { | |
| 50 | ✗ | for (; i < buf_size; i++) { | |
| 51 | ✗ | state = (state << 8) | buf[i]; | |
| 52 | ✗ | for (j = 0; j < 8; j++) { | |
| 53 | ✗ | if (((state >> j) & 0xFFFFF0) == 0x000100) { | |
| 54 | ✗ | pc->frame_start_found = 0; | |
| 55 | ✗ | pc->state = (state >> (3 * 8)) + 0xFF00; | |
| 56 | ✗ | return i - 2; | |
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | ✗ | pc->frame_start_found = vop_found; | |
| 63 | ✗ | pc->state = state; | |
| 64 | ✗ | return END_NOT_FOUND; | |
| 65 | } | ||
| 66 | |||
| 67 | 332 | static int h261_parse(AVCodecParserContext *s, | |
| 68 | AVCodecContext *avctx, | ||
| 69 | const uint8_t **poutbuf, int *poutbuf_size, | ||
| 70 | const uint8_t *buf, int buf_size) | ||
| 71 | { | ||
| 72 | 332 | ParseContext *pc = s->priv_data; | |
| 73 | int next; | ||
| 74 | |||
| 75 |
1/2✓ Branch 0 taken 332 times.
✗ Branch 1 not taken.
|
332 | if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
| 76 | 332 | next = buf_size; | |
| 77 | } else { | ||
| 78 | ✗ | next = h261_find_frame_end(pc, avctx, buf, buf_size); | |
| 79 | ✗ | if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { | |
| 80 | ✗ | *poutbuf = NULL; | |
| 81 | ✗ | *poutbuf_size = 0; | |
| 82 | ✗ | return buf_size; | |
| 83 | } | ||
| 84 | } | ||
| 85 | 332 | *poutbuf = buf; | |
| 86 | 332 | *poutbuf_size = buf_size; | |
| 87 | 332 | return next; | |
| 88 | } | ||
| 89 | |||
| 90 | const FFCodecParser ff_h261_parser = { | ||
| 91 | PARSER_CODEC_LIST(AV_CODEC_ID_H261), | ||
| 92 | .priv_data_size = sizeof(ParseContext), | ||
| 93 | .parse = h261_parse, | ||
| 94 | .close = ff_parse_close, | ||
| 95 | }; | ||
| 96 |