FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "rawdec.h"
26 #include "libavcodec/golomb.h"
27 
28 static int shn_probe(AVProbeData *p)
29 {
30  GetBitContext gb;
31  int version, internal_ftype, channels, blocksize;
32 
33  if (AV_RB32(p->buf) != 0x616a6b67)
34  return 0;
35  version = p->buf[4];
36  if (init_get_bits8(&gb, p->buf + 5, p->buf_size - 5 - AV_INPUT_BUFFER_PADDING_SIZE) < 0)
37  return 0;
38  if (!version) {
39  internal_ftype = get_ur_golomb_shorten(&gb, 4);
40  channels = get_ur_golomb_shorten(&gb, 0);
41  blocksize = 256;
42  } else {
43  int k;
44  k = get_ur_golomb_shorten(&gb, 2);
45  internal_ftype = get_ur_golomb_shorten(&gb, k);
46  k = get_ur_golomb_shorten(&gb, 2);
47  channels = get_ur_golomb_shorten(&gb, k);
48  k = get_ur_golomb_shorten(&gb, 2);
49  blocksize = get_ur_golomb_shorten(&gb, k);
50  }
51 
52  if (internal_ftype != 2 && internal_ftype != 3 && internal_ftype != 5)
53  return 0;
55  return 0;
56  if (blocksize < 1 || blocksize > 65535)
57  return 0;
58 
59  return AVPROBE_SCORE_EXTENSION + 1;
60 }
61 
63  .name = "shn",
64  .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
65  .read_probe = shn_probe,
66  .read_header = ff_raw_audio_read_header,
67  .read_packet = ff_raw_read_partial_packet,
69  .extensions = "shn",
70  .raw_codec_id = AV_CODEC_ID_SHORTEN,
71 };
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition: avformat.h:475
static int shn_probe(AVProbeData *p)
Definition: shortendec.c:28
channels
Definition: aptx.c:30
int version
Definition: avisynth_c.h:766
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:87
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawdec.c:35
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
AVInputFormat ff_shorten_demuxer
Definition: shortendec.c:62
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:451
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:450
int ff_raw_audio_read_header(AVFormatContext *s)
Definition: rawdec.c:55
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:469
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:650
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition: avformat.h:476
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:458
This structure contains the data a format has to probe a file.
Definition: avformat.h:448
Main libavformat public API header.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:782
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition: avformat.h:477
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:647
static unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k)
read unsigned golomb rice code (shorten).
Definition: golomb.h:543
exp golomb vlc stuff