tls: Hide backend implementation details from users
[libav.git] / libavformat / ncdec.c
CommitLineData
eaf5d011
NM
1/*
2 * NC camera feed demuxer
3 * Copyright (c) 2009 Nicolas Martin (martinic at iro dot umontreal dot ca)
4 * Edouard Auvinet
5 *
2912e87a 6 * This file is part of Libav.
eaf5d011 7 *
2912e87a 8 * Libav is free software; you can redistribute it and/or
eaf5d011
NM
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 *
2912e87a 13 * Libav is distributed in the hope that it will be useful,
eaf5d011
NM
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
2912e87a 19 * License along with Libav; if not, write to the Free Software
eaf5d011
NM
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include "libavutil/intreadwrite.h"
24#include "avformat.h"
c3f9ebf7 25#include "internal.h"
eaf5d011
NM
26
27#define NC_VIDEO_FLAG 0x1A5
28
29static int nc_probe(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)
0535f919 39 return AVPROBE_SCORE_MAX/4;
eaf5d011
NM
40
41 if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG)
42 return AVPROBE_SCORE_MAX;
43
44 return 0;
45}
46
6e9651d1 47static int nc_read_header(AVFormatContext *s)
eaf5d011 48{
3b3bbdd3 49 AVStream *st = avformat_new_stream(s, NULL);
eaf5d011
NM
50
51 if (!st)
52 return AVERROR(ENOMEM);
53
9200514a
AK
54 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
55 st->codecpar->codec_id = AV_CODEC_ID_MPEG4;
eaf5d011
NM
56 st->need_parsing = AVSTREAM_PARSE_FULL;
57
c3f9ebf7 58 avpriv_set_pts_info(st, 64, 1, 100);
eaf5d011
NM
59
60 return 0;
61}
62
63static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
64{
65 int size;
f9e5b942 66 int ret;
eaf5d011
NM
67
68 uint32_t state=-1;
69 while (state != NC_VIDEO_FLAG) {
66e5b1df 70 if (s->pb->eof_reached)
eaf5d011 71 return AVERROR(EIO);
b7effd4e 72 state = (state<<8) + avio_r8(s->pb);
eaf5d011
NM
73 }
74
b7effd4e
AK
75 avio_r8(s->pb);
76 size = avio_rl16(s->pb);
45a8a02a 77 avio_skip(s->pb, 9);
eaf5d011
NM
78
79 if (size == 0) {
80 av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n");
81 return AVERROR(EAGAIN);
82 }
83
f9e5b942 84 ret = av_get_packet(s->pb, pkt, size);
eaf5d011 85 if (ret != size) {
ce70f28a 86 if (ret > 0) av_packet_unref(pkt);
eaf5d011
NM
87 return AVERROR(EIO);
88 }
89
90 pkt->stream_index = 0;
91 return size;
92}
93
c6610a21 94AVInputFormat ff_nc_demuxer = {
dfc2c4d9 95 .name = "nc",
6774247a 96 .long_name = NULL_IF_CONFIG_SMALL("NC camera feed"),
dfc2c4d9
AK
97 .read_probe = nc_probe,
98 .read_header = nc_read_header,
99 .read_packet = nc_read_packet,
20234a4b 100 .extensions = "v",
eaf5d011 101};