| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2009 Michael Niedermayer | ||
| 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 "avformat.h" | ||
| 22 | #include "demux.h" | ||
| 23 | #include "internal.h" | ||
| 24 | |||
| 25 | |||
| 26 | 7467 | static int probe(const AVProbeData *p) | |
| 27 | { | ||
| 28 | // the single file I have starts with that, I do not know if others do, too | ||
| 29 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 7438 times.
|
7467 | if( p->buf[0] == 1 |
| 30 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 25 times.
|
29 | && p->buf[1] == 1 |
| 31 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | && p->buf[2] == 3 |
| 32 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | && p->buf[3] == 0xB8 |
| 33 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | && p->buf[4] == 0x80 |
| 34 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | && p->buf[5] == 0x60 |
| 35 | ) | ||
| 36 | 1 | return AVPROBE_SCORE_MAX-2; | |
| 37 | |||
| 38 | 7466 | return 0; | |
| 39 | } | ||
| 40 | |||
| 41 | 1 | static int read_header(AVFormatContext *s) | |
| 42 | { | ||
| 43 | AVStream *st; | ||
| 44 | |||
| 45 | 1 | st = avformat_new_stream(s, NULL); | |
| 46 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!st) |
| 47 | ✗ | return AVERROR(ENOMEM); | |
| 48 | |||
| 49 | 1 | st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; | |
| 50 | 1 | st->codecpar->codec_id = AV_CODEC_ID_MPEG4; | |
| 51 | 1 | ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; | |
| 52 | 1 | avpriv_set_pts_info(st, 64, 1, 90000); | |
| 53 | |||
| 54 | 1 | return 0; | |
| 55 | |||
| 56 | } | ||
| 57 | |||
| 58 | 27 | static int read_packet(AVFormatContext *s, AVPacket *pkt) | |
| 59 | { | ||
| 60 | int ret, size, pts, type, flags; | ||
| 61 | 27 | int first_pkt = 0; | |
| 62 | 27 | int frame_complete = 0; | |
| 63 | |||
| 64 |
2/2✓ Branch 0 taken 545 times.
✓ Branch 1 taken 24 times.
|
569 | while (!frame_complete) { |
| 65 | |||
| 66 | 545 | type = avio_rb16(s->pb); // 257 or 258 | |
| 67 | 545 | size = avio_rb16(s->pb); | |
| 68 | 545 | flags = avio_rb16(s->pb); //some flags, 0x80 indicates end of frame | |
| 69 | 545 | avio_rb16(s->pb); //packet number | |
| 70 | 545 | pts = avio_rb32(s->pb); | |
| 71 | 545 | avio_rb32(s->pb); //6A 13 E3 88 | |
| 72 | |||
| 73 | 545 | frame_complete = flags & 0x80; | |
| 74 | |||
| 75 | 545 | size -= 12; | |
| 76 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 543 times.
|
545 | if (size < 1) |
| 77 | 2 | return -1; | |
| 78 | |||
| 79 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 542 times.
|
543 | if (type == 258) { |
| 80 | 1 | avio_skip(s->pb, size); | |
| 81 | 1 | frame_complete = 0; | |
| 82 | 1 | continue; | |
| 83 | } | ||
| 84 | |||
| 85 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 517 times.
|
542 | if (!first_pkt) { |
| 86 | 25 | ret = av_get_packet(s->pb, pkt, size); | |
| 87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (ret < 0) |
| 88 | ✗ | return ret; | |
| 89 | 25 | first_pkt = 1; | |
| 90 | 25 | pkt->pts = pts; | |
| 91 | 25 | pkt->pos -= 16; | |
| 92 | } else { | ||
| 93 | 517 | ret = av_append_packet(s->pb, pkt, size); | |
| 94 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 517 times.
|
517 | if (ret < 0) { |
| 95 | ✗ | av_log(s, AV_LOG_ERROR, "failed to grow packet\n"); | |
| 96 | ✗ | return ret; | |
| 97 | } | ||
| 98 | } | ||
| 99 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 541 times.
|
542 | if (ret < size) { |
| 100 | 1 | av_log(s, AV_LOG_ERROR, "Truncated packet! Read %d of %d bytes\n", | |
| 101 | ret, size); | ||
| 102 | 1 | pkt->flags |= AV_PKT_FLAG_CORRUPT; | |
| 103 | 1 | break; | |
| 104 | } | ||
| 105 | } | ||
| 106 | 25 | pkt->stream_index = 0; | |
| 107 | |||
| 108 | 25 | return 0; | |
| 109 | } | ||
| 110 | |||
| 111 | const FFInputFormat ff_iv8_demuxer = { | ||
| 112 | .p.name = "iv8", | ||
| 113 | .p.long_name = NULL_IF_CONFIG_SMALL("IndigoVision 8000 video"), | ||
| 114 | .p.flags = AVFMT_GENERIC_INDEX, | ||
| 115 | .read_probe = probe, | ||
| 116 | .read_header = read_header, | ||
| 117 | .read_packet = read_packet, | ||
| 118 | }; | ||
| 119 |