1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * RAW MPEG-4 video demuxer
3cabdff1aSopenharmony_ci * Copyright (c) 2006  Thijs Vermeir <thijs.vermeir@barco.com>
4cabdff1aSopenharmony_ci *
5cabdff1aSopenharmony_ci * This file is part of FFmpeg.
6cabdff1aSopenharmony_ci *
7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
11cabdff1aSopenharmony_ci *
12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15cabdff1aSopenharmony_ci * Lesser General Public License for more details.
16cabdff1aSopenharmony_ci *
17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20cabdff1aSopenharmony_ci */
21cabdff1aSopenharmony_ci
22cabdff1aSopenharmony_ci#include "avformat.h"
23cabdff1aSopenharmony_ci#include "rawdec.h"
24cabdff1aSopenharmony_ci
25cabdff1aSopenharmony_ci#define VOS_STARTCODE        0x1B0
26cabdff1aSopenharmony_ci#define USER_DATA_STARTCODE  0x1B2
27cabdff1aSopenharmony_ci#define GOP_STARTCODE        0x1B3
28cabdff1aSopenharmony_ci#define VISUAL_OBJ_STARTCODE 0x1B5
29cabdff1aSopenharmony_ci#define VOP_STARTCODE        0x1B6
30cabdff1aSopenharmony_ci#define SLICE_STARTCODE      0x1B7
31cabdff1aSopenharmony_ci#define EXT_STARTCODE        0x1B8
32cabdff1aSopenharmony_ci
33cabdff1aSopenharmony_cistatic int mpeg4video_probe(const AVProbeData *probe_packet)
34cabdff1aSopenharmony_ci{
35cabdff1aSopenharmony_ci    uint32_t temp_buffer = -1;
36cabdff1aSopenharmony_ci    int VO = 0, VOL = 0, VOP = 0, VISO = 0, res = 0;
37cabdff1aSopenharmony_ci    int res_main = 0;
38cabdff1aSopenharmony_ci    int i;
39cabdff1aSopenharmony_ci
40cabdff1aSopenharmony_ci    for (i = 0; i < probe_packet->buf_size; i++) {
41cabdff1aSopenharmony_ci        temp_buffer = (temp_buffer << 8) + probe_packet->buf[i];
42cabdff1aSopenharmony_ci        if (temp_buffer & 0xfffffe00)
43cabdff1aSopenharmony_ci            continue;
44cabdff1aSopenharmony_ci        if (temp_buffer < 2)
45cabdff1aSopenharmony_ci            continue;
46cabdff1aSopenharmony_ci
47cabdff1aSopenharmony_ci        if (temp_buffer == VOP_STARTCODE)
48cabdff1aSopenharmony_ci            VOP++;
49cabdff1aSopenharmony_ci        else if (temp_buffer == VISUAL_OBJ_STARTCODE)
50cabdff1aSopenharmony_ci            VISO++;
51cabdff1aSopenharmony_ci        else if (temp_buffer >= 0x100 && temp_buffer < 0x120)
52cabdff1aSopenharmony_ci            VO++;
53cabdff1aSopenharmony_ci        else if (temp_buffer >= 0x120 && temp_buffer < 0x130)
54cabdff1aSopenharmony_ci            VOL++;
55cabdff1aSopenharmony_ci        else if (temp_buffer == SLICE_STARTCODE || temp_buffer == EXT_STARTCODE)
56cabdff1aSopenharmony_ci            res_main++;
57cabdff1aSopenharmony_ci        else if (!(0x1AF < temp_buffer && temp_buffer < 0x1B7) &&
58cabdff1aSopenharmony_ci                 !(0x1B9 < temp_buffer && temp_buffer < 0x1C4))
59cabdff1aSopenharmony_ci            res++;
60cabdff1aSopenharmony_ci    }
61cabdff1aSopenharmony_ci
62cabdff1aSopenharmony_ci    // res_main repesents the reserved codes within the "main" profile, they are
63cabdff1aSopenharmony_ci    // added to the reserved ones if it appears that this is a "main" profile
64cabdff1aSopenharmony_ci    // stream
65cabdff1aSopenharmony_ci    if (res_main && 2*res_main < VOP)
66cabdff1aSopenharmony_ci        res += res_main;
67cabdff1aSopenharmony_ci
68cabdff1aSopenharmony_ci    if (VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res == 0)
69cabdff1aSopenharmony_ci        return VOP+VO > 4 ? AVPROBE_SCORE_EXTENSION : AVPROBE_SCORE_EXTENSION/2;
70cabdff1aSopenharmony_ci
71cabdff1aSopenharmony_ci    if (VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && VOP+VO > 4)
72cabdff1aSopenharmony_ci        return AVPROBE_SCORE_EXTENSION/10;
73cabdff1aSopenharmony_ci    return 0;
74cabdff1aSopenharmony_ci}
75cabdff1aSopenharmony_ci
76cabdff1aSopenharmony_ciFF_DEF_RAWVIDEO_DEMUXER2(m4v, "raw MPEG-4 video", mpeg4video_probe, "m4v",
77cabdff1aSopenharmony_ci                         AV_CODEC_ID_MPEG4, AVFMT_GENERIC_INDEX | AVFMT_TS_DISCONT)
78