| 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 | 16 | 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 | 16 | vop_found = pc->frame_start_found; | |
| 38 | 16 | state = pc->state; | |
| 39 | |||
| 40 |
4/4✓ Branch 0 taken 50 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 10 times.
|
56 | for (i = 0; i < buf_size && !vop_found; i++) { |
| 41 | 40 | state = (state << 8) | buf[i]; | |
| 42 |
2/2✓ Branch 0 taken 264 times.
✓ Branch 1 taken 32 times.
|
296 | for (j = 0; j < 8; j++) { |
| 43 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 256 times.
|
264 | if (((state >> j) & 0xFFFFF0) == 0x000100) { |
| 44 | 8 | vop_found = 1; | |
| 45 | 8 | break; | |
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
|
16 | if (vop_found) { |
| 50 |
2/2✓ Branch 0 taken 8262 times.
✓ Branch 1 taken 10 times.
|
8272 | for (; i < buf_size; i++) { |
| 51 | 8262 | state = (state << 8) | buf[i]; | |
| 52 |
2/2✓ Branch 0 taken 66068 times.
✓ Branch 1 taken 8258 times.
|
74326 | for (j = 0; j < 8; j++) { |
| 53 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 66064 times.
|
66068 | if (((state >> j) & 0xFFFFF0) == 0x000100) { |
| 54 | 4 | pc->frame_start_found = 0; | |
| 55 | 4 | pc->state = (state >> (3 * 8)) + 0xFF00; | |
| 56 | 4 | return i - 2; | |
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | 12 | pc->frame_start_found = vop_found; | |
| 63 | 12 | pc->state = state; | |
| 64 | 12 | return END_NOT_FOUND; | |
| 65 | } | ||
| 66 | |||
| 67 | 348 | 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 | 348 | ParseContext *pc = s->priv_data; | |
| 73 | int next; | ||
| 74 | |||
| 75 |
2/2✓ Branch 0 taken 332 times.
✓ Branch 1 taken 16 times.
|
348 | if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
| 76 | 332 | next = buf_size; | |
| 77 | } else { | ||
| 78 | 16 | next = h261_find_frame_end(pc, avctx, buf, buf_size); | |
| 79 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
|
16 | if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { |
| 80 | 8 | *poutbuf = NULL; | |
| 81 | 8 | *poutbuf_size = 0; | |
| 82 | 8 | return buf_size; | |
| 83 | } | ||
| 84 | } | ||
| 85 | 340 | *poutbuf = buf; | |
| 86 | 340 | *poutbuf_size = buf_size; | |
| 87 | 340 | 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 |