FFmpeg
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 
23 #include "libavutil/intreadwrite.h"
24 #include "avformat.h"
25 #include "internal.h"
26 
27 #define NC_VIDEO_FLAG 0x1A5
28 
29 static int nc_probe(const AVProbeData *probe_packet)
30 {
31  int size;
32 
33  if (AV_RB32(probe_packet->buf) != NC_VIDEO_FLAG)
34  return 0;
35 
36  size = AV_RL16(probe_packet->buf + 5);
37 
38  if (size + 20 > probe_packet->buf_size)
39  return AVPROBE_SCORE_MAX/4;
40 
41  if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG)
42  return AVPROBE_SCORE_MAX;
43 
44  return 0;
45 }
46 
48 {
50 
51  if (!st)
52  return AVERROR(ENOMEM);
53 
57 
58  avpriv_set_pts_info(st, 64, 1, 100);
59 
60  return 0;
61 }
62 
64 {
65  int size;
66  int ret;
67 
68  uint32_t state=-1;
69  while (state != NC_VIDEO_FLAG) {
70  if (avio_feof(s->pb))
71  return AVERROR(EIO);
72  state = (state<<8) + avio_r8(s->pb);
73  }
74 
75  avio_r8(s->pb);
76  size = avio_rl16(s->pb);
77  avio_skip(s->pb, 9);
78 
79  if (size == 0) {
80  av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n");
81  return AVERROR(EAGAIN);
82  }
83 
84  ret = av_get_packet(s->pb, pkt, size);
85  if (ret != size) {
86  return AVERROR(EIO);
87  }
88 
89  pkt->stream_index = 0;
90  return size;
91 }
92 
94  .name = "nc",
95  .long_name = NULL_IF_CONFIG_SMALL("NC camera feed"),
96  .read_probe = nc_probe,
97  .read_header = nc_read_header,
98  .read_packet = nc_read_packet,
99  .extensions = "v",
100 };
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: options.c:243
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:58
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:454
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:463
avpriv_set_pts_info
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:771
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:413
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:735
pkt
AVPacket * pkt
Definition: movenc.c:59
AVInputFormat
Definition: avformat.h:546
nc_read_packet
static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: ncdec.c:63
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:551
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:453
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:94
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:386
AVFormatContext
Format I/O context.
Definition: avformat.h:1104
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:861
ff_nc_demuxer
const AVInputFormat ff_nc_demuxer
Definition: ncdec.c:93
NULL
#define NULL
Definition: coverity.c:32
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:451
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:115
size
int size
Definition: twinvq_data.h:10344
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:624
nc_probe
static int nc_probe(const AVProbeData *probe_packet)
Definition: ncdec.c:29
av_get_packet
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:102
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:838
avformat.h
nc_read_header
static int nc_read_header(AVFormatContext *s)
Definition: ncdec.c:47
AVPacket::stream_index
int stream_index
Definition: packet.h:376
NC_VIDEO_FLAG
#define NC_VIDEO_FLAG
Definition: ncdec.c:27
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:339
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:62
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:688
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
state
static struct @345 state
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:367