FFmpeg
shortendec.c
Go to the documentation of this file.
1 /*
2  * Shorten demuxer
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2005 Alex Beregszaszi
5  * Copyright (c) 2015 Carl Eugen Hoyos
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "avformat.h"
25 #include "demux.h"
26 #include "rawdec.h"
27 #include "libavcodec/golomb.h"
28 
29 static int shn_probe(const AVProbeData *p)
30 {
31  GetBitContext gb;
32  int version, internal_ftype, channels, blocksize;
33 
34  if (AV_RB32(p->buf) != 0x616a6b67)
35  return 0;
36  version = p->buf[4];
37  if (init_get_bits8(&gb, p->buf + 5, p->buf_size - 5 - AV_INPUT_BUFFER_PADDING_SIZE) < 0)
38  return 0;
39  if (!version) {
40  internal_ftype = get_ur_golomb_shorten(&gb, 4);
42  blocksize = 256;
43  } else {
44  unsigned k;
45  k = get_ur_golomb_shorten(&gb, 2);
46  if (k > 31)
47  return 0;
48  internal_ftype = get_ur_golomb_shorten(&gb, k);
49  k = get_ur_golomb_shorten(&gb, 2);
50  if (k > 31)
51  return 0;
53  k = get_ur_golomb_shorten(&gb, 2);
54  if (k > 31)
55  return 0;
56  blocksize = get_ur_golomb_shorten(&gb, k);
57  }
58 
59  if (internal_ftype != 2 && internal_ftype != 3 && internal_ftype != 5)
60  return 0;
62  return 0;
63  if (blocksize < 1 || blocksize > 65535)
64  return 0;
65 
66  return AVPROBE_SCORE_EXTENSION + 1;
67 }
68 
70  .p.name = "shn",
71  .p.long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
73  .p.extensions = "shn",
74  .p.priv_class = &ff_raw_demuxer_class,
75  .read_probe = shn_probe,
76  .read_header = ff_raw_audio_read_header,
77  .read_packet = ff_raw_read_partial_packet,
78  .raw_codec_id = AV_CODEC_ID_SHORTEN,
79  .priv_data_size = sizeof(FFRawDemuxerContext),
80 };
AVFMT_NO_BYTE_SEEK
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition: avformat.h:487
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:479
ff_shorten_demuxer
const FFInputFormat ff_shorten_demuxer
Definition: shortendec.c:69
get_ur_golomb_shorten
static unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k)
read unsigned golomb rice code (shorten).
Definition: golomb.h:554
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:454
AVFMT_NOBINSEARCH
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition: avformat.h:485
golomb.h
exp golomb vlc stuff
GetBitContext
Definition: get_bits.h:108
FFRawDemuxerContext
Definition: rawdec.h:37
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
ff_raw_read_partial_packet
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawdec.c:33
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:453
channels
channels
Definition: aptx.h:31
ff_raw_demuxer_class
const AVClass ff_raw_demuxer_class
Definition: rawdec.c:141
rawdec.h
ff_raw_audio_read_header
int ff_raw_audio_read_header(AVFormatContext *s)
Definition: rawdec.c:54
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:451
AVPROBE_SCORE_EXTENSION
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:461
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:41
version
version
Definition: libkvazaar.c:321
demux.h
shn_probe
static int shn_probe(const AVProbeData *p)
Definition: shortendec.c:29
avformat.h
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVFMT_NOGENSEARCH
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition: avformat.h:486
FFInputFormat
Definition: demux.h:37
AV_CODEC_ID_SHORTEN
@ AV_CODEC_ID_SHORTEN
Definition: codec_id.h:455