| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Forward Uncompressed | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de> | ||
| 5 | * | ||
| 6 | * This file is part of FFmpeg. | ||
| 7 | * | ||
| 8 | * FFmpeg is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with FFmpeg; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include "avcodec.h" | ||
| 24 | #include "bytestream.h" | ||
| 25 | #include "codec_internal.h" | ||
| 26 | #include "decode.h" | ||
| 27 | #include "libavutil/opt.h" | ||
| 28 | |||
| 29 | typedef struct { | ||
| 30 | AVClass *av_class; | ||
| 31 | int change_field_order; | ||
| 32 | } FRWUContext; | ||
| 33 | |||
| 34 | 2 | static av_cold int decode_init(AVCodecContext *avctx) | |
| 35 | { | ||
| 36 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (avctx->width & 1) { |
| 37 | ✗ | av_log(avctx, AV_LOG_ERROR, "frwu needs even width\n"); | |
| 38 | ✗ | return AVERROR(EINVAL); | |
| 39 | } | ||
| 40 | 2 | avctx->pix_fmt = AV_PIX_FMT_UYVY422; | |
| 41 | |||
| 42 | 2 | return 0; | |
| 43 | } | ||
| 44 | |||
| 45 | 10 | static int decode_frame(AVCodecContext *avctx, AVFrame *pic, | |
| 46 | int *got_frame, AVPacket *avpkt) | ||
| 47 | { | ||
| 48 | 10 | FRWUContext *s = avctx->priv_data; | |
| 49 | int field, ret; | ||
| 50 | 10 | const uint8_t *buf = avpkt->data; | |
| 51 | 10 | const uint8_t *buf_end = buf + avpkt->size; | |
| 52 | |||
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (avpkt->size < avctx->width * 2 * avctx->height + 4 + 2*8) { |
| 54 | ✗ | av_log(avctx, AV_LOG_ERROR, "Packet is too small.\n"); | |
| 55 | ✗ | return AVERROR_INVALIDDATA; | |
| 56 | } | ||
| 57 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if (bytestream_get_le32(&buf) != MKTAG('F', 'R', 'W', '1')) { |
| 58 | ✗ | av_log(avctx, AV_LOG_ERROR, "incorrect marker\n"); | |
| 59 | ✗ | return AVERROR_INVALIDDATA; | |
| 60 | } | ||
| 61 | |||
| 62 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if ((ret = ff_get_buffer(avctx, pic, 0)) < 0) |
| 63 | ✗ | return ret; | |
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10 times.
|
30 | for (field = 0; field < 2; field++) { |
| 66 | int i; | ||
| 67 | 20 | int field_h = (avctx->height + !field) >> 1; | |
| 68 | 20 | int field_size, min_field_size = avctx->width * 2 * field_h; | |
| 69 | 20 | uint8_t *dst = pic->data[0]; | |
| 70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (buf_end - buf < 8) |
| 71 | ✗ | return AVERROR_INVALIDDATA; | |
| 72 | 20 | buf += 4; // flags? 0x80 == bottom field maybe? | |
| 73 | 20 | field_size = bytestream_get_le32(&buf); | |
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (field_size < min_field_size) { |
| 75 | ✗ | av_log(avctx, AV_LOG_ERROR, "Field size %i is too small (required %i)\n", field_size, min_field_size); | |
| 76 | ✗ | return AVERROR_INVALIDDATA; | |
| 77 | } | ||
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (buf_end - buf < field_size) { |
| 79 | ✗ | av_log(avctx, AV_LOG_ERROR, "Packet is too small, need %i, have %i\n", field_size, (int)(buf_end - buf)); | |
| 80 | ✗ | return AVERROR_INVALIDDATA; | |
| 81 | } | ||
| 82 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
20 | if (field ^ s->change_field_order) { |
| 83 | 10 | dst += pic->linesize[0]; | |
| 84 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | } else if (s->change_field_order) { |
| 85 | ✗ | dst += 2 * pic->linesize[0]; | |
| 86 | } | ||
| 87 |
2/2✓ Branch 0 taken 2400 times.
✓ Branch 1 taken 20 times.
|
2420 | for (i = 0; i < field_h; i++) { |
| 88 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 2400 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2400 | if (s->change_field_order && field && i == field_h - 1) |
| 89 | ✗ | dst = pic->data[0]; | |
| 90 | 2400 | memcpy(dst, buf, avctx->width * 2); | |
| 91 | 2400 | buf += avctx->width * 2; | |
| 92 | 2400 | dst += pic->linesize[0] << 1; | |
| 93 | } | ||
| 94 | 20 | buf += field_size - min_field_size; | |
| 95 | } | ||
| 96 | |||
| 97 | 10 | *got_frame = 1; | |
| 98 | |||
| 99 | 10 | return avpkt->size; | |
| 100 | } | ||
| 101 | |||
| 102 | static const AVOption frwu_options[] = { | ||
| 103 | {"change_field_order", "Change field order", offsetof(FRWUContext, change_field_order), AV_OPT_TYPE_BOOL, | ||
| 104 | {.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM}, | ||
| 105 | {NULL} | ||
| 106 | }; | ||
| 107 | |||
| 108 | static const AVClass frwu_class = { | ||
| 109 | .class_name = "frwu Decoder", | ||
| 110 | .item_name = av_default_item_name, | ||
| 111 | .option = frwu_options, | ||
| 112 | .version = LIBAVUTIL_VERSION_INT, | ||
| 113 | }; | ||
| 114 | |||
| 115 | const FFCodec ff_frwu_decoder = { | ||
| 116 | .p.name = "frwu", | ||
| 117 | CODEC_LONG_NAME("Forward Uncompressed"), | ||
| 118 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 119 | .p.id = AV_CODEC_ID_FRWU, | ||
| 120 | .priv_data_size = sizeof(FRWUContext), | ||
| 121 | .init = decode_init, | ||
| 122 | FF_CODEC_DECODE_CB(decode_frame), | ||
| 123 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
| 124 | .p.priv_class = &frwu_class, | ||
| 125 | }; | ||
| 126 |