| 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 | #include "libavutil/attributes.h" | ||
| 24 | |||
| 25 | 7648 | static int cbs_bsf_update_side_data(AVBSFContext *bsf, AVPacket *pkt) | |
| 26 | { | ||
| 27 | 7648 | CBSBSFContext *ctx = bsf->priv_data; | |
| 28 | 7648 | CodedBitstreamFragment *frag = &ctx->fragment; | |
| 29 | uint8_t *side_data; | ||
| 30 | int err; | ||
| 31 | |||
| 32 |
2/2✓ Branch 1 taken 7647 times.
✓ Branch 2 taken 1 times.
|
7648 | if (!av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, NULL)) |
| 33 | 7647 | return 0; | |
| 34 | |||
| 35 | 1 | err = ff_cbs_read_packet_side_data(ctx->input, frag, pkt); | |
| 36 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) { |
| 37 | ✗ | av_log(bsf, AV_LOG_ERROR, | |
| 38 | "Failed to read extradata from packet side data.\n"); | ||
| 39 | ✗ | return err; | |
| 40 | } | ||
| 41 | |||
| 42 | 1 | err = ctx->type->update_fragment(bsf, NULL, frag); | |
| 43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 44 | ✗ | return err; | |
| 45 | |||
| 46 | 1 | err = ff_cbs_write_fragment_data(ctx->output, frag); | |
| 47 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) { |
| 48 | ✗ | av_log(bsf, AV_LOG_ERROR, | |
| 49 | "Failed to write extradata into packet side data.\n"); | ||
| 50 | ✗ | return err; | |
| 51 | } | ||
| 52 | |||
| 53 | 1 | side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, | |
| 54 | frag->data_size); | ||
| 55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!side_data) |
| 56 | ✗ | return AVERROR(ENOMEM); | |
| 57 | 1 | memcpy(side_data, frag->data, frag->data_size); | |
| 58 | |||
| 59 | 1 | ff_cbs_fragment_reset(frag); | |
| 60 | 1 | return 0; | |
| 61 | } | ||
| 62 | |||
| 63 | 15398 | int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt) | |
| 64 | { | ||
| 65 | 15398 | CBSBSFContext *ctx = bsf->priv_data; | |
| 66 | 15398 | CodedBitstreamFragment *frag = &ctx->fragment; | |
| 67 | int err; | ||
| 68 | |||
| 69 | 15398 | err = ff_bsf_get_packet_ref(bsf, pkt); | |
| 70 |
2/2✓ Branch 0 taken 7750 times.
✓ Branch 1 taken 7648 times.
|
15398 | if (err < 0) |
| 71 | 7750 | return err; | |
| 72 | |||
| 73 | 7648 | err = cbs_bsf_update_side_data(bsf, pkt); | |
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7648 times.
|
7648 | if (err < 0) |
| 75 | ✗ | goto fail; | |
| 76 | |||
| 77 | 7648 | err = ff_cbs_read_packet(ctx->input, frag, pkt); | |
| 78 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7647 times.
|
7648 | if (err < 0) { |
| 79 | 1 | av_log(bsf, AV_LOG_ERROR, "Failed to read %s from packet.\n", | |
| 80 | 1 | ctx->type->fragment_name); | |
| 81 | 1 | goto fail; | |
| 82 | } | ||
| 83 | |||
| 84 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7647 times.
|
7647 | if (frag->nb_units == 0) { |
| 85 | ✗ | av_log(bsf, AV_LOG_ERROR, "No %s found in packet.\n", | |
| 86 | ✗ | ctx->type->unit_name); | |
| 87 | ✗ | err = AVERROR_INVALIDDATA; | |
| 88 | ✗ | goto fail; | |
| 89 | } | ||
| 90 | |||
| 91 | 7647 | err = ctx->type->update_fragment(bsf, pkt, frag); | |
| 92 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7647 times.
|
7647 | if (err < 0) |
| 93 | ✗ | goto fail; | |
| 94 | |||
| 95 | 7647 | err = ff_cbs_write_packet(ctx->output, pkt, frag); | |
| 96 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7647 times.
|
7647 | if (err < 0) { |
| 97 | ✗ | av_log(bsf, AV_LOG_ERROR, "Failed to write %s into packet.\n", | |
| 98 | ✗ | ctx->type->fragment_name); | |
| 99 | ✗ | goto fail; | |
| 100 | } | ||
| 101 | |||
| 102 | 7647 | err = 0; | |
| 103 | 7648 | fail: | |
| 104 | 7648 | ff_cbs_fragment_reset(frag); | |
| 105 | |||
| 106 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7647 times.
|
7648 | if (err < 0) |
| 107 | 1 | av_packet_unref(pkt); | |
| 108 | |||
| 109 | 7648 | return err; | |
| 110 | } | ||
| 111 | |||
| 112 | 104 | av_cold int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type) | |
| 113 | { | ||
| 114 | 104 | CBSBSFContext *ctx = bsf->priv_data; | |
| 115 | 104 | CodedBitstreamFragment *frag = &ctx->fragment; | |
| 116 | int err; | ||
| 117 | |||
| 118 | 104 | ctx->type = type; | |
| 119 | |||
| 120 | 104 | err = ff_cbs_init(&ctx->input, type->codec_id, bsf); | |
| 121 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
|
104 | if (err < 0) |
| 122 | ✗ | return err; | |
| 123 | |||
| 124 | 104 | err = ff_cbs_init(&ctx->output, type->codec_id, bsf); | |
| 125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
|
104 | if (err < 0) |
| 126 | ✗ | return err; | |
| 127 | |||
| 128 | 104 | ctx->output->trace_enable = 1; | |
| 129 | 104 | ctx->output->trace_level = AV_LOG_TRACE; | |
| 130 | 104 | ctx->output->trace_context = ctx->output; | |
| 131 | 104 | ctx->output->trace_write_callback = ff_cbs_trace_write_log; | |
| 132 | |||
| 133 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 16 times.
|
104 | if (bsf->par_in->extradata) { |
| 134 | 88 | err = ff_cbs_read_extradata(ctx->input, frag, bsf->par_in); | |
| 135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
|
88 | if (err < 0) { |
| 136 | ✗ | av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); | |
| 137 | ✗ | goto fail; | |
| 138 | } | ||
| 139 | |||
| 140 | 88 | err = type->update_fragment(bsf, NULL, frag); | |
| 141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
|
88 | if (err < 0) |
| 142 | ✗ | goto fail; | |
| 143 | |||
| 144 | 88 | err = ff_cbs_write_extradata(ctx->output, bsf->par_out, frag); | |
| 145 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
|
88 | if (err < 0) { |
| 146 | ✗ | av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n"); | |
| 147 | ✗ | goto fail; | |
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | 104 | err = 0; | |
| 152 | 104 | fail: | |
| 153 | 104 | ff_cbs_fragment_reset(frag); | |
| 154 | 104 | return err; | |
| 155 | } | ||
| 156 | |||
| 157 | 104 | av_cold void ff_cbs_bsf_generic_close(AVBSFContext *bsf) | |
| 158 | { | ||
| 159 | 104 | CBSBSFContext *ctx = bsf->priv_data; | |
| 160 | |||
| 161 | 104 | ff_cbs_fragment_free(&ctx->fragment); | |
| 162 | 104 | ff_cbs_close(&ctx->input); | |
| 163 | 104 | ff_cbs_close(&ctx->output); | |
| 164 | 104 | } | |
| 165 |