/src/ffmpeg/libavcodec/bsf/movsub.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2008 Reimar Döffinger |
3 | | * |
4 | | * This file is part of FFmpeg. |
5 | | * |
6 | | * FFmpeg is free software; you can redistribute it and/or |
7 | | * modify it under the terms of the GNU Lesser General Public |
8 | | * License as published by the Free Software Foundation; either |
9 | | * version 2.1 of the License, or (at your option) any later version. |
10 | | * |
11 | | * FFmpeg is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | | * Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public |
17 | | * License along with FFmpeg; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #include "libavutil/common.h" |
22 | | #include "libavutil/intreadwrite.h" |
23 | | #include "bsf.h" |
24 | | #include "bsf_internal.h" |
25 | | |
26 | | static int text2movsub(AVBSFContext *ctx, AVPacket *out) |
27 | 13.5k | { |
28 | 13.5k | AVPacket *in; |
29 | 13.5k | int ret = 0; |
30 | | |
31 | 13.5k | ret = ff_bsf_get_packet(ctx, &in); |
32 | 13.5k | if (ret < 0) |
33 | 6.95k | return ret; |
34 | | |
35 | 6.58k | if (in->size > 0xffff) { |
36 | 52 | ret = AVERROR_INVALIDDATA; |
37 | 52 | goto fail; |
38 | 52 | } |
39 | | |
40 | 6.52k | ret = av_new_packet(out, in->size + 2); |
41 | 6.52k | if (ret < 0) { |
42 | 0 | ret = AVERROR(ENOMEM); |
43 | 0 | goto fail; |
44 | 0 | } |
45 | | |
46 | 6.52k | ret = av_packet_copy_props(out, in); |
47 | 6.52k | if (ret < 0) |
48 | 0 | goto fail; |
49 | | |
50 | 6.52k | AV_WB16(out->data, in->size); |
51 | 6.52k | memcpy(out->data + 2, in->data, in->size); |
52 | | |
53 | 6.58k | fail: |
54 | 6.58k | if (ret < 0) |
55 | 52 | av_packet_unref(out); |
56 | 6.58k | av_packet_free(&in); |
57 | 6.58k | return ret; |
58 | 6.52k | } |
59 | | |
60 | | const FFBitStreamFilter ff_text2movsub_bsf = { |
61 | | .p.name = "text2movsub", |
62 | | .filter = text2movsub, |
63 | | }; |
64 | | |
65 | | static int mov2textsub(AVBSFContext *ctx, AVPacket *pkt) |
66 | 12.3k | { |
67 | 12.3k | int ret = 0; |
68 | | |
69 | 12.3k | ret = ff_bsf_get_packet_ref(ctx, pkt); |
70 | 12.3k | if (ret < 0) |
71 | 4.34k | return ret; |
72 | | |
73 | 8.02k | if (pkt->size < 2) { |
74 | 4.17k | av_packet_unref(pkt); |
75 | 4.17k | return AVERROR_INVALIDDATA; |
76 | 4.17k | } |
77 | | |
78 | 3.85k | pkt->size = FFMIN(pkt->size - 2, AV_RB16(pkt->data)); |
79 | 3.85k | pkt->data += 2; |
80 | | |
81 | 3.85k | return 0; |
82 | 8.02k | } |
83 | | |
84 | | const FFBitStreamFilter ff_mov2textsub_bsf = { |
85 | | .p.name = "mov2textsub", |
86 | | .filter = mov2textsub, |
87 | | }; |