2018-09-12 04:13:53 +00:00
|
|
|
/*
|
|
|
|
* AVS2 video stream probe.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Huiwen Ren, <hwrenx@126.com>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avformat.h"
|
|
|
|
#include "rawdec.h"
|
2022-02-04 14:43:14 +00:00
|
|
|
#include "libavcodec/startcode.h"
|
2018-09-12 04:13:53 +00:00
|
|
|
#include "libavutil/intreadwrite.h"
|
|
|
|
|
2020-08-20 06:47:42 +00:00
|
|
|
#define AVS2_ISSQH(x) ((x) == 0xB0)
|
|
|
|
#define AVS2_ISEND(x) ((x) == 0xB1)
|
|
|
|
#define AVS2_ISPIC(x) ((x) == 0xB3 || (x) == 0xB6)
|
|
|
|
#define AVS2_ISUNIT(x) (AVS2_ISSQH(x) || AVS2_ISEND(x) || (x) == 0xB2 || AVS2_ISPIC(x) || (x) == 0xB5 || (x) == 0xB7)
|
|
|
|
#define AVS2_ISPROFILE(x) ((x) == 0x20 || (x) == 0x22 || (x) == 0x30 || (x) == 0x32)
|
2018-09-12 04:13:53 +00:00
|
|
|
|
2019-03-21 00:18:37 +00:00
|
|
|
static int avs2_probe(const AVProbeData *p)
|
2018-09-12 04:13:53 +00:00
|
|
|
{
|
2020-10-05 15:56:10 +00:00
|
|
|
uint32_t code = -1, hds = 0, pic = 0, seq = 0;
|
|
|
|
uint8_t state = 0;
|
|
|
|
const uint8_t *ptr = p->buf, *end = p->buf + p->buf_size, *sqb = 0;
|
2018-09-14 18:55:51 +00:00
|
|
|
if (AV_RB32(p->buf) != 0x1B0){
|
|
|
|
return 0;
|
|
|
|
}
|
2018-09-12 04:13:53 +00:00
|
|
|
|
|
|
|
while (ptr < end) {
|
|
|
|
ptr = avpriv_find_start_code(ptr, end, &code);
|
|
|
|
state = code & 0xFF;
|
|
|
|
if ((code & 0xffffff00) == 0x100) {
|
2020-08-20 06:47:42 +00:00
|
|
|
if (AVS2_ISUNIT(state)) {
|
2018-09-12 04:13:53 +00:00
|
|
|
if (sqb && !hds) {
|
|
|
|
hds = ptr - sqb;
|
|
|
|
}
|
2020-08-20 06:47:42 +00:00
|
|
|
if (AVS2_ISSQH(state)) {
|
|
|
|
if (!AVS2_ISPROFILE(*ptr))
|
2018-09-12 04:13:53 +00:00
|
|
|
return 0;
|
|
|
|
sqb = ptr;
|
|
|
|
seq++;
|
2020-08-20 06:47:42 +00:00
|
|
|
} else if (AVS2_ISPIC(state)) {
|
2018-09-12 04:13:53 +00:00
|
|
|
pic++;
|
2020-08-20 06:47:42 +00:00
|
|
|
} else if (AVS2_ISEND(state)) {
|
2018-09-12 04:13:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (seq && hds >= 21 && pic){
|
|
|
|
return AVPROBE_SCORE_EXTENSION + 2; // more than cavs
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FF_DEF_RAWVIDEO_DEMUXER(avs2, "raw AVS2-P2/IEEE1857.4", avs2_probe, "avs,avs2", AV_CODEC_ID_AVS2)
|