FFmpeg
Loading...
Searching...
No Matches
luodatdec.c
Go to the documentation of this file.
1/*
2 * CCTV DAT demuxer
3 *
4 * Copyright (c) 2020 Paul B Mahol
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
24#include "avio_internal.h"
25#include "avformat.h"
26#include "demux.h"
27#include "internal.h"
28
29static int dat_probe(const AVProbeData *p)
30{
31 if (p->buf_size < 0x2080)
32 return 0;
33
34 if (memcmp(p->buf, "luo ", 4))
35 return 0;
36
37 if (memcmp(p->buf + 0x1ffc, " oulliu ", 8))
38 return 0;
39
40 if (!AV_RL32(p->buf + 0x2004))
41 return 0;
42
43 if (memcmp(p->buf + 0x207c, " uil", 4))
44 return 0;
45
46 return AVPROBE_SCORE_MAX;
47}
48
50{
51 s->ctx_flags |= AVFMTCTX_NOHEADER;
52
53 avio_seek(s->pb, 0x2000, SEEK_SET);
54
55 return 0;
56}
57
59{
60 AVIOContext *pb = s->pb;
61 int index, ret, key, stream_id, stream_index, width, height, fps, pkt_size;
62 int64_t pts, pos = avio_tell(pb);
63
64 if (avio_feof(pb))
65 return AVERROR_EOF;
66
67 if (avio_rb32(pb) != MKBETAG('l', 'i', 'u', ' '))
69 stream_id = avio_rl32(pb);
70 width = avio_rl32(pb);
71 height = avio_rl32(pb);
72 fps = avio_rl32(pb);
73 avio_skip(pb, 16);
74 key = avio_rl32(pb) == 1;
75 avio_skip(pb, 4);
76 index = avio_rl32(pb);
77 avio_skip(pb, 4);
78 pts = avio_rl64(pb);
79 pkt_size = avio_rl32(pb);
80 avio_skip(pb, 64);
81
82 if (pkt_size == 0)
83 return AVERROR_EOF;
84
85 for (stream_index = 0; stream_index < s->nb_streams; stream_index++) {
86 if (s->streams[stream_index]->id == stream_id)
87 break;
88 }
89
90 if (stream_index == s->nb_streams) {
92
93 if (!st)
94 return AVERROR(ENOMEM);
95
96 st->id = stream_id;
99 st->codecpar->width = width;
100 st->codecpar->height = height;
101 avpriv_set_pts_info(st, 64, 1, fps);
102 }
103
104 if (index >= s->nb_streams)
105 av_log(s, AV_LOG_WARNING, "Stream index out of range.\n");
106
107 ret = av_get_packet(pb, pkt, pkt_size);
108 if (ret < 0)
109 return ret;
110 pkt->pos = pos;
111 pkt->pts = pts;
112 pkt->stream_index = stream_index;
113 if (key)
114 pkt->flags |= AV_PKT_FLAG_KEY;
115
116 return ret;
117}
118
120 .p.name = "luodat",
121 .p.long_name = NULL_IF_CONFIG_SMALL("Video CCTV DAT"),
122 .p.extensions = "dat",
123 .p.flags = AVFMT_GENERIC_INDEX,
124 .read_probe = dat_probe,
125 .read_header = dat_read_header,
126 .read_packet = dat_read_packet,
127};
const FFInputFormat ff_luodat_demuxer
Definition luodatdec.c:119
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
#define AVFMTCTX_NOHEADER
signal that no header is present (streams are added dynamically)
Definition avformat.h:1284
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition utils.c:98
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition avformat.h:499
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
unsigned int avio_rl32(AVIOContext *s)
Definition aviobuf.c:733
unsigned int avio_rb32(AVIOContext *s)
Definition aviobuf.c:764
uint64_t avio_rl64(AVIOContext *s)
Definition aviobuf.c:741
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
const char * key
@ AV_CODEC_ID_H264
Definition codec_id.h:77
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int index
Definition gxfenc.c:90
#define AV_RL32(p)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static int dat_probe(const AVProbeData *p)
Definition luodatdec.c:29
static int dat_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition luodatdec.c:58
static int dat_read_header(AVFormatContext *s)
Definition luodatdec.c:49
#define MKBETAG(a, b, c, d)
Definition macros.h:56
unsigned int pos
Definition spdifenc.c:431
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1333
Bytestream IO Context.
Definition avio.h:160
This structure stores compressed data.
Definition packet.h:580
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int id
Format-specific stream ID.
Definition avformat.h:778
#define av_log(a,...)
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
static int64_t pts