• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavformat/h264dec.c

Go to the documentation of this file.
00001 /*
00002  * RAW H.264 video demuxer
00003  * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "avformat.h"
00023 #include "rawdec.h"
00024 
00025 static int h264_probe(AVProbeData *p)
00026 {
00027     uint32_t code= -1;
00028     int sps=0, pps=0, idr=0, res=0, sli=0;
00029     int i;
00030 
00031     for(i=0; i<p->buf_size; i++){
00032         code = (code<<8) + p->buf[i];
00033         if ((code & 0xffffff00) == 0x100) {
00034             int ref_idc= (code>>5)&3;
00035             int type   = code & 0x1F;
00036             static const int8_t ref_zero[32]={
00037                 2, 0, 0, 0, 0,-1, 1,-1,
00038                -1, 1, 1, 1, 1,-1, 2, 2,
00039                 2, 2, 2, 0, 2, 2, 2, 2,
00040                 2, 2, 2, 2, 2, 2, 2, 2
00041             };
00042 
00043             if(code & 0x80) //forbidden bit
00044                 return 0;
00045 
00046             if(ref_zero[type] == 1 && ref_idc)
00047                 return 0;
00048             if(ref_zero[type] ==-1 && !ref_idc)
00049                 return 0;
00050             if(ref_zero[type] == 2)
00051                 res++;
00052 
00053             switch(type){
00054             case     1:   sli++; break;
00055             case     5:   idr++; break;
00056             case     7:
00057                 if(p->buf[i+2]&0x0F)
00058                     return 0;
00059                 sps++;
00060                 break;
00061             case     8:   pps++; break;
00062             }
00063         }
00064     }
00065     if(sps && pps && (idr||sli>3) && res<(sps+pps+idr))
00066         return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
00067     return 0;
00068 }
00069 
00070 FF_DEF_RAWVIDEO_DEMUXER(h264 , "raw H.264 video format", h264_probe, "h26l,h264,264", CODEC_ID_H264)
Generated on Sat Mar 17 2012 12:57:53 for Libav by doxygen 1.7.1