annotate h261dec.c @ 6469:eb68008daac2 libavformat

Add a muxer and demuxer for raw G.722
author mstorsjo
date Thu, 09 Sep 2010 19:27:41 +0000
parents 4775a49a6045
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 868
diff changeset
1 /*
6437
c0f18afd0074 move h261 demuxer to its own file
aurel
parents: 6436
diff changeset
2 * RAW H.261 video demuxer
c0f18afd0074 move h261 demuxer to its own file
aurel
parents: 6436
diff changeset
3 * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3274
diff changeset
21
4872
304a0ea063f0 Rename bitstream.h to get_bits.h.
stefano
parents: 4857
diff changeset
22 #include "libavcodec/get_bits.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include "avformat.h"
6448
4775a49a6045 split raw.c into rawdec.c and rawenc.c
aurel
parents: 6437
diff changeset
24 #include "rawdec.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25
473
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
26 static int h261_probe(AVProbeData *p)
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
27 {
5183
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
28 uint32_t code= -1;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
29 int i;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
30 int valid_psc=0;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
31 int invalid_psc=0;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
32 int next_gn=0;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
33 int src_fmt=0;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
34 GetBitContext gb;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
35
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
36 init_get_bits(&gb, p->buf, p->buf_size*8);
473
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
37
5183
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
38 for(i=0; i<p->buf_size*8; i++){
5656
408c4e4d278a Optimize h261_probe function, since it is far slower than all others.
reimar
parents: 5451
diff changeset
39 if ((code & 0x01ff0000) || !(code & 0xff00)) {
408c4e4d278a Optimize h261_probe function, since it is far slower than all others.
reimar
parents: 5451
diff changeset
40 code = (code<<8) + get_bits(&gb, 8);
408c4e4d278a Optimize h261_probe function, since it is far slower than all others.
reimar
parents: 5451
diff changeset
41 i += 7;
408c4e4d278a Optimize h261_probe function, since it is far slower than all others.
reimar
parents: 5451
diff changeset
42 } else
5657
7bf8594a625a Reindent
reimar
parents: 5656
diff changeset
43 code = (code<<1) + get_bits1(&gb);
5183
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
44 if ((code & 0xffff0000) == 0x10000) {
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
45 int gn= (code>>12)&0xf;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
46 if(!gn)
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
47 src_fmt= code&8;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
48 if(gn != next_gn) invalid_psc++;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
49 else valid_psc++;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
50
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
51 if(src_fmt){ // CIF
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
52 next_gn= (gn+1 )%13;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
53 }else{ //QCIF
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
54 next_gn= (gn+1+!!gn)% 7;
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
55 }
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
56 }
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
57 }
5191
9affc096944c Make h261 and mpegvideo probe a little more robust so they dont fail with
michael
parents: 5184
diff changeset
58 if(valid_psc > 2*invalid_psc + 6){
473
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
59 return 50;
5183
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
60 }else if(valid_psc > 2*invalid_psc + 2)
3f35ada98286 Rewrite h261_probe().
michael
parents: 5182
diff changeset
61 return 25;
473
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
62 return 0;
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
63 }
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
64
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1121
diff changeset
65 AVInputFormat h261_demuxer = {
473
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
66 "h261",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3405
diff changeset
67 NULL_IF_CONFIG_SMALL("raw H.261"),
473
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
68 0,
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
69 h261_probe,
6430
d3a51b32b769 move ingenient demuxer to its own file
aurel
parents: 6429
diff changeset
70 ff_raw_video_read_header,
4610
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
71 ff_raw_read_partial_packet,
1756
5d72afc6c8aa better generic index building and seeking code
michael
parents: 1463
diff changeset
72 .flags= AVFMT_GENERIC_INDEX,
473
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
73 .extensions = "h261",
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
74 .value = CODEC_ID_H261,
e0a66a870b7f h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents: 468
diff changeset
75 };