| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * DNxHD/VC-3 parser | ||
| 3 | * Copyright (c) 2008 Baptiste Coudurier <baptiste.coudurier@free.fr> | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @file | ||
| 24 | * DNxHD/VC-3 parser | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include "parser.h" | ||
| 28 | #include "dnxhddata.h" | ||
| 29 | #include "parser_internal.h" | ||
| 30 | |||
| 31 | typedef struct { | ||
| 32 | ParseContext pc; | ||
| 33 | int cur_byte; | ||
| 34 | int remaining; | ||
| 35 | int w, h; | ||
| 36 | } DNXHDParserContext; | ||
| 37 | |||
| 38 | 177532 | static int dnxhd_find_frame_end(DNXHDParserContext *dctx, | |
| 39 | const uint8_t *buf, int buf_size) | ||
| 40 | { | ||
| 41 | 177532 | ParseContext *pc = &dctx->pc; | |
| 42 | 177532 | uint64_t state = pc->state64; | |
| 43 | 177532 | int pic_found = pc->frame_start_found; | |
| 44 | 177532 | int i = 0; | |
| 45 | |||
| 46 |
2/2✓ Branch 0 taken 525 times.
✓ Branch 1 taken 177007 times.
|
177532 | if (!pic_found) { |
| 47 |
2/2✓ Branch 0 taken 2526 times.
✓ Branch 1 taken 104 times.
|
2630 | for (i = 0; i < buf_size; i++) { |
| 48 | 2526 | state = (state << 8) | buf[i]; | |
| 49 |
2/2✓ Branch 1 taken 421 times.
✓ Branch 2 taken 2105 times.
|
2526 | if (ff_dnxhd_check_header_prefix(state & 0xffffffffff00LL) != 0) { |
| 50 | 421 | i++; | |
| 51 | 421 | pic_found = 1; | |
| 52 | 421 | dctx->cur_byte = 0; | |
| 53 | 421 | dctx->remaining = 0; | |
| 54 | 421 | break; | |
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 |
4/4✓ Branch 0 taken 177428 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 421 times.
✓ Branch 3 taken 177007 times.
|
177532 | if (pic_found && !dctx->remaining) { |
| 60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 421 times.
|
421 | if (!buf_size) /* EOF considered as end of frame */ |
| 61 | ✗ | return 0; | |
| 62 |
1/2✓ Branch 0 taken 17682 times.
✗ Branch 1 not taken.
|
17682 | for (; i < buf_size; i++) { |
| 63 | 17682 | dctx->cur_byte++; | |
| 64 | 17682 | state = (state << 8) | buf[i]; | |
| 65 | |||
| 66 |
2/2✓ Branch 0 taken 421 times.
✓ Branch 1 taken 17261 times.
|
17682 | if (dctx->cur_byte == 24) { |
| 67 | 421 | dctx->h = (state >> 32) & 0xFFFF; | |
| 68 |
2/2✓ Branch 0 taken 421 times.
✓ Branch 1 taken 16840 times.
|
17261 | } else if (dctx->cur_byte == 26) { |
| 69 | 421 | dctx->w = (state >> 32) & 0xFFFF; | |
| 70 |
2/2✓ Branch 0 taken 421 times.
✓ Branch 1 taken 16419 times.
|
16840 | } else if (dctx->cur_byte == 42) { |
| 71 | 421 | int cid = (state >> 32) & 0xFFFFFFFF; | |
| 72 | int remaining; | ||
| 73 | |||
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 421 times.
|
421 | if (cid <= 0) |
| 75 | ✗ | continue; | |
| 76 | |||
| 77 | 421 | remaining = ff_dnxhd_get_frame_size(cid); | |
| 78 |
2/2✓ Branch 0 taken 218 times.
✓ Branch 1 taken 203 times.
|
421 | if (remaining <= 0) { |
| 79 | 218 | remaining = ff_dnxhd_get_hr_frame_size(cid, dctx->w, dctx->h); | |
| 80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
|
218 | if (remaining <= 0) |
| 81 | ✗ | continue; | |
| 82 | } | ||
| 83 | 421 | remaining += i - 47; | |
| 84 | 421 | dctx->remaining = remaining; | |
| 85 |
2/2✓ Branch 0 taken 84 times.
✓ Branch 1 taken 337 times.
|
421 | if (buf_size >= dctx->remaining) { |
| 86 | 84 | pc->frame_start_found = 0; | |
| 87 | 84 | pc->state64 = -1; | |
| 88 | 84 | dctx->cur_byte = 0; | |
| 89 | 84 | dctx->remaining = 0; | |
| 90 | 84 | return remaining; | |
| 91 | } else { | ||
| 92 | 337 | dctx->remaining -= buf_size; | |
| 93 | // Update variables for correctness, they are currently not used beyond here | ||
| 94 | 337 | state = -1; | |
| 95 | 337 | dctx->cur_byte += buf_size - i; | |
| 96 | 337 | break; | |
| 97 | } | ||
| 98 | } | ||
| 99 | } | ||
| 100 |
2/2✓ Branch 0 taken 177007 times.
✓ Branch 1 taken 104 times.
|
177111 | } else if (pic_found) { |
| 101 |
2/2✓ Branch 0 taken 176670 times.
✓ Branch 1 taken 337 times.
|
177007 | if (dctx->remaining > buf_size) { |
| 102 | 176670 | dctx->remaining -= buf_size; | |
| 103 | } else { | ||
| 104 | 337 | int remaining = dctx->remaining; | |
| 105 | |||
| 106 | 337 | pc->frame_start_found = 0; | |
| 107 | 337 | pc->state64 = -1; | |
| 108 | 337 | dctx->cur_byte = 0; | |
| 109 | 337 | dctx->remaining = 0; | |
| 110 | 337 | return remaining; | |
| 111 | } | ||
| 112 | } | ||
| 113 | 177111 | pc->frame_start_found = pic_found; | |
| 114 | 177111 | pc->state64 = state; | |
| 115 | 177111 | return END_NOT_FOUND; | |
| 116 | } | ||
| 117 | |||
| 118 | 177532 | static int dnxhd_parse(AVCodecParserContext *s, | |
| 119 | AVCodecContext *avctx, | ||
| 120 | const uint8_t **poutbuf, int *poutbuf_size, | ||
| 121 | const uint8_t *buf, int buf_size) | ||
| 122 | { | ||
| 123 | 177532 | DNXHDParserContext *dctx = s->priv_data; | |
| 124 | 177532 | ParseContext *pc = &dctx->pc; | |
| 125 | int next; | ||
| 126 | |||
| 127 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 177532 times.
|
177532 | if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
| 128 | ✗ | next = buf_size; | |
| 129 | } else { | ||
| 130 | 177532 | next = dnxhd_find_frame_end(dctx, buf, buf_size); | |
| 131 |
2/2✓ Branch 1 taken 177007 times.
✓ Branch 2 taken 525 times.
|
177532 | if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { |
| 132 | 177007 | *poutbuf = NULL; | |
| 133 | 177007 | *poutbuf_size = 0; | |
| 134 | 177007 | return buf_size; | |
| 135 | } | ||
| 136 | } | ||
| 137 | 525 | *poutbuf = buf; | |
| 138 | 525 | *poutbuf_size = buf_size; | |
| 139 | 525 | return next; | |
| 140 | } | ||
| 141 | |||
| 142 | const FFCodecParser ff_dnxhd_parser = { | ||
| 143 | PARSER_CODEC_LIST(AV_CODEC_ID_DNXHD), | ||
| 144 | .priv_data_size = sizeof(DNXHDParserContext), | ||
| 145 | .parse = dnxhd_parse, | ||
| 146 | .close = ff_parse_close, | ||
| 147 | }; | ||
| 148 |