FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
h264dec.c
Go to the documentation of this file.
1 /*
2  * RAW H.264 video demuxer
3  * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "avformat.h"
23 #include "rawdec.h"
24 #include "libavcodec/internal.h"
25 
26 static int h264_probe(AVProbeData *p)
27 {
28  uint32_t code = -1;
29  int sps = 0, pps = 0, idr = 0, res = 0, sli = 0;
30  int i;
31 
32  for (i = 0; i < p->buf_size; i++) {
33  code = (code << 8) + p->buf[i];
34  if ((code & 0xffffff00) == 0x100) {
35  int ref_idc = (code >> 5) & 3;
36  int type = code & 0x1F;
37  static const int8_t ref_zero[] = {
38  2, 0, 0, 0, 0, -1, 1, -1,
39  -1, 1, 1, 1, 1, -1, 2, 2,
40  2, 2, 2, 0, 2, 2, 2, 2,
41  2, 2, 2, 2, 2, 2, 2, 2
42  };
43 
44  if (code & 0x80) // forbidden_bit
45  return 0;
46 
47  if (ref_zero[type] == 1 && ref_idc)
48  return 0;
49  if (ref_zero[type] == -1 && !ref_idc)
50  return 0;
51  if (ref_zero[type] == 2) {
52  if (!(code == 0x100 && !p->buf[i + 1] && !p->buf[i + 2]))
53  res++;
54  }
55 
56  switch (type) {
57  case 1:
58  sli++;
59  break;
60  case 5:
61  idr++;
62  break;
63  case 7:
64  if (p->buf[i + 2] & 0x03)
65  return 0;
66  sps++;
67  break;
68  case 8:
69  pps++;
70  break;
71  }
72  }
73  }
74  ff_tlog(NULL, "sps:%d pps:%d idr:%d sli:%d res:%d\n", sps, pps, idr, sli, res);
75 
76  if (sps && pps && (idr || sli > 3) && res < (sps + pps + idr))
77  return AVPROBE_SCORE_EXTENSION + 1; // 1 more than .mpg
78 
79  return 0;
80 }
81 
82 FF_DEF_RAWVIDEO_DEMUXER(h264, "raw H.264 video", h264_probe, "h26l,h264,264,avc", AV_CODEC_ID_H264)
#define ff_tlog(ctx,...)
Definition: internal.h:65
#define NULL
Definition: coverity.c:32
#define FF_DEF_RAWVIDEO_DEMUXER(shortname, longname, probe, ext, id)
Definition: rawdec.h:69
static int h264_probe(AVProbeData *p)
Definition: h264dec.c:26
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:463
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:462
GLint GLenum type
Definition: opengl_enc.c:105
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:470
This structure contains the data a format has to probe a file.
Definition: avformat.h:460
static void idr(H264Context *h)
instantaneous decoder refresh.
Definition: h264.c:1077
Main libavformat public API header.
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:282