00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "libavutil/intreadwrite.h"
00024 #include "avformat.h"
00025 #include "internal.h"
00026
00027 #define NC_VIDEO_FLAG 0x1A5
00028
00029 static int nc_probe(AVProbeData *probe_packet)
00030 {
00031 int size;
00032
00033 if (AV_RB32(probe_packet->buf) != NC_VIDEO_FLAG)
00034 return 0;
00035
00036 size = AV_RL16(probe_packet->buf + 5);
00037
00038 if (size + 20 > probe_packet->buf_size)
00039 return AVPROBE_SCORE_MAX/4;
00040
00041 if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG)
00042 return AVPROBE_SCORE_MAX;
00043
00044 return 0;
00045 }
00046
00047 static int nc_read_header(AVFormatContext *s, AVFormatParameters *ap)
00048 {
00049 AVStream *st = avformat_new_stream(s, NULL);
00050
00051 if (!st)
00052 return AVERROR(ENOMEM);
00053
00054 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00055 st->codec->codec_id = CODEC_ID_MPEG4;
00056 st->need_parsing = AVSTREAM_PARSE_FULL;
00057
00058 avpriv_set_pts_info(st, 64, 1, 100);
00059
00060 return 0;
00061 }
00062
00063 static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
00064 {
00065 int size;
00066 int ret;
00067
00068 uint32_t state=-1;
00069 while (state != NC_VIDEO_FLAG) {
00070 if (url_feof(s->pb))
00071 return AVERROR(EIO);
00072 state = (state<<8) + avio_r8(s->pb);
00073 }
00074
00075 avio_r8(s->pb);
00076 size = avio_rl16(s->pb);
00077 avio_skip(s->pb, 9);
00078
00079 if (size == 0) {
00080 av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n");
00081 return AVERROR(EAGAIN);
00082 }
00083
00084 ret = av_get_packet(s->pb, pkt, size);
00085 if (ret != size) {
00086 if (ret > 0) av_free_packet(pkt);
00087 return AVERROR(EIO);
00088 }
00089
00090 pkt->stream_index = 0;
00091 return size;
00092 }
00093
00094 AVInputFormat ff_nc_demuxer = {
00095 .name = "nc",
00096 .long_name = NULL_IF_CONFIG_SMALL("NC camera feed format"),
00097 .read_probe = nc_probe,
00098 .read_header = nc_read_header,
00099 .read_packet = nc_read_packet,
00100 .extensions = "v",
00101 };