FFmpeg
davs2.c
Go to the documentation of this file.
1 /*
2  * AVS2 video stream probe.
3  *
4  * Copyright (C) 2018 Huiwen Ren, <hwrenx@126.com>
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 "avformat.h"
24 #include "rawdec.h"
25 #include "libavcodec/internal.h"
26 #include "libavutil/intreadwrite.h"
27 
28 #define ISSQH(x) ((x) == 0xB0 )
29 #define ISEND(x) ((x) == 0xB1 )
30 #define ISPIC(x) ((x) == 0xB3 || (x) == 0xB6)
31 #define ISUNIT(x) ( ISSQH(x) || ISEND(x) || (x) == 0xB2 || ISPIC(x) || (x) == 0xB5 || (x) == 0xB7 )
32 #define ISAVS2(x) ((x) == 0x20 || (x) == 0x22 || (x) == 0x30 || (x) == 0x32 )
33 
34 static int avs2_probe(const AVProbeData *p)
35 {
36  uint32_t code= -1, hds=0, pic=0, seq=0;
37  uint8_t state=0;
38  const uint8_t *ptr = p->buf, *end = p->buf + p->buf_size, *sqb=0;
39  if (AV_RB32(p->buf) != 0x1B0){
40  return 0;
41  }
42 
43  while (ptr < end) {
44  ptr = avpriv_find_start_code(ptr, end, &code);
45  state = code & 0xFF;
46  if ((code & 0xffffff00) == 0x100) {
47  if (ISUNIT(state)) {
48  if (sqb && !hds) {
49  hds = ptr - sqb;
50  }
51  if (ISSQH(state)) {
52  if (!ISAVS2(*ptr))
53  return 0;
54  sqb = ptr;
55  seq++;
56  } else if (ISPIC(state)) {
57  pic++;
58  } else if (ISEND(state)) {
59  break;
60  }
61  }
62  }
63  }
64  if (seq && hds >= 21 && pic){
65  return AVPROBE_SCORE_EXTENSION + 2; // more than cavs
66  }
67 
68  return 0;
69 }
70 
71 FF_DEF_RAWVIDEO_DEMUXER(avs2, "raw AVS2-P2/IEEE1857.4", avs2_probe, "avs,avs2", AV_CODEC_ID_AVS2)
ISAVS2
#define ISAVS2(x)
Definition: davs2.c:32
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
internal.h
AV_CODEC_ID_AVS2
@ AV_CODEC_ID_AVS2
Definition: avcodec.h:412
avpriv_find_start_code
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:449
ISSQH
#define ISSQH(x)
Definition: davs2.c:28
state
static struct @313 state
intreadwrite.h
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:448
FF_DEF_RAWVIDEO_DEMUXER
#define FF_DEF_RAWVIDEO_DEMUXER(shortname, longname, probe, ext, id)
Definition: rawdec.h:86
rawdec.h
avs2_probe
static int avs2_probe(const AVProbeData *p)
Definition: davs2.c:34
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:446
ISPIC
#define ISPIC(x)
Definition: davs2.c:30
AVPROBE_SCORE_EXTENSION
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:456
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:92
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
uint8_t
uint8_t
Definition: audio_convert.c:194
avformat.h
ISEND
#define ISEND(x)
Definition: davs2.c:29
ISUNIT
#define ISUNIT(x)
Definition: davs2.c:31