FFmpeg
Loading...
Searching...
No Matches
ncdec.c
Go to the documentation of this file.
1/*
2 * NC camera feed demuxer
3 * Copyright (c) 2009 Nicolas Martin (martinic at iro dot umontreal dot ca)
4 * Edouard Auvinet
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 "avformat.h"
25#include "demux.h"
26#include "internal.h"
27
28#define NC_VIDEO_FLAG 0x1A5
29
30static int nc_probe(const AVProbeData *probe_packet)
31{
32 int size;
33
34 if (AV_RB32(probe_packet->buf) != NC_VIDEO_FLAG)
35 return 0;
36
37 size = AV_RL16(probe_packet->buf + 5);
38
39 if (size + 20 > probe_packet->buf_size)
40 return AVPROBE_SCORE_MAX/4;
41
42 if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG)
43 return AVPROBE_SCORE_MAX;
44
45 return 0;
46}
47
49{
51
52 if (!st)
53 return AVERROR(ENOMEM);
54
58
59 avpriv_set_pts_info(st, 64, 1, 100);
60
61 return 0;
62}
63
65{
66 int size;
67 int ret;
68
69 uint32_t state=-1;
70 while (state != NC_VIDEO_FLAG) {
71 if (avio_feof(s->pb))
73 state = (state<<8) + avio_r8(s->pb);
74 }
75
76 avio_r8(s->pb);
77 size = avio_rl16(s->pb);
78 avio_skip(s->pb, 9);
79
80 if (size == 0) {
81 av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n");
82 return AVERROR(EAGAIN);
83 }
84
85 ret = av_get_packet(s->pb, pkt, size);
86 if (ret != size) {
88 }
89
90 pkt->stream_index = 0;
91 return size;
92}
93
95 .p.name = "nc",
96 .p.long_name = NULL_IF_CONFIG_SMALL("NC camera feed"),
97 .p.extensions = "v",
98 .read_probe = nc_probe,
99 .read_header = nc_read_header,
100 .read_packet = nc_read_packet,
101};
const FFInputFormat ff_nc_demuxer
Definition ncdec.c:94
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
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
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition avformat.h:611
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
unsigned int avio_rl16(AVIOContext *s)
Definition aviobuf.c:717
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
int avio_r8(AVIOContext *s)
Definition aviobuf.c:606
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
static AVPacket * pkt
static struct @346255127015250356166251341105367306144006377143 state
@ AV_CODEC_ID_MPEG4
Definition codec_id.h:62
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(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_RB32(p)
#define AV_RL16(p)
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:365
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static int nc_read_header(AVFormatContext *s)
Definition ncdec.c:48
static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition ncdec.c:64
#define NC_VIDEO_FLAG
Definition ncdec.c:28
static int nc_probe(const AVProbeData *probe_packet)
Definition ncdec.c:30
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
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
int buf_size
Size of buf except extra allocated bytes.
Definition avformat.h:474
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition avformat.h:473
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
enum AVStreamParseType need_parsing
Definition internal.h:321
#define av_log(a,...)
int size