annotate ncdec.c @ 5876:2c0f0162a110 libavformat

Move put_le16_nolen() to asf.c and give it a ff_ prefix. This way, it is easier to share it with e.g. MMS. Patch by Zhentan Feng <spyfeng gmail com>.
author rbultje
date Wed, 24 Mar 2010 18:40:43 +0000
parents ef6c4a95acb8
children 536e5527c1e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4415
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
1 /*
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
2 * NC camera feed demuxer
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
3 * Copyright (c) 2009 Nicolas Martin (martinic at iro dot umontreal dot ca)
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
4 * Edouard Auvinet
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
5 *
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
6 * This file is part of FFmpeg.
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
7 *
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
12 *
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
16 * Lesser General Public License for more details.
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
17 *
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
21 */
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
22
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
23 #include "libavutil/intreadwrite.h"
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
24 #include "avformat.h"
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
25
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
26 #define NC_VIDEO_FLAG 0x1A5
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
27
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
28 static int nc_probe(AVProbeData *probe_packet)
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
29 {
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
30 int size;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
31
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
32 if (AV_RB32(probe_packet->buf) != NC_VIDEO_FLAG)
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
33 return 0;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
34
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
35 size = AV_RL16(probe_packet->buf + 5);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
36
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
37 if (size + 20 > probe_packet->buf_size)
5192
ef6c4a95acb8 Do not return values above AVPROBE_SCORE_MAX from probe().
michael
parents: 4419
diff changeset
38 return AVPROBE_SCORE_MAX/4;
4415
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
39
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
40 if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG)
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
41 return AVPROBE_SCORE_MAX;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
42
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
43 return 0;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
44 }
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
45
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
46 static int nc_read_header(AVFormatContext *s, AVFormatParameters *ap)
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
47 {
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
48 AVStream *st = av_new_stream(s, 0);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
49
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
50 if (!st)
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
51 return AVERROR(ENOMEM);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
52
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
53 st->codec->codec_type = CODEC_TYPE_VIDEO;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
54 st->codec->codec_id = CODEC_ID_MPEG4;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
55 st->need_parsing = AVSTREAM_PARSE_FULL;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
56
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
57 av_set_pts_info(st, 64, 1, 100);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
58
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
59 return 0;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
60 }
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
61
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
62 static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
63 {
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
64 int size;
4419
24d2dfc9086d 10l: fix compiler warning:
vitor
parents: 4415
diff changeset
65 int ret;
4415
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
66
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
67 uint32_t state=-1;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
68 while (state != NC_VIDEO_FLAG) {
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
69 if (url_feof(s->pb))
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
70 return AVERROR(EIO);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
71 state = (state<<8) + get_byte(s->pb);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
72 }
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
73
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
74 get_byte(s->pb);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
75 size = get_le16(s->pb);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
76 url_fskip(s->pb, 9);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
77
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
78 if (size == 0) {
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
79 av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n");
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
80 return AVERROR(EAGAIN);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
81 }
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
82
4419
24d2dfc9086d 10l: fix compiler warning:
vitor
parents: 4415
diff changeset
83 ret = av_get_packet(s->pb, pkt, size);
4415
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
84 if (ret != size) {
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
85 if (ret > 0) av_free_packet(pkt);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
86 return AVERROR(EIO);
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
87 }
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
88
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
89 pkt->stream_index = 0;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
90 return size;
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
91 }
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
92
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
93 AVInputFormat nc_demuxer = {
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
94 "nc",
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
95 NULL_IF_CONFIG_SMALL("NC camera feed format"),
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
96 0,
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
97 nc_probe,
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
98 nc_read_header,
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
99 nc_read_packet,
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
100 .extensions = "v",
e0da6eba9942 NC camera demuxer
vitor
parents:
diff changeset
101 };