Libav
dtsdec.c
Go to the documentation of this file.
1 /*
2  * RAW DTS demuxer
3  * Copyright (c) 2008 Benjamin Larsson
4  *
5  * This file is part of Libav.
6  *
7  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavcodec/bytestream.h"
24 
25 #include "avformat.h"
26 #include "rawdec.h"
27 
28 static int dts_probe(AVProbeData *p)
29 {
30  const uint8_t *buf, *bufp;
31  uint32_t state = -1;
32  int markers[3] = {0};
33  int sum, max;
34 
35  buf = p->buf;
36 
37  for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
38  bufp = buf;
39  state = (state << 16) | bytestream_get_be16(&bufp);
40 
41  /* regular bitstream */
42  if (state == DCA_SYNCWORD_CORE_BE || state == DCA_SYNCWORD_CORE_LE)
43  markers[0]++;
44 
45  /* 14 bits big-endian bitstream */
46  if (state == DCA_SYNCWORD_CORE_14B_BE)
47  if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
48  markers[1]++;
49 
50  /* 14 bits little-endian bitstream */
51  if (state == DCA_SYNCWORD_CORE_14B_LE)
52  if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
53  markers[2]++;
54  }
55  sum = markers[0] + markers[1] + markers[2];
56  max = markers[1] > markers[0];
57  max = markers[2] > markers[max] ? 2 : max;
58  if (markers[max] > 3 && p->buf_size / markers[max] < 32*1024 &&
59  markers[max] * 4 > sum * 3)
60  return AVPROBE_SCORE_EXTENSION + 1;
61 
62  return 0;
63 }
64 
66  .name = "dts",
67  .long_name = NULL_IF_CONFIG_SMALL("raw DTS"),
68  .read_probe = dts_probe,
69  .read_header = ff_raw_audio_read_header,
70  .read_packet = ff_raw_read_partial_packet,
71  .flags = AVFMT_GENERIC_INDEX,
72  .extensions = "dts",
73  .raw_codec_id = AV_CODEC_ID_DTS,
74 };
static int dts_probe(AVProbeData *p)
Definition: dtsdec.c:28
uint8_t
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawdec.c:34
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:401
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:400
int ff_raw_audio_read_header(AVFormatContext *s)
Definition: rawdec.c:58
AVInputFormat ff_dts_demuxer
Definition: dtsdec.c:65
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:421
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:405
This structure contains the data a format has to probe a file.
Definition: avformat.h:398
Main libavformat public API header.
static struct @174 state
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:529