Directory: | ../../../ffmpeg/ |
---|---|
File: | src/libavcodec/rv34_parser.c |
Date: | 2022-07-04 19:11:22 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 22 | 22 | 100.0% |
Branches: | 10 | 10 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * RV30/40 parser | ||
3 | * Copyright (c) 2011 Konstantin Shishkov | ||
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 | * RV30/40 parser | ||
25 | */ | ||
26 | |||
27 | #include "config_components.h" | ||
28 | |||
29 | #include "parser.h" | ||
30 | #include "libavutil/intreadwrite.h" | ||
31 | |||
32 | typedef struct RV34ParseContext { | ||
33 | ParseContext pc; | ||
34 | int64_t key_dts; | ||
35 | int key_pts; | ||
36 | } RV34ParseContext; | ||
37 | |||
38 | static const int rv_to_av_frame_type[4] = { | ||
39 | AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, | ||
40 | }; | ||
41 | |||
42 | 550 | static int rv34_parse(AVCodecParserContext *s, | |
43 | AVCodecContext *avctx, | ||
44 | const uint8_t **poutbuf, int *poutbuf_size, | ||
45 | const uint8_t *buf, int buf_size) | ||
46 | { | ||
47 | 550 | RV34ParseContext *pc = s->priv_data; | |
48 | int type, pts, hdr; | ||
49 | |||
50 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 547 times.
|
550 | if (buf_size < 13 + *buf * 8) { |
51 | 3 | *poutbuf = buf; | |
52 | 3 | *poutbuf_size = buf_size; | |
53 | 3 | return buf_size; | |
54 | } | ||
55 | |||
56 | 547 | hdr = AV_RB32(buf + 9 + *buf * 8); | |
57 |
2/2✓ Branch 0 taken 244 times.
✓ Branch 1 taken 303 times.
|
547 | if (avctx->codec_id == AV_CODEC_ID_RV30) { |
58 | 244 | type = (hdr >> 27) & 3; | |
59 | 244 | pts = (hdr >> 7) & 0x1FFF; | |
60 | } else { | ||
61 | 303 | type = (hdr >> 29) & 3; | |
62 | 303 | pts = (hdr >> 6) & 0x1FFF; | |
63 | } | ||
64 | |||
65 |
4/4✓ Branch 0 taken 160 times.
✓ Branch 1 taken 387 times.
✓ Branch 2 taken 158 times.
✓ Branch 3 taken 2 times.
|
547 | if (type != 3 && s->pts != AV_NOPTS_VALUE) { |
66 | 158 | pc->key_dts = s->pts; | |
67 | 158 | pc->key_pts = pts; | |
68 | } else { | ||
69 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 387 times.
|
389 | if (type != 3) |
70 | 2 | s->pts = pc->key_dts + ((pts - pc->key_pts) & 0x1FFF); | |
71 | else | ||
72 | 387 | s->pts = pc->key_dts - ((pc->key_pts - pts) & 0x1FFF); | |
73 | } | ||
74 | 547 | s->pict_type = rv_to_av_frame_type[type]; | |
75 | |||
76 | 547 | *poutbuf = buf; | |
77 | 547 | *poutbuf_size = buf_size; | |
78 | 547 | return buf_size; | |
79 | } | ||
80 | |||
81 | #if CONFIG_RV30_PARSER | ||
82 | const AVCodecParser ff_rv30_parser = { | ||
83 | .codec_ids = { AV_CODEC_ID_RV30 }, | ||
84 | .priv_data_size = sizeof(RV34ParseContext), | ||
85 | .parser_parse = rv34_parse, | ||
86 | }; | ||
87 | #endif | ||
88 | |||
89 | #if CONFIG_RV40_PARSER | ||
90 | const AVCodecParser ff_rv40_parser = { | ||
91 | .codec_ids = { AV_CODEC_ID_RV40 }, | ||
92 | .priv_data_size = sizeof(RV34ParseContext), | ||
93 | .parser_parse = rv34_parse, | ||
94 | }; | ||
95 | #endif | ||
96 |