Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * This file is part of FFmpeg. | ||
3 | * | ||
4 | * FFmpeg is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * FFmpeg is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with FFmpeg; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | */ | ||
18 | |||
19 | #include "bsf.h" | ||
20 | #include "bsf_internal.h" | ||
21 | #include "cbs_bsf.h" | ||
22 | |||
23 | 7563 | static int cbs_bsf_update_side_data(AVBSFContext *bsf, AVPacket *pkt) | |
24 | { | ||
25 | 7563 | CBSBSFContext *ctx = bsf->priv_data; | |
26 | 7563 | CodedBitstreamFragment *frag = &ctx->fragment; | |
27 | uint8_t *side_data; | ||
28 | int err; | ||
29 | |||
30 |
2/2✓ Branch 1 taken 7561 times.
✓ Branch 2 taken 2 times.
|
7563 | if (!av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, NULL)) |
31 | 7561 | return 0; | |
32 | |||
33 | 2 | err = ff_cbs_read_packet_side_data(ctx->input, frag, pkt); | |
34 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (err < 0) { |
35 | ✗ | av_log(bsf, AV_LOG_ERROR, | |
36 | "Failed to read extradata from packet side data.\n"); | ||
37 | ✗ | return err; | |
38 | } | ||
39 | |||
40 | 2 | err = ctx->type->update_fragment(bsf, NULL, frag); | |
41 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (err < 0) |
42 | ✗ | return err; | |
43 | |||
44 | 2 | err = ff_cbs_write_fragment_data(ctx->output, frag); | |
45 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (err < 0) { |
46 | ✗ | av_log(bsf, AV_LOG_ERROR, | |
47 | "Failed to write extradata into packet side data.\n"); | ||
48 | ✗ | return err; | |
49 | } | ||
50 | |||
51 | 2 | side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, | |
52 | frag->data_size); | ||
53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!side_data) |
54 | ✗ | return AVERROR(ENOMEM); | |
55 | 2 | memcpy(side_data, frag->data, frag->data_size); | |
56 | |||
57 | 2 | ff_cbs_fragment_reset(frag); | |
58 | 2 | return 0; | |
59 | } | ||
60 | |||
61 | 15225 | int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt) | |
62 | { | ||
63 | 15225 | CBSBSFContext *ctx = bsf->priv_data; | |
64 | 15225 | CodedBitstreamFragment *frag = &ctx->fragment; | |
65 | int err; | ||
66 | |||
67 | 15225 | err = ff_bsf_get_packet_ref(bsf, pkt); | |
68 |
2/2✓ Branch 0 taken 7662 times.
✓ Branch 1 taken 7563 times.
|
15225 | if (err < 0) |
69 | 7662 | return err; | |
70 | |||
71 | 7563 | err = cbs_bsf_update_side_data(bsf, pkt); | |
72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7563 times.
|
7563 | if (err < 0) |
73 | ✗ | goto fail; | |
74 | |||
75 | 7563 | err = ff_cbs_read_packet(ctx->input, frag, pkt); | |
76 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7562 times.
|
7563 | if (err < 0) { |
77 | 1 | av_log(bsf, AV_LOG_ERROR, "Failed to read %s from packet.\n", | |
78 | 1 | ctx->type->fragment_name); | |
79 | 1 | goto fail; | |
80 | } | ||
81 | |||
82 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7562 times.
|
7562 | if (frag->nb_units == 0) { |
83 | ✗ | av_log(bsf, AV_LOG_ERROR, "No %s found in packet.\n", | |
84 | ✗ | ctx->type->unit_name); | |
85 | ✗ | err = AVERROR_INVALIDDATA; | |
86 | ✗ | goto fail; | |
87 | } | ||
88 | |||
89 | 7562 | err = ctx->type->update_fragment(bsf, pkt, frag); | |
90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7562 times.
|
7562 | if (err < 0) |
91 | ✗ | goto fail; | |
92 | |||
93 | 7562 | err = ff_cbs_write_packet(ctx->output, pkt, frag); | |
94 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7562 times.
|
7562 | if (err < 0) { |
95 | ✗ | av_log(bsf, AV_LOG_ERROR, "Failed to write %s into packet.\n", | |
96 | ✗ | ctx->type->fragment_name); | |
97 | ✗ | goto fail; | |
98 | } | ||
99 | |||
100 | 7562 | err = 0; | |
101 | 7563 | fail: | |
102 | 7563 | ff_cbs_fragment_reset(frag); | |
103 | |||
104 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7562 times.
|
7563 | if (err < 0) |
105 | 1 | av_packet_unref(pkt); | |
106 | |||
107 | 7563 | return err; | |
108 | } | ||
109 | |||
110 | 99 | int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type) | |
111 | { | ||
112 | 99 | CBSBSFContext *ctx = bsf->priv_data; | |
113 | 99 | CodedBitstreamFragment *frag = &ctx->fragment; | |
114 | int err; | ||
115 | |||
116 | 99 | ctx->type = type; | |
117 | |||
118 | 99 | err = ff_cbs_init(&ctx->input, type->codec_id, bsf); | |
119 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | if (err < 0) |
120 | ✗ | return err; | |
121 | |||
122 | 99 | err = ff_cbs_init(&ctx->output, type->codec_id, bsf); | |
123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | if (err < 0) |
124 | ✗ | return err; | |
125 | |||
126 | 99 | ctx->output->trace_enable = 1; | |
127 | 99 | ctx->output->trace_level = AV_LOG_TRACE; | |
128 | 99 | ctx->output->trace_context = ctx->output; | |
129 | 99 | ctx->output->trace_write_callback = ff_cbs_trace_write_log; | |
130 | |||
131 |
2/2✓ Branch 0 taken 85 times.
✓ Branch 1 taken 14 times.
|
99 | if (bsf->par_in->extradata) { |
132 | 85 | err = ff_cbs_read_extradata(ctx->input, frag, bsf->par_in); | |
133 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 85 times.
|
85 | if (err < 0) { |
134 | ✗ | av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); | |
135 | ✗ | goto fail; | |
136 | } | ||
137 | |||
138 | 85 | err = type->update_fragment(bsf, NULL, frag); | |
139 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 85 times.
|
85 | if (err < 0) |
140 | ✗ | goto fail; | |
141 | |||
142 | 85 | err = ff_cbs_write_extradata(ctx->output, bsf->par_out, frag); | |
143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 85 times.
|
85 | if (err < 0) { |
144 | ✗ | av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n"); | |
145 | ✗ | goto fail; | |
146 | } | ||
147 | } | ||
148 | |||
149 | 99 | err = 0; | |
150 | 99 | fail: | |
151 | 99 | ff_cbs_fragment_reset(frag); | |
152 | 99 | return err; | |
153 | } | ||
154 | |||
155 | 99 | void ff_cbs_bsf_generic_close(AVBSFContext *bsf) | |
156 | { | ||
157 | 99 | CBSBSFContext *ctx = bsf->priv_data; | |
158 | |||
159 | 99 | ff_cbs_fragment_free(&ctx->fragment); | |
160 | 99 | ff_cbs_close(&ctx->input); | |
161 | 99 | ff_cbs_close(&ctx->output); | |
162 | 99 | } | |
163 |